diff options
-rw-r--r-- | TODO.md | 2 | ||||
-rw-r--r-- | engine/src/opengl/texture.rs | 6 | ||||
-rw-r--r-- | engine/src/renderer/opengl.rs | 20 | ||||
-rw-r--r-- | engine/src/texture.rs | 5 |
4 files changed, 16 insertions, 17 deletions
@@ -16,7 +16,7 @@ - [x] Fix OpenGL warning "Vertex shader in program 3 is being recompiled based on GL state". It started at commit 526edc6f4cb5f29d17e2fe384e316236c033fccd. Fixed by c4686c2992417545e7a05a6a40ee9f1a8bbf3b96 -- [ ] New texture IDs are created for no reason. Crashes when on texture ID 31 +- [x] New texture IDs are created for no reason. Crashes when on texture ID 31 - [ ] Audio - [ ] Transparent/translucent models - [ ] Animations diff --git a/engine/src/opengl/texture.rs b/engine/src/opengl/texture.rs index 074ade7..52c8554 100644 --- a/engine/src/opengl/texture.rs +++ b/engine/src/opengl/texture.rs @@ -1,5 +1,5 @@ use crate::data_types::dimens::Dimens; -use crate::texture::{Id, Properties}; +use crate::texture::Properties; #[derive(Debug)] pub struct Texture @@ -224,8 +224,8 @@ macro_rules! texture_unit_enum { } } - pub fn from_texture_id(texture_id: Id) -> Option<Self> { - match texture_id.into_inner() { + pub fn from_num(num: usize) -> Option<Self> { + match num { #( N => Some(Self::No~N), )* diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index deb26a8..e7a630b 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -203,15 +203,12 @@ fn render( &camera_pos, ); - for texture in &material.textures { + for (index, texture) in material.textures.iter().enumerate() { let gl_texture = gl_textures .entry(texture.id()) .or_insert_with(|| create_gl_texture(texture)); - let texture_unit = - TextureUnit::from_texture_id(texture.id()).unwrap_or_else(|| { - panic!("Texture id {} is a invalid texture unit", texture.id()); - }); + let texture_unit = TextureUnit::from_num(index).expect("Too many textures"); set_active_texture_unit(texture_unit); @@ -562,22 +559,29 @@ fn apply_light<PointLightHolder>( gl_shader_program .set_uniform_vec_3fv(c"material.specular", &material.specular.clone().into()); + let texture_map = material + .textures + .iter() + .enumerate() + .map(|(index, texture)| (texture.id(), index)) + .collect::<HashMap<_, _>>(); + #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( c"material.ambient_map", - material.ambient_map.into_inner() as i32, + *texture_map.get(&material.ambient_map).unwrap() as i32, ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( c"material.diffuse_map", - material.diffuse_map.into_inner() as i32, + *texture_map.get(&material.diffuse_map).unwrap() as i32, ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( c"material.specular_map", - material.specular_map.into_inner() as i32, + *texture_map.get(&material.specular_map).unwrap() as i32, ); gl_shader_program.set_uniform_1fv(c"material.shininess", material.shininess); diff --git a/engine/src/texture.rs b/engine/src/texture.rs index f82b59d..16c1941 100644 --- a/engine/src/texture.rs +++ b/engine/src/texture.rs @@ -181,11 +181,6 @@ impl Id { Self { id } } - - pub(crate) fn into_inner(self) -> u32 - { - self.id - } } impl Display for Id |