summaryrefslogtreecommitdiff
path: root/engine/src/renderer/opengl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/renderer/opengl.rs')
-rw-r--r--engine/src/renderer/opengl.rs20
1 files changed, 12 insertions, 8 deletions
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);