1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Improve egui_kittest documentation and update CONTRIBUTING.md (#5296)

This should hopefully make it easier for egui contributors and
egui_kittest users to understand the snapshot tests


* [X] I have followed the instructions in the PR template
This commit is contained in:
lucasmerlin
2024-10-23 08:54:43 +02:00
committed by GitHub
parent 70a01138b7
commit 67a54ec5ce
5 changed files with 45 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ use image::RgbaImage;
use std::iter::once;
use wgpu::Maintain;
/// Utility to render snapshots from a [`Harness`] using [`egui_wgpu`].
pub struct TestRenderer {
device: wgpu::Device,
queue: wgpu::Queue,
@@ -19,6 +20,7 @@ impl Default for TestRenderer {
}
impl TestRenderer {
/// Create a new [`TestRenderer`] using a default [`wgpu::Instance`].
pub fn new() -> Self {
let instance = wgpu::Instance::new(InstanceDescriptor::default());
@@ -39,6 +41,7 @@ impl TestRenderer {
Self::create(device, queue)
}
/// Create a new [`TestRenderer`] using the provided [`wgpu::Device`] and [`wgpu::Queue`].
pub fn create(device: wgpu::Device, queue: wgpu::Queue) -> Self {
Self {
device,
@@ -47,13 +50,20 @@ impl TestRenderer {
}
}
/// Enable or disable dithering.
///
/// Disabled by default.
#[inline]
pub fn with_dithering(mut self, dithering: bool) -> Self {
self.dithering = dithering;
self
}
/// Render the [`Harness`] and return the resulting image.
pub fn render(&mut self, harness: &Harness<'_>) -> RgbaImage {
// We need to create a new renderer each time we render, since the renderer stores
// textures related to the Harnesses' egui Context.
// Calling the renderer from different Harnesses would cause problems if we store the renderer.
let mut renderer = egui_wgpu::Renderer::new(
&self.device,
TextureFormat::Rgba8Unorm,