From be5f698befe44c5637821d64f32be112c2f2e973 Mon Sep 17 00:00:00 2001 From: Julius Nehring-Wirxel Date: Fri, 26 Feb 2021 15:38:04 +0100 Subject: [PATCH 1/3] Add WIP --- CMakeLists.txt | 10 +++++++ glfw/glow-extras/glfw/GlfwApp.cc | 31 +++++++++++++++++++++- glfw/glow-extras/glfw/GlfwApp.hh | 15 ++++++++++- viewer/glow-extras/viewer/ViewerApp.cc | 36 +++++++++++++++++++++++++- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f43063c..a30d186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ set(GLOW_EXTRAS_OPENGL_DEBUG_GROUPS ON CACHE BOOL "Set OpenGL debug groups for b set(GLOW_EXTRAS_DEFAULT_FONTS ON CACHE BOOL "If true, adds 'sans' and 'mono' (Fira) default fonts to the binary dir and loads them into the viewer") +set(GLOW_EXTRAS_VIEWER_USE_STRUCTURED_INTERFACE OFF CACHE BOOL "If true, use structured-interface instead of imgui in the glow-viewer") + # # Utility # @@ -121,6 +123,14 @@ if (TARGET imgui) target_compile_definitions(glow-extras PUBLIC GLOW_EXTRAS_HAS_IMGUI) endif() +if (TARGET structured-interface) + target_link_libraries(glow-extras PUBLIC structured-interface) + target_compile_definitions(glow-extras PUBLIC GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE) + if(GLOW_EXTRAS_VIEWER_USE_STRUCTURED_INTERFACE) + target_compile_definitions(glow-extras PUBLIC GLOW_VIEWER_USE_SI) + endif() +endif() + if (TARGET aion) target_link_libraries(glow-extras PUBLIC aion) target_compile_definitions(glow-extras PUBLIC GLOW_EXTRAS_HAS_AION) diff --git a/glfw/glow-extras/glfw/GlfwApp.cc b/glfw/glow-extras/glfw/GlfwApp.cc index 9700c16..48da6b3 100644 --- a/glfw/glow-extras/glfw/GlfwApp.cc +++ b/glfw/glow-extras/glfw/GlfwApp.cc @@ -11,6 +11,10 @@ #include #endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + +#endif + #include #include @@ -34,6 +38,8 @@ #include #include #include +#include +#include #include @@ -225,6 +231,12 @@ void GlfwApp::init() #endif break; + case Gui::structured_interface: +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + +#endif + break; + case Gui::None: break; } @@ -317,6 +329,7 @@ bool GlfwApp::onKey(int key, int scancode, int action, int mods) return true; } + #ifdef GLOW_EXTRAS_HAS_IMGUI if (key == GLFW_KEY_F9 && action == GLFW_PRESS) { @@ -383,7 +396,6 @@ bool GlfwApp::onMousePosition(double x, double y) return true; } #endif - return false; } @@ -913,6 +925,23 @@ void GlfwApp::endRender() glViewport(0, 0, getWindowWidth(), getWindowHeight()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } +#endif + // draw structured-interface +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + tg::mat4 proj = tg::translation(-1.f, 1.f, 0.0f) * tg::scaling(2.f / getWindowWidth(), -2.f / getWindowHeight(), 1.f); + size_t vertex_byte_size = 0; + size_t index_byte_size = 0; + for (auto const& rl : si_merger.get_render_data().lists) + { + vertex_byte_size += rl.vertices.size_bytes(); + index_byte_size += rl.indices.size_bytes(); + } + + glow::VertexArray va; + glow::ElementArrayBuffer ib; + } #endif } diff --git a/glfw/glow-extras/glfw/GlfwApp.hh b/glfw/glow-extras/glfw/GlfwApp.hh index b297f5e..4fc170d 100644 --- a/glfw/glow-extras/glfw/GlfwApp.hh +++ b/glfw/glow-extras/glfw/GlfwApp.hh @@ -21,6 +21,12 @@ #include #include +#ifdef GLOW_VIEWER_USE_SI +#include +#include +#include +#endif + struct GLFWwindow; struct CTwBar; typedef struct CTwBar TwBar; // structure CTwBar is not exposed. @@ -92,7 +98,8 @@ public: { None, AntTweakBar, - ImGui + ImGui, + structured_interface, }; GlfwApp(Gui gui = Gui::None) : mGui(gui) {} @@ -158,6 +165,12 @@ private: bool mDrawGui = true; bool mGuiAfterRender = false; +protected: +#ifdef GLOW_VIEWER_USE_SI + si::Default2DMerger si_merger; + si::gui si_gui; +#endif + // Default graphics private: /// Default Camera diff --git a/viewer/glow-extras/viewer/ViewerApp.cc b/viewer/glow-extras/viewer/ViewerApp.cc index 95082fb..c09fd59 100644 --- a/viewer/glow-extras/viewer/ViewerApp.cc +++ b/viewer/glow-extras/viewer/ViewerApp.cc @@ -4,15 +4,21 @@ #include #include + +#ifdef GLOW_VIEWER_USE_SI +#else #include #include #include #include #include +#endif #include #include +#include + #include "view.hh" using namespace glow; @@ -85,7 +91,16 @@ SubViewData& ViewerApp::getOrCreateSubViewData(tg::ipos2 start, tg::isize2 size) } ViewerApp::ViewerApp(glow::viewer::detail::shared_command_queue queue, glow::viewer::detail::global_settings const& settings) - : GlfwApp(Gui::ImGui), mStaticCommandQueue(std::move(queue)), mIsInteractive(detail::is_interactive(*mStaticCommandQueue)), mSettings(settings) + : GlfwApp( +#ifdef GLOW_VIEWER_USE_SI + Gui::structured_interface +#else + Gui::ImGui +#endif + ), + mStaticCommandQueue(std::move(queue)), + mIsInteractive(detail::is_interactive(*mStaticCommandQueue)), + mSettings(settings) { mLayoutNodes.reserve(8); } @@ -257,7 +272,11 @@ void ViewerApp::updateCamera(float dt) void ViewerApp::updateLayoutNodes(float dt, tg::isize2 size) { +#ifdef GLOW_VIEWER_USE_SI +#else ImGuizmo::SetRect(0, 0, size.width, size.height); +#endif + mRootNode = layout::tree_node{}; // for now: only works correctly with one view @@ -282,12 +301,15 @@ void ViewerApp::recomputeLayout(tg::isize2 size) void ViewerApp::forceInteractiveExecution(float dt, tg::isize2 size) { +#ifdef GLOW_VIEWER_USE_SI +#else // Imgui state has to be alive so the interactive lambda doesn't crash ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); updateLayoutNodes(dt, size); ImGui::EndFrame(); +#endif } void ViewerApp::renderFrame(int width, int height, bool maximizeSamples) @@ -654,7 +676,18 @@ void ViewerApp::onGui() // if interactive, perform layouting now so the interactive lambda can use imgui if (mIsInteractive) updateLayoutNodes(getCurrentDeltaTime(), getWindowSize()); +#ifdef GLOW_VIEWER_USE_SI + + auto r = si_gui.record([]() { si::text("i am text"); }); + si_merger.total_time = 1; // todo, is this required? + si_merger.viewport = {{0, 0}, {float(getWindowWidth()), float(getWindowHeight())}}; + si_merger.mouse_pos = getMousePosition(); + si_merger.is_lmb_down = isMouseButtonDown(GLFW_MOUSE_BUTTON_1); + si_merger.set_record_timings(1); // todo: is this required? + si_gui.update(r, si_merger); + +#else // perform viewer-global imgui if (ImGui::BeginMainMenuBar()) { @@ -781,6 +814,7 @@ void ViewerApp::onGui() } } ImGuizmo::SetRect(0, 0, getWindowWidth(), getWindowHeight()); +#endif sIsViewerActive = false; } -- GitLab From 277a117fa9ea9a135fab9acb17fd49a7628b32df Mon Sep 17 00:00:00 2001 From: Julius Nehring-Wirxel Date: Tue, 2 Mar 2021 13:32:49 +0100 Subject: [PATCH 2/3] Add Opt-In SI support --- glfw/glow-extras/glfw/GlfwApp.cc | 229 ++++++++++++++++++++--- glfw/glow-extras/glfw/GlfwApp.hh | 31 +++- viewer/glow-extras/viewer/ViewerApp.cc | 241 ++++++++++++++----------- 3 files changed, 361 insertions(+), 140 deletions(-) diff --git a/glfw/glow-extras/glfw/GlfwApp.cc b/glfw/glow-extras/glfw/GlfwApp.cc index 48da6b3..1410bd3 100644 --- a/glfw/glow-extras/glfw/GlfwApp.cc +++ b/glfw/glow-extras/glfw/GlfwApp.cc @@ -12,7 +12,10 @@ #endif #ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE - +#include +#include +#include +#include #endif #include @@ -40,6 +43,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -57,6 +64,36 @@ using namespace glow; using namespace glow::glfw; +constexpr auto shader_code_si_vsh = R"( +uniform mat4 uProj; + +in vec2 aPosition; +in vec2 aTexCoord; +in vec4 aColor; + +out vec4 vColor; +out vec2 vTexCoord; + +void main() +{ + gl_Position = uProj * vec4(aPosition, 1.0f, 1.0f); + vColor = aColor; + vTexCoord = aTexCoord; +})"; + +constexpr auto shader_code_si_fsh = R"( +uniform sampler2D uFontTexture; + +in vec2 vTexCoord; +in vec4 vColor; + +out vec4 fColor; + +void main() +{ + fColor = vColor * vec4(1, 1, 1, texture(uFontTexture, vTexCoord).r); +})"; + static GlfwApp* sCurrApp = nullptr; #ifdef GLOW_EXTRAS_HAS_ANTTWEAKBAR @@ -75,6 +112,8 @@ static void TW_CALL GlfwAppTweakCallback(void* clientData) { (*(std::function(); + mSIMerger = std::make_unique(); + + // init si rendering + mSIArrayBuffer = glow::ArrayBuffer::create(); + mSIArrayBuffer->defineAttribute(&si::Default2DMerger::vertex::pos, "aPosition"); + mSIArrayBuffer->defineAttribute(&si::Default2DMerger::vertex::color, "aColor", GL_UNSIGNED_BYTE, 4, AttributeMode::NormalizedInteger); + mSIArrayBuffer->defineAttribute(&si::Default2DMerger::vertex::uv, "aTexCoord"); + mSIElementArrayBuffer = glow::ElementArrayBuffer::create(); + mSIVertexArray = glow::VertexArray::create(mSIArrayBuffer, mSIElementArrayBuffer); + + // load default font + mSIFontTexture = glow::Texture2D::create(); + { + auto const& font = mSIMerger->get_font_atlas(); + auto tex = mSIFontTexture->bind(); + tex.setData(GL_RED, font.width, font.height, GL_RED, GL_UNSIGNED_BYTE, font.data.data()); + tex.setFilter(GL_LINEAR, GL_LINEAR); + tex.setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); + tex.generateMipmaps(); + } + + // create shader + auto vsh = glow::Shader::createFromSource(GL_VERTEX_SHADER, shader_code_si_vsh); + auto fsh = glow::Shader::createFromSource(GL_FRAGMENT_SHADER, shader_code_si_fsh); + mSIShader = glow::Program::create({vsh, fsh}); + } +#else + glow::warning() << "structured-interface GUI not supported (are you missing a dependency?)"; +#endif + break; // imgui case Gui::ImGui: @@ -231,12 +306,6 @@ void GlfwApp::init() #endif break; - case Gui::structured_interface: -#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE - -#endif - break; - case Gui::None: break; } @@ -328,15 +397,49 @@ bool GlfwApp::onKey(int key, int scancode, int action, int mods) if (ImGui::GetIO().WantCaptureKeyboard || ImGui::GetIO().WantTextInput) return true; } +#endif + +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + if (mSIMerger->is_in_text_edit()) + { + // todo: + // - ctrl + // - shift + // - long press + // - marked text + auto& text = mSIMerger->editable_text(); + + if (action == GLFW_PRESS) + { + switch (key) + { + case GLFW_KEY_BACKSPACE: + text.remove_prev_char(); + break; + case GLFW_KEY_DELETE: + text.remove_next_char(); + break; + case GLFW_KEY_RIGHT: + text.move_cursor_right(); + break; + case GLFW_KEY_LEFT: + text.move_cursor_left(); + break; + } + } + return true; + } + } +#endif -#ifdef GLOW_EXTRAS_HAS_IMGUI if (key == GLFW_KEY_F9 && action == GLFW_PRESS) { toggleProfilingOverlay(); return true; } -#endif if (mEnableDebugOverlay) { @@ -346,7 +449,7 @@ bool GlfwApp::onKey(int key, int scancode, int action, int mods) return true; } } -#endif + if (key == GLFW_KEY_HOME && action != GLFW_RELEASE) { @@ -374,6 +477,21 @@ bool GlfwApp::onChar(unsigned int codepoint, int /*mods*/) } #endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + if (mSIMerger->is_in_text_edit()) + { + // currently only supports ascii + if (codepoint > 0 && codepoint < 0x10000) + { + char c = codepoint; + mSIMerger->editable_text().on_text_input({&c, 1}); + return true; + } + } + } +#endif return false; } @@ -396,6 +514,15 @@ bool GlfwApp::onMousePosition(double x, double y) return true; } #endif + +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + if (mSIMerger->uses_input) + return true; + } +#endif + return false; } @@ -423,6 +550,14 @@ bool GlfwApp::onMouseButton(double x, double y, int button, int action, int mods } #endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + if (mSIMerger->uses_input) + return true; + } +#endif + return false; } @@ -446,6 +581,14 @@ bool GlfwApp::onMouseScroll(double sx, double sy) } #endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + if (mSIMerger->uses_input) + return true; + } +#endif + return false; } @@ -539,6 +682,13 @@ void GlfwApp::mainLoop() doCameraHandling = false; } #endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + if (mSIMerger->uses_input) + doCameraHandling = false; + } +#endif if (doCameraHandling) mCamera->update(static_cast(mCurrentRenderDeltaTime), mInputState, mWASDController, mLookAroundController, mTargetOrbitController); @@ -608,7 +758,8 @@ void GlfwApp::mainLoop() mLastCpuTimeMs = cpuRenderDispatchTime * 1000; #ifdef GLOW_EXTRAS_HAS_IMGUI - mProfilingOverlay->onFrame(mLastGpuTimeMs, mLastCpuTimeMs); + if (mGui == Gui::ImGui) + mProfilingOverlay->onFrame(mLastGpuTimeMs, mLastCpuTimeMs); #else if (mOutputStatsInterval > 0 && lastTime > lastStatsTime + mOutputStatsInterval) { @@ -837,16 +988,14 @@ void GlfwApp::internalOnMouseButton(double x, double y, int button, int action, void GlfwApp::internalOnGui() { -#ifdef GLOW_EXTRAS_HAS_IMGUI - if (mEnableDebugOverlay) + if (mGui == Gui::ImGui && mEnableDebugOverlay) debugging::DebugOverlay::OnGui(); - if (mUsePipelineConfigGui) + if (mGui == Gui::ImGui && mUsePipelineConfigGui) mPipelineScene->imguiConfigWindow(); - if (mProfilingOverlayVisible) + if (mGui == Gui::ImGui && mProfilingOverlayVisible) mProfilingOverlay->onGui(); -#endif } void GlfwApp::internalPerformGui() @@ -867,6 +1016,18 @@ void GlfwApp::internalPerformGui() ImGui::EndFrame(); } #endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (mGui == Gui::structured_interface) + { + mSIMerger->total_time = 1; // todo, is this required? + mSIMerger->viewport = {{0, 0}, {float(getWindowWidth()), float(getWindowHeight())}}; + mSIMerger->mouse_pos = getMousePosition(); + mSIMerger->is_lmb_down = isMouseButtonDown(GLFW_MOUSE_BUTTON_1); + mSIMerger->set_record_timings(1); // todo: is this required? + onGui(); + internalOnGui(); + } +#endif } void GlfwApp::updateInput() @@ -931,16 +1092,36 @@ void GlfwApp::endRender() if (mGui == Gui::structured_interface) { tg::mat4 proj = tg::translation(-1.f, 1.f, 0.0f) * tg::scaling(2.f / getWindowWidth(), -2.f / getWindowHeight(), 1.f); - size_t vertex_byte_size = 0; - size_t index_byte_size = 0; - for (auto const& rl : si_merger.get_render_data().lists) + + // todo: make member for improved performance + std::vector vertex_data; + std::vector index_data; + + for (auto const& rl : mSIMerger->get_render_data().lists) { - vertex_byte_size += rl.vertices.size_bytes(); - index_byte_size += rl.indices.size_bytes(); + for (auto const& v : rl.vertices) + vertex_data.push_back(v); + for (auto const i : rl.indices) + index_data.push_back(i); } - glow::VertexArray va; - glow::ElementArrayBuffer ib; + if (!index_data.empty()) + { + mSIArrayBuffer->bind().setData(vertex_data); + mSIElementArrayBuffer->bind().setIndices(index_data); + + auto shader = mSIShader->use(); + shader.setUniform("uProj", proj); + shader.setTexture("uFontTexture", mSIFontTexture); + + GLOW_SCOPED(enable, GL_BLEND); + GLOW_SCOPED(blendEquation, GL_FUNC_ADD); + GLOW_SCOPED(disable, GL_CULL_FACE); + GLOW_SCOPED(disable, GL_DEPTH_TEST); + GLOW_SCOPED(blendFunc, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + mSIVertexArray->bind().draw(); + } } #endif } diff --git a/glfw/glow-extras/glfw/GlfwApp.hh b/glfw/glow-extras/glfw/GlfwApp.hh index 4fc170d..27e9d27 100644 --- a/glfw/glow-extras/glfw/GlfwApp.hh +++ b/glfw/glow-extras/glfw/GlfwApp.hh @@ -21,10 +21,8 @@ #include #include -#ifdef GLOW_VIEWER_USE_SI -#include -#include -#include +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE +#include #endif struct GLFWwindow; @@ -102,7 +100,7 @@ public: structured_interface, }; - GlfwApp(Gui gui = Gui::None) : mGui(gui) {} + GlfwApp(Gui gui = Gui::None); private: std::string mTitle = "GLFW/GLOW Application"; ///< window title @@ -165,10 +163,27 @@ private: bool mDrawGui = true; bool mGuiAfterRender = false; +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE +private: + std::unique_ptr mSIMerger; + std::unique_ptr mSIGui; + SharedVertexArray mSIVertexArray; + SharedArrayBuffer mSIArrayBuffer; + SharedElementArrayBuffer mSIElementArrayBuffer; + SharedProgram mSIShader; + SharedTexture2D mSIFontTexture; + protected: -#ifdef GLOW_VIEWER_USE_SI - si::Default2DMerger si_merger; - si::gui si_gui; + si::Default2DMerger& getSIMerger() + { + assert(mSIMerger != nullptr); + return *mSIMerger; + } + si::gui& getSIGui() + { + assert(mSIGui != nullptr); + return *mSIGui; + } #endif // Default graphics diff --git a/viewer/glow-extras/viewer/ViewerApp.cc b/viewer/glow-extras/viewer/ViewerApp.cc index c09fd59..4b28899 100644 --- a/viewer/glow-extras/viewer/ViewerApp.cc +++ b/viewer/glow-extras/viewer/ViewerApp.cc @@ -5,8 +5,7 @@ #include -#ifdef GLOW_VIEWER_USE_SI -#else +#if GLOW_EXTRAS_HAS_IMGUI #include #include #include @@ -17,7 +16,13 @@ #include #include +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE +#include +#include +#include #include +#include +#endif #include "view.hh" @@ -218,7 +223,8 @@ void ViewerApp::init() sPreservedCamera = mCamera; // if the next viewer uses gv::reuse_camera - debugging::applyGlowImguiTheme(mSettings.imguiDarkMode); + if (Gui::ImGui == getGui()) + debugging::applyGlowImguiTheme(mSettings.imguiDarkMode); // Dummy render render(0.f); @@ -272,8 +278,7 @@ void ViewerApp::updateCamera(float dt) void ViewerApp::updateLayoutNodes(float dt, tg::isize2 size) { -#ifdef GLOW_VIEWER_USE_SI -#else +#ifdef GLOW_EXTRAS_HAS_IMGUI ImGuizmo::SetRect(0, 0, size.width, size.height); #endif @@ -301,14 +306,23 @@ void ViewerApp::recomputeLayout(tg::isize2 size) void ViewerApp::forceInteractiveExecution(float dt, tg::isize2 size) { -#ifdef GLOW_VIEWER_USE_SI -#else - // Imgui state has to be alive so the interactive lambda doesn't crash - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - updateLayoutNodes(dt, size); - ImGui::EndFrame(); +#ifdef GLOW_EXTRAS_HAS_IMGUI + if (getGui() == Gui::ImGui) + { + // Imgui state has to be alive so the interactive lambda doesn't crash + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + updateLayoutNodes(dt, size); + ImGui::EndFrame(); + } +#endif +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + if (getGui() == Gui::structured_interface) + { + auto r = getSIGui().record([&]() { updateLayoutNodes(dt, size); }); + getSIGui().update(r, getSIMerger()); + } #endif } @@ -675,137 +689,146 @@ void ViewerApp::onGui() // if interactive, perform layouting now so the interactive lambda can use imgui if (mIsInteractive) - updateLayoutNodes(getCurrentDeltaTime(), getWindowSize()); -#ifdef GLOW_VIEWER_USE_SI - - auto r = si_gui.record([]() { si::text("i am text"); }); - si_merger.total_time = 1; // todo, is this required? - si_merger.viewport = {{0, 0}, {float(getWindowWidth()), float(getWindowHeight())}}; - si_merger.mouse_pos = getMousePosition(); - si_merger.is_lmb_down = isMouseButtonDown(GLFW_MOUSE_BUTTON_1); - si_merger.set_record_timings(1); // todo: is this required? - si_gui.update(r, si_merger); - - -#else - // perform viewer-global imgui - if (ImGui::BeginMainMenuBar()) { - ImGui::PushID("glow_viewer_menu"); - - ImGui::MenuItem("Viewer", nullptr, false, false); + if (getGui() == Gui::structured_interface) + { +#ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE + auto r = getSIGui().record([&]() { updateLayoutNodes(getCurrentDeltaTime(), getWindowSize()); }); + getSIGui().update(r, getSIMerger()); +#endif + } + else + { + updateLayoutNodes(getCurrentDeltaTime(), getWindowSize()); + } + } - if (ImGui::BeginMenu("Actions")) +#ifdef GLOW_EXTRAS_HAS_IMGUI + if (getGui() == Gui::ImGui) + { + // perform viewer-global imgui + if (ImGui::BeginMainMenuBar()) { - if (ImGui::MenuItem("Take Screenshot", "F2")) - renderScreenshot(mScreenshotFile); + ImGui::PushID("glow_viewer_menu"); - if (ImGui::MenuItem("Reset Camera", "F3")) - resetCameraToScene(); + ImGui::MenuItem("Viewer", nullptr, false, false); - if (ImGui::MenuItem("Quit", "Esc")) - requestClose(); + if (ImGui::BeginMenu("Actions")) + { + if (ImGui::MenuItem("Take Screenshot", "F2")) + renderScreenshot(mScreenshotFile); - if (ImGui::MenuItem("Quit All", "Shift + Esc")) - throw TerminateException(); + if (ImGui::MenuItem("Reset Camera", "F3")) + resetCameraToScene(); - ImGui::EndMenu(); - } + if (ImGui::MenuItem("Quit", "Esc")) + requestClose(); - if (ImGui::BeginMenu("Tools")) - { - ImGui::MenuItem("Screenshot Tool", nullptr, &mShowScreenshotTool); - ImGui::EndMenu(); - } + if (ImGui::MenuItem("Quit All", "Shift + Esc")) + throw TerminateException(); - if (ImGui::BeginMenu("Info")) - { - auto const camOrientation = mCamera->getSphericalCoordinates(); - ImGui::Text("Cam Orientation: Azimuth: %.3f, Altitude: %.3f", camOrientation.comp0.degree(), camOrientation.comp1.degree()); - ImGui::Text("Cam Distance: %.3f", mCamera->getTargetDistance()); - auto const camPos = mCamera->getPosition(); - ImGui::Text("Cam Position: x: %.3f, y: %.3f, z: %.3f", camPos.x, camPos.y, camPos.z); - auto const camTarget = mCamera->getTargetPos(); - ImGui::Text("Cam Target: x: %.3f, y: %.3f, z: %.3f", camTarget.x, camTarget.y, camTarget.z); - - if (ImGui::BeginMenu("Print cam configuration")) + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Tools")) { - if (ImGui::MenuItem("Orientation")) - { - glow::info() << "Cam config:\nGLOW_VIEWER_CONFIG(glow::viewer::camera_orientation(" << toCppString(camOrientation.comp0) << ", " - << toCppString(camOrientation.comp1) << ", " << toCppString(mCamera->getTargetDistance()) << "));"; - } + ImGui::MenuItem("Screenshot Tool", nullptr, &mShowScreenshotTool); + ImGui::EndMenu(); + } - if (ImGui::MenuItem("Transform (Full)")) + if (ImGui::BeginMenu("Info")) + { + auto const camOrientation = mCamera->getSphericalCoordinates(); + ImGui::Text("Cam Orientation: Azimuth: %.3f, Altitude: %.3f", camOrientation.comp0.degree(), camOrientation.comp1.degree()); + ImGui::Text("Cam Distance: %.3f", mCamera->getTargetDistance()); + auto const camPos = mCamera->getPosition(); + ImGui::Text("Cam Position: x: %.3f, y: %.3f, z: %.3f", camPos.x, camPos.y, camPos.z); + auto const camTarget = mCamera->getTargetPos(); + ImGui::Text("Cam Target: x: %.3f, y: %.3f, z: %.3f", camTarget.x, camTarget.y, camTarget.z); + + if (ImGui::BeginMenu("Print cam configuration")) { - glow::info() << "Cam config:\nGLOW_VIEWER_CONFIG(glow::viewer::camera_transform(" << toCppString(mCamera->getPosition()) << ", " - << toCppString(mCamera->getTargetPos()) << "));"; + if (ImGui::MenuItem("Orientation")) + { + glow::info() << "Cam config:\nGLOW_VIEWER_CONFIG(glow::viewer::camera_orientation(" << toCppString(camOrientation.comp0) + << ", " << toCppString(camOrientation.comp1) << ", " << toCppString(mCamera->getTargetDistance()) << "));"; + } + + if (ImGui::MenuItem("Transform (Full)")) + { + glow::info() << "Cam config:\nGLOW_VIEWER_CONFIG(glow::viewer::camera_transform(" << toCppString(mCamera->getPosition()) + << ", " << toCppString(mCamera->getTargetPos()) << "));"; + } + + ImGui::EndMenu(); } ImGui::EndMenu(); } - ImGui::EndMenu(); - } + if (ImGui::BeginMenu("Overlays")) + { + if (ImGui::MenuItem("Profiling", "F9")) + toggleProfilingOverlay(); - if (ImGui::BeginMenu("Overlays")) - { - if (ImGui::MenuItem("Profiling", "F9")) - toggleProfilingOverlay(); + if (ImGui::MenuItem("OpenGL Log", "F10")) + toggleDebugOverlay(); - if (ImGui::MenuItem("OpenGL Log", "F10")) - toggleDebugOverlay(); + ImGui::EndMenu(); + } - ImGui::EndMenu(); + ImGui::PopID(); + ImGui::EndMainMenuBar(); } - ImGui::PopID(); - ImGui::EndMainMenuBar(); - } - - // screenshot tool - if (mShowScreenshotTool) - { - if (ImGui::Begin("Screenshot Tool", &mShowScreenshotTool, ImGuiWindowFlags_AlwaysAutoResize)) + // screenshot tool + if (mShowScreenshotTool) { - ImGui::PushID("screenshot_tool"); + if (ImGui::Begin("Screenshot Tool", &mShowScreenshotTool, ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::PushID("screenshot_tool"); - ImGui::InputText("Output Path", &mScreenshotFile); + ImGui::InputText("Output Path", &mScreenshotFile); - if (ImGui::Button("Render Screenshot")) - { - auto format = mScreenshotWithAlpha ? GL_RGBA8 : GL_RGB8; - if (mScreenshotCustomRes) - renderScreenshot(mScreenshotFile, mScreenshotWidth, mScreenshotHeight, mScreenshotAccumulationCount, format); - else - renderScreenshot(mScreenshotFile, -1, -1, mScreenshotAccumulationCount, format); - } + if (ImGui::Button("Render Screenshot")) + { + auto format = mScreenshotWithAlpha ? GL_RGBA8 : GL_RGB8; + if (mScreenshotCustomRes) + renderScreenshot(mScreenshotFile, mScreenshotWidth, mScreenshotHeight, mScreenshotAccumulationCount, format); + else + renderScreenshot(mScreenshotFile, -1, -1, mScreenshotAccumulationCount, format); + } - ImGui::Separator(); + ImGui::Separator(); - ImGui::Checkbox("Show non-transparent pixels", &mShowNonTransparentPixels); + ImGui::Checkbox("Show non-transparent pixels", &mShowNonTransparentPixels); - ImGui::SliderInt("Accumulation Count", &mScreenshotAccumulationCount, 1, 256); + ImGui::SliderInt("Accumulation Count", &mScreenshotAccumulationCount, 1, 256); - ImGui::Checkbox("Output with Alpha", &mScreenshotWithAlpha); + ImGui::Checkbox("Output with Alpha", &mScreenshotWithAlpha); - ImGui::Checkbox("Custom Resolution", &mScreenshotCustomRes); - if (ImGui::SliderInt("Screenshot Width", &mScreenshotWidth, 1, 16000)) - mScreenshotCustomRes = true; - if (ImGui::SliderInt("Screenshot Height", &mScreenshotHeight, 1, 16000)) - mScreenshotCustomRes = true; + ImGui::Checkbox("Custom Resolution", &mScreenshotCustomRes); + if (ImGui::SliderInt("Screenshot Width", &mScreenshotWidth, 1, 16000)) + mScreenshotCustomRes = true; + if (ImGui::SliderInt("Screenshot Height", &mScreenshotHeight, 1, 16000)) + mScreenshotCustomRes = true; - ImGui::PopID(); + ImGui::PopID(); + } + ImGui::End(); } - ImGui::End(); } - - // perform imgui for each renderable +#endif + // perform gui for each renderable sIsViewerActive = true; for (auto const& node : mLayoutNodes) { - ImGuizmo::SetRect(node.start.x, node.start.y, node.size.width, node.size.height); +#ifdef GLOW_EXTRAS_HAS_IMGUI + if (Gui::ImGui == getGui()) + ImGuizmo::SetRect(node.start.x, node.start.y, node.size.width, node.size.height); +#endif + for (auto const& r : node.scene.getRenderables()) { sCurrentViewMatrix = node.scene.viewMatrix; @@ -813,7 +836,9 @@ void ViewerApp::onGui() r->onGui(); } } - ImGuizmo::SetRect(0, 0, getWindowWidth(), getWindowHeight()); +#ifdef GLOW_EXTRAS_HAS_IMGUI + if (Gui::ImGui == getGui()) + ImGuizmo::SetRect(0, 0, getWindowWidth(), getWindowHeight()); #endif sIsViewerActive = false; } -- GitLab From 9daca3b5c29d6850b5b859963992f80c61bd6d51 Mon Sep 17 00:00:00 2001 From: Julius Nehring-Wirxel Date: Tue, 2 Mar 2021 13:50:08 +0100 Subject: [PATCH 3/3] Add forward declaration for si::Default2DMerger --- glfw/glow-extras/glfw/GlfwApp.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glfw/glow-extras/glfw/GlfwApp.hh b/glfw/glow-extras/glfw/GlfwApp.hh index 27e9d27..1129d5e 100644 --- a/glfw/glow-extras/glfw/GlfwApp.hh +++ b/glfw/glow-extras/glfw/GlfwApp.hh @@ -23,6 +23,10 @@ #ifdef GLOW_EXTRAS_HAS_STRUCTURED_INTERFACE #include +namespace si +{ +class Default2DMerger; // currently missing in fwd.hh +} #endif struct GLFWwindow; -- GitLab