summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-24 17:25:54 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-24 17:25:54 +0100
commit700390bdb297a5fc2eb356b10f9ed2656cc75daa (patch)
tree7f4187a3c37029c0870b7021cd66e5314bb435b4 /wgpu/src/image.rs
parent1a6333c7f3985ada8aea0d8fe36072c184052080 (diff)
downloadiced-700390bdb297a5fc2eb356b10f9ed2656cc75daa.tar.gz
iced-700390bdb297a5fc2eb356b10f9ed2656cc75daa.tar.bz2
iced-700390bdb297a5fc2eb356b10f9ed2656cc75daa.zip
Use explicit `Uniforms` type in image pipeline
Diffstat (limited to 'wgpu/src/image.rs')
-rw-r--r--wgpu/src/image.rs38
1 files changed, 24 insertions, 14 deletions
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index b8c233d2..5dc972ac 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -8,7 +8,7 @@ pub struct Pipeline {
cache: RefCell<HashMap<String, Memory>>,
pipeline: wgpu::RenderPipeline,
- transform: wgpu::Buffer,
+ uniforms: wgpu::Buffer,
vertices: wgpu::Buffer,
indices: wgpu::Buffer,
instances: wgpu::Buffer,
@@ -46,14 +46,16 @@ impl Pipeline {
],
});
- let matrix: [f32; 16] = Transformation::identity().into();
+ let uniforms = Uniforms {
+ transform: Transformation::identity().into(),
+ };
- let transform_buffer = device
+ let uniforms_buffer = device
.create_buffer_mapped(
- 16,
+ 1,
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
)
- .fill_from_slice(&matrix[..]);
+ .fill_from_slice(&[uniforms]);
let constant_bind_group =
device.create_bind_group(&wgpu::BindGroupDescriptor {
@@ -62,8 +64,8 @@ impl Pipeline {
wgpu::Binding {
binding: 0,
resource: wgpu::BindingResource::Buffer {
- buffer: &transform_buffer,
- range: 0..64,
+ buffer: &uniforms_buffer,
+ range: 0..std::mem::size_of::<Uniforms>() as u64,
},
},
wgpu::Binding {
@@ -186,7 +188,7 @@ impl Pipeline {
cache: RefCell::new(HashMap::new()),
pipeline,
- transform: transform_buffer,
+ uniforms: uniforms_buffer,
vertices,
indices,
instances,
@@ -224,16 +226,18 @@ impl Pipeline {
bounds: Rectangle<u32>,
target: &wgpu::TextureView,
) {
- let transform_buffer = device
- .create_buffer_mapped(16, wgpu::BufferUsage::COPY_SRC)
- .fill_from_slice(transformation.as_ref());
+ let uniforms_buffer = device
+ .create_buffer_mapped(1, wgpu::BufferUsage::COPY_SRC)
+ .fill_from_slice(&[Uniforms {
+ transform: transformation.into(),
+ }]);
encoder.copy_buffer_to_buffer(
- &transform_buffer,
+ &uniforms_buffer,
0,
- &self.transform,
+ &self.uniforms,
0,
- 16 * 4,
+ std::mem::size_of::<Uniforms>() as u64,
);
// TODO: Batch draw calls using a texture atlas
@@ -450,3 +454,9 @@ struct Instance {
_position: [f32; 2],
_scale: [f32; 2],
}
+
+#[repr(C)]
+#[derive(Debug, Clone, Copy)]
+struct Uniforms {
+ transform: [f32; 16],
+}