From b5665a59c01728583978a0833f31c42deab7a64f Mon Sep 17 00:00:00 2001 From: tom lee Date: Wed, 15 Dec 2021 00:04:04 +0800 Subject: [PATCH] Renderer: Fix critical bug that black screen Minecraft --- .../seibel/lod/core/render/LodRenderer.java | 13 +++++------- .../core/render/objects/VertexAttribute.java | 21 ++++++++++--------- .../objects/VertexAttributePreGL43.java | 14 +++++++++++++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/seibel/lod/core/render/LodRenderer.java b/src/main/java/com/seibel/lod/core/render/LodRenderer.java index 6f3f6f81e..58baefc51 100644 --- a/src/main/java/com/seibel/lod/core/render/LodRenderer.java +++ b/src/main/java/com/seibel/lod/core/render/LodRenderer.java @@ -226,11 +226,9 @@ public class LodRenderer //===================// profiler.push("LOD draw setup"); - - // Get or setup the gl proxy and the needed objects - if (!GLProxy.hasInstance() && isSetupComplete) - ClientApi.LOGGER.warn("GLProxy has not yet been inited yet renderer state is enabled!"); + int currentProgram = GL20.glGetInteger(GL20.GL_CURRENT_PROGRAM); + // Setup LodRenderProgram and the LightmapTexture if it has not yet been done if (!isSetupComplete) setup(); @@ -250,7 +248,6 @@ public class LodRenderer GL15.glEnable(GL15.GL_BLEND); // get MC's shader program - int currentProgram = GL20.glGetInteger(GL20.GL_CURRENT_PROGRAM); // Get the matrixs for rendering Mat4f modelViewMatrix = translateModelViewMatrix(mcModelViewMatrix, partialTicks); @@ -317,7 +314,7 @@ public class LodRenderer shaderProgram.bind(); shaderProgram.bindVertexBuffer(bufferId); GL30.glDrawArrays(GL30.GL_TRIANGLES, 0, vbos[x][z][i].vertexCount); - shaderProgram.unbindVertexBuffer(); + //shaderProgram.unbindVertexBuffer(); } @@ -332,11 +329,11 @@ public class LodRenderer // if this cleanup isn't done MC will crash // when trying to render its own terrain GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); - + lightmapTexture.unbind(); shaderProgram.unbind(); lightmapTexture.free(); - + profiler.popPush("LOD cleanup"); GL15.glPolygonMode(GL15.GL_FRONT_AND_BACK, GL15.GL_FILL); diff --git a/src/main/java/com/seibel/lod/core/render/objects/VertexAttribute.java b/src/main/java/com/seibel/lod/core/render/objects/VertexAttribute.java index cdd6d6a23..8a72ccc63 100644 --- a/src/main/java/com/seibel/lod/core/render/objects/VertexAttribute.java +++ b/src/main/java/com/seibel/lod/core/render/objects/VertexAttribute.java @@ -19,6 +19,7 @@ package com.seibel.lod.core.render.objects; +import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; @@ -38,34 +39,34 @@ public abstract class VertexAttribute { this.byteSize = byteSize; } public static VertexPointer addFloatPointer(boolean normalized) { - return new VertexPointer(1, GL20.GL_FLOAT, normalized, 4); + return new VertexPointer(1, GL15.GL_FLOAT, normalized, 4); } public static VertexPointer addVec2Pointer(boolean normalized) { - return new VertexPointer(2, GL20.GL_FLOAT, normalized, 8); + return new VertexPointer(2, GL15.GL_FLOAT, normalized, 8); } public static VertexPointer addVec3Pointer(boolean normalized) { - return new VertexPointer(3, GL20.GL_FLOAT, normalized, 12); + return new VertexPointer(3, GL15.GL_FLOAT, normalized, 12); } public static VertexPointer addVec4Pointer(boolean normalized) { - return new VertexPointer(1, GL20.GL_FLOAT, normalized, 16); + return new VertexPointer(1, GL15.GL_FLOAT, normalized, 16); } public static VertexPointer addUnsignedBytePointer(boolean normalized) { - return new VertexPointer(1, GL20.GL_UNSIGNED_BYTE, normalized, 1); + return new VertexPointer(1, GL15.GL_UNSIGNED_BYTE, normalized, 1); } public static VertexPointer addUnsignedBytesPointer(int elementCount, boolean normalized) { - return new VertexPointer(elementCount, GL20.GL_UNSIGNED_BYTE, normalized, elementCount); + return new VertexPointer(elementCount, GL15.GL_UNSIGNED_BYTE, normalized, elementCount); } public static VertexPointer addIntPointer(boolean normalized) { - return new VertexPointer(1, GL20.GL_INT, normalized, 4); + return new VertexPointer(1, GL15.GL_INT, normalized, 4); } public static VertexPointer addIvec2Pointer(boolean normalized) { - return new VertexPointer(2, GL20.GL_INT, normalized, 8); + return new VertexPointer(2, GL15.GL_INT, normalized, 8); } public static VertexPointer addIvec3Pointer(boolean normalized) { - return new VertexPointer(3, GL20.GL_INT, normalized, 12); + return new VertexPointer(3, GL15.GL_INT, normalized, 12); } public static VertexPointer addIvec4Pointer(boolean normalized) { - return new VertexPointer(4, GL20.GL_INT, normalized, 16); + return new VertexPointer(4, GL15.GL_INT, normalized, 16); } } diff --git a/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java b/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java index 49d637ed2..608e06cf8 100644 --- a/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java +++ b/src/main/java/com/seibel/lod/core/render/objects/VertexAttributePreGL43.java @@ -128,6 +128,20 @@ public final class VertexAttributePreGL43 extends VertexAttribute { " does not match the provided expected stride size " + expectedStrideSize + "!"); strideSize = currentOffset; ClientApi.LOGGER.info("Vertex Attribute (pre GL43) completed."); + + // Debug logging + ClientApi.LOGGER.info("Vertex Attribute Debug Data:"); + + for (int i=0; i< pointers.length; i++) { + VertexPointer pointer = pointers[i]; + if (pointer==null) { + ClientApi.LOGGER.info(i + ": Null"); + continue; + } + ClientApi.LOGGER.info(i + ": "+pointer.elementCount+", "+ + pointer.glType+", "+pointer.normalized+", "+strideSize+", "+pointersOffset[i]); + } + } }