@@ -591,18 +591,23 @@ impl From<&Indices> for IndexFormat {
591
591
pub struct GpuMesh {
592
592
/// Contains all attribute data for each vertex.
593
593
pub vertex_buffer : Buffer ,
594
- pub index_info : Option < GpuIndexInfo > ,
594
+ pub buffer_info : GpuBufferInfo ,
595
595
pub has_tangents : bool ,
596
596
pub primitive_topology : PrimitiveTopology ,
597
597
}
598
598
599
- /// The index info of a [`GpuMesh`].
599
+ /// The index/vertex buffer info of a [`GpuMesh`].
600
600
#[ derive( Debug , Clone ) ]
601
- pub struct GpuIndexInfo {
602
- /// Contains all index data of a mesh.
603
- pub buffer : Buffer ,
604
- pub count : u32 ,
605
- pub index_format : IndexFormat ,
601
+ pub enum GpuBufferInfo {
602
+ Indexed {
603
+ /// Contains all index data of a mesh.
604
+ buffer : Buffer ,
605
+ count : u32 ,
606
+ index_format : IndexFormat ,
607
+ } ,
608
+ NonIndexed {
609
+ vertex_count : u32 ,
610
+ } ,
606
611
}
607
612
608
613
impl RenderAsset for Mesh {
@@ -627,19 +632,24 @@ impl RenderAsset for Mesh {
627
632
contents : & vertex_buffer_data,
628
633
} ) ;
629
634
630
- let index_info = mesh. get_index_buffer_bytes ( ) . map ( |data| GpuIndexInfo {
631
- buffer : render_device. create_buffer_with_data ( & BufferInitDescriptor {
632
- usage : BufferUsages :: INDEX ,
633
- contents : data,
634
- label : None ,
635
- } ) ,
636
- count : mesh. indices ( ) . unwrap ( ) . len ( ) as u32 ,
637
- index_format : mesh. indices ( ) . unwrap ( ) . into ( ) ,
638
- } ) ;
635
+ let buffer_info = mesh. get_index_buffer_bytes ( ) . map_or (
636
+ GpuBufferInfo :: NonIndexed {
637
+ vertex_count : mesh. count_vertices ( ) as u32 ,
638
+ } ,
639
+ |data| GpuBufferInfo :: Indexed {
640
+ buffer : render_device. create_buffer_with_data ( & BufferInitDescriptor {
641
+ usage : BufferUsages :: INDEX ,
642
+ contents : data,
643
+ label : None ,
644
+ } ) ,
645
+ count : mesh. indices ( ) . unwrap ( ) . len ( ) as u32 ,
646
+ index_format : mesh. indices ( ) . unwrap ( ) . into ( ) ,
647
+ } ,
648
+ ) ;
639
649
640
650
Ok ( GpuMesh {
641
651
vertex_buffer,
642
- index_info ,
652
+ buffer_info ,
643
653
has_tangents : mesh. attributes . contains_key ( Mesh :: ATTRIBUTE_TANGENT ) ,
644
654
primitive_topology : mesh. primitive_topology ( ) ,
645
655
} )
0 commit comments