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

Wgpu resources are no longer wrapped in Arc (since they are now Clone) (#5612)

Co-authored-by: Nicolas <bircni@icloud.com>
This commit is contained in:
Andreas Reich
2025-01-20 18:06:35 +01:00
committed by GitHub
parent cf965aaa30
commit 30e66e4575
6 changed files with 37 additions and 45 deletions

View File

@@ -1,5 +1,4 @@
use crate::app_kind::AppKind;
use crate::wgpu::WgpuTestRenderer;
use crate::{Harness, LazyRenderer, TestRenderer};
use egui::{Pos2, Rect, Vec2};
use std::marker::PhantomData;
@@ -75,16 +74,16 @@ impl<State> HarnessBuilder<State> {
/// Enable wgpu rendering with a default setup suitable for testing.
///
/// This sets up a [`WgpuTestRenderer`] with the default setup.
/// This sets up a [`crate::wgpu::WgpuTestRenderer`] with the default setup.
#[cfg(feature = "wgpu")]
pub fn wgpu(self) -> Self {
self.renderer(WgpuTestRenderer::default())
self.renderer(crate::wgpu::WgpuTestRenderer::default())
}
/// Enable wgpu rendering with the given setup.
#[cfg(feature = "wgpu")]
pub fn wgpu_setup(self, setup: egui_wgpu::WgpuSetup) -> Self {
self.renderer(WgpuTestRenderer::from_setup(setup))
self.renderer(crate::wgpu::WgpuTestRenderer::from_setup(setup))
}
/// Create a new Harness with the given app closure and a state.

View File

@@ -402,6 +402,7 @@ impl<'a, State> Harness<'a, State> {
///
/// # Errors
/// Returns an error if the rendering fails.
#[cfg(any(feature = "wgpu", feature = "snapshot"))]
pub fn render(&mut self) -> Result<image::RgbaImage, String> {
self.renderer.render(&self.ctx, &self.output)
}

View File

@@ -1,5 +1,4 @@
use egui::{Context, FullOutput, TexturesDelta};
use image::RgbaImage;
use egui::TexturesDelta;
pub trait TestRenderer {
/// We use this to pass the glow / wgpu render state to [`eframe::Frame`].
@@ -13,7 +12,12 @@ pub trait TestRenderer {
///
/// # Errors
/// Returns an error if the rendering fails.
fn render(&mut self, ctx: &Context, output: &FullOutput) -> Result<RgbaImage, String>;
#[cfg(any(feature = "wgpu", feature = "snapshot"))]
fn render(
&mut self,
ctx: &egui::Context,
output: &egui::FullOutput,
) -> Result<image::RgbaImage, String>;
}
/// A lazy renderer that initializes the renderer on the first render call.
@@ -58,7 +62,12 @@ impl TestRenderer for LazyRenderer {
}
}
fn render(&mut self, ctx: &Context, output: &FullOutput) -> Result<RgbaImage, String> {
#[cfg(any(feature = "wgpu", feature = "snapshot"))]
fn render(
&mut self,
ctx: &egui::Context,
output: &egui::FullOutput,
) -> Result<image::RgbaImage, String> {
match self {
Self::Uninitialized {
texture_ops,