Attempted improvements for outline performance

This commit is contained in:
mcrcortex
2025-05-02 16:12:47 +10:00
parent 3fa50a8965
commit 84a32581b7
2 changed files with 15 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ import static org.lwjgl.opengl.GL30.glBindVertexArray;
import static org.lwjgl.opengl.GL30C.*; import static org.lwjgl.opengl.GL30C.*;
import static org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER; import static org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER;
import static org.lwjgl.opengl.GL31.glDrawElementsInstanced; import static org.lwjgl.opengl.GL31.glDrawElementsInstanced;
import static org.lwjgl.opengl.GL42.glDrawElementsInstancedBaseInstance;
import static org.lwjgl.opengl.GL45.glClearNamedFramebufferfv; import static org.lwjgl.opengl.GL45.glClearNamedFramebufferfv;
//This is a render subsystem, its very simple in what it does //This is a render subsystem, its very simple in what it does
@@ -134,10 +135,19 @@ public class ChunkBoundRenderer {
glBindFramebuffer(GL_FRAMEBUFFER, this.frameBuffer.id); glBindFramebuffer(GL_FRAMEBUFFER, this.frameBuffer.id);
this.rasterShader.bind(); this.rasterShader.bind();
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniformBuffer.id); glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniformBuffer.id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE.id()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BYTE.id());
//TODO: BATCH with multiple cubes per instance, this helps fill the pipe and should greatly improve performance of this //TODO: BATCH with multiple cubes per instance, this helps fill the pipe and should greatly improve performance of this
glDrawElementsInstanced(GL_TRIANGLES, 6*2*3, GL_UNSIGNED_BYTE, SharedIndexBuffer.CUBE_INDEX_OFFSET, this.chunk2idx.size()); int count = this.chunk2idx.size();
int i = 0;
if (count/32 > 0) {
glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3 * 32, GL_UNSIGNED_BYTE, SharedIndexBuffer.CUBE_INDEX_OFFSET, count/32);
i = (count/32)*32;
count -= i;
}
if (count > 0) {
glDrawElementsInstancedBaseInstance(GL_TRIANGLES, 6 * 2 * 3 * count, GL_UNSIGNED_BYTE, SharedIndexBuffer.CUBE_INDEX_OFFSET, 1, i);
}
{ {
glFrontFace(GL_CCW);//Restore winding order glFrontFace(GL_CCW);//Restore winding order

View File

@@ -11,7 +11,9 @@ layout(binding = 1, std430) restrict readonly buffer ChunkPosBuffer {
}; };
void main() { void main() {
ivec3 origin = ivec3(chunkPos[gl_InstanceID], 0).xzy; uint id = gl_InstanceID+gl_BaseInstance+(gl_VertexID>>3);
ivec3 origin = ivec3(chunkPos[id], 0).xzy;
origin -= section.xyz; origin -= section.xyz;
ivec3 cubeCornerI = ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1); ivec3 cubeCornerI = ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1);