Renderer: Fixup some stuff that maybe an issue
This commit is contained in:
@@ -61,7 +61,7 @@ public class ClientApi
|
||||
private boolean firstTimeSetupComplete = false;
|
||||
private boolean configOverrideReminderPrinted = false;
|
||||
|
||||
private boolean rendererDisabledBecauseOfExceptions = false;
|
||||
public boolean rendererDisabledBecauseOfExceptions = false;
|
||||
|
||||
|
||||
private ClientApi()
|
||||
|
||||
@@ -121,7 +121,8 @@ public class EventApi
|
||||
{
|
||||
// the player just unloaded a world/dimension
|
||||
ThreadMapUtil.clearMaps();
|
||||
ClientApi.renderer.markForCleanup();
|
||||
// ClientApi.renderer.markForCleanup();
|
||||
// ClientApi.renderer.destroyBuffers();
|
||||
|
||||
new Thread(() -> checkIfDisconnectedFromServer()).start();
|
||||
}
|
||||
@@ -161,6 +162,7 @@ public class EventApi
|
||||
recalculateWidths = true;
|
||||
// TODO: Check if after the refactoring, is this still needed
|
||||
ClientApi.renderer = new LodRenderer(ApiShared.lodBufferBuilderFactory);
|
||||
ClientApi.INSTANCE.rendererDisabledBecauseOfExceptions = false;
|
||||
|
||||
// make sure the nulled objects are freed.
|
||||
// (this prevents an out of memory error when
|
||||
|
||||
@@ -166,19 +166,16 @@ public class LodRenderer
|
||||
// which blindness relies on.
|
||||
return;
|
||||
}
|
||||
|
||||
GLProxy glProxy = GLProxy.getInstance();
|
||||
if (CONFIG.client().graphics().fogQuality().getDisableVanillaFog())
|
||||
glProxy.disableLegacyFog();
|
||||
|
||||
|
||||
// TODO move the buffer regeneration logic into its own class (probably called in the client api instead)
|
||||
// starting here...
|
||||
determineIfLodsShouldRegenerate(lodDim, partialTicks);
|
||||
|
||||
// FIXME: Currently, we check for last Lod Dimension so that we can trigger a cleanup() if dimension has changed
|
||||
// The better thing to do is to call cleanup() on leaving dimensions in the EventApi, but only for client-side.
|
||||
if (markToCleanup || (lastLodDimension != null && lodDim != lastLodDimension)) {
|
||||
markToCleanup = false;
|
||||
cleanup(); // This will unset the isSetupComplete, causing a setup() call.
|
||||
lastLodDimension = lodDim;
|
||||
fullRegen = true;
|
||||
}
|
||||
|
||||
//=================//
|
||||
// create the LODs //
|
||||
@@ -214,6 +211,15 @@ public class LodRenderer
|
||||
// (Vbos should be setup by now)
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Currently, we check for last Lod Dimension so that we can trigger a cleanup() if dimension has changed
|
||||
// The better thing to do is to call cleanup() on leaving dimensions in the EventApi, but only for client-side.
|
||||
if (markToCleanup || (lastLodDimension != null && lodDim != lastLodDimension)) {
|
||||
markToCleanup = false;
|
||||
cleanup(); // This will unset the isSetupComplete, causing a setup() call.
|
||||
lastLodDimension = lodDim;
|
||||
//fullRegen = true;
|
||||
}
|
||||
|
||||
//===================//
|
||||
// draw params setup //
|
||||
@@ -225,12 +231,9 @@ public class LodRenderer
|
||||
if (!GLProxy.hasInstance() && isSetupComplete)
|
||||
ClientApi.LOGGER.warn("GLProxy has not yet been inited yet renderer state is enabled!");
|
||||
|
||||
GLProxy glProxy = GLProxy.getInstance();
|
||||
// Setup LodRenderProgram and the LightmapTexture if it has not yet been done
|
||||
if (!isSetupComplete) setup();
|
||||
|
||||
if (CONFIG.client().graphics().fogQuality().getDisableVanillaFog())
|
||||
GLProxy.getInstance().disableLegacyFog();
|
||||
|
||||
// set the required open GL settings
|
||||
|
||||
@@ -267,14 +270,17 @@ public class LodRenderer
|
||||
//==============//
|
||||
|
||||
// Bind and update the lightmap data
|
||||
lightmapTexture.bind();
|
||||
lightmapTexture.fillData(MC_RENDER.getLightmapTextureWidth(), MC_RENDER.getLightmapTextureHeight(), MC_RENDER.getLightmapPixels());
|
||||
|
||||
GL20.glActiveTexture(GL20.GL_TEXTURE0);
|
||||
|
||||
shaderProgram.bind();
|
||||
// Fill the uniform data. Note: GL_TEXTURE_2D == texture bindpoint 0
|
||||
shaderProgram.fillUniformData(modelViewMatrix, projectionMatrix, getTranslatedCameraPos(),
|
||||
getFogColor(), (int) (MC.getSkyDarken(partialTicks) * 15), 0);
|
||||
|
||||
lightmapTexture = new LightmapTexture();
|
||||
lightmapTexture.bind();
|
||||
lightmapTexture.fillData(MC_RENDER.getLightmapTextureWidth(), MC_RENDER.getLightmapTextureHeight(), MC_RENDER.getLightmapPixels());
|
||||
|
||||
// Previous guy said fog setting may be different from region to region, but the fogSettings never changed... soooooo...
|
||||
shaderProgram.fillUniformDataForFog(fogSettings);
|
||||
|
||||
@@ -308,6 +314,7 @@ public class LodRenderer
|
||||
bufferId = (storageBufferIds != null && renderBufferStorage) ? storageBufferIds[x][z][i] : vbos[x][z][i].id;
|
||||
if (bufferId==0) continue;
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferId);
|
||||
shaderProgram.bind();
|
||||
shaderProgram.bindVertexBuffer(bufferId);
|
||||
GL30.glDrawArrays(GL30.GL_TRIANGLES, 0, vbos[x][z][i].vertexCount);
|
||||
shaderProgram.unbindVertexBuffer();
|
||||
@@ -328,6 +335,7 @@ public class LodRenderer
|
||||
|
||||
lightmapTexture.unbind();
|
||||
shaderProgram.unbind();
|
||||
lightmapTexture.free();
|
||||
|
||||
profiler.popPush("LOD cleanup");
|
||||
|
||||
@@ -360,7 +368,7 @@ public class LodRenderer
|
||||
|
||||
isSetupComplete = true;
|
||||
shaderProgram = new LodRenderProgram();
|
||||
lightmapTexture = new LightmapTexture();
|
||||
//lightmapTexture = new LightmapTexture();
|
||||
}
|
||||
|
||||
/** Create all buffers that will be used. */
|
||||
@@ -459,7 +467,7 @@ public class LodRenderer
|
||||
//GLProxy.getInstance().setGlContext(GLProxyContext.LOD_BUILDER);
|
||||
|
||||
shaderProgram.free();
|
||||
lightmapTexture.free();
|
||||
//lightmapTexture.free();
|
||||
//GLProxy.getInstance().setGlContext(GLProxyContext.NONE);
|
||||
ClientApi.LOGGER.info("Renderer Cleanup Complete");
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ package com.seibel.lod.core.render.objects;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import com.seibel.lod.core.util.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftWrapper;
|
||||
|
||||
public class LightmapTexture {
|
||||
private static final IMinecraftWrapper MC = SingletonHandler.get(IMinecraftWrapper.class);
|
||||
public final int id;
|
||||
|
||||
public LightmapTexture() {
|
||||
id = GL30.glGenTextures();
|
||||
bind();
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_BORDER);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_BORDER);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_NEAREST);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_NEAREST);
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
@@ -25,30 +25,37 @@ public class LightmapTexture {
|
||||
public void free() {
|
||||
GL20.glDeleteTextures(id);
|
||||
}
|
||||
|
||||
// private int[] testArray;
|
||||
|
||||
public void fillData(int lightMapWidth, int lightMapHeight, int[] pixels) {
|
||||
if (pixels.length != lightMapWidth*lightMapHeight)
|
||||
throw new RuntimeException("Lightmap Width*Height not equal to pixels provided!");
|
||||
|
||||
// comment me out to see when the lightmap is changing
|
||||
// boolean same = true;
|
||||
// int badIndex = 0;
|
||||
// if (testArray != null && pixels != null)
|
||||
// for (int i = 0; i < pixels.length; i++)
|
||||
// {
|
||||
// if(pixels[i] != testArray[i])
|
||||
// {
|
||||
// same = false;
|
||||
// badIndex = i;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// testArray = pixels;
|
||||
// MC.sendChatMessage(same + " " + badIndex);
|
||||
|
||||
/*
|
||||
boolean same = true;
|
||||
int badIndex = 0;
|
||||
if (testArray != null && pixels != null)
|
||||
for (int i = 0; i < pixels.length; i++)
|
||||
{
|
||||
if(pixels[i] != testArray[i])
|
||||
{
|
||||
same = false;
|
||||
badIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
testArray = pixels;
|
||||
MC.sendChatMessage(same + " " + badIndex);
|
||||
*/
|
||||
// comment this line out to prevent uploading the new lightmap
|
||||
GL20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, lightMapWidth,
|
||||
lightMapHeight, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S, GL20.GL_CLAMP_TO_BORDER);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T, GL20.GL_CLAMP_TO_BORDER);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_NEAREST);
|
||||
GL20.glTexParameteri(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_NEAREST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user