diff options
author | makamys <makamys@outlook.com> | 2022-06-14 14:20:50 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-19 21:07:05 +0200 |
commit | 8131a2c49dfcad48e5bfaa08f29b84065e9ceaf6 (patch) | |
tree | 854e83a7796c2f4243bc6212cc251c7bc7f205c3 /src/main/java/makamys/neodymium/renderer | |
parent | 90aafc433a5aa74b8921c930c7b679bb084bf2d7 (diff) | |
download | Neodymium-8131a2c49dfcad48e5bfaa08f29b84065e9ceaf6.tar.gz Neodymium-8131a2c49dfcad48e5bfaa08f29b84065e9ceaf6.tar.bz2 Neodymium-8131a2c49dfcad48e5bfaa08f29b84065e9ceaf6.zip |
Render quads instead of triangles
So apparently, glDrawArrays has a secret undocumented feature that lets you draw
quads. This increases my framerate by 50% on my integrated GPU, so you bet I'm
going to make use of it. On my dedicated GPU there's no significant framerate
difference.
For the record, using EBOs didn't improve performance on the integrated GPU.
Diffstat (limited to 'src/main/java/makamys/neodymium/renderer')
4 files changed, 7 insertions, 9 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java index 1c979b7..971c6f2 100644 --- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java @@ -235,7 +235,7 @@ public class ChunkMesh extends Mesh { } private ByteBuffer createBuffer(List<? extends MeshQuad> quads, int quadCount) { - ByteBuffer buffer = BufferUtils.createByteBuffer(quadCount * 6 * MeshQuad.getStride()); + ByteBuffer buffer = BufferUtils.createByteBuffer(quadCount * 4 * MeshQuad.getStride()); BufferWriter out = new BufferWriter(buffer); try { diff --git a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java index e35cc30..9dd9b04 100644 --- a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java +++ b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java @@ -153,7 +153,7 @@ public class GPUMemoryManager { glBufferSubData(GL_ARRAY_BUFFER, nextBase, mesh.buffer); mesh.iFirst = nextBase / mesh.getStride(); - mesh.iCount = mesh.quadCount * 6; + mesh.iCount = mesh.quadCount * 4; mesh.offset = nextBase; if(insertIndex == -1) { diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java index 9192f8d..581e6f3 100644 --- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java +++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java @@ -113,11 +113,9 @@ public class MeshQuad { } public void writeToBuffer(BufferWriter out) throws IOException { - int[] vertexI_to_vi = new int[]{3, 0, 1, 1, 2, 3}; - for(int vertexI = 0; vertexI < 6; vertexI++) { - int vi = vertexI_to_vi[vertexI]; - int ti = vertexI / 3; - int provokingI = vertexI_to_vi[ti * 3 + 2]; + for(int vertexI = 0; vertexI < 4; vertexI++) { + int vi = vertexI; + int provokingI = 3; float x = xs[vi]; float y = ys[vi]; diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index b7d09fe..ef5c9bd 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -358,7 +358,7 @@ public class NeoRenderer { if(Config.wireframe) { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); } - glMultiDrawArrays(GL_TRIANGLES, piFirst[0], piCount[0]); + glMultiDrawArrays(GL_QUADS, piFirst[0], piCount[0]); if(Config.wireframe) { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); } @@ -369,7 +369,7 @@ public class NeoRenderer { if(Config.wireframe) { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); } - glMultiDrawArrays(GL_TRIANGLES, piFirst[1], piCount[1]); + glMultiDrawArrays(GL_QUADS, piFirst[1], piCount[1]); if(Config.wireframe) { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); } |