From 77c95618683612ff9c79142daa0a45937ccac1bd Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Wed, 17 Feb 2021 01:09:12 -0500 Subject: [PATCH] Re-enable multiviewport Also fixes a bunch of stuff to make multiviewport way more stable --- engine/core/include/engine.hpp | 8 +++++--- engine/core/src/engine.cpp | 24 +++++++++++++++--------- engine/core/src/imguilayer.cpp | 6 ++---- engine/renderer/src/imguipass.cpp | 6 ++++-- platforms/mac/main.mm.in | 2 ++ 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/engine/core/include/engine.hpp b/engine/core/include/engine.hpp index 1280c3e..657a8e1 100755 --- a/engine/core/include/engine.hpp +++ b/engine/core/include/engine.hpp @@ -76,6 +76,8 @@ public: @param index The index of the window to begin rendering for. */ void render(const int index); + + void end_frame(); /// Pause updating. void pause(); @@ -344,12 +346,12 @@ private: RenderTarget* render_target; }; - std::vector _windows; + std::vector> _windows; Window* get_window(const int identifier) { for(auto& window : _windows) { - if(window.identifier == identifier) - return &window; + if(window->identifier == identifier) + return window.get(); } return nullptr; diff --git a/engine/core/src/engine.cpp b/engine/core/src/engine.cpp index 0ceb1a9..712a505 100755 --- a/engine/core/src/engine.cpp +++ b/engine/core/src/engine.cpp @@ -84,11 +84,11 @@ bool Engine::is_paused() const { } void Engine::quit() { - _windows[0].quitRequested = true; + _windows[0]->quitRequested = true; } bool Engine::is_quitting() const { - return _windows[0].quitRequested; + return _windows[0]->quitRequested; } void Engine::prepare_quit() { @@ -193,7 +193,7 @@ ui::Screen* Engine::load_screen(const file::Path path) { void Engine::set_screen(ui::Screen* screen) { _current_screen = screen; - screen->extent = _windows[0].extent; + screen->extent = _windows[0]->extent; screen->calculate_sizes(); get_renderer()->set_screen(screen); @@ -414,10 +414,12 @@ void Engine::add_window(void* native_handle, const int identifier, const prism:: _gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height); - Window& window = _windows.emplace_back(); - window.identifier = identifier; - window.extent = extent; - window.render_target = _renderer->allocate_render_target(drawable_extent); + _windows.push_back(std::move(std::make_unique())); + + Window* window = _windows.back().get(); + window->identifier = identifier; + window->extent = extent; + window->render_target = _renderer->allocate_render_target(drawable_extent); render_ready = true; } @@ -425,8 +427,8 @@ void Engine::add_window(void* native_handle, const int identifier, const prism:: void Engine::remove_window(const int identifier) { Expects(identifier >= 0); - utility::erase_if(_windows, [identifier](Window& w) { - return w.identifier == identifier; + utility::erase_if(_windows, [identifier](std::unique_ptr& w) { + return w->identifier == identifier; }); } @@ -658,6 +660,10 @@ void Engine::begin_frame(const float delta_time) { _app->begin_frame(); } +void Engine::end_frame() { + ImGui::UpdatePlatformWindows(); +} + int frame_delay = 0; const int frame_delay_between_resolution_change = 60; diff --git a/engine/core/src/imguilayer.cpp b/engine/core/src/imguilayer.cpp index c49d5f6..4351cc9 100755 --- a/engine/core/src/imguilayer.cpp +++ b/engine/core/src/imguilayer.cpp @@ -41,8 +41,8 @@ ImGuiLayer::ImGuiLayer() { io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; io.BackendPlatformName = "Prism"; - //if(platform::supports_feature(PlatformFeature::Windowing)) - // io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + if(platform::supports_feature(PlatformFeature::Windowing)) + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; for (auto& [im, pl] : imToPl) io.KeyMap[im] = platform::get_keycode(pl); @@ -196,8 +196,6 @@ void ImGuiLayer::render(int index) { if(index == 0) { ImGui::EndFrame(); ImGui::Render(); - - ImGui::UpdatePlatformWindows(); } } diff --git a/engine/renderer/src/imguipass.cpp b/engine/renderer/src/imguipass.cpp index 9399eff..0143a58 100755 --- a/engine/renderer/src/imguipass.cpp +++ b/engine/renderer/src/imguipass.cpp @@ -75,9 +75,11 @@ void ImGuiPass::render_post(GFXCommandBuffer* command_buffer, const int index) { } else { auto& io = ImGui::GetPlatformIO(); for(int i = 1; i < io.Viewports.size(); i++) { - if((io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) - if(*(int*)io.Viewports[i]->PlatformHandle == index) + if((io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) { + auto platform_handle = (int*)io.Viewports[i]->PlatformHandle; + if(platform_handle != nullptr && *platform_handle == index) draw_data = io.Viewports[i]->DrawData; + } } } diff --git a/platforms/mac/main.mm.in b/platforms/mac/main.mm.in index 7cb6f18..fbf5a13 100755 --- a/platforms/mac/main.mm.in +++ b/platforms/mac/main.mm.in @@ -615,6 +615,8 @@ int main(int argc, char* argv[]) { if(window != nullptr) [window->delegate render]; } + + engine->end_frame(); scrollX = 0.0f; scrollY = 0.0f;