From d922b478156488a7bc03c6e791e05c040d702634 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 8 Apr 2024 15:04:35 +0200 Subject: Reintroduce support for custom primitives in `iced_wgpu` --- examples/custom_shader/src/scene.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'examples/custom_shader') 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, - _scale_factor: f32, + format: wgpu::TextureFormat, storage: &mut shader::Storage, + _bounds: &Rectangle, + viewport: &Viewport, ) { if !storage.has::() { - storage.store(Pipeline::new(device, queue, format, target_size)); + storage.store(Pipeline::new( + device, + queue, + format, + viewport.physical_size(), + )); } let pipeline = storage.get_mut::().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, - viewport: Rectangle, - encoder: &mut wgpu::CommandEncoder, + clip_bounds: &Rectangle, ) { - //at this point our pipeline should always be initialized + // At this point our pipeline should always be initialized let pipeline = storage.get::().unwrap(); - //render primitive + // Render primitive pipeline.render( target, encoder, - viewport, + *clip_bounds, self.cubes.len() as u32, self.show_depth_buffer, ); -- cgit From 15057a05c118dafcb8cf90d4119e66caaa6026c5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 3 May 2024 09:11:46 +0200 Subject: Introduce `center` widget helper ... and also make `center_x` and `center_y` set `width` and `height` to `Length::Fill`, respectively. This targets the most common use case when centering things and removes a bunch of boilerplate as a result. --- examples/custom_shader/src/main.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'examples/custom_shader') diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index aa3dafe9..463b2df9 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -4,7 +4,7 @@ use scene::Scene; use iced::time::Instant; use iced::widget::shader::wgpu; -use iced::widget::{checkbox, column, container, row, shader, slider, text}; +use iced::widget::{center, checkbox, column, row, shader, slider, text}; use iced::window; use iced::{Alignment, Color, Element, Length, Subscription}; @@ -123,12 +123,7 @@ impl IcedCubes { let shader = shader(&self.scene).width(Length::Fill).height(Length::Fill); - container(column![shader, controls].align_items(Alignment::Center)) - .width(Length::Fill) - .height(Length::Fill) - .center_x() - .center_y() - .into() + center(column![shader, controls].align_items(Alignment::Center)).into() } fn subscription(&self) -> Subscription { -- cgit