From 2fecd332fced95054309e289420ec5a5542340c1 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 19 Mar 2018 15:20:47 +0100 Subject: [PATCH] Viewport, Platform: Added void* to render/swap buffer functions. Comments. (#1542, #1042) --- examples/directx10_example/main.cpp | 4 ++-- examples/directx11_example/main.cpp | 4 ++-- examples/directx12_example/main.cpp | 4 ++-- examples/imgui_impl_dx10.cpp | 5 +++-- examples/imgui_impl_dx10.h | 1 + examples/imgui_impl_dx11.cpp | 5 +++-- examples/imgui_impl_dx11.h | 1 + examples/imgui_impl_dx12.cpp | 4 ++-- examples/imgui_impl_glfw.cpp | 5 +++-- examples/imgui_impl_glfw.h | 1 + examples/imgui_impl_opengl2.cpp | 3 +++ examples/imgui_impl_opengl2.h | 3 +++ examples/imgui_impl_opengl3.cpp | 6 +++++- examples/imgui_impl_opengl3.h | 4 ++++ examples/imgui_impl_sdl2.cpp | 6 +++--- examples/imgui_impl_sdl2.h | 3 +++ examples/imgui_impl_vulkan.cpp | 5 +++-- examples/imgui_impl_vulkan.h | 1 + examples/opengl3_example/main.cpp | 4 ++-- examples/sdl_opengl3_example/main.cpp | 4 ++-- examples/sdl_vulkan_example/main.cpp | 4 ++-- examples/vulkan_example/main.cpp | 4 ++-- imgui.cpp | 16 ++++++---------- imgui.h | 22 ++++++++++++---------- 24 files changed, 71 insertions(+), 48 deletions(-) diff --git a/examples/directx10_example/main.cpp b/examples/directx10_example/main.cpp index 6166a60ff..aea81a43a 100644 --- a/examples/directx10_example/main.cpp +++ b/examples/directx10_example/main.cpp @@ -208,9 +208,9 @@ int main(int, char**) ImGui::Render(); ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData()); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); 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 b5211009d..51c5b6d4a 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -226,9 +226,9 @@ int main(int, char**) ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); 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 f3d5d1713..57bd1bbcc 100644 --- a/examples/directx12_example/main.cpp +++ b/examples/directx12_example/main.cpp @@ -401,9 +401,9 @@ int main(int, char**) g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); g_pSwapChain->Present(1, 0); // Present with vsync //g_pSwapChain->Present(0, 0); // Present without vsync diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index eac0ccb8c..1a8858872 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -3,6 +3,7 @@ // Implemented features: // [X] User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). @@ -581,7 +582,7 @@ static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) } } -static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport) +static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx10* data = (ImGuiViewportDataDx10*)viewport->RendererUserData; ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); @@ -591,7 +592,7 @@ static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport) ImGui_ImplDX10_RenderDrawData(viewport->DrawData); } -static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport) +static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx10* data = (ImGuiViewportDataDx10*)viewport->RendererUserData; data->SwapChain->Present(0, 0); // Present without vsync diff --git a/examples/imgui_impl_dx10.h b/examples/imgui_impl_dx10.h index 5d972013a..401fa1ae6 100644 --- a/examples/imgui_impl_dx10.h +++ b/examples/imgui_impl_dx10.h @@ -3,6 +3,7 @@ // Implemented features: // [X] User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index 1a7ecdfda..4fdde88b8 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -3,6 +3,7 @@ // Implemented features: // [X] User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). @@ -589,7 +590,7 @@ static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) } } -static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport) +static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData; ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); @@ -599,7 +600,7 @@ static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport) ImGui_ImplDX11_RenderDrawData(viewport->DrawData); } -static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport) +static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData; data->SwapChain->Present(0, 0); // Present without vsync diff --git a/examples/imgui_impl_dx11.h b/examples/imgui_impl_dx11.h index 62fb627ef..6d75b2372 100644 --- a/examples/imgui_impl_dx11.h +++ b/examples/imgui_impl_dx11.h @@ -3,6 +3,7 @@ // Implemented features: // [X] User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 9eb5ac63f..e365827ec 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -726,7 +726,7 @@ static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) */ } -static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport) +static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; IM_ASSERT(0); @@ -740,7 +740,7 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport) ImGui_ImplDX12_RenderDrawData(viewport->DrawData); } -static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport) +static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; IM_ASSERT(0); diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index d1f2e54b5..528dc6908 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -4,6 +4,7 @@ // Implemented features: // [X] Gamepad navigation mapping. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. +// [X] Multi-viewport windows (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). @@ -448,14 +449,14 @@ static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewport* viewport, const char* t glfwSetWindowTitle(data->Window, title); } -static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport) +static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData; if (g_ClientApi == GlfwClientApi_OpenGL) glfwMakeContextCurrent(data->Window); } -static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport) +static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData; if (g_ClientApi == GlfwClientApi_OpenGL) diff --git a/examples/imgui_impl_glfw.h b/examples/imgui_impl_glfw.h index 84ab937f8..4c0cc39c6 100644 --- a/examples/imgui_impl_glfw.h +++ b/examples/imgui_impl_glfw.h @@ -4,6 +4,7 @@ // Implemented features: // [X] Gamepad navigation mapping. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. +// [X] Multi-viewport windows (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index cf763efd4..752b45a27 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -1,6 +1,9 @@ // ImGui Renderer for: OpenGL2 (legacy OpenGL, fixed pipeline) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) +// Implemented features: +// [X] User texture binding. Use 'GLUint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. + // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** // **Prefer using the code in imgui_impl_opengl3.cpp** // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. diff --git a/examples/imgui_impl_opengl2.h b/examples/imgui_impl_opengl2.h index a80dfac4b..5e9d5f22f 100644 --- a/examples/imgui_impl_opengl2.h +++ b/examples/imgui_impl_opengl2.h @@ -1,6 +1,9 @@ // ImGui Renderer for: OpenGL2 (legacy OpenGL, fixed pipeline) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) +// Implemented features: +// [X] User texture binding. Use 'GLUint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. + // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** // **Prefer using the code in imgui_impl_opengl3.cpp** // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index f753e2b46..f58d05255 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -2,6 +2,10 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) +// Implemented features: +// [X] User texture binding. Use 'GLUint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). + // CHANGELOG // (minor and older changes stripped away, please see git history for details) // 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. @@ -328,7 +332,7 @@ void ImGui_ImplOpenGL3_DestroyDeviceObjects() // Platform Interface (Optional, for multi-viewport support) //-------------------------------------------------------------------------------------------------------- -static void ImGui_ImplOpenGL3_RenderWindow(ImGuiViewport* viewport) +static void ImGui_ImplOpenGL3_RenderWindow(ImGuiViewport* viewport, void*) { if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) { diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 190148790..5d6afde64 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -2,6 +2,10 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) +// Implemented features: +// [X] User texture binding. Use 'GLUint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). + IMGUI_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); IMGUI_API void ImGui_ImplOpenGL3_Shutdown(); IMGUI_API void ImGui_ImplOpenGL3_NewFrame(); diff --git a/examples/imgui_impl_sdl2.cpp b/examples/imgui_impl_sdl2.cpp index 17d4ec038..36a415f3f 100644 --- a/examples/imgui_impl_sdl2.cpp +++ b/examples/imgui_impl_sdl2.cpp @@ -3,7 +3,7 @@ // (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) // Implemented features: -// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Multi-viewport windows (when ImGuiConfigFlags_EnableViewports is enabled). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). @@ -400,14 +400,14 @@ static void ImGui_ImplSDL2_SetWindowTitle(ImGuiViewport* viewport, const char* t SDL_SetWindowTitle(data->Window, title); } -static void ImGui_ImplSDL2_RenderWindow(ImGuiViewport* viewport) +static void ImGui_ImplSDL2_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData; if (data->GLContext) SDL_GL_MakeCurrent(data->Window, data->GLContext); } -static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport) +static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData; if (data->GLContext) diff --git a/examples/imgui_impl_sdl2.h b/examples/imgui_impl_sdl2.h index 051411d74..171ee374e 100644 --- a/examples/imgui_impl_sdl2.h +++ b/examples/imgui_impl_sdl2.h @@ -2,6 +2,9 @@ // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) // (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) +// Implemented features: +// [X] Multi-viewport windows (when ImGuiConfigFlags_EnableViewports is enabled). + // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 3a9e8b8fd..284901c43 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -3,6 +3,7 @@ // Missing features: // [ ] User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914 +// [ ] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). WORK-IN-PROGRESS. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 5 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXX_CreateFontsTexture(), ImGui_ImplXXXX_NewFrame(), ImGui_ImplXXXX_Render() and ImGui_ImplXXXX_Shutdown(). @@ -1113,7 +1114,7 @@ static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &data->WindowData, g_Allocator, (int)size.x, (int)size.y); } -static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport) +static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData; ImGui_ImplVulkan_WindowData* wd = &data->WindowData; @@ -1184,7 +1185,7 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport) } } -static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport) +static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData; ImGui_ImplVulkan_WindowData* wd = &data->WindowData; diff --git a/examples/imgui_impl_vulkan.h b/examples/imgui_impl_vulkan.h index 03d6ed3c0..7a89d9f2e 100644 --- a/examples/imgui_impl_vulkan.h +++ b/examples/imgui_impl_vulkan.h @@ -3,6 +3,7 @@ // Missing features: // [ ] User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914 +// [ ] Multi-viewport rendering (when ImGuiConfigFlags_EnableViewports is enabled). WORK-IN-PROGRESS. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 5 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXX_CreateFontsTexture(), ImGui_ImplXXXX_NewFrame(), ImGui_ImplXXXX_Render() and ImGui_ImplXXXX_Shutdown(). diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index b5c4f17bf..da53fa272 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -124,9 +124,9 @@ int main(int, char**) glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); glfwMakeContextCurrent(window); glfwSwapBuffers(window); diff --git a/examples/sdl_opengl3_example/main.cpp b/examples/sdl_opengl3_example/main.cpp index 0e4c40c4e..f53559444 100644 --- a/examples/sdl_opengl3_example/main.cpp +++ b/examples/sdl_opengl3_example/main.cpp @@ -132,9 +132,9 @@ int main(int, char**) glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); 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 4ec3083b4..5f92a0a21 100644 --- a/examples/sdl_vulkan_example/main.cpp +++ b/examples/sdl_vulkan_example/main.cpp @@ -469,9 +469,9 @@ int main(int, char**) memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float)); FrameRender(wd); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); FramePresent(wd); } diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index 111613f7a..69e6448ec 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -479,9 +479,9 @@ int main(int, char**) memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float)); FrameRender(wd); - // Update and Render additional Platform Windows + // Update and Render additional Platform Windows (when ImGuiConfigFlags_EnableViewports is enabled) ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindows(); + ImGui::RenderPlatformWindows(NULL, NULL); FramePresent(wd); } diff --git a/imgui.cpp b/imgui.cpp index 8310917e8..a45381c5c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3559,7 +3559,7 @@ void ImGui::UpdatePlatformWindows() // This is a default/basic function for performing the rendering/swap of multiple platform windows. // Custom renderers may prefer to not call this function at all, and instead iterate the platform data and handle rendering/sync themselves. -// The Render/Swap functions stored in ImGuiPlatformInterface are merely here to allow for this helper to exist, but you can do it yourself: +// The Render/Swap functions stored in ImGuiPlatformIO are merely here to allow for this helper to exist, but you can do it yourself: // // ImGuiPlatformData* data = ImGui::GetPlatformData(); // for (int i = 1; i < data->Viewports.Size; i++) @@ -3568,7 +3568,7 @@ void ImGui::UpdatePlatformWindows() // MySwapBufferFunction(data->Viewports[i], my_args); // // Note how we intentionally skip the main viewport (index 0) which is generally rendered as part of our main application. -void ImGui::RenderPlatformWindows() +void ImGui::RenderPlatformWindows(void* platform_render_arg, void* renderer_render_arg) { if (!(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_EnableViewports)) return; @@ -3578,18 +3578,14 @@ void ImGui::RenderPlatformWindows() for (int i = 1; i < data->Viewports.Size; i++) { ImGuiViewport* viewport = data->Viewports[i]; - if (platform_io.Platform_RenderWindow) - platform_io.Platform_RenderWindow(viewport); - if (platform_io.Renderer_RenderWindow) - platform_io.Renderer_RenderWindow(viewport); + if (platform_io.Platform_RenderWindow) platform_io.Platform_RenderWindow(viewport, platform_render_arg); + if (platform_io.Renderer_RenderWindow) platform_io.Renderer_RenderWindow(viewport, renderer_render_arg); } for (int i = 1; i < data->Viewports.Size; i++) { ImGuiViewport* viewport = data->Viewports[i]; - if (platform_io.Platform_SwapBuffers) - platform_io.Platform_SwapBuffers(viewport); - if (platform_io.Renderer_SwapBuffers) - platform_io.Renderer_SwapBuffers(viewport); + if (platform_io.Platform_SwapBuffers) platform_io.Platform_SwapBuffers(viewport, platform_render_arg); + if (platform_io.Renderer_SwapBuffers) platform_io.Renderer_SwapBuffers(viewport, renderer_render_arg); } } diff --git a/imgui.h b/imgui.h index a7415342a..9df9da494 100644 --- a/imgui.h +++ b/imgui.h @@ -545,12 +545,12 @@ namespace ImGui IMGUI_API void SetClipboardText(const char* text); // (Optional) Platform interface for multi-viewport support - IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // Platform/Renderer functions. - IMGUI_API ImGuiPlatformData* GetPlatformData(); // List of viewports. - IMGUI_API ImGuiViewport* GetMainViewport(); // GetPlatformData()->MainViewport - IMGUI_API void UpdatePlatformWindows(); // Call in main loop. Create/Destroy/Resize platform windows so there's one for each viewport - IMGUI_API void RenderPlatformWindows(); // Call in main loop. Call RenderWindow/SwapBuffers from the ImGuiPlatformIO structure. May be reimplemented by user. - IMGUI_API void DestroyPlatformWindows(); // Call in back-end shutdown. + IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // Platform/Renderer function, for back-end to setup. + IMGUI_API ImGuiPlatformData* GetPlatformData(); // List of viewports. Viewport 0 is always the main viewport, followed by the secondary viewports. + IMGUI_API ImGuiViewport* GetMainViewport(); // GetPlatformData()->MainViewport + IMGUI_API void UpdatePlatformWindows(); // Call in main loop. Create/Destroy/Resize platform windows so there's one for each viewport + IMGUI_API void RenderPlatformWindows(void* platform_render_arg, void* renderer_render_arg); // Call in main loop. Call RenderWindow/SwapBuffers from the ImGuiPlatformIO structure. May be reimplemented by user. + IMGUI_API void DestroyPlatformWindows(); // (Optional) Call in back-end shutdown if you need to close Platform Windows before imgui shutdown. IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // Memory Utilities @@ -1868,6 +1868,8 @@ struct ImFont // This is designed so we can mix and match two imgui_impl_xxxx files, one for the Platform (~ Windowing), one for Renderer. // Custom engine back-ends will often provide both Platform and Renderer interfaces and thus may not need to use all functions. // Platform functions are typically called before their Renderer counterpart, apart from Destroy which are called the other way. +// RenderPlatformWindows() basically iterate secondary viewports and call Platform+Renderer's RenderWindow then Platform+Renderer's SwapBuffers, +// You may skip using RenderPlatformWindows() and call your functions yourself if you need specific behavior for your multi-window rendering. struct ImGuiPlatformIO { // Platform (e.g. Win32, GLFW, SDL2) @@ -1880,8 +1882,8 @@ struct ImGuiPlatformIO ImVec2 (*Platform_GetWindowSize)(ImGuiViewport* vp); void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* title); void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // (Optional) Setup window transparency - void (*Platform_RenderWindow)(ImGuiViewport* vp); // (Optional) Setup for render (platform side) - void (*Platform_SwapBuffers)(ImGuiViewport* vp); // (Optional) Call Present/SwapBuffers (platform side) + void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Setup for render (platform side) + void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // (Optional) Call Present/SwapBuffers (platform side) float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // (Optional) DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. (FIXME-DPI) void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // (Optional) DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style. int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For Renderer to call into Platform code @@ -1890,8 +1892,8 @@ struct ImGuiPlatformIO void (*Renderer_CreateWindow)(ImGuiViewport* vp); // Create swap chains, frame buffers etc. void (*Renderer_DestroyWindow)(ImGuiViewport* vp); void (*Renderer_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // Resize swap chain, frame buffers etc. - void (*Renderer_RenderWindow)(ImGuiViewport* vp); // (Optional) Clear targets, Render viewport->DrawData - void (*Renderer_SwapBuffers)(ImGuiViewport* vp); // (Optional) Call Present/SwapBuffers (renderer side) + void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Clear targets, Render viewport->DrawData + void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // (Optional) Call Present/SwapBuffers (renderer side) }; // List of viewports to render as platform window (updated by ImGui::UpdatePlatformWindows)