From 082ef280691ee2cdfebd554c120fa420a2f6b3ed Mon Sep 17 00:00:00 2001 From: Birh Burh Date: Mon, 24 Jun 2024 17:25:03 +0200 Subject: [PATCH] Fixes has_integer_attributes and macroquad --- src/graphics.rs | 5 +++-- src/graphics/gl.rs | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index e9e8e2bc..16425432 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1052,11 +1052,12 @@ pub struct ContextInfo { } impl ContextInfo { - pub fn has_integer_attributes(&self) -> bool { + pub fn has_integer_attributes(&self, shader_version: u32) -> bool { match self.backend { Backend::Metal => true, Backend::OpenGl => { - self.glsl_support.v150 | self.glsl_support.v300es | self.glsl_support.v330 + (self.glsl_support.v150 | self.glsl_support.v300es | self.glsl_support.v330) + && shader_version >= 150 } } } diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 9bfe01e4..12091f04 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -41,6 +41,7 @@ struct ShaderUniform { struct ShaderInternal { program: GLuint, + version: u32, images: Vec, uniforms: Vec, } @@ -509,8 +510,8 @@ fn load_shader_internal( meta: ShaderMeta, ) -> Result { unsafe { - let vertex_shader = load_shader(GL_VERTEX_SHADER, vertex_shader)?; - let fragment_shader = load_shader(GL_FRAGMENT_SHADER, fragment_shader)?; + let (vertex_shader, vertex_version) = load_shader(GL_VERTEX_SHADER, vertex_shader)?; + let (fragment_shader, fragment_version) = load_shader(GL_FRAGMENT_SHADER, fragment_shader)?; let program = glCreateProgram(); glAttachShader(program, vertex_shader); @@ -559,15 +560,17 @@ fn load_shader_internal( Some(res) }).collect(); + assert!(vertex_version == fragment_version); // Probably most shader usages use same version for both Ok(ShaderInternal { program, + version: vertex_version, images, uniforms, }) } } -pub fn load_shader(shader_type: GLenum, source: &str) -> Result { +pub fn load_shader(shader_type: GLenum, source: &str) -> Result<(GLuint, u32), ShaderError> { unsafe { let shader = glCreateShader(shader_type); assert!(shader != 0); @@ -611,7 +614,26 @@ pub fn load_shader(shader_type: GLenum, source: &str) -> Result(); + version = version_str.parse().unwrap(); + } + } + } + + Ok((shader, version)) } } @@ -739,8 +761,8 @@ impl GlContext { self.cache.color_write = color_write; } - fn has_integer_attributes(&self) -> bool { - self.info.has_integer_attributes() + fn has_integer_attributes(&self, shader_version: u32) -> bool { + self.info.has_integer_attributes(shader_version) } } @@ -1332,8 +1354,9 @@ impl RenderingBackend for GlContext { unsafe { match attribute.type_ { GL_INT | GL_UNSIGNED_INT | GL_SHORT | GL_UNSIGNED_SHORT - | GL_UNSIGNED_BYTE | GL_BYTE => { - assert!(self.has_integer_attributes()); + | GL_UNSIGNED_BYTE | GL_BYTE + if self.has_integer_attributes(shader.version) => + { glVertexAttribIPointer( attr_index as GLuint, attribute.size,