Don't use dual source when stencil disabled

This commit is contained in:
Henrik Rydgard 2013-12-16 23:41:42 +01:00
parent 068d4f0ee5
commit a9a15d5196
3 changed files with 15 additions and 10 deletions

View File

@ -129,7 +129,7 @@ ReplaceAlphaType ReplaceAlphaWithStencil() {
}
if (gl_extensions.ARB_blend_func_extended) {
return REPLACE_ALPHA_YES;
return REPLACE_ALPHA_DUALSOURCE;
}
if (gstate.isAlphaBlendEnabled()) {
@ -365,7 +365,7 @@ void GenerateFragmentShader(char *buffer) {
bool doTextureAlpha = gstate.isTextureAlphaUsed();
ReplaceAlphaType stencilToAlpha;
if (!gstate.isModeClear()) {
if (gstate.isModeClear()) {
stencilToAlpha = REPLACE_ALPHA_NO;
} else {
stencilToAlpha = ReplaceAlphaWithStencil();
@ -412,7 +412,8 @@ void GenerateFragmentShader(char *buffer) {
else
WRITE(p, "vec3 roundAndScaleTo255v(in vec3 x) { return floor(x * 255.0 + 0.5); }\n");
}
if (gl_extensions.ARB_blend_func_extended) {
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
WRITE(p, "out vec4 fragColor0;\n");
WRITE(p, "out vec4 fragColor1;\n");
} else if (gl_extensions.VersionGEThan(3, 0, 0)) {
@ -527,14 +528,16 @@ void GenerateFragmentShader(char *buffer) {
}
}
if (gl_extensions.ARB_blend_func_extended) {
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
WRITE(p, " fragColor0 = vec4(v.rgb, 0.0);\n");
WRITE(p, " fragColor1 = vec4(0.0, 0.0, 0.0, v.a);\n");
} else {
} else if (stencilToAlpha == REPLACE_ALPHA_YES) {
WRITE(p, " %s = vec4(v.rgb, 0.0);\n", fragColor0);
} else { // stencilToAlpha == REPLACE_ALPHA_NO
WRITE(p, " %s = v;\n", fragColor0);
}
if (stencilToAlpha) {
if (stencilToAlpha != REPLACE_ALPHA_NO) {
switch (ReplaceAlphaWithStencilType()) {
case STENCIL_VALUE_UNIFORM:
WRITE(p, " %s.a = u_stencilReplaceValue;\n", fragColor0);

View File

@ -53,8 +53,9 @@ enum StencilValueType {
};
enum ReplaceAlphaType {
REPLACE_ALPHA_NO,
REPLACE_ALPHA_YES,
REPLACE_ALPHA_NO = 0,
REPLACE_ALPHA_YES = 1,
REPLACE_ALPHA_DUALSOURCE = 2,
};
StencilValueType ReplaceAlphaWithStencilType();

View File

@ -193,7 +193,8 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
if (blendFuncB > GE_DSTBLEND_FIXB) blendFuncB = GE_DSTBLEND_FIXB;
float constantAlpha = 1.0f;
if (gstate.isStencilTestEnabled() && ReplaceAlphaWithStencil() == REPLACE_ALPHA_NO) {
int replaceAlphaWithStencil = gstate.isStencilTestEnabled() ? ReplaceAlphaWithStencil() : REPLACE_ALPHA_NO;
if (gstate.isStencilTestEnabled() && replaceAlphaWithStencil == REPLACE_ALPHA_NO) {
if (ReplaceAlphaWithStencilType() == STENCIL_VALUE_UNIFORM) {
constantAlpha = (float) gstate.getStencilTestRef() * (1.0f / 255.0f);
}
@ -203,7 +204,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
GLuint glBlendFuncA = blendFuncA == GE_SRCBLEND_FIXA ? blendColor2Func(gstate.getFixA()) : aLookup[blendFuncA];
GLuint glBlendFuncB = blendFuncB == GE_DSTBLEND_FIXB ? blendColor2Func(gstate.getFixB()) : bLookup[blendFuncB];
if (gl_extensions.ARB_blend_func_extended) {
if (replaceAlphaWithStencil == REPLACE_ALPHA_DUALSOURCE) {
glBlendFuncA = toDualSource(glBlendFuncA);
glBlendFuncB = toDualSource(glBlendFuncB);
}