From be5ee8e2059125ff6b3b1d18560aae12de4f78b1 Mon Sep 17 00:00:00 2001 From: Imbris Date: Thu, 3 Jun 2021 00:45:04 -0400 Subject: [PATCH] Properly calculate the necessary length of the index buffers for checks that ensure they are large enough --- voxygen/src/render/renderer.rs | 22 +++++++++++++--------- voxygen/src/render/renderer/drawer.rs | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index bc77931326..ba36062fd1 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -943,36 +943,40 @@ impl Renderer { pub(super) fn ensure_sufficient_index_length( &mut self, // 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 { Some(wgpu::IndexFormat::Uint16) => { // 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 - if length > u16::MAX as usize { + if vert_length > u16::MAX as usize { panic!( "Vertex type: {} needs to use a larger index type, length: {}", core::any::type_name::(), - 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) => { // 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 - if length > u32::MAX as usize { + if vert_length > u32::MAX as usize { panic!( "More than u32::MAX({}) verts({}) for type({}) using an index buffer!", u32::MAX, - length, + vert_length, core::any::type_name::() ); } - 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 => {}, diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index ca8bb7e824..7e25c349d2 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -556,6 +556,7 @@ impl<'pass> FirstPassDrawer<'pass> { let mut render_pass = self.render_pass.scope("figures", self.borrow.device); render_pass.set_pipeline(&self.pipelines.figure.pipeline); + // Note: figures use the same vertex type as the terrain set_quad_index_buffer::(&mut render_pass, &self.borrow); FigureDrawer { render_pass } @@ -590,7 +591,7 @@ impl<'pass> FirstPassDrawer<'pass> { let mut render_pass = self.render_pass.scope("sprites", self.borrow.device); render_pass.set_pipeline(&self.pipelines.sprite.pipeline); - set_quad_index_buffer::(&mut render_pass, &self.borrow); + set_quad_index_buffer::(&mut render_pass, &self.borrow); render_pass.set_bind_group(0, &globals.bind_group, &[]); render_pass.set_bind_group(3, &col_lights.bind_group, &[]);