mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Move depth/stencil options into RendererOptions
This commit is contained in:
@@ -186,14 +186,14 @@ impl<'app> WgpuWinitApp<'app> {
|
|||||||
let mut painter = pollster::block_on(egui_wgpu::winit::Painter::new(
|
let mut painter = pollster::block_on(egui_wgpu::winit::Painter::new(
|
||||||
egui_ctx.clone(),
|
egui_ctx.clone(),
|
||||||
self.native_options.wgpu_options.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),
|
self.native_options.viewport.transparent.unwrap_or(false),
|
||||||
egui_wgpu::RendererOptions {
|
egui_wgpu::RendererOptions {
|
||||||
msaa_samples: self.native_options.multisampling.max(1) as _,
|
msaa_samples: self.native_options.multisampling.max(1) as _,
|
||||||
dithering: self.native_options.dithering,
|
dithering: self.native_options.dithering,
|
||||||
|
depth_stencil_format: egui_wgpu::depth_format_from_bits(
|
||||||
|
self.native_options.depth_buffer,
|
||||||
|
self.native_options.stencil_buffer,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ impl RenderState {
|
|||||||
config: &WgpuConfiguration,
|
config: &WgpuConfiguration,
|
||||||
instance: &wgpu::Instance,
|
instance: &wgpu::Instance,
|
||||||
compatible_surface: Option<&wgpu::Surface<'static>>,
|
compatible_surface: Option<&wgpu::Surface<'static>>,
|
||||||
depth_format: Option<wgpu::TextureFormat>,
|
|
||||||
options: RendererOptions,
|
options: RendererOptions,
|
||||||
) -> Result<Self, WgpuError> {
|
) -> Result<Self, WgpuError> {
|
||||||
profiling::scope!("RenderState::create"); // async yield give bad names using `profile_function`
|
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 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.
|
// 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.
|
// It doesn't make sense to switch to Rc for that special usecase, so simply disable the lint.
|
||||||
|
|||||||
@@ -198,6 +198,12 @@ pub struct RendererOptions {
|
|||||||
///
|
///
|
||||||
/// Defaults to true.
|
/// Defaults to true.
|
||||||
pub dithering: bool,
|
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 {
|
impl Default for RendererOptions {
|
||||||
@@ -205,6 +211,7 @@ impl Default for RendererOptions {
|
|||||||
Self {
|
Self {
|
||||||
msaa_samples: 0,
|
msaa_samples: 0,
|
||||||
dithering: true,
|
dithering: true,
|
||||||
|
depth_stencil_format: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,7 +251,6 @@ impl Renderer {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
output_color_format: wgpu::TextureFormat,
|
output_color_format: wgpu::TextureFormat,
|
||||||
output_depth_format: Option<wgpu::TextureFormat>,
|
|
||||||
options: RendererOptions,
|
options: RendererOptions,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
profiling::function_scope!();
|
profiling::function_scope!();
|
||||||
@@ -332,13 +338,15 @@ impl Renderer {
|
|||||||
push_constant_ranges: &[],
|
push_constant_ranges: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
let depth_stencil = output_depth_format.map(|format| wgpu::DepthStencilState {
|
let depth_stencil = options
|
||||||
format,
|
.depth_stencil_format
|
||||||
depth_write_enabled: false,
|
.map(|format| wgpu::DepthStencilState {
|
||||||
depth_compare: wgpu::CompareFunction::Always,
|
format,
|
||||||
stencil: wgpu::StencilState::default(),
|
depth_write_enabled: false,
|
||||||
bias: wgpu::DepthBiasState::default(),
|
depth_compare: wgpu::CompareFunction::Always,
|
||||||
});
|
stencil: wgpu::StencilState::default(),
|
||||||
|
bias: wgpu::DepthBiasState::default(),
|
||||||
|
});
|
||||||
|
|
||||||
let pipeline = {
|
let pipeline = {
|
||||||
profiling::scope!("create_render_pipeline");
|
profiling::scope!("create_render_pipeline");
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ pub struct Painter {
|
|||||||
configuration: WgpuConfiguration,
|
configuration: WgpuConfiguration,
|
||||||
options: RendererOptions,
|
options: RendererOptions,
|
||||||
support_transparent_backbuffer: bool,
|
support_transparent_backbuffer: bool,
|
||||||
depth_format: Option<wgpu::TextureFormat>,
|
|
||||||
screen_capture_state: Option<CaptureState>,
|
screen_capture_state: Option<CaptureState>,
|
||||||
|
|
||||||
instance: wgpu::Instance,
|
instance: wgpu::Instance,
|
||||||
@@ -56,7 +55,6 @@ impl Painter {
|
|||||||
pub async fn new(
|
pub async fn new(
|
||||||
context: Context,
|
context: Context,
|
||||||
configuration: WgpuConfiguration,
|
configuration: WgpuConfiguration,
|
||||||
depth_format: Option<wgpu::TextureFormat>,
|
|
||||||
support_transparent_backbuffer: bool,
|
support_transparent_backbuffer: bool,
|
||||||
options: RendererOptions,
|
options: RendererOptions,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -68,7 +66,6 @@ impl Painter {
|
|||||||
configuration,
|
configuration,
|
||||||
options,
|
options,
|
||||||
support_transparent_backbuffer,
|
support_transparent_backbuffer,
|
||||||
depth_format,
|
|
||||||
screen_capture_state: None,
|
screen_capture_state: None,
|
||||||
|
|
||||||
instance,
|
instance,
|
||||||
@@ -204,7 +201,6 @@ impl Painter {
|
|||||||
&self.configuration,
|
&self.configuration,
|
||||||
&self.instance,
|
&self.instance,
|
||||||
Some(&surface),
|
Some(&surface),
|
||||||
self.depth_format,
|
|
||||||
self.options,
|
self.options,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -278,7 +274,7 @@ impl Painter {
|
|||||||
|
|
||||||
Self::configure_surface(surface_state, render_state, &self.configuration);
|
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(
|
self.depth_texture_view.insert(
|
||||||
viewport_id,
|
viewport_id,
|
||||||
render_state
|
render_state
|
||||||
|
|||||||
Reference in New Issue
Block a user