diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:20 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:20 +0100 |
commit | 7cdb4bb159a7df88390e63c59f0d4c5538d7411b (patch) | |
tree | 87867a506fbc0ac0a641080042ee95130209d17d /stockton-render/src/draw/context.rs | |
parent | 38ec1aa6b22e7e02c4b25c8fbf376b7cf5885009 (diff) |
feat(render): add size parameter during stagedbuffer creation
Diffstat (limited to 'stockton-render/src/draw/context.rs')
-rw-r--r-- | stockton-render/src/draw/context.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/stockton-render/src/draw/context.rs b/stockton-render/src/draw/context.rs index fced5e8..882db44 100644 --- a/stockton-render/src/draw/context.rs +++ b/stockton-render/src/draw/context.rs @@ -48,9 +48,9 @@ const VERTEX_SOURCE: &str = include_str!("./data/stockton.vert"); /// Source for fragment shader. TODO const FRAGMENT_SOURCE: &str = include_str!("./data/stockton.frag"); -/// Represents a point of a vertices, including U/V information. +/// Represents a point of a vertices, including RGB and UV information. #[derive(Debug, Clone, Copy)] -pub struct UVPoint (pub Vector2, pub Vector3); +pub struct UVPoint (pub Vector2, pub Vector3, pub Vector2); /// Contains all the hal related stuff. /// In the end, this takes some 3D points and puts it on the screen. @@ -257,8 +257,8 @@ impl<'a> RenderingContext<'a> { let (vert_buffer, index_buffer) = { use hal::buffer::Usage; - let vert = StagedBuffer::new(&mut device, &adapter, Usage::VERTEX | Usage::TRANSFER_DST)?; - let index = StagedBuffer::new(&mut device, &adapter, Usage::TRANSFER_SRC)?; + let vert = StagedBuffer::new(&mut device, &adapter, Usage::VERTEX, 4)?; + let index = StagedBuffer::new(&mut device, &adapter, Usage::INDEX, 2)?; (vert, index) }; @@ -404,24 +404,31 @@ impl<'a> RenderingContext<'a> { // Vertex buffers let vertex_buffers: Vec<VertexBufferDesc> = vec![VertexBufferDesc { binding: 0, - stride: (size_of::<f32>() * 5) as u32, + stride: (size_of::<f32>() * 7) as u32, rate: VertexInputRate::Vertex, }]; - let attributes: Vec<AttributeDesc> = vec![AttributeDesc { + let attributes: Vec<AttributeDesc> = vec![AttributeDesc { // XY Attribute location: 0, binding: 0, element: Element { format: Format::Rg32Sfloat, offset: 0, }, - }, AttributeDesc { + }, AttributeDesc { // RGB Attribute location: 1, binding: 0, element: Element { format: Format::Rgb32Sfloat, offset: (size_of::<f32>() * 2) as ElemOffset, } + }, AttributeDesc { // UV Attribute + location: 2, + binding: 0, + element: Element { + format: Format::Rg32Sfloat, + offset: (size_of::<f32>() * 5) as ElemOffset, + } }]; // Rasterizer @@ -663,8 +670,7 @@ impl<'a> RenderingContext<'a> { range: SubRange::WHOLE, index_type: hal::IndexType::U16 }); - - buffer.draw_indexed(0..6, 0, 0..1); + buffer.draw_indexed(0..((self.index_buffer.highest_used as u32 + 1) * 3), 0, 0..1); buffer.end_render_pass(); } buffer.finish(); |