FrameContext

Struct FrameContext 

Source
pub struct FrameContext {
    pub context: Arc<GraphicsContext>,
    /* private fields */
}
Expand description

Context for a single frame of rendering.

Fields§

§context: Arc<GraphicsContext>

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) -> &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/camera_demo.rs (line 110)
90    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91        if window_id != self.window_id {
92            return;
93        }
94
95        events.dispatch(|event| {
96            if let astrelis_winit::event::Event::WindowResized(size) = event {
97                self.window.resized(*size);
98                astrelis_winit::event::HandleStatus::consumed()
99            } else {
100                astrelis_winit::event::HandleStatus::ignored()
101            }
102        });
103
104        let mut frame = self.window.begin_drawing();
105        frame.clear_and_render(
106            RenderTarget::Surface,
107            Color::from_rgb_u8(20, 30, 40),
108            |_pass| {},
109        );
110        frame.finish();
111    }
More examples
Hide additional examples
examples/mesh_primitives.rs (line 113)
93    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
94        if window_id != self.window_id {
95            return;
96        }
97
98        events.dispatch(|event| {
99            if let astrelis_winit::event::Event::WindowResized(size) = event {
100                self.window.resized(*size);
101                astrelis_winit::event::HandleStatus::consumed()
102            } else {
103                astrelis_winit::event::HandleStatus::ignored()
104            }
105        });
106
107        let mut frame = self.window.begin_drawing();
108        frame.clear_and_render(
109            RenderTarget::Surface,
110            Color::from_rgb_u8(20, 30, 40),
111            |_pass| {},
112        );
113        frame.finish();
114    }
examples/render_graph_demo.rs (line 110)
90    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91        if window_id != self.window_id {
92            return;
93        }
94
95        events.dispatch(|event| {
96            if let astrelis_winit::event::Event::WindowResized(size) = event {
97                self.window.resized(*size);
98                astrelis_winit::event::HandleStatus::consumed()
99            } else {
100                astrelis_winit::event::HandleStatus::ignored()
101            }
102        });
103
104        let mut frame = self.window.begin_drawing();
105        frame.clear_and_render(
106            RenderTarget::Surface,
107            Color::from_rgb_u8(20, 30, 40),
108            |_pass| {},
109        );
110        frame.finish();
111    }
examples/window_manager_demo.rs (line 100)
78    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
79        // Get the color for this window
80        let Some(&color) = self.window_colors.get(&window_id) else {
81            return;
82        };
83
84        // WindowManager automatically handles:
85        // 1. Window lookup (no manual HashMap.get_mut)
86        // 2. Resize events (automatic)
87        // 3. Event dispatching
88        self.window_manager
89            .render_window(window_id, events, |window, _events| {
90                // No need to manually handle resize events!
91                // WindowManager already did that for us
92
93                // Just render!
94                let mut frame = window.begin_drawing();
95
96                frame.clear_and_render(RenderTarget::Surface, color, |_pass| {
97                    // Additional rendering would go here
98                });
99
100                frame.finish();
101            });
102    }
examples/material_system.rs (line 138)
107    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
108        if window_id != self.window_id {
109            return;
110        }
111
112        // Handle resize
113        events.dispatch(|event| {
114            if let astrelis_winit::event::Event::WindowResized(size) = event {
115                self.window.resized(*size);
116                astrelis_winit::event::HandleStatus::consumed()
117            } else {
118                astrelis_winit::event::HandleStatus::ignored()
119            }
120        });
121
122        // In a real application, materials would be bound during rendering:
123        // material.bind(&mut render_pass);
124        // draw_mesh(&mesh);
125
126        // Begin frame
127        let mut frame = self.window.begin_drawing();
128
129        frame.clear_and_render(
130            RenderTarget::Surface,
131            Color::from_rgb_u8(20, 30, 40),
132            |_pass| {
133                // Materials would be applied here in actual rendering
134                // This is a conceptual demonstration
135            },
136        );
137
138        frame.finish();
139    }
examples/multi_window.rs (line 126)
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        // Render with automatic scoping (no manual {} block needed)
118        frame.clear_and_render(
119            RenderTarget::Surface,
120            astrelis_render::Color::rgba(color.r as f32, color.g as f32, color.b as f32, color.a as f32),
121            |_pass| {
122                // Just clearing - no rendering commands needed
123            },
124        );
125
126        frame.finish();
127    }
Source

