mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Compute vertex_count
for indexed meshes on GpuMesh
(#8460)
# Objective Compute the `vertex_count` for indexed meshes as well as non-indexed meshes. I will need this in a future PR based on #8427 that adds a gizmo component that draws the normals of a mesh when attached to an entity ([branch](https://github.com/devil-ira/bevy/compare/instanced-line-rendering...devil-ira:bevy:instanced-line-rendering-normals)). <details><summary>Example image</summary> <p> ![image](https://user-images.githubusercontent.com/29694403/233789526-cb5feb47-0aa7-4e69-90a2-e31ec24aadff.png) </p> </details> ## Solution Move `vertex_count` field from `GpuBufferInfo::NonIndexed` to `GpuMesh` ## Migration Guide `vertex_count` is now stored directly on `GpuMesh` instead of `GpuBufferInfo::NonIndexed`.
This commit is contained in:
parent
149c86b2ae
commit
6b774c0fda
4 changed files with 15 additions and 16 deletions
|
@ -1177,8 +1177,8 @@ impl<P: PhaseItem> RenderCommand<P> for DrawMesh {
|
|||
pass.set_index_buffer(buffer.slice(..), 0, *index_format);
|
||||
pass.draw_indexed(0..*count, 0, 0..1);
|
||||
}
|
||||
GpuBufferInfo::NonIndexed { vertex_count } => {
|
||||
pass.draw(0..*vertex_count, 0..1);
|
||||
GpuBufferInfo::NonIndexed => {
|
||||
pass.draw(0..gpu_mesh.vertex_count, 0..1);
|
||||
}
|
||||
}
|
||||
RenderCommandResult::Success
|
||||
|
|
|
@ -820,6 +820,7 @@ impl From<&Indices> for IndexFormat {
|
|||
pub struct GpuMesh {
|
||||
/// Contains all attribute data for each vertex.
|
||||
pub vertex_buffer: Buffer,
|
||||
pub vertex_count: u32,
|
||||
pub buffer_info: GpuBufferInfo,
|
||||
pub primitive_topology: PrimitiveTopology,
|
||||
pub layout: MeshVertexBufferLayout,
|
||||
|
@ -834,9 +835,7 @@ pub enum GpuBufferInfo {
|
|||
count: u32,
|
||||
index_format: IndexFormat,
|
||||
},
|
||||
NonIndexed {
|
||||
vertex_count: u32,
|
||||
},
|
||||
NonIndexed,
|
||||
}
|
||||
|
||||
impl RenderAsset for Mesh {
|
||||
|
@ -861,11 +860,8 @@ impl RenderAsset for Mesh {
|
|||
contents: &vertex_buffer_data,
|
||||
});
|
||||
|
||||
let buffer_info = mesh.get_index_buffer_bytes().map_or(
|
||||
GpuBufferInfo::NonIndexed {
|
||||
vertex_count: mesh.count_vertices() as u32,
|
||||
},
|
||||
|data| GpuBufferInfo::Indexed {
|
||||
let buffer_info = if let Some(data) = mesh.get_index_buffer_bytes() {
|
||||
GpuBufferInfo::Indexed {
|
||||
buffer: render_device.create_buffer_with_data(&BufferInitDescriptor {
|
||||
usage: BufferUsages::INDEX,
|
||||
contents: data,
|
||||
|
@ -873,13 +869,16 @@ impl RenderAsset for Mesh {
|
|||
}),
|
||||
count: mesh.indices().unwrap().len() as u32,
|
||||
index_format: mesh.indices().unwrap().into(),
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
GpuBufferInfo::NonIndexed
|
||||
};
|
||||
|
||||
let mesh_vertex_buffer_layout = mesh.get_mesh_vertex_buffer_layout();
|
||||
|
||||
Ok(GpuMesh {
|
||||
vertex_buffer,
|
||||
vertex_count: mesh.count_vertices() as u32,
|
||||
buffer_info,
|
||||
primitive_topology: mesh.primitive_topology(),
|
||||
layout: mesh_vertex_buffer_layout,
|
||||
|
|
|
@ -599,8 +599,8 @@ impl<P: PhaseItem> RenderCommand<P> for DrawMesh2d {
|
|||
pass.set_index_buffer(buffer.slice(..), 0, *index_format);
|
||||
pass.draw_indexed(0..*count, 0, 0..1);
|
||||
}
|
||||
GpuBufferInfo::NonIndexed { vertex_count } => {
|
||||
pass.draw(0..*vertex_count, 0..1);
|
||||
GpuBufferInfo::NonIndexed => {
|
||||
pass.draw(0..gpu_mesh.vertex_count, 0..1);
|
||||
}
|
||||
}
|
||||
RenderCommandResult::Success
|
||||
|
|
|
@ -253,8 +253,8 @@ impl<P: PhaseItem> RenderCommand<P> for DrawMeshInstanced {
|
|||
pass.set_index_buffer(buffer.slice(..), 0, *index_format);
|
||||
pass.draw_indexed(0..*count, 0, 0..instance_buffer.length as u32);
|
||||
}
|
||||
GpuBufferInfo::NonIndexed { vertex_count } => {
|
||||
pass.draw(0..*vertex_count, 0..instance_buffer.length as u32);
|
||||
GpuBufferInfo::NonIndexed => {
|
||||
pass.draw(0..gpu_mesh.vertex_count, 0..instance_buffer.length as u32);
|
||||
}
|
||||
}
|
||||
RenderCommandResult::Success
|
||||
|
|
Loading…
Reference in a new issue