diff options
author | 2020-04-19 21:55:33 +0200 | |
---|---|---|
committer | 2020-04-19 21:56:03 +0200 | |
commit | f59832e88e9e6c72cd65d51de6fbf91bddf4a9d3 (patch) | |
tree | 812ab4e90c3728b3ae21e84c10069dcc840e9bd5 /wgpu/src/triangle.rs | |
parent | 592cc685067c36cbba87e4db14f4ebc71d65b951 (diff) | |
download | iced-f59832e88e9e6c72cd65d51de6fbf91bddf4a9d3.tar.gz iced-f59832e88e9e6c72cd65d51de6fbf91bddf4a9d3.tar.bz2 iced-f59832e88e9e6c72cd65d51de6fbf91bddf4a9d3.zip |
Fix alignment in triangle pipeline of `iced_wgpu`
Diffstat (limited to 'wgpu/src/triangle.rs')
-rw-r--r-- | wgpu/src/triangle.rs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 86c74fcd..99365a4b 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -231,11 +231,9 @@ impl Pipeline { // We upload everything upfront for (origin, mesh) in meshes { - let transform = Uniforms { - transform: (transformation - * Transformation::translate(origin.x, origin.y)) - .into(), - }; + let transform = (transformation + * Transformation::translate(origin.x, origin.y)) + .into(); let vertex_buffer = device.create_buffer_with_data( mesh.vertices.as_bytes(), @@ -361,12 +359,28 @@ impl Pipeline { #[derive(Debug, Clone, Copy, AsBytes)] struct Uniforms { transform: [f32; 16], + // We need to align this to 256 bytes to please `wgpu`... + // TODO: Be smarter and stop wasting memory! + _padding_a: [f32; 32], + _padding_b: [f32; 16], } impl Default for Uniforms { fn default() -> Self { Self { transform: *Transformation::identity().as_ref(), + _padding_a: [0.0; 32], + _padding_b: [0.0; 16], + } + } +} + +impl From<Transformation> for Uniforms { + fn from(transformation: Transformation) -> Uniforms { + Self { + transform: transformation.into(), + _padding_a: [0.0; 32], + _padding_b: [0.0; 16], } } } |