From a4b500ff4b02165fdccd6d90c652f083c7114d4b Mon Sep 17 00:00:00 2001 From: Svenn-Arne Dragly Date: Mon, 8 Jul 2019 10:36:25 +0200 Subject: [PATCH] [rs] Make opengl_to_wgpu_matrix into a constant --- wgpu/examples/cube/main.rs | 2 +- wgpu/examples/framework.rs | 16 ++++++++-------- wgpu/examples/mipmap/main.rs | 2 +- wgpu/examples/shadow/main.rs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index dbb25e468d..b5544deb73 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -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 } } diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index 424da2ab92..40ea24f663 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -1,5 +1,13 @@ use log::info; +#[cfg_attr(rustfmt, rustfmt_skip)] +pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4 = 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(data: &[T]) -> &[u8] { use std::mem::size_of; @@ -30,14 +38,6 @@ pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec { spv } -pub fn opengl_to_wgpu_matrix() -> cgmath::Matrix4 { - // 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); diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index f6c39c7466..7194f2d231 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -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 } diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index 8a4cc86a4a..e57af3ea49 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -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 } }