summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-31 01:41:04 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-31 01:41:04 +0100
commit298c42ac5f208745cd3b23b3cc8f10f7c8769797 (patch)
treeed59801ab1194540fae6f8507a7eb83e152dcbd0 /wgpu
parent85916c9e8710ee90cbf37d384acbb6d208ff1da3 (diff)
downloadiced-298c42ac5f208745cd3b23b3cc8f10f7c8769797.tar.gz
iced-298c42ac5f208745cd3b23b3cc8f10f7c8769797.tar.bz2
iced-298c42ac5f208745cd3b23b3cc8f10f7c8769797.zip
Replace `nalgebra` with `glam`
`glam` compiles much faster and leverages SIMD nicely.
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/Cargo.toml2
-rw-r--r--wgpu/src/image.rs4
-rw-r--r--wgpu/src/quad.rs8
-rw-r--r--wgpu/src/transformation.rs31
4 files changed, 20 insertions, 25 deletions
diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml
index 30f9224f..04fae248 100644
--- a/wgpu/Cargo.toml
+++ b/wgpu/Cargo.toml
@@ -13,5 +13,5 @@ wgpu = { version = "0.3", git = "https://github.com/gfx-rs/wgpu-rs", rev = "ed2c
wgpu_glyph = { version = "0.4", git = "https://github.com/hecrj/wgpu_glyph", rev = "954ac865ca1b7f6b97bf403f8c6174a7120e667c" }
raw-window-handle = "0.3"
image = "0.22"
-nalgebra = "0.18"
+glam = "0.8"
log = "0.4"
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index c42e1cd4..75cfa166 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -222,11 +222,9 @@ impl Pipeline {
bounds: Rectangle<u32>,
target: &wgpu::TextureView,
) {
- let matrix: [f32; 16] = transformation.into();
-
let transform_buffer = device
.create_buffer_mapped(16, wgpu::BufferUsage::COPY_SRC)
- .fill_from_slice(&matrix[..]);
+ .fill_from_slice(transformation.as_ref());
encoder.copy_buffer_to_buffer(
&transform_buffer,
diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs
index 6365e117..bfbd7e2d 100644
--- a/wgpu/src/quad.rs
+++ b/wgpu/src/quad.rs
@@ -23,14 +23,12 @@ impl Pipeline {
}],
});
- let matrix: [f32; 16] = Transformation::identity().into();
-
let transform = device
.create_buffer_mapped(
16,
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
)
- .fill_from_slice(&matrix[..]);
+ .fill_from_slice(Transformation::identity().as_ref());
let constants = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &constant_layout,
@@ -169,11 +167,9 @@ impl Pipeline {
bounds: Rectangle<u32>,
target: &wgpu::TextureView,
) {
- let matrix: [f32; 16] = transformation.into();
-
let transform_buffer = device
.create_buffer_mapped(16, wgpu::BufferUsage::COPY_SRC)
- .fill_from_slice(&matrix[..]);
+ .fill_from_slice(transformation.as_ref());
encoder.copy_buffer_to_buffer(
&transform_buffer,
diff --git a/wgpu/src/transformation.rs b/wgpu/src/transformation.rs
index 53583e7e..b0d14cc8 100644
--- a/wgpu/src/transformation.rs
+++ b/wgpu/src/transformation.rs
@@ -1,29 +1,30 @@
-use nalgebra::Matrix3;
+use glam::{Mat4, Vec3, Vec4};
use std::ops::Mul;
/// A 2D transformation matrix.
#[derive(Debug, Clone, Copy, PartialEq)]
-pub struct Transformation(Matrix3<f32>);
+pub struct Transformation(Mat4);
impl Transformation {
/// Get the identity transformation.
pub fn identity() -> Transformation {
- Transformation(Matrix3::identity())
+ Transformation(Mat4::identity())
}
/// Creates an orthographic projection.
#[rustfmt::skip]
pub fn orthographic(width: u16, height: u16) -> Transformation {
- Transformation(nalgebra::Matrix3::new(
- 2.0 / f32::from(width), 0.0, -1.0,
- 0.0, 2.0 / f32::from(height), -1.0,
- 0.0, 0.0, 1.0
+ Transformation(Mat4::from_cols(
+ Vec4::new(2.0 / f32::from(width), 0.0, 0.0, 0.0),
+ Vec4::new(0.0, 2.0 / f32::from(height), 0.0, 0.0),
+ Vec4::new(0.0, 0.0, -1.0, 0.0),
+ Vec4::new(-1.0, -1.0, 0.0, 1.0)
))
}
/// Creates a translate transformation.
pub fn translate(x: f32, y: f32) -> Transformation {
- Transformation(Matrix3::new_translation(&nalgebra::Vector2::new(x, y)))
+ Transformation(Mat4::from_translation(Vec3::new(x, y, 0.0)))
}
}
@@ -35,14 +36,14 @@ impl Mul for Transformation {
}
}
+impl AsRef<[f32; 16]> for Transformation {
+ fn as_ref(&self) -> &[f32; 16] {
+ self.0.as_ref()
+ }
+}
+
impl From<Transformation> for [f32; 16] {
- #[rustfmt::skip]
fn from(t: Transformation) -> [f32; 16] {
- [
- t.0[0], t.0[1], 0.0, t.0[2],
- t.0[3], t.0[4], 0.0, t.0[5],
- 0.0, 0.0, -1.0, 0.0,
- t.0[6], t.0[7], 0.0, t.0[8]
- ]
+ t.as_ref().clone()
}
}