Skip to content

Commit

Permalink
[rs] Make opengl_to_wgpu_matrix into a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
dragly committed Jul 8, 2019
1 parent 8cf1dff commit a4b500f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
16 changes: 8 additions & 8 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit a4b500f

Please sign in to comment.