From 83dc63ffe03cc6c818fef40904bf51909145437b Mon Sep 17 00:00:00 2001 From: chyyran Date: Sat, 19 Nov 2022 02:28:22 -0500 Subject: [PATCH] gl: fix ubo binding --- librashader-runtime-gl/src/filter_pass.rs | 8 +++++--- librashader-runtime-gl/src/hello_triangle.rs | 3 ++- librashader-runtime-gl/src/lib.rs | 16 ++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index ae1e961..0debae1 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -177,14 +177,15 @@ impl FilterPass { self.build_semantics(parent, mvp, frame_count, frame_direction, fb_size, viewport, original, source); // shader_gl3:1514 - if !self.ubo_location.vertex == gl::INVALID_INDEX && !self.ubo_location.fragment == gl::INVALID_INDEX { + if self.ubo_location.vertex != gl::INVALID_INDEX && self.ubo_location.fragment != gl::INVALID_INDEX { if let (Some(ubo), Some(ring)) = (&self.reflection.ubo, &mut self.ubo_ring) { let size = ubo.size; let buffer = ring.current(); unsafe { gl::BindBuffer(gl::UNIFORM_BUFFER, *buffer); - gl::BufferSubData(gl::UNIFORM_BUFFER, 0, size as GLsizeiptr, self.uniform_buffer.as_ptr().cast()); + gl::BufferSubData(gl::UNIFORM_BUFFER, 0, size as GLsizeiptr, + self.uniform_buffer.as_ptr().cast()); gl::BindBuffer(gl::UNIFORM_BUFFER, 0); if self.ubo_location.vertex != gl::INVALID_INDEX { @@ -256,11 +257,12 @@ impl FilterPass { -1.0, -1.0, 0.0, 1.0 ]); + let mvp_size = mvp.len() * std::mem::size_of::(); let (buffer, offset) = match variable.offset { MemberOffset::Ubo(offset) => (&mut self.uniform_buffer, offset), MemberOffset::PushConstant(offset) => (&mut self.push_buffer, offset) }; - FilterPass::build_mvp(&mut buffer[offset..][..mvp.len() * std::mem::size_of::()], mvp) + FilterPass::build_mvp(&mut buffer[offset..][..mvp_size], mvp) } if let Some(variable) = self.reflection.meta.variable_meta.get(&VariableSemantics::Output) { diff --git a/librashader-runtime-gl/src/hello_triangle.rs b/librashader-runtime-gl/src/hello_triangle.rs index 29e7790..70f3b25 100644 --- a/librashader-runtime-gl/src/hello_triangle.rs +++ b/librashader-runtime-gl/src/hello_triangle.rs @@ -336,6 +336,7 @@ void main() // eprintln!("[core] rendered texture is {rendered_texture}"); + // do offscreen passes unsafe { filter.frame(0, &Viewport { x: 0, @@ -346,7 +347,7 @@ void main() } }, GlImage { handle: rendered_texture, - format: gl::RGBA, + format: gl::RGBA8, size: Size { width: WIDTH, height: HEIGHT diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index 4299424..62c4930 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -425,10 +425,10 @@ impl FilterChain { // how much info do we actually need? pub fn frame(&mut self, count: u32, vp: &Viewport, input: GlImage, clear: bool) { // - // unsafe { - // gl::BindFramebuffer(gl::FRAMEBUFFER, 0); - // gl::BindVertexArray(self.quad_vao); - // } + unsafe { + gl::BindFramebuffer(gl::FRAMEBUFFER, 0); + gl::BindVertexArray(self.quad_vao); + } // todo: copy framebuffer // shader_gl3: 2067 @@ -450,10 +450,10 @@ impl FilterChain { } - // unsafe { - // gl::BindFramebuffer(gl::FRAMEBUFFER, 0); - // gl::BindVertexArray(0); - // } + unsafe { + gl::BindFramebuffer(gl::FRAMEBUFFER, 0); + gl::BindVertexArray(0); + } // todo: deal with the mess that is frame history }