From bdbb32c06afbfe6b0956194aa1dfa26f080723f1 Mon Sep 17 00:00:00 2001 From: Fedor Logachev Date: Sat, 19 Oct 2024 21:15:50 -0600 Subject: [PATCH] graphics: Fix default texture multisampling values sample_count = 0 doesn't really make much sense, there should be at least one sample. However, because it was the default, miniquad will treat sample_count = 0 as sample_count = 1, and both should mean no multisampling --- src/graphics.rs | 5 ++--- src/graphics/gl.rs | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index c2a270a1..c289f89c 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -392,7 +392,6 @@ pub struct TextureParams { /// On OpenGL, for a `sample_count > 1` render texture, render buffer object will /// be created instead of a regulat texture. /// - /// The only way to use pub sample_count: i32, } @@ -408,7 +407,7 @@ impl Default for TextureParams { width: 0, height: 0, allocate_mipmaps: false, - sample_count: 0, + sample_count: 1, } } } @@ -1150,7 +1149,7 @@ pub trait RenderingBackend { mag_filter: FilterMode::Linear, mipmap_filter: MipmapFilterMode::None, allocate_mipmaps: false, - sample_count: 0, + sample_count: 1, }, ) } diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 1bc24708..622b9f8a 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -165,13 +165,13 @@ impl Texture { } if access != TextureAccess::RenderTarget { assert!( - params.sample_count == 0, + params.sample_count <= 1, "Multisampling is only supported for render textures" ); } let (internal_format, format, pixel_type) = params.format.into(); - if access == TextureAccess::RenderTarget && params.sample_count != 0 { + if access == TextureAccess::RenderTarget && params.sample_count > 1 { let mut renderbuffer: u32 = 0; unsafe { glGenRenderbuffers(1, &mut renderbuffer as *mut _); @@ -1013,7 +1013,7 @@ impl RenderingBackend for GlContext { glBindFramebuffer(GL_FRAMEBUFFER, gl_fb); for (i, color_img) in color_img.iter().enumerate() { let texture = self.textures.get(*color_img); - if texture.params.sample_count != 0 { + if texture.params.sample_count > 1 { glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i as u32, @@ -1032,7 +1032,7 @@ impl RenderingBackend for GlContext { } if let Some(depth_img) = depth_img { let texture = self.textures.get(depth_img); - if texture.params.sample_count != 0 { + if texture.params.sample_count > 1 { glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,