diff options
author | makamys <makamys@outlook.com> | 2022-07-11 23:30:12 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-07-11 23:38:56 +0200 |
commit | e3c0fc4adf83d97b86c0d9b17296ed841f588210 (patch) | |
tree | 2d4b9adb2941d3f143d6cae846212a8da894e0d2 /src | |
parent | 8eb350325f025ac0b3cb9e33505ee18c2b23a282 (diff) | |
download | Neodymium-e3c0fc4adf83d97b86c0d9b17296ed841f588210.tar.gz Neodymium-e3c0fc4adf83d97b86c0d9b17296ed841f588210.tar.bz2 Neodymium-e3c0fc4adf83d97b86c0d9b17296ed841f588210.zip |
Turn triangles into quads
Normals are ignored for now.
End of fix for #5
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/ChunkMesh.java | 14 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/MeshQuad.java | 23 |
2 files changed, 25 insertions, 12 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java index e284da3..f28b390 100644 --- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java @@ -82,15 +82,11 @@ public class ChunkMesh extends Mesh { return; } boolean errors = false; - if(t.vertexCount % 4 != 0) { - LOGGER.error("Error in chunk " + tessellatorToString(t) + ": Vertex count is not a multiple of 4"); - errors = true; - } - if(t.drawMode != GL11.GL_QUADS) { + if(t.drawMode != GL11.GL_QUADS && t.drawMode != GL11.GL_TRIANGLES) { LOGGER.error("Error in chunk " + tessellatorToString(t) + ": Unsupported draw mode: " + t.drawMode); errors = true; } - if(!t.hasTexture || !t.hasBrightness || !t.hasColor || t.hasNormals) { + if(!t.hasTexture || !t.hasBrightness || !t.hasColor /*|| t.hasNormals*/) { LOGGER.error("Error in chunk " + tessellatorToString(t) + ": Unsupported tessellator flags"); errors = true; } @@ -99,8 +95,10 @@ public class ChunkMesh extends Mesh { return; } - for(int quadI = 0; quadI < t.vertexCount / 4; quadI++) { - quadBuf.next().setState(t.rawBuffer, quadI * 32, FLAGS, (float)-t.xOffset, (float)-t.yOffset, (float)-t.zOffset); + int verticesPerPrimitive = t.drawMode == GL11.GL_QUADS ? 4 : 3; + + for(int quadI = 0; quadI < t.vertexCount / verticesPerPrimitive; quadI++) { + quadBuf.next().setState(t.rawBuffer, quadI * (verticesPerPrimitive * 8), FLAGS, t.drawMode, (float)-t.xOffset, (float)-t.yOffset, (float)-t.zOffset); } } diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java index ce3aa6f..56827ee 100644 --- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java +++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Locale; +import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Vector3f; import makamys.neodymium.config.Config; @@ -66,8 +67,9 @@ public class MeshQuad { private static Vector3f vectorB = new Vector3f(); private static Vector3f vectorC = new Vector3f(); - private void read(int[] rawBuffer, int offset, float offsetX, float offsetY, float offsetZ) { - for(int vi = 0; vi < 4; vi++) { + private void read(int[] rawBuffer, int offset, float offsetX, float offsetY, float offsetZ, int drawMode) { + int vertices = drawMode == GL11.GL_TRIANGLES ? 3 : 4; + for(int vi = 0; vi < vertices; vi++) { int i = offset + vi * 8; xs[vi] = Float.intBitsToFloat(rawBuffer[i + 0]) + offsetX; @@ -82,12 +84,25 @@ public class MeshQuad { i += 8; } + + if(vertices == 3) { + // Quadrangulate! + xs[3] = xs[2]; + ys[3] = ys[2]; + zs[3] = zs[2]; + + us[3] = us[2]; + vs[3] = vs[2]; + + bs[3] = bs[2]; + cs[3] = cs[2]; + } } - public void setState(int[] rawBuffer, int offset, ChunkMesh.Flags flags, float offsetX, float offsetY, float offsetZ) { + public void setState(int[] rawBuffer, int offset, ChunkMesh.Flags flags, int drawMode, float offsetX, float offsetY, float offsetZ) { resetState(); - read(rawBuffer, offset, offsetX, offsetY, offsetZ); + read(rawBuffer, offset, offsetX, offsetY, offsetZ, drawMode); uDirectionIs01 = us[0] != us[1]; |