From 466e033c5c2941f8ef71a36cd86ae8d3a77a1d00 Mon Sep 17 00:00:00 2001 From: makamys Date: Thu, 23 Jun 2022 09:16:11 +0200 Subject: Don't store megaquad info if chunk simplification is disabled Reduces memory usage by a bit. Doesn't seem to affect FPS. --- .../java/makamys/neodymium/renderer/MeshQuad.java | 27 ++++++++++++---------- .../makamys/neodymium/renderer/NeoRenderer.java | 9 +++++--- src/main/resources/shaders/chunk.vert | 7 ++++++ 3 files changed, 28 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java index 1244d5d..e8a761c 100644 --- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java +++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java @@ -7,6 +7,7 @@ import java.util.Locale; import org.lwjgl.util.vector.Vector3f; +import makamys.neodymium.Config; import makamys.neodymium.util.BufferWriter; /* @@ -176,17 +177,19 @@ public class MeshQuad { out.writeInt(c); - if((quadCountByUVDirection(false) == 1 && quadCountByUVDirection(true) == 1)) { - // let the fragment shader know this is not a megaquad - out.writeByte((byte)255); - out.writeByte((byte)255); - out.writeByte((byte)255); - out.writeByte((byte)255); - } else { - out.writeByte(us[vi] == us[provokingI] ? 0 : (byte)quadCountByUVDirection(false)); - out.writeByte(vs[vi] == vs[provokingI] ? 0 : (byte)quadCountByUVDirection(true)); - out.writeByte(us[vi] == us[provokingI] ? (byte)0 : 1); - out.writeByte(vs[vi] == vs[provokingI] ? (byte)0 : 1); + if(Config.simplifyChunkMeshes) { + if((quadCountByUVDirection(false) == 1 && quadCountByUVDirection(true) == 1)) { + // let the fragment shader know this is not a megaquad + out.writeByte((byte)255); + out.writeByte((byte)255); + out.writeByte((byte)255); + out.writeByte((byte)255); + } else { + out.writeByte(us[vi] == us[provokingI] ? 0 : (byte)quadCountByUVDirection(false)); + out.writeByte(vs[vi] == vs[provokingI] ? 0 : (byte)quadCountByUVDirection(true)); + out.writeByte(us[vi] == us[provokingI] ? (byte)0 : 1); + out.writeByte(vs[vi] == vs[provokingI] ? (byte)0 : 1); + } } assert out.position() % getStride() == 0; @@ -209,7 +212,7 @@ public class MeshQuad { + 2 * 4 // UV (float) + 4 // B (int) + 4 // C (int) - + 4 // megaquad XY (byte) + + (Config.simplifyChunkMeshes ? 4 : 0) // megaquad XY (byte) ; } diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index 5c4f191..ce8172d 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -446,14 +446,17 @@ public class NeoRenderer { glVertexAttribPointer(1, 2, GL_FLOAT, false, stride, 3 * 4); glVertexAttribPointer(2, 2, GL_SHORT, false, stride, 5 * 4); glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, false, stride, 6 * 4); - glVertexAttribPointer(4, 4, GL_UNSIGNED_BYTE, false, stride, 7 * 4); - // we only need 2 bytes for attribute 4, but GL freaks out if the stride isn't a multiple of 4, so we have 2 unused bytes + if(Config.simplifyChunkMeshes) { + glVertexAttribPointer(4, 4, GL_UNSIGNED_BYTE, false, stride, 7 * 4); + } glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); - glEnableVertexAttribArray(4); + if(Config.simplifyChunkMeshes) { + glEnableVertexAttribArray(4); + } for(int i = 0; i < 2; i++) { piFirst[i] = BufferUtils.createIntBuffer(MAX_MESHES); diff --git a/src/main/resources/shaders/chunk.vert b/src/main/resources/shaders/chunk.vert index eb43942..b0d9177 100644 --- a/src/main/resources/shaders/chunk.vert +++ b/src/main/resources/shaders/chunk.vert @@ -3,7 +3,10 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; layout (location = 2) in vec2 aBTexCoord; layout (location = 3) in vec4 aColor; + +#ifdef SIMPLIFY_MESHES layout (location = 4) in vec4 aMQPos; // if the first coordinate is 255, it means: disable megaquad processing for this quad +#endif uniform mat4 modelView; uniform mat4 proj; @@ -31,7 +34,11 @@ void main() TexCoord = aTexCoord; BTexCoord = aBTexCoord; Color = aColor; + +#ifdef SIMPLIFY_MESHES MQPos = aMQPos; +#endif + Viewport = viewport; ProjInv = projInv; FogColor = fogColor; -- cgit