aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/lodmod/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/makamys/lodmod/renderer')
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODChunk.java13
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java27
-rw-r--r--src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java55
3 files changed, 60 insertions, 35 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODChunk.java b/src/main/java/makamys/lodmod/renderer/LODChunk.java
index ae86103..0688d22 100644
--- a/src/main/java/makamys/lodmod/renderer/LODChunk.java
+++ b/src/main/java/makamys/lodmod/renderer/LODChunk.java
@@ -17,7 +17,7 @@ public class LODChunk {
int lod = 0;
boolean visible;
- SimpleChunkMesh simpleMesh;
+ SimpleChunkMesh[] simpleMeshes = new SimpleChunkMesh[2];
ChunkMesh[] chunkMeshes = new ChunkMesh[32];
LODRenderer renderer = LODMod.renderer;
@@ -66,11 +66,14 @@ public class LODChunk {
}
}
- public void putSimpleMesh(SimpleChunkMesh mesh) {
- if(simpleMesh != null) {
- renderer.setMeshVisible(simpleMesh, false);
+ public void putSimpleMeshes(List<SimpleChunkMesh> meshes) {
+ for(SimpleChunkMesh sm : simpleMeshes) {
+ if(sm!= null) {
+ renderer.setMeshVisible(sm, false);
+ }
}
- simpleMesh = mesh;
+
+ simpleMeshes = meshes.toArray(new SimpleChunkMesh[0]);
}
public boolean hasChunkMeshes() {
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index eb4dc45..8bfe85d 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -387,7 +387,8 @@ public class LODRenderer {
int y = Math.floorDiv(wr.posY, 16);
setMeshVisible(lodChunk.chunkMeshes[y * 2 + 0], false);
setMeshVisible(lodChunk.chunkMeshes[y * 2 + 1], false);
- setMeshVisible(lodChunk.simpleMesh, false);
+ setMeshVisible(lodChunk.simpleMeshes[0], false);
+ setMeshVisible(lodChunk.simpleMeshes[1], false);
}
public void onDontDraw(WorldRenderer wr) {
@@ -469,7 +470,7 @@ public class LODRenderer {
}
private void sendChunkToGPU(LODChunk lodChunk) {
- lodChunk.putSimpleMesh(new SimpleChunkMesh(lodChunk.chunk));
+ lodChunk.putSimpleMeshes(SimpleChunkMesh.generateSimpleMeshes(lodChunk.chunk));
Entity player = (Entity) Minecraft.getMinecraft().getIntegratedServer().getConfigurationManager().playerEntityList.get(0);
@@ -497,16 +498,18 @@ public class LODRenderer {
public void lodChunkChanged(LODChunk lodChunk) {
int newLOD = (!lodChunk.hasChunkMeshes() && lodChunk.lod == 2) ? 1 : lodChunk.lod;
- if(lodChunk.simpleMesh != null) {
- if(lodChunk.visible && newLOD == 1) {
- if(!lodChunk.simpleMesh.visible) {
- setMeshVisible(lodChunk.simpleMesh, true);
- }
- } else {
- if(lodChunk.simpleMesh.visible) {
- setMeshVisible(lodChunk.simpleMesh, false);
- }
- }
+ for(SimpleChunkMesh sm : lodChunk.simpleMeshes) {
+ if(sm != null) {
+ if(lodChunk.visible && newLOD == 1) {
+ if(!sm.visible) {
+ setMeshVisible(sm, true);
+ }
+ } else {
+ if(sm.visible) {
+ setMeshVisible(sm, false);
+ }
+ }
+ }
}
for(ChunkMesh cm : lodChunk.chunkMeshes) {
if(cm != null) {
diff --git a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
index 75b4349..9cdbea8 100644
--- a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
@@ -11,6 +11,7 @@ import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
+import java.util.List;
import org.lwjgl.BufferUtils;
@@ -23,6 +24,7 @@ import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.IIcon;
import net.minecraft.world.chunk.Chunk;
+import scala.actors.threadpool.Arrays;
public class SimpleChunkMesh extends Mesh {
@@ -31,12 +33,11 @@ public class SimpleChunkMesh extends Mesh {
public static int usedRAM;
public static int instances;
- public SimpleChunkMesh(Chunk target) {
+ public static List<SimpleChunkMesh> generateSimpleMeshes(Chunk target){
int divisions = 4;
- quadCount = divisions * divisions * 5;
- buffer = BufferUtils.createByteBuffer(4 * 6 * 7 * quadCount);
- vertices = buffer.asFloatBuffer();
+ SimpleChunkMesh pass1 = new SimpleChunkMesh(divisions * divisions * 25);
+ SimpleChunkMesh pass2 = new SimpleChunkMesh(divisions * divisions * 25);
for(int divX = 0; divX < divisions; divX++) {
for(int divZ = 0; divZ < divisions; divZ++) {
@@ -55,15 +56,12 @@ public class SimpleChunkMesh extends Mesh {
float offZ = target.zPosition * 16 + divZ * size;
if(!foundWater && block.getMaterial() == Material.water) {
- // TODO just add a face here, and keep the seabed
foundWater = true;
int meta = target.getBlockMetadata(xOff, y, zOff);
IIcon waterIcon = block.getIcon(1, meta);
int waterColor = block.colorMultiplier(Minecraft.getMinecraft().theWorld, target.xPosition * 16 + xOff, y, target.zPosition * 16 + zOff);
waterColor |= 0xFF000000;
-
- addCube(offX, offY, offZ, size, size, size*4, waterIcon, waterColor);
- break;
+ pass2.addFaceYPos(offX, offY, offZ, size, size, waterIcon, waterColor);
}
if(block.isBlockNormalCube() && block.isOpaqueCube() && block.renderAsNormalBlock()) {
@@ -72,26 +70,36 @@ public class SimpleChunkMesh extends Mesh {
color = block.colorMultiplier(Minecraft.getMinecraft().theWorld, target.xPosition * 16 + xOff, y, target.zPosition * 16 + zOff);
color = (0xFF << 24) | ((color >> 16 & 0xFF) << 0) | ((color >> 8 & 0xFF) << 8) | ((color >> 0 & 0xFF) << 16);
- addCube(offX, offY, offZ, size, size, offY, icon, color);
+ pass1.addCube(offX, offY, offZ, size, size, offY, icon, color);
break;
}
}
}
}
- vertices.flip();
- usedRAM += buffer.limit();
+ pass1.finish();
+ pass2.finish();
+
+ return Arrays.asList(new SimpleChunkMesh[] {pass1.quadCount != 0 ? pass1 : null, pass2.quadCount != 0 ? pass2 : null});
+ }
+
+ public SimpleChunkMesh(int maxQuads) {
+ buffer = BufferUtils.createByteBuffer(4 * 6 * 7 * maxQuads);
+ vertices = buffer.asFloatBuffer();
+ }
+
+ public void finish() {
+ vertices.flip();
+ buffer.limit(vertices.limit() * 4);
+
+ // may want to shrink the buffers to actual size to not waste memory
+
+ usedRAM += buffer.limit();
instances++;
}
private void addCube(float x, float y, float z, float sizeX, float sizeZ, float sizeY, IIcon icon, int color) {
- addFace(
- x + 0, y + 0, z + 0,
- x + 0, y + 0, z + sizeZ,
- x + sizeX, y + 0, z + sizeZ,
- x + sizeX, y + 0, z + 0,
- icon, color, 240
- );
+ addFaceYPos(x, y, z, sizeX, sizeZ, icon, color);
addFace(
x + 0, y - sizeY, z + 0,
x + 0, y + 0, z + 0,
@@ -122,6 +130,16 @@ public class SimpleChunkMesh extends Mesh {
);
}
+ private void addFaceYPos(float x, float y, float z, float sizeX, float sizeZ, IIcon icon, int color) {
+ addFace(
+ x + 0, y + 0, z + 0,
+ x + 0, y + 0, z + sizeZ,
+ x + sizeX, y + 0, z + sizeZ,
+ x + sizeX, y + 0, z + 0,
+ icon, color, 240
+ );
+ }
+
private void addFace(float p1x, float p1y, float p1z,
float p2x, float p2y, float p2z,
float p3x, float p3y, float p3z,
@@ -149,6 +167,7 @@ public class SimpleChunkMesh extends Mesh {
buffer.putInt(off + 5 * getStride() + 6 * 4, color);
buffer.putShort(off + 5 * getStride() + 5 * 4 + 2, (short)brightness);
+ quadCount++;
}
public int getStride() {