diff options
-rw-r--r-- | engine/src/material.rs | 22 | ||||
-rw-r--r-- | engine/src/renderer/mod.rs | 8 | ||||
-rw-r--r-- | engine/src/texture.rs | 17 |
3 files changed, 24 insertions, 23 deletions
diff --git a/engine/src/material.rs b/engine/src/material.rs index c292af4..6839fd1 100644 --- a/engine/src/material.rs +++ b/engine/src/material.rs @@ -1,7 +1,7 @@ use ecs::Component; use crate::color::Color; -use crate::texture::Id as TextureId; +use crate::texture::{Id as TextureId, Texture}; #[derive(Debug, Clone, Component)] pub struct Material @@ -12,6 +12,7 @@ pub struct Material ambient_map: TextureId, diffuse_map: TextureId, specular_map: TextureId, + textures: Vec<Texture>, shininess: f32, } @@ -54,6 +55,12 @@ impl Material } #[must_use] + pub fn textures(&self) -> &[Texture] + { + &self.textures + } + + #[must_use] pub fn shininess(&self) -> f32 { self.shininess @@ -70,6 +77,7 @@ pub struct Builder ambient_map: Option<TextureId>, diffuse_map: Option<TextureId>, specular_map: Option<TextureId>, + textures: Vec<Texture>, shininess: f32, } @@ -85,6 +93,7 @@ impl Builder ambient_map: None, diffuse_map: None, specular_map: None, + textures: Vec::new(), shininess: 32.0, } } @@ -138,6 +147,14 @@ impl Builder } #[must_use] + pub fn textures(mut self, textures: impl IntoIterator<Item = Texture>) -> Self + { + self.textures = textures.into_iter().collect(); + + self + } + + #[must_use] pub fn shininess(mut self, shininess: f32) -> Self { self.shininess = shininess; @@ -150,7 +167,7 @@ impl Builder /// # Panics /// Will panic if no ambient map, diffuse map or specular map is set. #[must_use] - pub fn build(&self) -> Material + pub fn build(self) -> Material { Material { ambient: self.ambient.clone(), @@ -159,6 +176,7 @@ impl Builder ambient_map: self.ambient_map.unwrap(), diffuse_map: self.diffuse_map.unwrap(), specular_map: self.specular_map.unwrap(), + textures: self.textures, shininess: self.shininess, } } diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index af91257..fbb86f7 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -37,7 +37,7 @@ use crate::opengl::vertex_array::{ use crate::opengl::{clear_buffers, enable, BufferClearMask, Capability}; use crate::projection::{new_perspective_matrix, Projection}; use crate::shader::Program as ShaderProgram; -use crate::texture::{Id as TextureId, List as TextureMap, Texture}; +use crate::texture::{Id as TextureId, Texture}; use crate::transform::Transform; use crate::vector::{Vec2, Vec3}; use crate::vertex::{AttributeComponentType, Vertex}; @@ -91,7 +91,7 @@ fn initialize(window: Single<Window>) } fn render( - query: Query<(Mesh, TextureMap, ShaderProgram, Material, Transform)>, + query: Query<(Mesh, ShaderProgram, Material, Transform)>, light_source_query: Query<(LightSource, Transform)>, camera_query: Query<(Camera,)>, window: Single<Window>, @@ -124,7 +124,7 @@ fn render( clear_buffers(BufferClearMask::COLOR | BufferClearMask::DEPTH); - for (mesh, texture_list, shader_program, material, transform) in &query { + for (mesh, shader_program, material, transform) in &query { let shader_program = gl_shader_programs .entry(shader_program.u64_hash()) .or_insert_with(|| create_gl_shader_program(&shader_program).unwrap()); @@ -147,7 +147,7 @@ fn render( &camera, ); - for texture in &texture_list.list { + for texture in material.textures() { let gl_texture = gl_textures .entry(texture.id()) .or_insert_with(|| create_gl_texture(texture)); diff --git a/engine/src/texture.rs b/engine/src/texture.rs index 88c57bd..f9bed1e 100644 --- a/engine/src/texture.rs +++ b/engine/src/texture.rs @@ -196,20 +196,3 @@ impl Display for Id self.id.fmt(formatter) } } - -/// Texture list. -#[derive(Component)] -pub struct List -{ - pub list: Vec<Texture>, -} - -impl FromIterator<Texture> for List -{ - fn from_iter<Iter>(iter: Iter) -> Self - where - Iter: IntoIterator<Item = Texture>, - { - Self { list: iter.into_iter().collect() } - } -} |