mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Allows to override the default `PREDICTABLE` render options, e.g. if it's desired to create snapshots with the exact texture options used by the app. See #7630 for details / examples.
This commit is contained in:
@@ -18,6 +18,9 @@ pub struct HarnessBuilder<State = ()> {
|
|||||||
|
|
||||||
#[cfg(feature = "snapshot")]
|
#[cfg(feature = "snapshot")]
|
||||||
pub(crate) default_snapshot_options: crate::SnapshotOptions,
|
pub(crate) default_snapshot_options: crate::SnapshotOptions,
|
||||||
|
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
pub(crate) render_options: egui_wgpu::RendererOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<State> Default for HarnessBuilder<State> {
|
impl<State> Default for HarnessBuilder<State> {
|
||||||
@@ -35,6 +38,9 @@ impl<State> Default for HarnessBuilder<State> {
|
|||||||
|
|
||||||
#[cfg(feature = "snapshot")]
|
#[cfg(feature = "snapshot")]
|
||||||
default_snapshot_options: crate::SnapshotOptions::default(),
|
default_snapshot_options: crate::SnapshotOptions::default(),
|
||||||
|
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
render_options: egui_wgpu::RendererOptions::PREDICTABLE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +125,16 @@ impl<State> HarnessBuilder<State> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configures the [`egui_wgpu::RendererOptions`] used by this harness.
|
||||||
|
///
|
||||||
|
/// The default is [`egui_wgpu::RendererOptions::PREDICTABLE`].
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
#[inline]
|
||||||
|
pub fn with_render_options(mut self, options: egui_wgpu::RendererOptions) -> Self {
|
||||||
|
self.render_options = options;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the [`TestRenderer`] to use for rendering.
|
/// Set the [`TestRenderer`] to use for rendering.
|
||||||
///
|
///
|
||||||
/// By default, a [`LazyRenderer`] is used.
|
/// By default, a [`LazyRenderer`] is used.
|
||||||
@@ -133,7 +149,8 @@ impl<State> HarnessBuilder<State> {
|
|||||||
/// This sets up a [`crate::wgpu::WgpuTestRenderer`] with the default setup.
|
/// This sets up a [`crate::wgpu::WgpuTestRenderer`] with the default setup.
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
pub fn wgpu(self) -> Self {
|
pub fn wgpu(self) -> Self {
|
||||||
self.renderer(crate::wgpu::WgpuTestRenderer::default())
|
let test_renderer = crate::wgpu::WgpuTestRenderer::with_render_options(self.render_options);
|
||||||
|
self.renderer(test_renderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable wgpu rendering with the given setup.
|
/// Enable wgpu rendering with the given setup.
|
||||||
|
|||||||
@@ -116,6 +116,11 @@ impl<'a, State> Harness<'a, State> {
|
|||||||
|
|
||||||
#[cfg(feature = "snapshot")]
|
#[cfg(feature = "snapshot")]
|
||||||
default_snapshot_options,
|
default_snapshot_options,
|
||||||
|
|
||||||
|
// rustfmt adds this weird indentation below.
|
||||||
|
// See: https://github.com/rust-lang/rustfmt/issues/5920
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
render_options: _,
|
||||||
} = builder;
|
} = builder;
|
||||||
let ctx = ctx.unwrap_or_default();
|
let ctx = ctx.unwrap_or_default();
|
||||||
ctx.set_theme(theme);
|
ctx.set_theme(theme);
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ pub fn default_wgpu_setup() -> egui_wgpu::WgpuSetup {
|
|||||||
egui_wgpu::WgpuSetup::CreateNew(setup)
|
egui_wgpu::WgpuSetup::CreateNew(setup)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_render_state(setup: WgpuSetup) -> egui_wgpu::RenderState {
|
pub fn create_render_state(
|
||||||
|
setup: WgpuSetup,
|
||||||
|
options: egui_wgpu::RendererOptions,
|
||||||
|
) -> egui_wgpu::RenderState {
|
||||||
// No display handle needed for headless testing — we don't present to a window.
|
// No display handle needed for headless testing — we don't present to a window.
|
||||||
let instance = pollster::block_on(setup.new_instance());
|
let instance = pollster::block_on(setup.new_instance());
|
||||||
|
|
||||||
@@ -69,7 +72,7 @@ pub fn create_render_state(setup: WgpuSetup) -> egui_wgpu::RenderState {
|
|||||||
},
|
},
|
||||||
&instance,
|
&instance,
|
||||||
None,
|
None,
|
||||||
egui_wgpu::RendererOptions::PREDICTABLE,
|
options,
|
||||||
))
|
))
|
||||||
.expect("Failed to create render state")
|
.expect("Failed to create render state")
|
||||||
}
|
}
|
||||||
@@ -89,14 +92,17 @@ impl WgpuTestRenderer {
|
|||||||
/// Create a new [`WgpuTestRenderer`] with the default setup.
|
/// Create a new [`WgpuTestRenderer`] with the default setup.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
render_state: create_render_state(default_wgpu_setup()),
|
render_state: create_render_state(
|
||||||
|
default_wgpu_setup(),
|
||||||
|
egui_wgpu::RendererOptions::PREDICTABLE,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new [`WgpuTestRenderer`] with the given setup.
|
/// Create a new [`WgpuTestRenderer`] with the given setup.
|
||||||
pub fn from_setup(setup: WgpuSetup) -> Self {
|
pub fn from_setup(setup: WgpuSetup) -> Self {
|
||||||
Self {
|
Self {
|
||||||
render_state: create_render_state(setup),
|
render_state: create_render_state(setup, egui_wgpu::RendererOptions::PREDICTABLE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +121,13 @@ impl WgpuTestRenderer {
|
|||||||
);
|
);
|
||||||
Self { render_state }
|
Self { render_state }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new [`WgpuTestRenderer`] with custom render options.
|
||||||
|
pub fn with_render_options(options: egui_wgpu::RendererOptions) -> Self {
|
||||||
|
Self {
|
||||||
|
render_state: create_render_state(default_wgpu_setup(), options),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::TestRenderer for WgpuTestRenderer {
|
impl crate::TestRenderer for WgpuTestRenderer {
|
||||||
|
|||||||
Reference in New Issue
Block a user