mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Add register_native_texture in eframe::Frame (#4246)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> * Closes https://github.com/emilk/egui/issues/4243 --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -614,6 +614,11 @@ pub struct Frame {
|
||||
#[cfg(feature = "glow")]
|
||||
pub(crate) gl: Option<std::sync::Arc<glow::Context>>,
|
||||
|
||||
/// Used to convert user custom [`glow::Texture`] to [`egui::TextureId`]
|
||||
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
|
||||
pub(crate) glow_register_native_texture:
|
||||
Option<Box<dyn FnMut(glow::Texture) -> egui::TextureId>>,
|
||||
|
||||
/// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s.
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub(crate) wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
@@ -690,6 +695,15 @@ impl Frame {
|
||||
self.gl.as_ref()
|
||||
}
|
||||
|
||||
/// Register your own [`glow::Texture`],
|
||||
/// and then you can use the returned [`egui::TextureId`] to render your texture with [`egui`].
|
||||
///
|
||||
/// This function will take the ownership of your [`glow::Texture`], so please do not delete your [`glow::Texture`] after registering.
|
||||
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
|
||||
pub fn register_native_glow_texture(&mut self, native: glow::Texture) -> egui::TextureId {
|
||||
self.glow_register_native_texture.as_mut().unwrap()(native)
|
||||
}
|
||||
|
||||
/// The underlying WGPU render state.
|
||||
///
|
||||
/// Only available when compiling with the `wgpu` feature and using [`Renderer::Wgpu`].
|
||||
|
||||
Reference in New Issue
Block a user