RenderPass

Struct RenderPass 

Source
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 FrameContext

Implementations§

Source§

impl<'a> RenderPass<'a>

Source

pub fn descriptor(&mut self) -> &mut RenderPass<'static>

Examples found in repository?
examples/textured_window.rs (line 268)
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
Hide additional examples
examples/sprite_sheet.rs (line 413)
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    }
examples/image_blitting.rs (line 471)
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    }
examples/renderer_api.rs (line 299)
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    }
Source

pub fn finish(self)

Source

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) coordinates
  • min_depth - Minimum depth value (typically 0.0)
  • max_depth - Maximum depth value (typically 1.0)
Source

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 coordinates
  • min_depth - Minimum depth value (typically 0.0)
  • max_depth - Maximum depth value (typically 1.0)
  • scale - Scale factor for logical to physical conversion
Source

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.

Source

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
Source

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 coordinates
  • scale - Scale factor for logical to physical conversion
Source

pub fn set_pipeline(&mut self, pipeline: &'a RenderPipeline)

Set the pipeline for this render pass.

Source

pub fn set_bind_group( &mut self, index: u32, bind_group: &'a BindGroup, offsets: &[u32], )

Set a bind group for this render pass.

Source

pub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>)

Set the vertex buffer for this render pass.

Source

pub fn set_index_buffer( &mut self, buffer_slice: BufferSlice<'a>, format: IndexFormat, )

Set the index buffer for this render pass.

Source

pub fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>)

Draw primitives.

Source

pub fn draw_indexed( &mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>, )

Draw indexed primitives.

Source

pub fn insert_debug_marker(&mut self, label: &str)

Insert a debug marker.

Source

pub fn push_debug_group(&mut self, label: &str)

Push a debug group.

Source

pub fn pop_debug_group(&mut self)

Pop a debug group.

Source

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 data
  • offset - Byte offset within the push constant range
  • data - 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,
);
Source

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>

Source§

type WgpuType = RenderPass<'static>

The underlying wgpu type.
Source§

fn as_wgpu(&self) -> &Self::WgpuType

Get a reference to the underlying wgpu type.
Source§

impl<'a> AsWgpuMut for RenderPass<'a>

Source§

fn as_wgpu_mut(&mut self) -> &mut Self::WgpuType

Get a mutable reference to the underlying wgpu type.
Source§

impl Drop for RenderPass<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> RenderPassRawExt<'a> for RenderPass<'a>

Source§

fn raw_pass(&mut self) -> &mut RenderPass<'static>

Get raw access to the underlying wgpu render pass.
Source§

fn graphics_context(&self) -> &GraphicsContext

Get the graphics context.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,