From 57f45d99419358ee35734b31037de494a4c944cc Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sat, 27 Nov 2021 20:17:18 +0100 Subject: [PATCH] renderer: Allow clear calls on specific regions --- CHANGELOG.md | 1 + anvil/src/render.rs | 2 +- anvil/src/udev.rs | 2 +- src/backend/renderer/gles2/mod.rs | 9 ++++++++- src/backend/renderer/mod.rs | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b67e92..81eda76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - `X11Surface::buffer` now additionally returns the age of the buffer - `X11Surface` now has an explicit `submit` function - `X11Surface` is now multi-window capable. +- `Renderer::clear` now expects a second argument to optionally only clear parts of the buffer/surface ### Additions diff --git a/anvil/src/render.rs b/anvil/src/render.rs index 4848c45..0d26b30 100644 --- a/anvil/src/render.rs +++ b/anvil/src/render.rs @@ -24,7 +24,7 @@ pub fn render_layers_and_windows( output_scale: f32, logger: &Logger, ) -> 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] { draw_layers( diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 957a419..f5a63bc 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -873,7 +873,7 @@ fn initial_render(surface: &mut RenderSurface, renderer: &mut Gles2Renderer) -> renderer .render((1, 1).into(), Transform::Normal, |_, frame| { frame - .clear([0.8, 0.8, 0.9, 1.0]) + .clear([0.8, 0.8, 0.9, 1.0], None) .map_err(Into::::into) }) .map_err(Into::::into) diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index 3a8c49b..5c15b3a 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -1121,10 +1121,17 @@ impl Frame for Gles2Frame { type Error = Gles2Error; type TextureId = Gles2Texture; - fn clear(&mut self, color: [f32; 4]) -> Result<(), Self::Error> { + fn clear(&mut self, color: [f32; 4], at: Option>) -> Result<(), Self::Error> { 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.Clear(ffi::COLOR_BUFFER_BIT); + if at.is_some() { + self.gl.Disable(ffi::SCISSOR_TEST); + } } Ok(()) diff --git a/src/backend/renderer/mod.rs b/src/backend/renderer/mod.rs index a975894..f2c8ee6 100644 --- a/src/backend/renderer/mod.rs +++ b/src/backend/renderer/mod.rs @@ -171,7 +171,7 @@ pub trait Frame { /// /// 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. - fn clear(&mut self, color: [f32; 4]) -> Result<(), Self::Error>; + fn clear(&mut self, color: [f32; 4], at: Option>) -> Result<(), Self::Error>; /// 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.