aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-20 23:54:34 +0200
committermakamys <makamys@outlook.com>2022-06-20 23:54:34 +0200
commit740382fb780b1f73bc9f7a733dc4884db94d0033 (patch)
tree037c280becc37f4db36e1096e879f8d0e658b052 /src/main/java
parent28d9972004afe27f0877c222f1ef66fa281ba423 (diff)
downloadNeodymium-740382fb780b1f73bc9f7a733dc4884db94d0033.tar.gz
Neodymium-740382fb780b1f73bc9f7a733dc4884db94d0033.tar.bz2
Neodymium-740382fb780b1f73bc9f7a733dc4884db94d0033.zip
Rewrite to use CullableMeshCollections in place of ChunkMeshes
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/makamys/neodymium/ducks/IWorldRenderer.java4
-rw-r--r--src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java5
-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
7 files changed, 85 insertions, 17 deletions
diff --git a/src/main/java/makamys/neodymium/ducks/IWorldRenderer.java b/src/main/java/makamys/neodymium/ducks/IWorldRenderer.java
index 3c3d7a8..0652984 100644
--- a/src/main/java/makamys/neodymium/ducks/IWorldRenderer.java
+++ b/src/main/java/makamys/neodymium/ducks/IWorldRenderer.java
@@ -2,9 +2,9 @@ package makamys.neodymium.ducks;
import java.util.List;
-import makamys.neodymium.renderer.ChunkMesh;
+import makamys.neodymium.renderer.CullableMeshCollection;
public interface IWorldRenderer {
- public List<ChunkMesh> getChunkMeshes();
+ public List<CullableMeshCollection> getChunkMeshes();
public boolean isDrawn();
}
diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java
index 86702fe..fb73362 100644
--- a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java
+++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java
@@ -15,6 +15,7 @@ import makamys.neodymium.Config;
import makamys.neodymium.Neodymium;
import makamys.neodymium.ducks.IWorldRenderer;
import makamys.neodymium.renderer.ChunkMesh;
+import makamys.neodymium.renderer.CullableMeshCollection;
import makamys.neodymium.renderer.NeoRenderer;
import makamys.neodymium.renderer.lod.FarChunkCache;
import makamys.neodymium.renderer.lod.FarWorldRenderer;
@@ -49,7 +50,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
boolean savedDrawnStatus;
- public List<ChunkMesh> chunkMeshes;
+ public List<CullableMeshCollection> chunkMeshes;
@Redirect(method = "setPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderAABB(Lnet/minecraft/util/AxisAlignedBB;)V"))
private void redirectRenderAABB(AxisAlignedBB p1) {
@@ -149,7 +150,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
}
@Override
- public List<ChunkMesh> getChunkMeshes() {
+ public List<CullableMeshCollection> getChunkMeshes() {
return chunkMeshes;
}
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
+}