diff options
Diffstat (limited to 'engine/src/renderer')
-rw-r--r-- | engine/src/renderer/opengl.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index 3fe3388..8cafe0d 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::ffi::{c_void, CString}; +use std::ops::Deref; use std::process::abort; use cstr::cstr; @@ -100,7 +101,7 @@ fn render( Option<MaterialFlags>, Transform, )>, - point_light_query: Query<(PointLight, Transform)>, + point_light_query: Query<(PointLight,)>, directional_lights: Query<(DirectionalLight,)>, camera_query: Query<(Camera,)>, window: Single<Window>, @@ -120,11 +121,9 @@ fn render( return; }; - // TODO: Maybe find a way to not clone here? Cloning here is needed since a transform - // can be in both the object query and the light source query let point_lights = point_light_query .iter() - .map(|(point_light, transform)| ((*point_light).clone(), (*transform).clone())) + .map(|(point_light,)| point_light) .collect::<Vec<_>>(); let directional_lights = directional_lights.iter().collect::<Vec<_>>(); @@ -361,15 +360,16 @@ fn apply_transformation_matrices( gl_shader_program.set_uniform_matrix_4fv(cstr!("projection"), &projection); } -fn apply_light( +fn apply_light<PointLightHolder>( material: &Material, material_flags: &MaterialFlags, global_light: &GlobalLight, gl_shader_program: &mut GlShaderProgram, - point_lights: &[(PointLight, Transform)], + point_lights: &[PointLightHolder], directional_lights: &[&DirectionalLight], camera: &Camera, -) +) where + PointLightHolder: Deref<Target = PointLight>, { debug_assert!( point_lights.len() < 64, @@ -404,19 +404,17 @@ fn apply_light( directional_lights.len() as i32, ); - for (point_light_index, (point_light, point_light_transform)) in - point_lights.iter().enumerate() - { + for (point_light_index, point_light) in point_lights.iter().enumerate() { gl_shader_program.set_uniform_vec_3fv( &create_light_uniform_name("point_lights", point_light_index, "position"), - &point_light_transform.position, + &point_light.position, ); set_light_phong_uniforms( gl_shader_program, "point_lights", point_light_index, - point_light, + &**point_light, ); set_light_attenuation_uniforms( |