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.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs
index 5c7435c..a90c069 100644
--- a/engine/src/renderer/opengl.rs
+++ b/engine/src/renderer/opengl.rs
@@ -115,20 +115,16 @@ fn render(
query: Query<RenderableEntity, Not<With<NoDraw>>>,
point_light_query: Query<(PointLight,)>,
directional_lights: Query<(DirectionalLight,)>,
- camera_query: Query<(Camera,)>,
+ camera_query: Query<(Camera, Position)>,
window: Single<Window>,
global_light: Single<GlobalLight>,
mut gl_objects: Local<GlobalGlObjects>,
mut actions: Actions,
)
{
- let Some(camera) = camera_query.iter().find_map(|(camera,)| {
- if !camera.current {
- return None;
- }
-
- Some(camera)
- }) else {
+ let Some((camera, camera_pos)) =
+ camera_query.iter().find(|(camera, _)| camera.current)
+ else {
#[cfg(feature = "debug")]
tracing::warn!("No current camera. Nothing will be rendered");
return;
@@ -196,6 +192,7 @@ fn render(
},
shader_program,
&camera,
+ &camera_pos,
window.size().expect("Failed to get window size"),
);
@@ -210,7 +207,7 @@ fn render(
.map(|(dir_light,)| &**dir_light)
.collect::<Vec<_>>()
.as_slice(),
- &camera,
+ &camera_pos,
);
for texture in &material.textures {
@@ -430,6 +427,7 @@ fn apply_transformation_matrices(
transformation: Transformation,
gl_shader_program: &mut GlShaderProgram,
camera: &Camera,
+ camera_pos: &Position,
window_size: Dimens<u32>,
)
{
@@ -438,7 +436,7 @@ fn apply_transformation_matrices(
&create_transformation_matrix(transformation),
);
- let view = create_view(camera);
+ let view = create_view(camera, camera_pos);
gl_shader_program.set_uniform_matrix_4fv(cstr!("view"), &view);
@@ -460,7 +458,7 @@ fn apply_light<PointLightHolder>(
gl_shader_program: &mut GlShaderProgram,
point_lights: &[PointLightHolder],
directional_lights: &[&DirectionalLight],
- camera: &Camera,
+ camera_pos: &Position,
) where
PointLightHolder: Deref<Target = PointLight>,
{
@@ -559,7 +557,7 @@ fn apply_light<PointLightHolder>(
gl_shader_program.set_uniform_1fv(cstr!("material.shininess"), material.shininess);
- gl_shader_program.set_uniform_vec_3fv(cstr!("view_pos"), &camera.position);
+ gl_shader_program.set_uniform_vec_3fv(cstr!("view_pos"), &camera_pos.position);
}
fn set_light_attenuation_uniforms(
@@ -656,11 +654,11 @@ fn create_light_uniform_name(
}
}
-fn create_view(camera: &Camera) -> Matrix<f32, 4, 4>
+fn create_view(camera: &Camera, camera_pos: &Position) -> Matrix<f32, 4, 4>
{
let mut view = Matrix::new();
- view.look_at(&camera.position, &camera.target, &camera.global_up);
+ view.look_at(&camera_pos.position, &camera.target, &camera.global_up);
view
}