Inline shader uniform setters, and cache values in vectors instead of maps. Also, deleted mUniformNameMap, mUniformNameMap, and uniform2i, as they were unused.
This commit is contained in:
@@ -38,12 +38,6 @@
|
|||||||
#include "OpenGL/OpenGL.h"
|
#include "OpenGL/OpenGL.h"
|
||||||
#endif
|
#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
|
// Lots of STL stuff in here, using namespace std to keep things more readable
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
@@ -431,7 +425,6 @@ void LLGLSLShader::mapUniform(GLint index, const vector<LLStaticHashedString> *
|
|||||||
}
|
}
|
||||||
|
|
||||||
LLStaticHashedString hashedName(name);
|
LLStaticHashedString hashedName(name);
|
||||||
mUniformNameMap[location] = name;
|
|
||||||
mUniformMap[hashedName] = location;
|
mUniformMap[hashedName] = location;
|
||||||
|
|
||||||
LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL;
|
LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL;
|
||||||
@@ -496,9 +489,10 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
|||||||
mActiveTextureChannels = 0;
|
mActiveTextureChannels = 0;
|
||||||
mUniform.clear();
|
mUniform.clear();
|
||||||
mUniformMap.clear();
|
mUniformMap.clear();
|
||||||
mUniformNameMap.clear();
|
|
||||||
mTexture.clear();
|
mTexture.clear();
|
||||||
mValue.clear();
|
mValueVec4.clear();
|
||||||
|
mValueMat3.clear();
|
||||||
|
mValueMat4.clear();
|
||||||
//initialize arrays
|
//initialize arrays
|
||||||
U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size();
|
U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size();
|
||||||
mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1);
|
mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1);
|
||||||
@@ -671,326 +665,6 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode)
|
|||||||
return index;
|
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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint>::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 LLGLSLShader::getUniformLocation(U32 index)
|
||||||
{
|
{
|
||||||
GLint ret = -1;
|
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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<GLint, LLVector4>::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<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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
|
||||||
{
|
{
|
||||||
if (mAttribute[index] > 0)
|
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)
|
void LLGLSLShader::setMinimumAlpha(F32 minimum)
|
||||||
{
|
{
|
||||||
gGL.flush();
|
gGL.flush();
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
#include "llgl.h"
|
#include "llgl.h"
|
||||||
#include "llrender.h"
|
#include "llrender.h"
|
||||||
#include "llstaticstringtable.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
|
class LLShaderFeatures
|
||||||
{
|
{
|
||||||
@@ -87,38 +92,256 @@ public:
|
|||||||
BOOL mapAttributes(const std::vector<LLStaticHashedString> * attributes);
|
BOOL mapAttributes(const std::vector<LLStaticHashedString> * attributes);
|
||||||
BOOL mapUniforms(const std::vector<LLStaticHashedString> *);
|
BOOL mapUniforms(const std::vector<LLStaticHashedString> *);
|
||||||
void mapUniform(GLint index, const std::vector<LLStaticHashedString> *);
|
void mapUniform(GLint index, const std::vector<LLStaticHashedString> *);
|
||||||
void uniform1i(U32 index, GLint i);
|
S32 getUniformFromIndex(const U32 index)
|
||||||
void uniform1f(U32 index, GLfloat v);
|
{
|
||||||
void uniform2f(U32 index, GLfloat x, GLfloat y);
|
if (mUniform.size() <= index)
|
||||||
void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z);
|
{
|
||||||
void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL;
|
||||||
void uniform1iv(U32 index, U32 count, const GLint* i);
|
return -1;
|
||||||
void uniform1fv(U32 index, U32 count, const GLfloat* v);
|
}
|
||||||
void uniform2fv(U32 index, U32 count, const GLfloat* v);
|
return mUniform[index];
|
||||||
void uniform3fv(U32 index, U32 count, const GLfloat* v);
|
}
|
||||||
void uniform4fv(U32 index, U32 count, const GLfloat* v);
|
template <typename T, int N>
|
||||||
void uniform2i(const LLStaticHashedString& uniform, GLint i, GLint j);
|
S32 updateUniform(std::vector<std::pair<GLint, T> >& cache, S32 uniform, const F32* val)
|
||||||
void uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
|
{
|
||||||
void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
|
if (mProgramObject > 0)
|
||||||
void uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
|
{
|
||||||
void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
|
if (uniform >= 0)
|
||||||
void uniform1i(const LLStaticHashedString& uniform, GLint i);
|
{
|
||||||
void uniform1f(const LLStaticHashedString& uniform, GLfloat v);
|
std::vector<std::pair<GLint, T> >::iterator iter = std::find_if(cache.begin(), cache.end(), boost::bind(&std::pair<GLint, T>::first, _1) == uniform);
|
||||||
void uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y);
|
if (iter == cache.end())
|
||||||
void uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y, GLfloat z);
|
{
|
||||||
void uniform1fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v);
|
T tmp;
|
||||||
void uniform2fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v);
|
memcpy(&tmp, val, sizeof(F32)*N);
|
||||||
void uniform3fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v);
|
cache.push_back(std::make_pair(uniform, tmp));
|
||||||
void uniform4fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v);
|
return true;
|
||||||
void uniformMatrix4fv(const LLStaticHashedString& uniform, U32 count, GLboolean transpose, const GLfloat *v);
|
}
|
||||||
|
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<LLVector4, 1>(mValueVec4, getUniformFromIndex(index), &val))
|
||||||
|
{
|
||||||
|
glUniform1iARB(mUniform[index], x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform1f(U32 index, GLfloat x)
|
||||||
|
{
|
||||||
|
if (updateUniform<LLVector4, 1>(mValueVec4, getUniformFromIndex(index), &x))
|
||||||
|
{
|
||||||
|
glUniform1fARB(mUniform[index], x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform2f(U32 index, GLfloat x, GLfloat y)
|
||||||
|
{
|
||||||
|
F32 val[] = { x, y };
|
||||||
|
if (updateUniform<LLVector4, 2>(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<LLVector4, 3>(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<LLVector4, 4>(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<LLVector4, 1>(mValueVec4, getUniformFromIndex(index), val) || count > 1)
|
||||||
|
{
|
||||||
|
glUniform1ivARB(mUniform[index], count, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform1fv(U32 index, U32 count, const GLfloat* v)
|
||||||
|
{
|
||||||
|
if (updateUniform<LLVector4, 1>(mValueVec4, getUniformFromIndex(index), v) || count > 1)
|
||||||
|
{
|
||||||
|
glUniform1fvARB(mUniform[index], count, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform2fv(U32 index, U32 count, const GLfloat* v)
|
||||||
|
{
|
||||||
|
if (updateUniform<LLVector4, 2>(mValueVec4, getUniformFromIndex(index), v) || count > 1)
|
||||||
|
{
|
||||||
|
glUniform2fvARB(mUniform[index], count, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform3fv(U32 index, U32 count, const GLfloat* v)
|
||||||
|
{
|
||||||
|
if (updateUniform<LLVector4, 3>(mValueVec4, getUniformFromIndex(index), v) || count > 1)
|
||||||
|
{
|
||||||
|
glUniform3fvARB(mUniform[index], count, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform4fv(U32 index, U32 count, const GLfloat* v)
|
||||||
|
{
|
||||||
|
if (updateUniform<LLVector4, 4>(mValueVec4, getUniformFromIndex(index), v) || count > 1)
|
||||||
|
{
|
||||||
|
glUniform4fvARB(mUniform[index], count, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v)
|
||||||
|
{
|
||||||
|
if (updateUniform<LLMatrix3, 9>(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<LLMatrix4, 12>(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<LLMatrix4, 16>(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<LLVector4, 1>(mValueVec4, getUniformLocation(uniform), &val))
|
||||||
|
{
|
||||||
|
glUniform1iARB(location, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void uniform1f(const LLStaticHashedString& uniform, GLfloat v)
|
||||||
|
{
|
||||||
|
GLint location = getUniformLocation(uniform);
|
||||||
|
if (location < 0)
|
||||||
|
return;
|
||||||
|
if (updateUniform<LLVector4, 1>(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<LLVector4, 2>(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<LLVector4, 3>(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<LLVector4, 1>(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<LLVector4, 2>(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<LLVector4, 3>(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<LLVector4, 4>(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<LLMatrix4, 16>(mValueMat4, location, v))
|
||||||
|
{
|
||||||
|
glUniformMatrix4fvARB(location, count, transpose, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setMinimumAlpha(F32 minimum);
|
void setMinimumAlpha(F32 minimum);
|
||||||
|
|
||||||
void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
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<GLint>::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 getUniformLocation(U32 index);
|
||||||
|
|
||||||
GLint getAttribLocation(U32 attrib);
|
GLint getAttribLocation(U32 attrib);
|
||||||
@@ -156,9 +379,12 @@ public:
|
|||||||
U32 mAttributeMask; //mask of which reserved attributes are set (lines up with LLVertexBuffer::getTypeMask())
|
U32 mAttributeMask; //mask of which reserved attributes are set (lines up with LLVertexBuffer::getTypeMask())
|
||||||
std::vector<GLint> mUniform; //lookup table of uniform enum to uniform location
|
std::vector<GLint> mUniform; //lookup table of uniform enum to uniform location
|
||||||
LLStaticStringTable<GLint> mUniformMap; //lookup map of uniform name to uniform location
|
LLStaticStringTable<GLint> mUniformMap; //lookup map of uniform name to uniform location
|
||||||
std::map<GLint, std::string> mUniformNameMap; //lookup map of uniform location to uniform name
|
//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::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value
|
std::vector<std::pair<GLint, LLVector4> > mValueVec4; //lookup map of uniform location to last known value
|
||||||
std::vector<GLint> mTexture;
|
std::vector<std::pair<GLint, LLMatrix3> > mValueMat3; //lookup map of uniform location to last known value
|
||||||
|
std::vector<std::pair<GLint, LLMatrix4> > mValueMat4; //lookup map of uniform location to last known value
|
||||||
|
|
||||||
|
std::vector<GLint> mTexture; //lookup table of texture uniform enum to texture channel
|
||||||
S32 mTotalUniformSize;
|
S32 mTotalUniformSize;
|
||||||
S32 mActiveTextureChannels;
|
S32 mActiveTextureChannels;
|
||||||
S32 mShaderClass;
|
S32 mShaderClass;
|
||||||
|
|||||||
Reference in New Issue
Block a user