diff --git a/examples/directx10_example/main.cpp b/examples/directx10_example/main.cpp index eb6e5a66..ab6a0fdb 100644 --- a/examples/directx10_example/main.cpp +++ b/examples/directx10_example/main.cpp @@ -205,8 +205,7 @@ int main(int, char**) ImGui::Render(); ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData()); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderAdditionalViewports(); g_pSwapChain->Present(1, 0); // Present with vsync //g_pSwapChain->Present(0, 0); // Present without vsync diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index f949037b..8c0a9857 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -208,8 +208,7 @@ int main(int, char**) ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderAdditionalViewports(); g_pSwapChain->Present(1, 0); // Present with vsync //g_pSwapChain->Present(0, 0); // Present without vsync diff --git a/examples/directx12_example/main.cpp b/examples/directx12_example/main.cpp index 61d65b02..1e2d8157 100644 --- a/examples/directx12_example/main.cpp +++ b/examples/directx12_example/main.cpp @@ -401,8 +401,7 @@ int main(int, char**) g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderAdditionalViewports(); g_pSwapChain->Present(1, 0); // Present with vsync //g_pSwapChain->Present(0, 0); // Present without vsync diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 9c1de56b..7ed9a394 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -709,6 +709,7 @@ static void ImGui_ImplDX12_ResizeViewport(ImGuiViewport* viewport, int w, int h) { ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData; IM_ASSERT(0); + (void)data; (void)w; (void)h; /* if (data->RTView) { @@ -730,6 +731,7 @@ static void ImGui_ImplDX12_RenderViewport(ImGuiViewport* viewport) { ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData; IM_ASSERT(0); + (void)data; /* ImVec4 clear_color = ImGui::GetStyle().Colors[ImGuiCol_WindowBg]; // FIXME-PLATFORM clear_color.w = 1.0f; @@ -743,6 +745,7 @@ static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport) { ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData; IM_ASSERT(0); + (void)data; /* data->SwapChain->Present(0, 0); // Present without vsync */ diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 5d8dba0f..38195426 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -122,9 +122,8 @@ int main(int, char**) glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + + ImGui::RenderAdditionalViewports(); glfwMakeContextCurrent(window); glfwSwapBuffers(window); diff --git a/examples/sdl_opengl3_example/main.cpp b/examples/sdl_opengl3_example/main.cpp index 1fb38c2c..0b9f9485 100644 --- a/examples/sdl_opengl3_example/main.cpp +++ b/examples/sdl_opengl3_example/main.cpp @@ -130,9 +130,7 @@ int main(int, char**) glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderAdditionalViewports(); SDL_GL_MakeCurrent(window, gl_context); SDL_GL_SwapWindow(window); diff --git a/examples/sdl_vulkan_example/main.cpp b/examples/sdl_vulkan_example/main.cpp index b494cf5c..c1358a4f 100644 --- a/examples/sdl_vulkan_example/main.cpp +++ b/examples/sdl_vulkan_example/main.cpp @@ -733,10 +733,7 @@ int main(int, char**) #endif swap_chain_has_at_least_one_image = true; wd->FrameIndex = (wd->FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; - - // FIXME-PLATFORM - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderAdditionalViewports(); } // Cleanup diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index bc05919f..106f58eb 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -735,9 +735,7 @@ int main(int, char**) swap_chain_has_at_least_one_image = true; wd->FrameIndex = (wd->FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES; - // FIXME-PLATFORM - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + //ImGui::RenderAdditionalViewports(); } // Cleanup diff --git a/imgui.cpp b/imgui.cpp index 4f1a3d81..7ee87a36 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3450,12 +3450,10 @@ static void ImGui::UpdateViewports() IM_ASSERT(g.MouseViewport != NULL); } -void ImGui::UpdatePlatformWindows() +static void UpdatePlatformWindows() { // Create/resize windows ImGuiContext& g = *GImGui; - if (!(g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports)) - return; for (int i = 0; i < g.Viewports.Size; i++) { ImGuiViewport* viewport = g.Viewports[i]; @@ -3492,12 +3490,12 @@ void ImGui::UpdatePlatformWindows() } } -void ImGui::RenderPlatformWindows() +static void RenderPlatformWindows() { // Render ImGuiContext& g = *GImGui; - if (!(g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports)) - return; + ImVec2 backup_display_pos = g.IO.DisplayPos; + ImVec2 backup_display_size = g.IO.DisplaySize; for (int i = 0; i < g.Viewports.Size; i++) { ImGuiViewport* viewport = g.Viewports[i]; @@ -3510,6 +3508,8 @@ void ImGui::RenderPlatformWindows() if (g.IO.RendererInterface.RenderViewport) g.IO.RendererInterface.RenderViewport(viewport); } + g.IO.DisplayPos = backup_display_pos; + g.IO.DisplaySize = backup_display_size; // Swap for (int i = 0; i < g.Viewports.Size; i++) @@ -4347,6 +4347,9 @@ void ImGui::EndFrame() memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs)); g.FrameCountEnded = g.FrameCount; + + if (g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports) + UpdatePlatformWindows(); } void ImGui::Render() @@ -4360,7 +4363,8 @@ void ImGui::Render() // Skip render altogether if alpha is 0.0 // Note that vertex buffers have been created and are wasted, so it is best practice that you don't create windows in the first place, or consistently respond to Begin() returning false. - if (g.Style.Alpha > 0.0f) + bool disable_render = (g.Style.Alpha <= 0.0f); + if (!disable_render) { // Gather windows to render g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsActiveWindows = 0; @@ -4402,7 +4406,10 @@ void ImGui::Render() g.IO.MetricsRenderVertices += viewport->DrawData.TotalVtxCount; g.IO.MetricsRenderIndices += viewport->DrawData.TotalIdxCount; } + } + if (!disable_render) + { // Render. If user hasn't set a callback then they may retrieve the draw data via GetDrawData() #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS if (g.Viewports[0]->DrawData.CmdListsCount > 0 && g.IO.RenderDrawListsFn != NULL) @@ -4411,6 +4418,13 @@ void ImGui::Render() } } +void ImGui::RenderAdditionalViewports() +{ + ImGuiContext& g = *GImGui; + if (g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports) + RenderPlatformWindows(); +} + ImGuiViewport* ImGui::FindViewportByID(ImGuiID id) { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index 8e05af60..f039c160 100644 --- a/imgui.h +++ b/imgui.h @@ -151,6 +151,7 @@ namespace ImGui IMGUI_API ImGuiStyle& GetStyle(); IMGUI_API void NewFrame(); // start a new ImGui frame, you can submit any command from this point until Render()/EndFrame(). IMGUI_API void Render(); // ends the ImGui frame, finalize the draw data. (Obsolete: optionally call io.RenderDrawListsFn if set. Nowadays, prefer calling your render function yourself.) + IMGUI_API void RenderAdditionalViewports(); IMGUI_API ImDrawData* GetDrawData(); // valid after Render() and until the next call to NewFrame(). this is what you have to render. (Obsolete: this used to be passed to your io.RenderDrawListsFn() function.) IMGUI_API ImDrawData* GetDrawDataForViewport(ImGuiID viewport_id);// ImDrawData filtered to hold only the ImDrawList covering a given viewport. valid after Render() and until the next call to NewFrame() IMGUI_API void EndFrame(); // ends the ImGui frame. automatically called by Render(), so most likely don't need to ever call that yourself directly. If you don't need to render you may call EndFrame() but you'll have wasted CPU already. If you don't need to render, better to not create any imgui windows instead! @@ -530,10 +531,6 @@ namespace ImGui // Clipboard Utilities (also see the LogToClipboard() function to capture or output text data to the clipboard) IMGUI_API const char* GetClipboardText(); IMGUI_API void SetClipboardText(const char* text); - - // Additional OS/Platform Windows (when ImGuiConfigFlags_MultiViewports is set) - IMGUI_API void UpdatePlatformWindows(); // FIXME-PLATFORM - IMGUI_API void RenderPlatformWindows(); // FIXME-PLATFORM // Memory Utilities // All those functions are not reliant on the current context.