mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Make opengl_to_wgpu_matrix into a constant
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user