diff options
author | HampusM <hampus@hampusmat.com> | 2025-06-03 18:06:29 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-06-03 18:06:54 +0200 |
commit | d56f5bce6a38ef71b3f15a3efa845637885a410f (patch) | |
tree | fbc5f96b877ef9765f27b7b2eb268e9b02158163 /engine/src | |
parent | 93ee9ee9a37ac410ea926997f08e1d5db052bb86 (diff) |
refactor(engine): bind texture to gl texture unit with DSA
Diffstat (limited to 'engine/src')
-rw-r--r-- | engine/src/opengl/texture.rs | 36 | ||||
-rw-r--r-- | engine/src/renderer/opengl.rs | 16 |
2 files changed, 7 insertions, 45 deletions
diff --git a/engine/src/opengl/texture.rs b/engine/src/opengl/texture.rs index 706b9c9..80a5f37 100644 --- a/engine/src/opengl/texture.rs +++ b/engine/src/opengl/texture.rs @@ -19,10 +19,10 @@ impl Texture Self { texture } } - pub fn bind(&self) + pub fn bind_to_texture_unit(&self, texture_unit: u32) { unsafe { - gl::BindTexture(gl::TEXTURE_2D, self.texture); + gl::BindTextureUnit(texture_unit, self.texture); } } @@ -167,35 +167,3 @@ impl PixelDataFormat } } } - -pub fn set_active_texture_unit(texture_unit: TextureUnit) -{ - unsafe { - gl::ActiveTexture(texture_unit.into_gl()); - } -} - -macro_rules! texture_unit_enum { - (cnt=$cnt: literal) => { - seq_macro::seq!(N in 0..$cnt { - #[derive(Debug, Clone, Copy)] - pub enum TextureUnit { - #( - No~N, - )* - } - - impl TextureUnit { - fn into_gl(self) -> gl::types::GLenum { - match self { - #( - Self::No~N => gl::TEXTURE~N, - )* - } - } - } - }); - }; -} - -texture_unit_enum!(cnt = 3); diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index ea66de0..cfd046f 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -47,11 +47,9 @@ use crate::opengl::shader::{ Shader as GlShader, }; use crate::opengl::texture::{ - set_active_texture_unit, Filtering as GlTextureFiltering, PixelDataFormat as GlTexturePixelDataFormat, Texture as GlTexture, - TextureUnit, Wrapping as GlTextureWrapping, }; use crate::opengl::vertex_array::{ @@ -82,9 +80,9 @@ use crate::window::Window; mod vertex; -const AMBIENT_MAP_TEXTURE_UNIT: TextureUnit = TextureUnit::No0; -const DIFFUSE_MAP_TEXTURE_UNIT: TextureUnit = TextureUnit::No1; -const SPECULAR_MAP_TEXTURE_UNIT: TextureUnit = TextureUnit::No2; +const AMBIENT_MAP_TEXTURE_UNIT: u32 = 0; +const DIFFUSE_MAP_TEXTURE_UNIT: u32 = 1; +const SPECULAR_MAP_TEXTURE_UNIT: u32 = 2; type RenderableEntity<'a> = ( &'a Model, @@ -260,9 +258,7 @@ fn render( ) }); - set_active_texture_unit(texture_unit); - - gl_texture.bind(); + gl_texture.bind_to_texture_unit(texture_unit); continue; }; @@ -288,9 +284,7 @@ fn render( } }; - set_active_texture_unit(texture_unit); - - gl_texture.bind(); + gl_texture.bind_to_texture_unit(texture_unit); } shader_program.activate(); |