From a7ba5145cc7d9890c508cd7080db1f3f20e82e24 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Sat, 23 May 2015 17:16:02 -0500 Subject: [PATCH] Inline shader uniform setters, and cache values in vectors instead of maps. Also, deleted mUniformNameMap, mUniformNameMap, and uniform2i, as they were unused. --- indra/llrender/llglslshader.cpp | 501 +------------------------------- indra/llrender/llglslshader.h | 286 ++++++++++++++++-- 2 files changed, 259 insertions(+), 528 deletions(-) diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 19c2722e7..7e11ffcf0 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -38,12 +38,6 @@ #include "OpenGL/OpenGL.h" #endif -#ifdef LL_RELEASE_FOR_DOWNLOAD -#define UNIFORM_ERRS LL_WARNS_ONCE("Shader") -#else -#define UNIFORM_ERRS LL_ERRS("Shader") -#endif - // Lots of STL stuff in here, using namespace std to keep things more readable using std::vector; using std::pair; @@ -431,7 +425,6 @@ void LLGLSLShader::mapUniform(GLint index, const vector * } LLStaticHashedString hashedName(name); - mUniformNameMap[location] = name; mUniformMap[hashedName] = location; LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL; @@ -496,9 +489,10 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) mActiveTextureChannels = 0; mUniform.clear(); mUniformMap.clear(); - mUniformNameMap.clear(); mTexture.clear(); - mValue.clear(); + mValueVec4.clear(); + mValueMat3.clear(); + mValueMat4.clear(); //initialize arrays U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); @@ -671,326 +665,6 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) return index; } -void LLGLSLShader::uniform1i(U32 index, GLint x) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - if (iter == mValue.end() || iter->second.mV[0] != x) - { - glUniform1iARB(mUniform[index], x); - mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); - } - } - } -} - -void LLGLSLShader::uniform1f(U32 index, GLfloat x) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - if (iter == mValue.end() || iter->second.mV[0] != x) - { - glUniform1fARB(mUniform[index], x); - mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); - } - } - } -} - -void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(x,y,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform2fARB(mUniform[index], x, y); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(x,y,z,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform3fARB(mUniform[index], x, y, z); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(x,y,z,w); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform4fARB(mUniform[index], x, y, z, w); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform1ivARB(mUniform[index], count, v); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform1fvARB(mUniform[index], count, v); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],v[1],0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform2fvARB(mUniform[index], count, v); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],v[1],v[2],0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform3fvARB(mUniform[index], count, v); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - std::map::iterator iter = mValue.find(mUniform[index]); - LLVector4 vec(v[0],v[1],v[2],v[3]); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform4fvARB(mUniform[index], count, v); - mValue[mUniform[index]] = vec; - } - } - } -} - -void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - glUniformMatrix2fvARB(mUniform[index], count, transpose, v); - } - } -} - -void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - glUniformMatrix3fvARB(mUniform[index], count, transpose, v); - } - } -} - -void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - glUniformMatrix3x4fv(mUniform[index], count, transpose, v); - } - } -} - -void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) -{ - if (mProgramObject > 0) - { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } - - if (mUniform[index] >= 0) - { - glUniformMatrix4fvARB(mUniform[index], count, transpose, v); - } - } -} - -GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform) -{ - GLint ret = -1; - if (mProgramObject > 0) - { - LLStaticStringTable::iterator iter = mUniformMap.find(uniform); - if (iter != mUniformMap.end()) - { - if (gDebugGL) - { - stop_glerror(); - if (iter->second != glGetUniformLocationARB(mProgramObject, uniform.String().c_str())) - { - llerrs << "Uniform does not match." << llendl; - } - stop_glerror(); - } - ret = iter->second; - } - } - - return ret; -} - GLint LLGLSLShader::getUniformLocation(U32 index) { GLint ret = -1; @@ -1015,167 +689,6 @@ GLint LLGLSLShader::getAttribLocation(U32 attrib) } } -void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(v,0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform1iARB(location, v); - mValue[location] = vec; - } - } -} - -void LLGLSLShader::uniform2i(const LLStaticHashedString& uniform, GLint i, GLint j) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(i,j,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform2iARB(location, i, j); - mValue[location] = vec; - } - } -} - - -void LLGLSLShader::uniform1f(const LLStaticHashedString& uniform, GLfloat v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(v,0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform1fARB(location, v); - mValue[location] = vec; - } - } -} - -void LLGLSLShader::uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(x,y,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform2fARB(location, x,y); - mValue[location] = vec; - } - } - -} - -void LLGLSLShader::uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y, GLfloat z) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(x,y,z,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec)) - { - glUniform3fARB(location, x,y,z); - mValue[location] = vec; - } - } -} - -void LLGLSLShader::uniform1fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(v[0],0.f,0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform1fvARB(location, count, v); - mValue[location] = vec; - } - } -} - -void LLGLSLShader::uniform2fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(v[0],v[1],0.f,0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform2fvARB(location, count, v); - mValue[location] = vec; - } - } -} - -void LLGLSLShader::uniform3fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - std::map::iterator iter = mValue.find(location); - LLVector4 vec(v[0],v[1],v[2],0.f); - if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1) - { - glUniform3fvARB(location, count, v); - mValue[location] = vec; - } - } -} - -void LLGLSLShader::uniform4fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - LLVector4 vec(v); - std::map::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; - } - } -} - -void LLGLSLShader::uniformMatrix4fv(const LLStaticHashedString& uniform, U32 count, GLboolean transpose, const GLfloat* v) -{ - GLint location = getUniformLocation(uniform); - - if (location >= 0) - { - stop_glerror(); - glUniformMatrix4fvARB(location, count, transpose, v); - stop_glerror(); - } -} - - void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { if (mAttribute[index] > 0) @@ -1184,14 +697,6 @@ void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GL } } -void LLGLSLShader::vertexAttrib4fv(U32 index, GLfloat* v) -{ - if (mAttribute[index] > 0) - { - glVertexAttrib4fvARB(mAttribute[index], v); - } -} - void LLGLSLShader::setMinimumAlpha(F32 minimum) { gGL.flush(); diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index a530d2658..c5fc3abca 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -30,6 +30,11 @@ #include "llgl.h" #include "llrender.h" #include "llstaticstringtable.h" +#ifdef LL_RELEASE_FOR_DOWNLOAD +#define UNIFORM_ERRS LL_WARNS_ONCE("Shader") +#else +#define UNIFORM_ERRS LL_ERRS("Shader") +#endif class LLShaderFeatures { @@ -87,38 +92,256 @@ public: BOOL mapAttributes(const std::vector * attributes); BOOL mapUniforms(const std::vector *); void mapUniform(GLint index, const std::vector *); - void uniform1i(U32 index, GLint i); - void uniform1f(U32 index, GLfloat v); - void uniform2f(U32 index, GLfloat x, GLfloat y); - void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z); - void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); - void uniform1iv(U32 index, U32 count, const GLint* i); - void uniform1fv(U32 index, U32 count, const GLfloat* v); - void uniform2fv(U32 index, U32 count, const GLfloat* v); - void uniform3fv(U32 index, U32 count, const GLfloat* v); - void uniform4fv(U32 index, U32 count, const GLfloat* v); - void uniform2i(const LLStaticHashedString& uniform, GLint i, GLint j); - void uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); - void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); - void uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); - void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); - void uniform1i(const LLStaticHashedString& uniform, GLint i); - void uniform1f(const LLStaticHashedString& uniform, GLfloat v); - void uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y); - void uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y, GLfloat z); - void uniform1fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v); - void uniform2fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v); - void uniform3fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v); - void uniform4fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v); - void uniformMatrix4fv(const LLStaticHashedString& uniform, U32 count, GLboolean transpose, const GLfloat *v); + S32 getUniformFromIndex(const U32 index) + { + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return -1; + } + return mUniform[index]; + } + template + S32 updateUniform(std::vector >& cache, S32 uniform, const F32* val) + { + if (mProgramObject > 0) + { + if (uniform >= 0) + { + std::vector >::iterator iter = std::find_if(cache.begin(), cache.end(), boost::bind(&std::pair::first, _1) == uniform); + if (iter == cache.end()) + { + T tmp; + memcpy(&tmp, val, sizeof(F32)*N); + cache.push_back(std::make_pair(uniform, tmp)); + return true; + } + else if (memcmp(&iter->second, val, sizeof(F32)*N)) + { + memcpy(&iter->second, val, sizeof(F32)*N); + return true; + } + } + } + return false; + } + void uniform1i(U32 index, GLint x) + { + F32 val = x; + if (updateUniform(mValueVec4, getUniformFromIndex(index), &val)) + { + glUniform1iARB(mUniform[index], x); + } + } + void uniform1f(U32 index, GLfloat x) + { + if (updateUniform(mValueVec4, getUniformFromIndex(index), &x)) + { + glUniform1fARB(mUniform[index], x); + } + } + void uniform2f(U32 index, GLfloat x, GLfloat y) + { + F32 val[] = { x, y }; + if (updateUniform(mValueVec4, getUniformFromIndex(index), val)) + { + glUniform2fARB(mUniform[index], x, y); + } + } + void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) + { + F32 val[] = { x, y, z }; + if (updateUniform(mValueVec4, getUniformFromIndex(index), val)) + { + glUniform3fARB(mUniform[index], x, y, z); + } + } + void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) + { + F32 val[] = { x, y, z, w }; + if (updateUniform(mValueVec4, getUniformFromIndex(index), val)) + { + glUniform4fARB(mUniform[index], x, y, z, w); + } + } + void uniform1iv(U32 index, U32 count, const GLint* v) + { + F32 val[] = { v[0] }; + if (updateUniform(mValueVec4, getUniformFromIndex(index), val) || count > 1) + { + glUniform1ivARB(mUniform[index], count, v); + } + } + void uniform1fv(U32 index, U32 count, const GLfloat* v) + { + if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) + { + glUniform1fvARB(mUniform[index], count, v); + } + } + void uniform2fv(U32 index, U32 count, const GLfloat* v) + { + if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) + { + glUniform2fvARB(mUniform[index], count, v); + } + } + void uniform3fv(U32 index, U32 count, const GLfloat* v) + { + if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) + { + glUniform3fvARB(mUniform[index], count, v); + } + } + void uniform4fv(U32 index, U32 count, const GLfloat* v) + { + if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) + { + glUniform4fvARB(mUniform[index], count, v); + } + } + void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) + { + if (updateUniform(mValueMat3, getUniformFromIndex(index), v) || count > 1) + { + glUniformMatrix3fvARB(mUniform[index], count, transpose, v); + } + } + void uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) + { + if (updateUniform(mValueMat4, getUniformFromIndex(index), v) || count > 1) + { + glUniformMatrix3x4fv(mUniform[index], count, transpose, v); + } + } + void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) + { + if (updateUniform(mValueMat4, getUniformFromIndex(index), v) || count > 1) + { + glUniformMatrix4fvARB(mUniform[index], count, transpose, v); + } + } + void uniform1i(const LLStaticHashedString& uniform, GLint i) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + F32 val = i; + if (updateUniform(mValueVec4, getUniformLocation(uniform), &val)) + { + glUniform1iARB(location, i); + } + } + void uniform1f(const LLStaticHashedString& uniform, GLfloat v) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + if (updateUniform(mValueVec4, location, &v)) + { + glUniform1fARB(location, v); + } + } + void uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + F32 val[] = { x, y }; + if (updateUniform(mValueVec4, location, val)) + { + glUniform2fARB(location, x, y); + } + } + void uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y, GLfloat z) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + F32 val[] = { x, y, z }; + if (updateUniform(mValueVec4, location, val)) + { + glUniform3fARB(location, x, y, z); + } + } + void uniform1fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + if (updateUniform(mValueVec4, location, v)) + { + glUniform1fvARB(location, count, v); + } + } + void uniform2fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + if (updateUniform(mValueVec4, location, v)) + { + glUniform2fvARB(location, count, v); + } + } + void uniform3fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + if (updateUniform(mValueVec4, location, v)) + { + glUniform3fvARB(location, count, v); + } + } + void uniform4fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + if (updateUniform(mValueVec4, location, v)) + { + glUniform4fvARB(location, count, v); + } + } + void uniformMatrix4fv(const LLStaticHashedString& uniform, U32 count, GLboolean transpose, const GLfloat *v) + { + GLint location = getUniformLocation(uniform); + if (location < 0) + return; + if (updateUniform(mValueMat4, location, v)) + { + glUniformMatrix4fvARB(location, count, transpose, v); + } + } void setMinimumAlpha(F32 minimum); void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); - void vertexAttrib4fv(U32 index, GLfloat* v); - //GLint getUniformLocation(const std::string& uniform); - GLint getUniformLocation(const LLStaticHashedString& uniform); + GLint getUniformLocation(const LLStaticHashedString& uniform) + { + GLint ret = -1; + if (mProgramObject > 0) + { + LLStaticStringTable::iterator iter = mUniformMap.find(uniform); + if (iter != mUniformMap.end()) + { + if (gDebugGL) + { + stop_glerror(); + if (iter->second != glGetUniformLocationARB(mProgramObject, uniform.String().c_str())) + { + llerrs << "Uniform does not match." << llendl; + } + stop_glerror(); + } + ret = iter->second; + } + } + + return ret; + } GLint getUniformLocation(U32 index); GLint getAttribLocation(U32 attrib); @@ -156,9 +379,12 @@ public: U32 mAttributeMask; //mask of which reserved attributes are set (lines up with LLVertexBuffer::getTypeMask()) std::vector mUniform; //lookup table of uniform enum to uniform location LLStaticStringTable mUniformMap; //lookup map of uniform name to uniform location - std::map mUniformNameMap; //lookup map of uniform location to uniform name - std::map mValue; //lookup map of uniform location to last known value - std::vector mTexture; + //There are less naive ways to do this than just having several vectors for the differing types, but this method is of least complexity and has some inherent type-safety. + std::vector > mValueVec4; //lookup map of uniform location to last known value + std::vector > mValueMat3; //lookup map of uniform location to last known value + std::vector > mValueMat4; //lookup map of uniform location to last known value + + std::vector mTexture; //lookup table of texture uniform enum to texture channel S32 mTotalUniformSize; S32 mActiveTextureChannels; S32 mShaderClass;