89 lines
3.7 KiB
Diff

--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -20,6 +20,29 @@
))]
/// You can use this for storage when implementing [`CallbackTrait`].
pub type CallbackResources = type_map::TypeMap;
+
+/// Marker for a same-frame backdrop effect handled by a host renderer.
+///
+/// This marker alone draws nothing. A host must split rendering at this marker,
+/// sample the preceding frame contents from its own offscreen target, and composite
+/// the result before continuing. Without host support use an opaque fallback.
+#[derive(Clone, Copy, Debug)]
+pub struct BackdropMarker {
+ /// Gaussian blur radius in logical points, interpreted by the host.
+ pub blur_radius_points: f32,
+ /// Rounded mask radius in logical points, interpreted by the host.
+ pub corner_radius_points: f32,
+}
+
+impl BackdropMarker {
+ /// Creates a marker with a logical viewport rectangle.
+ pub fn new_paint_callback(self, rect: epaint::emath::Rect) -> epaint::PaintCallback {
+ epaint::PaintCallback {
+ rect,
+ callback: std::sync::Arc::new(self),
+ }
+ }
+}
/// You can use this to do custom [`wgpu`] rendering in an egui app.
///
@@ -482,6 +505,24 @@
paint_jobs: &[epaint::ClippedPrimitive],
screen_descriptor: &ScreenDescriptor,
) {
+ self.render_range(render_pass, paint_jobs, screen_descriptor, 0);
+ }
+
+ /// Renders a contiguous subset of the exact paint job list passed to
+ /// `update_buffers`, preserving its original mesh-buffer positions.
+ ///
+ /// `preceding_mesh_count` must count *all* meshes preceding this subset,
+ /// including clipped-out and missing-texture meshes; callbacks do not count.
+ /// Each call targets a fresh render pass. The caller owns pass ordering and
+ /// attachment load/store behavior. Buffer upload and callback preparation must
+ /// still be performed exactly once for the complete list before any range.
+ pub fn render_range(
+ &self,
+ render_pass: &mut wgpu::RenderPass<'static>,
+ paint_jobs: &[epaint::ClippedPrimitive],
+ screen_descriptor: &ScreenDescriptor,
+ preceding_mesh_count: usize,
+ ) {
profiling::function_scope!();
let pixels_per_point = screen_descriptor.pixels_per_point;
@@ -491,8 +532,8 @@
// run.
let mut needs_reset = true;
- let mut index_buffer_slices = self.index_buffer.slices.iter();
- let mut vertex_buffer_slices = self.vertex_buffer.slices.iter();
+ let mut index_buffer_slices = self.index_buffer.slices.iter().skip(preceding_mesh_count);
+ let mut vertex_buffer_slices = self.vertex_buffer.slices.iter().skip(preceding_mesh_count);
for epaint::ClippedPrimitive {
clip_rect,
@@ -562,6 +603,10 @@
}
}
Primitive::Callback(callback) => {
+ if callback.callback.is::<BackdropMarker>() {
+ // The host handles this between render passes.
+ continue;
+ }
let Some(cbfn) = callback.callback.downcast_ref::<Callback>() else {
// We already warned in the `prepare` callback
continue;
@@ -951,6 +996,8 @@
Primitive::Callback(callback) => {
if let Some(c) = callback.callback.downcast_ref::<Callback>() {
callbacks.push(c.0.as_ref());
+ } else if callback.callback.is::<BackdropMarker>() {
+ // Host marker, not an egui rendering callback.
} else {
log::warn!("Unknown paint callback: expected `egui_wgpu::Callback`");
}