diff options
Diffstat (limited to 'src/main/java/makamys/lodmod')
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/LODRenderer.java | 43 | ||||
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/Mesh.java | 6 |
2 files changed, 27 insertions, 22 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index 6ea54c6..8aa3955 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -42,6 +42,7 @@ import org.lwjgl.util.vector.Matrix4f; import makamys.lodmod.LODMod; import makamys.lodmod.ducks.IWorldRenderer; +import makamys.lodmod.renderer.Mesh.GPUStatus; import makamys.lodmod.util.Util; import static org.lwjgl.opengl.GL11.*; @@ -258,7 +259,7 @@ public class LODRenderer { for(Iterator<Mesh> it = sentMeshes[i].iterator(); it.hasNext(); ) { Mesh mesh = it.next(); - if(!mesh.pendingGPUDelete) { + if(mesh.gpuStatus == GPUStatus.SENT) { if(mesh.offset != nextMeshOffset) { glBufferSubData(GL_ARRAY_BUFFER, nextMeshOffset, mesh.buffer); } @@ -272,10 +273,10 @@ public class LODRenderer { piFirst[i].put(mesh.iFirst); piCount[i].limit(piCount[i].limit() + 1); piCount[i].put(mesh.iCount); - } else { + } else if(mesh.gpuStatus == GPUStatus.PENDING_DELETE) { mesh.iFirst = mesh.offset = -1; mesh.visible = false; - mesh.pendingGPUDelete = false; + mesh.gpuStatus = GPUStatus.UNSENT; it.remove(); deletedNum[i]++; deletedRAM += mesh.bufferSize(); @@ -599,31 +600,31 @@ public class LODRenderer { if(mesh == null) { return; } - if(mesh.pendingGPUDelete) { - mesh.pendingGPUDelete = false; - return; + if(mesh.gpuStatus == GPUStatus.UNSENT) { + glBindVertexArray(VAO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + + glBufferSubData(GL_ARRAY_BUFFER, nextMeshOffset, mesh.buffer); + mesh.iFirst = nextTri; + mesh.iCount = mesh.quadCount * 6; + mesh.offset = nextMeshOffset; + + nextTri += mesh.quadCount * 6; + nextMeshOffset += mesh.buffer.limit(); + sentMeshes[mesh.pass].add(mesh); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); } - glBindVertexArray(VAO); - glBindBuffer(GL_ARRAY_BUFFER, VBO); - - glBufferSubData(GL_ARRAY_BUFFER, nextMeshOffset, mesh.buffer); - mesh.iFirst = nextTri; - mesh.iCount = mesh.quadCount * 6; - mesh.offset = nextMeshOffset; - - nextTri += mesh.quadCount * 6; - nextMeshOffset += mesh.buffer.limit(); - sentMeshes[mesh.pass].add(mesh); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0); + mesh.gpuStatus = GPUStatus.SENT; } private void deleteMeshFromGPU(Mesh mesh) { - if(mesh == null) { + if(mesh == null || mesh.gpuStatus == GPUStatus.UNSENT) { return; } - mesh.pendingGPUDelete = true; + mesh.gpuStatus = GPUStatus.PENDING_DELETE; } public Chunk getChunkFromChunkCoords(int x, int z) { diff --git a/src/main/java/makamys/lodmod/renderer/Mesh.java b/src/main/java/makamys/lodmod/renderer/Mesh.java index 3f8b0fe..fca742c 100644 --- a/src/main/java/makamys/lodmod/renderer/Mesh.java +++ b/src/main/java/makamys/lodmod/renderer/Mesh.java @@ -12,7 +12,7 @@ public abstract class Mesh { public ByteBuffer buffer; public int quadCount; public boolean visible; - public boolean pendingGPUDelete; + public GPUStatus gpuStatus = GPUStatus.UNSENT; public int iFirst = -1, iCount = -1; public int offset = -1; public int pass; @@ -32,4 +32,8 @@ public abstract class Mesh { } return bufferSize; } + + public static enum GPUStatus { + UNSENT, SENT, PENDING_DELETE + } } |