diff --git a/docs/01-rainbow-triangle.md b/docs/01-rainbow-triangle.md index a294ee3..9a931ab 100644 --- a/docs/01-rainbow-triangle.md +++ b/docs/01-rainbow-triangle.md @@ -217,6 +217,7 @@ struct State { device: wgpu::Device, queue: wgpu::Queue, config: wgpu::SurfaceConfiguration, + window: Arc, pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, } @@ -235,6 +236,12 @@ struct State { - **`config`** — holds the surface's current width, height, pixel format, and [present mode](concepts/GLOSSARY.md#present-mode). When the window is resized, we reconfigure the surface with updated dimensions. +- **`window`** — shared reference to the winit window. Stored as an `Arc` so + the `resize()` method and the `SurfaceError::Outdated` recovery handler can + access the window's current dimensions. When the surface becomes outdated + (e.g., after a compositor restart or display hotplug), recovery requires + reconfiguring the swapchain with the window's live size — and that requires + holding a reference to the window itself. - **`pipeline`** — the compiled [render pipeline](concepts/GLOSSARY.md#render-pipeline). A render pipeline is an immutable configuration combining a shader, a vertex buffer layout, a primitive topology, and a [color target](concepts/GLOSSARY.md#color-target) @@ -389,6 +396,7 @@ impl State { device, queue, config, + window: Arc::clone(&window), pipeline, vertex_buffer, }) @@ -964,6 +972,11 @@ fn render(&mut self) { }; self.resize(size); } + // The window field stored in State enables Outdated recovery: + // when the compositor or display server invalidates the surface, + // we can reconfigure the swapchain using the window's current + // dimensions (self.window.inner_size()) without needing a + // separate reference to the window from the event loop. wgpu::SurfaceError::Lost => { log::error!("Surface error: Lost — cannot recover without re-creating State"); }