gl: initialize history and feedback fbos before drawing

This commit is contained in:
chyyran 2022-11-21 02:36:37 -05:00
parent 4cbc831bf3
commit b799c1c6ef
5 changed files with 36 additions and 28 deletions

View file

@ -634,13 +634,17 @@ impl FilterChain {
let mut source = original; let mut source = original;
let passes_len = self.passes.len(); // rescale render buffers to ensure all bindings are valid.
let (pass, last) = self.passes.split_at_mut(passes_len - 1); for (index, pass) in self.passes.iter_mut().enumerate() {
self.output_framebuffers[index].scale(
pass.config.scaling.clone(),
pass.get_format(),
viewport,
&original,
&source,
);
for (index, pass) in pass.iter_mut().enumerate() { self.feedback_framebuffers[index].scale(
{
let target = &mut self.output_framebuffers[index];
let _framebuffer_size = target.scale(
pass.config.scaling.clone(), pass.config.scaling.clone(),
pass.get_format(), pass.get_format(),
viewport, viewport,
@ -649,6 +653,10 @@ impl FilterChain {
); );
} }
let passes_len = self.passes.len();
let (pass, last) = self.passes.split_at_mut(passes_len - 1);
for (index, pass) in pass.iter_mut().enumerate() {
let target = &self.output_framebuffers[index]; let target = &self.output_framebuffers[index];
pass.draw( pass.draw(
index, index,
@ -675,6 +683,7 @@ impl FilterChain {
for pass in last { for pass in last {
source.filter = pass.config.filter; source.filter = pass.config.filter;
source.mip_filter = pass.config.filter; source.mip_filter = pass.config.filter;
pass.draw( pass.draw(
passes_len - 1, passes_len - 1,
&self.common, &self.common,
@ -689,6 +698,7 @@ impl FilterChain {
&source, &source,
RenderTarget::new(viewport.output, viewport.mvp), RenderTarget::new(viewport.output, viewport.mvp),
); );
} }
// swap feedback framebuffers with output // swap feedback framebuffers with output

View file

@ -93,11 +93,8 @@ impl FilterPass {
Self::build_uniform(location, buffer, value, gl::Uniform1f) Self::build_uniform(location, buffer, value, gl::Uniform1f)
} }
fn bind_texture(binding: &TextureImage, texture: &Texture, semantic: TextureSemantics) { fn bind_texture(binding: &TextureImage, texture: &Texture) {
unsafe { unsafe {
if texture.image.handle == 0 {
eprintln!("[WARNING] trying to bind {semantic:?} texture 0 to slot {} ", binding.binding)
}
// eprintln!("setting {} to texunit {}", texture.image.handle, binding.binding); // eprintln!("setting {} to texunit {}", texture.image.handle, binding.binding);
gl::ActiveTexture(gl::TEXTURE0 + binding.binding); gl::ActiveTexture(gl::TEXTURE0 + binding.binding);
gl::BindTexture(gl::TEXTURE_2D, texture.image.handle); gl::BindTexture(gl::TEXTURE_2D, texture.image.handle);
@ -347,7 +344,7 @@ impl FilterPass {
.texture_meta .texture_meta
.get(&TextureSemantics::Original.semantics(0)) .get(&TextureSemantics::Original.semantics(0))
{ {
FilterPass::bind_texture(binding, original, TextureSemantics::Original); FilterPass::bind_texture(binding, original);
} }
// bind OriginalSize // bind OriginalSize
@ -374,7 +371,7 @@ impl FilterPass {
.get(&TextureSemantics::Source.semantics(0)) .get(&TextureSemantics::Source.semantics(0))
{ {
// eprintln!("setting source binding to {}", binding.binding); // eprintln!("setting source binding to {}", binding.binding);
FilterPass::bind_texture(binding, source, TextureSemantics::Source); FilterPass::bind_texture(binding, source);
} }
// bind SourceSize // bind SourceSize
@ -395,7 +392,7 @@ impl FilterPass {
if let Some(binding) = self.reflection.meta.texture_meta.get(&TextureSemantics::OriginalHistory.semantics(0)) { if let Some(binding) = self.reflection.meta.texture_meta.get(&TextureSemantics::OriginalHistory.semantics(0)) {
FilterPass::bind_texture(binding, original, TextureSemantics::OriginalHistory); FilterPass::bind_texture(binding, original);
} }
if let Some((location, offset)) = self if let Some((location, offset)) = self
.variable_bindings .variable_bindings
@ -419,7 +416,7 @@ impl FilterPass {
.texture_meta .texture_meta
.get(&TextureSemantics::OriginalHistory.semantics(index + 1)) .get(&TextureSemantics::OriginalHistory.semantics(index + 1))
{ {
FilterPass::bind_texture(binding, output, TextureSemantics::OriginalHistory); FilterPass::bind_texture(binding, output);
} }
if let Some((location, offset)) = self if let Some((location, offset)) = self
@ -446,7 +443,7 @@ impl FilterPass {
.texture_meta .texture_meta
.get(&TextureSemantics::PassOutput.semantics(index)) .get(&TextureSemantics::PassOutput.semantics(index))
{ {
FilterPass::bind_texture(binding, output, TextureSemantics::PassOutput); FilterPass::bind_texture(binding, output);
} }
if let Some((location, offset)) = self if let Some((location, offset)) = self
@ -473,7 +470,10 @@ impl FilterPass {
.texture_meta .texture_meta
.get(&TextureSemantics::PassFeedback.semantics(index)) .get(&TextureSemantics::PassFeedback.semantics(index))
{ {
FilterPass::bind_texture(binding, feedback, TextureSemantics::PassFeedback); if feedback.image.handle == 0 {
eprintln!("[WARNING] trying to bind PassFeedback: {index} which has texture 0 to slot {} in pass {pass_index}", binding.binding)
}
FilterPass::bind_texture(binding, feedback);
} }
if let Some((location, offset)) = self if let Some((location, offset)) = self
@ -535,7 +535,7 @@ impl FilterPass {
.texture_meta .texture_meta
.get(&TextureSemantics::User.semantics(*index)) .get(&TextureSemantics::User.semantics(*index))
{ {
FilterPass::bind_texture(binding, lut, TextureSemantics::User); FilterPass::bind_texture(binding, lut);
} }
if let Some((location, offset)) = self if let Some((location, offset)) = self

View file

@ -10,8 +10,8 @@ use crate::filter_chain::FilterChain;
use crate::framebuffer::Framebuffer; use crate::framebuffer::Framebuffer;
use crate::util::{GlImage, Size, Viewport}; use crate::util::{GlImage, Size, Viewport};
const WIDTH: u32 = 1920; const WIDTH: u32 = 900;
const HEIGHT: u32 = 1080; const HEIGHT: u32 = 700;
const TITLE: &str = "Hello From OpenGL World!"; const TITLE: &str = "Hello From OpenGL World!";
pub fn compile_program(vertex: &str, fragment: &str) -> GLuint { pub fn compile_program(vertex: &str, fragment: &str) -> GLuint {
@ -113,7 +113,7 @@ pub fn setup() -> (Glfw, Window, Receiver<(f64, WindowEvent)>, GLuint, GLuint) {
glfw::OpenGlProfileHint::Core, glfw::OpenGlProfileHint::Core,
)); ));
glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true)); glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true));
glfw.window_hint(glfw::WindowHint::Resizable(false)); glfw.window_hint(glfw::WindowHint::Resizable(true));
glfw.window_hint(glfw::WindowHint::OpenGlDebugContext(true)); glfw.window_hint(glfw::WindowHint::OpenGlDebugContext(true));
let (mut window, events) = glfw let (mut window, events) = glfw

View file

@ -18,7 +18,7 @@ mod tests {
#[test] #[test]
fn triangle() { fn triangle() {
let (glfw, window, events, shader, vao) = hello_triangle::setup(); let (glfw, window, events, shader, vao) = hello_triangle::setup();
let mut filter = FilterChain::load("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV-GLASS.slangp").unwrap(); let mut filter = FilterChain::load("../test/slang-shaders/crt/crt-royale-fake-bloom.slangp").unwrap();
// FilterChain::load("../test/slang-shaders/crt/crt-royale.slangp").unwrap(); // FilterChain::load("../test/slang-shaders/crt/crt-royale.slangp").unwrap();

View file

@ -6,5 +6,3 @@ alias0 = ""
float_framebuffer0 = "false" float_framebuffer0 = "false"
srgb_framebuffer0 = "false" srgb_framebuffer0 = "false"
ColorMod = "1.700000" ColorMod = "1.700000"
textures = "BORDER;"
BORDER = "agb.png"