-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Drawlists callbacks questions with OpenGL #7665
Comments
You can process geometry in callbacks, but you shouldn't process geometry that you submitted to ImGui. In that case, you should use the callback to just set up render state, then submit the geometry to ImGui, then add another callback to reset or restore the render state to something that is expected. If you forget to do that, changed render state will affect everything that comes after, even other draw lists that are executed afterwards. So if you are not careful, you can mess up all rendering down the line, and you don't have direct control over the order in which draw lists are executed. But they are executed sequentially, so basically you just need to make sure to fix the render state before the end of the draw list. This is not a bug of the library, just an advanced feature that puts the responsibility of proper use on the user. If you need to identify your callbacks, you can put identifying information into the user data pointer you are prividing to your callback. If you want to analyze draw calls and render state to get a better understanding and see where it goes wrong, RenderDoc is a great tool to do so. |
Thank you for the response.
Ok, got it. For a test I commented out the code and in one project everything looks broken and in second only if I change window draw list to background. Looks like I need to rework the callbacks. I'm not sure what you mean by 'submitting geometry to ImGui', at the moment callbacks look more or less like this:
I suspect I shouldn't use something ( Oh, and in some callbacks I use more shaders, giving some Adding Any hints appreciated. |
What I meant was using a callback to set up shaders and other state without drawing anything, then calling other drawing functions like f.e. So now you need to find out what state is wrong, maybe |
I just did an extra check and in 'full' project I removed all the
lines and checked that callbacks use the same drawlist ( |
If, instead of Edit: there is just one Edit2: After analyzing all 3 saved cases, it may look like sometimes ImGui is adding |
Investigation, part 2. The case can be narrowed to one callback. If we take a ImGui-OpenGL project containing only one window with one callback, Callback could contain only the binding of the texture that later on the ImGui will be rendered on
and reset command should be submitted after the callback
From the RenderDoc point of view it looks like if we add |
Hello,
That's correct and expected.
I am not sure I understand what you are saying or suggesting here. AFAIK you should never have to call Some comments on further replies:
This is what is currently happening defacto but I don't expect to guarantee that draw calls won't be merged in the future. In particular, once we add AABB information in ImDrawCmd there will be opportunities to merge more draw calls and even reorder some. My expectation is that user should never have to use
This is all correct. Additionally, you can use Tools->Metrics/Debugger to visualize the draw lists submitted to your backend.
Yes, the imgui_impl_opengl3 backend currently only uses GL_TEXTURE0. OpenGL is a giant intricate state machine, lots of implicit state etc.
I think you pretty much understood that at this point. Honestly, in OpenGL it is rather difficult and confusing to achieve. There's lots of contents in your messages but it's difficult to make sense of it or draw conclusions. Narrowing it down would be good.
Indeed. My advice with OpenGL would be to render all your contents into textures and then just emitting
Yes. |
Version/Branch of Dear ImGui:
Version 1.90.3, Branch: master
Back-ends:
imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
Windows 10 + Clang-cl 18.1.6
Full config/build information:
No response
Details:
Hello.
I'm using drawlists callbacks the usual(?) way:
In
callback_function
I juggle textures, bind to units, use glsl programs, the whole zoo is involved.That's why I add
ImDrawCallback_ResetRenderState
.At first I didn't add
AddDrawCmd();
to redraw the rectangle that I will be processing in callback,but I noticed that I have to do it in more and more cases.
First question: is there any clue about when I should or shouldn't refresh / force redraw this part of image?
Second question is about different draw lists in this context, maybe this will help me understand better the ImGui flow.
If I have a single callback in the frame (or all callbacks are in the same draw lists) skipping redraw (
AddDrawCmd
) results in messed up rectangle(s) that was processed in the callback(s). And now the interesting observation which I mention because it was quite hard to debug/trace it: if callbacks are from different draw lists (GetWindowDrawList
/GetBackgroundDrawList
) and one is lacking the redraw, then weird and terrible things are happening. In particular, the fonts looks like someone throw a grenade into textures store (font atlas gets textures from random locations?). The whole ImGui goes loco.Additionally, changing window properties, like making window invisible (no background, titlebar, borders) causes the mess looks slightly different.
Is there a short explanation for this?
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
The text was updated successfully, but these errors were encountered: