pub struct RenderPass<'a> {
pub context: &'a mut FrameContext,
/* private fields */
}Expand description
A render pass wrapper that automatically returns the encoder to the frame context.
Fields§
§context: &'a mut FrameContextImplementations§
Source§impl<'a> RenderPass<'a>
impl<'a> RenderPass<'a>
Sourcepub fn descriptor(&mut self) -> &mut RenderPass<'static>
pub fn descriptor(&mut self) -> &mut RenderPass<'static>
Examples found in repository?
241 fn render(
242 &mut self,
243 _ctx: &mut astrelis_winit::app::AppCtx,
244 window_id: WindowId,
245 events: &mut astrelis_winit::event::EventBatch,
246 ) {
247 if window_id != self.window_id {
248 return;
249 }
250
251 // Handle window resize events
252 events.dispatch(|event| {
253 if let astrelis_winit::event::Event::WindowResized(size) = event {
254 self.window.resized(*size);
255 astrelis_winit::event::HandleStatus::consumed()
256 } else {
257 astrelis_winit::event::HandleStatus::ignored()
258 }
259 });
260
261 let mut frame = self.window.begin_drawing();
262
263 // Render with automatic scoping (no manual {} block needed)
264 frame.clear_and_render(
265 RenderTarget::Surface,
266 Color::rgb(0.1, 0.2, 0.3),
267 |pass| {
268 let pass = pass.descriptor();
269 pass.set_pipeline(&self.pipeline);
270 pass.set_bind_group(0, &self.bind_group, &[]);
271 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
272 pass.draw(0..6, 0..1);
273 },
274 );
275
276 frame.finish();
277 }More examples
386 fn render(
387 &mut self,
388 _ctx: &mut astrelis_winit::app::AppCtx,
389 window_id: WindowId,
390 events: &mut astrelis_winit::event::EventBatch,
391 ) {
392 let Some(window) = self.windows.get_mut(&window_id) else {
393 return;
394 };
395
396 // Handle resize
397 events.dispatch(|event| {
398 if let astrelis_winit::event::Event::WindowResized(size) = event {
399 window.resized(*size);
400 astrelis_winit::event::HandleStatus::consumed()
401 } else {
402 astrelis_winit::event::HandleStatus::ignored()
403 }
404 });
405
406 let mut frame = window.begin_drawing();
407
408 // Render with automatic scoping (no manual {} block needed)
409 frame.clear_and_render(
410 RenderTarget::Surface,
411 Color::rgb(0.1, 0.1, 0.15),
412 |pass| {
413 let pass = pass.descriptor();
414 pass.set_pipeline(&self.pipeline);
415 pass.set_bind_group(0, &self.bind_group, &[]);
416 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
417 pass.draw(0..6, 0..1);
418 },
419 );
420
421 frame.finish();
422 }444 fn render(
445 &mut self,
446 _ctx: &mut astrelis_winit::app::AppCtx,
447 window_id: WindowId,
448 events: &mut astrelis_winit::event::EventBatch,
449 ) {
450 let Some(window) = self.windows.get_mut(&window_id) else {
451 return;
452 };
453
454 // Handle resize
455 events.dispatch(|event| {
456 if let astrelis_winit::event::Event::WindowResized(size) = event {
457 window.resized(*size);
458 astrelis_winit::event::HandleStatus::consumed()
459 } else {
460 astrelis_winit::event::HandleStatus::ignored()
461 }
462 });
463
464 let mut frame = window.begin_drawing();
465
466 // Render with automatic scoping (no manual {} block needed)
467 frame.clear_and_render(
468 RenderTarget::Surface,
469 Color::rgb(0.05, 0.05, 0.08),
470 |pass| {
471 let pass = pass.descriptor();
472 pass.set_pipeline(&self.pipeline);
473 pass.set_bind_group(0, &self.bind_group, &[]);
474 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
475 pass.draw(0..6, 0..1);
476 },
477 );
478
479 frame.finish();
480 }277 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
278 if window_id != self.window_id {
279 return;
280 }
281
282 // Handle window-specific resize events
283 events.dispatch(|event| {
284 if let astrelis_winit::event::Event::WindowResized(size) = event {
285 self.window.resized(*size);
286 astrelis_winit::event::HandleStatus::consumed()
287 } else {
288 astrelis_winit::event::HandleStatus::ignored()
289 }
290 });
291
292 let mut frame = self.window.begin_drawing();
293
294 // Pass 1: Render to offscreen framebuffer with automatic scoping
295 frame.clear_and_render(
296 RenderTarget::Framebuffer(&self.offscreen_fb),
297 Color::rgb(0.2, 0.1, 0.3),
298 |pass| {
299 let pass = pass.descriptor();
300 pass.set_pipeline(&self.pipeline);
301 pass.set_bind_group(0, &self.bind_group, &[]);
302 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
303 pass.draw(0..6, 0..1);
304 },
305 );
306
307 // Pass 2: Blit framebuffer to surface with automatic scoping
308 frame.clear_and_render(
309 RenderTarget::Surface,
310 Color::rgb(0.1, 0.2, 0.3),
311 |pass| {
312 let pass = pass.descriptor();
313 pass.set_pipeline(&self.blit_pipeline);
314 pass.set_bind_group(0, &self.blit_bind_group, &[]);
315 // Draw fullscreen triangle
316 pass.draw(0..3, 0..1);
317 },
318 );
319
320 frame.finish();
321 }pub fn finish(self)
Sourcepub fn set_viewport_physical(
&mut self,
rect: PhysicalRect<f32>,
min_depth: f32,
max_depth: f32,
)
pub fn set_viewport_physical( &mut self, rect: PhysicalRect<f32>, min_depth: f32, max_depth: f32, )
Set the viewport using physical coordinates.
The viewport defines the transformation from normalized device coordinates to window coordinates.
§Arguments
rect- The viewport rectangle in physical (pixel) coordinatesmin_depth- Minimum depth value (typically 0.0)max_depth- Maximum depth value (typically 1.0)
Sourcepub fn set_viewport_logical(
&mut self,
rect: LogicalRect<f32>,
min_depth: f32,
max_depth: f32,
scale: ScaleFactor,
)
pub fn set_viewport_logical( &mut self, rect: LogicalRect<f32>, min_depth: f32, max_depth: f32, scale: ScaleFactor, )
Set the viewport using logical coordinates (converts with scale factor).
§Arguments
rect- The viewport rectangle in logical coordinatesmin_depth- Minimum depth value (typically 0.0)max_depth- Maximum depth value (typically 1.0)scale- Scale factor for logical to physical conversion
Sourcepub fn set_viewport(&mut self, viewport: &Viewport)
pub fn set_viewport(&mut self, viewport: &Viewport)
Set the viewport from a Viewport struct.
Uses the viewport’s position and size, with depth range 0.0 to 1.0.
Sourcepub fn set_scissor_physical(&mut self, rect: PhysicalRect<u32>)
pub fn set_scissor_physical(&mut self, rect: PhysicalRect<u32>)
Set the scissor rectangle using physical coordinates.
The scissor rectangle defines the area of the render target that can be modified by drawing commands.
§Arguments
rect- The scissor rectangle in physical (pixel) coordinates
Sourcepub fn set_scissor_logical(
&mut self,
rect: LogicalRect<f32>,
scale: ScaleFactor,
)
pub fn set_scissor_logical( &mut self, rect: LogicalRect<f32>, scale: ScaleFactor, )
Set the scissor rectangle using logical coordinates.
§Arguments
rect- The scissor rectangle in logical coordinatesscale- Scale factor for logical to physical conversion
Sourcepub fn set_pipeline(&mut self, pipeline: &'a RenderPipeline)
pub fn set_pipeline(&mut self, pipeline: &'a RenderPipeline)
Set the pipeline for this render pass.
Sourcepub fn set_bind_group(
&mut self,
index: u32,
bind_group: &'a BindGroup,
offsets: &[u32],
)
pub fn set_bind_group( &mut self, index: u32, bind_group: &'a BindGroup, offsets: &[u32], )
Set a bind group for this render pass.
Sourcepub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>)
pub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>)
Set the vertex buffer for this render pass.
Sourcepub fn set_index_buffer(
&mut self,
buffer_slice: BufferSlice<'a>,
format: IndexFormat,
)
pub fn set_index_buffer( &mut self, buffer_slice: BufferSlice<'a>, format: IndexFormat, )
Set the index buffer for this render pass.
Sourcepub fn draw_indexed(
&mut self,
indices: Range<u32>,
base_vertex: i32,
instances: Range<u32>,
)
pub fn draw_indexed( &mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>, )
Draw indexed primitives.
Sourcepub fn insert_debug_marker(&mut self, label: &str)
pub fn insert_debug_marker(&mut self, label: &str)
Insert a debug marker.
Sourcepub fn push_debug_group(&mut self, label: &str)
pub fn push_debug_group(&mut self, label: &str)
Push a debug group.
Sourcepub fn pop_debug_group(&mut self)
pub fn pop_debug_group(&mut self)
Pop a debug group.
Sourcepub fn set_push_constants<T: Pod>(
&mut self,
stages: ShaderStages,
offset: u32,
data: &T,
)
pub fn set_push_constants<T: Pod>( &mut self, stages: ShaderStages, offset: u32, data: &T, )
Set push constants for a range of shader stages.
Push constants are a fast way to pass small amounts of data to shaders without the overhead of buffer updates. They are limited in size (typically 128-256 bytes depending on the GPU).
Requires the PUSH_CONSTANTS feature to be enabled.
§Arguments
stages- Which shader stages can access this dataoffset- Byte offset within the push constant rangedata- The data to set (must be Pod)
§Example
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct PushConstants {
transform: [[f32; 4]; 4],
color: [f32; 4],
}
let constants = PushConstants {
transform: /* ... */,
color: [1.0, 0.0, 0.0, 1.0],
};
pass.set_push_constants(
wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
0,
&constants,
);Sourcepub fn set_push_constants_raw(
&mut self,
stages: ShaderStages,
offset: u32,
data: &[u8],
)
pub fn set_push_constants_raw( &mut self, stages: ShaderStages, offset: u32, data: &[u8], )
Set push constants from raw bytes.
Use this when you need more control over the data layout.
Trait Implementations§
Source§impl<'a> AsWgpu for RenderPass<'a>
impl<'a> AsWgpu for RenderPass<'a>
Source§impl<'a> AsWgpuMut for RenderPass<'a>
impl<'a> AsWgpuMut for RenderPass<'a>
Source§fn as_wgpu_mut(&mut self) -> &mut Self::WgpuType
fn as_wgpu_mut(&mut self) -> &mut Self::WgpuType
Source§impl Drop for RenderPass<'_>
impl Drop for RenderPass<'_>
Source§impl<'a> RenderPassRawExt<'a> for RenderPass<'a>
impl<'a> RenderPassRawExt<'a> for RenderPass<'a>
Source§fn raw_pass(&mut self) -> &mut RenderPass<'static>
fn raw_pass(&mut self) -> &mut RenderPass<'static>
Source§fn graphics_context(&self) -> &GraphicsContext
fn graphics_context(&self) -> &GraphicsContext
Auto Trait Implementations§
impl<'a> Freeze for RenderPass<'a>
impl<'a> !RefUnwindSafe for RenderPass<'a>
impl<'a> Send for RenderPass<'a>
impl<'a> Sync for RenderPass<'a>
impl<'a> Unpin for RenderPass<'a>
impl<'a> !UnwindSafe for RenderPass<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more