2
0
Эх сурвалжийг харах

Viewport: Misc comments following user feedbacks..

omar 6 жил өмнө
parent
commit
a71d3c8cb3

+ 4 - 1
examples/example_glfw_opengl2/main.cpp

@@ -144,11 +144,14 @@ int main(int, char**)
         ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
 
         // Update and Render additional Platform Windows
+        // (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
+        //  For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
         if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
         {
+            GLFWwindow* backup_current_context = glfwGetCurrentContext();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
-            glfwMakeContextCurrent(window);
+            glfwMakeContextCurrent(backup_current_context);
         }
 
         glfwSwapBuffers(window);

+ 4 - 1
examples/example_glfw_opengl3/main.cpp

@@ -189,11 +189,14 @@ int main(int, char**)
         ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
     	
         // Update and Render additional Platform Windows
+        // (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
+        //  For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
         if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
         {
+            GLFWwindow* backup_current_context = glfwGetCurrentContext();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
-            glfwMakeContextCurrent(window);
+            glfwMakeContextCurrent(backup_current_context);
         }
 
         glfwSwapBuffers(window);

+ 5 - 1
examples/example_sdl_opengl2/main.cpp

@@ -147,11 +147,15 @@ int main(int, char**)
         ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
 
         // Update and Render additional Platform Windows
+        // (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
+        //  For this specific demo app we could also call SDL_GL_MakeCurrent(window, gl_context) directly)
         if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
         {
+            SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
+            SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
-            SDL_GL_MakeCurrent(window, gl_context);
+            SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
         }
 
         SDL_GL_SwapWindow(window);

+ 5 - 1
examples/example_sdl_opengl3/main.cpp

@@ -188,11 +188,15 @@ int main(int, char**)
         ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
 
         // Update and Render additional Platform Windows
+        // (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
+        //  For this specific demo app we could also call SDL_GL_MakeCurrent(window, gl_context) directly)
         if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
         {
+            SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
+            SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
-            SDL_GL_MakeCurrent(window, gl_context);
+            SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
         }
 
         SDL_GL_SwapWindow(window);

+ 4 - 4
imgui.cpp

@@ -3812,10 +3812,12 @@ void ImGui::EndFrame()
         viewport->LastPos = viewport->Pos;
         if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0.0f || viewport->Size.y <= 0.0f)
             continue;
-        if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window))
+        if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)) // Will be destroyed in UpdatePlatformWindows()
             continue;
         if (i > 0)
             IM_ASSERT(viewport->Window != NULL);
+
+        // Add to user-facing list
         g.PlatformIO.Viewports.push_back(viewport);
     }
     g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called
@@ -7680,11 +7682,9 @@ void ImGui::UpdatePlatformWindows()
             DestroyPlatformWindow(viewport);
             continue;
         }
-        if (viewport->LastFrameActive < g.FrameCount)
-            continue;
 
         // New windows that appears directly in a new viewport won't always have a size on their first frame
-        if (viewport->Size.x <= 0 || viewport->Size.y <= 0)
+        if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0 || viewport->Size.y <= 0)
             continue;
 
         // Update common viewport flags for owned viewports

+ 1 - 0
imgui_internal.h

@@ -651,6 +651,7 @@ enum ImGuiViewportFlagsPrivate_
 };
 
 // ImGuiViewport Private/Internals fields (cardinal sin: we are using inheritance!)
+// Note that every instance of ImGuiViewport is in fact a ImGuiViewportP.
 struct ImGuiViewportP : public ImGuiViewport
 {
     int                 Idx;