eframe: rename render_state
to wgpu_render_state
for added clarity
This commit is contained in:
parent
66c601f775
commit
9e41fa021a
6 changed files with 37 additions and 23 deletions
|
@ -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<std::sync::Arc<glow::Context>>,
|
||||
|
||||
/// 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<egui_wgpu::RenderState>,
|
||||
pub wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -510,10 +515,9 @@ pub struct Frame {
|
|||
#[cfg(feature = "glow")]
|
||||
pub(crate) gl: Option<std::sync::Arc<glow::Context>>,
|
||||
|
||||
/// 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<egui_wgpu::RenderState>,
|
||||
pub(crate) wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
}
|
||||
|
||||
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<glow::Context>> {
|
||||
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"))]
|
||||
|
|
|
@ -196,7 +196,7 @@ impl EpiIntegration {
|
|||
system_theme: Option<Theme>,
|
||||
storage: Option<Box<dyn epi::Storage>>,
|
||||
#[cfg(feature = "glow")] gl: Option<std::sync::Arc<glow::Context>>,
|
||||
#[cfg(feature = "wgpu")] render_state: Option<egui_wgpu::RenderState>,
|
||||
#[cfg(feature = "wgpu")] wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
) -> 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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<NeedRepaint> = Default::default();
|
||||
|
|
|
@ -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<wgpu::Device>,
|
||||
pub queue: Arc<wgpu::Queue>,
|
||||
pub target_format: TextureFormat,
|
||||
pub target_format: wgpu::TextureFormat,
|
||||
pub egui_rpass: Arc<RwLock<renderer::RenderPass>>,
|
||||
}
|
||||
|
||||
|
@ -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<RenderState> {
|
||||
pub fn render_state(&self) -> Option<RenderState> {
|
||||
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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue