[rs] Make opengl_to_wgpu_matrix into a constant

This commit is contained in:
Svenn-Arne Dragly
2019-07-08 10:36:25 +02:00
parent 8cf1dff41f
commit a4b500ff4b
4 changed files with 12 additions and 12 deletions

View File

@@ -100,7 +100,7 @@ impl Example {
cgmath::Point3::new(0f32, 0.0, 0.0),
cgmath::Vector3::unit_z(),
);
let mx_correction = framework::opengl_to_wgpu_matrix();
let mx_correction = framework::OPENGL_TO_WGPU_MATRIX;
mx_correction * mx_projection * mx_view
}
}

View File

@@ -1,5 +1,13 @@
use log::info;
#[cfg_attr(rustfmt, rustfmt_skip)]
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
1.0, 0.0, 0.0, 0.0,
0.0, -1.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.0, 0.0, 0.5, 1.0,
);
#[allow(dead_code)]
pub fn cast_slice<T>(data: &[T]) -> &[u8] {
use std::mem::size_of;
@@ -30,14 +38,6 @@ pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u8> {
spv
}
pub fn opengl_to_wgpu_matrix() -> cgmath::Matrix4<f32> {
// converts from -1,1 Z to 0,1 Z and flips Y
cgmath::Matrix4::new(1.0, 0.0, 0.0, 0.0,
0.0, -1.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.0, 0.0, 0.5, 1.0)
}
pub trait Example {
fn init(sc_desc: &wgpu::SwapChainDescriptor, device: &mut wgpu::Device) -> Self;
fn resize(&mut self, sc_desc: &wgpu::SwapChainDescriptor, device: &mut wgpu::Device);

View File

@@ -64,7 +64,7 @@ impl Example {
cgmath::Point3::new(0f32, 50.0, 0.0),
cgmath::Vector3::unit_z(),
);
let mx_correction = framework::opengl_to_wgpu_matrix();
let mx_correction = framework::OPENGL_TO_WGPU_MATRIX;
mx_correction * mx_projection * mx_view
}

View File

@@ -113,7 +113,7 @@ impl Light {
near: self.depth.start,
far: self.depth.end,
};
let mx_correction = framework::opengl_to_wgpu_matrix();
let mx_correction = framework::OPENGL_TO_WGPU_MATRIX;
let mx_view_proj = mx_correction * cgmath::Matrix4::from(projection.to_perspective()) * mx_view;
LightRaw {
proj: *mx_view_proj.as_ref(),
@@ -175,7 +175,7 @@ impl Example {
cgmath::Point3::new(0f32, 0.0, 0.0),
cgmath::Vector3::unit_z(),
);
let mx_correction = framework::opengl_to_wgpu_matrix();
let mx_correction = framework::OPENGL_TO_WGPU_MATRIX;
mx_correction * mx_projection * mx_view
}
}