aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/makamys/neodymium/Compat.java10
-rw-r--r--src/main/java/makamys/neodymium/renderer/ChunkMesh.java5
-rw-r--r--src/main/java/makamys/neodymium/renderer/MeshQuad.java41
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java33
4 files changed, 72 insertions, 17 deletions
diff --git a/src/main/java/makamys/neodymium/Compat.java b/src/main/java/makamys/neodymium/Compat.java
index 2d39d2f..8af4319 100644
--- a/src/main/java/makamys/neodymium/Compat.java
+++ b/src/main/java/makamys/neodymium/Compat.java
@@ -25,6 +25,8 @@ public class Compat {
private static boolean wasAdvancedOpenGLEnabled;
private static int notEnoughVRAMAmountMB = -1;
+
+ private static boolean RPLE;
public static void init() {
isGL33Supported = GLContext.getCapabilities().OpenGL33;
@@ -32,6 +34,14 @@ public class Compat {
if (Loader.isModLoaded("triangulator")) {
disableTriangulator();
}
+
+ if (Loader.isModLoaded("rple")) {
+ RPLE = true;
+ }
+ }
+
+ public static boolean RPLE() {
+ return RPLE;
}
private static void disableTriangulator() {
diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java
index 663cce5..5bd38f6 100644
--- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java
+++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java
@@ -11,6 +11,7 @@ import java.util.Comparator;
import java.util.List;
import lombok.val;
+import makamys.neodymium.Compat;
import makamys.neodymium.Neodymium;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
@@ -108,10 +109,12 @@ public class ChunkMesh extends Mesh {
FLAGS.hasColor = t.hasColor;
int verticesPerPrimitive = t.drawMode == GL11.GL_QUADS ? 4 : 3;
+
+ int tessellatorVertexSize = Compat.RPLE() ? 12 : 8;
for(int quadI = 0; quadI < t.vertexCount / verticesPerPrimitive; quadI++) {
MeshQuad quad = quadBuf.next();
- quad.setState(t.rawBuffer, quadI * (verticesPerPrimitive * 8), FLAGS, t.drawMode, (float)-t.xOffset, (float)-t.yOffset, (float)-t.zOffset);
+ quad.setState(t.rawBuffer, tessellatorVertexSize, quadI * (verticesPerPrimitive * tessellatorVertexSize), FLAGS, t.drawMode, (float)-t.xOffset, (float)-t.yOffset, (float)-t.zOffset);
if(quad.deleted) {
quadBuf.remove();
}
diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java
index 98fef18..484ab8b 100644
--- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java
+++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java
@@ -6,6 +6,7 @@ import java.util.Comparator;
import java.util.Locale;
import makamys.neodymium.Neodymium;
+import makamys.neodymium.Compat;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
@@ -26,6 +27,10 @@ public class MeshQuad {
// TODO normals?
public int[] bs = new int[4];
+ //RPLE compat. bs reused as RED
+ public int[] bsG = new int[4];
+ public int[] bsB = new int[4];
+
public boolean deleted;
public QuadNormal normal;
@@ -34,10 +39,10 @@ public class MeshQuad {
private static Vector3f vectorB = new Vector3f();
private static Vector3f vectorC = new Vector3f();
- private void read(int[] rawBuffer, int offset, float offsetX, float offsetY, float offsetZ, int drawMode, ChunkMesh.Flags flags) {
+ private void read(int[] rawBuffer, int tessellatorVertexSize, int offset, float offsetX, float offsetY, float offsetZ, int drawMode, ChunkMesh.Flags flags) {
int vertices = drawMode == GL11.GL_TRIANGLES ? 3 : 4;
for(int vi = 0; vi < vertices; vi++) {
- int i = offset + vi * 8;
+ int i = offset + vi * tessellatorVertexSize;
xs[vi] = Float.intBitsToFloat(rawBuffer[i + 0]) + offsetX;
ys[vi] = Float.intBitsToFloat(rawBuffer[i + 1]) + offsetY;
@@ -52,7 +57,15 @@ public class MeshQuad {
bs[vi] = flags.hasBrightness ? rawBuffer[i + 7] : DEFAULT_BRIGHTNESS;
- i += 8;
+ if (Compat.RPLE()) {
+ if (flags.hasBrightness) {
+ bsG[vi] = rawBuffer[i + 8];
+ bsB[vi] = rawBuffer[i + 9];
+ } else {
+ bsG[vi] = DEFAULT_BRIGHTNESS;
+ bsB[vi] = DEFAULT_BRIGHTNESS;
+ }
+ }
}
if(vertices == 3) {
@@ -65,14 +78,18 @@ public class MeshQuad {
vs[3] = vs[2];
bs[3] = bs[2];
+ if (Compat.RPLE()) {
+ bsG[3] = bsG[2];
+ bsB[3] = bsB[2];
+ }
cs[3] = cs[2];
}
}
- public void setState(int[] rawBuffer, int offset, ChunkMesh.Flags flags, int drawMode, float offsetX, float offsetY, float offsetZ) {
+ public void setState(int[] rawBuffer, int tessellatorVertexSize, int offset, ChunkMesh.Flags flags, int drawMode, float offsetX, float offsetY, float offsetZ) {
deleted = false;
- read(rawBuffer, offset, offsetX, offsetY, offsetZ, drawMode, flags);
+ read(rawBuffer, tessellatorVertexSize, offset, offsetX, offsetY, offsetZ, drawMode, flags);
if(xs[0] == xs[1] && xs[1] == xs[2] && xs[2] == xs[3] && ys[0] == ys[1] && ys[1] == ys[2] && ys[2] == ys[3]) {
// ignore empty quads (e.g. alpha pass of EnderIO item conduits)
@@ -91,9 +108,7 @@ public class MeshQuad {
* @implSpec This needs to be kept in sync with the attributes in {@link NeoRenderer#init()}
*/
public void writeToBuffer(BufferWriter out, int expectedStride) throws IOException {
- for(int vertexI = 0; vertexI < 4; vertexI++) {
- int vi = vertexI;
-
+ for(int vi = 0; vi < 4; vi++) {
float x = xs[vi];
float y = ys[vi];
float z = zs[vi];
@@ -112,10 +127,12 @@ public class MeshQuad {
out.writeFloat(u);
out.writeFloat(v);
}
-
- int b = bs[vi];
-
- out.writeInt(b);
+
+ out.writeInt(bs[vi]);
+ if (Compat.RPLE()) {
+ out.writeInt(bsG[vi]);
+ out.writeInt(bsB[vi]);
+ }
int c = cs[vi];
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index 048fc7a..613871a 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import makamys.neodymium.Compat;
import makamys.neodymium.renderer.attribs.AttributeSet;
import makamys.neodymium.util.BufferWriter;
import org.lwjgl.BufferUtils;
@@ -349,7 +350,14 @@ public class NeoRenderer {
int u_modelView = glGetUniformLocation(shaderProgram, "modelView");
int u_proj = glGetUniformLocation(shaderProgram, "proj");
int u_playerPos = glGetUniformLocation(shaderProgram, "playerPos");
- int u_light = glGetUniformLocation(shaderProgram, "lightTex");
+ int u_light = 0, u_light_r = 0, u_light_g = 0, u_light_b = 0;
+ if (Compat.RPLE()) {
+ u_light_r = glGetUniformLocation(shaderProgram, "lightTexR");
+ u_light_g = glGetUniformLocation(shaderProgram, "lightTexG");
+ u_light_b = glGetUniformLocation(shaderProgram, "lightTexB");
+ } else {
+ u_light = glGetUniformLocation(shaderProgram, "lightTex");
+ }
int u_viewport = glGetUniformLocation(shaderProgram, "viewport");
int u_projInv = glGetUniformLocation(shaderProgram, "projInv");
int u_fogColor = glGetUniformLocation(shaderProgram, "fogColor");
@@ -367,8 +375,16 @@ public class NeoRenderer {
glUniform1f(u_fogDensity, glGetFloat(GL_FOG_DENSITY));
glUniform3f(u_playerPos, (float)eyePosX, (float)eyePosY, (float)eyePosZ);
-
- glUniform1i(u_light, 1);
+
+ if (Compat.RPLE()) {
+ //TODO connect to RPLE gl api (once that exists)
+ // For now we just use the RPLE default texture indices
+ glUniform1i(u_light_r, 1);
+ glUniform1i(u_light_g, 2);
+ glUniform1i(u_light_b, 3);
+ } else {
+ glUniform1i(u_light, 1);
+ }
modelView.position(0);
projBuf.position(0);
@@ -395,7 +411,13 @@ public class NeoRenderer {
} else {
attributes.addAttribute("TEXTURE", 2, 4, GL_FLOAT);
}
- attributes.addAttribute("BRIGHTNESS", 2, 2, GL_SHORT);
+ if (Compat.RPLE()) {
+ attributes.addAttribute("BRIGHTNESS_RED", 2, 2, GL_SHORT);
+ attributes.addAttribute("BRIGHTNESS_GREEN", 2, 2, GL_SHORT);
+ attributes.addAttribute("BRIGHTNESS_BLUE", 2, 2, GL_SHORT);
+ } else {
+ attributes.addAttribute("BRIGHTNESS", 2, 2, GL_SHORT);
+ }
attributes.addAttribute("COLOR", 4, 1, GL_UNSIGNED_BYTE);
reloadShader();
@@ -435,6 +457,9 @@ public class NeoRenderer {
if(Config.shortUV) {
defines.put("SHORT_UV", "");
}
+ if (Compat.RPLE()) {
+ defines.put("RPLE", "");
+ }
if(pass == 0) {
defines.put("PASS_0", "");
}