From eb582e396ecb18b7e3ba71146fb617cddb190c7d Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 20 Nov 2022 00:05:50 -0500 Subject: [PATCH] gl: make framecount usize --- librashader-presets/src/parse/preset.rs | 2 +- librashader-runtime-gl/src/filter_chain.rs | 6 +++--- librashader-runtime-gl/src/hello_triangle.rs | 21 +++++--------------- librashader-runtime-gl/src/render_target.rs | 5 ++++- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/librashader-presets/src/parse/preset.rs b/librashader-presets/src/parse/preset.rs index da31823..db2e4d8 100644 --- a/librashader-presets/src/parse/preset.rs +++ b/librashader-presets/src/parse/preset.rs @@ -139,7 +139,7 @@ pub fn resolve_values(mut values: Vec) -> ShaderPreset { Value::FrameCountMod(_, value) => Some(*value), _ => None, }) - .unwrap_or(0), + .unwrap_or(1), srgb_framebuffer: shader_values .iter() .find_map(|f| match f { diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index b8b8305..27ed5b8 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -487,7 +487,7 @@ impl FilterChain { }) } - pub fn frame(&mut self, count: u32, vp: &Viewport, input: GlImage, _clear: bool) { + pub fn frame(&mut self, count: usize, vp: &Viewport, input: GlImage, _clear: bool) { if self.passes.is_empty() { return; } @@ -540,7 +540,7 @@ impl FilterChain { let target = &self.common.outputs[index]; pass.draw( &self.common, - count, + (count % pass.config.frame_count_mod as usize) as u32, 1, vp, &original, @@ -560,7 +560,7 @@ impl FilterChain { source.mip_filter = pass.config.filter; pass.draw( &self.common, - count, + (count % pass.config.frame_count_mod as usize) as u32, 1, vp, &original, diff --git a/librashader-runtime-gl/src/hello_triangle.rs b/librashader-runtime-gl/src/hello_triangle.rs index 7a04b07..89731d5 100644 --- a/librashader-runtime-gl/src/hello_triangle.rs +++ b/librashader-runtime-gl/src/hello_triangle.rs @@ -267,6 +267,7 @@ pub fn do_loop( triangle_vao: GLuint, filter: &mut FilterChain, ) { + let mut framecount = 0; let mut rendered_framebuffer = 0; let mut rendered_texture = 0; let mut quad_vbuf = 0; @@ -478,8 +479,6 @@ void main() unsafe { // render to fb gl::BindFramebuffer(gl::FRAMEBUFFER, rendered_framebuffer); - // gl::BindFramebuffer(gl::FRAMEBUFFER, 0); - gl::Viewport(0, 0, WIDTH as GLsizei, HEIGHT as GLsizei); // clear color @@ -501,17 +500,9 @@ void main() gl::BindFramebuffer(gl::FRAMEBUFFER, 0); } - // eprintln!("[core] rendered texture is {rendered_texture}"); - - // do offscreen passes - - // unsafe { - // gl::ActiveTexture(gl::TEXTURE0); - // gl::BindTexture(gl::TEXTURE_2D, rendered_texture); - // } unsafe { filter.frame( - 0, + framecount, &Viewport { x: 0, y: 0, @@ -533,10 +524,7 @@ void main() unsafe { // texture is done now. - - // todo: insert postprocessing stuff to rendered_texture - - // map quad to screen + // draw quad to screen gl::BindFramebuffer(gl::FRAMEBUFFER, 0); gl::UseProgram(quad_programid); @@ -544,10 +532,11 @@ void main() gl::BindTexture(gl::TEXTURE_2D, output_texture); gl::BindVertexArray(quad_vao); - gl::DrawArrays(gl::TRIANGLE_STRIP, 0, 4); } + + framecount += 1; window.swap_buffers(); } } diff --git a/librashader-runtime-gl/src/render_target.rs b/librashader-runtime-gl/src/render_target.rs index 203e84e..0131046 100644 --- a/librashader-runtime-gl/src/render_target.rs +++ b/librashader-runtime-gl/src/render_target.rs @@ -2,7 +2,10 @@ use crate::framebuffer::Framebuffer; use crate::util::Viewport; static DEFAULT_MVP: &[f32] = &[ - 2f32, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, -1.0, -1.0, 0.0, 1.0, + 2f32, 0.0, 0.0, 0.0, + 0.0, 2.0, 0.0, 0.0, + 0.0, 0.0, 2.0, 0.0, + -1.0, -1.0, 0.0, 1.0, ]; #[derive(Debug, Copy, Clone)]