Fix Debug renderer on newer MC versions
This commit is contained in:
@@ -74,7 +74,6 @@ public class ClientApi
|
||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||
|
||||
public static final ClientApi INSTANCE = new ClientApi();
|
||||
public static final TestRenderer TEST_RENDERER = new TestRenderer();
|
||||
|
||||
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
@@ -553,6 +552,11 @@ public class ClientApi
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DISABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
///endregion
|
||||
|
||||
|
||||
@@ -568,24 +572,15 @@ public class ClientApi
|
||||
|
||||
if (!renderingDeferredLayer)
|
||||
{
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DEFAULT)
|
||||
boolean renderingCancelled = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, renderParams);
|
||||
if (!renderingCancelled)
|
||||
{
|
||||
boolean renderingCancelledForThisFrame = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, renderParams);
|
||||
if (!renderingCancelledForThisFrame)
|
||||
{
|
||||
LodRenderer.INSTANCE.render(renderParams, profiler);
|
||||
}
|
||||
|
||||
if (!DhApi.Delayed.renderProxy.getDeferTransparentRendering())
|
||||
{
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterRenderEvent.class, null);
|
||||
}
|
||||
LodRenderer.INSTANCE.render(renderParams, profiler);
|
||||
}
|
||||
else if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DEBUG)
|
||||
|
||||
if (!DhApi.Delayed.renderProxy.getDeferTransparentRendering())
|
||||
{
|
||||
profiler.push("Render Debug");
|
||||
ClientApi.TEST_RENDERER.render();
|
||||
profiler.pop();
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterRenderEvent.class, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -638,7 +633,7 @@ public class ClientApi
|
||||
public void renderFadeOpaque() // TODO is this actually the transparent pass in MC 1.21.11?
|
||||
{
|
||||
// only fade when DH is rendering
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DEFAULT
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED
|
||||
&&
|
||||
(
|
||||
// only fade when requested
|
||||
@@ -660,7 +655,7 @@ public class ClientApi
|
||||
public void renderFadeTransparent() // TODO is this actually the opaque pass in MC 1.21.11?
|
||||
{
|
||||
// only fade when DH is rendering
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DEFAULT)
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED)
|
||||
{
|
||||
boolean renderFade =
|
||||
(
|
||||
|
||||
@@ -85,7 +85,6 @@ public class WebDownloader
|
||||
totalDataRead = totalDataRead + i;
|
||||
bout.write(data, 0, i);
|
||||
|
||||
// TODO: Link this to an atomic integer rather than printing it to log
|
||||
int newPercent = (int) ((totalDataRead * 100) / filesize);
|
||||
if (percent != newPercent)
|
||||
{
|
||||
@@ -100,7 +99,6 @@ public class WebDownloader
|
||||
public static String downloadAsString(URL url) throws Exception
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
// URL url = new URL(urlS);
|
||||
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
urlConnection.setConnectTimeout(1000);
|
||||
|
||||
+46
-23
@@ -19,11 +19,13 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.render.renderer;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
@@ -116,6 +118,7 @@ public class LodRenderer
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
//region
|
||||
|
||||
/**
|
||||
* This will draw both opaque and transparent LODs if
|
||||
@@ -361,11 +364,14 @@ public class LodRenderer
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// Setup Functions //
|
||||
//=================//
|
||||
//region
|
||||
|
||||
private void setGLState(
|
||||
DhApiRenderParam renderEventParam,
|
||||
@@ -590,11 +596,14 @@ public class LodRenderer
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterColorDepthTextureCreatedEvent.class, textureCreatedParam);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// LOD rendering //
|
||||
//===============//
|
||||
//region
|
||||
|
||||
private void renderLodPass(IDhApiShaderProgram shaderProgram, RenderBufferHandler lodBufferHandler, RenderParams renderEventParam, boolean opaquePass)
|
||||
{
|
||||
@@ -644,40 +653,49 @@ public class LodRenderer
|
||||
GLMC.enableFaceCulling();
|
||||
}
|
||||
|
||||
|
||||
SortedArraySet<LodBufferContainer> lodBufferContainer = lodBufferHandler.getColumnRenderBuffers();
|
||||
if (lodBufferContainer != null)
|
||||
if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DEFAULT)
|
||||
{
|
||||
for (int lodIndex = 0; lodIndex < lodBufferContainer.size(); lodIndex++)
|
||||
// Normal LOD rendering
|
||||
|
||||
SortedArraySet<LodBufferContainer> lodBufferContainer = lodBufferHandler.getColumnRenderBuffers();
|
||||
if (lodBufferContainer != null)
|
||||
{
|
||||
LodBufferContainer bufferContainer = lodBufferContainer.get(lodIndex);
|
||||
this.setShaderProgramMvmOffset(bufferContainer.minCornerBlockPos, shaderProgram, renderEventParam);
|
||||
|
||||
GLVertexBuffer[] vbos = opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent;
|
||||
for (int vboIndex = 0; vboIndex < vbos.length; vboIndex++)
|
||||
for (int lodIndex = 0; lodIndex < lodBufferContainer.size(); lodIndex++)
|
||||
{
|
||||
GLVertexBuffer vbo = vbos[vboIndex];
|
||||
if (vbo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
LodBufferContainer bufferContainer = lodBufferContainer.get(lodIndex);
|
||||
this.setShaderProgramMvmOffset(bufferContainer.minCornerBlockPos, shaderProgram, renderEventParam);
|
||||
|
||||
if (vbo.getVertexCount() == 0)
|
||||
GLVertexBuffer[] vbos = opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent;
|
||||
for (int vboIndex = 0; vboIndex < vbos.length; vboIndex++)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vbo.bind();
|
||||
shaderProgram.bindVertexBuffer(vbo.getId());
|
||||
GL32.glDrawElements(
|
||||
GLVertexBuffer vbo = vbos[vboIndex];
|
||||
if (vbo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vbo.getVertexCount() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vbo.bind();
|
||||
shaderProgram.bindVertexBuffer(vbo.getId());
|
||||
GL32.glDrawElements(
|
||||
GL32.GL_TRIANGLES,
|
||||
(vbo.getVertexCount() / 4) * 6, // TODO what does the 4 and 6 here represent?
|
||||
this.quadIBO.getType(), 0);
|
||||
vbo.unbind();
|
||||
vbo.unbind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// basic quad rendering
|
||||
|
||||
TestRenderer.INSTANCE.render();
|
||||
}
|
||||
|
||||
|
||||
//=========================//
|
||||
@@ -711,11 +729,14 @@ public class LodRenderer
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// API functions //
|
||||
//===============//
|
||||
//region
|
||||
|
||||
/** @return -1 if no frame buffer has been bound yet */
|
||||
public int getActiveFramebufferId() { return this.activeFramebufferId; }
|
||||
@@ -726,6 +747,8 @@ public class LodRenderer
|
||||
/** @return -1 if no texture has been bound yet */
|
||||
public int getActiveDepthTextureId() { return this.activeDepthTextureId; }
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+38
-27
@@ -35,7 +35,11 @@ import org.lwjgl.opengl.GL32;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
|
||||
/**
|
||||
* Renders a UV colored quad
|
||||
* to the center of the screen to confirm DH's
|
||||
* apply shader is running correctly
|
||||
*/
|
||||
public class TestRenderer
|
||||
{
|
||||
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||
@@ -43,6 +47,17 @@ public class TestRenderer
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
|
||||
|
||||
public static final TestRenderer INSTANCE = new TestRenderer();
|
||||
|
||||
// Render a square with uv color
|
||||
private static final float[] VERTICES = {
|
||||
// PosX,Y, ColorR,G,B,A
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.4f, -0.4f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.3f, 0.3f, 1.0f, 1.0f, 0.0f, 0.0f,
|
||||
-0.2f, 0.2f, 0.0f, 1.0f, 1.0f, 1.0f
|
||||
};
|
||||
|
||||
|
||||
|
||||
ShaderProgram basicShader;
|
||||
@@ -52,8 +67,12 @@ public class TestRenderer
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
//region
|
||||
|
||||
public TestRenderer() { }
|
||||
private TestRenderer() { }
|
||||
|
||||
public void init()
|
||||
{
|
||||
@@ -71,48 +90,39 @@ public class TestRenderer
|
||||
// Color
|
||||
this.va.setVertexAttribute(0, 1, VertexPointer.addVec4Pointer(false));
|
||||
this.va.completeAndCheck(Float.BYTES * 6);
|
||||
this.basicShader = new ShaderProgram("shaders/test/vert.vert", "shaders/test/frag.frag",
|
||||
"fragColor", new String[]{"vPosition", "color"});
|
||||
this.basicShader = new ShaderProgram(
|
||||
"shaders/test/vert.vert", "shaders/test/frag.frag",
|
||||
"fragColor", new String[]{"vPosition", "color"});
|
||||
|
||||
this.createBuffer();
|
||||
}
|
||||
|
||||
// Render a square with uv color
|
||||
private static final float[] vertices = {
|
||||
// PosX,Y, ColorR,G,B,A
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.4f, -0.4f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.3f, 0.3f, 1.0f, 1.0f, 0.0f, 0.0f,
|
||||
-0.2f, 0.2f, 0.0f, 1.0f, 1.0f, 1.0f
|
||||
};
|
||||
|
||||
private void createBuffer()
|
||||
{
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(vertices.length * Float.BYTES);
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(VERTICES.length * Float.BYTES);
|
||||
// Fill buffer with vertices.
|
||||
buffer.order(ByteOrder.nativeOrder());
|
||||
buffer.asFloatBuffer().put(vertices);
|
||||
buffer.asFloatBuffer().put(VERTICES);
|
||||
buffer.rewind();
|
||||
|
||||
this.vbo = new GLVertexBuffer(false);
|
||||
this.vbo.bind();
|
||||
this.vbo.uploadBuffer(buffer, 4, EDhApiGpuUploadMethod.DATA, vertices.length * Float.BYTES);
|
||||
this.vbo.uploadBuffer(buffer, 4, EDhApiGpuUploadMethod.DATA, VERTICES.length * Float.BYTES);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
//========//
|
||||
// render //
|
||||
//========//
|
||||
//region
|
||||
|
||||
public void render()
|
||||
{
|
||||
// TODO fix for MC 1.21.5+
|
||||
this.init();
|
||||
|
||||
GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, MC_RENDER.getTargetFramebuffer());
|
||||
GL32.glViewport(0, 0, MC_RENDER.getTargetFramebufferViewportWidth(), MC_RENDER.getTargetFramebufferViewportHeight());
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
|
||||
GLMC.disableFaceCulling();
|
||||
GLMC.disableDepthTest();
|
||||
GLMC.disableBlend();
|
||||
GLMC.disableScissorTest();
|
||||
|
||||
this.basicShader.bind();
|
||||
this.va.bind();
|
||||
|
||||
@@ -121,9 +131,10 @@ public class TestRenderer
|
||||
|
||||
// Render the square
|
||||
GL32.glDrawArrays(GL32.GL_TRIANGLE_FAN, 0, 4);
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ public class ThreadUtil
|
||||
|
||||
public static final String THREAD_NAME_PREFIX = ModInfo.THREAD_NAME_PREFIX;
|
||||
|
||||
// TODO move all "Runtime.getRuntime().availableProcessors()" calls here
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
|
||||
Reference in New Issue
Block a user