Skip to content

Commit

Permalink
graphics: Fix default texture multisampling values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
not-fl3 committed Oct 20, 2024
1 parent a06a6df commit bdbb32c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -408,7 +407,7 @@ impl Default for TextureParams {
width: 0,
height: 0,
allocate_mipmaps: false,
sample_count: 0,
sample_count: 1,
}
}
}
Expand Down Expand Up @@ -1150,7 +1149,7 @@ pub trait RenderingBackend {
mag_filter: FilterMode::Linear,
mipmap_filter: MipmapFilterMode::None,
allocate_mipmaps: false,
sample_count: 0,
sample_count: 1,
},
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit bdbb32c

Please sign in to comment.