1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-28 07:23:13 -04:00

Re-implement PaintCallbacks With Support for WGPU (#1684)

* Re-implement PaintCallbacks With Support for WGPU

This makes breaking changes to the PaintCallback system, but makes it
flexible enough to support both the WGPU and glow backends with custom
rendering.

Also adds a WGPU equivalent to the glow demo for custom painting.
This commit is contained in:
Zicklag
2022-05-28 10:52:36 -05:00
committed by GitHub
parent 8173093c67
commit 1d9524cc59
22 changed files with 595 additions and 130 deletions

View File

@@ -1,6 +1,6 @@
//! The different shapes that can be painted.
use std::sync::Arc;
use std::{any::Any, sync::Arc};
use crate::{
text::{FontId, Fonts, Galley},
@@ -747,21 +747,19 @@ pub struct PaintCallback {
/// Paint something custom (e.g. 3D stuff).
///
/// The argument is the render context, and what it contains depends on the backend.
/// In `eframe` it will be `egui_glow::Painter`.
/// The concrete value of `callback` depends on the rendering backend used. For instance, the
/// `glow` backend requires that callback be an `egui_glow::CallbackFn` while the `wgpu`
/// backend requires a `egui_wgpu::CallbackFn`.
///
/// The rendering backend is responsible for first setting the active viewport to [`Self::rect`].
/// If the type cannnot be downcast to the type expected by the current backend the callback
/// will not be drawn.
///
/// The rendering backend is also responsible for restoring any state,
/// such as the bound shader program and vertex array.
pub callback: Arc<dyn Fn(&PaintCallbackInfo, &mut dyn std::any::Any) + Send + Sync>,
}
impl PaintCallback {
#[inline]
pub fn call(&self, info: &PaintCallbackInfo, render_ctx: &mut dyn std::any::Any) {
(self.callback)(info, render_ctx);
}
/// The rendering backend is responsible for first setting the active viewport to
/// [`Self::rect`].
///
/// The rendering backend is also responsible for restoring any state, such as the bound shader
/// program, vertex array, etc.
pub callback: Arc<dyn Any + Sync + Send>,
}
impl std::fmt::Debug for PaintCallback {