FrameContext

Struct FrameContext 

Source
pub struct FrameContext { /* private fields */ }
Expand description

Context for a single frame of rendering.

Implementations§

Source§

impl FrameContext

Source

pub fn surface(&self) -> &Surface

Source

pub fn surface_format(&self) -> TextureFormat

Source

pub fn increment_passes(&mut self)

Source

pub fn increment_draw_calls(&mut self)

Source

pub fn stats(&self) -> &FrameStats

Source

pub fn graphics_context(&self) -> &'static GraphicsContext

Source

pub fn encoder(&mut self) -> &mut CommandEncoder

Source

pub fn encoder_and_surface(&mut self) -> (&mut CommandEncoder, &Surface)

Source

pub fn finish(self)

Examples found in repository?
examples/multi_window.rs (line 125)
93    fn render(
94        &mut self,
95        _ctx: &mut astrelis_winit::app::AppCtx,
96        window_id: WindowId,
97        events: &mut astrelis_winit::event::EventBatch,
98    ) {
99        // Get the window and color for this specific window
100        let Some((window, color)) = self.windows.get_mut(&window_id) else {
101            return;
102        };
103
104        // Handle window-specific resize events
105        events.dispatch(|event| {
106            if let astrelis_winit::event::Event::WindowResized(size) = event {
107                window.resized(*size);
108                astrelis_winit::event::HandleStatus::consumed()
109            } else {
110                astrelis_winit::event::HandleStatus::ignored()
111            }
112        });
113
114        // Render this specific window
115        let mut frame = window.begin_drawing();
116
117        {
118            let _render_pass = RenderPassBuilder::new()
119                .label("Multi-Window Render Pass")
120                .target(RenderTarget::Surface)
121                .clear_color(*color)
122                .build(&mut frame);
123        }
124
125        frame.finish();
126    }
More examples
Hide additional examples
examples/image_blitting.rs (line 485)
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        {
467            let mut render_pass = RenderPassBuilder::new()
468                .label("Blit Render Pass")
469                .target(RenderTarget::Surface)
470                .clear_color(wgpu::Color {
471                    r: 0.05,
472                    g: 0.05,
473                    b: 0.08,
474                    a: 1.0,
475                })
476                .build(&mut frame);
477
478            let pass = render_pass.descriptor();
479            pass.set_pipeline(&self.pipeline);
480            pass.set_bind_group(0, &self.bind_group, &[]);
481            pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
482            pass.draw(0..6, 0..1);
483        }
484
485        frame.finish();
486    }
examples/sprite_sheet.rs (line 427)
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        {
409            let mut render_pass = RenderPassBuilder::new()
410                .label("Sprite Render Pass")
411                .target(RenderTarget::Surface)
412                .clear_color(wgpu::Color {
413                    r: 0.1,
414                    g: 0.1,
415                    b: 0.15,
416                    a: 1.0,
417                })
418                .build(&mut frame);
419
420            let pass = render_pass.descriptor();
421            pass.set_pipeline(&self.pipeline);
422            pass.set_bind_group(0, &self.bind_group, &[]);
423            pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
424            pass.draw(0..6, 0..1);
425        }
426
427        frame.finish();
428    }
examples/textured_window.rs (line 283)
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        // Using new simplified RenderPassBuilder API with RenderTarget
264        {
265            let mut render_pass = RenderPassBuilder::new()
266                .label("Render Pass")
267                .target(RenderTarget::Surface)
268                .clear_color(wgpu::Color {
269                    r: 0.1,
270                    g: 0.2,
271                    b: 0.3,
272                    a: 1.0,
273                })
274                .build(&mut frame);
275
276            let pass = render_pass.descriptor();
277            pass.set_pipeline(&self.pipeline);
278            pass.set_bind_group(0, &self.bind_group, &[]);
279            pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
280            pass.draw(0..6, 0..1);
281        }
282
283        frame.finish();
284    }
examples/renderer_api.rs (line 333)
276    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
277        if window_id != self.window_id {
278            return;
279        }
280
281        // Handle window-specific resize events
282        events.dispatch(|event| {
283            if let astrelis_winit::event::Event::WindowResized(size) = event {
284                self.window.resized(*size);
285                astrelis_winit::event::HandleStatus::consumed()
286            } else {
287                astrelis_winit::event::HandleStatus::ignored()
288            }
289        });
290
291        let mut frame = self.window.begin_drawing();
292
293        // Pass 1: Render to offscreen framebuffer using new simplified API
294        {
295            let mut render_pass = RenderPassBuilder::new()
296                .label("Offscreen Pass")
297                .target(RenderTarget::Framebuffer(&self.offscreen_fb))
298                .clear_color(wgpu::Color {
299                    r: 0.2,
300                    g: 0.1,
301                    b: 0.3,
302                    a: 1.0,
303                })
304                .build(&mut frame);
305
306            let pass = render_pass.descriptor();
307            pass.set_pipeline(&self.pipeline);
308            pass.set_bind_group(0, &self.bind_group, &[]);
309            pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
310            pass.draw(0..6, 0..1);
311        }
312
313        // Pass 2: Blit framebuffer to surface using new simplified API
314        {
315            let mut render_pass = RenderPassBuilder::new()
316                .label("Surface Pass")
317                .target(RenderTarget::Surface)
318                .clear_color(wgpu::Color {
319                    r: 0.1,
320                    g: 0.2,
321                    b: 0.3,
322                    a: 1.0,
323                })
324                .build(&mut frame);
325
326            let pass = render_pass.descriptor();
327            pass.set_pipeline(&self.blit_pipeline);
328            pass.set_bind_group(0, &self.blit_bind_group, &[]);
329            // Draw fullscreen triangle
330            pass.draw(0..3, 0..1);
331        }
332
333        frame.finish();
334    }

Trait Implementations§

Source§

impl ComputePassExt for FrameContext

Source§

fn compute_pass<'a>(&'a mut self, label: &'a str) -> ComputePass<'a>

Create a compute pass with a label.
Source§

fn compute_pass_unlabeled(&mut self) -> ComputePass<'_>

Create a compute pass without a label.
Source§

impl Drop for FrameContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl RenderPassExt for FrameContext

Source§

fn clear_pass<'a>( &'a mut self, target: RenderTarget<'a>, clear_color: Color, ) -> RenderPass<'a>

Create a render pass that clears to the given color.
Source§

fn load_pass<'a>(&'a mut self, target: RenderTarget<'a>) -> RenderPass<'a>

Create a render pass that loads existing content.

Auto Trait Implementations§

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 + Send + Sync>

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,