diff options
author | makamys <makamys@outlook.com> | 2022-06-07 23:19:51 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-07 23:19:51 +0200 |
commit | 6f99449bd858a15d5ee1bc5e89a5a88c0356ec1c (patch) | |
tree | 45301a58995037ad7436f4e60ee9a3b085e8771e | |
parent | a91466fdc6280b12b26b0caf528c5170ec2a48f9 (diff) | |
download | Neodymium-6f99449bd858a15d5ee1bc5e89a5a88c0356ec1c.tar.gz Neodymium-6f99449bd858a15d5ee1bc5e89a5a88c0356ec1c.tar.bz2 Neodymium-6f99449bd858a15d5ee1bc5e89a5a88c0356ec1c.zip |
Fix mesh tracking
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/ChunkMesh.java | 3 | ||||
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java | 24 | ||||
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/Mesh.java | 2 |
3 files changed, 13 insertions, 16 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java index ab8ce1f..0bf4b60 100644 --- a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java +++ b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java @@ -248,8 +248,9 @@ public class ChunkMesh extends Mesh { void destroy() { if(buffer != null) { usedRAM -= buffer.limit(); + instances--; + buffer = null; } - instances--; } @Override diff --git a/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java b/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java index 4eb1418..6789406 100644 --- a/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java +++ b/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java @@ -31,11 +31,6 @@ public class GPUMemoryManager { public void runGC() { glBindBuffer(GL_ARRAY_BUFFER, VBO); - - int deletedNum = 0; - int deletedRAM = 0; - - long t0 = System.nanoTime(); int moved = 0; int checksLeft = sentMeshes.size(); @@ -59,12 +54,10 @@ public class GPUMemoryManager { mesh.iFirst = mesh.offset = -1; mesh.visible = false; mesh.gpuStatus = GPUStatus.UNSENT; - mesh.destroyBuffer(); sentMeshes.remove(nextMesh); - deletedNum++; - deletedRAM += mesh.bufferSize(); + mesh.destroyBuffer(); if(nextMesh > 0) { nextMesh--; @@ -72,10 +65,6 @@ public class GPUMemoryManager { } } - long t1 = System.nanoTime(); - - //System.out.println("Deleted " + deletedNum + " meshes in " + ((t1 - t0) / 1_000_000.0) + " ms, freeing up " + (deletedRAM / 1024 / 1024) + "MB of VRAM"); - glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -112,8 +101,15 @@ public class GPUMemoryManager { if(!sentMeshes.isEmpty()) { if(nextMesh < sentMeshes.size() - 1) { Mesh next = sentMeshes.get(nextMesh); - Mesh nextnext = sentMeshes.get(nextMesh + 1); - if(nextnext.offset - next.getEnd() >= size) { + Mesh nextnext = null; + for(int i = nextMesh + 1; i < sentMeshes.size(); i++) { + Mesh m = sentMeshes.get(i); + if(m.gpuStatus == Mesh.GPUStatus.SENT) { + nextnext = m; + break; + } + } + if(nextnext != null && nextnext.offset - next.getEnd() >= size) { nextBase = next.getEnd(); insertIndex = nextMesh + 1; } diff --git a/src/main/java/makamys/lodmod/renderer/Mesh.java b/src/main/java/makamys/lodmod/renderer/Mesh.java index 600ccf1..9d41960 100644 --- a/src/main/java/makamys/lodmod/renderer/Mesh.java +++ b/src/main/java/makamys/lodmod/renderer/Mesh.java @@ -25,7 +25,7 @@ public abstract class Mesh { } public int bufferSize() { - return buffer.limit(); + return buffer == null ? 0 : buffer.limit(); } public int getEnd() { |