Initial work to update to 1.16.4
This commit is contained in:
@@ -13,7 +13,6 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.Project;
|
||||
|
||||
import com.backsun.lod.objects.LodChunk;
|
||||
import com.backsun.lod.objects.LodDimension;
|
||||
@@ -23,15 +22,19 @@ import com.backsun.lod.util.enums.ColorDirection;
|
||||
import com.backsun.lod.util.enums.FogDistance;
|
||||
import com.backsun.lod.util.enums.FogQuality;
|
||||
import com.backsun.lod.util.enums.LodLocation;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.profiler.IProfiler;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
@@ -44,6 +47,8 @@ public class LodRenderer
|
||||
public boolean debugging = false;
|
||||
|
||||
private Minecraft mc;
|
||||
private GameRenderer gameRender;
|
||||
private IProfiler profiler;
|
||||
private float farPlaneDistance;
|
||||
// make sure this is an even number, or else it won't align with the chunk grid
|
||||
/** this is the total width of the LODs (I.E the diameter, not the radius) */
|
||||
@@ -66,10 +71,10 @@ public class LodRenderer
|
||||
|
||||
private int maxNumbThreads = Runtime.getRuntime().availableProcessors();
|
||||
/** How many threads should be used for building the render buffer. */
|
||||
private int numbBufferThreads = maxNumbThreads;
|
||||
private int numbBufferThreads = 1;
|
||||
private ArrayList<BuildBufferThread> bufferThreads = new ArrayList<BuildBufferThread>();
|
||||
private volatile ByteBuffer[] nearBuffers = new ByteBuffer[maxNumbThreads];
|
||||
private volatile ByteBuffer[] farBuffers = new ByteBuffer[maxNumbThreads];
|
||||
private volatile BufferBuilder[] nearBuffers = new BufferBuilder[maxNumbThreads];
|
||||
private volatile BufferBuilder[] farBuffers = new BufferBuilder[maxNumbThreads];
|
||||
private ExecutorService bufferThreadPool = Executors.newFixedThreadPool(maxNumbThreads);
|
||||
/*
|
||||
* this is the maximum number of bytes a buffer
|
||||
@@ -90,12 +95,14 @@ public class LodRenderer
|
||||
/** if this is true the LODs should be regenerated */
|
||||
private boolean regen = false;
|
||||
|
||||
private volatile boolean regenerating = false;
|
||||
|
||||
|
||||
|
||||
public LodRenderer()
|
||||
{
|
||||
mc = Minecraft.getMinecraft();
|
||||
mc = Minecraft.getInstance();
|
||||
gameRender = mc.gameRenderer;
|
||||
|
||||
// for some reason "Tessellator.getInstance()" won't work here, we have to create a new one
|
||||
tessellator = new Tessellator(2097152);
|
||||
@@ -104,36 +111,24 @@ public class LodRenderer
|
||||
reflectionHandler = new ReflectionHandler();
|
||||
}
|
||||
|
||||
private ExecutorService genThread = Executors.newSingleThreadExecutor();
|
||||
private ExecutorService loadQueueThread = Executors.newSingleThreadExecutor();
|
||||
|
||||
|
||||
public void drawLODs(LodDimension newDimension, float partialTicks)
|
||||
public void drawLODs(LodDimension newDimension, float partialTicks, IProfiler newProfiler)
|
||||
{
|
||||
if (reflectionHandler.fovMethod == null)
|
||||
{
|
||||
// don't continue if we can't get the
|
||||
// user's FOV
|
||||
return;
|
||||
}
|
||||
|
||||
if (reflectionHandler.fovMethod == null)
|
||||
{
|
||||
// we aren't able to get the user's
|
||||
// FOV, don't render anything
|
||||
return;
|
||||
}
|
||||
|
||||
// should the LODs be regenerated?
|
||||
if ((int)Minecraft.getMinecraft().player.posX / LodChunk.WIDTH != prevChunkX ||
|
||||
(int)Minecraft.getMinecraft().player.posZ / LodChunk.WIDTH != prevChunkZ ||
|
||||
if ((int)mc.player.getPosX() / LodChunk.WIDTH != prevChunkX ||
|
||||
(int)mc.player.getPosZ() / LodChunk.WIDTH != prevChunkZ ||
|
||||
previousChunkRenderDistance != mc.gameSettings.renderDistanceChunks ||
|
||||
prevFogDistance != LodConfig.fogDistance ||
|
||||
prevFogDistance != LodConfig.COMMON.fogDistance.get() ||
|
||||
lodDimension != newDimension)
|
||||
{
|
||||
regen = true;
|
||||
|
||||
prevChunkX = (int)Minecraft.getMinecraft().player.posX / LodChunk.WIDTH;
|
||||
prevChunkZ = (int)Minecraft.getMinecraft().player.posZ / LodChunk.WIDTH;
|
||||
prevFogDistance = LodConfig.fogDistance;
|
||||
prevChunkX = (int)mc.player.getPosX() / LodChunk.WIDTH;
|
||||
prevChunkZ = (int)mc.player.getPosZ() / LodChunk.WIDTH;
|
||||
prevFogDistance = LodConfig.COMMON.fogDistance.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -143,6 +138,7 @@ public class LodRenderer
|
||||
regen = false;
|
||||
}
|
||||
|
||||
profiler = newProfiler;
|
||||
lodDimension = newDimension;
|
||||
if (lodDimension == null)
|
||||
{
|
||||
@@ -157,20 +153,19 @@ public class LodRenderer
|
||||
|
||||
|
||||
// used for debugging and viewing how long different processes take
|
||||
mc.mcProfiler.endSection();
|
||||
mc.mcProfiler.startSection("LOD");
|
||||
mc.mcProfiler.startSection("LOD setup");
|
||||
profiler.startSection("LOD_setup");
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
long startTime = System.nanoTime();
|
||||
if (LodConfig.drawCheckerBoard)
|
||||
if (LodConfig.COMMON.drawCheckerBoard.get())
|
||||
{
|
||||
if (debugging != LodConfig.drawCheckerBoard)
|
||||
if (debugging != LodConfig.COMMON.drawCheckerBoard.get())
|
||||
regen = true;
|
||||
debugging = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (debugging != LodConfig.drawCheckerBoard)
|
||||
if (debugging != LodConfig.COMMON.drawCheckerBoard.get())
|
||||
regen = true;
|
||||
debugging = false;
|
||||
}
|
||||
@@ -190,10 +185,11 @@ public class LodRenderer
|
||||
|
||||
|
||||
// get the camera location
|
||||
Entity player = mc.player;
|
||||
double cameraX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
||||
double cameraY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
||||
double cameraZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
||||
ActiveRenderInfo renderInfo = mc.gameRenderer.getActiveRenderInfo();
|
||||
Vector3d projectedView = renderInfo.getProjectedView();
|
||||
double cameraX = projectedView.x;
|
||||
double cameraY = projectedView.y;
|
||||
double cameraZ = projectedView.z;
|
||||
|
||||
|
||||
|
||||
@@ -224,113 +220,147 @@ public class LodRenderer
|
||||
|
||||
|
||||
|
||||
|
||||
//=================//
|
||||
// create the LODs //
|
||||
//=================//
|
||||
|
||||
|
||||
profiler.endStartSection("LOD_generation");
|
||||
|
||||
if (regen)
|
||||
{
|
||||
mc.mcProfiler.endStartSection("LOD generation");
|
||||
|
||||
// x axis
|
||||
for (int i = 0; i < numbChunksWide; i++)
|
||||
Thread t = new Thread(()->
|
||||
{
|
||||
// z axis
|
||||
for (int j = 0; j < numbChunksWide; j++)
|
||||
int numbChunksGen = 0;
|
||||
int maxChunkGen = 640;
|
||||
|
||||
// x axis
|
||||
for (int i = 0; i < numbChunksWide; i++)
|
||||
{
|
||||
// skip the middle
|
||||
// (As the player moves some chunks will overlap or be missing,
|
||||
// this is just how chunk loading/unloading works. This can hopefully
|
||||
// be hidden with careful use of fog)
|
||||
int middle = (numbChunksWide / 2);
|
||||
if (RenderUtil.isCoordinateInLoadedArea(i, j, middle))
|
||||
// z axis
|
||||
for (int j = 0; j < numbChunksWide; j++)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// set where this square will be drawn in the world
|
||||
double xOffset = (LodChunk.WIDTH * i) + // offset by the number of LOD blocks
|
||||
startX; // offset so the center LOD block is centered underneath the player
|
||||
double yOffset = 0;
|
||||
double zOffset = (LodChunk.WIDTH * j) + startZ;
|
||||
|
||||
int chunkX = i + (startX / LodChunk.WIDTH);
|
||||
int chunkZ = j + (startZ / LodChunk.WIDTH);
|
||||
|
||||
LodChunk lod = lodDimension.getLodFromCoordinates(chunkX, chunkZ); // new LodChunk(); //
|
||||
if (lod == null)
|
||||
{
|
||||
// note: for some reason if any color or lod object are set here
|
||||
// it causes the game to use 100% gpu, all of it undefined in the debug menu
|
||||
// and drop to ~6 fps.
|
||||
// colorArray[i][j] = null;
|
||||
// lodArray[i][j] = null;
|
||||
// skip the middle
|
||||
// (As the player moves some chunks will overlap or be missing,
|
||||
// this is just how chunk loading/unloading works. This can hopefully
|
||||
// be hidden with careful use of fog)
|
||||
int middle = (numbChunksWide / 2);
|
||||
if (RenderUtil.isCoordinateInLoadedArea(i, j, middle))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Color c = new Color(
|
||||
(lod.colors[ColorDirection.TOP.value].getRed()),
|
||||
(lod.colors[ColorDirection.TOP.value].getGreen()),
|
||||
(lod.colors[ColorDirection.TOP.value].getBlue()),
|
||||
lod.colors[ColorDirection.TOP.value].getAlpha());
|
||||
|
||||
|
||||
|
||||
if (!debugging)
|
||||
{
|
||||
// add the color to the array
|
||||
colorArray[i][j] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if debugging draw the squares as a black and white checker board
|
||||
if ((chunkX + chunkZ) % 2 == 0)
|
||||
c = white;
|
||||
|
||||
// set where this square will be drawn in the world
|
||||
double xOffset = (LodChunk.WIDTH * i) + // offset by the number of LOD blocks
|
||||
startX; // offset so the center LOD block is centered underneath the player
|
||||
double yOffset = 0;
|
||||
double zOffset = (LodChunk.WIDTH * j) + startZ;
|
||||
|
||||
int chunkX = i + (startX / LodChunk.WIDTH);
|
||||
int chunkZ = j + (startZ / LodChunk.WIDTH);
|
||||
|
||||
LodChunk lod = lodDimension.getLodFromCoordinates(chunkX, chunkZ);
|
||||
if (lod == null)
|
||||
{
|
||||
// note: for some reason if any color or lod object are set here
|
||||
// it causes the game to use 100% gpu, all of it undefined in the debug menu
|
||||
// and drop to ~6 fps.
|
||||
// colorArray[i][j] = null;
|
||||
// lodArray[i][j] = null;
|
||||
|
||||
// TODO this partially works, but not fully
|
||||
if (numbChunksGen < maxChunkGen)
|
||||
{
|
||||
// if (lod == null)
|
||||
// {
|
||||
// LodChunk placeholder = new LodChunk();
|
||||
// placeholder.x = chunkX;
|
||||
// placeholder.z = chunkZ;
|
||||
// placeholder.colors[ColorDirection.TOP.value] = error;
|
||||
// lodDimension.addLod(placeholder);
|
||||
// }
|
||||
|
||||
// Thread loadT = new Thread(()-> {
|
||||
Chunk newChunk = mc.world.getChunk(chunkX, chunkZ);
|
||||
lodDimension.addLod(new LodChunk(newChunk, newChunk.getWorld()));
|
||||
System.out.println(chunkX + "," + chunkZ + "\t" + numbChunksGen);
|
||||
// });
|
||||
// loadQueueThread.execute(loadT);
|
||||
numbChunksGen++;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Color c = new Color(
|
||||
(lod.colors[ColorDirection.TOP.value].getRed()),
|
||||
(lod.colors[ColorDirection.TOP.value].getGreen()),
|
||||
(lod.colors[ColorDirection.TOP.value].getBlue()),
|
||||
lod.colors[ColorDirection.TOP.value].getAlpha());
|
||||
|
||||
|
||||
|
||||
if (!debugging)
|
||||
{
|
||||
// add the color to the array
|
||||
colorArray[i][j] = c;
|
||||
}
|
||||
else
|
||||
c = black;
|
||||
// draw the first square as red
|
||||
if (i == 0 && j == 0)
|
||||
c = red;
|
||||
{
|
||||
// if debugging draw the squares as a black and white checker board
|
||||
if ((chunkX + chunkZ) % 2 == 0)
|
||||
c = white;
|
||||
else
|
||||
c = black;
|
||||
// draw the first square as red
|
||||
if (i == 0 && j == 0)
|
||||
c = red;
|
||||
|
||||
colorArray[i][j] = c;
|
||||
}
|
||||
|
||||
colorArray[i][j] = c;
|
||||
|
||||
// add the new box to the array
|
||||
int topPoint = getLodHeightPoint(lod.top);
|
||||
int bottomPoint = getLodHeightPoint(lod.bottom);
|
||||
|
||||
// don't draw an LOD if it is empty
|
||||
if (topPoint == -1 && bottomPoint == -1)
|
||||
continue;
|
||||
|
||||
lodArray[i][j] = new AxisAlignedBB(0, bottomPoint, 0, LodChunk.WIDTH, topPoint, LodChunk.WIDTH).offset(xOffset, yOffset, zOffset);
|
||||
}
|
||||
|
||||
|
||||
// add the new box to the array
|
||||
int topPoint = getLodHeightPoint(lod.top);
|
||||
int bottomPoint = getLodHeightPoint(lod.bottom);
|
||||
|
||||
// don't draw an LOD if it is empty
|
||||
if (topPoint == -1 && bottomPoint == -1)
|
||||
continue;
|
||||
|
||||
lodArray[i][j] = new AxisAlignedBB(0, bottomPoint, 0, LodChunk.WIDTH, topPoint, LodChunk.WIDTH).offset(xOffset, yOffset, zOffset);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.run();
|
||||
// genThread.execute(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//===========================//
|
||||
// GL settings for rendering //
|
||||
//===========================//
|
||||
|
||||
profiler.endStartSection("LOD_setup");
|
||||
// set the required open GL settings
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glLineWidth(2.0f);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
|
||||
GlStateManager.translate(-cameraX, -cameraY, -cameraZ);
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.rotatef(renderInfo.getPitch(), 1, 0, 0); // Fixes camera rotation.
|
||||
RenderSystem.rotatef(renderInfo.getYaw() + 180, 0, 1, 0); // Fixes camera rotation.
|
||||
RenderSystem.translated(-cameraX, -cameraY, -cameraZ);
|
||||
|
||||
setProjectionMatrix(partialTicks);
|
||||
setupLighting(partialTicks);
|
||||
// setupProjectionMatrix(partialTicks);
|
||||
// setupLighting(partialTicks);
|
||||
setupBufferThreads(lodArray);
|
||||
|
||||
|
||||
@@ -338,32 +368,41 @@ public class LodRenderer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD build buffer");
|
||||
profiler.endStartSection("LOD build buffer");
|
||||
if (regen)
|
||||
generateLodBuffers(lodArray, colorArray, LodConfig.fogDistance);
|
||||
generateLodBuffers(lodArray, colorArray, LodConfig.COMMON.fogDistance.get());
|
||||
|
||||
switch(LodConfig.fogDistance)
|
||||
profiler.endStartSection("LOD draw");
|
||||
|
||||
switch(LodConfig.COMMON.fogDistance.get())
|
||||
{
|
||||
case NEAR_AND_FAR:
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
profiler.startSection("LOD draw near");
|
||||
setupFog(FogDistance.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
profiler.endSection();
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
// profiler.startSection("LOD draw far");
|
||||
// setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
// sendLodsToGpuAndDraw(farBuffers);
|
||||
// profiler.endSection();
|
||||
break;
|
||||
case NEAR:
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
profiler.endStartSection("LOD draw near");
|
||||
setupFog(FogDistance.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
break;
|
||||
case FAR:
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
profiler.endStartSection("LOD draw far");
|
||||
setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
break;
|
||||
@@ -372,50 +411,57 @@ public class LodRenderer
|
||||
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// cleanup //
|
||||
//=========//
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD cleanup");
|
||||
profiler.endStartSection("LOD_cleanup");
|
||||
|
||||
|
||||
// this must be done otherwise other parts of the screen may be drawn with a fog effect
|
||||
// IE the GUI
|
||||
GlStateManager.disableFog();
|
||||
RenderSystem.disableFog();
|
||||
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LIGHT1);
|
||||
GL11.glDisable(GL11.GL_LIGHT2);
|
||||
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
|
||||
// undo any projection matrix changes we did to prevent other renders
|
||||
// from being corrupted
|
||||
RenderSystem.popMatrix();
|
||||
|
||||
// change the perspective matrix back to prevent incompatibilities
|
||||
// with other mods that may render during forgeRenderLast
|
||||
Project.gluPerspective(reflectionHandler.getFov(mc, partialTicks, true), (float) this.mc.displayWidth / (float) this.mc.displayHeight, 0.05F, this.farPlaneDistance * MathHelper.SQRT_2);
|
||||
|
||||
// this can't be called until after the buffers are built
|
||||
// because otherwise the buffers may be set to the wrong size
|
||||
previousChunkRenderDistance = mc.gameSettings.renderDistanceChunks;
|
||||
|
||||
|
||||
|
||||
// This is about how long this whole process should take
|
||||
// 16 ms = 60 hz
|
||||
@SuppressWarnings("unused")
|
||||
long endTime = System.nanoTime();
|
||||
|
||||
// end of profiler tracking
|
||||
mc.mcProfiler.endSection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* draw an array of cubes (or squares) with the given colors.
|
||||
* @param lods bounding boxes to draw
|
||||
@@ -431,11 +477,11 @@ public class LodRenderer
|
||||
{
|
||||
if (nearBuffers[i] == null || previousChunkRenderDistance != mc.gameSettings.renderDistanceChunks)
|
||||
{
|
||||
nearBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
nearBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
nearBuffers[i] = new BufferBuilder(bufferMaxCapacity); //ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
// nearBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
farBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
farBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
farBuffers[i] = new BufferBuilder(bufferMaxCapacity); //ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
// farBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
clearBytes = new byte[bufferMaxCapacity];
|
||||
}
|
||||
@@ -446,18 +492,18 @@ public class LodRenderer
|
||||
// overwrite the old data
|
||||
// (which needs to be done otherwise old
|
||||
// LODs may be drawn)
|
||||
nearBuffers[i].clear();
|
||||
nearBuffers[i].put(clearBytes);
|
||||
nearBuffers[i].clear();
|
||||
nearBuffers[i].byteBuffer.clear();
|
||||
nearBuffers[i].byteBuffer.put(clearBytes);
|
||||
nearBuffers[i].byteBuffer.clear();
|
||||
|
||||
farBuffers[i].clear();
|
||||
farBuffers[i].put(clearBytes);
|
||||
farBuffers[i].clear();
|
||||
farBuffers[i].byteBuffer.clear();
|
||||
farBuffers[i].byteBuffer.put(clearBytes);
|
||||
farBuffers[i].byteBuffer.clear();
|
||||
}
|
||||
|
||||
int pos = bufferBuilder.getByteBuffer().position();
|
||||
nearBuffers[i].position(pos);
|
||||
farBuffers[i].position(pos);
|
||||
// int pos = bufferBuilder.byteBuffer.position();
|
||||
// nearBuffers[i].byteBuffer.position(pos);
|
||||
// farBuffers[i].byteBuffer.position(pos);
|
||||
|
||||
bufferThreads.get(i).setNewData(nearBuffers[i], farBuffers[i], fogDistance, lods, colors, i, numbBufferThreads);
|
||||
}
|
||||
@@ -478,6 +524,9 @@ public class LodRenderer
|
||||
{
|
||||
nearBuffers[i] = bufferFutures.get(i).get().nearBuffer;
|
||||
farBuffers[i] = bufferFutures.get(i).get().farBuffer;
|
||||
|
||||
nearBuffers[i].finishDrawing();
|
||||
farBuffers[i].finishDrawing();
|
||||
}
|
||||
catch(CancellationException | ExecutionException| InterruptedException e)
|
||||
{
|
||||
@@ -488,22 +537,23 @@ public class LodRenderer
|
||||
|
||||
}
|
||||
|
||||
private void sendLodsToGpuAndDraw(ByteBuffer[] buffers)
|
||||
private void sendLodsToGpuAndDraw(BufferBuilder[] nearBuffers)
|
||||
{
|
||||
for(int i = 0; i < numbBufferThreads; i++)
|
||||
{
|
||||
int pos = bufferBuilder.getByteBuffer().position();
|
||||
buffers[i].position(pos);
|
||||
profiler.startSection("LOD setup");
|
||||
// int pos = bufferBuilder.byteBuffer.position();
|
||||
// nearBuffers[i].byteBuffer.position(pos);
|
||||
|
||||
bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.getByteBuffer().clear();
|
||||
bufferBuilder.putBulkData(buffers[i]);
|
||||
bufferBuilder.byteBuffer.clear();
|
||||
bufferBuilder.putBulkData(nearBuffers[i].byteBuffer);
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw");
|
||||
profiler.endStartSection("LOD draw");
|
||||
tessellator.draw();
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
|
||||
bufferBuilder.getByteBuffer().clear(); // this is required otherwise nothing is drawn
|
||||
bufferBuilder.byteBuffer.clear(); // this is required otherwise nothing is drawn
|
||||
profiler.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,11 +567,12 @@ public class LodRenderer
|
||||
// Setup Functions //
|
||||
//=================//
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void setupFog(FogDistance fogDistance, FogQuality fogQuality)
|
||||
{
|
||||
if(fogQuality == FogQuality.OFF)
|
||||
{
|
||||
GlStateManager.disableFog();
|
||||
RenderSystem.disableFog();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -542,8 +593,8 @@ public class LodRenderer
|
||||
|
||||
if (fogQuality == FogQuality.FANCY)
|
||||
{
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 0.3f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.35f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
RenderSystem.fogEnd(farPlaneDistance * 0.3f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
RenderSystem.fogStart(farPlaneDistance * 0.35f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
}
|
||||
else if(fogQuality == FogQuality.FAST)
|
||||
{
|
||||
@@ -551,49 +602,55 @@ public class LodRenderer
|
||||
// to start right where the LODs' end use:
|
||||
// end = 0.8f, start = 1.5f
|
||||
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 1.5f);
|
||||
GlStateManager.setFogStart(farPlaneDistance * 2.0f);
|
||||
RenderSystem.fogEnd(farPlaneDistance * 1.5f);
|
||||
RenderSystem.fogStart(farPlaneDistance * 2.0f);
|
||||
}
|
||||
}
|
||||
else if(fogDistance == FogDistance.FAR)
|
||||
{
|
||||
if (fogQuality == FogQuality.FANCY)
|
||||
{
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.78f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 1.0f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
RenderSystem.fogStart(farPlaneDistance * 0.78f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
RenderSystem.fogEnd(farPlaneDistance * 1.0f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
}
|
||||
else if(fogQuality == FogQuality.FAST)
|
||||
{
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.5f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 0.75f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
RenderSystem.fogStart(farPlaneDistance * 0.5f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
RenderSystem.fogEnd(farPlaneDistance * 0.75f * LOD_CHUNK_DISTANCE_RADIUS);
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.setFogDensity(0.1f);
|
||||
GlStateManager.enableFog();
|
||||
RenderSystem.fogDensity(0.1f);
|
||||
RenderSystem.enableFog();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* create a new projection matrix and send it over to the GPU
|
||||
* @param partialTicks how many ticks into the frame we are
|
||||
* @return true if the matrix was successfully created and sent to the GPU, false otherwise
|
||||
*/
|
||||
private void setProjectionMatrix(float partialTicks)
|
||||
private void setupProjectionMatrix(float partialTicks)
|
||||
{
|
||||
// create a new view frustum so that the squares can be drawn outside the normal view distance
|
||||
GlStateManager.matrixMode(GL11.GL_PROJECTION);
|
||||
GlStateManager.loadIdentity();
|
||||
// Project.gluPerspective(getFov(partialTicks, true), (float) mc.currentScreen.width / (float) mc.currentScreen.height, 0.5F, farPlaneDistance * 12);
|
||||
gameRender.resetProjectionMatrix(getCustomProjectionMatrix(partialTicks, false));
|
||||
|
||||
// only continue if we can get the FOV
|
||||
if (reflectionHandler.fovMethod != null)
|
||||
{
|
||||
Project.gluPerspective(reflectionHandler.getFov(mc, partialTicks, true), (float) mc.displayWidth / (float) mc.displayHeight, 0.5F, farPlaneDistance * 12);
|
||||
}
|
||||
|
||||
// we weren't able to set up the projection matrix
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Almost an exact copy of what is in GameRenderer
|
||||
*/
|
||||
public Matrix4f getCustomProjectionMatrix(float partialTicks, boolean useFovSetting)
|
||||
{
|
||||
ActiveRenderInfo activeRenderInfoIn = mc.gameRenderer.getActiveRenderInfo();
|
||||
|
||||
return Matrix4f.perspective(
|
||||
gameRender.getFOVModifier(activeRenderInfoIn, partialTicks, useFovSetting),
|
||||
(float)this.mc.getMainWindow().getFramebufferWidth() / (float)this.mc.getMainWindow().getFramebufferHeight(),
|
||||
0.5F,
|
||||
this.farPlaneDistance * LOD_CHUNK_DISTANCE_RADIUS * 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -604,18 +661,18 @@ public class LodRenderer
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL); // set the color to be used as the material (this allows lighting to be enabled)
|
||||
|
||||
// this isn't perfect right now, but it looks pretty good at 50% brightness
|
||||
float sunBrightness = mc.world.getSunBrightness(partialTicks) * mc.world.provider.getSunBrightnessFactor(partialTicks);
|
||||
float skyHasLight = mc.world.provider.hasSkyLight()? 1.0f : 0.15f;
|
||||
float gammaMultiplyer = (mc.gameSettings.gammaSetting * 0.5f + 0.5f);
|
||||
float sunBrightness = mc.world.getSunBrightness(partialTicks);
|
||||
float skyHasLight = 1.0f; //mc.world.provider.hasSkyLight()? 1.0f : 0.15f;
|
||||
float gammaMultiplyer = ((float)mc.gameSettings.gamma * 0.5f + 0.5f);
|
||||
float lightStrength = sunBrightness * skyHasLight * gammaMultiplyer;
|
||||
float lightAmbient[] = {lightStrength, lightStrength, lightStrength, 1.0f};
|
||||
|
||||
ByteBuffer temp = ByteBuffer.allocateDirect(16);
|
||||
temp.order(ByteOrder.nativeOrder());
|
||||
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer) temp.asFloatBuffer().put(lightAmbient).flip());
|
||||
GL11.glEnable(GL11.GL_LIGHT1); // Enable the above lighting
|
||||
GL11.glLightfv(GL11.GL_LIGHT2, GL11.GL_AMBIENT, (FloatBuffer) temp.asFloatBuffer().put(lightAmbient).flip());
|
||||
GL11.glEnable(GL11.GL_LIGHT2); // Enable the above lighting
|
||||
|
||||
GlStateManager.enableLighting();
|
||||
RenderSystem.enableLighting();
|
||||
}
|
||||
|
||||
|
||||
@@ -633,11 +690,11 @@ public class LodRenderer
|
||||
|
||||
for(int i = 0; i < maxNumbThreads; i++)
|
||||
{
|
||||
nearBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
nearBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
nearBuffers[i] = new BufferBuilder(bufferMaxCapacity); //ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
// nearBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
farBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
farBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
farBuffers[i] = new BufferBuilder(bufferMaxCapacity); //ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
// farBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -646,6 +703,7 @@ public class LodRenderer
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns -1 if there are no valid points
|
||||
*/
|
||||
@@ -661,6 +719,10 @@ public class LodRenderer
|
||||
}
|
||||
|
||||
|
||||
public double getFov(float partialTicks, boolean useFovSetting)
|
||||
{
|
||||
return mc.gameRenderer.getFOVModifier(mc.gameRenderer.getActiveRenderInfo(), partialTicks, useFovSetting);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user