diff options
author | 2020-05-29 02:00:28 +0200 | |
---|---|---|
committer | 2020-05-29 02:00:28 +0200 | |
commit | 0cde20b3550ede81bc7ddef628b91eec225aa8af (patch) | |
tree | 56920437979012cceb49718f2dd4ce27d5ba5d40 /wgpu/src/quad.rs | |
parent | 67b6f044e870df41be92cdc79f571682b97a5d0d (diff) | |
parent | e11b5c614f5bf73c137b8b4f24f56047617527eb (diff) | |
download | iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.gz iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.bz2 iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.zip |
Merge branch 'master' into improvement/update-wgpu_glyph
Diffstat (limited to 'wgpu/src/quad.rs')
-rw-r--r-- | wgpu/src/quad.rs | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 0c2d2244..0b62f44f 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -1,4 +1,5 @@ use crate::Transformation; +use iced_graphics::layer; use iced_native::Rectangle; use std::mem; @@ -107,7 +108,7 @@ impl Pipeline { }], }, wgpu::VertexBufferDescriptor { - stride: mem::size_of::<Quad>() as u64, + stride: mem::size_of::<layer::Quad>() as u64, step_mode: wgpu::InputStepMode::Instance, attributes: &[ wgpu::VertexAttributeDescriptor { @@ -161,7 +162,7 @@ impl Pipeline { let instances = device.create_buffer(&wgpu::BufferDescriptor { label: None, - size: mem::size_of::<Quad>() as u64 * Quad::MAX as u64, + size: mem::size_of::<layer::Quad>() as u64 * MAX_INSTANCES as u64, usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, }); @@ -179,7 +180,7 @@ impl Pipeline { &mut self, device: &wgpu::Device, encoder: &mut wgpu::CommandEncoder, - instances: &[Quad], + instances: &[layer::Quad], transformation: Transformation, scale: f32, bounds: Rectangle<u32>, @@ -204,11 +205,11 @@ impl Pipeline { let total = instances.len(); while i < total { - let end = (i + Quad::MAX).min(total); + let end = (i + MAX_INSTANCES).min(total); let amount = end - i; let instance_buffer = device.create_buffer_with_data( - &instances[i..end].as_bytes(), + bytemuck::cast_slice(&instances[i..end]), wgpu::BufferUsage::COPY_SRC, ); @@ -217,7 +218,7 @@ impl Pipeline { 0, &self.instances, 0, - (mem::size_of::<Quad>() * amount) as u64, + (mem::size_of::<layer::Quad>() * amount) as u64, ); { @@ -260,7 +261,7 @@ impl Pipeline { ); } - i += Quad::MAX; + i += MAX_INSTANCES; } } } @@ -288,20 +289,7 @@ const QUAD_VERTS: [Vertex; 4] = [ }, ]; -#[repr(C)] -#[derive(Debug, Clone, Copy, AsBytes)] -pub struct Quad { - pub position: [f32; 2], - pub scale: [f32; 2], - pub color: [f32; 4], - pub border_color: [f32; 4], - pub border_radius: f32, - pub border_width: f32, -} - -impl Quad { - const MAX: usize = 100_000; -} +const MAX_INSTANCES: usize = 100_000; #[repr(C)] #[derive(Debug, Clone, Copy, AsBytes)] |