From bfed01435bebf8928a640c8645785816e48c6e38 Mon Sep 17 00:00:00 2001 From: chyyran Date: Sat, 26 Nov 2022 16:58:23 -0500 Subject: [PATCH] gl: fix redundant fbo rebind --- librashader-runtime-gl/src/filter_chain.rs | 9 +++++++-- librashader-runtime-gl/src/filter_pass.rs | 1 - librashader-runtime-gl/src/hello_triangle.rs | 1 - librashader-runtime-gl/src/lib.rs | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index 26f4d94..b3254d8 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -593,6 +593,9 @@ impl FilterChain { Ok(()) } + /// Process a frame with the input image. + /// + /// When this frame returns, GL_FRAMEBUFFER is bound to 0. pub fn frame(&mut self, count: usize, viewport: &Viewport, input: &GlImage, clear: bool) -> Result<()> { if clear { for framebuffer in &self.history_framebuffers { @@ -605,7 +608,8 @@ impl FilterChain { } unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, 0); + // do not need to rebind FBO 0 here since first `draw` will + // bind automatically. gl::BindVertexArray(self.filter_vao); } @@ -719,8 +723,9 @@ impl FilterChain { } self.push_history(input)?; + + // pass.draw should return framebuffer bound to 0. unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, 0); gl::BindVertexArray(0); } diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index b257045..fca3b12 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -190,7 +190,6 @@ impl FilterPass { // todo: final pass? unsafe { - gl::BindFramebuffer(gl::FRAMEBUFFER, framebuffer.handle); gl::ColorMask(gl::TRUE, gl::TRUE, gl::TRUE, gl::TRUE); gl::ClearColor(0.0f32, 0.0f32, 0.0f32, 0.0f32); gl::Clear(gl::COLOR_BUFFER_BIT); diff --git a/librashader-runtime-gl/src/hello_triangle.rs b/librashader-runtime-gl/src/hello_triangle.rs index 69978d9..756b877 100644 --- a/librashader-runtime-gl/src/hello_triangle.rs +++ b/librashader-runtime-gl/src/hello_triangle.rs @@ -523,7 +523,6 @@ void main() unsafe { // texture is done now. // draw quad to screen - gl::BindFramebuffer(gl::FRAMEBUFFER, 0); gl::UseProgram(quad_programid); gl::ActiveTexture(gl::TEXTURE0); diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index d4a7054..b9e8837 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -27,7 +27,7 @@ mod tests { fn triangle_gl() { let (glfw, window, events, shader, vao) = hello_triangle::setup(); let mut filter = - FilterChain::load_from_path("../test/slang-shaders/crt/crt-royale.slangp") + FilterChain::load_from_path("../test/slang-shaders/vhs/VHSPro.slangp") .unwrap(); hello_triangle::do_loop(glfw, window, events, shader, vao, &mut filter); }