3

I am currently converting some code from using OpenGL to WGPU, and I have hit a problem I can't seem to resolve. In my original code, I set the scissor rectangle before clearing the render area, as I want to keep most of my framebuffer intact and only re-render the area that has been modified.

However, from what I can find, the clearing operation seems to be only available as a loading operation in WGPU, when creating the render pass. So when I set the scissor rectangle, which is done on the render pass itself, the clearing has already been performed during creation, clearing the entire framebuffer.

Am I missing something or is this currently not possible on WGPU?

Regards,

Gustav

let mut render_pass = encoder.begin_render_pass(
    &wgpu::RenderPassDescriptor {
        label: Some("Render Pass"),
        color_attachments: &[Some(
            wgpu::RenderPassColorAttachment {
                view: &view,
                resolve_target: None,
                ops: wgpu::Operations {
                    load: wgpu::LoadOp::Clear(
                        wgpu::Color {
                            r: 0.04,
                            g: 0.08,
                            b: 0.08,
                            a: 1.0,
                        }
                    ),
                    store: true,
                },
            }
        )],
        depth_stencil_attachment: None,
    }
);

render_pass.set_scissor_rect(
    render_area.x,
    render_area.y,
    render_area.width(), 
    render_area.height()
);

1 Answers1

1

In wgpu/WebGPU, updating only part of the framebuffer means that the previous framebuffer needs to be loaded:

let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
            label: Some("Render Pass"),
            color_attachments: &[Some(wgpu::RenderPassColorAttachment {
                view: &view,
                resolve_target: None,
                ops: wgpu::Operations {
                    load: wgpu::LoadOp::Load,
                    store: true,
                },
            })],
            depth_stencil_attachment: None,
        });

and then the scissor_rect can be set to draw to the specified area.

Jinlei Li
  • 240
  • 6