pub struct RenderWindowBuilder { /* private fields */ }Expand description
Builder for configuring a RenderWindow.
§Example
let render_window = RenderWindow::builder()
.present_mode(wgpu::PresentMode::Fifo)
.with_depth_default()
.with_profiling(true)
.build(window, graphics)
.expect("Failed to create window");Implementations§
Source§impl RenderWindowBuilder
impl RenderWindowBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with default settings.
Examples found in repository?
examples/multi_window.rs (line 65)
25fn main() {
26 logging::init();
27
28 run_app(|ctx| {
29 let graphics_ctx =
30 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
31
32 let mut windows = HashMap::new();
33
34 // Create 3 windows with different colors
35 let colors = [
36 wgpu::Color {
37 r: 0.8,
38 g: 0.2,
39 b: 0.2,
40 a: 1.0,
41 },
42 wgpu::Color {
43 r: 0.2,
44 g: 0.8,
45 b: 0.2,
46 a: 1.0,
47 },
48 wgpu::Color {
49 r: 0.2,
50 g: 0.2,
51 b: 0.8,
52 a: 1.0,
53 },
54 ];
55
56 for (i, color) in colors.iter().enumerate() {
57 let window = ctx
58 .create_window(WindowDescriptor {
59 title: format!("Window {} - Multi-Window Example", i + 1),
60 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
61 ..Default::default()
62 })
63 .expect("Failed to create window");
64
65 let renderable_window = RenderWindowBuilder::new()
66 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
67 .with_depth_default()
68 .build(window, graphics_ctx.clone())
69 .expect("Failed to create render window");
70
71 let window_id = renderable_window.id();
72 windows.insert(window_id, (renderable_window, *color));
73 }
74
75 Box::new(App { windows })
76 });
77}More examples
examples/performance_benchmark.rs (line 51)
36fn main() {
37 logging::init();
38
39 run_app(|ctx| {
40 let graphics_ctx =
41 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
42
43 let window = ctx
44 .create_window(WindowDescriptor {
45 title: "Performance Benchmark - Render Stress Test".to_string(),
46 size: Some(WinitPhysicalSize::new(1280.0, 720.0)),
47 ..Default::default()
48 })
49 .expect("Failed to create window");
50
51 let window = RenderWindowBuilder::new()
52 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
53 .with_depth_default()
54 .build(window, graphics_ctx.clone())
55 .expect("Failed to create render window");
56
57 let window_id = window.id();
58
59 println!("\n═══════════════════════════════════════════════════════");
60 println!(" ⚡ PERFORMANCE BENCHMARK - Render Stress Test");
61 println!("═══════════════════════════════════════════════════════");
62 println!(" CONTROLS:");
63 println!(" [Space] Toggle rendering on/off");
64 println!(" [+/-] Increase/decrease object count");
65 println!(" Starting with 1000 objects");
66 println!("═══════════════════════════════════════════════════════\n");
67
68 Box::new(PerformanceBenchmark {
69 _context: graphics_ctx,
70 window,
71 window_id,
72 object_count: 1000,
73 rendering: true,
74 frame_count: 0,
75 last_fps_time: Instant::now(),
76 fps: 0.0,
77 last_frame_time: 0.0,
78 })
79 });
80}examples/camera_demo.rs (line 45)
30fn main() {
31 logging::init();
32
33 run_app(|ctx| {
34 let graphics_ctx =
35 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
36
37 let window = ctx
38 .create_window(WindowDescriptor {
39 title: "Camera Demo - View & Projection".to_string(),
40 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
41 ..Default::default()
42 })
43 .expect("Failed to create window");
44
45 let window = RenderWindowBuilder::new()
46 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
47 .with_depth_default()
48 .build(window, graphics_ctx.clone())
49 .expect("Failed to create render window");
50
51 let window_id = window.id();
52
53 println!("\n═══════════════════════════════════════════════════════");
54 println!(" 📹 CAMERA DEMO - View & Projection");
55 println!("═══════════════════════════════════════════════════════");
56 println!("\n CAMERA API FEATURES:");
57 println!(" • Orthographic cameras (2D, UI, isometric)");
58 println!(" • Perspective cameras (3D scenes)");
59 println!(" • View matrix (position, rotation, look-at)");
60 println!(" • Projection matrix (FOV, aspect, near/far planes)");
61 println!(" • Screen-to-world coordinate conversion");
62 println!(" • Camera movement helpers");
63 println!("\n CAMERA TYPES:");
64 println!(" • OrthographicCamera - 2D games, UI overlays");
65 println!(" camera.orthographic(left, right, bottom, top, near, far)");
66 println!(" • PerspectiveCamera - 3D scenes");
67 println!(" camera.perspective(fov, aspect, near, far)");
68 println!("\n Camera API Usage:");
69 println!(" let camera = Camera::new()");
70 println!(" .position(Vec3::new(0.0, 5.0, 10.0))");
71 println!(" .look_at(Vec3::ZERO)");
72 println!(" .perspective(60.0, aspect, 0.1, 100.0);");
73 println!(" let view_proj = camera.view_projection_matrix();");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Camera demo initialized");
77
78 Box::new(CameraDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/render_graph_demo.rs (line 44)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n RENDER GRAPH FEATURES:");
56 println!(" • Declarative pass definition");
57 println!(" • Automatic dependency resolution");
58 println!(" • Resource lifetime management");
59 println!(" • Parallel pass execution");
60 println!(" • Automatic optimization");
61 println!("\n EXAMPLE PIPELINE:");
62 println!(" 1. Shadow Pass → depth texture");
63 println!(" 2. Geometry Pass → color + normal + depth");
64 println!(" 3. Lighting Pass → lit scene");
65 println!(" 4. Post-Processing → bloom, tone mapping");
66 println!(" 5. UI Pass → final composite");
67 println!("\n Render Graph API Usage:");
68 println!(" let mut graph = RenderGraph::new();");
69 println!(" graph.add_pass(\"shadow\", shadow_pass_descriptor);");
70 println!(" graph.add_pass(\"geometry\", geometry_pass_descriptor);");
71 println!(" graph.add_dependency(\"lighting\", \"geometry\");");
72 println!(" graph.compile();");
73 println!(" graph.execute(&mut encoder);");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Render graph demo initialized");
77
78 Box::new(RenderGraphDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/mesh_primitives.rs (line 44)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Mesh Primitives Demo - Geometry API".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 📐 MESH PRIMITIVES DEMO - Geometry API");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n MESH API FEATURES:");
56 println!(" • MeshBuilder for custom geometry");
57 println!(" • Primitive generation (cube, sphere, plane, etc.)");
58 println!(" • Flexible vertex formats (Position, Normal, UV, Color)");
59 println!(" • Index buffer optimization");
60 println!(" • Instanced rendering support");
61 println!("\n EXAMPLE PRIMITIVES:");
62 println!(" • Cube - box with 24 vertices (6 faces × 4 vertices)");
63 println!(" • Sphere - tessellated sphere with UV mapping");
64 println!(" • Plane - quad with optional subdivisions");
65 println!(" • Cylinder - sides + caps");
66 println!(" • Custom - arbitrary vertex/index data");
67 println!("\n Mesh API Usage:");
68 println!(" let mesh = MeshBuilder::new()");
69 println!(" .with_positions(vertices)");
70 println!(" .with_normals(normals)");
71 println!(" .with_uvs(uvs)");
72 println!(" .with_indices(indices)");
73 println!(" .build(&ctx);");
74 println!(" mesh.draw(&mut pass);");
75 println!(" mesh.draw_instanced(&mut pass, instance_count);");
76 println!("═══════════════════════════════════════════════════════\n");
77
78 tracing::info!("Mesh primitives demo initialized");
79
80 Box::new(MeshPrimitivesDemo {
81 _context: graphics_ctx,
82 window,
83 window_id,
84 })
85 });
86}examples/batched_renderer.rs (line 313)
278fn main() {
279 logging::init();
280
281 run_app(|ctx| {
282 let tier_override = parse_tier();
283
284 // Use the capability API to configure GPU requirements.
285 // For auto-detect, request the best capability (graceful degradation).
286 // For a specific tier, require that tier's capability.
287 let descriptor = match tier_override {
288 None => GraphicsContextDescriptor::new().request_capability::<BestBatchCapability2D>(),
289 Some(RenderTier::Direct) => {
290 GraphicsContextDescriptor::new().require_capability::<DirectBatchCapability2D>()
291 }
292 Some(RenderTier::Indirect) => {
293 GraphicsContextDescriptor::new().require_capability::<IndirectBatchCapability2D>()
294 }
295 Some(RenderTier::Bindless) => {
296 GraphicsContextDescriptor::new().require_capability::<BindlessBatchCapability2D>()
297 }
298 };
299 let graphics_ctx =
300 pollster::block_on(GraphicsContext::new_owned_with_descriptor(descriptor))
301 .expect("Failed to create graphics context");
302
303 let window = ctx
304 .create_window(WindowDescriptor {
305 title: "Batched Renderer Example".to_string(),
306 size: Some(WinitPhysicalSize::new(800.0, 600.0)),
307 ..Default::default()
308 })
309 .expect("Failed to create window");
310
311 let surface_format = wgpu::TextureFormat::Bgra8UnormSrgb;
312
313 let renderable_window = RenderWindowBuilder::new()
314 .color_format(surface_format)
315 .with_depth_default()
316 .build(window, graphics_ctx.clone())
317 .expect("Failed to create render window");
318
319 let window_id = renderable_window.id();
320
321 let renderer =
322 create_batch_renderer_2d(graphics_ctx.clone(), surface_format, tier_override);
323
324 tracing::info!("Using render tier: {}", renderer.tier());
325
326 // Create initial depth buffer
327 let depth_texture = graphics_ctx
328 .device()
329 .create_texture(&wgpu::TextureDescriptor {
330 label: Some("example_depth"),
331 size: wgpu::Extent3d {
332 width: 1,
333 height: 1,
334 depth_or_array_layers: 1,
335 },
336 mip_level_count: 1,
337 sample_count: 1,
338 dimension: wgpu::TextureDimension::D2,
339 format: DEPTH_FORMAT,
340 usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
341 view_formats: &[],
342 });
343 let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
344
345 let mut windows = HashMap::new();
346 windows.insert(window_id, renderable_window);
347
348 Box::new(App {
349 context: graphics_ctx,
350 windows,
351 renderer,
352 depth_texture,
353 depth_view,
354 depth_width: 1,
355 depth_height: 1,
356 frame_count: 0,
357 })
358 });
359}Sourcepub fn present_mode(self, mode: PresentMode) -> Self
pub fn present_mode(self, mode: PresentMode) -> Self
Set the present mode for vsync behavior.
Sourcepub fn color_format(self, format: TextureFormat) -> Self
pub fn color_format(self, format: TextureFormat) -> Self
Set the color format for the surface.
Examples found in repository?
examples/multi_window.rs (line 66)
25fn main() {
26 logging::init();
27
28 run_app(|ctx| {
29 let graphics_ctx =
30 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
31
32 let mut windows = HashMap::new();
33
34 // Create 3 windows with different colors
35 let colors = [
36 wgpu::Color {
37 r: 0.8,
38 g: 0.2,
39 b: 0.2,
40 a: 1.0,
41 },
42 wgpu::Color {
43 r: 0.2,
44 g: 0.8,
45 b: 0.2,
46 a: 1.0,
47 },
48 wgpu::Color {
49 r: 0.2,
50 g: 0.2,
51 b: 0.8,
52 a: 1.0,
53 },
54 ];
55
56 for (i, color) in colors.iter().enumerate() {
57 let window = ctx
58 .create_window(WindowDescriptor {
59 title: format!("Window {} - Multi-Window Example", i + 1),
60 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
61 ..Default::default()
62 })
63 .expect("Failed to create window");
64
65 let renderable_window = RenderWindowBuilder::new()
66 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
67 .with_depth_default()
68 .build(window, graphics_ctx.clone())
69 .expect("Failed to create render window");
70
71 let window_id = renderable_window.id();
72 windows.insert(window_id, (renderable_window, *color));
73 }
74
75 Box::new(App { windows })
76 });
77}More examples
examples/performance_benchmark.rs (line 52)
36fn main() {
37 logging::init();
38
39 run_app(|ctx| {
40 let graphics_ctx =
41 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
42
43 let window = ctx
44 .create_window(WindowDescriptor {
45 title: "Performance Benchmark - Render Stress Test".to_string(),
46 size: Some(WinitPhysicalSize::new(1280.0, 720.0)),
47 ..Default::default()
48 })
49 .expect("Failed to create window");
50
51 let window = RenderWindowBuilder::new()
52 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
53 .with_depth_default()
54 .build(window, graphics_ctx.clone())
55 .expect("Failed to create render window");
56
57 let window_id = window.id();
58
59 println!("\n═══════════════════════════════════════════════════════");
60 println!(" ⚡ PERFORMANCE BENCHMARK - Render Stress Test");
61 println!("═══════════════════════════════════════════════════════");
62 println!(" CONTROLS:");
63 println!(" [Space] Toggle rendering on/off");
64 println!(" [+/-] Increase/decrease object count");
65 println!(" Starting with 1000 objects");
66 println!("═══════════════════════════════════════════════════════\n");
67
68 Box::new(PerformanceBenchmark {
69 _context: graphics_ctx,
70 window,
71 window_id,
72 object_count: 1000,
73 rendering: true,
74 frame_count: 0,
75 last_fps_time: Instant::now(),
76 fps: 0.0,
77 last_frame_time: 0.0,
78 })
79 });
80}examples/camera_demo.rs (line 46)
30fn main() {
31 logging::init();
32
33 run_app(|ctx| {
34 let graphics_ctx =
35 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
36
37 let window = ctx
38 .create_window(WindowDescriptor {
39 title: "Camera Demo - View & Projection".to_string(),
40 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
41 ..Default::default()
42 })
43 .expect("Failed to create window");
44
45 let window = RenderWindowBuilder::new()
46 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
47 .with_depth_default()
48 .build(window, graphics_ctx.clone())
49 .expect("Failed to create render window");
50
51 let window_id = window.id();
52
53 println!("\n═══════════════════════════════════════════════════════");
54 println!(" 📹 CAMERA DEMO - View & Projection");
55 println!("═══════════════════════════════════════════════════════");
56 println!("\n CAMERA API FEATURES:");
57 println!(" • Orthographic cameras (2D, UI, isometric)");
58 println!(" • Perspective cameras (3D scenes)");
59 println!(" • View matrix (position, rotation, look-at)");
60 println!(" • Projection matrix (FOV, aspect, near/far planes)");
61 println!(" • Screen-to-world coordinate conversion");
62 println!(" • Camera movement helpers");
63 println!("\n CAMERA TYPES:");
64 println!(" • OrthographicCamera - 2D games, UI overlays");
65 println!(" camera.orthographic(left, right, bottom, top, near, far)");
66 println!(" • PerspectiveCamera - 3D scenes");
67 println!(" camera.perspective(fov, aspect, near, far)");
68 println!("\n Camera API Usage:");
69 println!(" let camera = Camera::new()");
70 println!(" .position(Vec3::new(0.0, 5.0, 10.0))");
71 println!(" .look_at(Vec3::ZERO)");
72 println!(" .perspective(60.0, aspect, 0.1, 100.0);");
73 println!(" let view_proj = camera.view_projection_matrix();");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Camera demo initialized");
77
78 Box::new(CameraDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/render_graph_demo.rs (line 45)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n RENDER GRAPH FEATURES:");
56 println!(" • Declarative pass definition");
57 println!(" • Automatic dependency resolution");
58 println!(" • Resource lifetime management");
59 println!(" • Parallel pass execution");
60 println!(" • Automatic optimization");
61 println!("\n EXAMPLE PIPELINE:");
62 println!(" 1. Shadow Pass → depth texture");
63 println!(" 2. Geometry Pass → color + normal + depth");
64 println!(" 3. Lighting Pass → lit scene");
65 println!(" 4. Post-Processing → bloom, tone mapping");
66 println!(" 5. UI Pass → final composite");
67 println!("\n Render Graph API Usage:");
68 println!(" let mut graph = RenderGraph::new();");
69 println!(" graph.add_pass(\"shadow\", shadow_pass_descriptor);");
70 println!(" graph.add_pass(\"geometry\", geometry_pass_descriptor);");
71 println!(" graph.add_dependency(\"lighting\", \"geometry\");");
72 println!(" graph.compile();");
73 println!(" graph.execute(&mut encoder);");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Render graph demo initialized");
77
78 Box::new(RenderGraphDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/mesh_primitives.rs (line 45)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Mesh Primitives Demo - Geometry API".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 📐 MESH PRIMITIVES DEMO - Geometry API");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n MESH API FEATURES:");
56 println!(" • MeshBuilder for custom geometry");
57 println!(" • Primitive generation (cube, sphere, plane, etc.)");
58 println!(" • Flexible vertex formats (Position, Normal, UV, Color)");
59 println!(" • Index buffer optimization");
60 println!(" • Instanced rendering support");
61 println!("\n EXAMPLE PRIMITIVES:");
62 println!(" • Cube - box with 24 vertices (6 faces × 4 vertices)");
63 println!(" • Sphere - tessellated sphere with UV mapping");
64 println!(" • Plane - quad with optional subdivisions");
65 println!(" • Cylinder - sides + caps");
66 println!(" • Custom - arbitrary vertex/index data");
67 println!("\n Mesh API Usage:");
68 println!(" let mesh = MeshBuilder::new()");
69 println!(" .with_positions(vertices)");
70 println!(" .with_normals(normals)");
71 println!(" .with_uvs(uvs)");
72 println!(" .with_indices(indices)");
73 println!(" .build(&ctx);");
74 println!(" mesh.draw(&mut pass);");
75 println!(" mesh.draw_instanced(&mut pass, instance_count);");
76 println!("═══════════════════════════════════════════════════════\n");
77
78 tracing::info!("Mesh primitives demo initialized");
79
80 Box::new(MeshPrimitivesDemo {
81 _context: graphics_ctx,
82 window,
83 window_id,
84 })
85 });
86}examples/batched_renderer.rs (line 314)
278fn main() {
279 logging::init();
280
281 run_app(|ctx| {
282 let tier_override = parse_tier();
283
284 // Use the capability API to configure GPU requirements.
285 // For auto-detect, request the best capability (graceful degradation).
286 // For a specific tier, require that tier's capability.
287 let descriptor = match tier_override {
288 None => GraphicsContextDescriptor::new().request_capability::<BestBatchCapability2D>(),
289 Some(RenderTier::Direct) => {
290 GraphicsContextDescriptor::new().require_capability::<DirectBatchCapability2D>()
291 }
292 Some(RenderTier::Indirect) => {
293 GraphicsContextDescriptor::new().require_capability::<IndirectBatchCapability2D>()
294 }
295 Some(RenderTier::Bindless) => {
296 GraphicsContextDescriptor::new().require_capability::<BindlessBatchCapability2D>()
297 }
298 };
299 let graphics_ctx =
300 pollster::block_on(GraphicsContext::new_owned_with_descriptor(descriptor))
301 .expect("Failed to create graphics context");
302
303 let window = ctx
304 .create_window(WindowDescriptor {
305 title: "Batched Renderer Example".to_string(),
306 size: Some(WinitPhysicalSize::new(800.0, 600.0)),
307 ..Default::default()
308 })
309 .expect("Failed to create window");
310
311 let surface_format = wgpu::TextureFormat::Bgra8UnormSrgb;
312
313 let renderable_window = RenderWindowBuilder::new()
314 .color_format(surface_format)
315 .with_depth_default()
316 .build(window, graphics_ctx.clone())
317 .expect("Failed to create render window");
318
319 let window_id = renderable_window.id();
320
321 let renderer =
322 create_batch_renderer_2d(graphics_ctx.clone(), surface_format, tier_override);
323
324 tracing::info!("Using render tier: {}", renderer.tier());
325
326 // Create initial depth buffer
327 let depth_texture = graphics_ctx
328 .device()
329 .create_texture(&wgpu::TextureDescriptor {
330 label: Some("example_depth"),
331 size: wgpu::Extent3d {
332 width: 1,
333 height: 1,
334 depth_or_array_layers: 1,
335 },
336 mip_level_count: 1,
337 sample_count: 1,
338 dimension: wgpu::TextureDimension::D2,
339 format: DEPTH_FORMAT,
340 usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
341 view_formats: &[],
342 });
343 let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
344
345 let mut windows = HashMap::new();
346 windows.insert(window_id, renderable_window);
347
348 Box::new(App {
349 context: graphics_ctx,
350 windows,
351 renderer,
352 depth_texture,
353 depth_view,
354 depth_width: 1,
355 depth_height: 1,
356 frame_count: 0,
357 })
358 });
359}Sourcepub fn alpha_mode(self, mode: CompositeAlphaMode) -> Self
pub fn alpha_mode(self, mode: CompositeAlphaMode) -> Self
Set the alpha compositing mode.
Sourcepub fn with_depth(self, format: TextureFormat) -> Self
pub fn with_depth(self, format: TextureFormat) -> Self
Enable depth buffer with the specified format.
Sourcepub fn with_depth_default(self) -> Self
pub fn with_depth_default(self) -> Self
Enable depth buffer with default format (Depth32Float).
Examples found in repository?
examples/multi_window.rs (line 67)
25fn main() {
26 logging::init();
27
28 run_app(|ctx| {
29 let graphics_ctx =
30 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
31
32 let mut windows = HashMap::new();
33
34 // Create 3 windows with different colors
35 let colors = [
36 wgpu::Color {
37 r: 0.8,
38 g: 0.2,
39 b: 0.2,
40 a: 1.0,
41 },
42 wgpu::Color {
43 r: 0.2,
44 g: 0.8,
45 b: 0.2,
46 a: 1.0,
47 },
48 wgpu::Color {
49 r: 0.2,
50 g: 0.2,
51 b: 0.8,
52 a: 1.0,
53 },
54 ];
55
56 for (i, color) in colors.iter().enumerate() {
57 let window = ctx
58 .create_window(WindowDescriptor {
59 title: format!("Window {} - Multi-Window Example", i + 1),
60 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
61 ..Default::default()
62 })
63 .expect("Failed to create window");
64
65 let renderable_window = RenderWindowBuilder::new()
66 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
67 .with_depth_default()
68 .build(window, graphics_ctx.clone())
69 .expect("Failed to create render window");
70
71 let window_id = renderable_window.id();
72 windows.insert(window_id, (renderable_window, *color));
73 }
74
75 Box::new(App { windows })
76 });
77}More examples
examples/performance_benchmark.rs (line 53)
36fn main() {
37 logging::init();
38
39 run_app(|ctx| {
40 let graphics_ctx =
41 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
42
43 let window = ctx
44 .create_window(WindowDescriptor {
45 title: "Performance Benchmark - Render Stress Test".to_string(),
46 size: Some(WinitPhysicalSize::new(1280.0, 720.0)),
47 ..Default::default()
48 })
49 .expect("Failed to create window");
50
51 let window = RenderWindowBuilder::new()
52 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
53 .with_depth_default()
54 .build(window, graphics_ctx.clone())
55 .expect("Failed to create render window");
56
57 let window_id = window.id();
58
59 println!("\n═══════════════════════════════════════════════════════");
60 println!(" ⚡ PERFORMANCE BENCHMARK - Render Stress Test");
61 println!("═══════════════════════════════════════════════════════");
62 println!(" CONTROLS:");
63 println!(" [Space] Toggle rendering on/off");
64 println!(" [+/-] Increase/decrease object count");
65 println!(" Starting with 1000 objects");
66 println!("═══════════════════════════════════════════════════════\n");
67
68 Box::new(PerformanceBenchmark {
69 _context: graphics_ctx,
70 window,
71 window_id,
72 object_count: 1000,
73 rendering: true,
74 frame_count: 0,
75 last_fps_time: Instant::now(),
76 fps: 0.0,
77 last_frame_time: 0.0,
78 })
79 });
80}examples/camera_demo.rs (line 47)
30fn main() {
31 logging::init();
32
33 run_app(|ctx| {
34 let graphics_ctx =
35 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
36
37 let window = ctx
38 .create_window(WindowDescriptor {
39 title: "Camera Demo - View & Projection".to_string(),
40 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
41 ..Default::default()
42 })
43 .expect("Failed to create window");
44
45 let window = RenderWindowBuilder::new()
46 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
47 .with_depth_default()
48 .build(window, graphics_ctx.clone())
49 .expect("Failed to create render window");
50
51 let window_id = window.id();
52
53 println!("\n═══════════════════════════════════════════════════════");
54 println!(" 📹 CAMERA DEMO - View & Projection");
55 println!("═══════════════════════════════════════════════════════");
56 println!("\n CAMERA API FEATURES:");
57 println!(" • Orthographic cameras (2D, UI, isometric)");
58 println!(" • Perspective cameras (3D scenes)");
59 println!(" • View matrix (position, rotation, look-at)");
60 println!(" • Projection matrix (FOV, aspect, near/far planes)");
61 println!(" • Screen-to-world coordinate conversion");
62 println!(" • Camera movement helpers");
63 println!("\n CAMERA TYPES:");
64 println!(" • OrthographicCamera - 2D games, UI overlays");
65 println!(" camera.orthographic(left, right, bottom, top, near, far)");
66 println!(" • PerspectiveCamera - 3D scenes");
67 println!(" camera.perspective(fov, aspect, near, far)");
68 println!("\n Camera API Usage:");
69 println!(" let camera = Camera::new()");
70 println!(" .position(Vec3::new(0.0, 5.0, 10.0))");
71 println!(" .look_at(Vec3::ZERO)");
72 println!(" .perspective(60.0, aspect, 0.1, 100.0);");
73 println!(" let view_proj = camera.view_projection_matrix();");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Camera demo initialized");
77
78 Box::new(CameraDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/render_graph_demo.rs (line 46)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n RENDER GRAPH FEATURES:");
56 println!(" • Declarative pass definition");
57 println!(" • Automatic dependency resolution");
58 println!(" • Resource lifetime management");
59 println!(" • Parallel pass execution");
60 println!(" • Automatic optimization");
61 println!("\n EXAMPLE PIPELINE:");
62 println!(" 1. Shadow Pass → depth texture");
63 println!(" 2. Geometry Pass → color + normal + depth");
64 println!(" 3. Lighting Pass → lit scene");
65 println!(" 4. Post-Processing → bloom, tone mapping");
66 println!(" 5. UI Pass → final composite");
67 println!("\n Render Graph API Usage:");
68 println!(" let mut graph = RenderGraph::new();");
69 println!(" graph.add_pass(\"shadow\", shadow_pass_descriptor);");
70 println!(" graph.add_pass(\"geometry\", geometry_pass_descriptor);");
71 println!(" graph.add_dependency(\"lighting\", \"geometry\");");
72 println!(" graph.compile();");
73 println!(" graph.execute(&mut encoder);");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Render graph demo initialized");
77
78 Box::new(RenderGraphDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/mesh_primitives.rs (line 46)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Mesh Primitives Demo - Geometry API".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 📐 MESH PRIMITIVES DEMO - Geometry API");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n MESH API FEATURES:");
56 println!(" • MeshBuilder for custom geometry");
57 println!(" • Primitive generation (cube, sphere, plane, etc.)");
58 println!(" • Flexible vertex formats (Position, Normal, UV, Color)");
59 println!(" • Index buffer optimization");
60 println!(" • Instanced rendering support");
61 println!("\n EXAMPLE PRIMITIVES:");
62 println!(" • Cube - box with 24 vertices (6 faces × 4 vertices)");
63 println!(" • Sphere - tessellated sphere with UV mapping");
64 println!(" • Plane - quad with optional subdivisions");
65 println!(" • Cylinder - sides + caps");
66 println!(" • Custom - arbitrary vertex/index data");
67 println!("\n Mesh API Usage:");
68 println!(" let mesh = MeshBuilder::new()");
69 println!(" .with_positions(vertices)");
70 println!(" .with_normals(normals)");
71 println!(" .with_uvs(uvs)");
72 println!(" .with_indices(indices)");
73 println!(" .build(&ctx);");
74 println!(" mesh.draw(&mut pass);");
75 println!(" mesh.draw_instanced(&mut pass, instance_count);");
76 println!("═══════════════════════════════════════════════════════\n");
77
78 tracing::info!("Mesh primitives demo initialized");
79
80 Box::new(MeshPrimitivesDemo {
81 _context: graphics_ctx,
82 window,
83 window_id,
84 })
85 });
86}examples/batched_renderer.rs (line 315)
278fn main() {
279 logging::init();
280
281 run_app(|ctx| {
282 let tier_override = parse_tier();
283
284 // Use the capability API to configure GPU requirements.
285 // For auto-detect, request the best capability (graceful degradation).
286 // For a specific tier, require that tier's capability.
287 let descriptor = match tier_override {
288 None => GraphicsContextDescriptor::new().request_capability::<BestBatchCapability2D>(),
289 Some(RenderTier::Direct) => {
290 GraphicsContextDescriptor::new().require_capability::<DirectBatchCapability2D>()
291 }
292 Some(RenderTier::Indirect) => {
293 GraphicsContextDescriptor::new().require_capability::<IndirectBatchCapability2D>()
294 }
295 Some(RenderTier::Bindless) => {
296 GraphicsContextDescriptor::new().require_capability::<BindlessBatchCapability2D>()
297 }
298 };
299 let graphics_ctx =
300 pollster::block_on(GraphicsContext::new_owned_with_descriptor(descriptor))
301 .expect("Failed to create graphics context");
302
303 let window = ctx
304 .create_window(WindowDescriptor {
305 title: "Batched Renderer Example".to_string(),
306 size: Some(WinitPhysicalSize::new(800.0, 600.0)),
307 ..Default::default()
308 })
309 .expect("Failed to create window");
310
311 let surface_format = wgpu::TextureFormat::Bgra8UnormSrgb;
312
313 let renderable_window = RenderWindowBuilder::new()
314 .color_format(surface_format)
315 .with_depth_default()
316 .build(window, graphics_ctx.clone())
317 .expect("Failed to create render window");
318
319 let window_id = renderable_window.id();
320
321 let renderer =
322 create_batch_renderer_2d(graphics_ctx.clone(), surface_format, tier_override);
323
324 tracing::info!("Using render tier: {}", renderer.tier());
325
326 // Create initial depth buffer
327 let depth_texture = graphics_ctx
328 .device()
329 .create_texture(&wgpu::TextureDescriptor {
330 label: Some("example_depth"),
331 size: wgpu::Extent3d {
332 width: 1,
333 height: 1,
334 depth_or_array_layers: 1,
335 },
336 mip_level_count: 1,
337 sample_count: 1,
338 dimension: wgpu::TextureDimension::D2,
339 format: DEPTH_FORMAT,
340 usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
341 view_formats: &[],
342 });
343 let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
344
345 let mut windows = HashMap::new();
346 windows.insert(window_id, renderable_window);
347
348 Box::new(App {
349 context: graphics_ctx,
350 windows,
351 renderer,
352 depth_texture,
353 depth_view,
354 depth_width: 1,
355 depth_height: 1,
356 frame_count: 0,
357 })
358 });
359}Sourcepub fn with_profiling(self, enabled: bool) -> Self
pub fn with_profiling(self, enabled: bool) -> Self
Enable GPU profiling for this window.
Sourcepub fn build(
self,
window: Window,
graphics: Arc<GraphicsContext>,
) -> Result<RenderWindow, GraphicsError>
pub fn build( self, window: Window, graphics: Arc<GraphicsContext>, ) -> Result<RenderWindow, GraphicsError>
Build the render window.
Examples found in repository?
examples/multi_window.rs (line 68)
25fn main() {
26 logging::init();
27
28 run_app(|ctx| {
29 let graphics_ctx =
30 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
31
32 let mut windows = HashMap::new();
33
34 // Create 3 windows with different colors
35 let colors = [
36 wgpu::Color {
37 r: 0.8,
38 g: 0.2,
39 b: 0.2,
40 a: 1.0,
41 },
42 wgpu::Color {
43 r: 0.2,
44 g: 0.8,
45 b: 0.2,
46 a: 1.0,
47 },
48 wgpu::Color {
49 r: 0.2,
50 g: 0.2,
51 b: 0.8,
52 a: 1.0,
53 },
54 ];
55
56 for (i, color) in colors.iter().enumerate() {
57 let window = ctx
58 .create_window(WindowDescriptor {
59 title: format!("Window {} - Multi-Window Example", i + 1),
60 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
61 ..Default::default()
62 })
63 .expect("Failed to create window");
64
65 let renderable_window = RenderWindowBuilder::new()
66 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
67 .with_depth_default()
68 .build(window, graphics_ctx.clone())
69 .expect("Failed to create render window");
70
71 let window_id = renderable_window.id();
72 windows.insert(window_id, (renderable_window, *color));
73 }
74
75 Box::new(App { windows })
76 });
77}More examples
examples/performance_benchmark.rs (line 54)
36fn main() {
37 logging::init();
38
39 run_app(|ctx| {
40 let graphics_ctx =
41 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
42
43 let window = ctx
44 .create_window(WindowDescriptor {
45 title: "Performance Benchmark - Render Stress Test".to_string(),
46 size: Some(WinitPhysicalSize::new(1280.0, 720.0)),
47 ..Default::default()
48 })
49 .expect("Failed to create window");
50
51 let window = RenderWindowBuilder::new()
52 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
53 .with_depth_default()
54 .build(window, graphics_ctx.clone())
55 .expect("Failed to create render window");
56
57 let window_id = window.id();
58
59 println!("\n═══════════════════════════════════════════════════════");
60 println!(" ⚡ PERFORMANCE BENCHMARK - Render Stress Test");
61 println!("═══════════════════════════════════════════════════════");
62 println!(" CONTROLS:");
63 println!(" [Space] Toggle rendering on/off");
64 println!(" [+/-] Increase/decrease object count");
65 println!(" Starting with 1000 objects");
66 println!("═══════════════════════════════════════════════════════\n");
67
68 Box::new(PerformanceBenchmark {
69 _context: graphics_ctx,
70 window,
71 window_id,
72 object_count: 1000,
73 rendering: true,
74 frame_count: 0,
75 last_fps_time: Instant::now(),
76 fps: 0.0,
77 last_frame_time: 0.0,
78 })
79 });
80}examples/camera_demo.rs (line 48)
30fn main() {
31 logging::init();
32
33 run_app(|ctx| {
34 let graphics_ctx =
35 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
36
37 let window = ctx
38 .create_window(WindowDescriptor {
39 title: "Camera Demo - View & Projection".to_string(),
40 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
41 ..Default::default()
42 })
43 .expect("Failed to create window");
44
45 let window = RenderWindowBuilder::new()
46 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
47 .with_depth_default()
48 .build(window, graphics_ctx.clone())
49 .expect("Failed to create render window");
50
51 let window_id = window.id();
52
53 println!("\n═══════════════════════════════════════════════════════");
54 println!(" 📹 CAMERA DEMO - View & Projection");
55 println!("═══════════════════════════════════════════════════════");
56 println!("\n CAMERA API FEATURES:");
57 println!(" • Orthographic cameras (2D, UI, isometric)");
58 println!(" • Perspective cameras (3D scenes)");
59 println!(" • View matrix (position, rotation, look-at)");
60 println!(" • Projection matrix (FOV, aspect, near/far planes)");
61 println!(" • Screen-to-world coordinate conversion");
62 println!(" • Camera movement helpers");
63 println!("\n CAMERA TYPES:");
64 println!(" • OrthographicCamera - 2D games, UI overlays");
65 println!(" camera.orthographic(left, right, bottom, top, near, far)");
66 println!(" • PerspectiveCamera - 3D scenes");
67 println!(" camera.perspective(fov, aspect, near, far)");
68 println!("\n Camera API Usage:");
69 println!(" let camera = Camera::new()");
70 println!(" .position(Vec3::new(0.0, 5.0, 10.0))");
71 println!(" .look_at(Vec3::ZERO)");
72 println!(" .perspective(60.0, aspect, 0.1, 100.0);");
73 println!(" let view_proj = camera.view_projection_matrix();");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Camera demo initialized");
77
78 Box::new(CameraDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/render_graph_demo.rs (line 47)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Render Graph Demo - Multi-Pass Rendering".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 🔀 RENDER GRAPH DEMO - Multi-Pass Rendering");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n RENDER GRAPH FEATURES:");
56 println!(" • Declarative pass definition");
57 println!(" • Automatic dependency resolution");
58 println!(" • Resource lifetime management");
59 println!(" • Parallel pass execution");
60 println!(" • Automatic optimization");
61 println!("\n EXAMPLE PIPELINE:");
62 println!(" 1. Shadow Pass → depth texture");
63 println!(" 2. Geometry Pass → color + normal + depth");
64 println!(" 3. Lighting Pass → lit scene");
65 println!(" 4. Post-Processing → bloom, tone mapping");
66 println!(" 5. UI Pass → final composite");
67 println!("\n Render Graph API Usage:");
68 println!(" let mut graph = RenderGraph::new();");
69 println!(" graph.add_pass(\"shadow\", shadow_pass_descriptor);");
70 println!(" graph.add_pass(\"geometry\", geometry_pass_descriptor);");
71 println!(" graph.add_dependency(\"lighting\", \"geometry\");");
72 println!(" graph.compile();");
73 println!(" graph.execute(&mut encoder);");
74 println!("═══════════════════════════════════════════════════════\n");
75
76 tracing::info!("Render graph demo initialized");
77
78 Box::new(RenderGraphDemo {
79 _context: graphics_ctx,
80 window,
81 window_id,
82 })
83 });
84}examples/mesh_primitives.rs (line 47)
29fn main() {
30 logging::init();
31
32 run_app(|ctx| {
33 let graphics_ctx =
34 GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
35
36 let window = ctx
37 .create_window(WindowDescriptor {
38 title: "Mesh Primitives Demo - Geometry API".to_string(),
39 size: Some(WinitPhysicalSize::new(1024.0, 768.0)),
40 ..Default::default()
41 })
42 .expect("Failed to create window");
43
44 let window = RenderWindowBuilder::new()
45 .color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
46 .with_depth_default()
47 .build(window, graphics_ctx.clone())
48 .expect("Failed to create render window");
49
50 let window_id = window.id();
51
52 println!("\n═══════════════════════════════════════════════════════");
53 println!(" 📐 MESH PRIMITIVES DEMO - Geometry API");
54 println!("═══════════════════════════════════════════════════════");
55 println!("\n MESH API FEATURES:");
56 println!(" • MeshBuilder for custom geometry");
57 println!(" • Primitive generation (cube, sphere, plane, etc.)");
58 println!(" • Flexible vertex formats (Position, Normal, UV, Color)");
59 println!(" • Index buffer optimization");
60 println!(" • Instanced rendering support");
61 println!("\n EXAMPLE PRIMITIVES:");
62 println!(" • Cube - box with 24 vertices (6 faces × 4 vertices)");
63 println!(" • Sphere - tessellated sphere with UV mapping");
64 println!(" • Plane - quad with optional subdivisions");
65 println!(" • Cylinder - sides + caps");
66 println!(" • Custom - arbitrary vertex/index data");
67 println!("\n Mesh API Usage:");
68 println!(" let mesh = MeshBuilder::new()");
69 println!(" .with_positions(vertices)");
70 println!(" .with_normals(normals)");
71 println!(" .with_uvs(uvs)");
72 println!(" .with_indices(indices)");
73 println!(" .build(&ctx);");
74 println!(" mesh.draw(&mut pass);");
75 println!(" mesh.draw_instanced(&mut pass, instance_count);");
76 println!("═══════════════════════════════════════════════════════\n");
77
78 tracing::info!("Mesh primitives demo initialized");
79
80 Box::new(MeshPrimitivesDemo {
81 _context: graphics_ctx,
82 window,
83 window_id,
84 })
85 });
86}examples/batched_renderer.rs (line 316)
278fn main() {
279 logging::init();
280
281 run_app(|ctx| {
282 let tier_override = parse_tier();
283
284 // Use the capability API to configure GPU requirements.
285 // For auto-detect, request the best capability (graceful degradation).
286 // For a specific tier, require that tier's capability.
287 let descriptor = match tier_override {
288 None => GraphicsContextDescriptor::new().request_capability::<BestBatchCapability2D>(),
289 Some(RenderTier::Direct) => {
290 GraphicsContextDescriptor::new().require_capability::<DirectBatchCapability2D>()
291 }
292 Some(RenderTier::Indirect) => {
293 GraphicsContextDescriptor::new().require_capability::<IndirectBatchCapability2D>()
294 }
295 Some(RenderTier::Bindless) => {
296 GraphicsContextDescriptor::new().require_capability::<BindlessBatchCapability2D>()
297 }
298 };
299 let graphics_ctx =
300 pollster::block_on(GraphicsContext::new_owned_with_descriptor(descriptor))
301 .expect("Failed to create graphics context");
302
303 let window = ctx
304 .create_window(WindowDescriptor {
305 title: "Batched Renderer Example".to_string(),
306 size: Some(WinitPhysicalSize::new(800.0, 600.0)),
307 ..Default::default()
308 })
309 .expect("Failed to create window");
310
311 let surface_format = wgpu::TextureFormat::Bgra8UnormSrgb;
312
313 let renderable_window = RenderWindowBuilder::new()
314 .color_format(surface_format)
315 .with_depth_default()
316 .build(window, graphics_ctx.clone())
317 .expect("Failed to create render window");
318
319 let window_id = renderable_window.id();
320
321 let renderer =
322 create_batch_renderer_2d(graphics_ctx.clone(), surface_format, tier_override);
323
324 tracing::info!("Using render tier: {}", renderer.tier());
325
326 // Create initial depth buffer
327 let depth_texture = graphics_ctx
328 .device()
329 .create_texture(&wgpu::TextureDescriptor {
330 label: Some("example_depth"),
331 size: wgpu::Extent3d {
332 width: 1,
333 height: 1,
334 depth_or_array_layers: 1,
335 },
336 mip_level_count: 1,
337 sample_count: 1,
338 dimension: wgpu::TextureDimension::D2,
339 format: DEPTH_FORMAT,
340 usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
341 view_formats: &[],
342 });
343 let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
344
345 let mut windows = HashMap::new();
346 windows.insert(window_id, renderable_window);
347
348 Box::new(App {
349 context: graphics_ctx,
350 windows,
351 renderer,
352 depth_texture,
353 depth_view,
354 depth_width: 1,
355 depth_height: 1,
356 frame_count: 0,
357 })
358 });
359}Trait Implementations§
Source§impl Default for RenderWindowBuilder
impl Default for RenderWindowBuilder
Source§fn default() -> RenderWindowBuilder
fn default() -> RenderWindowBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RenderWindowBuilder
impl RefUnwindSafe for RenderWindowBuilder
impl Send for RenderWindowBuilder
impl Sync for RenderWindowBuilder
impl Unpin for RenderWindowBuilder
impl UnwindSafe for RenderWindowBuilder
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