Closed meshula closed 6 years ago
Thanks Nick! I have just stumbled on the same problem today and after poking around remembered your post. Currently trying to improve the situation toward moving the main example backends to support multiple windows better.
The only issue I can find in this code is the fact that it maps 1 imgui context to 1 opengl context, whereas right now what I am doing will break exactly this assumption. I will rework the examples accordingly before patching this in.
Yes, I was able to enforce 1:1 at a higher level in my app where I manage GL context sharing. edin-p's docking code does a bunch of work to create and manage multiple ImGui contexts through copying around a bunch of state. I look forward to a cleaner solution!
You can see how it's doing there: https://github.com/ocornut/imgui/issues/351#issuecomment-354348675 Basically I'm working on a system where 1 imgui contexts will be able to output to multiple virtual viewports, and it'll all dynamic.
For the GLFW/GL VAO part, the problem is that I cannot use the GLFWWindow*
as a key because that function has no knowledge of a window being destroyed. For now to keep things simple I am recreating the VAO every frame, which I suspect is totally fine. As I will refactor the code/api in examples/
to support inputs/rendering for multiple windows I'll see if I can provide enough data to the render function to use a cache that we can clean.
(One problem I will be facing ahead is making those main backends (DX11, GLFW etc.) support multiple windows while still making them simple and clear enough so that a first time user who want to use their engine won't be overwhelmed by the too many details.)
Yes, my code leaks the VAO in the case a window is closed.
The leak isn’t too bad but if you destroy and recreate an imgui context (along with associated gl context) and end up with same pointer the rendering will fail.
(It’s an easy problem to solve but I want to reorganize those functions a bit and i’ll only know the proper design once I have all features in place.)
At this point, I have backed my docking code out to a simple splitter system. I still have multiple GL contexts to manage because I do offscreen rendering and what not, but I don't have multiple glfw windows. I'll re-migrate to docks when official support lands :)
Merged change where the VAO is created in the draw function, so that fixes the issue described here. Hopefully it's not a perf issue.
@meshula Saw you posting a message and deleting it. Thanks - they was indeed a leak in my commit earlier today. Handling multiple branches (since I'm refactoring the example) made me make those mistakes :( Should be fixed now. I couldn't see a perf difference but it could depend on drivers.
OpenGL context is dissociated from ImGuiContext because the code is heading toward a single imgui context managing multiple viewport that can be rendered with multiple graphics context. Eventually the target is to make the example architecture store per-viewport information, this may be coming next month hopefully.
I didn't mean to delete, must have fumble-clicked :)
Thanks for addressing my questions!
Hi there, I'm using this for docking -
https://github.com/edin-p/ImGuiDock
but it doesn't work with GLFW3 as written. In order to "tear off" a panel to become a free floating OS window, it's necessary to adapt imgui_impl_glfw_gl3.cpp to be smart enough to work with multiple GL contexts.
Unfortunately imgui_impl_glfw_gl3.cpp uses a global vertex array object, which can't be shared between multiple GL contexts because it isn't shareable GL data, like say a texture.
As a result, in order for ImGui to work with multiple OS windows in the same application, a patch like the following is necessary. Note that I realize std::map is not idiomatic for ImGui, I'm using it here as a quick implementation to illustrate a non-disruptive fix for the problem.