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
impl FrameContext
pub fn surface(&self) -> &Surface
pub fn surface_format(&self) -> TextureFormat
pub fn increment_passes(&mut self)
pub fn increment_draw_calls(&mut self)
pub fn stats(&self) -> &FrameStats
pub fn graphics_context(&self) -> &GraphicsContext
pub fn encoder(&mut self) -> &mut CommandEncoder
pub fn encoder_and_surface(&mut self) -> (&mut CommandEncoder, &Surface)
Sourcepub fn finish(self)
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
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 }Additional examples can be found in:
Sourcepub fn with_pass<'a, F>(&'a mut self, builder: RenderPassBuilder<'a>, f: F)where
F: FnOnce(&mut RenderPass<'a>),
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();Sourcepub 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>),
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
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 }Additional examples can be found in:
Trait Implementations§
Source§impl<'a> AsWgpu for FrameContext
impl<'a> AsWgpu for FrameContext
Source§impl<'a> AsWgpuMut for FrameContext
impl<'a> AsWgpuMut for FrameContext
Source§fn as_wgpu_mut(&mut self) -> &mut Self::WgpuType
fn as_wgpu_mut(&mut self) -> &mut Self::WgpuType
Get a mutable reference to the underlying wgpu type.
Source§impl ComputePassExt for FrameContext
impl ComputePassExt for FrameContext
Source§fn compute_pass<'a>(&'a mut self, label: &'a str) -> ComputePass<'a>
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<'_>
fn compute_pass_unlabeled(&mut self) -> ComputePass<'_>
Create a compute pass without a label.
Source§impl Drop for FrameContext
impl Drop for FrameContext
Source§impl FrameContextExt for FrameContext
impl FrameContextExt for FrameContext
Source§fn encoder_ref(&self) -> Option<&CommandEncoder>
fn encoder_ref(&self) -> Option<&CommandEncoder>
Get direct access to the command encoder.
Source§fn encoder_mut(&mut self) -> Option<&mut CommandEncoder>
fn encoder_mut(&mut self) -> Option<&mut CommandEncoder>
Get mutable access to the command encoder.
Source§fn surface_view(&self) -> &TextureView
fn surface_view(&self) -> &TextureView
Get the surface texture view for this frame.
Source§fn surface_texture(&self) -> &Texture
fn surface_texture(&self) -> &Texture
Get the surface texture for this frame.
Source§impl RenderPassExt for FrameContext
impl RenderPassExt for FrameContext
Source§fn clear_pass<'a>(
&'a mut self,
target: RenderTarget<'a>,
clear_color: Color,
) -> RenderPass<'a>
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>
fn load_pass<'a>(&'a mut self, target: RenderTarget<'a>) -> RenderPass<'a>
Create a render pass that loads existing content.
Auto Trait Implementations§
impl Freeze for FrameContext
impl !RefUnwindSafe for FrameContext
impl Send for FrameContext
impl Sync for FrameContext
impl Unpin for FrameContext
impl !UnwindSafe for FrameContext
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
Mutably borrows from an owned value. Read more
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>
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>
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)
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)
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
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>
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 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>
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