Fix multiple little bugs

This commit is contained in:
TomTheFurry
2022-04-15 16:48:49 +08:00
parent b98082980b
commit 705060fa97
7 changed files with 33 additions and 15 deletions
@@ -31,6 +31,7 @@ import com.seibel.lod.core.objects.lod.LodDimension;
import com.seibel.lod.core.objects.lod.RegionPos;
import com.seibel.lod.core.objects.opengl.RenderRegion;
import com.seibel.lod.core.render.LodRenderer;
import com.seibel.lod.core.render.objects.GLBuffer;
import com.seibel.lod.core.util.*;
import com.seibel.lod.core.util.gridList.MovableGridRingList;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
@@ -291,12 +292,14 @@ public class LodBufferBuilderFactory {
if (renderRegions == null) {
ramLogger.info("Buildable VBOs are null!");
} else
} else {
for (RenderRegion buffers : renderRegions) {
if (buffers == null)
continue;
buffers.debugDumpStats(statsMap);
}
}
statsMap.incStat("Total Buffers", GLBuffer.count.get());
ramLogger.info("================================================");
ramLogger.info("Stats: {}", statsMap);
ramLogger.info("================================================");
@@ -125,6 +125,9 @@ public class SimpleRenderBuffer extends RenderBuffer
int i = 0;
Iterator<ByteBuffer> iter = builder.makeVertexBuffers();
while (iter.hasNext()) {
if (i >= vbos.length) {
throw new RuntimeException("Too many vertex buffers!!");
}
ByteBuffer bb = iter.next();
GLVertexBuffer vbo = getOrMakeVbo(i++, method.useBufferStorage);
int size = bb.limit() - bb.position();
@@ -150,6 +153,9 @@ public class SimpleRenderBuffer extends RenderBuffer
remainingNS = 0;
}
}
if (i < vbos.length) {
throw new RuntimeException("Too few vertex buffers!!");
}
}
private void _uploadBuffersMapped(LodQuadBuilder builder, GpuUploadMethod method)
@@ -436,9 +436,10 @@ public class GLProxy
*/
public void recordOpenGlCall(Runnable renderCall)
{
workerThread.execute(() -> runnableContainer(renderCall));
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
workerThread.execute(() -> runnableContainer(renderCall, stackTrace));
}
private void runnableContainer(Runnable renderCall)
private void runnableContainer(Runnable renderCall, StackTraceElement[] stackTrace)
{
try
{
@@ -449,8 +450,9 @@ public class GLProxy
}
catch (Exception e)
{
GL_LOGGER.error(Thread.currentThread().getName() + " ran into a issue: " + e.getMessage());
e.printStackTrace();
RuntimeException error = new RuntimeException("Uncaught Exception during execution:", e);
error.setStackTrace(stackTrace);
GL_LOGGER.error(Thread.currentThread().getName() + " ran into a issue: ", error);
}
finally
{
@@ -360,7 +360,7 @@ public class LodFogConfig
if (drawNearFog)
str += "max(1.0-near, far*height);\n";
else
str += "near * far*height);\n";
str += "near * far * height;\n";
break;
case LIMITED_ADDITION:
@@ -58,6 +58,7 @@ public class RenderSystemTest {
logger.info("init");
init = true;
va = VertexAttribute.create();
va.bind();
// Pos
va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false));
// Color
@@ -78,12 +79,13 @@ public class RenderSystemTest {
};
private static GLVertexBuffer createTextingBuffer() {
GLVertexBuffer vbo = new GLVertexBuffer(false);
ByteBuffer buffer = ByteBuffer.allocateDirect(vertices.length * Float.BYTES);
// Fill buffer with the vertices.
buffer = buffer.order(ByteOrder.nativeOrder());
buffer.asFloatBuffer().put(vertices);
buffer.rewind();
GLVertexBuffer vbo = new GLVertexBuffer(false);
vbo.bind();
vbo.uploadBuffer(buffer, 4, GpuUploadMethod.DATA, vertices.length * Float.BYTES);
return vbo;
}
@@ -9,11 +9,12 @@ import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GL44;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger;
public class GLBuffer implements AutoCloseable {
public static final double BUFFER_EXPANSION_MULTIPLIER = 1.3;
public static final double BUFFER_SHRINK_TRIGGER = BUFFER_EXPANSION_MULTIPLIER * BUFFER_EXPANSION_MULTIPLIER;
public static int count = 0;
public static AtomicInteger count = new AtomicInteger(0);
protected int id;
public final int getId() {
return id;
@@ -50,23 +51,25 @@ public class GLBuffer implements AutoCloseable {
throw new IllegalStateException("Thread [" +Thread.currentThread().getName() + "] tried to create a GLBuffer outside a OpenGL context.");
this.id = GL32.glGenBuffers();
this.bufferStorage = asBufferStorage;
count++;
count.getAndIncrement();
}
//DEBUG USE
//private StackTraceElement[] firstCloseCallStack = null;
protected void destroy(boolean async) {
if (this.id == 0) {
ApiShared.LOGGER.warn("Buffer double close!");
return;
//ApiShared.LOGGER.warn("Buffer double close! First close call stack: {}", Arrays.toString(firstCloseCallStack));
throw new IllegalStateException("Buffer double close!");
}
if (async && GLProxy.getInstance().getGlContext() != GLProxyContext.PROXY_WORKER) {
GLProxy.getInstance().recordOpenGlCall(() -> destroy((false)));
} else {
GL32.glDeleteBuffers(id);
//firstCloseCallStack = Thread.currentThread().getStackTrace();
id = 0;
size = 0;
if (count.decrementAndGet()==0) ApiShared.LOGGER.info("All GLBuffer is freed.");
}
id = 0;
size = 0;
count--;
if (count==0) ApiShared.LOGGER.info("All GLBuffer is freed.");
}
// Requires already binded
@@ -81,7 +81,9 @@ public class Shader
// check if the shader compiled
int status = GL32.glGetShaderi(id, GL32.GL_COMPILE_STATUS);
if (status != GL32.GL_TRUE) {
String message = "Shader compiler error. Details: "+GL32.glGetShaderInfoLog(id);
message += "\nSource:\n"+sourceString;
free(); // important!
throw new RuntimeException(message);
}