-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Viewports for win32+opengl backend (fix #2600) #5170
Conversation
Each window created in imgui_impl_win32.cpp now creates an openGL context which shares its display list space with the primary window's. IMGUI_IMPL_WIN32_OPENGL3 must be defined to use this fix.
ImGui_ImplWin32_Init() now optionally accepts a render context handle, and IMGUI_IMPL_WIN32_OPENGL3 is no longer a necessary define.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion on whether this is the right thing for the Win32 backend, but this definitely seems pretty close to being as low impact as it could be.
I mainly reviewed this from the perspective of how this will affect DirectX developers consuming/maintaining this backend.
It'd probably be a good idea to read all of the review comments before making changes since some of them cancel other ones out.
Device Contexts are no longer maintained for the application lifetime. ::GetDC() is now never called when using DirectX backend. Removed lambda callback and brought WGL function loading into conformance with XInput DLL loading.
I've just committed a change that should resolve all of these issues. We no longer maintain the device context when it's not in use. To make this possible, I did have to add some changes to imgui.h, but I don't believe the change is invasive. |
ocornut/imgui#5170 following this implementation
Hello, There is a The examples don't expect current context to be unchanged after rendering platform windows, see e.g. example_opengl3_glfw: // 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(backup_current_context);
} Therefore I don't think a "pop" is needed here and it looks like this could be simplified. While I have no timeframe for merging this, some other feedback:
Thanks! |
Could you post your example app for this? |
I rebased, added a (maybe) working example into: The whole topic has been extremely confusing, even more so as if we 8 open issues/PR and none of them goes 100%. #3218 seems particularly elegant, do you know if there's something that it doesn't do? |
Closed/solved, see #3218 (comment) |
Adds support for Win32 + OpenGL backends. Previously, this combination didn't work correctly because spawned windows weren't given rendering contexts. This PR makes it so OpenGL contexts are created and destroyed correctly for each new window. Additionally, it links the contexts to the main one via
wglShareLists()
.The only API change is the addition of an optional parameter,
hglrc
, inImGui_ImplWin32_Init()
. Passing in the main window's render context handle here will engage the new code. If only the first parameter is passed, a non-OpenGL API will be inferred. This makes it so existing projects using the Win32 backend will be able to merge this change without issue.When an OpenGL render context is specified, four WGL functions,
wglCreateContext()
,wglDeleteContext()
,wglMakeCurrent()
, andwglShareLists()
will be loaded dynamically to enable the context management. The OpenGL library will not be loaded if nohglrc
is specified.