-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Harness::new_eframe
and TestRenderer
trait
#5539
base: master
Are you sure you want to change the base?
Conversation
8746345
to
77ce48b
Compare
Preview available at https://egui-pr-preview.github.io/pr/5539-lucaskittest-eframe-app |
8f5f0ec
to
8eee137
Compare
Tests should pass once #5542 is merged and this is rebased |
Harness::new_eframe
Harness::new_eframe
and TestRenderer
trait
surface.map_or_else( | ||
|| vec![TextureFormat::Rgba8Unorm], | ||
|s| s.get_capabilities(&adapter).formats, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the best fallback, or if there are some other capabilities I should query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just works! ✨
/// In order to access the [`eframe::App`] trait from the generic `State`, we store a function pointer | ||
/// here that will return the dyn trait from the struct. In the builder we have the correct where | ||
/// clause to be able to create this. | ||
/// Later we can use it anywhere to get the [`eframe::App`] from the `State`. | ||
#[cfg(feature = "eframe")] | ||
type AppKindEframe<'a, State> = (fn(&mut State) -> &mut dyn eframe::App, eframe::Frame); | ||
|
||
pub(crate) enum AppKind<'a, State> { | ||
Context(AppKindContext<'a>), | ||
Ui(AppKindUi<'a>), | ||
ContextState(AppKindContextState<'a, State>), | ||
UiState(AppKindUiState<'a, State>), | ||
#[cfg(feature = "eframe")] | ||
Eframe(AppKindEframe<'a, State>), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to be able to store the eframe::App
in the State, so it would be accessible via the already existing Harness::state_mut
fns, but I needed some way to access the State as a eframe::App when updating.
I think my solution with the function pointer is really cool, but maybe there is a cleaner way to do it?
8eee137
to
1ef8ad1
Compare
1ef8ad1
to
a01927e
Compare
This allows creating
egui_kittest::Harness
es fromeframe::App
s.I also introduce a new
TestRenderer
trait and aWgpuTestRenderer
. I really didn't like how tightly egui_kittest was coupled to wgpu. This should make it possible to create e.g. aGlowTestRenderer
in oder to support custom glow rendering with PaintCallbacks.HarnessBuilder
now has an option to initialize a WgpuTestRenderer, either from a default configuration (this should be updated based on #5506) or a WgpuSetup or existing RenderState.I also introduce a
LazyTestRenderer
which basically has the old behavior. In the uninitialized state it remembers the TextureDeltas and a closure to create the actual test renderer. When rendering a snapshot, it will actually initialize the wgpu renderer and apply the texture deltas. This means tests without any snapshots will save the overhead of having to create the wgpu resources and tests with snapshots will continue to work fine without having to configure wgpu in the beginning.I also renamed
Harness::wgpu_snapshot
etc... toHarness::snapshot
.eframe_kittest
to test a wholeeframe::App
#5389