Alpha testing cleanup in both OpenGL and Direct3D.

This commit is contained in:
Jean-Philip Desjardins 2014-11-22 01:50:17 -05:00
parent a9ae0a446c
commit 993944c75c
3 changed files with 55 additions and 57 deletions

View File

@ -678,45 +678,28 @@ void CGSH_OpenGL::SetupTestFunctions(uint64 nData)
if(tst.nAlphaEnabled)
{
unsigned int nFunc = GL_NEVER;
switch(tst.nAlphaMethod)
static const GLenum g_alphaTestFunc[ALPHA_TEST_MAX] =
{
case 0:
nFunc = GL_NEVER;
break;
case 1:
nFunc = GL_ALWAYS;
break;
case 2:
nFunc = GL_LESS;
break;
case 4:
nFunc = GL_EQUAL;
break;
case 5:
nFunc = GL_GEQUAL;
break;
case 6:
nFunc = GL_GREATER;
break;
case 7:
nFunc = GL_NOTEQUAL;
break;
default:
assert(0);
break;
}
GL_NEVER,
GL_ALWAYS,
GL_LESS,
GL_LEQUAL,
GL_EQUAL,
GL_GEQUAL,
GL_GREATER,
GL_NOTEQUAL
};
//Special way of turning off depth writes:
//Always fail alpha testing but write RGBA and not depth if it fails
if(tst.nAlphaMethod == 0 && tst.nAlphaFail == 1)
if(tst.nAlphaMethod == ALPHA_TEST_NEVER && tst.nAlphaFail == ALPHA_TEST_FAIL_FBONLY)
{
glDisable(GL_ALPHA_TEST);
}
else
{
float nValue = (float)tst.nAlphaRef / 255.0f;
glAlphaFunc(nFunc, nValue);
glAlphaFunc(g_alphaTestFunc[tst.nAlphaMethod], nValue);
glEnable(GL_ALPHA_TEST);
}

View File

@ -570,6 +570,27 @@ protected:
MIN_FILTER_LINEAR_MIP_LINEAR = 5
};
enum ALPHA_TEST_METHOD
{
ALPHA_TEST_NEVER,
ALPHA_TEST_ALWAYS,
ALPHA_TEST_LESS,
ALPHA_TEST_LEQUAL,
ALPHA_TEST_EQUAL,
ALPHA_TEST_GEQUAL,
ALPHA_TEST_GREATER,
ALPHA_TEST_NOTEQUAL,
ALPHA_TEST_MAX
};
enum ALPHA_TEST_FAIL_METHOD
{
ALPHA_TEST_FAIL_KEEP,
ALPHA_TEST_FAIL_FBONLY,
ALPHA_TEST_FAIL_ZBONLY,
ALPHA_TEST_FAIL_RGBONLY
};
//-----------------------------------
//Private Registers

View File

@ -774,36 +774,30 @@ void CGSH_Direct3D9::SetupTestFunctions(uint64 nData)
if(tst.nAlphaEnabled)
{
unsigned int alphaFunc = D3DCMP_NEVER;
switch(tst.nAlphaMethod)
static const D3DCMPFUNC g_alphaTestFunc[ALPHA_TEST_MAX] =
{
case 0:
alphaFunc = D3DCMP_NEVER;
break;
case 1:
alphaFunc = D3DCMP_ALWAYS;
break;
case 2:
alphaFunc = D3DCMP_LESS;
break;
case 5:
alphaFunc = D3DCMP_GREATEREQUAL;
break;
case 6:
alphaFunc = D3DCMP_GREATER;
break;
case 7:
alphaFunc = D3DCMP_NOTEQUAL;
break;
default:
assert(0);
break;
}
D3DCMP_NEVER,
D3DCMP_ALWAYS,
D3DCMP_LESS,
D3DCMP_LESSEQUAL,
D3DCMP_EQUAL,
D3DCMP_GREATEREQUAL,
D3DCMP_GREATER,
D3DCMP_NOTEQUAL
};
m_device->SetRenderState(D3DRS_ALPHAFUNC, alphaFunc);
m_device->SetRenderState(D3DRS_ALPHAREF, tst.nAlphaRef);
m_device->SetRenderState(D3DRS_ALPHATESTENABLE, D3DZB_TRUE);
//Special way of turning off depth writes:
//Always fail alpha testing but write RGBA and not depth if it fails
if(tst.nAlphaMethod == ALPHA_TEST_NEVER && tst.nAlphaFail == ALPHA_TEST_FAIL_FBONLY)
{
m_device->SetRenderState(D3DRS_ALPHATESTENABLE, D3DZB_FALSE);
}
else
{
m_device->SetRenderState(D3DRS_ALPHAFUNC, g_alphaTestFunc[tst.nAlphaMethod]);
m_device->SetRenderState(D3DRS_ALPHAREF, tst.nAlphaRef);
m_device->SetRenderState(D3DRS_ALPHATESTENABLE, D3DZB_TRUE);
}
}
else
{