aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-04 11:08:54 +0200
committermakamys <makamys@outlook.com>2022-06-04 13:29:14 +0200
commit524c250c683a380395dd065065f72731b730ed74 (patch)
tree6780daf81c9ebe5d7675df4b45a8cb8e4cdcccac /src
parent9e3b64d35ae5f9e5a4f28097426de70112ca0942 (diff)
downloadNeodymium-524c250c683a380395dd065065f72731b730ed74.tar.gz
Neodymium-524c250c683a380395dd065065f72731b730ed74.tar.bz2
Neodymium-524c250c683a380395dd065065f72731b730ed74.zip
Make visibility and sentness to gpu independent
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/lodmod/renderer/ChunkMesh.java15
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODChunk.java2
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java22
-rw-r--r--src/main/java/makamys/lodmod/renderer/Mesh.java4
4 files changed, 26 insertions, 17 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
index eef8ecd..33814a6 100644
--- a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java
@@ -96,13 +96,14 @@ public class ChunkMesh extends Mesh {
}
@Override
- public void onVisibilityChanged() {
- if(visible) {
- this.buffer = createBuffer(((NBTTagByteArray)nbtData).func_150292_c(), nameList);
- } else {
- usedRAM -= buffer.limit();
- this.buffer = null;
- }
+ public void prepareBuffer() {
+ this.buffer = createBuffer(((NBTTagByteArray)nbtData).func_150292_c(), nameList);
+ }
+
+ @Override
+ public void destroyBuffer(){
+ usedRAM -= buffer.limit();
+ this.buffer = null;
}
private ByteBuffer createBuffer(byte[] data, List<String> stringTable) {
diff --git a/src/main/java/makamys/lodmod/renderer/LODChunk.java b/src/main/java/makamys/lodmod/renderer/LODChunk.java
index a0adfe2..bc17c90 100644
--- a/src/main/java/makamys/lodmod/renderer/LODChunk.java
+++ b/src/main/java/makamys/lodmod/renderer/LODChunk.java
@@ -65,7 +65,7 @@ public class LODChunk {
newChunkMesh.pass = i;
}
- renderer.setMeshVisible(chunkMeshes[cy * 2 + i], false);
+ renderer.removeMesh(chunkMeshes[cy * 2 + i]);
chunkMeshes[cy * 2 + i].destroy();
}
chunkMeshes[cy * 2 + i] = newChunkMesh;
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index 8aa3955..95273c4 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -247,7 +247,7 @@ public class LODRenderer {
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
-
+
int[] deletedNum = new int[2];
int deletedRAM = 0;
@@ -277,6 +277,8 @@ public class LODRenderer {
mesh.iFirst = mesh.offset = -1;
mesh.visible = false;
mesh.gpuStatus = GPUStatus.UNSENT;
+ mesh.destroyBuffer();
+
it.remove();
deletedNum[i]++;
deletedRAM += mesh.bufferSize();
@@ -587,20 +589,24 @@ public class LODRenderer {
if(mesh.visible != visible) {
mesh.visible = visible;
- mesh.onVisibilityChanged();
- if(!visible) {
- deleteMeshFromGPU(mesh);
- } else if(visible) {
- sendMeshToGPU(mesh);
- }
+
+ if(mesh.gpuStatus == GPUStatus.UNSENT) {
+ sendMeshToGPU(mesh);
+ }
}
}
+ public void removeMesh(Mesh mesh) {
+ deleteMeshFromGPU(mesh);
+ }
+
private void sendMeshToGPU(Mesh mesh) {
if(mesh == null) {
return;
}
- if(mesh.gpuStatus == GPUStatus.UNSENT) {
+ if(mesh.gpuStatus == GPUStatus.UNSENT) {
+ mesh.prepareBuffer();
+
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
diff --git a/src/main/java/makamys/lodmod/renderer/Mesh.java b/src/main/java/makamys/lodmod/renderer/Mesh.java
index fca742c..ca645e8 100644
--- a/src/main/java/makamys/lodmod/renderer/Mesh.java
+++ b/src/main/java/makamys/lodmod/renderer/Mesh.java
@@ -19,7 +19,6 @@ public abstract class Mesh {
int x, y, z;
public abstract int getStride();
- public void onVisibilityChanged() {}
public double distSq(double x2, double y2, double z2) {
return Util.distSq(x, y, z, x2, y2, z2);
@@ -33,6 +32,9 @@ public abstract class Mesh {
return bufferSize;
}
+ public void prepareBuffer() {}
+ public void destroyBuffer() {}
+
public static enum GPUStatus {
UNSENT, SENT, PENDING_DELETE
}