mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Properly calculate the necessary length of the index buffers for checks that ensure they are large enough
This commit is contained in:
parent
923988da5f
commit
be5ee8e205
@ -943,36 +943,40 @@ impl Renderer {
|
|||||||
pub(super) fn ensure_sufficient_index_length<V: Vertex>(
|
pub(super) fn ensure_sufficient_index_length<V: Vertex>(
|
||||||
&mut self,
|
&mut self,
|
||||||
// Length of the vert buffer with 4 verts per quad
|
// Length of the vert buffer with 4 verts per quad
|
||||||
length: usize,
|
vert_length: usize,
|
||||||
) {
|
) {
|
||||||
|
let quad_index_length = vert_length / 4 * 6;
|
||||||
|
|
||||||
match V::QUADS_INDEX {
|
match V::QUADS_INDEX {
|
||||||
Some(wgpu::IndexFormat::Uint16) => {
|
Some(wgpu::IndexFormat::Uint16) => {
|
||||||
// Make sure the global quad index buffer is large enough
|
// Make sure the global quad index buffer is large enough
|
||||||
if self.quad_index_buffer_u16.len() < length {
|
if self.quad_index_buffer_u16.len() < quad_index_length {
|
||||||
// Make sure we aren't over the max
|
// Make sure we aren't over the max
|
||||||
if length > u16::MAX as usize {
|
if vert_length > u16::MAX as usize {
|
||||||
panic!(
|
panic!(
|
||||||
"Vertex type: {} needs to use a larger index type, length: {}",
|
"Vertex type: {} needs to use a larger index type, length: {}",
|
||||||
core::any::type_name::<V>(),
|
core::any::type_name::<V>(),
|
||||||
length
|
vert_length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
self.quad_index_buffer_u16 = create_quad_index_buffer_u16(&self.device, length);
|
self.quad_index_buffer_u16 =
|
||||||
|
create_quad_index_buffer_u16(&self.device, vert_length);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(wgpu::IndexFormat::Uint32) => {
|
Some(wgpu::IndexFormat::Uint32) => {
|
||||||
// Make sure the global quad index buffer is large enough
|
// Make sure the global quad index buffer is large enough
|
||||||
if self.quad_index_buffer_u32.len() < length {
|
if self.quad_index_buffer_u32.len() < quad_index_length {
|
||||||
// Make sure we aren't over the max
|
// Make sure we aren't over the max
|
||||||
if length > u32::MAX as usize {
|
if vert_length > u32::MAX as usize {
|
||||||
panic!(
|
panic!(
|
||||||
"More than u32::MAX({}) verts({}) for type({}) using an index buffer!",
|
"More than u32::MAX({}) verts({}) for type({}) using an index buffer!",
|
||||||
u32::MAX,
|
u32::MAX,
|
||||||
length,
|
vert_length,
|
||||||
core::any::type_name::<V>()
|
core::any::type_name::<V>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
self.quad_index_buffer_u32 = create_quad_index_buffer_u32(&self.device, length);
|
self.quad_index_buffer_u32 =
|
||||||
|
create_quad_index_buffer_u32(&self.device, vert_length);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {},
|
None => {},
|
||||||
|
@ -556,6 +556,7 @@ impl<'pass> FirstPassDrawer<'pass> {
|
|||||||
let mut render_pass = self.render_pass.scope("figures", self.borrow.device);
|
let mut render_pass = self.render_pass.scope("figures", self.borrow.device);
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.pipelines.figure.pipeline);
|
render_pass.set_pipeline(&self.pipelines.figure.pipeline);
|
||||||
|
// Note: figures use the same vertex type as the terrain
|
||||||
set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow);
|
set_quad_index_buffer::<terrain::Vertex>(&mut render_pass, &self.borrow);
|
||||||
|
|
||||||
FigureDrawer { render_pass }
|
FigureDrawer { render_pass }
|
||||||
@ -590,7 +591,7 @@ impl<'pass> FirstPassDrawer<'pass> {
|
|||||||
let mut render_pass = self.render_pass.scope("sprites", self.borrow.device);
|
let mut render_pass = self.render_pass.scope("sprites", self.borrow.device);
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.pipelines.sprite.pipeline);
|
render_pass.set_pipeline(&self.pipelines.sprite.pipeline);
|
||||||
set_quad_index_buffer::<particle::Vertex>(&mut render_pass, &self.borrow);
|
set_quad_index_buffer::<sprite::Vertex>(&mut render_pass, &self.borrow);
|
||||||
render_pass.set_bind_group(0, &globals.bind_group, &[]);
|
render_pass.set_bind_group(0, &globals.bind_group, &[]);
|
||||||
render_pass.set_bind_group(3, &col_lights.bind_group, &[]);
|
render_pass.set_bind_group(3, &col_lights.bind_group, &[]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user