From a9adebcab33986adfe998ecef09b0a4bab036bfb Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 19 Apr 2020 20:46:04 +0100 Subject: [PATCH] Improved rendering performance with smarter meshing order --- voxygen/src/mesh/terrain.rs | 25 +++++++++++++++++++++---- voxygen/src/render/mesh.rs | 24 +++++++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 82a301040d..43ee5261d4 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -219,9 +219,6 @@ impl + ReadVol + Debug> Meshable (Mesh, Mesh) { - let mut opaque_mesh = Mesh::new(); - let mut fluid_mesh = Mesh::new(); - let mut light = calc_light(range, self); let mut lowest_opaque = range.size().d; @@ -300,6 +297,12 @@ impl + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable| { + m.verts().chunks_exact(3).rev().for_each(|vs| { + opaque_mesh.push(vs[0]); + opaque_mesh.push(vs[1]); + opaque_mesh.push(vs[2]); + }); + opaque_mesh + }); + (opaque_mesh, fluid_mesh) } } diff --git a/voxygen/src/render/mesh.rs b/voxygen/src/render/mesh.rs index 1d3a45431b..9a0b6a3251 100644 --- a/voxygen/src/render/mesh.rs +++ b/voxygen/src/render/mesh.rs @@ -1,11 +1,16 @@ use super::Pipeline; /// A `Vec`-based mesh structure used to store mesh data on the CPU. -#[derive(Clone)] pub struct Mesh { verts: Vec, } +impl Clone for Mesh

where P::Vertex: Clone { + fn clone(&self) -> Self { + Self { verts: self.verts.clone() } + } +} + impl Mesh

{ /// Create a new `Mesh`. pub fn new() -> Self { Self { verts: vec![] } } @@ -55,6 +60,23 @@ impl Mesh

{ self.verts.push(f(vert.clone())); } } + + pub fn verts(&self) -> &[P::Vertex] { + &self.verts + } + + pub fn iter(&self) -> std::slice::Iter { + self.verts.iter() + } +} + +impl IntoIterator for Mesh

{ + type Item = P::Vertex; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.verts.into_iter() + } } /// Represents a triangle stored on the CPU.