diff options
author | 2023-09-14 13:58:36 -0700 | |
---|---|---|
committer | 2023-11-14 11:31:44 +0100 | |
commit | 781ef1f94c4859aeeb852f801b72be095b8ff82b (patch) | |
tree | 63e2678eca11dd41c26a40633c04341fd795d733 /examples/custom_shader/src/primitive/buffer.rs | |
parent | 817f72868746461891ca4e74473c555f3b5c5703 (diff) | |
download | iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.gz iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.bz2 iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.zip |
Added support for custom shader widget for iced_wgpu backend.
Diffstat (limited to 'examples/custom_shader/src/primitive/buffer.rs')
-rw-r--r-- | examples/custom_shader/src/primitive/buffer.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/custom_shader/src/primitive/buffer.rs b/examples/custom_shader/src/primitive/buffer.rs new file mode 100644 index 00000000..377ce1bb --- /dev/null +++ b/examples/custom_shader/src/primitive/buffer.rs @@ -0,0 +1,39 @@ +// A custom buffer container for dynamic resizing. +pub struct Buffer { + pub raw: wgpu::Buffer, + label: &'static str, + size: u64, + usage: wgpu::BufferUsages, +} + +impl Buffer { + pub fn new( + device: &wgpu::Device, + label: &'static str, + size: u64, + usage: wgpu::BufferUsages, + ) -> Self { + Self { + raw: device.create_buffer(&wgpu::BufferDescriptor { + label: Some(label), + size, + usage, + mapped_at_creation: false, + }), + label, + size, + usage, + } + } + + pub fn resize(&mut self, device: &wgpu::Device, new_size: u64) { + if new_size > self.size { + self.raw = device.create_buffer(&wgpu::BufferDescriptor { + label: Some(self.label), + size: new_size, + usage: self.usage, + mapped_at_creation: false, + }); + } + } +} |