diff options
author | 2024-04-14 13:43:10 +0200 | |
---|---|---|
committer | 2024-04-14 13:43:10 +0200 | |
commit | 105b8bd5ad6ade1f203a0d8b0b93bd06f61f621a (patch) | |
tree | 4a5efa021b0dbe7d87ff57993c118753a32ea241 /examples/custom_shader | |
parent | ee105e3bee1bc676dcf3324693984ccda8e4e733 (diff) | |
parent | dbbbadfc950dfdfd02c7abbbf993e0685ca0f64a (diff) | |
download | iced-105b8bd5ad6ade1f203a0d8b0b93bd06f61f621a.tar.gz iced-105b8bd5ad6ade1f203a0d8b0b93bd06f61f621a.tar.bz2 iced-105b8bd5ad6ade1f203a0d8b0b93bd06f61f621a.zip |
Merge pull request #2382 from iced-rs/wgpu/better-architecture
Improved architecture for `iced_wgpu` and `iced_tiny_skia`
Diffstat (limited to 'examples/custom_shader')
-rw-r--r-- | examples/custom_shader/src/scene.rs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/examples/custom_shader/src/scene.rs b/examples/custom_shader/src/scene.rs index a35efdd9..5fa42188 100644 --- a/examples/custom_shader/src/scene.rs +++ b/examples/custom_shader/src/scene.rs @@ -9,8 +9,8 @@ use pipeline::cube::{self, Cube}; use iced::mouse; use iced::time::Duration; -use iced::widget::shader; -use iced::{Color, Rectangle, Size}; +use iced::widget::shader::{self, Viewport}; +use iced::{Color, Rectangle}; use glam::Vec3; use rand::Rng; @@ -130,25 +130,29 @@ impl Primitive { impl shader::Primitive for Primitive { fn prepare( &self, - format: wgpu::TextureFormat, device: &wgpu::Device, queue: &wgpu::Queue, - _bounds: Rectangle, - target_size: Size<u32>, - _scale_factor: f32, + format: wgpu::TextureFormat, storage: &mut shader::Storage, + _bounds: &Rectangle, + viewport: &Viewport, ) { if !storage.has::<Pipeline>() { - storage.store(Pipeline::new(device, queue, format, target_size)); + storage.store(Pipeline::new( + device, + queue, + format, + viewport.physical_size(), + )); } let pipeline = storage.get_mut::<Pipeline>().unwrap(); - //upload data to GPU + // Upload data to GPU pipeline.update( device, queue, - target_size, + viewport.physical_size(), &self.uniforms, self.cubes.len(), &self.cubes, @@ -157,20 +161,19 @@ impl shader::Primitive for Primitive { fn render( &self, + encoder: &mut wgpu::CommandEncoder, storage: &shader::Storage, target: &wgpu::TextureView, - _target_size: Size<u32>, - viewport: Rectangle<u32>, - encoder: &mut wgpu::CommandEncoder, + clip_bounds: &Rectangle<u32>, ) { - //at this point our pipeline should always be initialized + // At this point our pipeline should always be initialized let pipeline = storage.get::<Pipeline>().unwrap(); - //render primitive + // Render primitive pipeline.render( target, encoder, - viewport, + *clip_bounds, self.cubes.len() as u32, self.show_depth_buffer, ); |