diff options
author | 2023-11-28 23:13:38 +0100 | |
---|---|---|
committer | 2023-11-28 23:13:38 +0100 | |
commit | ab7dae554cac801aeed5d9aa4d3850d50be86263 (patch) | |
tree | 4165df808d50fbaa4cb9b27ded59077b769a4135 /examples | |
parent | 100d15f30654d446cffe2fb60a435c79c81b0188 (diff) | |
download | iced-ab7dae554cac801aeed5d9aa4d3850d50be86263.tar.gz iced-ab7dae554cac801aeed5d9aa4d3850d50be86263.tar.bz2 iced-ab7dae554cac801aeed5d9aa4d3850d50be86263.zip |
Provide actual bounds to `Shader` primitives
... and allow for proper translation and scissoring.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/custom_shader/src/main.rs | 21 | ||||
-rw-r--r-- | examples/custom_shader/src/scene.rs | 6 | ||||
-rw-r--r-- | examples/custom_shader/src/scene/pipeline.rs | 21 |
3 files changed, 24 insertions, 24 deletions
diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 2eb1ac4a..3bfa3a43 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -5,9 +5,7 @@ use scene::Scene; use iced::executor; use iced::time::Instant; use iced::widget::shader::wgpu; -use iced::widget::{ - checkbox, column, container, row, shader, slider, text, vertical_space, -}; +use iced::widget::{checkbox, column, container, row, shader, slider, text}; use iced::window; use iced::{ Alignment, Application, Color, Command, Element, Length, Renderer, @@ -138,21 +136,18 @@ impl Application for IcedCubes { let controls = column![top_controls, bottom_controls,] .spacing(10) + .padding(20) .align_items(Alignment::Center); let shader = shader(&self.scene).width(Length::Fill).height(Length::Fill); - container( - column![shader, controls, vertical_space(20),] - .spacing(40) - .align_items(Alignment::Center), - ) - .width(Length::Fill) - .height(Length::Fill) - .center_x() - .center_y() - .into() + container(column![shader, controls].align_items(Alignment::Center)) + .width(Length::Fill) + .height(Length::Fill) + .center_x() + .center_y() + .into() } fn subscription(&self) -> Subscription<Self::Message> { diff --git a/examples/custom_shader/src/scene.rs b/examples/custom_shader/src/scene.rs index 3b291ce2..a35efdd9 100644 --- a/examples/custom_shader/src/scene.rs +++ b/examples/custom_shader/src/scene.rs @@ -133,9 +133,9 @@ impl shader::Primitive for Primitive { format: wgpu::TextureFormat, device: &wgpu::Device, queue: &wgpu::Queue, + _bounds: Rectangle, target_size: Size<u32>, _scale_factor: f32, - _transform: shader::Transformation, storage: &mut shader::Storage, ) { if !storage.has::<Pipeline>() { @@ -158,9 +158,9 @@ impl shader::Primitive for Primitive { fn render( &self, storage: &shader::Storage, - bounds: Rectangle<u32>, target: &wgpu::TextureView, _target_size: Size<u32>, + viewport: Rectangle<u32>, encoder: &mut wgpu::CommandEncoder, ) { //at this point our pipeline should always be initialized @@ -170,7 +170,7 @@ impl shader::Primitive for Primitive { pipeline.render( target, encoder, - bounds, + viewport, self.cubes.len() as u32, self.show_depth_buffer, ); diff --git a/examples/custom_shader/src/scene/pipeline.rs b/examples/custom_shader/src/scene/pipeline.rs index 94c6c562..124b421f 100644 --- a/examples/custom_shader/src/scene/pipeline.rs +++ b/examples/custom_shader/src/scene/pipeline.rs @@ -351,7 +351,7 @@ impl Pipeline { &self, target: &wgpu::TextureView, encoder: &mut wgpu::CommandEncoder, - bounds: Rectangle<u32>, + viewport: Rectangle<u32>, num_cubes: u32, show_depth: bool, ) { @@ -384,10 +384,10 @@ impl Pipeline { }); pass.set_scissor_rect( - bounds.x, - bounds.y, - bounds.width, - bounds.height, + viewport.x, + viewport.y, + viewport.width, + viewport.height, ); pass.set_pipeline(&self.pipeline); pass.set_bind_group(0, &self.uniform_bind_group, &[]); @@ -397,7 +397,7 @@ impl Pipeline { } if show_depth { - self.depth_pipeline.render(encoder, target, bounds); + self.depth_pipeline.render(encoder, target, viewport); } } } @@ -550,7 +550,7 @@ impl DepthPipeline { &self, encoder: &mut wgpu::CommandEncoder, target: &wgpu::TextureView, - bounds: Rectangle<u32>, + viewport: Rectangle<u32>, ) { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("cubes.pipeline.depth_pass"), @@ -573,7 +573,12 @@ impl DepthPipeline { occlusion_query_set: None, }); - pass.set_scissor_rect(bounds.x, bounds.y, bounds.width, bounds.height); + pass.set_scissor_rect( + viewport.x, + viewport.y, + viewport.width, + viewport.height, + ); pass.set_pipeline(&self.pipeline); pass.set_bind_group(0, &self.bind_group, &[]); pass.draw(0..6, 0..1); |