pub struct RenderableWindow { /* private fields */ }Expand description
A renderable window that combines a window with a rendering context.
Implementations§
Source§impl RenderableWindow
impl RenderableWindow
pub fn new( window: Window, context: Arc<GraphicsContext>, ) -> Result<Self, GraphicsError>
Sourcepub fn new_with_descriptor(
window: Window,
context: Arc<GraphicsContext>,
descriptor: WindowContextDescriptor,
) -> Result<Self, GraphicsError>
pub fn new_with_descriptor( window: Window, context: Arc<GraphicsContext>, descriptor: WindowContextDescriptor, ) -> Result<Self, GraphicsError>
Examples found in repository?
examples/multi_window.rs (lines 67-74)
28fn main() {
29 logging::init();
30
31 run_app(|ctx| {
32 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
33
34 let mut windows = HashMap::new();
35
36 // Create 3 windows with different colors
37 let colors = [
38 wgpu::Color {
39 r: 0.8,
40 g: 0.2,
41 b: 0.2,
42 a: 1.0,
43 },
44 wgpu::Color {
45 r: 0.2,
46 g: 0.8,
47 b: 0.2,
48 a: 1.0,
49 },
50 wgpu::Color {
51 r: 0.2,
52 g: 0.2,
53 b: 0.8,
54 a: 1.0,
55 },
56 ];
57
58 for (i, color) in colors.iter().enumerate() {
59 let window = ctx
60 .create_window(WindowDescriptor {
61 title: format!("Window {} - Multi-Window Example", i + 1),
62 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
63 ..Default::default()
64 })
65 .expect("Failed to create window");
66
67 let renderable_window = RenderableWindow::new_with_descriptor(
68 window,
69 graphics_ctx.clone(),
70 WindowContextDescriptor {
71 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
72 ..Default::default()
73 },
74 ).expect("Failed to create renderable window");
75
76 let window_id = renderable_window.id();
77 windows.insert(window_id, (renderable_window, *color));
78 }
79
80 Box::new(App {
81 context: graphics_ctx,
82 windows,
83 })
84 });
85}More examples
examples/performance_benchmark.rs (lines 50-57)
36fn main() {
37 logging::init();
38
39 run_app(|ctx| {
40 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
41
42 let window = ctx
43 .create_window(WindowDescriptor {
44 title: "Performance Benchmark - Render Stress Test".to_string(),
45 size: Some(WinitPhysicalSize::new(1280.0, 720.0)),
46 ..Default::default()
47 })
48 .expect("Failed to create window");
49
50 let window = RenderableWindow::new_with_descriptor(
51 window,
52 graphics_ctx.clone(),
53 WindowContextDescriptor {
54 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
55 ..Default::default()
56 },
57 ).expect("Failed to create renderable window");
58
59 let window_id = window.id();
60
61 println!("\n═══════════════════════════════════════════════════════");
62 println!(" ⚡ PERFORMANCE BENCHMARK - Render Stress Test");
63 println!("═══════════════════════════════════════════════════════");
64 println!(" CONTROLS:");
65 println!(" [Space] Toggle rendering on/off");
66 println!(" [+/-] Increase/decrease object count");
67 println!(" Starting with 1000 objects");
68 println!("═══════════════════════════════════════════════════════\n");
69
70 Box::new(PerformanceBenchmark {
71 _context: graphics_ctx,
72 window,
73 window_id,
74 object_count: 1000,
75 rendering: true,
76 frame_count: 0,
77 last_fps_time: Instant::now(),
78 fps: 0.0,
79 last_frame_time: 0.0,
80 })
81 });
82}examples/camera_demo.rs (lines 43-50)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
34
35 let window = ctx
36 .create_window(WindowDescriptor {
37 title: "Camera Demo - View & Projection".to_string(),
38 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
39 ..Default::default()
40 })
41 .expect("Failed to create window");
42
43 let window = RenderableWindow::new_with_descriptor(
44 window,
45 graphics_ctx.clone(),
46 WindowContextDescriptor {
47 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
48 ..Default::default()
49 },
50 ).expect("Failed to create renderable window");
51
52 let window_id = window.id();
53
54 println!("\n═══════════════════════════════════════════════════════");
55 println!(" 📹 CAMERA DEMO - View & Projection");
56 println!("═══════════════════════════════════════════════════════");
57 println!("\n CAMERA API FEATURES:");
58 println!(" • Orthographic cameras (2D, UI, isometric)");
59 println!(" • Perspective cameras (3D scenes)");
60 println!(" • View matrix (position, rotation, look-at)");
61 println!(" • Projection matrix (FOV, aspect, near/far planes)");
62 println!(" • Screen-to-world coordinate conversion");
63 println!(" • Camera movement helpers");
64 println!("\n CAMERA TYPES:");
65 println!(" • OrthographicCamera - 2D games, UI overlays");
66 println!(" camera.orthographic(left, right, bottom, top, near, far)");
67 println!(" • PerspectiveCamera - 3D scenes");
68 println!(" camera.perspective(fov, aspect, near, far)");
69 println!("\n Camera API Usage:");
70 println!(" let camera = Camera::new()");
71 println!(" .position(Vec3::new(0.0, 5.0, 10.0))");
72 println!(" .look_at(Vec3::ZERO)");
73 println!(" .perspective(60.0, aspect, 0.1, 100.0);");
74 println!(" let view_proj = camera.view_projection_matrix();");
75 println!("═══════════════════════════════════════════════════════\n");
76
77 tracing::info!("Camera demo initialized");
78
79 Box::new(CameraDemo {
80 _context: graphics_ctx,
81 window,
82 window_id,
83 })
84 });
85}examples/render_graph_demo.rs (lines 42-49)
28fn main() {
29 logging::init();
30
31 run_app(|ctx| {
32 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
33
34 let window = ctx
35 .create_window(WindowDescriptor {
36 title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
37 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
38 ..Default::default()
39 })
40 .expect("Failed to create window");
41
42 let window = RenderableWindow::new_with_descriptor(
43 window,
44 graphics_ctx.clone(),
45 WindowContextDescriptor {
46 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
47 ..Default::default()
48 },
49 ).expect("Failed to create renderable window");
50
51 let window_id = window.id();
52
53 println!("\n═══════════════════════════════════════════════════════");
54 println!(" 🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
55 println!("═══════════════════════════════════════════════════════");
56 println!("\n RENDER GRAPH FEATURES:");
57 println!(" • Declarative pass definition");
58 println!(" • Automatic dependency resolution");
59 println!(" • Resource lifetime management");
60 println!(" • Parallel pass execution");
61 println!(" • Automatic optimization");
62 println!("\n EXAMPLE PIPELINE:");
63 println!(" 1. Shadow Pass → depth texture");
64 println!(" 2. Geometry Pass → color + normal + depth");
65 println!(" 3. Lighting Pass → lit scene");
66 println!(" 4. Post-Processing → bloom, tone mapping");
67 println!(" 5. UI Pass → final composite");
68 println!("\n Render Graph API Usage:");
69 println!(" let mut graph = RenderGraph::new();");
70 println!(" graph.add_pass(\"shadow\", shadow_pass_descriptor);");
71 println!(" graph.add_pass(\"geometry\", geometry_pass_descriptor);");
72 println!(" graph.add_dependency(\"lighting\", \"geometry\");");
73 println!(" graph.compile();");
74 println!(" graph.execute(&mut encoder);");
75 println!("═══════════════════════════════════════════════════════\n");
76
77 tracing::info!("Render graph demo initialized");
78
79 Box::new(RenderGraphDemo {
80 _context: graphics_ctx,
81 window,
82 window_id,
83 })
84 });
85}examples/mesh_primitives.rs (lines 43-50)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
34
35 let window = ctx
36 .create_window(WindowDescriptor {
37 title: "Mesh Primitives Demo - Geometry API".to_string(),
38 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
39 ..Default::default()
40 })
41 .expect("Failed to create window");
42
43 let window = RenderableWindow::new_with_descriptor(
44 window,
45 graphics_ctx.clone(),
46 WindowContextDescriptor {
47 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
48 ..Default::default()
49 },
50 ).expect("Failed to create renderable window");
51
52 let window_id = window.id();
53
54 println!("\n═══════════════════════════════════════════════════════");
55 println!(" 📐 MESH PRIMITIVES DEMO - Geometry API");
56 println!("═══════════════════════════════════════════════════════");
57 println!("\n MESH API FEATURES:");
58 println!(" • MeshBuilder for custom geometry");
59 println!(" • Primitive generation (cube, sphere, plane, etc.)");
60 println!(" • Flexible vertex formats (Position, Normal, UV, Color)");
61 println!(" • Index buffer optimization");
62 println!(" • Instanced rendering support");
63 println!("\n EXAMPLE PRIMITIVES:");
64 println!(" • Cube - box with 24 vertices (6 faces × 4 vertices)");
65 println!(" • Sphere - tessellated sphere with UV mapping");
66 println!(" • Plane - quad with optional subdivisions");
67 println!(" • Cylinder - sides + caps");
68 println!(" • Custom - arbitrary vertex/index data");
69 println!("\n Mesh API Usage:");
70 println!(" let mesh = MeshBuilder::new()");
71 println!(" .with_positions(vertices)");
72 println!(" .with_normals(normals)");
73 println!(" .with_uvs(uvs)");
74 println!(" .with_indices(indices)");
75 println!(" .build(&ctx);");
76 println!(" mesh.draw(&mut pass);");
77 println!(" mesh.draw_instanced(&mut pass, instance_count);");
78 println!("═══════════════════════════════════════════════════════\n");
79
80 tracing::info!("Mesh primitives demo initialized");
81
82 Box::new(MeshPrimitivesDemo {
83 _context: graphics_ctx,
84 window,
85 window_id,
86 })
87 });
88}examples/material_system.rs (lines 46-53)
32fn main() {
33 logging::init();
34
35 run_app(|ctx| {
36 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
37
38 let window = ctx
39 .create_window(WindowDescriptor {
40 title: "Material System Demo - Shader Parameters".to_string(),
41 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
42 ..Default::default()
43 })
44 .expect("Failed to create window");
45
46 let window = RenderableWindow::new_with_descriptor(
47 window,
48 graphics_ctx.clone(),
49 WindowContextDescriptor {
50 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
51 ..Default::default()
52 },
53 ).expect("Failed to create renderable window");
54
55 let window_id = window.id();
56
57 // Demonstration of Material API usage
58 // In actual use, you would create materials with shaders:
59 //
60 // let material = Material::new(shader, graphics_ctx.clone());
61 // material.set_parameter("base_color", MaterialParameter::Color(Color::RED));
62 // material.set_parameter("roughness", MaterialParameter::Float(0.5));
63 // material.set_parameter("view_matrix", MaterialParameter::Matrix4(view_matrix));
64 // material.set_texture("albedo", texture_handle);
65 // material.bind(&mut render_pass);
66
67 println!("\n═══════════════════════════════════════════════════════");
68 println!(" 🎨 MATERIAL SYSTEM DEMO - Shader Parameters");
69 println!("═══════════════════════════════════════════════════════");
70 println!("\n MATERIAL API FEATURES:");
71 println!(" • Type-safe parameter setting (float, vec, matrix, color)");
72 println!(" • Texture binding and management");
73 println!(" • Automatic buffer creation and updates");
74 println!(" • Material instancing for performance");
75 println!(" • Hot-reloadable shader parameters");
76 println!("\n EXAMPLE MATERIAL TYPES:");
77 println!(" 1. Color Material - PBR properties (color, roughness, metallic)");
78 println!(" 2. Textured Material - UV transforms (offset, scale, tint)");
79 println!(" 3. Animated Material - Time-based effects (frequency, amplitude)");
80 println!(" 4. Transform Material - View/projection matrices");
81 println!("\n Material API Usage:");
82 println!(" material.set_parameter(\"color\", MaterialParameter::Color(..))");
83 println!(" material.set_parameter(\"time\", MaterialParameter::Float(..))");
84 println!(" material.set_parameter(\"matrix\", MaterialParameter::Matrix4(..))");
85 println!(" material.set_texture(\"albedo\", texture_handle)");
86 println!(" material.bind(&mut render_pass)");
87 println!("\n Materials abstract shader parameter management,");
88 println!(" eliminating manual buffer binding boilerplate.");
89 println!("═══════════════════════════════════════════════════════\n");
90
91 tracing::info!("Material system demo initialized");
92
93 Box::new(MaterialSystemDemo {
94 _context: graphics_ctx,
95 window,
96 window_id,
97 time: 0.0,
98 })
99 });
100}Additional examples can be found in:
Sourcepub fn id(&self) -> WindowId
pub fn id(&self) -> WindowId
Examples found in repository?
examples/multi_window.rs (line 76)
28fn main() {
29 logging::init();
30
31 run_app(|ctx| {
32 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
33
34 let mut windows = HashMap::new();
35
36 // Create 3 windows with different colors
37 let colors = [
38 wgpu::Color {
39 r: 0.8,
40 g: 0.2,
41 b: 0.2,
42 a: 1.0,
43 },
44 wgpu::Color {
45 r: 0.2,
46 g: 0.8,
47 b: 0.2,
48 a: 1.0,
49 },
50 wgpu::Color {
51 r: 0.2,
52 g: 0.2,
53 b: 0.8,
54 a: 1.0,
55 },
56 ];
57
58 for (i, color) in colors.iter().enumerate() {
59 let window = ctx
60 .create_window(WindowDescriptor {
61 title: format!("Window {} - Multi-Window Example", i + 1),
62 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
63 ..Default::default()
64 })
65 .expect("Failed to create window");
66
67 let renderable_window = RenderableWindow::new_with_descriptor(
68 window,
69 graphics_ctx.clone(),
70 WindowContextDescriptor {
71 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
72 ..Default::default()
73 },
74 ).expect("Failed to create renderable window");
75
76 let window_id = renderable_window.id();
77 windows.insert(window_id, (renderable_window, *color));
78 }
79
80 Box::new(App {
81 context: graphics_ctx,
82 windows,
83 })
84 });
85}More examples
examples/performance_benchmark.rs (line 59)
36fn main() {
37 logging::init();
38
39 run_app(|ctx| {
40 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
41
42 let window = ctx
43 .create_window(WindowDescriptor {
44 title: "Performance Benchmark - Render Stress Test".to_string(),
45 size: Some(WinitPhysicalSize::new(1280.0, 720.0)),
46 ..Default::default()
47 })
48 .expect("Failed to create window");
49
50 let window = RenderableWindow::new_with_descriptor(
51 window,
52 graphics_ctx.clone(),
53 WindowContextDescriptor {
54 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
55 ..Default::default()
56 },
57 ).expect("Failed to create renderable window");
58
59 let window_id = window.id();
60
61 println!("\n═══════════════════════════════════════════════════════");
62 println!(" ⚡ PERFORMANCE BENCHMARK - Render Stress Test");
63 println!("═══════════════════════════════════════════════════════");
64 println!(" CONTROLS:");
65 println!(" [Space] Toggle rendering on/off");
66 println!(" [+/-] Increase/decrease object count");
67 println!(" Starting with 1000 objects");
68 println!("═══════════════════════════════════════════════════════\n");
69
70 Box::new(PerformanceBenchmark {
71 _context: graphics_ctx,
72 window,
73 window_id,
74 object_count: 1000,
75 rendering: true,
76 frame_count: 0,
77 last_fps_time: Instant::now(),
78 fps: 0.0,
79 last_frame_time: 0.0,
80 })
81 });
82}examples/camera_demo.rs (line 52)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
34
35 let window = ctx
36 .create_window(WindowDescriptor {
37 title: "Camera Demo - View & Projection".to_string(),
38 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
39 ..Default::default()
40 })
41 .expect("Failed to create window");
42
43 let window = RenderableWindow::new_with_descriptor(
44 window,
45 graphics_ctx.clone(),
46 WindowContextDescriptor {
47 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
48 ..Default::default()
49 },
50 ).expect("Failed to create renderable window");
51
52 let window_id = window.id();
53
54 println!("\n═══════════════════════════════════════════════════════");
55 println!(" 📹 CAMERA DEMO - View & Projection");
56 println!("═══════════════════════════════════════════════════════");
57 println!("\n CAMERA API FEATURES:");
58 println!(" • Orthographic cameras (2D, UI, isometric)");
59 println!(" • Perspective cameras (3D scenes)");
60 println!(" • View matrix (position, rotation, look-at)");
61 println!(" • Projection matrix (FOV, aspect, near/far planes)");
62 println!(" • Screen-to-world coordinate conversion");
63 println!(" • Camera movement helpers");
64 println!("\n CAMERA TYPES:");
65 println!(" • OrthographicCamera - 2D games, UI overlays");
66 println!(" camera.orthographic(left, right, bottom, top, near, far)");
67 println!(" • PerspectiveCamera - 3D scenes");
68 println!(" camera.perspective(fov, aspect, near, far)");
69 println!("\n Camera API Usage:");
70 println!(" let camera = Camera::new()");
71 println!(" .position(Vec3::new(0.0, 5.0, 10.0))");
72 println!(" .look_at(Vec3::ZERO)");
73 println!(" .perspective(60.0, aspect, 0.1, 100.0);");
74 println!(" let view_proj = camera.view_projection_matrix();");
75 println!("═══════════════════════════════════════════════════════\n");
76
77 tracing::info!("Camera demo initialized");
78
79 Box::new(CameraDemo {
80 _context: graphics_ctx,
81 window,
82 window_id,
83 })
84 });
85}examples/render_graph_demo.rs (line 51)
28fn main() {
29 logging::init();
30
31 run_app(|ctx| {
32 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
33
34 let window = ctx
35 .create_window(WindowDescriptor {
36 title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
37 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
38 ..Default::default()
39 })
40 .expect("Failed to create window");
41
42 let window = RenderableWindow::new_with_descriptor(
43 window,
44 graphics_ctx.clone(),
45 WindowContextDescriptor {
46 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
47 ..Default::default()
48 },
49 ).expect("Failed to create renderable window");
50
51 let window_id = window.id();
52
53 println!("\n═══════════════════════════════════════════════════════");
54 println!(" 🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
55 println!("═══════════════════════════════════════════════════════");
56 println!("\n RENDER GRAPH FEATURES:");
57 println!(" • Declarative pass definition");
58 println!(" • Automatic dependency resolution");
59 println!(" • Resource lifetime management");
60 println!(" • Parallel pass execution");
61 println!(" • Automatic optimization");
62 println!("\n EXAMPLE PIPELINE:");
63 println!(" 1. Shadow Pass → depth texture");
64 println!(" 2. Geometry Pass → color + normal + depth");
65 println!(" 3. Lighting Pass → lit scene");
66 println!(" 4. Post-Processing → bloom, tone mapping");
67 println!(" 5. UI Pass → final composite");
68 println!("\n Render Graph API Usage:");
69 println!(" let mut graph = RenderGraph::new();");
70 println!(" graph.add_pass(\"shadow\", shadow_pass_descriptor);");
71 println!(" graph.add_pass(\"geometry\", geometry_pass_descriptor);");
72 println!(" graph.add_dependency(\"lighting\", \"geometry\");");
73 println!(" graph.compile();");
74 println!(" graph.execute(&mut encoder);");
75 println!("═══════════════════════════════════════════════════════\n");
76
77 tracing::info!("Render graph demo initialized");
78
79 Box::new(RenderGraphDemo {
80 _context: graphics_ctx,
81 window,
82 window_id,
83 })
84 });
85}examples/mesh_primitives.rs (line 52)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
34
35 let window = ctx
36 .create_window(WindowDescriptor {
37 title: "Mesh Primitives Demo - Geometry API".to_string(),
38 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
39 ..Default::default()
40 })
41 .expect("Failed to create window");
42
43 let window = RenderableWindow::new_with_descriptor(
44 window,
45 graphics_ctx.clone(),
46 WindowContextDescriptor {
47 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
48 ..Default::default()
49 },
50 ).expect("Failed to create renderable window");
51
52 let window_id = window.id();
53
54 println!("\n═══════════════════════════════════════════════════════");
55 println!(" 📐 MESH PRIMITIVES DEMO - Geometry API");
56 println!("═══════════════════════════════════════════════════════");
57 println!("\n MESH API FEATURES:");
58 println!(" • MeshBuilder for custom geometry");
59 println!(" • Primitive generation (cube, sphere, plane, etc.)");
60 println!(" • Flexible vertex formats (Position, Normal, UV, Color)");
61 println!(" • Index buffer optimization");
62 println!(" • Instanced rendering support");
63 println!("\n EXAMPLE PRIMITIVES:");
64 println!(" • Cube - box with 24 vertices (6 faces × 4 vertices)");
65 println!(" • Sphere - tessellated sphere with UV mapping");
66 println!(" • Plane - quad with optional subdivisions");
67 println!(" • Cylinder - sides + caps");
68 println!(" • Custom - arbitrary vertex/index data");
69 println!("\n Mesh API Usage:");
70 println!(" let mesh = MeshBuilder::new()");
71 println!(" .with_positions(vertices)");
72 println!(" .with_normals(normals)");
73 println!(" .with_uvs(uvs)");
74 println!(" .with_indices(indices)");
75 println!(" .build(&ctx);");
76 println!(" mesh.draw(&mut pass);");
77 println!(" mesh.draw_instanced(&mut pass, instance_count);");
78 println!("═══════════════════════════════════════════════════════\n");
79
80 tracing::info!("Mesh primitives demo initialized");
81
82 Box::new(MeshPrimitivesDemo {
83 _context: graphics_ctx,
84 window,
85 window_id,
86 })
87 });
88}examples/material_system.rs (line 55)
32fn main() {
33 logging::init();
34
35 run_app(|ctx| {
36 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
37
38 let window = ctx
39 .create_window(WindowDescriptor {
40 title: "Material System Demo - Shader Parameters".to_string(),
41 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
42 ..Default::default()
43 })
44 .expect("Failed to create window");
45
46 let window = RenderableWindow::new_with_descriptor(
47 window,
48 graphics_ctx.clone(),
49 WindowContextDescriptor {
50 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
51 ..Default::default()
52 },
53 ).expect("Failed to create renderable window");
54
55 let window_id = window.id();
56
57 // Demonstration of Material API usage
58 // In actual use, you would create materials with shaders:
59 //
60 // let material = Material::new(shader, graphics_ctx.clone());
61 // material.set_parameter("base_color", MaterialParameter::Color(Color::RED));
62 // material.set_parameter("roughness", MaterialParameter::Float(0.5));
63 // material.set_parameter("view_matrix", MaterialParameter::Matrix4(view_matrix));
64 // material.set_texture("albedo", texture_handle);
65 // material.bind(&mut render_pass);
66
67 println!("\n═══════════════════════════════════════════════════════");
68 println!(" 🎨 MATERIAL SYSTEM DEMO - Shader Parameters");
69 println!("═══════════════════════════════════════════════════════");
70 println!("\n MATERIAL API FEATURES:");
71 println!(" • Type-safe parameter setting (float, vec, matrix, color)");
72 println!(" • Texture binding and management");
73 println!(" • Automatic buffer creation and updates");
74 println!(" • Material instancing for performance");
75 println!(" • Hot-reloadable shader parameters");
76 println!("\n EXAMPLE MATERIAL TYPES:");
77 println!(" 1. Color Material - PBR properties (color, roughness, metallic)");
78 println!(" 2. Textured Material - UV transforms (offset, scale, tint)");
79 println!(" 3. Animated Material - Time-based effects (frequency, amplitude)");
80 println!(" 4. Transform Material - View/projection matrices");
81 println!("\n Material API Usage:");
82 println!(" material.set_parameter(\"color\", MaterialParameter::Color(..))");
83 println!(" material.set_parameter(\"time\", MaterialParameter::Float(..))");
84 println!(" material.set_parameter(\"matrix\", MaterialParameter::Matrix4(..))");
85 println!(" material.set_texture(\"albedo\", texture_handle)");
86 println!(" material.bind(&mut render_pass)");
87 println!("\n Materials abstract shader parameter management,");
88 println!(" eliminating manual buffer binding boilerplate.");
89 println!("═══════════════════════════════════════════════════════\n");
90
91 tracing::info!("Material system demo initialized");
92
93 Box::new(MaterialSystemDemo {
94 _context: graphics_ctx,
95 window,
96 window_id,
97 time: 0.0,
98 })
99 });
100}Additional examples can be found in:
pub fn window(&self) -> &Window
Sourcepub fn context(&self) -> &WindowContext
pub fn context(&self) -> &WindowContext
Examples found in repository?
examples/sprite_sheet.rs (line 377)
363 fn update(&mut self, _ctx: &mut astrelis_winit::app::AppCtx, _time: &astrelis_winit::FrameTime) {
364 let now = Instant::now();
365 let dt = now.duration_since(self.last_update).as_secs_f32();
366 self.last_update = now;
367
368 // Update animation
369 if self.animation.update(dt) {
370 // Frame changed - update vertex buffer with new UVs
371 let frame = self.animation.current_frame();
372 let uv = self.sprite_sheet.sprite_uv(frame);
373 let vertices = create_quad_vertices(uv.u_min, uv.v_min, uv.u_max, uv.v_max);
374
375 // Get context from first window
376 if let Some(window) = self.windows.values().next() {
377 window.context().graphics_context().queue.write_buffer(
378 &self.vertex_buffer,
379 0,
380 bytemuck::cast_slice(&vertices),
381 );
382 }
383 }
384 }pub fn context_mut(&mut self) -> &mut WindowContext
Sourcepub fn resized(&mut self, new_size: LogicalSize<u32>)
pub fn resized(&mut self, new_size: LogicalSize<u32>)
Handle window resize event (logical size).
Examples found in repository?
examples/camera_demo.rs (line 97)
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 100)
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 97)
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/material_system.rs (line 115)
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 107)
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 }examples/textured_window.rs (line 254)
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 }Additional examples can be found in:
Sourcepub fn resized_physical(&mut self, new_size: PhysicalSize<u32>)
pub fn resized_physical(&mut self, new_size: PhysicalSize<u32>)
Handle window resize event (physical size).
Sourcepub fn physical_size(&self) -> PhysicalSize<u32>
pub fn physical_size(&self) -> PhysicalSize<u32>
Get the physical size of the window.
Sourcepub fn scale_factor(&self) -> ScaleFactor
pub fn scale_factor(&self) -> ScaleFactor
Get the scale factor.
Methods from Deref<Target = WindowContext>§
Sourcepub fn resized(&mut self, new_size: LogicalSize<u32>)
pub fn resized(&mut self, new_size: LogicalSize<u32>)
Handle window resize event (logical size).
Sourcepub fn resized_physical(&mut self, new_size: PhysicalSize<u32>)
pub fn resized_physical(&mut self, new_size: PhysicalSize<u32>)
Handle window resize event (physical size).
pub fn window(&self) -> &Window
Sourcepub fn graphics_context(&self) -> &GraphicsContext
pub fn graphics_context(&self) -> &GraphicsContext
Examples found in repository?
examples/sprite_sheet.rs (line 377)
363 fn update(&mut self, _ctx: &mut astrelis_winit::app::AppCtx, _time: &astrelis_winit::FrameTime) {
364 let now = Instant::now();
365 let dt = now.duration_since(self.last_update).as_secs_f32();
366 self.last_update = now;
367
368 // Update animation
369 if self.animation.update(dt) {
370 // Frame changed - update vertex buffer with new UVs
371 let frame = self.animation.current_frame();
372 let uv = self.sprite_sheet.sprite_uv(frame);
373 let vertices = create_quad_vertices(uv.u_min, uv.v_min, uv.u_max, uv.v_max);
374
375 // Get context from first window
376 if let Some(window) = self.windows.values().next() {
377 window.context().graphics_context().queue.write_buffer(
378 &self.vertex_buffer,
379 0,
380 bytemuck::cast_slice(&vertices),
381 );
382 }
383 }
384 }pub fn surface(&self) -> &Surface<'static>
pub fn surface_config(&self) -> &SurfaceConfiguration
Sourcepub fn logical_size(&self) -> LogicalSize<u32>
pub fn logical_size(&self) -> LogicalSize<u32>
Get the logical size of the window.
Sourcepub fn physical_size(&self) -> PhysicalSize<u32>
pub fn physical_size(&self) -> PhysicalSize<u32>
Get the physical size of the window.
Sourcepub fn logical_size_f32(&self) -> LogicalSize<f32>
pub fn logical_size_f32(&self) -> LogicalSize<f32>
Get the logical size as f32.
Sourcepub fn physical_size_f32(&self) -> PhysicalSize<f32>
pub fn physical_size_f32(&self) -> PhysicalSize<f32>
Get the physical size as f32.
Sourcepub fn reconfigure_surface(&mut self, config: SurfaceConfiguration)
pub fn reconfigure_surface(&mut self, config: SurfaceConfiguration)
Reconfigure the surface with a new configuration.
Trait Implementations§
Source§impl Deref for RenderableWindow
impl Deref for RenderableWindow
Source§impl DerefMut for RenderableWindow
impl DerefMut for RenderableWindow
Source§impl WindowBackend for RenderableWindow
impl WindowBackend for RenderableWindow
type FrameContext = FrameContext
fn begin_drawing(&mut self) -> Self::FrameContext
Auto Trait Implementations§
impl !Freeze for RenderableWindow
impl !RefUnwindSafe for RenderableWindow
impl Send for RenderableWindow
impl Sync for RenderableWindow
impl Unpin for RenderableWindow
impl !UnwindSafe for RenderableWindow
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