-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Shape::Callback to do custom rendering inside of an egui UI #1351
Conversation
e6b357a
to
81a06fe
Compare
glow::Context doesn't need to be mutable. so, a simple one question i have is whether the user will be able to access the textures loaded into egui already? I would assume they don't want to duplicate textures in their app used both by egui::Image as well as their own custom rendering code, so reusing the textures from egui's tex manager would be cool. |
81a06fe
to
07a8991
Compare
Great question! My initial thinking was that a user would either want to either manage their textures manually OR ask egui to do so, but not both. But I guess we could pass the full |
07a8991
to
f661ac1
Compare
if we able to redirecting to Texture would save energy. in this case pass Painter to user would better. |
37227eb
to
a913449
Compare
There - now the callback code has access to |
39e2c7d
to
8c2ec55
Compare
44ba3c7
to
bff72bf
Compare
I think this is a decent start. Future work: Make |
This adds a new shape
Shape::Callback
which can be used to inline custom rendering code inside an egui UI. The callback will be given the underlying rendering context, and will therefore be integration specific. When usingeframe
, it will beglow::Context
(unless one opts in to the glium or WebGL backends).This means you can paint anything anywhere, including behind or on top of other egui windows and with transparency. Previously this was only possible by first rendering to a texture and then displaying that texture using
egui::TextureId
.The design is very similar to Dear ImGui's
AddCallback/UserCallback
.Closes #1198
Unresolved issues
One unresolved issue is where to free any resources (shaders, buffer, textures, …) allocated by the custom painting callback. Perhaps we could pass a
Rc<Cell<glow::Context>>
and let the user clone it and destroy the resources onDrop
?