-
Notifications
You must be signed in to change notification settings - Fork 352
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
Add callbacks to the draw_list. #702
Conversation
2869aaf
to
7c9cd5d
Compare
This looks good, thanks for the PR! Added a couple of minor notes on the doc strings - I also wonder, would it be much work to add a simple example to |
e5eab6a
to
7969d1b
Compare
Ah, examples are tricky because they are usually used to do random OpenGL stuff that happens to be quite specific. Indeed, even DearImGui does not provide any callback example, that I know of, it just comments about using it for a render-to-texture pass and so on... Anyway, I'm adding a commit with an example to the imgui-glow-renderer subdirectory that uses the callback to render a FramebufferObject, not so different from what I'm doing in my real project. I had to wrap the Feel free to suggest any other way to change that and still get access to the GL context from the callback. On a footnote, I'm quite sure that it is technically possible to get rid of that pesky |
Hey, @dbr could you check my latest commits to this PR? |
Oh sorry for missing this - I think the change to the renderer needed are fine I fixed up conflict, shall merge when CI is happy (I think it might fail due to unrelated changes of MSRV from an upstream library - shall fix that first in |
With the merge of the new @dbr: After the latest merges the git-log of this PR is a bit messy. I don't know the policy of this project, but if you like I can do a rebase/squash, before an eventual final merge? |
Ahh good, was worried I had botched something in the merge. Yep a rebase sounds like a good idea! |
It can be cloned and stored on drawing callbacks, for example.
Ok, I have just rebased this. I've split the |
Perfect, thanks! |
This PR adds the possibility to add callbacks to the draw_lists. Those were handled by the glow/glium backends, but we would have to add them using unsafe code and raw C callbacks.
Currently the callback must implement
FnOnce() + 'static
, that is the safest bet and enough for my needs.Once the callback is run, I'm setting it to NULL, even though it is a
const
C pointer to avoid the risk of calling it twice, although I think that is not really needed, because an imgui draw-list can only be called once. But just in case...Also, if the callback is added to the draw-list but then the draw-list is never run, the callback will leak, as DearImGui has no provision of a unused draw-list cleanup.