Skip to content

Commit d12d427

Browse files
committed
docs(tessera-ui): update DrawablePipeline.draw docs to describe batch rendering and scene_texture_view
1 parent 9931f19 commit d12d427

File tree

1 file changed

+19
-44
lines changed

1 file changed

+19
-44
lines changed

tessera-ui/src/renderer/drawer/pipeline.rs

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub trait DrawablePipeline<T: DrawCommand> {
232232
/// * `gpu_queue` - The WGPU queue for submitting commands
233233
/// * `config` - Current surface configuration
234234
/// * `render_pass` - The active render pass
235+
/// * `scene_texture_view` - View of the current scene texture for background sampling
235236
///
236237
/// # Default Implementation
237238
///
@@ -246,62 +247,35 @@ pub trait DrawablePipeline<T: DrawCommand> {
246247
) {
247248
}
248249

249-
/// Renders a single draw command.
250+
/// Renders a batch of draw commands.
250251
///
251252
/// This is the core method where the actual rendering happens. It's called
252-
/// once for each draw command of type `T` that needs to be rendered.
253+
/// once for a batch of draw commands of type `T` that need to be rendered.
253254
///
254255
/// # Parameters
255256
///
256-
/// * `gpu` - The WGPU device for creating resources
257-
/// * `gpu_queue` - The WGPU queue for submitting commands and updating buffers
258-
/// * `config` - Current surface configuration containing format and size information
259-
/// * `render_pass` - The active render pass to record draw commands into
260-
/// * `command` - The specific draw command to render
261-
/// * `size` - The size of the rendering area in pixels
262-
/// * `start_pos` - The top-left position where rendering should begin
263-
/// * `scene_texture_view` - View of the current scene texture for background sampling
257+
/// * `gpu` - The WGPU device for creating resources.
258+
/// * `gpu_queue` - The WGPU queue for submitting commands and updating buffers.
259+
/// * `config` - Current surface configuration containing format and size information.
260+
/// * `render_pass` - The active render pass to record draw commands into.
261+
/// * `commands` - A slice of tuples, each containing the command, its size, and its position.
262+
/// * `scene_texture_view` - View of the current scene texture for background sampling.
263+
/// * `clip_rect` - An optional rectangle to clip the drawing area.
264264
///
265265
/// # Implementation Guidelines
266266
///
267-
/// - Update any per-command uniforms or push constants
268-
/// - Set the appropriate render pipeline
269-
/// - Bind necessary resources (textures, buffers, bind groups)
270-
/// - Issue draw calls (typically `draw()`, `draw_indexed()`, or `draw_indirect()`)
271-
/// - Avoid expensive operations like buffer creation; prefer reusing resources
267+
/// - Iterate over the `commands` slice to process each command.
268+
/// - Update buffers (e.g., instance buffers, storage buffers) with data from the command batch.
269+
/// - Set the appropriate render pipeline.
270+
/// - Bind necessary resources (textures, buffers, bind groups).
271+
/// - Issue one or more draw calls (e.g., an instanced draw call) to render the entire batch.
272+
/// - If `clip_rect` is `Some`, use `render_pass.set_scissor_rect()` to clip rendering.
273+
/// - Avoid expensive operations like buffer creation; prefer reusing and updating existing resources.
272274
///
273275
/// # Scene Texture Usage
274276
///
275277
/// The `scene_texture_view` provides access to the current rendered scene,
276-
/// enabling effects that sample from the background. This is commonly used for:
277-
///
278-
/// - Blur and post-processing effects
279-
/// - Glass and transparency effects
280-
/// - Distortion and refraction
281-
///
282-
/// # Example
283-
///
284-
/// ```rust,ignore
285-
/// fn draw(&mut self, gpu: &wgpu::Device, gpu_queue: &wgpu::Queue,
286-
/// config: &wgpu::SurfaceConfiguration, render_pass: &mut wgpu::RenderPass<'_>,
287-
/// command: &MyCommand, size: PxSize, start_pos: PxPosition,
288-
/// scene_texture_view: &wgpu::TextureView) {
289-
/// // Update uniforms with command-specific data
290-
/// let uniforms = MyUniforms {
291-
/// color: command.color,
292-
/// position: [start_pos.x as f32, start_pos.y as f32],
293-
/// size: [size.width as f32, size.height as f32],
294-
/// };
295-
/// gpu_queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[uniforms]));
296-
///
297-
/// // Set pipeline and resources
298-
/// render_pass.set_pipeline(&self.render_pipeline);
299-
/// render_pass.set_bind_group(0, &self.bind_group, &[]);
300-
///
301-
/// // Draw a quad (two triangles)
302-
/// render_pass.draw(0..6, 0..1);
303-
/// }
304-
/// ```
278+
/// enabling effects that sample from the background.
305279
fn draw(
306280
&mut self,
307281
gpu: &wgpu::Device,
@@ -328,6 +302,7 @@ pub trait DrawablePipeline<T: DrawCommand> {
328302
/// * `gpu_queue` - The WGPU queue for submitting commands
329303
/// * `config` - Current surface configuration
330304
/// * `render_pass` - The active render pass
305+
/// * `scene_texture_view` - View of the current scene texture for background sampling
331306
///
332307
/// # Default Implementation
333308
///

0 commit comments

Comments
 (0)