fixes, part 2

This commit is contained in:
lax1dude 2023-10-13 00:13:46 -07:00
parent 0154bd9744
commit 60fc4bc096
3 changed files with 509 additions and 295 deletions

View File

@ -86,21 +86,22 @@ uniform vec3 normalUniform;
#endif
#ifdef CC_fog
uniform vec4 fogColor;
uniform int fogMode;
uniform float fogStart;
uniform float fogEnd;
uniform float fogDensity;
uniform float fogPremultiply;
//X = uniform float fogMode;
//Y = uniform float fogStart;
//Z = uniform float fogEnd - fogStart;
//W = uniform float fogDensity;
uniform vec4 fogParam;
#endif
uniform vec4 colorUniform;
#ifdef CC_alphatest
uniform float alphaTestF;
#endif
#ifdef CC_TEX_GEN_STRQ
uniform int textureGenS_M;
uniform int textureGenT_M;
uniform int textureGenR_M;
uniform int textureGenQ_M;
//uniform int textureGenS_M;
//uniform int textureGenT_M;
//uniform int textureGenR_M;
//uniform int textureGenQ_M;
uniform ivec4 textureGen_M;
uniform vec4 textureGenS_V;
uniform vec4 textureGenT_V;
uniform vec4 textureGenR_V;
@ -144,10 +145,10 @@ void main(){
texSrc[1] = v_position;
vec4 texPos;
texPos.x = dot(texSrc[textureGenS_M], textureGenS_V);
texPos.y = dot(texSrc[textureGenT_M], textureGenT_V);
texPos.z = dot(texSrc[textureGenR_M], textureGenR_V);
texPos.w = dot(texSrc[textureGenQ_M], textureGenQ_V);
texPos.x = dot(texSrc[textureGen_M.x], textureGenS_V);
texPos.y = dot(texSrc[textureGen_M.y], textureGenT_V);
texPos.z = dot(texSrc[textureGen_M.z], textureGenR_V);
texPos.w = dot(texSrc[textureGen_M.w], textureGenQ_V);
texPos = matrix_t * texPos;
color *= texture(tex0, texPos.xy / texPos.w).bgra;
#ifdef CC_alphatest
@ -210,7 +211,7 @@ void main(){
#ifdef CC_fog
float dist = sqrt(dot(v_position, v_position));
float i = fogMode == 1 ? (dist - fogStart) / (fogEnd - fogStart) : 1.0 - exp(-fogDensity * dist);
float i = fogParam.x == 1.0 ? (dist - fogParam.y) / fogParam.z : 1.0 - exp(-fogParam.w * dist);
color.rgb = mix(color.rgb, fogColor.xyz, clamp(i, 0.0, 1.0) * fogColor.a);
#endif

View File

@ -133,100 +133,131 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final boolean isWebGL = _wisWebGL();
private static final GLObjectMap<TextureGL> texObjects = new GLObjectMap(256);
static final GLObjectMap<TextureGL> texObjects = new GLObjectMap(256);
private static boolean enableTexture2D = false;
private static boolean enableTexture2D_1 = false;
private static boolean enableLighting = false;
private static boolean enableAlphaTest = false;
private static float alphaThresh = 0.1f;
static boolean enableTexture2D = false;
static boolean enableTexture2D_1 = false;
static boolean enableLighting = false;
static boolean enableAlphaTest = false;
static float alphaThresh = 0.1f;
private static boolean isCompilingDisplayList = false;
private static DisplayList compilingDisplayList = null;
static boolean isDepthTest = false;
static int currentDepthFunc = -99999;
static boolean isCullFace = false;
static int currentCullFace = -99999;
static boolean isPolygonOffset = false;
static float polygonOffset1 = -999.9f;
static float polygonOffset2 = -999.9f;
static boolean isBlend = false;
static int blendSRC = 0;
static int blendDST = 0;
static int colorMask = 15;
static boolean isDepthMask = true;
private static boolean enableColorArray = false;
private static boolean enableNormalArray = false;
private static boolean enableTex0Array = false;
private static boolean enableTex1Array = false;
static boolean isCompilingDisplayList = false;
static DisplayList compilingDisplayList = null;
private static boolean enableAnisotropicFix = false;
private static float anisotropicFixX = 1024.0f;
private static float anisotropicFixY = 1024.0f;
static boolean enableColorArray = false;
static boolean enableNormalArray = false;
static boolean enableTex0Array = false;
static boolean enableTex1Array = false;
private static float colorR = 1.0f;
private static float colorG = 1.0f;
private static float colorB = 1.0f;
private static float colorA = 1.0f;
static boolean enableAnisotropicFix = false;
static int anisotropicFixSerial = 0;
static float anisotropicFixX = 1024.0f;
static float anisotropicFixY = 1024.0f;
private static float normalX = 1.0f;
private static float normalY = 0.0f;
private static float normalZ = 0.0f;
static int colorSerial = 0;
static float colorR = 1.0f;
static float colorG = 1.0f;
static float colorB = 1.0f;
static float colorA = 1.0f;
private static int selectedTex = 0;
private static int selectedClientTex = 0;
private static float tex0X = 0;
private static float tex0Y = 0;
private static float tex1X = 0;
private static float tex1Y = 0;
private static TextureGL boundTexture0 = null;
private static boolean enableAnisotropicPatch = false;
private static boolean hintAnisotropicPatch = false;
private static boolean swapRB = false;
static int normalSerial = 0;
static float normalX = 1.0f;
static float normalY = 0.0f;
static float normalZ = 0.0f;
static int selectedTex = 0;
static int selectedClientTex = 0;
static int[] boundTex = new int[2];
static int tex0Serial = 0;
static float tex0X = 0;
static float tex0Y = 0;
static int tex1Serial = 0;
static float tex1X = 0;
static float tex1Y = 0;
static TextureGL boundTexture0 = null;
static boolean enableAnisotropicPatch = false;
static boolean hintAnisotropicPatch = false;
static boolean swapRB = false;
public static final void anisotropicPatch(boolean e) {
enableAnisotropicPatch = e;
}
private static boolean enableTexGen = false;
private static boolean enableColorMaterial = false;
static boolean enableTexGen = false;
static boolean enableColorMaterial = false;
private static int texS_plane = 0;
private static float texS_X = 0.0f;
private static float texS_Y = 0.0f;
private static float texS_Z = 0.0f;
private static float texS_W = 0.0f;
static int texPlaneSerial = 0;
static int texSSerial = 0;
static int texS_plane = 0;
static float texS_X = 0.0f;
static float texS_Y = 0.0f;
static float texS_Z = 0.0f;
static float texS_W = 0.0f;
private static int texT_plane = 0;
private static float texT_X = 0.0f;
private static float texT_Y = 0.0f;
private static float texT_Z = 0.0f;
private static float texT_W = 0.0f;
static int texTSerial = 0;
static int texT_plane = 0;
static float texT_X = 0.0f;
static float texT_Y = 0.0f;
static float texT_Z = 0.0f;
static float texT_W = 0.0f;
private static int texR_plane = 0;
private static float texR_X = 0.0f;
private static float texR_Y = 0.0f;
private static float texR_Z = 0.0f;
private static float texR_W = 0.0f;
static int texRSerial = 0;
static int texR_plane = 0;
static float texR_X = 0.0f;
static float texR_Y = 0.0f;
static float texR_Z = 0.0f;
static float texR_W = 0.0f;
private static int texQ_plane = 0;
private static float texQ_X = 0.0f;
private static float texQ_Y = 0.0f;
private static float texQ_Z = 0.0f;
private static float texQ_W = 0.0f;
static int texQSerial = 0;
static int texQ_plane = 0;
static float texQ_X = 0.0f;
static float texQ_Y = 0.0f;
static float texQ_Z = 0.0f;
static float texQ_W = 0.0f;
private static float fogColorR = 1.0f;
private static float fogColorG = 1.0f;
private static float fogColorB = 1.0f;
private static float fogColorA = 1.0f;
private static int fogMode = 1;
private static boolean fogEnabled = false;
private static boolean fogPremultiply = false;
private static float fogStart = 1.0f;
private static float fogEnd = 1.0f;
private static float fogDensity = 1.0f;
static int fogColorSerial = 0;
static float fogColorR = 1.0f;
static float fogColorG = 1.0f;
static float fogColorB = 1.0f;
static float fogColorA = 1.0f;
static int fogCfgSerial = 0;
static int fogMode = 1;
static boolean fogEnabled = false;
static float fogStart = 1.0f;
static float fogEnd = 1.0f;
static float fogDensity = 1.0f;
private static int bytesUploaded = 0;
private static int vertexDrawn = 0;
private static int triangleDrawn = 0;
static int bytesUploaded = 0;
static int vertexDrawn = 0;
static int triangleDrawn = 0;
private static int matrixMode = GL_MODELVIEW;
static int matrixMode = GL_MODELVIEW;
static int matModelSerialCounter = 0;
static int[] matModelVSerial = new int[32];
static Matrix4f[] matModelV = new Matrix4f[32];
static int matModelPointer = 0;
static int matProjSerialCounter = 0;
static int[] matProjVSerial = new int[6];
static Matrix4f[] matProjV = new Matrix4f[6];
static int matProjPointer = 0;
static int matTexSerialCounter = 0;
static int[] matTexVSerial = new int[16];
static Matrix4f[] matTexV = new Matrix4f[16];
static int matTexPointer = 0;
@ -280,13 +311,22 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glEnable(int p1) {
switch (p1) {
case GL_DEPTH_TEST:
_wglEnable(_wGL_DEPTH_TEST);
if(!isDepthTest) {
_wglEnable(_wGL_DEPTH_TEST);
isDepthTest = true;
}
break;
case GL_CULL_FACE:
_wglEnable(_wGL_CULL_FACE);
if(!isCullFace) {
_wglEnable(_wGL_CULL_FACE);
isCullFace = true;
}
break;
case GL_BLEND:
_wglEnable(_wGL_BLEND);
if(!isBlend) {
_wglEnable(_wGL_BLEND);
isBlend = true;
}
break;
case GL_RESCALE_NORMAL:
break;
@ -317,7 +357,10 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
enableTexGen = true;
break;
case GL_POLYGON_OFFSET_FILL:
_wglEnable(_wGL_POLYGON_OFFSET_FILL);
if(!isPolygonOffset) {
_wglEnable(_wGL_POLYGON_OFFSET_FILL);
isPolygonOffset = true;
}
break;
case EAG_SWAP_RB:
swapRB = true;
@ -349,7 +392,10 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
default:
break;
}
_wglDepthFunc(f);
if(f != currentDepthFunc) {
_wglDepthFunc(f);
currentDepthFunc = f;
}
}
public static final void glAlphaFunc(int p1, float p2) {
@ -357,27 +403,33 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glCullFace(int p1) {
_wglCullFace(p1);
if(p1 != currentCullFace) {
_wglCullFace(p1);
currentCullFace = p1;
}
}
public static final void glMatrixMode(int p1) {
matrixMode = p1;
}
private static final Matrix4f getMatrix() {
private static final Matrix4f getMatrixIncrSerial() {
switch (matrixMode) {
case GL_MODELVIEW:
default:
matModelVSerial[matModelPointer] = ++matModelSerialCounter;
return matModelV[matModelPointer];
case GL_PROJECTION:
matProjVSerial[matProjPointer] = ++matProjSerialCounter;
return matProjV[matProjPointer];
case GL_TEXTURE:
matTexVSerial[matTexPointer] = ++matTexSerialCounter;
return matTexV[matTexPointer];
}
}
public static final void glLoadIdentity() {
getMatrix().setIdentity();
getMatrixIncrSerial().setIdentity();
}
public static final void glViewport(int p1, int p2, int p3, int p4) {
@ -389,7 +441,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {
Matrix4f res = getMatrix();
Matrix4f res = getMatrixIncrSerial();
res.m00 = 2.0f / (right - left);
res.m01 = 0.0f;
res.m02 = 0.0f;
@ -412,7 +464,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glTranslatef(float p1, float p2, float p3) {
deevis.set(p1, p2, p3);
getMatrix().translate(deevis);
getMatrixIncrSerial().translate(deevis);
if (isCompilingDisplayList) {
System.err.println("matrix is not supported while recording display list use tessellator class instead");
}
@ -425,13 +477,22 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glDisable(int p1) {
switch (p1) {
case GL_DEPTH_TEST:
_wglDisable(_wGL_DEPTH_TEST);
if(isDepthTest) {
_wglDisable(_wGL_DEPTH_TEST);
isDepthTest = false;
}
break;
case GL_CULL_FACE:
_wglDisable(_wGL_CULL_FACE);
if(isCullFace) {
_wglDisable(_wGL_CULL_FACE);
isCullFace = false;
}
break;
case GL_BLEND:
_wglDisable(_wGL_BLEND);
if(isBlend) {
_wglDisable(_wGL_BLEND);
isBlend = false;
}
break;
case GL_RESCALE_NORMAL:
break;
@ -462,7 +523,10 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
enableTexGen = false;
break;
case GL_POLYGON_OFFSET_FILL:
_wglDisable(_wGL_POLYGON_OFFSET_FILL);
if(isPolygonOffset) {
_wglDisable(_wGL_POLYGON_OFFSET_FILL);
isPolygonOffset = false;
}
break;
case EAG_SWAP_RB:
swapRB = false;
@ -473,6 +537,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glColor4f(float p1, float p2, float p3, float p4) {
++colorSerial;
colorR = p1;
colorG = p2;
colorB = p3;
@ -511,12 +576,16 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
static int lightPos0Serial = 0;
static int lightPos1Serial = 0;
private static Vector4f lightPos0vec0 = new Vector4f();
private static Vector4f lightPos1vec0 = new Vector4f();
private static Vector4f lightPos0vec = new Vector4f();
private static Vector4f lightPos1vec = new Vector4f();
static Vector4f lightPos0vec = new Vector4f();
static Vector4f lightPos1vec = new Vector4f();
public static final void copyModelToLightMatrix() {
++lightPos0Serial;
++lightPos1Serial;
lightPos0vec0.set(lightPos0vec);
lightPos1vec0.set(lightPos1vec);
lightPos0vec.set(0.2f, 1.0f, -0.7f, 0.0f);
@ -528,6 +597,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void flipLightMatrix() {
++lightPos0Serial;
++lightPos1Serial;
lightPos0vec.x = -lightPos0vec.x;
lightPos1vec.x = -lightPos1vec.x;
lightPos0vec.y = -lightPos0vec.y;
@ -537,6 +608,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void revertLightMatrix() {
++lightPos0Serial;
++lightPos1Serial;
lightPos0vec.set(lightPos0vec0);
lightPos1vec.set(lightPos1vec0);
}
@ -548,6 +621,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
if (matModelPointer < matModelV.length - 1) {
++matModelPointer;
matModelV[matModelPointer].load(matModelV[matModelPointer - 1]);
matModelVSerial[matModelPointer] = matModelVSerial[matModelPointer - 1];
} else {
System.err.println("modelview matrix stack overflow");
}
@ -556,6 +630,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
if (matProjPointer < matProjV.length - 1) {
++matProjPointer;
matProjV[matProjPointer].load(matProjV[matProjPointer - 1]);
matProjVSerial[matProjPointer] = matProjVSerial[matProjPointer - 1];
} else {
System.err.println("projection matrix stack overflow");
}
@ -564,6 +639,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
if (matTexPointer < matTexV.length - 1) {
++matTexPointer;
matTexV[matTexPointer].load(matTexV[matTexPointer - 1]);
matTexVSerial[matTexPointer] = matTexVSerial[matTexPointer - 1];
} else {
System.err.println("texture matrix stack overflow");
}
@ -575,7 +651,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glRotatef(float p1, float p2, float p3, float p4) {
deevis.set(p2, p3, p4);
getMatrix().rotate(p1 * toRad, deevis);
getMatrixIncrSerial().rotate(p1 * toRad, deevis);
if (isCompilingDisplayList) {
System.err.println("matrix is not supported while recording display list use tessellator class instead");
}
@ -632,7 +708,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glScalef(float p1, float p2, float p3) {
deevis.set(p1, p2, p3);
getMatrix().scale(deevis);
getMatrixIncrSerial().scale(deevis);
if (isCompilingDisplayList) {
System.err.println("matrix is not supported while recording display list use tessellator class instead");
}
@ -641,15 +717,24 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
private static final Matrix4f tmpMat = new Matrix4f();
public static final void glMultMatrixf(Matrix4f mat) {
getMatrix().load(Matrix4f.mul(getMatrix(), mat, tmpMat));
getMatrixIncrSerial().load(Matrix4f.mul(getMatrixIncrSerial(), mat, tmpMat));
}
public static final void glBlendFunc(int p1, int p2) {
fogPremultiply = (p1 == GL_ONE && p2 == GL_ONE_MINUS_SRC_ALPHA);
if(overlayFBOBlending) {
_wglBlendFuncSeparate(p1, p2, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
int i = p1 | 0x10000;
int j = p2 | 0x10000;
if(blendSRC != i || blendDST != j) {
_wglBlendFuncSeparate(p1, p2, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
blendSRC = i;
blendDST = j;
}
}else {
_wglBlendFunc(p1, p2);
if(blendSRC != p1 || blendDST != p2) {
_wglBlendFunc(p1, p2);
blendSRC = p1;
blendDST = p2;
}
}
}
@ -660,11 +745,18 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glDepthMask(boolean p1) {
_wglDepthMask(p1);
if(isDepthMask != p1) {
_wglDepthMask(p1);
isDepthMask = p1;
}
}
public static final void glColorMask(boolean p1, boolean p2, boolean p3, boolean p4) {
_wglColorMask(p1, p2, p3, p4);
int hsh = (p1 ? 1 : 0) | (p2 ? 2 : 0) | (p3 ? 4 : 0) | (p4 ? 8 : 0);
if(colorMask != hsh) {
_wglColorMask(p1, p2, p3, p4);
colorMask = hsh;
}
}
private static final void updateAnisotropicPatch() {
@ -672,6 +764,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
enableAnisotropicFix = false;
if (enableAnisotropicPatch && boundTexture0 != null && boundTexture0.anisotropic && boundTexture0.nearest) {
enableAnisotropicFix = true;
++anisotropicFixSerial;
anisotropicFixX = boundTexture0.w;
anisotropicFixY = boundTexture0.h;
}
@ -679,11 +772,14 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glBindTexture(int p1, int p2) {
TextureGL t = texObjects.get(p2);
_wglBindTexture(_wGL_TEXTURE_2D, t);
if (selectedTex == 0) {
boundTexture0 = t;
updateAnisotropicPatch();
if(boundTex[selectedTex] != p2) {
TextureGL t = texObjects.get(p2);
_wglBindTexture(_wGL_TEXTURE_2D, t);
if (selectedTex == 0) {
boundTexture0 = t;
updateAnisotropicPatch();
}
boundTex[selectedTex] = p2;
}
}
@ -715,6 +811,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glNormal3f(float p1, float p2, float p3) {
++normalSerial;
float len = (float) Math.sqrt(p1 * p1 + p2 * p2 + p3 * p3);
normalX = p1 / len;
normalY = p2 / len;
@ -731,8 +828,10 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void _wglBindVertexArray0(BufferArrayGL p1) {
currentArray = p1;
_wglBindVertexArray(p1);
if(currentArray != p1) {
currentArray = p1;
_wglBindVertexArray(p1);
}
}
private static int displayListId = 0;
@ -798,7 +897,9 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final HighPolyMesh loadMesh(String path) {
try {
return HighPolyMesh.loadMeshData(EaglerAdapter.loadResourceBytes(path));
HighPolyMesh ret = HighPolyMesh.loadMeshData(EaglerAdapter.loadResourceBytes(path));
currentArray = ret.vertexArray;
return ret;
} catch (IOException ex) {
System.err.println("Could not load HighPolyMesh! " + ex.toString());
ex.printStackTrace();
@ -807,6 +908,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glColor3f(float p1, float p2, float p3) {
++colorSerial;
colorR = p1;
colorG = p2;
colorB = p3;
@ -828,6 +930,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
switch (p1) {
case GL_S:
++texPlaneSerial;
++texSSerial;
texS_plane = (p2 == GL_EYE_PLANE ? 1 : 0);
texS_X = vec.x;
texS_Y = vec.y;
@ -835,6 +939,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
texS_W = vec.w;
break;
case GL_T:
++texPlaneSerial;
++texTSerial;
texT_plane = (p2 == GL_EYE_PLANE ? 1 : 0);
texT_X = vec.x;
texT_Y = vec.y;
@ -842,6 +948,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
texT_W = vec.w;
break;
case GL_R:
++texPlaneSerial;
++texRSerial;
texR_plane = (p2 == GL_EYE_PLANE ? 1 : 0);
texR_X = vec.x;
texR_Y = vec.y;
@ -849,6 +957,8 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
texR_W = vec.w;
break;
case GL_Q:
++texPlaneSerial;
++texQSerial;
texQ_plane = (p2 == GL_EYE_PLANE ? 1 : 0);
texQ_X = vec.x;
texQ_Y = vec.y;
@ -908,7 +1018,11 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void glPolygonOffset(float p1, float p2) {
_wglPolygonOffset(p1, p2);
if(p1 != polygonOffset1 || p2 != polygonOffset2) {
_wglPolygonOffset(p1, p2);
polygonOffset1 = p1;
polygonOffset2 = p2;
}
}
public static final void glCallLists(IntBuffer p1) {
@ -1023,40 +1137,13 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
private static final void bindTheShader(int mode) {
FixedFunctionShader s = shader = FixedFunctionShader.instance(mode);
s.useProgram();
if (enableAlphaTest) {
s.setAlphaTest(alphaThresh);
}
s.setColor(colorR, colorG, colorB, colorA);
if (fogEnabled) {
s.setFogMode((fogPremultiply ? 2 : 0) + fogMode);
s.setFogColor(fogColorR, fogColorG, fogColorB, fogColorA);
s.setFogDensity(fogDensity);
s.setFogStartEnd(fogStart, fogEnd);
}
s.setModelMatrix(matModelV[matModelPointer]);
s.setProjectionMatrix(matProjV[matProjPointer]);
s.setTextureMatrix(matTexV[matTexPointer]);
if (enableColorMaterial && enableLighting) {
s.setNormal(normalX, normalY, normalZ);
s.setLightPositions(lightPos0vec, lightPos1vec);
}
s.setTex0Coords(tex0X, tex0Y);
s.setTex1Coords(tex1X, tex1Y);
if (enableTexGen) {
s.setTexGenS(texS_plane, texS_X, texS_Y, texS_Z, texS_W);
s.setTexGenT(texT_plane, texT_X, texT_Y, texT_Z, texT_W);
s.setTexGenR(texR_plane, texR_X, texR_Y, texR_Z, texR_W);
s.setTexGenQ(texQ_plane, texQ_X, texQ_Y, texQ_Z, texQ_W);
}
if (enableAnisotropicFix) {
s.setAnisotropicFix(anisotropicFixX, anisotropicFixY);
}
s.update();
}
public static final void drawHighPoly(HighPolyMesh msh) {
bindTheShader((msh.hasTexture ? (FixedFunctionShader.NORMAL | FixedFunctionShader.TEXTURE0)
: FixedFunctionShader.NORMAL) | getShaderModeFlag1());
_wglBindVertexArray(msh.vertexArray);
_wglBindVertexArray0(msh.vertexArray);
_wglDrawElements(_wGL_TRIANGLES, msh.indexCount, _wGL_UNSIGNED_SHORT, 0);
triangleDrawn += msh.indexCount / 3;
shader.unuseProgram();
@ -1237,7 +1324,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
if (occlusion_vao == null)
initializeOcclusionObjects();
_wglUseProgram(occlusion_program);
_wglBindVertexArray(occlusion_vao);
_wglBindVertexArray0(occlusion_vao);
if (!cachedOcclusionP.equals(matProjV[matProjPointer])) {
cachedOcclusionP.load(matProjV[matProjPointer]);
cachedOcclusionP.store(occlusionProj);
@ -1302,9 +1389,11 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
switch (p2) {
default:
case GL_LINEAR:
++fogCfgSerial;
fogMode = 1;
break;
case GL_EXP:
++fogCfgSerial;
fogMode = 2;
break;
}
@ -1314,12 +1403,15 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glFogf(int p1, float p2) {
switch (p1) {
case GL_FOG_START:
++fogCfgSerial;
fogStart = p2;
break;
case GL_FOG_END:
++fogCfgSerial;
fogEnd = p2;
break;
case GL_FOG_DENSITY:
++fogCfgSerial;
fogDensity = p2;
break;
default:
@ -1329,6 +1421,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glFog(int p1, FloatBuffer p2) {
if (p1 == GL_FOG_COLOR) {
++fogColorSerial;
fogColorR = p2.get();
fogColorG = p2.get();
fogColorB = p2.get();
@ -1380,10 +1473,12 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
public static final void glMultiTexCoord2f(int p1, float p2, float p3) {
switch (p1) {
case GL_TEXTURE0:
++tex0Serial;
tex0X = p2;
tex0Y = p3;
break;
case GL_TEXTURE1:
++tex1Serial;
tex1X = p2;
tex1Y = p3;
break;
@ -1412,7 +1507,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
Matrix4f res = getMatrix();
Matrix4f res = getMatrixIncrSerial();
float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f);
res.m00 = cotangent / aspect;
res.m01 = 0.0f;
@ -1433,7 +1528,7 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
public static final void gluPerspectiveFlat(float fovy, float aspect, float zNear, float zFar) {
Matrix4f res = getMatrix();
Matrix4f res = getMatrixIncrSerial();
float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f);
res.m00 = cotangent / aspect;
res.m01 = 0.0f;

View File

@ -121,21 +121,22 @@ public class FixedFunctionShader {
private UniformGL u_matrix_t = null;
private UniformGL u_fogColor = null;
private UniformGL u_fogMode = null;
private UniformGL u_fogStart = null;
private UniformGL u_fogEnd = null;
private UniformGL u_fogDensity = null;
private UniformGL u_fogPremultiply = null;
//private UniformGL u_fogMode = null;
//private UniformGL u_fogStart = null;
//private UniformGL u_fogEnd = null;
//private UniformGL u_fogDensity = null;
private UniformGL u_fogParam = null;
private UniformGL u_colorUniform = null;
private UniformGL u_normalUniform = null;
private UniformGL u_alphaTestF = null;
private UniformGL u_textureGenS_M = null;
private UniformGL u_textureGenT_M = null;
private UniformGL u_textureGenR_M = null;
private UniformGL u_textureGenQ_M = null;
//private UniformGL u_textureGenS_M = null;
//private UniformGL u_textureGenT_M = null;
//private UniformGL u_textureGenR_M = null;
//private UniformGL u_textureGenQ_M = null;
private UniformGL u_textureGen_M = null;
private UniformGL u_textureGenS_V = null;
private UniformGL u_textureGenT_V = null;
private UniformGL u_textureGenR_V = null;
@ -277,11 +278,11 @@ public class FixedFunctionShader {
if(enable_fog) {
u_fogColor = _wglGetUniformLocation(globject, "fogColor");
u_fogMode = _wglGetUniformLocation(globject, "fogMode");
u_fogStart = _wglGetUniformLocation(globject, "fogStart");
u_fogEnd = _wglGetUniformLocation(globject, "fogEnd");
u_fogDensity = _wglGetUniformLocation(globject, "fogDensity");
u_fogPremultiply = _wglGetUniformLocation(globject, "fogPremultiply");
//u_fogMode = _wglGetUniformLocation(globject, "fogMode");
//u_fogStart = _wglGetUniformLocation(globject, "fogStart");
//u_fogEnd = _wglGetUniformLocation(globject, "fogEnd");
//u_fogDensity = _wglGetUniformLocation(globject, "fogDensity");
u_fogParam = _wglGetUniformLocation(globject, "fogParam");
}
if(enable_alphatest) {
@ -289,10 +290,11 @@ public class FixedFunctionShader {
}
if(enable_TEX_GEN_STRQ) {
u_textureGenS_M = _wglGetUniformLocation(globject, "textureGenS_M");
u_textureGenT_M = _wglGetUniformLocation(globject, "textureGenT_M");
u_textureGenR_M = _wglGetUniformLocation(globject, "textureGenR_M");
u_textureGenQ_M = _wglGetUniformLocation(globject, "textureGenQ_M");
//u_textureGenS_M = _wglGetUniformLocation(globject, "textureGenS_M");
//u_textureGenT_M = _wglGetUniformLocation(globject, "textureGenT_M");
//u_textureGenR_M = _wglGetUniformLocation(globject, "textureGenR_M");
//u_textureGenQ_M = _wglGetUniformLocation(globject, "textureGenQ_M");
u_textureGen_M = _wglGetUniformLocation(globject, "textureGen_M");
u_textureGenS_V = _wglGetUniformLocation(globject, "textureGenS_V");
u_textureGenT_V = _wglGetUniformLocation(globject, "textureGenT_V");
u_textureGenR_V = _wglGetUniformLocation(globject, "textureGenR_V");
@ -317,7 +319,7 @@ public class FixedFunctionShader {
});
}
public void setupArrayForProgram() {
_wglEnableVertexAttribArray(a_position);
_wglVertexAttribPointer(a_position, 3, _wGL_FLOAT, false, 32, 0);
@ -338,11 +340,11 @@ public class FixedFunctionShader {
_wglVertexAttribPointer(a_texture1, 2, _wGL_SHORT, false, 32, 28);
}
}
public void useProgram() {
_wglUseProgram(globject);
}
public void unuseProgram() {
}
@ -354,165 +356,281 @@ public class FixedFunctionShader {
}
}
private float[] modelBuffer = new float[16];
private float[] projectionBuffer = new float[16];
private float[] textureBuffer = new float[16];
private float[] matBuffer = new float[16];
private Matrix4f modelMatrix = (Matrix4f) new Matrix4f().setZero();
private Matrix4f projectionMatrix = (Matrix4f) new Matrix4f().setZero();
private Matrix4f textureMatrix = (Matrix4f) new Matrix4f().setZero();
private Vector4f light0Pos = new Vector4f();
private Vector4f light1Pos = new Vector4f();
private Vector2f anisotropicFix = new Vector2f(0.0f, 0.0f);
public void setAnisotropicFix(float x, float y) {
if(anisotropicFix.x != x || anisotropicFix.y != y) {
anisotropicFix.x = x;
anisotropicFix.y = y;
_wglUniform2f(u_anisotropic_fix, x, y);
}
}
public void setModelMatrix(Matrix4f mat) {
if(!mat.equals(modelMatrix)) {
modelMatrix.load(mat).store(modelBuffer);
_wglUniformMat4fv(u_matrix_m, modelBuffer);
}
}
public void setProjectionMatrix(Matrix4f mat) {
if(!mat.equals(projectionMatrix)) {
projectionMatrix.load(mat).store(projectionBuffer);
_wglUniformMat4fv(u_matrix_p, projectionBuffer);
}
}
public void setTextureMatrix(Matrix4f mat) {
if(!mat.equals(textureMatrix)) {
textureMatrix.load(mat).store(textureBuffer);
_wglUniformMat4fv(u_matrix_t, textureBuffer);
}
}
public void setLightPositions(Vector4f pos0, Vector4f pos1) {
if(!pos0.equals(light0Pos) || !pos1.equals(light1Pos)) {
light0Pos.set(pos0);
light1Pos.set(pos1);
_wglUniform3f(u_light0Pos, light0Pos.x, light0Pos.y, light0Pos.z);
_wglUniform3f(u_light1Pos, light1Pos.x, light1Pos.y, light1Pos.z);
}
}
private int fogMode = 0;
public void setFogMode(int mode) {
if(fogMode != mode) {
fogMode = mode;
_wglUniform1i(u_fogMode, mode % 2);
_wglUniform1f(u_fogPremultiply, mode / 2);
}
}
private float fogColorR = 0.0f;
private float fogColorG = 0.0f;
private float fogColorB = 0.0f;
private float fogColorA = 0.0f;
public void setFogColor(float r, float g, float b, float a) {
if(fogColorR != r || fogColorG != g || fogColorB != b || fogColorA != a) {
fogColorR = r;
fogColorG = g;
fogColorB = b;
fogColorA = a;
_wglUniform4f(u_fogColor, fogColorR, fogColorG, fogColorB, fogColorA);
}
}
private float fogStart = 0.0f;
private float fogEnd = 0.0f;
public void setFogStartEnd(float s, float e) {
if(fogStart != s || fogEnd != e) {
fogStart = s;
fogEnd = e;
_wglUniform1f(u_fogStart, fogStart);
_wglUniform1f(u_fogEnd, fogEnd);
}
}
private float fogDensity = 0.0f;
public void setFogDensity(float d) {
if(fogDensity != d) {
fogDensity = d;
_wglUniform1f(u_fogDensity, fogDensity);
}
}
private float alphaTestValue = 0.0f;
public void setAlphaTest(float limit) {
if(alphaTestValue != limit) {
alphaTestValue = limit;
_wglUniform1f(u_alphaTestF, alphaTestValue);
}
}
private float tex0x = 0.0f;
private float tex0y = 0.0f;
public void setTex0Coords(float x, float y) {
if(tex0x != x || tex0y != y) {
tex0x = x;
tex0y = y;
_wglUniform2f(u_texCoordV0, tex0x, tex0y);
}
}
private float tex1x = 0.0f;
private float tex1y = 0.0f;
public void setTex1Coords(float x, float y) {
if(tex1x != x || tex1y != y) {
tex1x = x;
tex1y = y;
_wglUniform2f(u_texCoordV1, tex1x, tex1y);
}
}
public void setTexGenS(int plane, float x, float y, float z, float w) {
_wglUniform1i(u_textureGenS_M, plane);
_wglUniform4f(u_textureGenS_V, x, y, z, w);
}
public void setTexGenT(int plane, float x, float y, float z, float w) {
_wglUniform1i(u_textureGenT_M, plane);
_wglUniform4f(u_textureGenT_V, x, y, z, w);
}
public void setTexGenR(int plane, float x, float y, float z, float w) {
_wglUniform1i(u_textureGenR_M, plane);
_wglUniform4f(u_textureGenR_V, x, y, z, w);
}
public void setTexGenQ(int plane, float x, float y, float z, float w) {
_wglUniform1i(u_textureGenQ_M, plane);
_wglUniform4f(u_textureGenQ_V, x, y, z, w);
}
private float colorUniformR = 0.0f;
private float colorUniformG = 0.0f;
private float colorUniformB = 0.0f;
private float colorUniformA = 0.0f;
public void setColor(float r, float g, float b, float a) {
if(colorUniformR != r || colorUniformG != g || colorUniformB != b || colorUniformA != a) {
colorUniformR = r;
colorUniformG = g;
colorUniformB = b;
colorUniformA = a;
_wglUniform4f(u_colorUniform, colorUniformR, colorUniformG, colorUniformB, colorUniformA);
}
}
private float normalUniformX = 0.0f;
private float normalUniformY = 0.0f;
private float normalUniformZ = 0.0f;
public void setNormal(float x, float y, float z) {
if(normalUniformX != x || normalUniformY != y || normalUniformZ != z) {
normalUniformX = x;
normalUniformY = y;
normalUniformZ = z;
_wglUniform3f(u_normalUniform, normalUniformX, normalUniformY, normalUniformZ);
private int anisotropicFixSerial = -1;
private int colorSerial = -1;
private int normalSerial = -1;
private int tex0Serial = -1;
private int tex1Serial = -1;
private int texPlaneSerial = -1;
private int texSSerial = -1;
private int texTSerial = -1;
private int texRSerial = -1;
private int texQSerial = -1;
private int fogColorSerial = -1;
private int fogCfgSerial = -1;
private int matModelSerialCounter = -1;
private int matProjSerialCounter = -1;
private int matTexSerialCounter = -1;
private int lightPos0Serial = -1;
private int lightPos1Serial = -1;
static int texS_plane = -1;
static float texS_X = -999.0f;
static float texS_Y = -999.0f;
static float texS_Z = -999.0f;
static float texS_W = -999.0f;
static int texT_plane = -1;
static float texT_X = -999.0f;
static float texT_Y = -999.0f;
static float texT_Z = -999.0f;
static float texT_W = -999.0f;
static int texR_plane = -1;
static float texR_X = -999.0f;
static float texR_Y = -999.0f;
static float texR_Z = -999.0f;
static float texR_W = -999.0f;
static int texQ_plane = -1;
static float texQ_X = -999.0f;
static float texQ_Y = -999.0f;
static float texQ_Z = -999.0f;
static float texQ_W = -999.0f;
public void update() {
if(anisotropicFixSerial != EaglerAdapterGL30.anisotropicFixSerial) {
float x = EaglerAdapterGL30.anisotropicFixX;
float y = EaglerAdapterGL30.anisotropicFixY;
anisotropicFixSerial = EaglerAdapterGL30.anisotropicFixSerial;
if(anisotropicFix.x != x || anisotropicFix.y != y) {
anisotropicFix.x = x;
anisotropicFix.y = y;
_wglUniform2f(u_anisotropic_fix, x, y);
}
}
if(colorSerial != EaglerAdapterGL30.colorSerial) {
float r = EaglerAdapterGL30.colorR;
float g = EaglerAdapterGL30.colorG;
float b = EaglerAdapterGL30.colorB;
float a = EaglerAdapterGL30.colorA;
colorSerial = EaglerAdapterGL30.colorSerial;
if(colorUniformR != r || colorUniformG != g || colorUniformB != b || colorUniformA != a) {
colorUniformR = r;
colorUniformG = g;
colorUniformB = b;
colorUniformA = a;
_wglUniform4f(u_colorUniform, r, g, b, a);
}
}
if(normalSerial != EaglerAdapterGL30.normalSerial) {
float x = EaglerAdapterGL30.normalX;
float y = EaglerAdapterGL30.normalY;
float z = EaglerAdapterGL30.normalZ;
normalSerial = EaglerAdapterGL30.normalSerial;
if(normalUniformX != x || normalUniformY != y || normalUniformZ != z) {
normalUniformX = x;
normalUniformY = y;
normalUniformZ = z;
_wglUniform3f(u_normalUniform, x, y, z);
}
}
if(tex0Serial != EaglerAdapterGL30.tex0Serial) {
float x = EaglerAdapterGL30.tex0X;
float y = EaglerAdapterGL30.tex0Y;
tex0Serial = EaglerAdapterGL30.tex0Serial;
if(tex0x != x || tex0y != y) {
tex0x = x;
tex0y = y;
_wglUniform2f(u_texCoordV0, x, y);
}
}
if(tex1Serial != EaglerAdapterGL30.tex1Serial) {
float x = EaglerAdapterGL30.tex1X;
float y = EaglerAdapterGL30.tex1Y;
tex1Serial = EaglerAdapterGL30.tex1Serial;
if(tex1x != x || tex1y != y) {
tex1x = x;
tex1y = y;
_wglUniform2f(u_texCoordV1, x, y);
}
}
if(texPlaneSerial != EaglerAdapterGL30.texPlaneSerial) {
int s = EaglerAdapterGL30.texS_plane;
int t = EaglerAdapterGL30.texT_plane;
int r = EaglerAdapterGL30.texR_plane;
int q = EaglerAdapterGL30.texQ_plane;
texPlaneSerial = EaglerAdapterGL30.texPlaneSerial;
if(texS_plane != s || texT_plane != t || texR_plane != r || texQ_plane != q) {
texS_plane = s;
texT_plane = t;
texR_plane = r;
texQ_plane = q;
_wglUniform4i(u_textureGen_M, s, t, r, q);
}
}
if(texSSerial != EaglerAdapterGL30.texSSerial) {
float x = EaglerAdapterGL30.texS_X;
float y = EaglerAdapterGL30.texS_Y;
float z = EaglerAdapterGL30.texS_Z;
float w = EaglerAdapterGL30.texS_W;
texSSerial = EaglerAdapterGL30.texSSerial;
if(texS_X != x || texS_Y != y || texS_Z != z || texS_W != w) {
texS_X = x;
texS_Y = y;
texS_Z = z;
texS_W = w;
_wglUniform4f(u_textureGenS_V, x, y, z, w);
}
}
if(texTSerial != EaglerAdapterGL30.texTSerial) {
float x = EaglerAdapterGL30.texT_X;
float y = EaglerAdapterGL30.texT_Y;
float z = EaglerAdapterGL30.texT_Z;
float w = EaglerAdapterGL30.texT_W;
texTSerial = EaglerAdapterGL30.texTSerial;
if(texT_X != x || texT_Y != y || texT_Z != z || texT_W != w) {
texT_X = x;
texT_Y = y;
texT_Z = z;
texT_W = w;
_wglUniform4f(u_textureGenT_V, x, y, z, w);
}
}
if(texRSerial != EaglerAdapterGL30.texRSerial) {
float x = EaglerAdapterGL30.texR_X;
float y = EaglerAdapterGL30.texR_Y;
float z = EaglerAdapterGL30.texR_Z;
float w = EaglerAdapterGL30.texR_W;
texRSerial = EaglerAdapterGL30.texRSerial;
if(texR_X != x || texR_Y != y || texR_Z != z || texR_W != w) {
texR_X = x;
texR_Y = y;
texR_Z = z;
texR_W = w;
_wglUniform4f(u_textureGenR_V, x, y, z, w);
}
}
if(texQSerial != EaglerAdapterGL30.texQSerial) {
float x = EaglerAdapterGL30.texQ_X;
float y = EaglerAdapterGL30.texQ_Y;
float z = EaglerAdapterGL30.texQ_Z;
float w = EaglerAdapterGL30.texQ_W;
texQSerial = EaglerAdapterGL30.texQSerial;
if(texQ_X != x || texQ_Y != y || texQ_Z != z || texQ_W != w) {
texQ_X = x;
texQ_Y = y;
texQ_Z = z;
texQ_W = w;
_wglUniform4f(u_textureGenQ_V, x, y, z, w);
}
}
if(fogColorSerial != EaglerAdapterGL30.fogColorSerial) {
float r = EaglerAdapterGL30.fogColorR;
float g = EaglerAdapterGL30.fogColorG;
float b = EaglerAdapterGL30.fogColorB;
float a = EaglerAdapterGL30.fogColorA;
fogColorSerial = EaglerAdapterGL30.fogColorSerial;
if(fogColorR != r || fogColorG != g || fogColorB != b || fogColorA != a) {
fogColorR = r;
fogColorG = g;
fogColorB = b;
fogColorA = a;
_wglUniform4f(u_fogColor, r, g, b, a);
}
}
if(fogCfgSerial != EaglerAdapterGL30.fogCfgSerial) {
int fogModex = EaglerAdapterGL30.fogMode;
float fogStarty = EaglerAdapterGL30.fogStart;
float fogEndz = EaglerAdapterGL30.fogEnd - fogStarty;
float fogDensityw = EaglerAdapterGL30.fogDensity;
fogCfgSerial = EaglerAdapterGL30.fogCfgSerial;
if(fogMode != fogModex || fogStart != fogStarty ||
fogEnd != fogEndz || fogDensity != fogDensityw) {
fogMode = fogModex;
fogStart = fogStarty;
fogEnd = fogEndz;
fogDensity = fogDensityw;
_wglUniform4f(u_fogParam, fogModex, fogStarty, fogEndz, fogDensityw);
}
}
float limit = EaglerAdapterGL30.alphaThresh;
if(alphaTestValue != limit) {
alphaTestValue = limit;
_wglUniform1f(u_alphaTestF, limit);
}
float[] matCopyBuffer = matBuffer;
int i = EaglerAdapterGL30.matModelPointer;
int j = EaglerAdapterGL30.matModelVSerial[i];
if(matModelSerialCounter != j) {
matModelSerialCounter = j;
EaglerAdapterGL30.matModelV[i].store(matCopyBuffer);
_wglUniformMat4fv(u_matrix_m, matCopyBuffer);
}
i = EaglerAdapterGL30.matProjPointer;
j = EaglerAdapterGL30.matProjVSerial[i];
if(matProjSerialCounter != j) {
matProjSerialCounter = j;
EaglerAdapterGL30.matProjV[i].store(matCopyBuffer);
_wglUniformMat4fv(u_matrix_p, matCopyBuffer);
}
i = EaglerAdapterGL30.matTexPointer;
j = EaglerAdapterGL30.matTexVSerial[i];
if(matTexSerialCounter != j) {
matTexSerialCounter = j;
EaglerAdapterGL30.matTexV[i].store(matCopyBuffer);
_wglUniformMat4fv(u_matrix_t, matCopyBuffer);
}
if(lightPos0Serial != EaglerAdapterGL30.lightPos0Serial) {
lightPos0Serial = EaglerAdapterGL30.lightPos0Serial;
Vector4f pos = EaglerAdapterGL30.lightPos0vec;
if(!pos.equals(light0Pos)) {
light0Pos.set(pos);
_wglUniform3f(u_light0Pos, pos.x, pos.y, pos.z);
}
}
if(lightPos1Serial != EaglerAdapterGL30.lightPos1Serial) {
lightPos1Serial = EaglerAdapterGL30.lightPos1Serial;
Vector4f pos = EaglerAdapterGL30.lightPos1vec;
if(!pos.equals(light1Pos)) {
light1Pos.set(pos);
_wglUniform3f(u_light1Pos, pos.x, pos.y, pos.z);
}
}
}