From e5f18be985bac742cc9bbcdf0427187d666a304a Mon Sep 17 00:00:00 2001 From: makamys Date: Fri, 24 Jun 2022 10:17:50 +0200 Subject: Clean up in ChunkMesh --- src/main/java/makamys/neodymium/renderer/ChunkMesh.java | 14 ++++++-------- src/main/java/makamys/neodymium/renderer/Mesh.java | 7 +++---- src/main/java/makamys/neodymium/renderer/NeoRenderer.java | 15 +++++---------- 3 files changed, 14 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java index 47c082e..26429a7 100644 --- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java @@ -244,15 +244,12 @@ public class ChunkMesh extends Mesh { } @Override - public void writeToIndexBuffer(IntBuffer piFirst, IntBuffer piCount, int[] renderedMeshesReturn, - int[] renderedQuadsReturn, int cameraXDiv, int cameraYDiv, int cameraZDiv) { + public int writeToIndexBuffer(IntBuffer piFirst, IntBuffer piCount, int cameraXDiv, int cameraYDiv, int cameraZDiv) { if(!Config.cullFaces) { - super.writeToIndexBuffer(piFirst, piCount, renderedMeshesReturn, renderedQuadsReturn, cameraXDiv, cameraYDiv, cameraZDiv); - return; + return super.writeToIndexBuffer(piFirst, piCount, cameraXDiv, cameraYDiv, cameraZDiv); } - renderedMeshesReturn[0] = 0; - renderedQuadsReturn[0] = 0; + int renderedMeshes = 0; int startIndex = -1; for(int i = 0; i < NORMAL_ORDER.length + 1; i++) { @@ -268,12 +265,13 @@ public class ChunkMesh extends Mesh { piFirst.put(iFirst + (startIndex*4)); piCount.put((endIndex - startIndex)*4); - renderedMeshesReturn[0]++; - renderedQuadsReturn[0] += endIndex - startIndex; // TODO remove this, it's redundant + renderedMeshes++; startIndex = -1; } } + + return renderedMeshes; } private boolean isNormalVisible(QuadNormal normal, int interpXDiv, int interpYDiv, int interpZDiv) { diff --git a/src/main/java/makamys/neodymium/renderer/Mesh.java b/src/main/java/makamys/neodymium/renderer/Mesh.java index 6db523d..f73bb51 100644 --- a/src/main/java/makamys/neodymium/renderer/Mesh.java +++ b/src/main/java/makamys/neodymium/renderer/Mesh.java @@ -42,11 +42,10 @@ public abstract class Mesh { UNSENT, SENT, PENDING_DELETE } - public void writeToIndexBuffer(IntBuffer piFirst, IntBuffer piCount, int[] renderedMeshesReturn, - int[] renderedQuadsReturn, int cameraXDiv, int cameraYDiv, int cameraZDiv) { - renderedMeshesReturn[0] = 1; - renderedQuadsReturn[0] = quadCount; + public int writeToIndexBuffer(IntBuffer piFirst, IntBuffer piCount, int cameraXDiv, int cameraYDiv, int cameraZDiv) { piFirst.put(iFirst); piCount.put(iCount); + + return 1; } } diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index 73a3be2..75ce575 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -18,10 +18,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Queue; import java.util.Set; -import java.util.concurrent.ConcurrentLinkedQueue; - import org.lwjgl.BufferUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -44,7 +41,6 @@ import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import net.minecraftforge.event.world.ChunkEvent; /** The main renderer class. */ public class NeoRenderer { @@ -170,18 +166,17 @@ public class NeoRenderer { } } - private static int[] renderedMeshesReturn = new int[1]; - private static int[] renderedQuadsReturn = new int[1]; - private void initIndexBuffers() { for(int i = 0; i < 2; i++) { piFirst[i].limit(MAX_MESHES); piCount[i].limit(MAX_MESHES); for(Mesh mesh : sentMeshes[i]) { if(mesh.visible && (Config.maxMeshesPerFrame == -1 || renderedMeshes < Config.maxMeshesPerFrame)) { - mesh.writeToIndexBuffer(piFirst[i], piCount[i], renderedMeshesReturn, renderedQuadsReturn, interpXDiv, interpYDiv, interpZDiv); - renderedMeshes += renderedMeshesReturn[0]; - renderedQuads += renderedQuadsReturn[0]; + int meshes = mesh.writeToIndexBuffer(piFirst[i], piCount[i], interpXDiv, interpYDiv, interpZDiv); + renderedMeshes += meshes; + for(int j = piCount[i].position() - meshes; j < piCount[i].position(); j++) { + renderedQuads += piCount[i].get(j) / 4; + } } } piFirst[i].flip(); -- cgit