diff options
author | HampusM <hampus@hampusmat.com> | 2024-05-19 17:47:37 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-05-19 21:15:49 +0200 |
commit | 2ab8ca293f9548238b22d96d4fd88ec93d6b2431 (patch) | |
tree | f9e5e5ab06b540493431c602e22a6fbd0526f52b /engine | |
parent | 46dced7a770783f81c651371e0e42eebce292343 (diff) |
refactor(engine): make Material non-exhaustive & fields public
Diffstat (limited to 'engine')
-rw-r--r-- | engine/src/material.rs | 68 | ||||
-rw-r--r-- | engine/src/renderer/mod.rs | 20 |
2 files changed, 18 insertions, 70 deletions
diff --git a/engine/src/material.rs b/engine/src/material.rs index f71cee5..5e360cd 100644 --- a/engine/src/material.rs +++ b/engine/src/material.rs @@ -5,67 +5,17 @@ use crate::data_types::dimens::Dimens; use crate::texture::{Id as TextureId, Texture}; #[derive(Debug, Clone, Component)] +#[non_exhaustive] pub struct Material { - ambient: Color<f32>, - diffuse: Color<f32>, - specular: Color<f32>, - ambient_map: TextureId, - diffuse_map: TextureId, - specular_map: TextureId, - textures: Vec<Texture>, - shininess: f32, -} - -impl Material -{ - #[must_use] - pub fn ambient(&self) -> &Color<f32> - { - &self.ambient - } - - #[must_use] - pub fn diffuse(&self) -> &Color<f32> - { - &self.diffuse - } - - #[must_use] - pub fn specular(&self) -> &Color<f32> - { - &self.specular - } - - #[must_use] - pub fn ambient_map(&self) -> &TextureId - { - &self.ambient_map - } - - #[must_use] - pub fn diffuse_map(&self) -> &TextureId - { - &self.diffuse_map - } - - #[must_use] - pub fn specular_map(&self) -> &TextureId - { - &self.specular_map - } - - #[must_use] - pub fn textures(&self) -> &[Texture] - { - &self.textures - } - - #[must_use] - pub fn shininess(&self) -> f32 - { - self.shininess - } + pub ambient: Color<f32>, + pub diffuse: Color<f32>, + pub specular: Color<f32>, + pub ambient_map: TextureId, + pub diffuse_map: TextureId, + pub specular_map: TextureId, + pub textures: Vec<Texture>, + pub shininess: f32, } /// [`Material`] builder. diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index e32f308..2035a3c 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -149,7 +149,7 @@ fn render( &camera, ); - for texture in material.textures() { + for texture in &material.textures { let gl_texture = gl_textures .entry(texture.id()) .or_insert_with(|| create_gl_texture(texture)); @@ -388,39 +388,37 @@ fn apply_light( gl_shader_program.set_uniform_vec_3fv( cstr!("material.ambient"), - &(material.ambient().clone() + global_light.ambient_offset.clone()).into(), + &(material.ambient.clone() + global_light.ambient_offset.clone()).into(), ); - gl_shader_program.set_uniform_vec_3fv( - cstr!("material.diffuse"), - &material.diffuse().clone().into(), - ); + gl_shader_program + .set_uniform_vec_3fv(cstr!("material.diffuse"), &material.diffuse.clone().into()); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_vec_3fv( cstr!("material.specular"), - &material.specular().clone().into(), + &material.specular.clone().into(), ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( cstr!("material.ambient_map"), - material.ambient_map().into_inner() as i32, + material.ambient_map.into_inner() as i32, ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( cstr!("material.diffuse_map"), - material.diffuse_map().into_inner() as i32, + material.diffuse_map.into_inner() as i32, ); #[allow(clippy::cast_possible_wrap)] gl_shader_program.set_uniform_1i( cstr!("material.specular_map"), - material.specular_map().into_inner() as i32, + material.specular_map.into_inner() as i32, ); - gl_shader_program.set_uniform_1fv(cstr!("material.shininess"), material.shininess()); + gl_shader_program.set_uniform_1fv(cstr!("material.shininess"), material.shininess); gl_shader_program.set_uniform_vec_3fv(cstr!("view_pos"), &camera.position); } |