Skip to content

Commit

Permalink
Merge pull request hrydgard#1602 from unknownbrackets/gpu-minor
Browse files Browse the repository at this point in the history
Double alpha at least for the src case
  • Loading branch information
hrydgard committed Apr 30, 2013
2 parents 833596e + 320951a commit 5247041
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
8 changes: 8 additions & 0 deletions GPU/GLES/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue();
bool enableColorTest = gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue();
bool enableColorDoubling = (gstate.texfunc & 0x10000) != 0;
bool enableAlphaDoubling = gstate.getBlendFuncA() == GE_SRCBLEND_DOUBLESRCALPHA || gstate.getBlendFuncB() == GE_DSTBLEND_DOUBLESRCALPHA;
bool doTextureProjection = gstate.getUVGenMode() == 1;

// id->d[0] |= (gstate.clearmode & 1);
Expand All @@ -105,6 +106,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
id->d[0] |= (enableFog & 1) << 15;
id->d[0] |= (doTextureProjection & 1) << 16;
id->d[0] |= (enableColorDoubling & 1) << 17;
id->d[0] |= (enableAlphaDoubling & 1) << 18;
}
}

Expand All @@ -125,6 +127,8 @@ void GenerateFragmentShader(char *buffer) {
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !gstate.isModeClear();
bool enableColorTest = gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue() && !gstate.isModeClear();
bool enableColorDoubling = (gstate.texfunc & 0x10000) != 0;
// TODO: This only does one of the four possible modes.
bool enableAlphaDoubling = gstate.getBlendFuncA() == GE_SRCBLEND_DOUBLESRCALPHA || gstate.getBlendFuncB() == GE_DSTBLEND_DOUBLESRCALPHA;
bool doTextureProjection = gstate.getUVGenMode() == 1;

if (doTexture)
Expand Down Expand Up @@ -233,6 +237,10 @@ void GenerateFragmentShader(char *buffer) {
WRITE(p, " if (v.a %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]);
}
}

if (enableAlphaDoubling) {
WRITE(p, " v.a = v.a * 2.0;\n");
}

if (enableColorTest) {
int colorTestFunc = gstate.colortest & 3;
Expand Down
6 changes: 6 additions & 0 deletions GPU/GLES/StateMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GPU/ge_constants.h"
#include "Core/System.h"
#include "Core/Config.h"
#include "Core/Reporting.h"
#include "DisplayListInterpreter.h"
#include "ShaderManager.h"
#include "TextureCache.h"
Expand Down Expand Up @@ -171,6 +172,11 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
const float blendColor[4] = {(fixA & 0xFF)/255.0f, ((fixA >> 8) & 0xFF)/255.0f, ((fixA >> 16) & 0xFF)/255.0f, 1.0f};
glstate.blendColor.set(blendColor);
} else {
static bool didReportBlend = false;
if (!didReportBlend)
Reporting::ReportMessage("ERROR INVALID blendcolorstate: FixA=%06x FixB=%06x FuncA=%i FuncB=%i", gstate.getFixA(), gstate.getFixB(), gstate.getBlendFuncA(), gstate.getBlendFuncB());
didReportBlend = true;

DEBUG_LOG(HLE, "ERROR INVALID blendcolorstate: FixA=%06x FixB=%06x FuncA=%i FuncB=%i", gstate.getFixA(), gstate.getFixB(), gstate.getBlendFuncA(), gstate.getBlendFuncB());
glBlendFuncA = GL_ONE;
glBlendFuncB = GL_ONE;
Expand Down
40 changes: 39 additions & 1 deletion GPU/GeDisasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,45 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer) {
break;

case GE_CMD_BLENDMODE:
sprintf(buffer, "Blend mode: %06x", data);
{
const char *blendModes[] = {
"add",
"subtract",
"reverse subtract",
"min",
"max",
"abs subtract",
"unsupported1",
"unsupported2",
};
const char *blendFactors[] = {
"a",
"1.0 - a",
"src.a",
"1.0 - src.a",
"dst.a",
"1.0 - dst.a",
"2.0 * src.a",
"1.0 - 2.0 * src.a",
"2.0 * dst.a",
"1.0 - 2.0 * dst.a",
"fixed",
"fixed2",
"fixed3",
"fixed4",
"fixed5",
"fixed6",
};

const char *blendFactorA = blendFactors[(data >> 0) & 0xF];
const char *blendFactorB = blendFactors[(data >> 4) & 0xF];
const char *blendMode = blendModes[(data >> 8) & 0x7];

if (data & ~0xFF0007FF)
sprintf(buffer, "Blend mode: %s %s, %s (extra: %06x)", blendMode, blendFactorA, blendFactorB, data & ~0xFF0007FF);
else
sprintf(buffer, "Blend mode: %s %s, %s", blendMode, blendFactorA, blendFactorB);
}
break;

case GE_CMD_BLENDFIXEDA:
Expand Down

0 comments on commit 5247041

Please sign in to comment.