Skip to content

Commit

Permalink
eframe: rename render_state to wgpu_render_state for added clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Aug 8, 2022
1 parent 66c601f commit 9e41fa0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
28 changes: 21 additions & 7 deletions eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))]
Expand Down
4 changes: 2 additions & 2 deletions eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(
Expand All @@ -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());
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions eframe/src/web/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions egui-wgpu/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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>>,
}

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions egui_demo_app/src/apps/custom3d_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e41fa0

Please sign in to comment.