From 8fe6eff36c92b20bef80238fd99351e4aec26fa9 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 7 Oct 2021 22:45:48 -0500 Subject: [PATCH] improve the buffer expanding logging --- .../bufferBuilding/LodBufferBuilder.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java b/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java index b2d71fb5b..7ea92e0e7 100644 --- a/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java +++ b/src/main/java/com/seibel/lod/builders/bufferBuilding/LodBufferBuilder.java @@ -576,7 +576,7 @@ public class LodBufferBuilder for (int i = 0; i < buildableBuffers[x][z].length; i++) { ByteBuffer builderBuffer = buildableBuffers[x][z][i].popNextBuffer().getSecond(); - vboUpload(buildableVbos[x][z][i], buildableStorageBufferIds[x][z], builderBuffer); + vboUpload(buildableVbos[x][z][i], buildableStorageBufferIds[x][z], builderBuffer, x,z); lodDim.setRegenRegionBufferByArrayIndex(x, z, false); } } @@ -599,7 +599,10 @@ public class LodBufferBuilder } /** Uploads the uploadBuffer into the VBO and then into GPU memory. */ - private void vboUpload(VertexBuffer vbo, int storageBufferId, ByteBuffer uploadBuffer) + private void vboUpload(VertexBuffer vbo, int storageBufferId, ByteBuffer uploadBuffer, + int xVboIndex, int zVboIndex) + // x/zVboIndex are just used for the debugging console logging + // and should be removed when the logger is removed. { // this shouldn't happen, but just to be safe if (vbo.id != -1 && GlProxy.getInstance().getGlContext() == GlProxyContext.LOD_BUILDER) @@ -615,13 +618,20 @@ public class LodBufferBuilder ByteBuffer vboBuffer = GL45.glMapBufferRange(GL45.GL_ARRAY_BUFFER, 0, uploadBuffer.capacity(), GL45.GL_MAP_WRITE_BIT | GL45.GL_MAP_UNSYNCHRONIZED_BIT); if (vboBuffer == null) { - // the buffer in system memory isn't big enough, - // expand it so next time hopefully it will be big enough. - // This does cause lag/stuttering so it should be avoided! - GL45.glBufferData(GL45.GL_ARRAY_BUFFER, uploadBuffer.capacity() * 4, GL45.GL_STREAM_DRAW); - GL45.glBufferSubData(GL45.GL_ARRAY_BUFFER, 0, uploadBuffer); + int previousCapacity = uploadBuffer.capacity(); - ClientProxy.LOGGER.info("null"); + // only change the system buffer if the uploadBuffer actually + // has something in it + if (previousCapacity != 0) + { + // the buffer in system memory isn't big enough, + // expand it so next time hopefully it will be big enough. + // This does cause lag/stuttering so it should be avoided! + GL45.glBufferData(GL45.GL_ARRAY_BUFFER, uploadBuffer.capacity() * 4, GL45.GL_DYNAMIC_DRAW); + GL45.glBufferSubData(GL45.GL_ARRAY_BUFFER, 0, uploadBuffer); + + ClientProxy.LOGGER.info("vbo (" + xVboIndex + "," + zVboIndex + ") expanded: " + previousCapacity + " -> " + (previousCapacity * 4)); + } } else { @@ -636,8 +646,8 @@ public class LodBufferBuilder } catch(Exception e) { - ClientProxy.LOGGER.info(e.getClass().getSimpleName()); -// e.printStackTrace(); + ClientProxy.LOGGER.error("vboUpload failed: " + e.getClass().getSimpleName()); + e.printStackTrace(); } finally {