Add u_colormask and use it in enableColorTest

This commit is contained in:
raven02 2013-02-25 05:42:23 +08:00
parent 7140ef01a4
commit d99ca71a47
3 changed files with 9 additions and 4 deletions

View File

@ -94,6 +94,7 @@ void GenerateFragmentShader(char *buffer)
WRITE(p, "uniform sampler2D tex;\n");
if (enableAlphaTest || enableColorTest) {
WRITE(p, "uniform vec4 u_alphacolorref;\n");
WRITE(p, "uniform vec4 u_colormask;\n");
}
if (gstate.textureMapEnable & 1) {
WRITE(p, "uniform vec3 u_texenv;\n");
@ -189,9 +190,8 @@ void GenerateFragmentShader(char *buffer)
const char *colorTestFuncs[] = { "#", "#", " == ", " != " }; // never/always don't make sense}
int colorTestMask = gstate.colormask;
if (colorTestFuncs[colorTestFunc][0] != '#')
WRITE(p, "if (!(v.rgb %s u_alphacolorref.rgb)) discard;\n", colorTestFuncs[colorTestFunc]);
}*/
WRITE(p, "if (!(v.rgb %s (u_alphacolorref.rgb & u_colormask.rgb)) discard;\n", colorTestFuncs[colorTestFunc]);
}*/
if (enableFog) {
WRITE(p, " float fogCoef = clamp(v_fogdepth, 0.0, 1.0);\n");
WRITE(p, " gl_FragColor = mix(vec4(u_fogcolor, v.a), v, fogCoef);\n");

View File

@ -89,6 +89,7 @@ LinkedShader::LinkedShader(Shader *vs, Shader *fs)
u_fogcolor = glGetUniformLocation(program, "u_fogcolor");
u_fogcoef = glGetUniformLocation(program, "u_fogcoef");
u_alphacolorref = glGetUniformLocation(program, "u_alphacolorref");
u_colormask = glGetUniformLocation(program, "u_colormask");
// Transform
u_view = glGetUniformLocation(program, "u_view");
@ -252,6 +253,9 @@ void LinkedShader::updateUniforms() {
if (u_alphacolorref != -1 && (dirtyUniforms & DIRTY_ALPHACOLORREF)) {
SetColorUniform3Alpha(u_alphacolorref, gstate.colorref, (gstate.alphatest >> 8) & 0xFF);
}
if (u_colormask != -1 && (dirtyUniforms & DIRTY_COLORMASK)) {
SetColorUniform3(u_colormask, gstate.colormask);
}
if (u_fogcolor != -1 && (dirtyUniforms & DIRTY_FOGCOLOR)) {
SetColorUniform3(u_fogcolor, gstate.fogcolor);
}

View File

@ -58,6 +58,7 @@ public:
// Fragment processing inputs
int u_alphacolorref;
int u_colormask;
int u_fogcolor;
int u_fogcoef;
@ -88,7 +89,7 @@ enum
DIRTY_TEXENV = (1 << 4),
DIRTY_ALPHACOLORREF = (1 << 5),
DIRTY_COLORREF = (1 << 6),
DIRTY_COLORMASK = (1 << 7),
DIRTY_LIGHT0 = (1 << 8),
DIRTY_LIGHT1 = (1 << 9),
DIRTY_LIGHT2 = (1 << 10),