From b70ebad5bae738aece21f35c334b36f5ef8a9fe2 Mon Sep 17 00:00:00 2001 From: Katt <51190960+coolcatcoder@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:11:15 +0800 Subject: [PATCH] fix triangle-util and viewport extent docs --- examples/triangle-util/main.rs | 22 ++++++---------------- vulkano/src/pipeline/graphics/viewport.rs | 3 +-- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index db297d7101..cc3f55ab3f 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -62,7 +62,6 @@ struct RenderContext { render_pass: Arc, framebuffers: Vec>, pipeline: Arc, - viewport: Viewport, } impl App { @@ -133,7 +132,6 @@ impl ApplicationHandler for App { self.windows .create_window(event_loop, &self.context, &Default::default(), |_| {}); let window_renderer = self.windows.get_primary_renderer_mut().unwrap(); - let window_size = window_renderer.window().inner_size(); // The next step is to create the shaders. // @@ -315,14 +313,6 @@ impl ApplicationHandler for App { .unwrap() }; - // Dynamic viewports allow us to recreate just the viewport when the window is resized. - // Otherwise we would have to recreate the whole pipeline. - let viewport = Viewport { - offset: [0.0, 0.0], - extent: window_size.into(), - depth_range: 0.0..=1.0, - }; - // In the `window_event` handler below we are going to submit commands to the GPU. // Submitting a command produces an object that implements the `GpuFuture` trait, which // holds the resources for as long as they are in use by the GPU. @@ -331,7 +321,6 @@ impl ApplicationHandler for App { render_pass, framebuffers, pipeline, - viewport, }); } @@ -363,10 +352,8 @@ impl ApplicationHandler for App { // Begin rendering by acquiring the gpu future from the window renderer. let previous_frame_end = window_renderer .acquire(Some(Duration::from_millis(1000)), |swapchain_images| { - // Whenever the window resizes we need to recreate everything dependent - // on the window size. In this example that - // includes the swapchain, the framebuffers - // and the dynamic state viewport. + // Whenever the swapchain gets recreated, we need to recreate everything dependent upon it. + // In this example, that is only the framebuffers. rcx.framebuffers = window_size_dependent_setup(swapchain_images, &rcx.render_pass); }) @@ -416,7 +403,10 @@ impl ApplicationHandler for App { // We are now inside the first subpass of the render pass. // // TODO: Document state setting and how it affects subsequent draw commands. - .set_viewport(0, [rcx.viewport.clone()].into_iter().collect()) + .set_viewport(0, [Viewport { + extent: window_size.into(), + ..Default::default() + }].into_iter().collect()) .unwrap() .bind_pipeline_graphics(rcx.pipeline.clone()) .unwrap() diff --git a/vulkano/src/pipeline/graphics/viewport.rs b/vulkano/src/pipeline/graphics/viewport.rs index ab12c71bb8..9138a6ef0b 100644 --- a/vulkano/src/pipeline/graphics/viewport.rs +++ b/vulkano/src/pipeline/graphics/viewport.rs @@ -281,8 +281,7 @@ pub struct Viewport { /// Dimensions in pixels of the viewport. /// - /// The default value is `[1.0; 2]`, which you probably want to override if you are not - /// using dynamic state. + /// The default value is `[1.0; 2]`, which you probably want to override. pub extent: [f32; 2], /// Minimum and maximum values of the depth.