-
-
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
Can ImDrawLists be reused in a later Render()? #3515
Comments
Hello,
As suggested in the guidelines, if you ever state "it crashes" please provide details and evidence in the form of a call-stack. There's no copy constructor but you may currently use More specifically for what you seem to be trying to do (swap window's draw list) I believe we could do it more easily by flagging a window as Active but not clearing its ImDrawList contents, nor calling Begin(). I would like to use that technique to allow for windows with variable refresh rate, but it's not done yet. |
Sorry, there's the assertion: stored_draw_list = *ImGui::GetCurrentWindow()->DrawList->CloneOutput(); It was a long shot anyway. The approach you describe sounds better. Here's a nice article about that approach, in case you are interested: Thanks for the quick response! |
You are free to store expensive calculations however you want, I don't understand which problem you are trying to solve. |
It's just that now, I have the calculations of what to draw in a particular state, combined with the actual drawlist commands in my code.
I could separate the logic from the actual drawlist commands, storing x,y and size somewhere but I like the directness of ImGui to keep logic and draw commands together. |
For example, otherwise, I would need something like:
|
This related to #2391/#1878 right ? To clarify the situation, correct me if I am wrong:
I am curious wether there are other methods ? |
Is there any update on this? @WildRackoon have you figured out anything? I in particular would like to "cache" certain areas of a window. So, my idea is
I was just trying to make this work, reached a point where it's not crashing, but what I'm drawing in the I roughly tried to follow Generally for the merging I'm doing
My guess is that it has something to do with the Is what I'm trying to do possible? And if so,.. how? As far as I understand what @ocornut has suggested is caching a whole window (by not clearing it's drawlist). Thanks in advance! (edit: using PrimReserve & PrimWrite*) |
…DrawData itself. Faclitate user-manipulation of the array (#6406, #4879, #1878) + deep swap. (#6597, #6475, #6167, #5776, #5109, #4763, #3515, #1860) + Metrics: avoid misleadingly iterating all layers of DrawDataBuilder as everything is flattened into Layers[0] at this point. # Conflicts: # imgui.cpp # imgui_internal.h
FYI, tangential: I have posted a |
I think it should be possible already. When you want to update the ImDrawList:
When you want to simply re-render:
I think this should work. I realize this issue/request is old and it may not matter to do specially, but I'm happy to help further if needed.
That's planned and desirable but I think it may need to wait until we change the |
…#7556, #5116 , #4076, #2749, #2268) currently: ImGui::SetNextWindowRefreshPolicy(ImGuiWindowRefreshFlags_TryToAvoidRefresh); - This is NOT meant to replace frame-wide/app-wide idle mode. - This is another tool: the idea that a given window could avoid refresh and reuse last frame contents. - I think it needs to be backed by a careful and smart design overall (refresh policy, load balancing, making it easy and obvious to user). - It's not there yet, this is currently a toy for experimenting. My other issues with this: - It appears to be very simple, but skipping most of Begin() logic will inevitably lead to tricky/confusing bugs. Let's see how it goes. - I don't like very much that this opens a door to varying inconsistencies - I don't like very much that it can lead us to situation where the lazy refresh gets disabled in bulk due to some reason (e.g. resizing a dock space) and we get sucked in the temptation to update for idle rather than update for dynamism.
I pushed an experiment: d449544 |
Thank you! I will play with it when I have the time. Does the refreshPolicy only apply to the window's drawlist, or entire content, e.g. buttons as well? |
Currently the idea is that when not refreshed Begin() returns false and you can’t submit items anyhow. So everything will look frozen. There are flag to eg always refresh when hovered etc and the key will be to improve this design. |
Looking good, though what I'd ideally want for my use case are two more things (which can both be easily substituted but would make for a more complete API): First is to be able to force an update for a specific window, since my code can notify the UI that it wants a UI update. Second is to more easily know if the window UI was updated last frame - though this one is trivial to implement on my own since it's equivalent to checking if Begin returns true. I'd personally also set this flag to false myself since I already call RenderDrawData more than I call NewFrame (for GL views that need constant updates). Thanks for the work on this front! |
Version/Branch of Dear ImGui:
Version: 1.75
Back-ends: imgui_impl_glfw.cpp
Operating System: Windows
My Issue/Question:
This may not be possible, and may not fit the immediate mode paradigm, but I'm still curious:
Can ImDrawLists be stored, and reused in a later Render() call?
XXX (please provide as much context as possible)
I want to do some cpu-intensive stuff that informs the drawing, that I wouldn't want to update every frame. I could create my own drawing command queue that only updates after user-input, and then add drawlist commands based on my queue on every ImGui call.
But then I thought, why the extra abstraction: the drawlist itself is a list of commands. Could a particular drawlist be stored and reused at a later time?
It tried the following, but it crashes:
Would this at all be possible?
Thanks in advance!
The text was updated successfully, but these errors were encountered: