SimpleBuffer

Struct SimpleBuffer 

Source
pub struct SimpleBuffer { /* private fields */ }
Expand description

wrapper for Buffer which stores count of elements

Implementations§

Source§

impl SimpleBuffer

Source

pub fn size(&self) -> u32

Examples found in repository?
examples/display_rect.rs (line 67)
31fn render(app_data: &AppData, _: &mut (), mut encoder: CommandEncoder, view: TextureView) {
32    let vertex_buffer = BufferCreator::vertex(&app_data.device)
33        .data(vec![
34            ColoredVertex {
35                position: [-0.5, 0.5, 0.0],
36                color: [0.2, 0.0, 0.3],
37            },
38            ColoredVertex {
39                position: [-0.5, -0.5, 0.0],
40                color: [0.2, 0.0, 0.3],
41            },
42            ColoredVertex {
43                position: [0.5, 0.5, 0.0],
44                color: [0.2, 0.0, 0.3],
45            },
46            ColoredVertex {
47                position: [0.5, -0.5, 0.0],
48                color: [0.2, 0.0, 0.3],
49            },
50        ])
51        .build();
52
53    let indices_buffer = BufferCreator::indices(&app_data.device)
54        .data(vec![0, 1, 2, 2, 1, 3])
55        .build();
56
57    {
58        let mut render_pass: RenderPass = RenderPassCreator::new(&view)
59            .clear_color(Color::BLACK)
60            .build(&mut encoder);
61
62        render_pass.set_pipeline(app_data.render_pipelines.get(0).unwrap());
63
64        render_pass.set_vertex_buffer(0, vertex_buffer.slice());
65        render_pass.set_index_buffer(indices_buffer.slice(), wgpu::IndexFormat::Uint32);
66
67        render_pass.draw_indexed(0..indices_buffer.size(), 0, 0..1);
68    }
69
70    app_data.queue.submit(once(encoder.finish()));
71}
Source

pub fn slice(&self) -> BufferSlice<'_>

Examples found in repository?
examples/moving_triangle.rs (line 71)
43fn render(app_data: &AppData, state: &mut State, mut encoder: CommandEncoder, view: TextureView) {
44    let vertex_buffer = BufferCreator::vertex(&app_data.device)
45        .data(vec![
46            ColoredPosVertex {
47                position: [
48                    (0.0 + state.pos.0) * state.x_scale,
49                    TRIANGLE_SIZE + state.pos.1,
50                ],
51            },
52            ColoredPosVertex {
53                position: [
54                    (-TRIANGLE_SIZE + state.pos.0) * state.x_scale,
55                    -TRIANGLE_SIZE + state.pos.1,
56                ],
57            },
58            ColoredPosVertex {
59                position: [
60                    (TRIANGLE_SIZE + state.pos.0) * state.x_scale,
61                    -TRIANGLE_SIZE + state.pos.1,
62                ],
63            },
64        ])
65        .build();
66
67    {
68        let mut render_pass = RenderPassCreator::new(&view).build(&mut encoder);
69
70        render_pass.set_pipeline(app_data.render_pipelines.get(0).unwrap());
71        render_pass.set_vertex_buffer(0, vertex_buffer.slice());
72
73        render_pass.draw(0..3, 0..1);
74    }
75
76    app_data.queue.submit(once(encoder.finish()));
77}
More examples
Hide additional examples
examples/display_rect.rs (line 64)
31fn render(app_data: &AppData, _: &mut (), mut encoder: CommandEncoder, view: TextureView) {
32    let vertex_buffer = BufferCreator::vertex(&app_data.device)
33        .data(vec![
34            ColoredVertex {
35                position: [-0.5, 0.5, 0.0],
36                color: [0.2, 0.0, 0.3],
37            },
38            ColoredVertex {
39                position: [-0.5, -0.5, 0.0],
40                color: [0.2, 0.0, 0.3],
41            },
42            ColoredVertex {
43                position: [0.5, 0.5, 0.0],
44                color: [0.2, 0.0, 0.3],
45            },
46            ColoredVertex {
47                position: [0.5, -0.5, 0.0],
48                color: [0.2, 0.0, 0.3],
49            },
50        ])
51        .build();
52
53    let indices_buffer = BufferCreator::indices(&app_data.device)
54        .data(vec![0, 1, 2, 2, 1, 3])
55        .build();
56
57    {
58        let mut render_pass: RenderPass = RenderPassCreator::new(&view)
59            .clear_color(Color::BLACK)
60            .build(&mut encoder);
61
62        render_pass.set_pipeline(app_data.render_pipelines.get(0).unwrap());
63
64        render_pass.set_vertex_buffer(0, vertex_buffer.slice());
65        render_pass.set_index_buffer(indices_buffer.slice(), wgpu::IndexFormat::Uint32);
66
67        render_pass.draw_indexed(0..indices_buffer.size(), 0, 0..1);
68    }
69
70    app_data.queue.submit(once(encoder.finish()));
71}

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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>