aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/makamys/neodymium/renderer')
-rw-r--r--src/main/java/makamys/neodymium/renderer/ChunkMesh.java6
-rw-r--r--src/main/java/makamys/neodymium/renderer/CullableMeshCollection.java41
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoChunk.java17
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java24
-rw-r--r--src/main/java/makamys/neodymium/renderer/QuadNormal.java5
5 files changed, 80 insertions, 13 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java
index 35ed49c..12dd538 100644
--- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java
+++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java
@@ -69,7 +69,7 @@ public class ChunkMesh extends Mesh {
private static int totalOriginalQuadCount = 0;
private static int totalSimplifiedQuadCount = 0;
- public static ChunkMesh fromTessellator(int pass, WorldRenderer wr, Tessellator t) {
+ public static CullableMeshCollection fromTessellator(int pass, WorldRenderer wr, Tessellator t) {
if(t.vertexCount % 4 != 0) {
System.out.println("Error: Vertex count is not a multiple of 4");
return null;
@@ -128,7 +128,7 @@ public class ChunkMesh extends Mesh {
//System.out.println("simplified quads " + totalOriginalQuadCount + " -> " + totalSimplifiedQuadCount + " (ratio: " + ((float)totalSimplifiedQuadCount / (float)totalOriginalQuadCount) + ") totalMergeCountByPlane: " + Arrays.toString(totalMergeCountByPlane));
if(quadCount > 0) {
- return new ChunkMesh(
+ return new CullableMeshCollection(
(int)(xOffset / 16), (int)(yOffset / 16), (int)(zOffset / 16),
new ChunkMesh.Flags(t.hasTexture, t.hasBrightness, t.hasColor, t.hasNormals),
quadCount, quads, pass);
@@ -289,7 +289,7 @@ public class ChunkMesh extends Mesh {
//Tessellator.endSave();
}
- static List<ChunkMesh> getChunkMesh(int theX, int theY, int theZ) {
+ static List<CullableMeshCollection> getChunkMesh(int theX, int theY, int theZ) {
WorldRenderer wr = new WorldRenderer(Minecraft.getMinecraft().theWorld, new ArrayList<TileEntity>(), theX * 16, theY * 16, theZ * 16, 100000);
wr.isWaitingOnOcclusionQuery = false;
diff --git a/src/main/java/makamys/neodymium/renderer/CullableMeshCollection.java b/src/main/java/makamys/neodymium/renderer/CullableMeshCollection.java
new file mode 100644
index 0000000..034c3bb
--- /dev/null
+++ b/src/main/java/makamys/neodymium/renderer/CullableMeshCollection.java
@@ -0,0 +1,41 @@
+package makamys.neodymium.renderer;
+
+import java.util.Arrays;
+import java.util.List;
+
+import makamys.neodymium.renderer.ChunkMesh.Flags;
+
+public class CullableMeshCollection {
+
+ private ChunkMesh[] meshes = new ChunkMesh[QuadNormal.values().length];
+
+ public CullableMeshCollection(int x, int y, int z, Flags flags, int quadCount, List<MeshQuad> quads, int pass) {
+ putMeshWithNormal(QuadNormal.NONE, new ChunkMesh(x, y, z, flags, quadCount, quads, pass));
+ }
+
+ public ChunkMesh getMeshWithNormal(QuadNormal normal) {
+ return meshes[normal.ordinal()];
+ }
+
+ public void putMeshWithNormal(QuadNormal normal, ChunkMesh mesh) {
+ meshes[normal.ordinal()] = mesh;
+ }
+
+ public List<ChunkMesh> getMeshes() {
+ return Arrays.asList(meshes);
+ }
+
+ public void destroy() {
+ for(ChunkMesh mesh : meshes) {
+ if(mesh != null) mesh.destroy();
+ }
+ }
+
+ public boolean isVisible() {
+ for(ChunkMesh mesh : meshes) {
+ if(mesh != null && mesh.visible) return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/makamys/neodymium/renderer/NeoChunk.java b/src/main/java/makamys/neodymium/renderer/NeoChunk.java
index 79deedf..4dd692e 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoChunk.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoChunk.java
@@ -18,7 +18,7 @@ public class NeoChunk {
boolean discardedMesh;
SimpleChunkMesh[] simpleMeshes = new SimpleChunkMesh[2];
- ChunkMesh[] chunkMeshes = new ChunkMesh[32];
+ CullableMeshCollection[] chunkMeshes = new CullableMeshCollection[32];
public boolean[] isSectionVisible = new boolean[16];
@@ -56,12 +56,17 @@ public class NeoChunk {
return Math.pow(entity.posX - x * 16, 2) + Math.pow(entity.posZ - z * 16, 2);
}
- public void putChunkMeshes(int cy, List<ChunkMesh> newChunkMeshes) {
+ public void putChunkMeshes(int cy, List<CullableMeshCollection> newChunkMeshes) {
for(int i = 0; i < 2; i++) {
- ChunkMesh newChunkMesh = newChunkMeshes.size() > i ? newChunkMeshes.get(i) : null;
+ CullableMeshCollection newChunkMesh = newChunkMeshes.size() > i ? newChunkMeshes.get(i) : null;
if(chunkMeshes[cy * 2 + i] != null) {
if(newChunkMesh != null) {
- newChunkMesh.pass = i;
+ // ??? why is this needed?
+ for(ChunkMesh mesh : newChunkMesh.getMeshes()) {
+ if(mesh != null) {
+ mesh.pass = i;
+ }
+ }
}
renderer.removeMesh(chunkMeshes[cy * 2 + i]);
@@ -92,7 +97,7 @@ public class NeoChunk {
}
public boolean hasChunkMeshes() {
- for(ChunkMesh cm : chunkMeshes) {
+ for(CullableMeshCollection cm : chunkMeshes) {
if(cm != null) {
return true;
}
@@ -156,7 +161,7 @@ public class NeoChunk {
scm.destroy();
}
}
- for(ChunkMesh cm: chunkMeshes) {
+ for(CullableMeshCollection cm: chunkMeshes) {
if(cm != null) {
cm.destroy();
}
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index ac30199..b4e0607 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -592,14 +592,14 @@ public class NeoRenderer {
}
for(int y = 0; y < 16; y++) {
for(int pass = 0; pass < 2; pass++) {
- ChunkMesh cm = lodChunk.chunkMeshes[y * 2 + pass];
+ CullableMeshCollection cm = lodChunk.chunkMeshes[y * 2 + pass];
if(cm != null) {
if(lodChunk.isSectionVisible[y] && newLOD == 2) {
- if(!cm.visible) {
+ if(!cm.isVisible()) {
setMeshVisible(cm, true);
}
} else {
- if(cm.visible) {
+ if(cm.isVisible()) {
setMeshVisible(cm, false);
}
}
@@ -608,6 +608,14 @@ public class NeoRenderer {
}
}
+ protected void setMeshVisible(CullableMeshCollection cm, boolean visible) {
+ if(cm == null) return;
+
+ for(ChunkMesh mesh : cm.getMeshes()) {
+ if(mesh != null) setMeshVisible(mesh, visible);
+ }
+ }
+
protected void setMeshVisible(Mesh mesh, boolean visible) {
setMeshVisible(mesh, visible, false);
}
@@ -631,7 +639,15 @@ public class NeoRenderer {
mem.deleteMeshFromGPU(mesh);
sentMeshes[mesh.pass].remove(mesh);
setMeshVisible(mesh, false);
- }
+ }
+
+ public void removeMesh(CullableMeshCollection cm) {
+ if(cm == null) return;
+
+ for(Mesh mesh : cm.getMeshes()) {
+ if(mesh != null) removeMesh(mesh);
+ }
+ }
public Chunk getChunkFromChunkCoords(int x, int z) {
for(Chunk chunk : myChunks) {
diff --git a/src/main/java/makamys/neodymium/renderer/QuadNormal.java b/src/main/java/makamys/neodymium/renderer/QuadNormal.java
new file mode 100644
index 0000000..23e2eeb
--- /dev/null
+++ b/src/main/java/makamys/neodymium/renderer/QuadNormal.java
@@ -0,0 +1,5 @@
+package makamys.neodymium.renderer;
+
+public enum QuadNormal {
+ NONE, POSITIVE_X, NEGATIVE_X, POSITIVE_Y, NEGATIVE_Y, POSITIVE_Z, NEGATIVE_Z
+}