we do a little bit of merging

This commit is contained in:
UnknownUser1789 2023-01-19 02:49:21 +00:00
parent 190e053b80
commit be7ad251dd
3 changed files with 28029 additions and 27991 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,5 @@
package net.lax1dude.eaglercraft.v1_8.opengl; package net.lax1dude.eaglercraft.v1_8.opengl;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer; import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger; import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
@ -10,6 +7,9 @@ import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f; import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f; import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
/** /**
* Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved. * Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved.
* *
@ -94,7 +94,10 @@ public class GlStateManager {
static int activeTexture = 0; static int activeTexture = 0;
static final boolean[] stateTexture = new boolean[16]; static final boolean[] stateTexture = new boolean[16];
static final int[] boundTexture = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static final int[] boundTexture = new int[] {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1
};
static float stateAnisotropicFixW = -999.0f; static float stateAnisotropicFixW = -999.0f;
static float stateAnisotropicFixH = -999.0f; static float stateAnisotropicFixH = -999.0f;
@ -117,14 +120,12 @@ public class GlStateManager {
static float clearDepth = -999.0f; static float clearDepth = -999.0f;
public static enum TexGen { public static enum TexGen {
S, S, T, R, Q;
T,
R,
Q;
int source = GL_OBJECT_LINEAR; int source = GL_OBJECT_LINEAR;
int plane = GL_OBJECT_PLANE; int plane = GL_OBJECT_PLANE;
Vector4f vector = new Vector4f(); Vector4f vector = new Vector4f();
} }
static int stateTexGenSerial = 0; static int stateTexGenSerial = 0;
@ -160,20 +161,20 @@ public class GlStateManager {
} }
static void populateStack(Matrix4f[] stack) { static void populateStack(Matrix4f[] stack) {
for (int i = 0; i < stack.length; ++i) { for(int i = 0; i < stack.length; ++i) {
stack[i] = new Matrix4f(); stack[i] = new Matrix4f();
} }
} }
static void populateStack(Matrix4f[][] stack) { static void populateStack(Matrix4f[][] stack) {
for (int i = 0; i < stack.length; ++i) { for(int i = 0; i < stack.length; ++i) {
populateStack(stack[i]); populateStack(stack[i]);
} }
} }
static void populateStack(Vector4f[][] stack) { static void populateStack(Vector4f[][] stack) {
for (int i = 0; i < stack.length; ++i) { for(int i = 0; i < stack.length; ++i) {
for (int j = 0; j < stack[i].length; ++j) { for(int j = 0; j < stack[i].length; ++j) {
stack[i][j] = new Vector4f(0.0f, -1.0f, 0.0f, 0.0f); stack[i][j] = new Vector4f(0.0f, -1.0f, 0.0f, 0.0f);
} }
} }
@ -181,32 +182,34 @@ public class GlStateManager {
public static final void pushLightCoords() { public static final void pushLightCoords() {
int push = stateLightsStackPointer + 1; int push = stateLightsStackPointer + 1;
if (push < stateLightsStack.length) { if(push < stateLightsStack.length) {
Vector4f[] copyFrom = stateLightsStack[stateLightsStackPointer]; Vector4f[] copyFrom = stateLightsStack[stateLightsStackPointer];
boolean[] copyFrom2 = stateLightsEnabled[stateLightsStackPointer]; boolean[] copyFrom2 = stateLightsEnabled[stateLightsStackPointer];
Vector4f[] copyTo = stateLightsStack[push]; Vector4f[] copyTo = stateLightsStack[push];
boolean[] copyTo2 = stateLightsEnabled[push]; boolean[] copyTo2 = stateLightsEnabled[push];
for (int i = 0; i < copyFrom.length; ++i) { for(int i = 0; i < copyFrom.length; ++i) {
if (copyFrom2[i]) { if(copyFrom2[i]) {
copyTo[i].set(copyFrom[i]); copyTo[i].set(copyFrom[i]);
copyTo2[i] = true; copyTo2[i] = true;
} else { }else {
copyTo2[i] = false; copyTo2[i] = false;
} }
} }
stateLightingSerial[push] = stateLightingSerial[stateLightsStackPointer]; stateLightingSerial[push] = stateLightingSerial[stateLightsStackPointer];
stateLightsStackPointer = push; stateLightsStackPointer = push;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_LIGHT direction stack overflow!" + " Exceeded " + stateLightsStack.length + " calls to GlStateManager.pushLightCoords"); Throwable t = new IndexOutOfBoundsException("GL_LIGHT direction stack overflow!" +
" Exceeded " + stateLightsStack.length + " calls to GlStateManager.pushLightCoords");
logger.error(t); logger.error(t);
} }
} }
public static final void popLightCoords() { public static final void popLightCoords() {
if (stateLightsStackPointer > 0) { if(stateLightsStackPointer > 0) {
--stateLightsStackPointer; --stateLightsStackPointer;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_LIGHT direction stack underflow!" + " Called GlStateManager.popLightCoords on an empty light stack"); Throwable t = new IndexOutOfBoundsException("GL_LIGHT direction stack underflow!" +
" Called GlStateManager.popLightCoords on an empty light stack");
logger.error(t); logger.error(t);
} }
} }
@ -220,9 +223,9 @@ public class GlStateManager {
} }
public static final void alphaFunc(int func, float ref) { public static final void alphaFunc(int func, float ref) {
if (func != GL_GREATER) { if(func != GL_GREATER) {
throw new UnsupportedOperationException("Only GL_GREATER alphaFunc is supported"); throw new UnsupportedOperationException("Only GL_GREATER alphaFunc is supported");
} else { }else {
stateAlphaTestRef = ref; stateAlphaTestRef = ref;
} }
} }
@ -236,12 +239,12 @@ public class GlStateManager {
} }
private static final Vector4f paramVector4 = new Vector4f(); private static final Vector4f paramVector4 = new Vector4f();
public static final void enableMCLight(int light, float diffuse, double dirX,
public static final void enableMCLight(int light, float diffuse, double dirX, double dirY, double dirZ, double dirW) { double dirY, double dirZ, double dirW) {
paramVector4.x = (float) dirX; paramVector4.x = (float)dirX;
paramVector4.y = (float) dirY; paramVector4.y = (float)dirY;
paramVector4.z = (float) dirZ; paramVector4.z = (float)dirZ;
paramVector4.w = (float) dirW; paramVector4.w = (float)dirW;
Matrix4f.transform(modelMatrixStack[modelMatrixStackPointer], paramVector4, paramVector4); Matrix4f.transform(modelMatrixStack[modelMatrixStackPointer], paramVector4, paramVector4);
paramVector4.normalise(); paramVector4.normalise();
Vector4f dest = stateLightsStack[stateLightsStackPointer][light]; Vector4f dest = stateLightsStack[stateLightsStackPointer][light];
@ -274,14 +277,14 @@ public class GlStateManager {
} }
public static final void disableDepth() { public static final void disableDepth() {
if (stateDepthTest) { if(stateDepthTest) {
_wglDisable(GL_DEPTH_TEST); _wglDisable(GL_DEPTH_TEST);
stateDepthTest = false; stateDepthTest = false;
} }
} }
public static final void enableDepth() { public static final void enableDepth() {
if (!stateDepthTest) { if(!stateDepthTest) {
_wglEnable(GL_DEPTH_TEST); _wglEnable(GL_DEPTH_TEST);
stateDepthTest = true; stateDepthTest = true;
} }
@ -289,7 +292,7 @@ public class GlStateManager {
public static final void depthFunc(int depthFunc) { public static final void depthFunc(int depthFunc) {
int rev = depthFunc; int rev = depthFunc;
switch (depthFunc) { switch(depthFunc) {
case GL_GREATER: case GL_GREATER:
rev = GL_LESS; rev = GL_LESS;
break; break;
@ -306,28 +309,28 @@ public class GlStateManager {
rev = GL_GREATER; rev = GL_GREATER;
break; break;
} }
if (rev != stateDepthFunc) { if(rev != stateDepthFunc) {
_wglDepthFunc(rev); _wglDepthFunc(rev);
stateDepthFunc = rev; stateDepthFunc = rev;
} }
} }
public static final void depthMask(boolean flagIn) { public static final void depthMask(boolean flagIn) {
if (flagIn != stateDepthMask) { if(flagIn != stateDepthMask) {
_wglDepthMask(flagIn); _wglDepthMask(flagIn);
stateDepthMask = flagIn; stateDepthMask = flagIn;
} }
} }
public static final void disableBlend() { public static final void disableBlend() {
if (stateBlend) { if(stateBlend) {
_wglDisable(GL_BLEND); _wglDisable(GL_BLEND);
stateBlend = false; stateBlend = false;
} }
} }
public static final void enableBlend() { public static final void enableBlend() {
if (!stateBlend) { if(!stateBlend) {
_wglEnable(GL_BLEND); _wglEnable(GL_BLEND);
stateBlend = true; stateBlend = true;
} }
@ -348,6 +351,10 @@ public class GlStateManager {
} }
public static final void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) { public static final void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) {
if(stateEnableOverlayFramebufferBlending) { // game overlay framebuffer in EntityRenderer.java
srcFactorAlpha = GL_ONE;
dstFactorAlpha = GL_ONE_MINUS_SRC_ALPHA;
}
int srcBits = (srcFactor | (srcFactorAlpha << 16)); int srcBits = (srcFactor | (srcFactorAlpha << 16));
int dstBits = (dstFactor | (dstFactorAlpha << 16)); int dstBits = (dstFactor | (dstFactorAlpha << 16));
if(srcBits != stateBlendSRC || dstBits != stateBlendDST) { if(srcBits != stateBlendSRC || dstBits != stateBlendDST) {
@ -357,6 +364,14 @@ public class GlStateManager {
} }
} }
public static final void enableOverlayFramebufferBlending() {
stateEnableOverlayFramebufferBlending = true;
}
public static final void disableOverlayFramebufferBlending() {
stateEnableOverlayFramebufferBlending = false;
}
public static final void setShaderBlendSrc(float r, float g, float b, float a) { public static final void setShaderBlendSrc(float r, float g, float b, float a) {
stateShaderBlendSrcColorR = r; stateShaderBlendSrcColorR = r;
stateShaderBlendSrcColorG = g; stateShaderBlendSrcColorG = g;
@ -410,42 +425,42 @@ public class GlStateManager {
} }
public static final void enableCull() { public static final void enableCull() {
if (!stateCull) { if(!stateCull) {
_wglEnable(GL_CULL_FACE); _wglEnable(GL_CULL_FACE);
stateCull = true; stateCull = true;
} }
} }
public static final void disableCull() { public static final void disableCull() {
if (stateCull) { if(stateCull) {
_wglDisable(GL_CULL_FACE); _wglDisable(GL_CULL_FACE);
stateCull = false; stateCull = false;
} }
} }
public static final void cullFace(int mode) { public static final void cullFace(int mode) {
if (stateCullFace != mode) { if(stateCullFace != mode) {
_wglCullFace(mode); _wglCullFace(mode);
stateCullFace = mode; stateCullFace = mode;
} }
} }
public static final void enablePolygonOffset() { public static final void enablePolygonOffset() {
if (!statePolygonOffset) { if(!statePolygonOffset) {
_wglEnable(GL_POLYGON_OFFSET_FILL); _wglEnable(GL_POLYGON_OFFSET_FILL);
statePolygonOffset = true; statePolygonOffset = true;
} }
} }
public static final void disablePolygonOffset() { public static final void disablePolygonOffset() {
if (statePolygonOffset) { if(statePolygonOffset) {
_wglDisable(GL_POLYGON_OFFSET_FILL); _wglDisable(GL_POLYGON_OFFSET_FILL);
statePolygonOffset = false; statePolygonOffset = false;
} }
} }
public static final void doPolygonOffset(float factor, float units) { public static final void doPolygonOffset(float factor, float units) {
if (factor != statePolygonOffsetFactor || units != statePolygonOffsetUnits) { if(factor != statePolygonOffsetFactor || units != statePolygonOffsetUnits) {
_wglPolygonOffset(-factor, units); _wglPolygonOffset(-factor, units);
statePolygonOffsetFactor = factor; statePolygonOffsetFactor = factor;
statePolygonOffsetUnits = units; statePolygonOffsetUnits = units;
@ -456,9 +471,13 @@ public class GlStateManager {
System.err.println("TODO: rewrite text field cursor to use blending"); System.err.println("TODO: rewrite text field cursor to use blending");
} }
public static final void disableColorLogic() {} public static final void disableColorLogic() {
public static final void colorLogicOp(int opcode) {} }
public static final void colorLogicOp(int opcode) {
}
public static final void enableTexGen() { public static final void enableTexGen() {
stateTexGen = true; stateTexGen = true;
@ -476,7 +495,7 @@ public class GlStateManager {
public static final void func_179105_a(GlStateManager.TexGen coord, int plane, FloatBuffer vector) { public static final void func_179105_a(GlStateManager.TexGen coord, int plane, FloatBuffer vector) {
coord.plane = plane; coord.plane = plane;
coord.vector.load(vector); coord.vector.load(vector);
if (plane == GL_EYE_PLANE) { if(plane == GL_EYE_PLANE) {
tmpInvertedMatrix.load(GlStateManager.modelMatrixStack[GlStateManager.modelMatrixStackPointer]).invert().transpose(); tmpInvertedMatrix.load(GlStateManager.modelMatrixStack[GlStateManager.modelMatrixStackPointer]).invert().transpose();
Matrix4f.transform(tmpInvertedMatrix, coord.vector, coord.vector); Matrix4f.transform(tmpInvertedMatrix, coord.vector, coord.vector);
} }
@ -485,7 +504,7 @@ public class GlStateManager {
public static final void setActiveTexture(int texture) { public static final void setActiveTexture(int texture) {
int textureIdx = texture - GL_TEXTURE0; int textureIdx = texture - GL_TEXTURE0;
if (textureIdx != activeTexture) { if(textureIdx != activeTexture) {
_wglActiveTexture(texture); _wglActiveTexture(texture);
activeTexture = textureIdx; activeTexture = textureIdx;
} }
@ -514,7 +533,7 @@ public class GlStateManager {
} }
public static final void bindTexture(int texture) { public static final void bindTexture(int texture) {
if (texture != boundTexture[activeTexture]) { if(texture != boundTexture[activeTexture]) {
_wglBindTexture(GL_TEXTURE_2D, EaglercraftGPU.mapTexturesGL.get(texture)); _wglBindTexture(GL_TEXTURE_2D, EaglercraftGPU.mapTexturesGL.get(texture));
boundTexture[activeTexture] = texture; boundTexture[activeTexture] = texture;
} }
@ -524,16 +543,20 @@ public class GlStateManager {
return boundTexture[activeTexture]; return boundTexture[activeTexture];
} }
public static final void shadeModel(int mode) {} public static final void shadeModel(int mode) {
}
public static final void enableRescaleNormal() { public static final void enableRescaleNormal() {
// still not sure what this is for // still not sure what this is for
} }
public static final void disableRescaleNormal() {} public static final void disableRescaleNormal() {
}
public static final void viewport(int x, int y, int w, int h) { public static final void viewport(int x, int y, int w, int h) {
if (viewportX != x || viewportY != y || viewportW != w || viewportH != h) { if(viewportX != x || viewportY != y || viewportW != w || viewportH != h) {
_wglViewport(x, y, w, h); _wglViewport(x, y, w, h);
viewportX = x; viewportX = x;
viewportY = y; viewportY = y;
@ -544,7 +567,7 @@ public class GlStateManager {
public static final void colorMask(boolean red, boolean green, boolean blue, boolean alpha) { public static final void colorMask(boolean red, boolean green, boolean blue, boolean alpha) {
int bits = (red ? 1 : 0) | (green ? 2 : 0) | (blue ? 4 : 0) | (alpha ? 8 : 0); int bits = (red ? 1 : 0) | (green ? 2 : 0) | (blue ? 4 : 0) | (alpha ? 8 : 0);
if (bits != colorMaskBits) { if(bits != colorMaskBits) {
_wglColorMask(red, green, blue, alpha); _wglColorMask(red, green, blue, alpha);
colorMaskBits = bits; colorMaskBits = bits;
} }
@ -552,14 +575,14 @@ public class GlStateManager {
public static final void clearDepth(float depth) { public static final void clearDepth(float depth) {
depth = 1.0f - depth; depth = 1.0f - depth;
if (depth != clearDepth) { if(depth != clearDepth) {
_wglClearDepth(depth); _wglClearDepth(depth);
clearDepth = depth; clearDepth = depth;
} }
} }
public static final void clearColor(float red, float green, float blue, float alpha) { public static final void clearColor(float red, float green, float blue, float alpha) {
if (red != clearColorR || green != clearColorG || blue != clearColorB || alpha != clearColorA) { if(red != clearColorR || green != clearColorG || blue != clearColorB || alpha != clearColorA) {
_wglClearColor(red, green, blue, alpha); _wglClearColor(red, green, blue, alpha);
clearColorR = red; clearColorR = red;
clearColorG = green; clearColorG = green;
@ -577,7 +600,7 @@ public class GlStateManager {
} }
public static final void loadIdentity() { public static final void loadIdentity() {
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modelMatrixStack[modelMatrixStackPointer].setIdentity(); modelMatrixStack[modelMatrixStackPointer].setIdentity();
@ -589,46 +612,50 @@ public class GlStateManager {
break; break;
case GL_TEXTURE: case GL_TEXTURE:
textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]].setIdentity(); textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]].setIdentity();
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
} }
public static final void pushMatrix() { public static final void pushMatrix() {
int push; int push;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
push = modelMatrixStackPointer + 1; push = modelMatrixStackPointer + 1;
if (push < modelMatrixStack.length) { if(push < modelMatrixStack.length) {
modelMatrixStack[push].load(modelMatrixStack[modelMatrixStackPointer]); modelMatrixStack[push].load(modelMatrixStack[modelMatrixStackPointer]);
modelMatrixStackAccessSerial[push] = modelMatrixStackAccessSerial[modelMatrixStackPointer]; modelMatrixStackAccessSerial[push] = modelMatrixStackAccessSerial[modelMatrixStackPointer];
modelMatrixStackPointer = push; modelMatrixStackPointer = push;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_MODELVIEW matrix stack overflow!" + " Exceeded " + modelMatrixStack.length + " calls to GlStateManager.pushMatrix"); Throwable t = new IndexOutOfBoundsException("GL_MODELVIEW matrix stack overflow!" +
" Exceeded " + modelMatrixStack.length + " calls to GlStateManager.pushMatrix");
logger.error(t); logger.error(t);
} }
break; break;
case GL_PROJECTION: case GL_PROJECTION:
push = projectionMatrixStackPointer + 1; push = projectionMatrixStackPointer + 1;
if (push < projectionMatrixStack.length) { if(push < projectionMatrixStack.length) {
projectionMatrixStack[push].load(projectionMatrixStack[projectionMatrixStackPointer]); projectionMatrixStack[push].load(projectionMatrixStack[projectionMatrixStackPointer]);
projectionMatrixStackAccessSerial[push] = projectionMatrixStackAccessSerial[projectionMatrixStackPointer]; projectionMatrixStackAccessSerial[push] = projectionMatrixStackAccessSerial[projectionMatrixStackPointer];
projectionMatrixStackPointer = push; projectionMatrixStackPointer = push;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_PROJECTION matrix stack overflow!" + " Exceeded " + projectionMatrixStack.length + " calls to GlStateManager.pushMatrix"); Throwable t = new IndexOutOfBoundsException("GL_PROJECTION matrix stack overflow!" +
" Exceeded " + projectionMatrixStack.length + " calls to GlStateManager.pushMatrix");
logger.error(t); logger.error(t);
} }
break; break;
case GL_TEXTURE: case GL_TEXTURE:
push = textureMatrixStackPointer[activeTexture] + 1; push = textureMatrixStackPointer[activeTexture] + 1;
if (push < textureMatrixStack.length) { if(push < textureMatrixStack.length) {
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][push].load(textureMatrixStack[activeTexture][ptr]); textureMatrixStack[activeTexture][push].load(textureMatrixStack[activeTexture][ptr]);
textureMatrixStackAccessSerial[activeTexture][push] = textureMatrixStackAccessSerial[activeTexture][ptr]; textureMatrixStackAccessSerial[activeTexture][push] = textureMatrixStackAccessSerial[activeTexture][ptr];
textureMatrixStackPointer[activeTexture] = push; textureMatrixStackPointer[activeTexture] = push;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_TEXTURE #" + activeTexture + " matrix stack overflow!" + " Exceeded " + textureMatrixStack.length + " calls to GlStateManager.pushMatrix"); Throwable t = new IndexOutOfBoundsException("GL_TEXTURE #" + activeTexture + " matrix stack overflow!" +
" Exceeded " + textureMatrixStack.length + " calls to GlStateManager.pushMatrix");
logger.error(t); logger.error(t);
} }
break; break;
@ -636,29 +663,32 @@ public class GlStateManager {
} }
public static final void popMatrix() { public static final void popMatrix() {
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
if (modelMatrixStackPointer > 0) { if(modelMatrixStackPointer > 0) {
--modelMatrixStackPointer; --modelMatrixStackPointer;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_MODELVIEW matrix stack underflow!" + " Called GlStateManager.popMatrix on an empty matrix stack"); Throwable t = new IndexOutOfBoundsException("GL_MODELVIEW matrix stack underflow!" +
" Called GlStateManager.popMatrix on an empty matrix stack");
logger.error(t); logger.error(t);
} }
break; break;
case GL_PROJECTION: case GL_PROJECTION:
if (projectionMatrixStackPointer > 0) { if(projectionMatrixStackPointer > 0) {
--projectionMatrixStackPointer; --projectionMatrixStackPointer;
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_PROJECTION matrix stack underflow!" + " Called GlStateManager.popMatrix on an empty matrix stack"); Throwable t = new IndexOutOfBoundsException("GL_PROJECTION matrix stack underflow!" +
" Called GlStateManager.popMatrix on an empty matrix stack");
logger.error(t); logger.error(t);
} }
break; break;
case GL_TEXTURE: case GL_TEXTURE:
if (textureMatrixStackPointer[activeTexture] > 0) { if(textureMatrixStackPointer[activeTexture] > 0) {
--textureMatrixStackPointer[activeTexture]; --textureMatrixStackPointer[activeTexture];
} else { }else {
Throwable t = new IndexOutOfBoundsException("GL_TEXTURE #" + activeTexture + " matrix stack underflow! Called GlStateManager.popMatrix on an empty matrix stack"); Throwable t = new IndexOutOfBoundsException("GL_TEXTURE #" + activeTexture +
" matrix stack underflow! Called GlStateManager.popMatrix on an empty matrix stack");
logger.error(t); logger.error(t);
} }
break; break;
@ -666,7 +696,7 @@ public class GlStateManager {
} }
public static final void getFloat(int pname, float[] params) { public static final void getFloat(int pname, float[] params) {
switch (pname) { switch(pname) {
case GL_MODELVIEW_MATRIX: case GL_MODELVIEW_MATRIX:
modelMatrixStack[modelMatrixStackPointer].store(params); modelMatrixStack[modelMatrixStackPointer].store(params);
break; break;
@ -683,7 +713,7 @@ public class GlStateManager {
public static final void ortho(double left, double right, double bottom, double top, double zNear, double zFar) { public static final void ortho(double left, double right, double bottom, double top, double zNear, double zFar) {
Matrix4f matrix; Matrix4f matrix;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
matrix = modelMatrixStack[modelMatrixStackPointer]; matrix = modelMatrixStack[modelMatrixStackPointer];
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial; modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
@ -696,35 +726,35 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
matrix = textureMatrixStack[activeTexture][ptr]; matrix = textureMatrixStack[activeTexture][ptr];
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
matrix.m00 = 2.0f / (float) (right - left); matrix.m00 = 2.0f / (float)(right - left);
matrix.m01 = 0.0f; matrix.m01 = 0.0f;
matrix.m02 = 0.0f; matrix.m02 = 0.0f;
matrix.m03 = 0.0f; matrix.m03 = 0.0f;
matrix.m10 = 0.0f; matrix.m10 = 0.0f;
matrix.m11 = 2.0f / (float) (top - bottom); matrix.m11 = 2.0f / (float)(top - bottom);
matrix.m12 = 0.0f; matrix.m12 = 0.0f;
matrix.m13 = 0.0f; matrix.m13 = 0.0f;
matrix.m20 = 0.0f; matrix.m20 = 0.0f;
matrix.m21 = 0.0f; matrix.m21 = 0.0f;
matrix.m22 = 2.0f / (float) (zFar - zNear); matrix.m22 = 2.0f / (float)(zFar - zNear);
matrix.m23 = 0.0f; matrix.m23 = 0.0f;
matrix.m30 = (float) (-(right + left) / (right - left)); matrix.m30 = (float)(-(right + left) / (right - left));
matrix.m31 = (float) (-(top + bottom) / (top - bottom)); matrix.m31 = (float)(-(top + bottom) / (top - bottom));
matrix.m32 = (float) ((zFar + zNear) / (zFar - zNear)); matrix.m32 = (float)((zFar + zNear) / (zFar - zNear));
matrix.m33 = 1.0f; matrix.m33 = 1.0f;
} }
private static final Vector3f paramVector = new Vector3f(); private static final Vector3f paramVector = new Vector3f();
private static final float toRad = 0.0174532925f; private static final float toRad = 0.0174532925f;
public static final void rotate(float angle, float x, float y, float z) { public static final void rotate(float angle, float x, float y, float z) {
paramVector.x = x; paramVector.x = x;
paramVector.y = y; paramVector.y = y;
paramVector.z = z; paramVector.z = z;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modelMatrixStack[modelMatrixStackPointer].rotate(angle * toRad, paramVector); modelMatrixStack[modelMatrixStackPointer].rotate(angle * toRad, paramVector);
@ -737,7 +767,8 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].rotate(angle * toRad, paramVector); textureMatrixStack[activeTexture][ptr].rotate(angle * toRad, paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
} }
@ -746,7 +777,7 @@ public class GlStateManager {
paramVector.x = x; paramVector.x = x;
paramVector.y = y; paramVector.y = y;
paramVector.z = z; paramVector.z = z;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modelMatrixStack[modelMatrixStackPointer].scale(paramVector); modelMatrixStack[modelMatrixStackPointer].scale(paramVector);
@ -759,16 +790,17 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].scale(paramVector); textureMatrixStack[activeTexture][ptr].scale(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
} }
public static final void scale(double x, double y, double z) { public static final void scale(double x, double y, double z) {
paramVector.x = (float) x; paramVector.x = (float)x;
paramVector.y = (float) y; paramVector.y = (float)y;
paramVector.z = (float) z; paramVector.z = (float)z;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modelMatrixStack[modelMatrixStackPointer].scale(paramVector); modelMatrixStack[modelMatrixStackPointer].scale(paramVector);
@ -781,7 +813,8 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].scale(paramVector); textureMatrixStack[activeTexture][ptr].scale(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
} }
@ -790,7 +823,7 @@ public class GlStateManager {
paramVector.x = x; paramVector.x = x;
paramVector.y = y; paramVector.y = y;
paramVector.z = z; paramVector.z = z;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modelMatrixStack[modelMatrixStackPointer].translate(paramVector); modelMatrixStack[modelMatrixStackPointer].translate(paramVector);
@ -803,16 +836,17 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].translate(paramVector); textureMatrixStack[activeTexture][ptr].translate(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
} }
public static final void translate(double x, double y, double z) { public static final void translate(double x, double y, double z) {
paramVector.x = (float) x; paramVector.x = (float)x;
paramVector.y = (float) y; paramVector.y = (float)y;
paramVector.z = (float) z; paramVector.z = (float)z;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modelMatrixStack[modelMatrixStackPointer].translate(paramVector); modelMatrixStack[modelMatrixStackPointer].translate(paramVector);
@ -825,17 +859,17 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
textureMatrixStack[activeTexture][ptr].translate(paramVector); textureMatrixStack[activeTexture][ptr].translate(paramVector);
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
} }
private static final Matrix4f paramMatrix = new Matrix4f(); private static final Matrix4f paramMatrix = new Matrix4f();
public static final void multMatrix(float[] matrix) { public static final void multMatrix(float[] matrix) {
Matrix4f modeMatrix; Matrix4f modeMatrix;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
default: default:
modeMatrix = modelMatrixStack[modelMatrixStackPointer]; modeMatrix = modelMatrixStack[modelMatrixStackPointer];
@ -848,7 +882,8 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
modeMatrix = textureMatrixStack[activeTexture][ptr]; modeMatrix = textureMatrixStack[activeTexture][ptr];
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
@ -887,7 +922,7 @@ public class GlStateManager {
public static final void gluPerspective(float fovy, float aspect, float zNear, float zFar) { public static final void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
Matrix4f matrix; Matrix4f matrix;
switch (stateMatrixMode) { switch(stateMatrixMode) {
case GL_MODELVIEW: case GL_MODELVIEW:
matrix = modelMatrixStack[modelMatrixStackPointer]; matrix = modelMatrixStack[modelMatrixStackPointer];
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial; modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
@ -900,7 +935,8 @@ public class GlStateManager {
case GL_TEXTURE: case GL_TEXTURE:
int ptr = textureMatrixStackPointer[activeTexture]; int ptr = textureMatrixStackPointer[activeTexture];
matrix = textureMatrixStack[activeTexture][ptr]; matrix = textureMatrixStack[activeTexture][ptr];
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture]; textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
++textureMatrixAccessSerial[activeTexture];
break; break;
} }
float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f); float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f);
@ -925,13 +961,14 @@ public class GlStateManager {
private static final Matrix4f unprojA = new Matrix4f(); private static final Matrix4f unprojA = new Matrix4f();
private static final Matrix4f unprojB = new Matrix4f(); private static final Matrix4f unprojB = new Matrix4f();
private static final Vector4f unprojC = new Vector4f(); private static final Vector4f unprojC = new Vector4f();
public static final void gluUnProject(float p1, float p2, float p3, float[] modelview, float[] projection,
public static final void gluUnProject(float p1, float p2, float p3, float[] modelview, float[] projection, int[] viewport, float[] objectcoords) { int[] viewport, float[] objectcoords) {
unprojA.load(modelview); unprojA.load(modelview);
unprojB.load(projection); unprojB.load(projection);
Matrix4f.mul(unprojA, unprojB, unprojB); Matrix4f.mul(unprojA, unprojB, unprojB);
unprojB.invert(); unprojB.invert();
unprojC.set(((p1 - (float) viewport[0]) / (float) viewport[2]) * 2f - 1f, ((p2 - (float) viewport[1]) / (float) viewport[3]) * 2f - 1f, p3, 1.0f); unprojC.set(((p1 - (float)viewport[0]) / (float)viewport[2]) * 2f - 1f,
((p2 - (float)viewport[1]) / (float)viewport[3]) * 2f - 1f, p3, 1.0f);
Matrix4f.transform(unprojB, unprojC, unprojC); Matrix4f.transform(unprojB, unprojC, unprojC);
objectcoords[0] = unprojC.x / unprojC.w; objectcoords[0] = unprojC.x / unprojC.w;
objectcoords[1] = unprojC.y / unprojC.w; objectcoords[1] = unprojC.y / unprojC.w;