diff options
Diffstat (limited to 'indra/llrender/llglslshader.cpp')
-rw-r--r-- | indra/llrender/llglslshader.cpp | 95 |
1 files changed, 69 insertions, 26 deletions
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index f51d83abe4..4b7e639aed 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -31,6 +31,7 @@ #include "llshadermgr.h" #include "llfile.h" #include "llrender.h" +#include "llvertexbuffer.h" #if LL_DARWIN #include "OpenGL/OpenGL.h" @@ -50,6 +51,7 @@ using std::string; GLhandleARB LLGLSLShader::sCurBoundShader = 0; LLGLSLShader* LLGLSLShader::sCurBoundShaderPtr = NULL; +S32 LLGLSLShader::sIndexedTextureChannels = 0; bool LLGLSLShader::sNoFixedFunction = false; //UI shader -- declared here so llui_libtest will link properly @@ -62,10 +64,23 @@ BOOL shouldChange(const LLVector4& v1, const LLVector4& v2) } LLShaderFeatures::LLShaderFeatures() -: calculatesLighting(false), isShiny(false), isFullbright(false), hasWaterFog(false), -hasTransport(false), hasSkinning(false), hasObjectSkinning(false), hasAtmospherics(false), isSpecular(false), -hasGamma(false), hasLighting(false), calculatesAtmospherics(false), mIndexedTextureChannels(0), disableTextureIndex(false), -hasAlphaMask(false) + : atmosphericHelpers(false) + , calculatesLighting(false) + , calculatesAtmospherics(false) + , hasLighting(false) + , isAlphaLighting(false) + , isShiny(false) + , isFullbright(false) + , isSpecular(false) + , hasWaterFog(false) + , hasTransport(false) + , hasSkinning(false) + , hasObjectSkinning(false) + , hasAtmospherics(false) + , hasGamma(false) + , mIndexedTextureChannels(0) + , disableTextureIndex(false) + , hasAlphaMask(false) { } @@ -75,6 +90,7 @@ hasAlphaMask(false) LLGLSLShader::LLGLSLShader() : mProgramObject(0), mActiveTextureChannels(0), mShaderLevel(0), mShaderGroup(SG_DEFAULT), mUniformsDirty(FALSE) { + } void LLGLSLShader::unload() @@ -93,7 +109,12 @@ void LLGLSLShader::unload() glGetAttachedObjectsARB(mProgramObject, 1024, &count, obj); for (GLsizei i = 0; i < count; i++) { - glDeleteObjectARB(obj[i]); +#if !LL_DARWIN + if (glIsProgramARB(obj[i])) +#endif + { + glDeleteObjectARB(obj[i]); + } } glDeleteObjectARB(mProgramObject); @@ -110,17 +131,19 @@ void LLGLSLShader::unload() BOOL LLGLSLShader::createShader(vector<string> * attributes, vector<string> * uniforms) { + //reloading, reset matrix hash values + for (U32 i = 0; i < LLRender::NUM_MATRIX_MODES; ++i) + { + mMatHash[i] = 0xFFFFFFFF; + } + mLightHash = 0xFFFFFFFF; + llassert_always(!mShaderFiles.empty()); BOOL success = TRUE; // Create program mProgramObject = glCreateProgramObjectARB(); - if (gGLManager.mGLVersion < 3.1f) - { //force indexed texture channels to 1 if GL version is old (performance improvement for drivers with poor branching shader model support) - mFeatures.mIndexedTextureChannels = llmin(mFeatures.mIndexedTextureChannels, 1); - } - //compile new source vector< pair<string,GLenum> >::iterator fileIter = mShaderFiles.begin(); for ( ; fileIter != mShaderFiles.end(); fileIter++ ) @@ -143,8 +166,9 @@ BOOL LLGLSLShader::createShader(vector<string> * attributes, return FALSE; } - if (gGLManager.mGLVersion < 3.1f) - { //attachShaderFeatures may have set the number of indexed texture channels, so set to 1 again + if (gGLManager.mGLSLVersionMajor < 2 && gGLManager.mGLSLVersionMinor < 3) + { //indexed texture rendering requires GLSL 1.3 or later + //attachShaderFeatures may have set the number of indexed texture channels, so set to 1 again mFeatures.mIndexedTextureChannels = llmin(mFeatures.mIndexedTextureChannels, 1); } @@ -235,6 +259,13 @@ void LLGLSLShader::attachObjects(GLhandleARB* objects, S32 count) BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes) { + //before linking, make sure reserved attributes always have consistent locations + for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++) + { + const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str(); + glBindAttribLocationARB(mProgramObject, i, (const GLcharARB *) name); + } + //link the program BOOL res = link(); @@ -308,7 +339,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms) for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) { if ( (mUniform[i] == -1) - && (LLShaderMgr::instance()->mReservedUniforms[i].compare(0, length, name, LLShaderMgr::instance()->mReservedUniforms[i].length()) == 0)) + && (LLShaderMgr::instance()->mReservedUniforms[i] == name)) { //found it mUniform[i] = location; @@ -322,7 +353,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms) for (U32 i = 0; i < uniforms->size(); i++) { if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) - && ((*uniforms)[i].compare(0, length, name, (*uniforms)[i].length()) == 0)) + && ((*uniforms)[i] == name)) { //found it mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; @@ -386,6 +417,7 @@ void LLGLSLShader::bind() gGL.flush(); if (gGLManager.mHasShaderObjects) { + LLVertexBuffer::unbind(); glUseProgramObjectARB(mProgramObject); sCurBoundShader = mProgramObject; sCurBoundShaderPtr = this; @@ -411,6 +443,7 @@ void LLGLSLShader::unbind() stop_glerror(); } } + LLVertexBuffer::unbind(); glUseProgramObjectARB(0); sCurBoundShader = 0; sCurBoundShaderPtr = NULL; @@ -420,9 +453,13 @@ void LLGLSLShader::unbind() void LLGLSLShader::bindNoShader(void) { - glUseProgramObjectARB(0); - sCurBoundShader = 0; - sCurBoundShaderPtr = NULL; + LLVertexBuffer::unbind(); + if (gGLManager.mHasShaderObjects) + { + glUseProgramObjectARB(0); + sCurBoundShader = 0; + sCurBoundShaderPtr = NULL; + } } S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) @@ -768,13 +805,17 @@ GLint LLGLSLShader::getUniformLocation(const string& uniform) } } - /*if (gDebugGL) + return ret; +} + +GLint LLGLSLShader::getUniformLocation(U32 index) +{ + GLint ret = -1; + if (mProgramObject > 0) { - if (ret == -1 && ret != glGetUniformLocationARB(mProgramObject, uniform.c_str())) - { - llerrs << "Uniform map invalid." << llendl; - } - }*/ + llassert(index < mUniform.size()); + return mUniform[index]; + } return ret; } @@ -930,7 +971,9 @@ void LLGLSLShader::uniform4fv(const string& uniform, U32 count, const GLfloat* v std::map<GLint, LLVector4>::iterator iter = mValue.find(location); if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) { + stop_glerror(); glUniform4fvARB(location, count, v); + stop_glerror(); mValue[location] = vec; } } @@ -985,8 +1028,8 @@ void LLGLSLShader::vertexAttrib4fv(U32 index, GLfloat* v) } } -void LLGLSLShader::setAlphaRange(F32 minimum, F32 maximum) +void LLGLSLShader::setMinimumAlpha(F32 minimum) { - uniform1f("minimum_alpha", minimum); - uniform1f("maximum_alpha", maximum); + gGL.flush(); + uniform1f(LLShaderMgr::MINIMUM_ALPHA, minimum); } |