1- use gfx_hal:: {
2- memory:: {
3- Segment ,
4- SparseFlags ,
5- } ,
6- Backend ,
1+ use gfx_hal:: memory:: {
2+ Segment ,
3+ SparseFlags ,
74} ;
85
96use super :: gpu:: Gpu ;
@@ -12,12 +9,21 @@ use super::gpu::Gpu;
129pub type Usage = gfx_hal:: buffer:: Usage ;
1310pub type Properties = gfx_hal:: memory:: Properties ;
1411
12+ /// A buffer is a block of memory that can be used to store data that is accessed
13+ #[ derive( Debug , Clone , Copy ) ]
14+ pub enum BufferType {
15+ Vertex ,
16+ Index ,
17+ }
18+
1519/// A buffer is a block of memory that can be used to store data that can be
1620/// accessed by the GPU.
1721#[ derive( Debug , Clone , Copy ) ]
1822pub struct Buffer < RenderBackend : super :: internal:: Backend > {
1923 buffer : RenderBackend :: Buffer ,
2024 memory : RenderBackend :: Memory ,
25+ stride : usize ,
26+ buffer_type : BufferType ,
2127}
2228
2329impl < RenderBackend : super :: internal:: Backend > Buffer < RenderBackend > { }
@@ -26,14 +32,16 @@ pub struct BufferBuilder {
2632 buffer_length : usize ,
2733 usage : Usage ,
2834 properties : Properties ,
35+ buffer_type : BufferType ,
2936}
3037
3138impl BufferBuilder {
3239 pub fn new ( ) -> Self {
3340 return Self {
3441 buffer_length : 0 ,
35- usage : gfx_hal:: buffer:: Usage :: empty ( ) ,
36- properties : gfx_hal:: memory:: Properties :: empty ( ) ,
42+ usage : Usage :: empty ( ) ,
43+ properties : Properties :: empty ( ) ,
44+ buffer_type : BufferType :: Vertex ,
3745 } ;
3846 }
3947
@@ -48,6 +56,12 @@ impl BufferBuilder {
4856 }
4957
5058 pub fn with_properties ( & mut self , properties : Properties ) -> & mut Self {
59+ self . properties = properties;
60+ return self ;
61+ }
62+
63+ pub fn with_buffer_type ( & mut self , buffer_type : BufferType ) -> & mut Self {
64+ self . buffer_type = buffer_type;
5165 return self ;
5266 }
5367
@@ -160,6 +174,8 @@ impl BufferBuilder {
160174 return Ok ( Buffer {
161175 buffer,
162176 memory : buffer_memory,
177+ stride : std:: mem:: size_of :: < Data > ( ) ,
178+ buffer_type : self . buffer_type ,
163179 } ) ;
164180 }
165181}
0 commit comments