CommandBuffer

Struct CommandBuffer 

Source
pub struct CommandBuffer { /* private fields */ }

Implementations§

Source§

impl CommandBuffer

Source

pub fn renderpass_builder(&mut self) -> RenderpassBuilder<'_>

Creates a new renderpass builder.

This function is used to create a renderpass builder that can be used to configure and build a render pass.

This is useful when you want to create a render pass with specific configurations, such as adding color attachments, depth attachments, etc.

Examples found in repository?
examples/clear_color.rs (line 35)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Clear Color Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    while runner.pump_events(None) {
18        for event in runner.get_events() {
19            match event {
20                Event::WindowClosed { .. } => {
21                    return;
22                }
23                _ => {}
24            }
25        }
26
27        if let Ok(mut cmd) = gpu.begin_command() {
28            let surface = cmd.get_surface_texture();
29            if surface.is_err() {
30                println!("Failed to get surface texture: {:?}", surface.err());
31                continue;
32            }
33
34            // Or you could use `cmd.begin_renderpass()` directly
35            if let Ok(mut rp) = cmd.renderpass_builder()
36                .add_surface_color_attachment(surface.as_ref().unwrap(), Some(&BlendState::ALPHA_BLEND))
37                .build() 
38            {
39                rp.set_clear_color(Color::BLUE);
40            }
41        }
42    }
43}
Source

pub fn begin_renderpass(&mut self) -> Result<RenderPass, RenderPassBuildError>

Begins a new graphics pass.

This function will initiate a renderpass with the swapchain’s surface texture. If the swapchain is not valid, it will attempt to recreate it.

The swapchain will be used as the color attachment at index 0 with a default blend mode (NONE).

