1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 14:49:06 -04:00

Move depth/stencil options into RendererOptions

This commit is contained in:
Emil Ernerfeldt
2025-10-07 16:36:08 +02:00
parent e5c86a549d
commit 3511d07af2
4 changed files with 22 additions and 19 deletions

View File

@@ -186,14 +186,14 @@ impl<'app> WgpuWinitApp<'app> {
let mut painter = pollster::block_on(egui_wgpu::winit::Painter::new(
egui_ctx.clone(),
self.native_options.wgpu_options.clone(),
egui_wgpu::depth_format_from_bits(
self.native_options.depth_buffer,
self.native_options.stencil_buffer,
),
self.native_options.viewport.transparent.unwrap_or(false),
egui_wgpu::RendererOptions {
msaa_samples: self.native_options.multisampling.max(1) as _,
dithering: self.native_options.dithering,
depth_stencil_format: egui_wgpu::depth_format_from_bits(
self.native_options.depth_buffer,
self.native_options.stencil_buffer,
),
},
));

View File

@@ -173,7 +173,6 @@ impl RenderState {
config: &WgpuConfiguration,
instance: &wgpu::Instance,
compatible_surface: Option<&wgpu::Surface<'static>>,
depth_format: Option<wgpu::TextureFormat>,
options: RendererOptions,
) -> Result<Self, WgpuError> {
profiling::scope!("RenderState::create"); // async yield give bad names using `profile_function`
@@ -243,7 +242,7 @@ impl RenderState {
};
let target_format = crate::preferred_framebuffer_format(&surface_formats)?;
let renderer = Renderer::new(&device, target_format, depth_format, options);
let renderer = Renderer::new(&device, target_format, options);
// On wasm, depending on feature flags, wgpu objects may or may not implement sync.
// It doesn't make sense to switch to Rc for that special usecase, so simply disable the lint.

View File

@@ -198,6 +198,12 @@ pub struct RendererOptions {
///
/// Defaults to true.
pub dithering: bool,
/// What format to use for the depth and stencil buffers,
/// e.g. [`wgpu::TextureFormat::Depth32FloatStencil8`].
///
/// egui doesn't need depth/stencil, so the default value is `None` (no depth or stancil buffers).
pub depth_stencil_format: Option<wgpu::TextureFormat>,
}
impl Default for RendererOptions {
@@ -205,6 +211,7 @@ impl Default for RendererOptions {
Self {
msaa_samples: 0,
dithering: true,
depth_stencil_format: None,
}
}
}
@@ -244,7 +251,6 @@ impl Renderer {
pub fn new(
device: &wgpu::Device,
output_color_format: wgpu::TextureFormat,
output_depth_format: Option<wgpu::TextureFormat>,
options: RendererOptions,
) -> Self {
profiling::function_scope!();
@@ -332,13 +338,15 @@ impl Renderer {
push_constant_ranges: &[],
});
let depth_stencil = output_depth_format.map(|format| wgpu::DepthStencilState {
format,
depth_write_enabled: false,
depth_compare: wgpu::CompareFunction::Always,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
let depth_stencil = options
.depth_stencil_format
.map(|format| wgpu::DepthStencilState {
format,
depth_write_enabled: false,
depth_compare: wgpu::CompareFunction::Always,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
let pipeline = {
profiling::scope!("create_render_pipeline");

View File

@@ -26,7 +26,6 @@ pub struct Painter {
configuration: WgpuConfiguration,
options: RendererOptions,
support_transparent_backbuffer: bool,
depth_format: Option<wgpu::TextureFormat>,
screen_capture_state: Option<CaptureState>,
instance: wgpu::Instance,
@@ -56,7 +55,6 @@ impl Painter {
pub async fn new(
context: Context,
configuration: WgpuConfiguration,
depth_format: Option<wgpu::TextureFormat>,
support_transparent_backbuffer: bool,
options: RendererOptions,
) -> Self {
@@ -68,7 +66,6 @@ impl Painter {
configuration,
options,
support_transparent_backbuffer,
depth_format,
screen_capture_state: None,
instance,
@@ -204,7 +201,6 @@ impl Painter {
&self.configuration,
&self.instance,
Some(&surface),
self.depth_format,
self.options,
)
.await?;
@@ -278,7 +274,7 @@ impl Painter {
Self::configure_surface(surface_state, render_state, &self.configuration);
if let Some(depth_format) = self.depth_format {
if let Some(depth_format) = self.options.depth_stencil_format {
self.depth_texture_view.insert(
viewport_id,
render_state