renderer: Allow clear calls on specific regions

This commit is contained in:
Victor Brekenfeld 2021-11-27 20:17:18 +01:00
parent 55ec6dc7cb
commit 57f45d9941
5 changed files with 12 additions and 4 deletions

View File

@ -31,6 +31,7 @@
- `X11Surface::buffer` now additionally returns the age of the buffer - `X11Surface::buffer` now additionally returns the age of the buffer
- `X11Surface` now has an explicit `submit` function - `X11Surface` now has an explicit `submit` function
- `X11Surface` is now multi-window capable. - `X11Surface` is now multi-window capable.
- `Renderer::clear` now expects a second argument to optionally only clear parts of the buffer/surface
### Additions ### Additions

View File

@ -24,7 +24,7 @@ pub fn render_layers_and_windows(
output_scale: f32, output_scale: f32,
logger: &Logger, logger: &Logger,
) -> Result<(), SwapBuffersError> { ) -> Result<(), SwapBuffersError> {
frame.clear([0.8, 0.8, 0.9, 1.0])?; frame.clear([0.8, 0.8, 0.9, 1.0], None)?;
for layer in [Layer::Background, Layer::Bottom] { for layer in [Layer::Background, Layer::Bottom] {
draw_layers( draw_layers(

View File

@ -873,7 +873,7 @@ fn initial_render(surface: &mut RenderSurface, renderer: &mut Gles2Renderer) ->
renderer renderer
.render((1, 1).into(), Transform::Normal, |_, frame| { .render((1, 1).into(), Transform::Normal, |_, frame| {
frame frame
.clear([0.8, 0.8, 0.9, 1.0]) .clear([0.8, 0.8, 0.9, 1.0], None)
.map_err(Into::<SwapBuffersError>::into) .map_err(Into::<SwapBuffersError>::into)
}) })
.map_err(Into::<SwapBuffersError>::into) .map_err(Into::<SwapBuffersError>::into)

View File

@ -1121,10 +1121,17 @@ impl Frame for Gles2Frame {
type Error = Gles2Error; type Error = Gles2Error;
type TextureId = Gles2Texture; type TextureId = Gles2Texture;
fn clear(&mut self, color: [f32; 4]) -> Result<(), Self::Error> { fn clear(&mut self, color: [f32; 4], at: Option<Rectangle<i32, Physical>>) -> Result<(), Self::Error> {
unsafe { unsafe {
if let Some(rect) = at {
self.gl.Enable(ffi::SCISSOR_TEST);
self.gl.Scissor(rect.loc.x, rect.loc.y, rect.size.w, rect.size.h);
}
self.gl.ClearColor(color[0], color[1], color[2], color[3]); self.gl.ClearColor(color[0], color[1], color[2], color[3]);
self.gl.Clear(ffi::COLOR_BUFFER_BIT); self.gl.Clear(ffi::COLOR_BUFFER_BIT);
if at.is_some() {
self.gl.Disable(ffi::SCISSOR_TEST);
}
} }
Ok(()) Ok(())

View File

@ -171,7 +171,7 @@ pub trait Frame {
/// ///
/// This operation is only valid in between a `begin` and `finish`-call. /// This operation is only valid in between a `begin` and `finish`-call.
/// If called outside this operation may error-out, do nothing or modify future rendering results in any way. /// If called outside this operation may error-out, do nothing or modify future rendering results in any way.
fn clear(&mut self, color: [f32; 4]) -> Result<(), Self::Error>; fn clear(&mut self, color: [f32; 4], at: Option<Rectangle<i32, Physical>>) -> Result<(), Self::Error>;
/// Render a texture to the current target as a flat 2d-plane at a given /// Render a texture to the current target as a flat 2d-plane at a given
/// position and applying the given transformation with the given alpha value. /// position and applying the given transformation with the given alpha value.