pub fn with_pass<'a, F>(&'a mut self, builder: RenderPassBuilder<'a>, f: F)
where F: FnOnce(&mut RenderPass<'a>),

Execute a closure with a render pass, automatically handling scoping.

This is the ergonomic RAII pattern that eliminates the need for manual { } blocks. The render pass is automatically dropped after the closure completes.

§Example
frame.with_pass(
    RenderPassBuilder::new()
        .target(RenderTarget::Surface)
        .clear_color(Color::BLACK),
    |pass| {
        // Render commands here
        // pass automatically drops when closure ends
    }
);
frame.finish();
Source

pub fn clear_and_render<'a, F>( &'a mut self, target: RenderTarget<'a>, clear_color: impl Into<Color>, f: F, )
where F: FnOnce(&mut RenderPass<'a>),

Convenience method to clear to a color and execute rendering commands.

This is the most common pattern - clear the surface and render.

§Example
frame.clear_and_render(
    RenderTarget::Surface,
    Color::BLACK,
    |pass| {
        // Render your content here
        // Example: ui.render(pass.descriptor());
    }
);
frame.finish();
Examples found in repository?
examples/camera_demo.rs (lines 105-109)
90    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91        if window_id != self.window_id {
92            return;
93        }
94
95        events.dispatch(|event| {
96            if let astrelis_winit::event::Event::WindowResized(size) = event {
97                self.window.resized(*size);
98                astrelis_winit::event::HandleStatus::consumed()
99            } else {
100                astrelis_winit::event::HandleStatus::ignored()
101            }
102        });
103
104        let mut frame = self.window.begin_drawing();
105        frame.clear_and_render(
106            RenderTarget::Surface,
107            Color::from_rgb_u8(20, 30, 40),
108            |_pass| {},
109        );
110        frame.finish();
111    }
More examples
Hide additional examples
examples/mesh_primitives.rs (lines 108-112)
93    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
94        if window_id != self.window_id {
95            return;
96        }
97
98        events.dispatch(|event| {
99            if let astrelis_winit::event::Event::WindowResized(size) = event {
100                self.window.resized(*size);
101                astrelis_winit::event::HandleStatus::consumed()
102            } else {
103                astrelis_winit::event::HandleStatus::ignored()
104            }
105        });
106
107        let mut frame = self.window.begin_drawing();
108        frame.clear_and_render(
109            RenderTarget::Surface,
110            Color::from_rgb_u8(20, 30, 40),
111            |_pass| {},
112        );
113        frame.finish();
114    }
examples/render_graph_demo.rs (lines 105-109)
90    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91        if window_id != self.window_id {
92            return;
93        }
94
95        events.dispatch(|event| {
96            if let astrelis_winit::event::Event::WindowResized(size) = event {
97                self.window.resized(*size);
98                astrelis_winit::event::HandleStatus::consumed()
99            } else {
100                astrelis_winit::event::HandleStatus::ignored()
101            }
102        });
103
104        let mut frame = self.window.begin_drawing();
105        frame.clear_and_render(
106            RenderTarget::Surface,
107            Color::from_rgb_u8(20, 30, 40),
108            |_pass| {},
109        );
110        frame.finish();
111    }
examples/window_manager_demo.rs (lines 96-98)
78    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
79        // Get the color for this window
80        let Some(&color) = self.window_colors.get(&window_id) else {
81            return;
82        };
83
84        // WindowManager automatically handles:
85        // 1. Window lookup (no manual HashMap.get_mut)
86        // 2. Resize events (automatic)
87        // 3. Event dispatching
88        self.window_manager
89            .render_window(window_id, events, |window, _events| {
90                // No need to manually handle resize events!
91                // WindowManager already did that for us
92
93                // Just render!
94                let mut frame = window.begin_drawing();
95
96                frame.clear_and_render(RenderTarget::Surface, color, |_pass| {
97                    // Additional rendering would go here
98                });
99
100                frame.finish();
101            });
102    }
examples/material_system.rs (lines 129-136)
107    fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
108        if window_id != self.window_id {
109            return;
110        }
111
112        // Handle resize
113        events.dispatch(|event| {
114            if let astrelis_winit::event::Event::WindowResized(size) = event {
115                self.window.resized(*size);
116                astrelis_winit::event::HandleStatus::consumed()
117            } else {
118                astrelis_winit::event::HandleStatus::ignored()
119            }
120        });
121
122        // In a real application, materials would be bound during rendering:
123        // material.bind(&mut render_pass);
124        // draw_mesh(&mesh);
125
126        // Begin frame
127        let mut frame = self.window.begin_drawing();
128
129        frame.clear_and_render(
130            RenderTarget::Surface,
131            Color::from_rgb_u8(20, 30, 40),
132            |_pass| {
133                // Materials would be applied here in actual rendering
134                // This is a conceptual demonstration
135            },
136        );
137
138        frame.finish();
139    }
examples/multi_window.rs (lines 118-124)
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        // Render with automatic scoping (no manual {} block needed)
118        frame.clear_and_render(
119            RenderTarget::Surface,
120            astrelis_render::Color::rgba(color.r as f32, color.g as f32, color.b as f32, color.a as f32),
121            |_pass| {
122                // Just clearing - no rendering commands needed
123            },
124        );
125
126        frame.finish();
127    }

Trait Implementations§

Source§

impl<'a> AsWgpu for FrameContext

Source§

type WgpuType = CommandEncoder

The underlying wgpu type.
Source§

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

Get a reference to the underlying wgpu type.
Source§

impl<'a> AsWgpuMut for FrameContext

Source§

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

Get a mutable reference to the underlying wgpu type.
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 FrameContextExt for FrameContext

Source§

fn encoder_ref(&self) -> Option<&CommandEncoder>

Get direct access to the command encoder.
Source§

fn encoder_mut(&mut self) -> Option<&mut CommandEncoder>

Get mutable access to the command encoder.
Source§

fn surface_view(&self) -> &TextureView

Get the surface texture view for this frame.
Source§

fn surface_texture(&self) -> &Texture

Get the surface texture for this frame.
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 + 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,