Alphamasking migrated to shaders instead of using fixed-function. Very early code. Hasn't even made it into viewer-development yet.

This commit is contained in:
Shyotl
2011-08-12 19:20:11 -05:00
parent 8e1c70dcaa
commit f551294e66
34 changed files with 892 additions and 194 deletions

View File

@@ -53,6 +53,7 @@
#include "llstacktrace.h"
#include "llglheaders.h"
#include "llglslshader.h"
#ifdef _DEBUG
//#define GL_STATE_VERIFY
@@ -1642,6 +1643,16 @@ void LLGLState::checkClientArrays(const std::string& msg, U32 data_mask)
LLGLState::LLGLState(LLGLenum state, S32 enabled) :
mState(state), mWasEnabled(FALSE), mIsEnabled(FALSE)
{
if (LLGLSLShader::sNoFixedFunction)
{ //always disable state that's deprecated post GL 3.0
switch (state)
{
case GL_ALPHA_TEST:
enabled = 0;
break;
}
}
stop_glerror();
if (state)
{

View File

@@ -55,6 +55,7 @@ using std::make_pair;
using std::string;
GLhandleARB LLGLSLShader::sCurBoundShader = 0;
LLGLSLShader* LLGLSLShader::sCurBoundShaderPtr = NULL;
bool LLGLSLShader::sNoFixedFunction = false;
//UI shader -- declared here so llui_libtest will link properly
@@ -72,7 +73,7 @@ LLShaderFeatures::LLShaderFeatures()
: calculatesLighting(false), isShiny(false), isFullbright(false), hasWaterFog(false),
hasTransport(false), hasSkinning(false), hasAtmospherics(false), isSpecular(false),
hasGamma(false), hasLighting(false), calculatesAtmospherics(false)
, mIndexedTextureChannels(0), disableTextureIndex(false)
, mIndexedTextureChannels(0), disableTextureIndex(false), hasAlphaMask(false)
#if MESH_ENABLED
, hasObjectSkinning(false)
#endif //MESH_ENABLED
@@ -409,6 +410,7 @@ void LLGLSLShader::bind()
{
glUseProgramObjectARB(mProgramObject);
sCurBoundShader = mProgramObject;
sCurBoundShaderPtr = this;
if (mUniformsDirty)
{
LLShaderMgr::instance()->updateShaderUniforms(this);
@@ -433,6 +435,7 @@ void LLGLSLShader::unbind()
}
glUseProgramObjectARB(0);
sCurBoundShader = 0;
sCurBoundShaderPtr = NULL;
stop_glerror();
}
}
@@ -441,6 +444,7 @@ void LLGLSLShader::bindNoShader(void)
{
glUseProgramObjectARB(0);
sCurBoundShader = 0;
sCurBoundShaderPtr = NULL;
}
S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode)
@@ -986,6 +990,12 @@ void LLGLSLShader::uniformMatrix4fv(const string& uniform, U32 count, GLboolean
}
}
void LLGLSLShader::setAlphaRange(F32 minimum, F32 maximum)
{
uniform1f("minimum_alpha", minimum);
uniform1f("maximum_alpha", maximum);
}
void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{

View File

@@ -55,6 +55,7 @@ public:
bool hasGamma;
S32 mIndexedTextureChannels;
bool disableTextureIndex;
bool hasAlphaMask;
// char numLights;
@@ -75,6 +76,7 @@ public:
LLGLSLShader(S32 shader_class);
static GLhandleARB sCurBoundShader;
static LLGLSLShader* sCurBoundShaderPtr;
static bool sNoFixedFunction;
void unload();
@@ -113,6 +115,8 @@ public:
void uniformMatrix3fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
void uniformMatrix4fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
void setAlphaRange(F32 minimum, F32 maximum);
void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void vertexAttrib4fv(U32 index, GLfloat* v);

View File

@@ -1092,6 +1092,10 @@ void LLRender::setSceneBlendType(eBlendType type)
void LLRender::setAlphaRejectSettings(eCompareFunc func, F32 value)
{
flush();
if (LLGLSLShader::sNoFixedFunction)
{ //glAlphaFunc is deprecated in OpenGL 3.3
return;
}
if (mCurrAlphaFunc != func ||
mCurrAlphaFuncVal != value)
@@ -1107,6 +1111,30 @@ void LLRender::setAlphaRejectSettings(eCompareFunc func, F32 value)
glAlphaFunc(sGLCompareFunc[func], value);
}
}
if (gDebugGL)
{ //make sure cached state is correct
GLint cur_func = 0;
glGetIntegerv(GL_ALPHA_TEST_FUNC, &cur_func);
if (func == CF_DEFAULT)
{
func = CF_GREATER;
}
if (cur_func != sGLCompareFunc[func])
{
llerrs << "Alpha test function corrupted!" << llendl;
}
F32 ref = 0.f;
glGetFloatv(GL_ALPHA_TEST_REF, &ref);
if (ref != value)
{
llerrs << "Alpha test value corrupted!" << llendl;
}
}
}
void LLRender::blendFunc(eBlendFactor sfactor, eBlendFactor dfactor)

View File

@@ -219,16 +219,36 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
{
if (features->disableTextureIndex)
{
if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl"))
if (features->hasAlphaMask)
{
return FALSE;
if (!shader->attachObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl"))
{
return FALSE;
}
}
}
else
{
if (!shader->attachObject("lighting/lightWaterF.glsl"))
if (features->hasAlphaMask)
{
return FALSE;
if (!shader->attachObject("lighting/lightWaterAlphaMaskF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightWaterF.glsl"))
{
return FALSE;
}
}
shader->mFeatures.mIndexedTextureChannels = gGLManager.mNumTextureImageUnits-1;
}
@@ -238,16 +258,36 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
{
if (features->disableTextureIndex)
{
if (!shader->attachObject("lighting/lightNonIndexedF.glsl"))
if (features->hasAlphaMask)
{
return FALSE;
if (!shader->attachObject("lighting/lightAlphaMaskNonIndexedF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightNonIndexedF.glsl"))
{
return FALSE;
}
}
}
else
{
if (!shader->attachObject("lighting/lightF.glsl"))
if (features->hasAlphaMask)
{
return FALSE;
if (!shader->attachObject("lighting/lightAlphaMaskF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightF.glsl"))
{
return FALSE;
}
}
shader->mFeatures.mIndexedTextureChannels = gGLManager.mNumTextureImageUnits-1;
}
@@ -280,14 +320,28 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
{
if (features->disableTextureIndex)
{
if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl"))
if (features->hasAlphaMask)
{
if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl"))
{
return FALSE;
}
}
else if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl"))
if (features->hasAlphaMask)
{
if (!shader->attachObject("lighting/lightFullbrightWaterAlphaMaskF.glsl"))
{
return FALSE;
}
}
else if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl"))
{
return FALSE;
}
@@ -318,16 +372,37 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
{
if (features->disableTextureIndex)
{
if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl"))
if (features->hasAlphaMask)
{
return FALSE;
if (!shader->attachObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl"))
{
return FALSE;
}
}
}
else
{
if (!shader->attachObject("lighting/lightFullbrightF.glsl"))
if (features->hasAlphaMask)
{
return FALSE;
if (!shader->attachObject("lighting/lightFullbrightAlphaMaskF.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("lighting/lightFullbrightF.glsl"))
{
return FALSE;
}
}
shader->mFeatures.mIndexedTextureChannels = gGLManager.mNumTextureImageUnits-1;
}