diff --git a/eframe/src/epi.rs b/eframe/src/epi.rs index ab4ee0ef04b..950a94cb710 100644 --- a/eframe/src/epi.rs +++ b/eframe/src/epi.rs @@ -27,13 +27,18 @@ pub struct CreationContext<'s> { /// The [`glow::Context`] allows you to initialize OpenGL resources (e.g. shaders) that /// you might want to use later from a [`egui::PaintCallback`]. + /// + /// Only available when compiling with the `glow` feature and using [`Renderer::Glow`]. #[cfg(feature = "glow")] pub gl: Option>, - /// Can be used to manage GPU resources for custom rendering with WGPU using - /// [`egui::PaintCallback`]s. + /// The underlying WGPU render state. + /// + /// Only available when compiling with the `wgpu` feature and using [`Renderer::Wgpu`]. + /// + /// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s. #[cfg(feature = "wgpu")] - pub render_state: Option, + pub wgpu_render_state: Option, } // ---------------------------------------------------------------------------- @@ -510,10 +515,9 @@ pub struct Frame { #[cfg(feature = "glow")] pub(crate) gl: Option>, - /// Can be used to manage GPU resources for custom rendering with WGPU using - /// [`egui::PaintCallback`]s. + /// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s. #[cfg(feature = "wgpu")] - pub render_state: Option, + pub(crate) wgpu_render_state: Option, } impl Frame { @@ -551,12 +555,22 @@ impl Frame { /// ([`egui`] only collects [`egui::Shape`]s and then eframe paints them all in one go later on). /// /// To get a [`glow`] context you need to compile with the `glow` feature flag, - /// and run eframe with the glow backend. + /// and run eframe using [`Renderer::Glow`]. #[cfg(feature = "glow")] pub fn gl(&self) -> Option<&std::sync::Arc> { self.gl.as_ref() } + /// The underlying WGPU render state. + /// + /// Only available when compiling with the `wgpu` feature and using [`Renderer::Wgpu`]. + /// + /// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s. + #[cfg(feature = "wgpu")] + pub fn wgpu_render_state(&self) -> Option<&egui_wgpu::RenderState> { + self.wgpu_render_state.as_ref() + } + /// Signal the app to stop/exit/quit the app (only works for native apps, not web apps). /// The framework will not quit immediately, but at the end of the this frame. #[cfg(not(target_arch = "wasm32"))] diff --git a/eframe/src/native/epi_integration.rs b/eframe/src/native/epi_integration.rs index b2b7d7e266b..ee32f1b2af5 100644 --- a/eframe/src/native/epi_integration.rs +++ b/eframe/src/native/epi_integration.rs @@ -196,7 +196,7 @@ impl EpiIntegration { system_theme: Option, storage: Option>, #[cfg(feature = "glow")] gl: Option>, - #[cfg(feature = "wgpu")] render_state: Option, + #[cfg(feature = "wgpu")] wgpu_render_state: Option, ) -> Self { let egui_ctx = egui::Context::default(); @@ -214,7 +214,7 @@ impl EpiIntegration { #[cfg(feature = "glow")] gl, #[cfg(feature = "wgpu")] - render_state, + wgpu_render_state, }; let mut egui_winit = egui_winit::State::new(event_loop); diff --git a/eframe/src/native/run.rs b/eframe/src/native/run.rs index 0087aafa908..4bd36c4b52b 100644 --- a/eframe/src/native/run.rs +++ b/eframe/src/native/run.rs @@ -254,7 +254,7 @@ mod glow_integration { storage: integration.frame.storage(), gl: Some(gl.clone()), #[cfg(feature = "wgpu")] - render_state: None, + wgpu_render_state: None, }); if app.warm_up_enabled() { @@ -484,7 +484,7 @@ mod wgpu_integration { painter }; - let render_state = painter.get_render_state().expect("Uninitialized"); + let wgpu_render_state = painter.render_state().expect("Uninitialized"); let system_theme = native_options.system_theme(); let mut integration = epi_integration::EpiIntegration::new( @@ -495,7 +495,7 @@ mod wgpu_integration { storage, #[cfg(feature = "glow")] None, - Some(render_state.clone()), + Some(wgpu_render_state.clone()), ); let theme = system_theme.unwrap_or(native_options.default_theme); integration.egui_ctx.set_visuals(theme.egui_visuals()); @@ -513,7 +513,7 @@ mod wgpu_integration { storage: integration.frame.storage(), #[cfg(feature = "glow")] gl: None, - render_state: Some(render_state), + wgpu_render_state: Some(wgpu_render_state), }); if app.warm_up_enabled() { diff --git a/eframe/src/web/backend.rs b/eframe/src/web/backend.rs index 7c1a37a67cd..aed3a81d60d 100644 --- a/eframe/src/web/backend.rs +++ b/eframe/src/web/backend.rs @@ -219,7 +219,7 @@ impl AppRunner { #[cfg(feature = "glow")] gl: Some(painter.painter.gl().clone()), #[cfg(feature = "wgpu")] - render_state: None, + wgpu_render_state: None, }); let frame = epi::Frame { @@ -229,7 +229,7 @@ impl AppRunner { #[cfg(feature = "glow")] gl: Some(painter.gl().clone()), #[cfg(feature = "wgpu")] - render_state: None, + wgpu_render_state: None, }; let needs_repaint: std::sync::Arc = Default::default(); diff --git a/egui-wgpu/src/winit.rs b/egui-wgpu/src/winit.rs index 2b6c6d0239e..33518d89732 100644 --- a/egui-wgpu/src/winit.rs +++ b/egui-wgpu/src/winit.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use egui::mutex::RwLock; use tracing::error; -use wgpu::{Adapter, Instance, Surface, TextureFormat}; +use wgpu::{Adapter, Instance, Surface}; use crate::renderer; @@ -12,7 +12,7 @@ use crate::renderer; pub struct RenderState { pub device: Arc, pub queue: Arc, - pub target_format: TextureFormat, + pub target_format: wgpu::TextureFormat, pub egui_rpass: Arc>, } @@ -75,14 +75,14 @@ impl<'a> Painter<'a> { /// Get the [`RenderState`]. /// /// Will return [`None`] if the render state has not been initialized yet. - pub fn get_render_state(&self) -> Option { + pub fn render_state(&self) -> Option { self.render_state.as_ref().cloned() } async fn init_render_state( &self, adapter: &Adapter, - target_format: TextureFormat, + target_format: wgpu::TextureFormat, ) -> RenderState { let (device, queue) = pollster::block_on(adapter.request_device(&self.device_descriptor, None)).unwrap(); diff --git a/egui_demo_app/src/apps/custom3d_wgpu.rs b/egui_demo_app/src/apps/custom3d_wgpu.rs index d868a57be2a..1904da98b54 100644 --- a/egui_demo_app/src/apps/custom3d_wgpu.rs +++ b/egui_demo_app/src/apps/custom3d_wgpu.rs @@ -13,9 +13,9 @@ impl Custom3d { pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Self { // Get the WGPU render state from the eframe creation context. This can also be retrieved // from `eframe::Frame` when you don't have a `CreationContext` available. - let render_state = cc.render_state.as_ref().expect("WGPU enabled"); + let wgpu_render_state = cc.wgpu_render_state.as_ref().expect("WGPU enabled"); - let device = &render_state.device; + let device = &wgpu_render_state.device; let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, @@ -53,7 +53,7 @@ impl Custom3d { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[Some(render_state.target_format.into())], + targets: &[Some(wgpu_render_state.target_format.into())], }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, @@ -81,7 +81,7 @@ impl Custom3d { // Because the graphics pipeline must have the same lifetime as the egui render pass, // instead of storing the pipeline in our `Custom3D` struct, we insert it into the // `paint_callback_resources` type map, which is stored alongside the render pass. - render_state + wgpu_render_state .egui_rpass .write() .paint_callback_resources