Examples found in repository?
examples/gpu_adapter.rs (line 45)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7    let mut window = runner
8        .create_window("Engine Example", Point2::new(800, 600))
9        .build()
10        .expect("Failed to create window");
11
12    let adapters = est_render::gpu::query_gpu_adapter(Some(&window));
13    if adapters.is_empty() {
14        eprintln!("No GPU adapters found. Exiting.");
15        return;
16    }
17
18    let selected_adapter = adapters
19        .iter()
20        .find(|adapter| adapter.backend_enum == AdapterBackend::Vulkan)
21        .cloned();
22
23    if selected_adapter.is_none() {
24        eprintln!("No suitable GPU adapter found. Exiting.");
25        return;
26    }
27
28    let adapter = selected_adapter.unwrap();
29    let mut gpu = est_render::gpu::new(Some(&mut window))
30        .set_adapter(&adapter)
31        .build()
32        .expect("Failed to create GPU");
33
34    while runner.pump_events(None) {
35        for event in runner.get_events() {
36            match event {
37                Event::WindowClosed { .. } => {
38                    return;
39                }
40                _ => {}
41            }
42        }
43
44        if let Ok(mut cmd) = gpu.begin_command() {
45            if let Ok(mut rp) = cmd.begin_renderpass() {
46                rp.set_clear_color(Color::LIGHTBLUE);
47            }
48        }
49    }
50}
More examples
Hide additional examples
examples/drawing.rs (line 34)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Drawing Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    let mut rotation = 0.0f32;
18    while runner.pump_events(None) {
19        for event in runner.get_events() {
20            match event {
21                Event::WindowClosed { .. } => {
22                    return;
23                }
24                _ => {}
25            }
26        }
27
28        rotation += runner.get_frame_time() as f32 * 60.0f32; // Rotate at 60 degrees per second
29        if rotation >= 360.0 {
30            rotation -= 360.0; // Reset rotation after a full circle
31        }
32
33        if let Ok(mut cmd) = gpu.begin_command() {
34            if let Ok(mut gp) = cmd.begin_renderpass() {
35                gp.set_clear_color(Color::BLUE); // Set the clear color to blue
36
37                if let Some(mut drawing) = gp.begin_drawing() {
38                    drawing.set_rotation(rotation); // Set rotation to 45 degrees
39                    gp.set_blend(0, Some(&BlendState::ALPHA_BLEND));
40                    drawing.draw_rect_filled(
41                        Vector2::new(100.0, 100.0),
42                        Vector2::new(200.0, 200.0),
43                        Color::RED,
44                    );
45
46                    drawing.draw_circle_filled(Vector2::new(400.0, 300.0), 50.0, 25, Color::GREEN);
47
48                    gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
49
50                    drawing.draw_text(
51                        "Hello, World!",
52                        Vector2::new(300.0, 500.0),
53                        Color::WHITE,
54                    );
55                }
56            }
57        }
58    }
59}
examples/font.rs (line 39)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Font Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    let mut font_manager = est_render::font::new();
18
19    let font = font_manager
20        .load_font("Arial", None, 20.0)
21        .expect("Failed to load font");
22
23    // Generate baked text texture
24    let texture = font
25        .create_baked_text(&mut gpu, "Hello, World!\nThis is a clear color example.", None)
26        .expect("Failed to create baked text");
27
28    while runner.pump_events(None) {
29        for event in runner.get_events() {
30            match event {
31                Event::WindowClosed { .. } => {
32                    return;
33                }
34                _ => {}
35            }
36        }
37
38        if let Ok(mut cmd) = gpu.begin_command() {
39            if let Ok(mut gp) = cmd.begin_renderpass() {
40                gp.set_clear_color(Color::BLUE);
41
42                // The best texture blend for font rendering, others may has artifacts like black borders
43                gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
44                
45                if let Some(mut drawing) = gp.begin_drawing() {
46                    let size: Vector2 = texture.size().into();
47
48                    // Baked text rendering
49                    drawing.set_texture(Some(&texture));
50                    drawing.draw_rect_image(Vector2::new(0.0, 0.0), size, Color::WHITE);
51
52                    // Online text rendering
53                    drawing.set_font(&font);
54                    drawing.draw_text(
55                        "Hello, World!\nThis is a clear color example.",
56                        Vector2::new(size.x, 0.0),
57                        Color::WHITE,
58                    );
59                }
60            }
61        }
62    }
63}
examples/texture_atlas.rs (line 41)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Clear Color Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    let texture_atlas = gpu
18        .create_texture_atlas()
19        .add_texture_file(
20            "example_texture",
21            "./examples/resources/test1.png",
22        )
23        .add_texture_file(
24            "example_texture2",
25            "./examples/resources/test2.png",
26        )
27        .build()
28        .expect("Failed to create texture atlas");
29
30    while runner.pump_events(None) {
31        for event in runner.get_events() {
32            match event {
33                Event::WindowClosed { .. } => {
34                    return;
35                }
36                _ => {}
37            }
38        }
39
40        if let Ok(mut cmd) = gpu.begin_command() {
41            if let Ok(mut gp) = cmd.begin_renderpass() {
42                gp.set_clear_color(Color::BLUEVIOLET);
43                gp.set_blend(0, Some(&BlendState::NONE));
44
45                if let Some(mut drawing) = gp.begin_drawing() {
46                    drawing.set_texture_atlas(Some((&texture_atlas, "example_texture")));
47                    drawing.draw_rect_image(
48                        Vector2::new(100.0, 100.0),
49                        Vector2::new(200.0, 200.0),
50                        Color::WHITE,
51                    );
52                    drawing.set_texture_atlas(Some((&texture_atlas, "example_texture2")));
53                    drawing.draw_rect_image(
54                        Vector2::new(350.0, 100.0),
55                        Vector2::new(200.0, 200.0),
56                        Color::WHITE,
57                    );
58                    drawing.draw_circle_image(Vector2::new(600.0, 200.0), 100.0, 20, Color::WHITE);
59                }
60            }
61        }
62    }
63}
examples/msaa.rs (line 101)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7    let mut window = runner
8        .create_window("Engine Example", Point2::new(800, 600))
9        .build()
10        .expect("Failed to create window");
11
12    let mut gpu = est_render::gpu::new(Some(&mut window))
13        .build()
14        .expect("Failed to create GPU");
15
16    let mut msaa_texture = Some(
17        gpu.create_texture()
18            .set_render_target(Point2::new(800, 600), None)
19            .set_usage(TextureUsage::Sampler)
20            .set_sample_count(SampleCount::SampleCount4)
21            .build()
22            .expect("Failed to create MSAA texture"),
23    );
24
25    let mut msaa_count = SampleCount::SampleCount4;
26    let mut window_size = Point2::new(800, 600);
27
28    while runner.pump_events(None) {
29        for event in runner.get_events() {
30            match event {
31                Event::WindowClosed { .. } => {
32                    return;
33                }
34                Event::KeyboardInput { key, pressed, .. } => {
35                    if !*pressed {
36                        continue;
37                    }
38
39                    let mut need_recreate = false;
40                    if *key == "1" {
41                        msaa_count = SampleCount::SampleCount1;
42                        need_recreate = true;
43                    }
44
45                    if *key == "2" {
46                        msaa_count = SampleCount::SampleCount2;
47                        need_recreate = true;
48                    }
49
50                    if *key == "3" {
51                        msaa_count = SampleCount::SampleCount4;
52                        need_recreate = true;
53                    }
54
55                    if *key == "4" {
56                        msaa_count = SampleCount::SampleCount8;
57                        need_recreate = true;
58                    }
59
60                    if need_recreate {
61                        if msaa_count == SampleCount::SampleCount1 {
62                            msaa_texture = None;
63                        } else {
64                            msaa_texture = Some(
65                                gpu.create_texture()
66                                    .set_render_target(
67                                        Point2::new(window_size.x, window_size.y),
68                                        None,
69                                    )
70                                    .set_usage(TextureUsage::Sampler)
71                                    .set_sample_count(msaa_count)
72                                    .build()
73                                    .expect("Failed to recreate MSAA texture"),
74                            );
75                        }
76                    }
77                }
78                Event::WindowResized { size, .. } => {
79                    if size.x <= 0 || size.y <= 0 {
80                        eprintln!("Invalid window size: {:?}", size);
81                        continue;
82                    }
83
84                    window_size = *size;
85
86                    // Resize the MSAA texture to match the new window size
87                    msaa_texture = Some(
88                        gpu.create_texture()
89                            .set_render_target(Point2::new(size.x, size.y), None)
90                            .set_usage(TextureUsage::Sampler)
91                            .set_sample_count(msaa_count)
92                            .build()
93                            .expect("Failed to resize MSAA texture"),
94                    );
95                }
96                _ => {}
97            }
98        }
99
100        if let Ok(mut cmd) = gpu.begin_command() {
101            if let Ok(mut rp) = cmd.begin_renderpass() {
102                rp.set_clear_color(Color::BLACK);
103                if let Some(texture) = msaa_texture.as_ref() {
104                    rp.push_msaa_texture(texture);
105                }
106
107                if let Some(mut drawing) = rp.begin_drawing() {
108                    let pos1 = Vector2::new(0.0, 0.0);
109                    let pos2 = Vector2::new(800.0, 0.0);
110                    let pos3 = Vector2::new(400.0, 600.0);
111
112                    // Draw a full triangle covering the window
113                    drawing.draw_triangle_filled(pos1, pos2, pos3, Color::BLUE);
114                }
115            }
116        }
117    }
118}
examples/pipeline.rs (line 184)
61fn main() {
62    let mut runner = est_render::runner::new().expect("Failed to create runner");
63    let mut window = runner
64        .create_window("Engine Example", Point2::new(800, 600))
65        .build()
66        .expect("Failed to create window");
67
68    let mut gpu = est_render::gpu::new(Some(&mut window))
69        .build()
70        .expect("Failed to create GPU");
71
72    let mut msaa_texture = gpu
73        .create_texture()
74        .set_render_target(Point2::new(800, 600), None)
75        .set_sample_count(SampleCount::SampleCount4)
76        .build()
77        .expect("Failed to create MSAA texture");
78
79    let blank_texture = gpu
80        .create_texture()
81        .set_raw_image(
82            &[255u8; 4],
83            Point2::new(1, 1),
84            TextureFormat::Bgra8Unorm,
85        )
86        .set_usage(TextureUsage::Sampler)
87        .build()
88        .expect("Failed to create blank texture");
89
90    let shader = gpu
91        .create_graphics_shader()
92        .set_vertex_code(VERTEX_DRAWING_SHADER)
93        .set_fragment_code(FRAGMENT_DRAWING_SHADER)
94        .build()
95        .expect("Failed to create graphics shader");
96
97    let compute_shader = gpu
98        .create_compute_shader()
99        .set_source(COMPUTE_NOOP_SHADER)
100        .build()
101        .expect("Failed to create compute shader");
102
103    let pipeline = gpu
104        .create_render_pipeline()
105        .set_shader(Some(&shader))
106        .set_blend(Some(&BlendState::ALPHA_BLEND))
107        .set_attachment_texture(0, 0, Some(&blank_texture))
108        .set_attachment_sampler(0, 1, Some(&TextureSampler::DEFAULT))
109        .build()
110        .expect("Failed to create render pipeline");
111
112    let compute_pipeline = gpu
113        .create_compute_pipeline()
114        .set_shader(Some(&compute_shader))
115        .build()
116        .expect("Failed to create compute pipeline");
117
118    // Triangle vertices
119    let vertices = vec![
120        Vertex {
121            position: Vector3::new(-0.5, -0.5, 0.0),
122            color: Color::new(1.0, 0.0, 0.0, 1.0),
123            texcoord: Vector2::new(0.0, 1.0),
124        },
125        Vertex {
126            position: Vector3::new(0.5, -0.5, 0.0),
127            color: Color::new(0.0, 1.0, 0.0, 1.0),
128            texcoord: Vector2::new(1.0, 1.0),
129        },
130        Vertex {
131            position: Vector3::new(0.0, 0.5, 0.0),
132            color: Color::new(0.0, 0.0, 1.0, 1.0),
133            texcoord: Vector2::new(0.5, 0.0),
134        },
135    ];
136
137    let indexes = vec![0u16, 1u16, 2u16];
138
139    let vbo = gpu
140        .create_buffer()
141        .set_data_vec(vertices)
142        .set_usage(BufferUsage::VERTEX)
143        .build()
144        .expect("Failed to create vertex buffer");
145
146    let ibo = gpu
147        .create_buffer()
148        .set_data_vec(indexes)
149        .set_usage(BufferUsage::INDEX)
150        .build()
151        .expect("Failed to create index buffer");
152
153    while runner.pump_events(PumpMode::WaitDraw) {
154        for event in runner.get_events() {
155            match event {
156                Event::KeyboardInput {
157                    window_id,
158                    key,
159                    pressed,
160                } => {
161                    if *window_id == window.id() && key == "Escape" && *pressed {
162                        window.quit();
163                    }
164                }
165                Event::WindowResized { window_id: _, size } => {
166                    if size.x <= 0 || size.y <= 0 {
167                        continue; // Skip invalid sizes
168                    }
169
170                    msaa_texture = gpu
171                        .create_texture()
172                        .set_render_target(Point2::new(size.x as u32, size.y as u32), None)
173                        .set_sample_count(SampleCount::SampleCount4)
174                        .build()
175                        .expect("Failed to resize MSAA texture");
176                }
177                Event::RedrawRequested { window_id: _ } => {
178                    if let Ok(mut cmd) = gpu.begin_command() {
179                        if let Ok(mut cm) = cmd.begin_computepass() {
180                            cm.set_pipeline(Some(&compute_pipeline));
181                            cm.dispatch(1, 1, 1);
182                        }
183
184                        if let Ok(mut rp) = cmd.begin_renderpass() {
185                            rp.set_clear_color(Color::BLACK);
186                            rp.push_msaa_texture(&msaa_texture);
187
188                            rp.set_pipeline(Some(&pipeline));
189                            rp.set_gpu_buffer(Some(&vbo), Some(&ibo));
190                            rp.draw_indexed(0..3, 0, 1);
191                        }
192                    }
193
194                    window.request_redraw();
195                }
196                _ => {}
197            }
198        }
199    }
200}
Source

