Viewport: Replaced UpdatePlatformWindows/RenderPlatformWindows by RenderAdditionalViewports(). The update is always called in EndFrame(). (#1542)

This commit is contained in:
omar 2018-03-02 22:44:06 +01:00
parent b807347e94
commit e9fa17e1bf
10 changed files with 33 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
*/

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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.