aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/makamys/neodymium/renderer/ChunkMesh.java14
-rw-r--r--src/main/java/makamys/neodymium/renderer/MeshQuad.java23
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];