pub fn begin_depth_texture( &mut self, texture: &Texture, ) -> Result<RenderPass, RenderPassBuildError>

Begins a new graphics pass with a depth texture.

This function is used to create a render pass with a depth texture for depth-only rendering. Which can be useful for shadow mapping or other depth-based effects.

Source

pub fn begin_texture<'a>( &'a mut self, texture: &'a Texture, ) -> Result<RenderPass, RenderPassBuildError>

Begins a new graphics pass to a render target texture.

Can be used to render to a specific texture instead of the default swapchain. This is useful for offscreen rendering or rendering to a texture for later use.

The render texture will be placed at index 0 with a default blend mode (NONE).

Source

pub fn begin_computepass( &mut self, ) -> Result<ComputePass, ComputePassBuildError>

Begins a new compute pass.

Examples found in repository?
examples/pipeline.rs (line 179)
61fn main() {
62    let mut runner = est_render::runner::new().expect("Failed to create runner");
63    let mut window = runner
64        .create_window("Engine Example", Point2::new(800, 600))
65        .build()
66        .expect("Failed to create window");
67
68    let mut gpu = est_render::gpu::new(Some(&mut window))
69        .build()
70        .expect("Failed to create GPU");
71
72    let mut msaa_texture = gpu
73        .create_texture()
74        .set_render_target(Point2::new(800, 600), None)
75        .set_sample_count(SampleCount::SampleCount4)
76        .build()
77        .expect("Failed to create MSAA texture");
78
79    let blank_texture = gpu
80        .create_texture()
81        .set_raw_image(
82            &[255u8; 4],
83            Point2::new(1, 1),
84            TextureFormat::Bgra8Unorm,
85        )
86        .set_usage(TextureUsage::Sampler)
87        .build()
88        .expect("Failed to create blank texture");
89
90    let shader = gpu
91        .create_graphics_shader()
92        .set_vertex_code(VERTEX_DRAWING_SHADER)
93        .set_fragment_code(FRAGMENT_DRAWING_SHADER)
94        .build()
95        .expect("Failed to create graphics shader");
96
97    let compute_shader = gpu
98        .create_compute_shader()
99        .set_source(COMPUTE_NOOP_SHADER)
100        .build()
101        .expect("Failed to create compute shader");
102
103    let pipeline = gpu
104        .create_render_pipeline()
105        .set_shader(Some(&shader))
106        .set_blend(Some(&BlendState::ALPHA_BLEND))
107        .set_attachment_texture(0, 0, Some(&blank_texture))
108        .set_attachment_sampler(0, 1, Some(&TextureSampler::DEFAULT))
109        .build()
110        .expect("Failed to create render pipeline");
111
112    let compute_pipeline = gpu
113        .create_compute_pipeline()
114        .set_shader(Some(&compute_shader))
115        .build()
116        .expect("Failed to create compute pipeline");
117
118    // Triangle vertices
119    let vertices = vec![
120        Vertex {
121            position: Vector3::new(-0.5, -0.5, 0.0),
122            color: Color::new(1.0, 0.0, 0.0, 1.0),
123            texcoord: Vector2::new(0.0, 1.0),
124        },
125        Vertex {
126            position: Vector3::new(0.5, -0.5, 0.0),
127            color: Color::new(0.0, 1.0, 0.0, 1.0),
128            texcoord: Vector2::new(1.0, 1.0),
129        },
130        Vertex {
131            position: Vector3::new(0.0, 0.5, 0.0),
132            color: Color::new(0.0, 0.0, 1.0, 1.0),
133            texcoord: Vector2::new(0.5, 0.0),
134        },
135    ];
136
137    let indexes = vec![0u16, 1u16, 2u16];
138
139    let vbo = gpu
140        .create_buffer()
141        .set_data_vec(vertices)
142        .set_usage(BufferUsage::VERTEX)
143        .build()
144        .expect("Failed to create vertex buffer");
145
146    let ibo = gpu
147        .create_buffer()
148        .set_data_vec(indexes)
149        .set_usage(BufferUsage::INDEX)
150        .build()
151        .expect("Failed to create index buffer");
152
153    while runner.pump_events(PumpMode::WaitDraw) {
154        for event in runner.get_events() {
155            match event {
156                Event::KeyboardInput {
157                    window_id,
158                    key,
159                    pressed,
160                } => {
161                    if *window_id == window.id() && key == "Escape" && *pressed {
162                        window.quit();
163                    }
164                }
165                Event::WindowResized { window_id: _, size } => {
166                    if size.x <= 0 || size.y <= 0 {
167                        continue; // Skip invalid sizes
168                    }
169
170                    msaa_texture = gpu
171                        .create_texture()
172                        .set_render_target(Point2::new(size.x as u32, size.y as u32), None)
173                        .set_sample_count(SampleCount::SampleCount4)
174                        .build()
175                        .expect("Failed to resize MSAA texture");
176                }
177                Event::RedrawRequested { window_id: _ } => {
178                    if let Ok(mut cmd) = gpu.begin_command() {
179                        if let Ok(mut cm) = cmd.begin_computepass() {
180                            cm.set_pipeline(Some(&compute_pipeline));
181                            cm.dispatch(1, 1, 1);
182                        }
183
184                        if let Ok(mut rp) = cmd.begin_renderpass() {
185                            rp.set_clear_color(Color::BLACK);
186                            rp.push_msaa_texture(&msaa_texture);
187
188                            rp.set_pipeline(Some(&pipeline));
189                            rp.set_gpu_buffer(Some(&vbo), Some(&ibo));
190                            rp.draw_indexed(0..3, 0, 1);
191                        }
192                    }
193
194                    window.request_redraw();
195                }
196                _ => {}
197            }
198        }
199    }
200}
Source

