diff --git a/crates/egui_demo_lib/src/demo/demo_app_windows.rs b/crates/egui_demo_lib/src/demo/demo_app_windows.rs index 929aec7b1b7..6a6becd599d 100644 --- a/crates/egui_demo_lib/src/demo/demo_app_windows.rs +++ b/crates/egui_demo_lib/src/demo/demo_app_windows.rs @@ -383,8 +383,6 @@ mod tests { use crate::demo::demo_app_windows::Demos; use egui::Vec2; use egui_kittest::kittest::Queryable; - use egui_kittest::try_image_snapshot; - use egui_kittest::wgpu::TestRenderer; use egui_kittest::Harness; #[test] @@ -409,10 +407,6 @@ mod tests { demo.show(ctx, &mut true); }); - // We need to run the app for multiple frames before all windows have the right size - harness.run(); - harness.run(); - let window = harness.node().children().next().unwrap(); // TODO(lucasmerlin): Windows should probably have a label? //let window = harness.get_by_name(name); @@ -420,12 +414,10 @@ mod tests { let size = window.raw_bounds().expect("window bounds").size(); harness.set_size(Vec2::new(size.width as f32, size.height as f32)); - // We need to run the app for some more frames... - harness.run(); + // Run the app for some more frames... harness.run(); - let image = TestRenderer::new().render(&harness); - let result = try_image_snapshot(&image, &format!("demos/{name}")); + let result = harness.try_wgpu_snapshot(&format!("demos/{name}")); if let Err(err) = result { errors.push(err); } diff --git a/crates/egui_demo_lib/src/demo/widget_gallery.rs b/crates/egui_demo_lib/src/demo/widget_gallery.rs index e8851a34c02..60c9bccf0a9 100644 --- a/crates/egui_demo_lib/src/demo/widget_gallery.rs +++ b/crates/egui_demo_lib/src/demo/widget_gallery.rs @@ -291,8 +291,6 @@ mod tests { use super::*; use crate::View; use egui::{CentralPanel, Context, Vec2}; - use egui_kittest::image_snapshot; - use egui_kittest::wgpu::TestRenderer; use egui_kittest::Harness; #[test] @@ -307,16 +305,11 @@ mod tests { demo.ui(ui); }); }; - let mut harness = Harness::builder() + let harness = Harness::builder() .with_size(Vec2::new(380.0, 550.0)) .with_dpi(2.0) .build(app); - // The first and second frames are slightly different, so we take the second frame - harness.run(); - - let image = TestRenderer::new().render(&harness); - - image_snapshot(&image, "widget_gallery"); + harness.wgpu_snapshot("widget_gallery"); } } diff --git "a/crates/egui_demo_lib/tests/snapshots/demos/B\303\251zier Curve.png" "b/crates/egui_demo_lib/tests/snapshots/demos/B\303\251zier Curve.png" index 34125f1bdad..ad7d9becfaa 100644 --- "a/crates/egui_demo_lib/tests/snapshots/demos/B\303\251zier Curve.png" +++ "b/crates/egui_demo_lib/tests/snapshots/demos/B\303\251zier Curve.png" @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:56ae71faf0786aedc9d78c8bfe822c1a138085f31c477a8117e4906189c66cdd -size 153413 +oid sha256:4a725aa81433f301fda4ff8a28be869366332964995d1ae4ed996591596eb7e2 +size 31461 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Code Editor.png b/crates/egui_demo_lib/tests/snapshots/demos/Code Editor.png index a472ee0ded8..252c7c8f205 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Code Editor.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Code Editor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4116ee3996fab18e591e8f82023f9a3aa6c7c8f4081cf33b34596f952f637e4c -size 88807 +oid sha256:36028d85f49ee77562250214237def2b676ecc9ed413d2fd8afc473d61289ca1 +size 32761 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png b/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png index 0c43a9e95ef..093b2c6a33b 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7ce3216aa8082c797b59ebd245a519ec3c3ec405c3952650dc8a5a8c7458915d -size 97977 +oid sha256:b8d4f004ee11ea68ae0f30657601b6e51403fcc3ca91fa5b8cdcb58585d8d40d +size 78318 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Context Menus.png b/crates/egui_demo_lib/tests/snapshots/demos/Context Menus.png index 43dafee1cbf..c29267377b7 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Context Menus.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Context Menus.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:00d208432d86f03f9c3be94f4abf3810e8de367bedd13926f04f8e3762ed4f98 -size 25357 +oid sha256:684648bea4ef5ce138fc25dbe7576e3937a797e87f2244cb3656ff8b4c2777f5 +size 11574 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Dancing Strings.png b/crates/egui_demo_lib/tests/snapshots/demos/Dancing Strings.png index 048bbdcfe4c..bdc4739c77f 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Dancing Strings.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Dancing Strings.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d6dad3634f4792d04351e2146e17f6aec3736d2ca11a6d3f524acba501114fe0 -size 144784 +oid sha256:ad38bff7cc5661be43e730e1b34c444b571b24b9f50791209496a1687610dd3d +size 20543 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Drag and Drop.png b/crates/egui_demo_lib/tests/snapshots/demos/Drag and Drop.png index dd0007e498c..035d4c13f7b 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Drag and Drop.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Drag and Drop.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3ea0cad20d1e27e1a8119b72ae1e518b1f20c3a751502ff1fe98dd2d3187e6cd -size 57699 +oid sha256:ff78748f2571c49638d8fe8fdc859aaa5181758aad65498b7217551350fb9138 +size 20672 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Extra Viewport.png b/crates/egui_demo_lib/tests/snapshots/demos/Extra Viewport.png index 69f7165ce92..2d48a7e085f 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Extra Viewport.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Extra Viewport.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9e55adec917b41d56ea98122c8274e7430dfe3cc4b0faecd75c36cea88c97250 -size 20522 +oid sha256:9dee66004cc47f5e27aaac34d137ff005eedf70cbfa3fbe43153dfd5c09d5e18 +size 10610 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Font Book.png b/crates/egui_demo_lib/tests/snapshots/demos/Font Book.png index d253b2c3d8c..69201f86154 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Font Book.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Font Book.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f33c094b90b4eef4bc9622d1e871c3943c557be9393ace007624ec895fb5d04b -size 153464 +oid sha256:0d1086b789f1fe0a8085c86f5b6a5ae7ecb53020f385b84775d6812ebc9d74a3 +size 132349 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Frame.png b/crates/egui_demo_lib/tests/snapshots/demos/Frame.png index f958a9ad942..ff4d08bafe8 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Frame.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Frame.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1990cddcfddec74973689b45aa4bb6d10e2ab4e45c70da03f7f5daef24f34b73 -size 52093 +oid sha256:08be378c01e376aab6e99ba3158519bbd7b301e815dc3447b57c9abab558977f +size 24237 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Highlighting.png b/crates/egui_demo_lib/tests/snapshots/demos/Highlighting.png index ea24aca8e58..a3cab2a3097 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Highlighting.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Highlighting.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ca14bb1c6a95fd12d15442af9e9526d1afff224f4d16afee1d9ee0001a389154 -size 31294 +oid sha256:53097b2c26ebcba8b8ad657ed8e52ca40261155e96dbbfca1e8eb01fce25d290 +size 17586 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Interactive Container.png b/crates/egui_demo_lib/tests/snapshots/demos/Interactive Container.png index 9983bc4a5f8..2bfbf20f91e 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Interactive Container.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Interactive Container.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:227a4b4acfe2f1eced25853268919e4e186277a44d4770be4940fcdbb28089e4 -size 36986 +oid sha256:d9c8395e6b4287b92d85a52ca2d47750f67abeb0ad88c6b42264bfe2e62fd09d +size 22283 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png b/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png index 7d90397e41d..80cb5b5a177 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a16afc76a9330b815d90c9b1d90b0f1672c6788d4bad35d5ced024d2e33b439 -size 75910 +oid sha256:38d21b6f8c364f86ad759e88ea1068649c23c58ded5d2953ba8ff1c83b46112f +size 63884 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Multi Touch.png b/crates/egui_demo_lib/tests/snapshots/demos/Multi Touch.png index bdb5081196e..23bad456c8c 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Multi Touch.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Multi Touch.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3f9f1ef4f040bf66123ac1a4ab0c324cf77acfa9d75ac6f30409d50ade48db8e -size 324417 +oid sha256:83162f8c496a55230375dbc4cc636cfacf63049c913904bea9d06bdb56e63da6 +size 36282 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Painting.png b/crates/egui_demo_lib/tests/snapshots/demos/Painting.png index 3fba3df87fd..89a17e67406 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Painting.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Painting.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0765fe7c99045c712ca61ff9041ad52d35a72e2a10906cb53c8ee2e1616345ce -size 323299 +oid sha256:2537c681d1ffceb5cf4bf19d11295891525c96aea0b1422ab28f133021185be0 +size 17451 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Pan Zoom.png b/crates/egui_demo_lib/tests/snapshots/demos/Pan Zoom.png index ab70a0ca0a1..7ba225feae8 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Pan Zoom.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Pan Zoom.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d0f2cb342d0d362cebd55efa2597379b54ebf30409139bfd1dfe50e9e01e086 -size 39949 +oid sha256:79ce1dbf7627579d4e10de6494e34d8fd9685506d7b35cb3c9148f90f8c01366 +size 25144 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Panels.png b/crates/egui_demo_lib/tests/snapshots/demos/Panels.png index 4b8649140d3..585c126360c 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Panels.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Panels.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d620ae7b39e45eb2a8dbd983de981a3bb01c17c779794d1d7f7a664e5d01859b -size 457277 +oid sha256:5068df8549ffc91028addfec6f851f12a4de80e208b50b39e4d44b6aa2c7240e +size 261946 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Scrolling.png b/crates/egui_demo_lib/tests/snapshots/demos/Scrolling.png index cd0098fb6aa..440a51f3871 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Scrolling.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Scrolling.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65f868023382bae61ad9ce34ec0ef5d666e1d1058e72a406f917ebd12bd6e64a -size 210361 +oid sha256:be2ac005fd5aafa293e21b162c22a09078e46d2d45b6208ce0f7841eeb05314a +size 183934 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Sliders.png b/crates/egui_demo_lib/tests/snapshots/demos/Sliders.png index 4bd15045151..e3a213176e9 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Sliders.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Sliders.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1b48c83f6a0ed1eff52711b294f4a40f1b4b5f9b2738a29b4de37a3f748070c4 -size 138886 +oid sha256:2e3436906f7ac459b7f4330a286937722e78ad885ae1e90f75be566e970a8ca7 +size 116899 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Strip.png b/crates/egui_demo_lib/tests/snapshots/demos/Strip.png index 1bc42553c70..69ec9e88230 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Strip.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Strip.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e952386e6fcf854976ddc4fe66abd51d2f2cb2d7365c3dbdf4f8ad9a987d075 -size 123440 +oid sha256:df7dabf726620ab5205ce153f692d1ba02365848ead7b79c95b873d5121d52a6 +size 25850 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Table.png b/crates/egui_demo_lib/tests/snapshots/demos/Table.png index 71f81cc331c..9f3618ba039 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Table.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Table.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fea321e004352fd52c34ed9231fa41a37467665239ac57b20175d33252b91abb -size 95610 +oid sha256:ae6c2e3aad43cfad3322340ff7045ec50ba01d58feb7b8acc5ba062a8a5c9ab8 +size 70230 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Text Layout.png b/crates/egui_demo_lib/tests/snapshots/demos/Text Layout.png index 25d5e6eaac7..ff972ae484c 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Text Layout.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Text Layout.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a7f649fea4527922b2e2ebe60e5935c9b5c1e53f5a6006e96cad74baccbc5fb5 -size 83406 +oid sha256:ec0c2efff75cb8d621f5a4ea59f9fa8d3076521ca34f4499e07fb9dc8681d7ba +size 65916 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/TextEdit.png b/crates/egui_demo_lib/tests/snapshots/demos/TextEdit.png index ceeb5082b3d..7af3611b924 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/TextEdit.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/TextEdit.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7bd317d11a0f7e7b548736b93e24f421d18061394f1dcacfa0ab2774551109b7 -size 53625 +oid sha256:c04aee0a3a77a3691bb601a93871117500be917e0896138fda43251454ec04c2 +size 20988 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Tooltips.png b/crates/egui_demo_lib/tests/snapshots/demos/Tooltips.png index bda5aad0673..4e7d8a9230b 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Tooltips.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Tooltips.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:abbe31223ca2f34d608cfd27af6ebfe4eedcd05724481c514cfbcab767838834 -size 196557 +oid sha256:814d863deaa4fa029044da1783db87744f0d82e874edd6cbab16e712ed8715aa +size 59881 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Undo Redo.png b/crates/egui_demo_lib/tests/snapshots/demos/Undo Redo.png index c441c93d104..a635cdfabd0 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Undo Redo.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Undo Redo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:96f65efbb8a5a4a33454a7bf5f2a679cce078df9405c18207dddbcaace5a7553 -size 31041 +oid sha256:e682f5cb9ecb1bdf89281c2ba1612078e70e97f28c76facc64d717e4015ced6a +size 12977 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Window Options.png b/crates/egui_demo_lib/tests/snapshots/demos/Window Options.png index 83ac40c476c..f28774030aa 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Window Options.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Window Options.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eeac86f381618379f57a702a7db47a4a6915885b4acea13b87457b2c6d2d2981 -size 59516 +oid sha256:15acfb041cc53ef9bd966d6edd53a6b692cdb645ae5cf34bc20e70d403371c30 +size 34809 diff --git a/crates/egui_demo_lib/tests/snapshots/widget_gallery.png b/crates/egui_demo_lib/tests/snapshots/widget_gallery.png index 9c46e244fdf..273b85a6303 100644 --- a/crates/egui_demo_lib/tests/snapshots/widget_gallery.png +++ b/crates/egui_demo_lib/tests/snapshots/widget_gallery.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7752724def1a0f7e72c6b058c196c0d2d6b3ee05fe78761d105e69cf5200dc2a -size 177261 +oid sha256:5dc632962f8894c4f20a48c9b9e57d60470f3f83ef7f19d05854dba718610a2f +size 161820 diff --git a/crates/egui_kittest/README.md b/crates/egui_kittest/README.md index 78b46b662f6..86ccf551506 100644 --- a/crates/egui_kittest/README.md +++ b/crates/egui_kittest/README.md @@ -30,6 +30,6 @@ fn main() { // You can even render the ui and do image snapshot tests #[cfg(all(feature = "wgpu", feature = "snapshot"))] - egui_kittest::image_snapshot(&egui_kittest::wgpu::TestRenderer::new().render(&harness), "readme_example"); + harness.wgpu_snapshot("readme_example"); } ``` diff --git a/crates/egui_kittest/src/snapshot.rs b/crates/egui_kittest/src/snapshot.rs index 679927f9983..62b5b6ba8e8 100644 --- a/crates/egui_kittest/src/snapshot.rs +++ b/crates/egui_kittest/src/snapshot.rs @@ -1,3 +1,4 @@ +use crate::Harness; use image::ImageError; use std::fmt::Display; use std::io::ErrorKind; @@ -74,7 +75,8 @@ impl Display for SnapshotError { /// Image snapshot test. /// /// # Errors -/// Returns a [`SnapshotError`] if the image does not match the snapshot. +/// Returns a [`SnapshotError`] if the image does not match the snapshot or if there was an error +/// reading or writing the snapshot. pub fn try_image_snapshot(current: &image::RgbaImage, name: &str) -> Result<(), SnapshotError> { let snapshots_path = Path::new("tests/snapshots"); @@ -163,7 +165,8 @@ fn maybe_update_snapshot( /// Image snapshot test. /// /// # Panics -/// Panics if the image does not match the snapshot. +/// Panics if the image does not match the snapshot or if there was an error reading or writing the +/// snapshot. #[track_caller] pub fn image_snapshot(current: &image::RgbaImage, name: &str) { match try_image_snapshot(current, name) { @@ -173,3 +176,32 @@ pub fn image_snapshot(current: &image::RgbaImage, name: &str) { } } } + +#[cfg(feature = "wgpu")] +impl Harness<'_> { + /// Render a image using a default [`crate::wgpu::TestRenderer`] and compare it to the snapshot. + /// + /// # Errors + /// Returns a [`SnapshotError`] if the image does not match the snapshot or if there was an error + /// reading or writing the snapshot. + #[track_caller] + pub fn try_wgpu_snapshot(&self, name: &str) -> Result<(), SnapshotError> { + let image = crate::wgpu::TestRenderer::new().render(self); + try_image_snapshot(&image, name) + } + + /// Render a image using a default [`crate::wgpu::TestRenderer`] and compare it to the snapshot. + /// + /// # Panics + /// Panics if the image does not match the snapshot or if there was an error reading or writing the + /// snapshot. + #[track_caller] + pub fn wgpu_snapshot(&self, name: &str) { + match self.try_wgpu_snapshot(name) { + Ok(_) => {} + Err(err) => { + panic!("{}", err); + } + } + } +} diff --git a/crates/egui_kittest/src/wgpu.rs b/crates/egui_kittest/src/wgpu.rs index b6085aae815..e6a4c419379 100644 --- a/crates/egui_kittest/src/wgpu.rs +++ b/crates/egui_kittest/src/wgpu.rs @@ -7,9 +7,9 @@ use std::iter::once; use wgpu::Maintain; pub struct TestRenderer { - renderer: egui_wgpu::Renderer, device: wgpu::Device, queue: wgpu::Queue, + dithering: bool, } impl Default for TestRenderer { @@ -36,20 +36,34 @@ impl TestRenderer { )) .expect("Failed to create device"); - let renderer = egui_wgpu::Renderer::new(&device, TextureFormat::Rgba8Unorm, None, 1, true); + Self::create(device, queue) + } + pub fn create(device: wgpu::Device, queue: wgpu::Queue) -> Self { Self { - renderer, device, queue, + dithering: false, } } + pub fn with_dithering(mut self, dithering: bool) -> Self { + self.dithering = dithering; + self + } + pub fn render(&mut self, harness: &Harness<'_>) -> RgbaImage { + let mut renderer = egui_wgpu::Renderer::new( + &self.device, + TextureFormat::Rgba8Unorm, + None, + 1, + self.dithering, + ); + for delta in &harness.texture_deltas { for (id, image_delta) in &delta.set { - self.renderer - .update_texture(&self.device, &self.queue, *id, image_delta); + renderer.update_texture(&self.device, &self.queue, *id, image_delta); } } @@ -70,7 +84,7 @@ impl TestRenderer { harness.ctx.pixels_per_point(), ); - let user_buffers = self.renderer.update_buffers( + let user_buffers = renderer.update_buffers( &self.device, &self.queue, &mut encoder, @@ -113,7 +127,7 @@ impl TestRenderer { }) .forget_lifetime(); - self.renderer.render(&mut pass, &tessellated, &screen); + renderer.render(&mut pass, &tessellated, &screen); } self.queue