f32 in renderer

This commit is contained in:
Thomas Forgione 2018-07-23 11:43:34 +02:00
parent 6807773b38
commit 30c4bf5c3a
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
2 changed files with 15 additions and 9 deletions

View File

@ -6,6 +6,11 @@ use nalgebra::Vector4;
use math::vector::{Vector2, Vector3};
use math::frustum::Frustum;
/// Converts a Matrix4<f64> into a Matrix4<f32>
pub fn mat_to_f32(mat: Matrix4<f64>) -> Matrix4<f32> {
mat.map(|x| x as f32)
}
/// The trait that a render camera should implement.
///
/// It allows the renderer to use it.

View File

@ -16,7 +16,7 @@ use glium::index::{NoIndices, PrimitiveType};
use glium::glutin::GlWindow;
use scene::Scene;
use camera::RenderCamera;
use camera::{RenderCamera, mat_to_f32};
use model::{Vertex, Part, Model};
use math::vector::Vector3;
@ -124,8 +124,8 @@ impl Renderer {
let mut target = self.draw();
target.clear_color_srgb_and_depth(self.clear_color, 1.0);
let perspective = camera.perspective();
let view = camera.view();
let perspective = mat_to_f32(camera.perspective());
let view = mat_to_f32(camera.view());
let params = DrawParameters {
depth: Depth {
@ -144,7 +144,8 @@ impl Renderer {
if let &Some(ref buffer) = part.vertex_buffer() {
let diffuse = if let Some(ref name) = part.material_name {
model.materials.get(name).unwrap().diffuse
let t = model.materials.get(name).unwrap().diffuse;
Vector3::new(t[0] as f32, t[1] as f32, t[2] as f32)
} else {
Vector3::new(1.0, 1.0, 1.0)
};
@ -152,7 +153,7 @@ impl Renderer {
let texture = self.get_texture_of_part(&model, part);
let (texture, size) = if let Some((texture, size)) = texture {
(texture, size)
(texture, Vector3::new(size[0] as f32, size[1] as f32, size[2] as f32))
} else {
(&self.default_texture, Vector3::new(1.0, 1.0, 1.0))
};
@ -162,11 +163,11 @@ impl Renderer {
NoIndices(PrimitiveType::TrianglesList),
&self.program,
&uniform!(
diffuse: Into::<[f64; 3]>::into(diffuse),
diffuse: Into::<[f32; 3]>::into(diffuse),
tex: texture,
perspective: Into::<[[f64; 4]; 4]>::into(perspective),
view: Into::<[[f64; 4]; 4]>::into(view),
texture_size: Into::<[f64; 3]>::into(size),
perspective: Into::<[[f32; 4]; 4]>::into(perspective),
view: Into::<[[f32; 4]; 4]>::into(view),
texture_size: Into::<[f32; 3]>::into(size),
),
&params,
).unwrap();