render: Reset buffers after non-space-tracked rendering

This commit is contained in:
Victoria Brekenfeld 2022-04-26 16:52:49 +02:00
parent 81374ed282
commit 969cc8dae5
4 changed files with 51 additions and 6 deletions

View file

@ -35,15 +35,25 @@ pub struct WinitState {
backend: Rc<RefCell<WinitGraphicsBackend>>,
//_global: GlobalDrop<WlOutput>,
output: Output,
age_reset: u8,
#[cfg(feature = "debug")]
fps: Fps,
}
impl WinitState {
pub fn render_output(&mut self, state: &mut Common) -> Result<()> {
if render::needs_buffer_reset(&self.output, state) {
self.reset_buffers();
}
let backend = &mut *self.backend.borrow_mut();
backend.bind().with_context(|| "Failed to bind buffer")?;
let age = backend.buffer_age().unwrap_or(0);
let age = if self.age_reset > 0 {
self.age_reset -= 1;
0
} else {
backend.buffer_age().unwrap_or(0)
};
match render::render_output(
None,
@ -98,6 +108,10 @@ impl WinitState {
Ok(())
}
}
pub fn reset_buffers(&mut self) {
self.age_reset = 3;
}
}
pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Result<()> {
@ -186,6 +200,7 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
output: output.clone(),
#[cfg(feature = "debug")]
fps: Fps::default(),
age_reset: 0,
});
state.common.output_conf.add_heads(std::iter::once(&output));
state