pub fn write_buffer(&mut self, src: &Buffer, dst: &Buffer)

Writes a buffer to a destination buffer.

This is useful to copy from compute buffers or other buffers to a destination buffer, such as when you want to update a buffer with new data

Source

pub fn write_buffer_raw<T: Pod>(&mut self, data: &[T], dst: &Buffer)

Writes a buffer to a destination buffer with raw data.

Will panic if the data is not compatible with the destination buffer, such in the case of mismatched sizes or types.

Source

pub fn blit_texture(&mut self, src: &Texture, dst: &Texture)

Copies a source texture to a destination texture.

This function uses a texture blitter to perform the copy operation, such copying between different texture formats or sizes (ex from a render target to a texture).

Source

pub fn copy_texture(&mut self, src: &Texture, dst: &Texture)

Copies a source texture to a destination texture.

The ‘src’ texture must be compatible with the ‘dst’ texture in format and size.

This is useful for copying textures that are already in the GPU memory, such as when you want to copy a texture from one render target to another.

Source

pub fn end(&mut self, present: bool)

Source

pub fn get_surface_texture( &mut self, ) -> Result<SurfaceTexture, SurfaceTextureError>

Returns the current surface texture handle.

This will attach current swapchain texture to the command buffer if it is not already set.

Examples found in repository?
examples/clear_color.rs (line 28)
5fn main() {
6    let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8    let mut window = runner
9        .create_window("Clear Color Example", Point2::new(800, 600))
10        .build()
11        .expect("Failed to create window");
12
13    let mut gpu = est_render::gpu::new(Some(&mut window))
14        .build()
15        .expect("Failed to create GPU");
16
17    while runner.pump_events(None) {
18        for event in runner.get_events() {
19            match event {
20                Event::WindowClosed { .. } => {
21                    return;
22                }
23                _ => {}
24            }
25        }
26
27        if let Ok(mut cmd) = gpu.begin_command() {
28            let surface = cmd.get_surface_texture();
29            if surface.is_err() {
30                println!("Failed to get surface texture: {:?}", surface.err());
31                continue;
32            }
33
34            // Or you could use `cmd.begin_renderpass()` directly
35            if let Ok(mut rp) = cmd.renderpass_builder()
36                .add_surface_color_attachment(surface.as_ref().unwrap(), Some(&BlendState::ALPHA_BLEND))
37                .build() 
38            {
39                rp.set_clear_color(Color::BLUE);
40            }
41        }
42    }
43}

Trait Implementations§

Source§

impl Clone for CommandBuffer

Source§

fn clone(&self) -> CommandBuffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for CommandBuffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more