Use LLStaticHashedString for faster uniform lookup.
This commit is contained in:
@@ -91,11 +91,22 @@ LLShaderFeatures::LLShaderFeatures()
|
||||
// LLGLSL Shader implementation
|
||||
//===============================
|
||||
LLGLSLShader::LLGLSLShader(S32 shader_class)
|
||||
: mProgramObject(0), mShaderClass(shader_class), mActiveTextureChannels(0), mShaderLevel(0), mShaderGroup(SG_DEFAULT), mUniformsDirty(FALSE)
|
||||
: mProgramObject(0),
|
||||
mShaderClass(shader_class),
|
||||
mAttributeMask(0),
|
||||
mTotalUniformSize(0),
|
||||
mActiveTextureChannels(0),
|
||||
mShaderLevel(0),
|
||||
mShaderGroup(SG_DEFAULT),
|
||||
mUniformsDirty(FALSE)
|
||||
{
|
||||
LLShaderMgr::getGlobalShaderList().push_back(this);
|
||||
}
|
||||
|
||||
LLGLSLShader::~LLGLSLShader()
|
||||
{
|
||||
|
||||
}
|
||||
void LLGLSLShader::unload()
|
||||
{
|
||||
stop_glerror();
|
||||
@@ -103,6 +114,7 @@ void LLGLSLShader::unload()
|
||||
mTexture.clear();
|
||||
mUniform.clear();
|
||||
mShaderFiles.clear();
|
||||
mDefines.clear();
|
||||
|
||||
if (mProgramObject)
|
||||
{
|
||||
@@ -127,8 +139,8 @@ void LLGLSLShader::unload()
|
||||
stop_glerror();
|
||||
}
|
||||
|
||||
BOOL LLGLSLShader::createShader(vector<string> * attributes,
|
||||
vector<string> * uniforms,
|
||||
BOOL LLGLSLShader::createShader(std::vector<LLStaticHashedString> * attributes,
|
||||
std::vector<LLStaticHashedString> * uniforms,
|
||||
U32 varying_count,
|
||||
const char** varyings)
|
||||
{
|
||||
@@ -151,7 +163,7 @@ BOOL LLGLSLShader::createShader(vector<string> * attributes,
|
||||
vector< pair<string,GLenum> >::iterator fileIter = mShaderFiles.begin();
|
||||
for ( ; fileIter != mShaderFiles.end(); fileIter++ )
|
||||
{
|
||||
GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, mFeatures.mIndexedTextureChannels);
|
||||
GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels);
|
||||
LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL;
|
||||
if (shaderhandle > 0)
|
||||
{
|
||||
@@ -217,7 +229,8 @@ BOOL LLGLSLShader::createShader(vector<string> * attributes,
|
||||
|
||||
for (S32 i = 0; i < channel_count; i++)
|
||||
{
|
||||
uniform1i(llformat("tex%d", i), i);
|
||||
LLStaticHashedString uniName(llformat("tex%d", i));
|
||||
uniform1i(uniName, i);
|
||||
}
|
||||
|
||||
S32 cur_tex = channel_count; //adjust any texture channels that might have been overwritten
|
||||
@@ -290,7 +303,7 @@ void LLGLSLShader::attachObjects(GLhandleARB* objects, S32 count)
|
||||
}
|
||||
}
|
||||
|
||||
BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes)
|
||||
BOOL LLGLSLShader::mapAttributes(const std::vector<LLStaticHashedString> * attributes)
|
||||
{
|
||||
//before linking, make sure reserved attributes always have consistent locations
|
||||
for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++)
|
||||
@@ -309,6 +322,8 @@ BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes)
|
||||
if (res)
|
||||
{ //read back channel locations
|
||||
|
||||
mAttributeMask = 0;
|
||||
|
||||
//read back reserved channels first
|
||||
for (U32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedAttribs.size(); i++)
|
||||
{
|
||||
@@ -317,6 +332,7 @@ BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes)
|
||||
if (index != -1)
|
||||
{
|
||||
mAttribute[i] = index;
|
||||
mAttributeMask |= 1 << i;
|
||||
LL_DEBUGS("ShaderLoading") << "Attribute " << name << " assigned to channel " << index << LL_ENDL;
|
||||
}
|
||||
}
|
||||
@@ -324,7 +340,7 @@ BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes)
|
||||
{
|
||||
for (U32 i = 0; i < numAttributes; i++)
|
||||
{
|
||||
const char* name = (*attributes)[i].c_str();
|
||||
const char* name = (*attributes)[i].String().c_str();
|
||||
S32 index = glGetAttribLocationARB(mProgramObject, name);
|
||||
if (index != -1)
|
||||
{
|
||||
@@ -340,7 +356,7 @@ BOOL LLGLSLShader::mapAttributes(const vector<string> * attributes)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms)
|
||||
void LLGLSLShader::mapUniform(GLint index, const vector<LLStaticHashedString> * uniforms)
|
||||
{
|
||||
if (index == -1)
|
||||
{
|
||||
@@ -349,11 +365,55 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms)
|
||||
|
||||
GLenum type;
|
||||
GLsizei length;
|
||||
GLint size;
|
||||
GLint size = -1;
|
||||
char name[1024]; /* Flawfinder: ignore */
|
||||
name[0] = 0;
|
||||
|
||||
glGetActiveUniformARB(mProgramObject, index, 1024, &length, &size, &type, (GLcharARB *)name);
|
||||
#if !LL_DARWIN
|
||||
if (size > 0)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case GL_FLOAT_VEC2: size *= 2; break;
|
||||
case GL_FLOAT_VEC3: size *= 3; break;
|
||||
case GL_FLOAT_VEC4: size *= 4; break;
|
||||
case GL_DOUBLE: size *= 2; break;
|
||||
case GL_DOUBLE_VEC2: size *= 2; break;
|
||||
case GL_DOUBLE_VEC3: size *= 6; break;
|
||||
case GL_DOUBLE_VEC4: size *= 8; break;
|
||||
case GL_INT_VEC2: size *= 2; break;
|
||||
case GL_INT_VEC3: size *= 3; break;
|
||||
case GL_INT_VEC4: size *= 4; break;
|
||||
case GL_UNSIGNED_INT_VEC2: size *= 2; break;
|
||||
case GL_UNSIGNED_INT_VEC3: size *= 3; break;
|
||||
case GL_UNSIGNED_INT_VEC4: size *= 4; break;
|
||||
case GL_BOOL_VEC2: size *= 2; break;
|
||||
case GL_BOOL_VEC3: size *= 3; break;
|
||||
case GL_BOOL_VEC4: size *= 4; break;
|
||||
case GL_FLOAT_MAT2: size *= 4; break;
|
||||
case GL_FLOAT_MAT3: size *= 9; break;
|
||||
case GL_FLOAT_MAT4: size *= 16; break;
|
||||
case GL_FLOAT_MAT2x3: size *= 6; break;
|
||||
case GL_FLOAT_MAT2x4: size *= 8; break;
|
||||
case GL_FLOAT_MAT3x2: size *= 6; break;
|
||||
case GL_FLOAT_MAT3x4: size *= 12; break;
|
||||
case GL_FLOAT_MAT4x2: size *= 8; break;
|
||||
case GL_FLOAT_MAT4x3: size *= 12; break;
|
||||
case GL_DOUBLE_MAT2: size *= 8; break;
|
||||
case GL_DOUBLE_MAT3: size *= 18; break;
|
||||
case GL_DOUBLE_MAT4: size *= 32; break;
|
||||
case GL_DOUBLE_MAT2x3: size *= 12; break;
|
||||
case GL_DOUBLE_MAT2x4: size *= 16; break;
|
||||
case GL_DOUBLE_MAT3x2: size *= 12; break;
|
||||
case GL_DOUBLE_MAT3x4: size *= 24; break;
|
||||
case GL_DOUBLE_MAT4x2: size *= 16; break;
|
||||
case GL_DOUBLE_MAT4x3: size *= 24; break;
|
||||
}
|
||||
mTotalUniformSize += size;
|
||||
}
|
||||
#endif
|
||||
|
||||
S32 location = glGetUniformLocationARB(mProgramObject, name);
|
||||
if (location != -1)
|
||||
{
|
||||
@@ -365,7 +425,10 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms)
|
||||
is_array[0] = 0;
|
||||
}
|
||||
|
||||
mUniformMap[name] = location;
|
||||
LLStaticHashedString hashedName(name);
|
||||
mUniformNameMap[location] = name;
|
||||
mUniformMap[hashedName] = location;
|
||||
|
||||
LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL;
|
||||
|
||||
//find the index of this uniform
|
||||
@@ -386,7 +449,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] == name))
|
||||
&& ((*uniforms)[i].String() == name))
|
||||
{
|
||||
//found it
|
||||
mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location;
|
||||
@@ -396,7 +459,17 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::addPermutation(std::string name, std::string value)
|
||||
{
|
||||
mDefines[name] = value;
|
||||
}
|
||||
|
||||
void LLGLSLShader::removePermutation(std::string name)
|
||||
{
|
||||
mDefines[name].erase();
|
||||
}
|
||||
|
||||
GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type)
|
||||
{
|
||||
@@ -410,13 +483,15 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type)
|
||||
return -1;
|
||||
}
|
||||
|
||||
BOOL LLGLSLShader::mapUniforms(const vector<string> * uniforms)
|
||||
BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
||||
{
|
||||
BOOL res = TRUE;
|
||||
|
||||
mTotalUniformSize = 0;
|
||||
mActiveTextureChannels = 0;
|
||||
mUniform.clear();
|
||||
mUniformMap.clear();
|
||||
mUniformNameMap.clear();
|
||||
mTexture.clear();
|
||||
mValue.clear();
|
||||
//initialize arrays
|
||||
@@ -437,6 +512,7 @@ BOOL LLGLSLShader::mapUniforms(const vector<string> * uniforms)
|
||||
|
||||
unbind();
|
||||
|
||||
LL_DEBUGS("ShaderLoading") << "Total Uniform Size: " << mTotalUniformSize << llendl;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -495,6 +571,58 @@ void LLGLSLShader::bindNoShader(void)
|
||||
}
|
||||
}
|
||||
|
||||
S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LLTexUnit::eTextureType mode)
|
||||
{
|
||||
S32 channel = 0;
|
||||
channel = getUniformLocation(uniform);
|
||||
|
||||
return bindTexture(channel, texture, mode);
|
||||
}
|
||||
|
||||
S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode)
|
||||
{
|
||||
if (uniform < 0 || uniform >= (S32)mTexture.size())
|
||||
{
|
||||
UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uniform = mTexture[uniform];
|
||||
|
||||
if (uniform > -1)
|
||||
{
|
||||
gGL.getTexUnit(uniform)->bind(texture, mode);
|
||||
}
|
||||
|
||||
return uniform;
|
||||
}
|
||||
|
||||
S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureType mode)
|
||||
{
|
||||
S32 channel = 0;
|
||||
channel = getUniformLocation(uniform);
|
||||
|
||||
return unbindTexture(channel);
|
||||
}
|
||||
|
||||
S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode)
|
||||
{
|
||||
if (uniform < 0 || uniform >= (S32)mTexture.size())
|
||||
{
|
||||
UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uniform = mTexture[uniform];
|
||||
|
||||
if (uniform > -1)
|
||||
{
|
||||
gGL.getTexUnit(uniform)->unbind(mode);
|
||||
}
|
||||
|
||||
return uniform;
|
||||
}
|
||||
|
||||
S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode)
|
||||
{
|
||||
if (uniform < 0 || uniform >= (S32)mTexture.size())
|
||||
@@ -817,18 +945,18 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c
|
||||
}
|
||||
}
|
||||
|
||||
GLint LLGLSLShader::getUniformLocation(const string& uniform)
|
||||
GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform)
|
||||
{
|
||||
GLint ret = -1;
|
||||
if (mProgramObject > 0)
|
||||
{
|
||||
std::map<string, GLint>::iterator iter = mUniformMap.find(uniform);
|
||||
LLStaticStringTable<GLint>::iterator iter = mUniformMap.find(uniform);
|
||||
if (iter != mUniformMap.end())
|
||||
{
|
||||
if (gDebugGL)
|
||||
{
|
||||
stop_glerror();
|
||||
if (iter->second != glGetUniformLocationARB(mProgramObject, uniform.c_str()))
|
||||
if (iter->second != glGetUniformLocationARB(mProgramObject, uniform.String().c_str()))
|
||||
{
|
||||
llerrs << "Uniform does not match." << llendl;
|
||||
}
|
||||
@@ -865,7 +993,7 @@ GLint LLGLSLShader::getAttribLocation(U32 attrib)
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform1i(const string& uniform, GLint v)
|
||||
void LLGLSLShader::uniform1i(const LLStaticHashedString& uniform, GLint v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -881,7 +1009,24 @@ void LLGLSLShader::uniform1i(const string& uniform, GLint v)
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform1f(const string& uniform, GLfloat v)
|
||||
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);
|
||||
|
||||
@@ -897,7 +1042,7 @@ void LLGLSLShader::uniform1f(const string& uniform, GLfloat v)
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform2f(const string& uniform, GLfloat x, GLfloat y)
|
||||
void LLGLSLShader::uniform2f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -914,7 +1059,7 @@ void LLGLSLShader::uniform2f(const string& uniform, GLfloat x, GLfloat y)
|
||||
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform3f(const string& uniform, GLfloat x, GLfloat y, GLfloat z)
|
||||
void LLGLSLShader::uniform3f(const LLStaticHashedString& uniform, GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -930,23 +1075,7 @@ void LLGLSLShader::uniform3f(const string& uniform, GLfloat x, GLfloat y, GLfloa
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform4f(const string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
if (location >= 0)
|
||||
{
|
||||
std::map<GLint, LLVector4>::iterator iter = mValue.find(location);
|
||||
LLVector4 vec(x,y,z,w);
|
||||
if (iter == mValue.end() || shouldChange(iter->second,vec))
|
||||
{
|
||||
glUniform4fARB(location, x,y,z,w);
|
||||
mValue[location] = vec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform1fv(const string& uniform, U32 count, const GLfloat* v)
|
||||
void LLGLSLShader::uniform1fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -962,7 +1091,7 @@ void LLGLSLShader::uniform1fv(const string& uniform, U32 count, const GLfloat* v
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform2fv(const string& uniform, U32 count, const GLfloat* v)
|
||||
void LLGLSLShader::uniform2fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -978,7 +1107,7 @@ void LLGLSLShader::uniform2fv(const string& uniform, U32 count, const GLfloat* v
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform3fv(const string& uniform, U32 count, const GLfloat* v)
|
||||
void LLGLSLShader::uniform3fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -994,7 +1123,7 @@ void LLGLSLShader::uniform3fv(const string& uniform, U32 count, const GLfloat* v
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniform4fv(const string& uniform, U32 count, const GLfloat* v)
|
||||
void LLGLSLShader::uniform4fv(const LLStaticHashedString& uniform, U32 count, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
@@ -1012,27 +1141,7 @@ void LLGLSLShader::uniform4fv(const string& uniform, U32 count, const GLfloat* v
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniformMatrix2fv(const string& uniform, U32 count, GLboolean transpose, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
if (location >= 0)
|
||||
{
|
||||
glUniformMatrix2fvARB(location, count, transpose, v);
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniformMatrix3fv(const string& uniform, U32 count, GLboolean transpose, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
if (location >= 0)
|
||||
{
|
||||
glUniformMatrix3fvARB(location, count, transpose, v);
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLSLShader::uniformMatrix4fv(const string& uniform, U32 count, GLboolean transpose, const GLfloat* v)
|
||||
void LLGLSLShader::uniformMatrix4fv(const LLStaticHashedString& uniform, U32 count, GLboolean transpose, const GLfloat* v)
|
||||
{
|
||||
GLint location = getUniformLocation(uniform);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "llgl.h"
|
||||
#include "llrender.h"
|
||||
#include "llstaticstringtable.h"
|
||||
|
||||
class LLShaderFeatures
|
||||
{
|
||||
@@ -68,6 +69,7 @@ public:
|
||||
};
|
||||
|
||||
LLGLSLShader(S32 shader_class);
|
||||
~LLGLSLShader();
|
||||
|
||||
static GLhandleARB sCurBoundShader;
|
||||
static LLGLSLShader* sCurBoundShaderPtr;
|
||||
@@ -75,16 +77,16 @@ public:
|
||||
static bool sNoFixedFunction;
|
||||
|
||||
void unload();
|
||||
BOOL createShader(std::vector<std::string> * attributes,
|
||||
std::vector<std::string> * uniforms,
|
||||
BOOL createShader(std::vector<LLStaticHashedString> * attributes,
|
||||
std::vector<LLStaticHashedString> * uniforms,
|
||||
U32 varying_count = 0,
|
||||
const char** varyings = NULL);
|
||||
BOOL attachObject(std::string object);
|
||||
void attachObject(GLhandleARB object);
|
||||
void attachObjects(GLhandleARB* objects = NULL, S32 count = 0);
|
||||
BOOL mapAttributes(const std::vector<std::string> * attributes);
|
||||
BOOL mapUniforms(const std::vector<std::string> * uniforms);
|
||||
void mapUniform(GLint index, const std::vector<std::string> * uniforms);
|
||||
BOOL mapAttributes(const std::vector<LLStaticHashedString> * attributes);
|
||||
BOOL mapUniforms(const std::vector<LLStaticHashedString> *);
|
||||
void mapUniform(GLint index, const std::vector<LLStaticHashedString> *);
|
||||
void uniform1i(U32 index, GLint i);
|
||||
void uniform1f(U32 index, GLfloat v);
|
||||
void uniform2f(U32 index, GLfloat x, GLfloat y);
|
||||
@@ -95,34 +97,35 @@ public:
|
||||
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 uniform1i(const std::string& uniform, GLint i);
|
||||
void uniform1f(const std::string& uniform, GLfloat v);
|
||||
void uniform2f(const std::string& uniform, GLfloat x, GLfloat y);
|
||||
void uniform3f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z);
|
||||
void uniform4f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
||||
void uniform1iv(const std::string& uniform, U32 count, const GLint* i);
|
||||
void uniform1fv(const std::string& uniform, U32 count, const GLfloat* v);
|
||||
void uniform2fv(const std::string& uniform, U32 count, const GLfloat* v);
|
||||
void uniform3fv(const std::string& uniform, U32 count, const GLfloat* v);
|
||||
void uniform4fv(const std::string& uniform, 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 uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
|
||||
void uniformMatrix2fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
|
||||
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 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);
|
||||
|
||||
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 std::string& uniform);
|
||||
GLint getUniformLocation(const LLStaticHashedString& uniform);
|
||||
GLint getUniformLocation(U32 index);
|
||||
|
||||
GLint getAttribLocation(U32 attrib);
|
||||
GLint mapUniformTextureChannel(GLint location, GLenum type);
|
||||
|
||||
void addPermutation(std::string name, std::string value);
|
||||
void removePermutation(std::string name);
|
||||
|
||||
//enable/disable texture channel for specified uniform
|
||||
//if given texture uniform is active in the shader,
|
||||
//the corresponding channel will be active upon return
|
||||
@@ -130,6 +133,13 @@ public:
|
||||
S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
|
||||
S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
|
||||
|
||||
// bindTexture returns the texture unit we've bound the texture to.
|
||||
// You can reuse the return value to unbind a texture when required.
|
||||
S32 bindTexture(const std::string& uniform, LLTexture *texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
|
||||
S32 bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
|
||||
S32 unbindTexture(const std::string& uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
|
||||
S32 unbindTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
|
||||
|
||||
BOOL link(BOOL suppress_errors = FALSE);
|
||||
void bind();
|
||||
void unbind();
|
||||
@@ -142,10 +152,13 @@ public:
|
||||
|
||||
GLhandleARB mProgramObject;
|
||||
std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel
|
||||
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::map<std::string, 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
|
||||
std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value
|
||||
std::vector<GLint> mTexture;
|
||||
S32 mTotalUniformSize;
|
||||
S32 mActiveTextureChannels;
|
||||
S32 mShaderClass;
|
||||
S32 mShaderLevel;
|
||||
@@ -154,6 +167,7 @@ public:
|
||||
LLShaderFeatures mFeatures;
|
||||
std::vector< std::pair< std::string, GLenum > > mShaderFiles;
|
||||
std::string mName;
|
||||
std::map<std::string, std::string> mDefines;
|
||||
};
|
||||
|
||||
//UI shader (declared here so llui_libtest will link properly)
|
||||
|
||||
@@ -51,6 +51,28 @@ extern LLGLSLShader gPostPosterizeProgram;
|
||||
extern LLGLSLShader gPostMotionBlurProgram;
|
||||
extern LLGLSLShader gPostVignetteProgram;
|
||||
|
||||
static LLStaticHashedString sGamma("gamma");
|
||||
static LLStaticHashedString sBrightness("brightness");
|
||||
static LLStaticHashedString sContrast("contrast");
|
||||
static LLStaticHashedString sContrastBase("contrastBase");
|
||||
static LLStaticHashedString sSaturation("saturation");
|
||||
static LLStaticHashedString sBrightMult("brightMult");
|
||||
static LLStaticHashedString sNoiseStrength("noiseStrength");
|
||||
static LLStaticHashedString sLayerCount("layerCount");
|
||||
|
||||
static LLStaticHashedString sVignetteStrength("vignette_strength");
|
||||
static LLStaticHashedString sVignettRadius("vignette_radius");
|
||||
static LLStaticHashedString sVignetteDarkness("vignette_darkness");
|
||||
static LLStaticHashedString sVignetteDesaturation("vignette_desaturation");
|
||||
static LLStaticHashedString sVignetteChromaticAberration("vignette_chromatic_aberration");
|
||||
static LLStaticHashedString sScreenRes("screen_res");
|
||||
|
||||
static LLStaticHashedString sHorizontalPass("horizontalPass");
|
||||
|
||||
static LLStaticHashedString sPrevProj("prev_proj");
|
||||
static LLStaticHashedString sInvProj("inv_proj");
|
||||
static LLStaticHashedString sBlurStrength("blur_strength");
|
||||
|
||||
static const unsigned int NOISE_SIZE = 512;
|
||||
|
||||
static const char * const XML_FILENAME = "postprocesseffects.xml";
|
||||
@@ -155,16 +177,16 @@ public:
|
||||
|
||||
/*virtual*/ QuadType preDraw()
|
||||
{
|
||||
getShader().uniform1f("gamma", mGamma);
|
||||
getShader().uniform1f("brightness", mBrightness);
|
||||
getShader().uniform1f("contrast", mContrast);
|
||||
getShader().uniform1f(sGamma, mGamma);
|
||||
getShader().uniform1f(sBrightness, mBrightness);
|
||||
getShader().uniform1f(sContrast, mContrast);
|
||||
float baseI = (mContrastBase.get()[VX] + mContrastBase.get()[VY] + mContrastBase.get()[VZ]) / 3.0f;
|
||||
baseI = mContrastBase.get()[VW] / llmax(baseI,0.001f);
|
||||
float baseR = mContrastBase.get()[VX] * baseI;
|
||||
float baseG = mContrastBase.get()[VY] * baseI;
|
||||
float baseB = mContrastBase.get()[VZ] * baseI;
|
||||
getShader().uniform3fv("contrastBase", 1, LLVector3(baseR, baseG, baseB).mV);
|
||||
getShader().uniform1f("saturation", mSaturation);
|
||||
getShader().uniform3fv(sContrastBase, 1, LLVector3(baseR, baseG, baseB).mV);
|
||||
getShader().uniform1f(sSaturation, mSaturation);
|
||||
|
||||
return QUAD_NORMAL;
|
||||
}
|
||||
@@ -187,8 +209,8 @@ public:
|
||||
{
|
||||
LLPostProcess::getInstance()->bindNoise(1);
|
||||
|
||||
getShader().uniform1f("brightMult", mBrightnessMult);
|
||||
getShader().uniform1f("noiseStrength", mNoiseStrength);
|
||||
getShader().uniform1f(sBrightMult, mBrightnessMult);
|
||||
getShader().uniform1f(sNoiseStrength, mNoiseStrength);
|
||||
|
||||
return QUAD_NOISE;
|
||||
}
|
||||
@@ -206,7 +228,7 @@ public:
|
||||
}
|
||||
/*virtual*/ QuadType preDraw()
|
||||
{
|
||||
getShader().uniform1i("layerCount", mNumLayers);
|
||||
getShader().uniform1i(sLayerCount, mNumLayers);
|
||||
return QUAD_NORMAL;
|
||||
}
|
||||
};
|
||||
@@ -232,12 +254,13 @@ public:
|
||||
/*virtual*/ QuadType preDraw()
|
||||
{
|
||||
LLVector2 screen_rect = LLPostProcess::getInstance()->getDimensions();
|
||||
getShader().uniform1f("vignette_strength", mStrength);
|
||||
getShader().uniform1f("vignette_radius", mRadius);
|
||||
getShader().uniform1f("vignette_darkness", mDarkness);
|
||||
getShader().uniform1f("vignette_desaturation", mDesaturation);
|
||||
getShader().uniform1f("vignette_chromatic_aberration", mChromaticAberration);
|
||||
getShader().uniform2fv("screen_res", 1, screen_rect.mV);
|
||||
|
||||
getShader().uniform1f(sVignetteStrength, mStrength);
|
||||
getShader().uniform1f(sVignettRadius, mRadius);
|
||||
getShader().uniform1f(sVignetteDarkness, mDarkness);
|
||||
getShader().uniform1f(sVignetteDesaturation, mDesaturation);
|
||||
getShader().uniform1f(sVignetteChromaticAberration, mChromaticAberration);
|
||||
getShader().uniform2fv(sScreenRes, 1, screen_rect.mV);
|
||||
return QUAD_NORMAL;
|
||||
}
|
||||
};
|
||||
@@ -259,7 +282,7 @@ public:
|
||||
/*virtual*/ S32 getDepthChannel() const { return -1; }
|
||||
/*virtual*/ QuadType preDraw()
|
||||
{
|
||||
mPassLoc = getShader().getUniformLocation("horizontalPass");
|
||||
mPassLoc = getShader().getUniformLocation(sHorizontalPass);
|
||||
return QUAD_NORMAL;
|
||||
}
|
||||
/*virtual*/ bool draw(U32 pass)
|
||||
@@ -295,10 +318,10 @@ public:
|
||||
|
||||
LLVector2 screen_rect = LLPostProcess::getInstance()->getDimensions();
|
||||
|
||||
getShader().uniformMatrix4fv("prev_proj", 1, GL_FALSE, prev_proj.m);
|
||||
getShader().uniformMatrix4fv("inv_proj", 1, GL_FALSE, inv_proj.m);
|
||||
getShader().uniform2fv("screen_res", 1, screen_rect.mV);
|
||||
getShader().uniform1i("blur_strength", mStrength);
|
||||
getShader().uniformMatrix4fv(sPrevProj, 1, GL_FALSE, prev_proj.m);
|
||||
getShader().uniformMatrix4fv(sInvProj, 1, GL_FALSE, inv_proj.m);
|
||||
getShader().uniform2fv(sScreenRes, 1, screen_rect.mV);
|
||||
getShader().uniform1i(sBlurStrength, mStrength);
|
||||
|
||||
return QUAD_NORMAL;
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns)
|
||||
}
|
||||
}
|
||||
|
||||
GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, S32 texture_index_channels)
|
||||
GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map<std::string, std::string>* defines, S32 texture_index_channels)
|
||||
{
|
||||
std::pair<std::multimap<std::string, CachedObjectInfo >::iterator, std::multimap<std::string, CachedObjectInfo>::iterator> range;
|
||||
range = mShaderObjects.equal_range(filename);
|
||||
@@ -669,8 +669,9 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
|
||||
if(SHPackDeferredNormals)
|
||||
text[count++] = strdup("#define PACK_NORMALS\n");
|
||||
|
||||
//copy preprocessor definitions into buffer
|
||||
for (std::map<std::string,std::string>::iterator iter = mDefinitions.begin(); iter != mDefinitions.end(); ++iter)
|
||||
if(defines)
|
||||
{
|
||||
for (std::map<std::string,std::string>::iterator iter = defines->begin(); iter != defines->end(); ++iter)
|
||||
{
|
||||
std::string define = "#define " + iter->first + " " + iter->second + "\n";
|
||||
text[count++] = (GLcharARB *) strdup(define.c_str());
|
||||
@@ -924,7 +925,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
|
||||
if (shader_level > 1)
|
||||
{
|
||||
shader_level--;
|
||||
return loadShaderFile(filename,shader_level,type,texture_index_channels);
|
||||
return loadShaderFile(filename,shader_level,type, defines, texture_index_channels);
|
||||
}
|
||||
LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL;
|
||||
}
|
||||
@@ -1044,7 +1045,9 @@ void LLShaderMgr::initAttribsAndUniforms()
|
||||
mReservedUniforms.push_back("texture_matrix1");
|
||||
mReservedUniforms.push_back("texture_matrix2");
|
||||
mReservedUniforms.push_back("texture_matrix3");
|
||||
llassert(mReservedUniforms.size() == LLShaderMgr::TEXTURE_MATRIX3+1);
|
||||
mReservedUniforms.push_back("object_plane_s");
|
||||
mReservedUniforms.push_back("object_plane_t");
|
||||
llassert(mReservedUniforms.size() == LLShaderMgr::OBJECT_PLANE_T+1);
|
||||
|
||||
mReservedUniforms.push_back("viewport");
|
||||
|
||||
@@ -1185,7 +1188,47 @@ void LLShaderMgr::initAttribsAndUniforms()
|
||||
mReservedUniforms.push_back("lightMap");
|
||||
mReservedUniforms.push_back("bloomMap");
|
||||
mReservedUniforms.push_back("projectionMap");
|
||||
mReservedUniforms.push_back("norm_mat");
|
||||
|
||||
mReservedUniforms.push_back("matrixPalette");
|
||||
|
||||
mReservedUniforms.push_back("screenTex");
|
||||
mReservedUniforms.push_back("screenDepth");
|
||||
mReservedUniforms.push_back("refTex");
|
||||
mReservedUniforms.push_back("eyeVec");
|
||||
mReservedUniforms.push_back("time");
|
||||
mReservedUniforms.push_back("d1");
|
||||
mReservedUniforms.push_back("d2");
|
||||
mReservedUniforms.push_back("lightDir");
|
||||
mReservedUniforms.push_back("specular");
|
||||
mReservedUniforms.push_back("lightExp");
|
||||
mReservedUniforms.push_back("waterFogColor");
|
||||
mReservedUniforms.push_back("waterFogDensity");
|
||||
mReservedUniforms.push_back("waterFogKS");
|
||||
mReservedUniforms.push_back("refScale");
|
||||
mReservedUniforms.push_back("waterHeight");
|
||||
mReservedUniforms.push_back("waterPlane");
|
||||
mReservedUniforms.push_back("normScale");
|
||||
mReservedUniforms.push_back("fresnelScale");
|
||||
mReservedUniforms.push_back("fresnelOffset");
|
||||
mReservedUniforms.push_back("blurMultiplier");
|
||||
mReservedUniforms.push_back("sunAngle");
|
||||
mReservedUniforms.push_back("scaledAngle");
|
||||
mReservedUniforms.push_back("sunAngle2");
|
||||
|
||||
mReservedUniforms.push_back("camPosLocal");
|
||||
|
||||
mReservedUniforms.push_back("gWindDir");
|
||||
mReservedUniforms.push_back("gSinWaveParams");
|
||||
mReservedUniforms.push_back("gGravity");
|
||||
|
||||
mReservedUniforms.push_back("detail_0");
|
||||
mReservedUniforms.push_back("detail_1");
|
||||
mReservedUniforms.push_back("detail_2");
|
||||
mReservedUniforms.push_back("detail_3");
|
||||
mReservedUniforms.push_back("alpha_ramp");
|
||||
|
||||
mReservedUniforms.push_back("origin");
|
||||
llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS);
|
||||
|
||||
std::set<std::string> dupe_check;
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
TEXTURE_MATRIX1,
|
||||
TEXTURE_MATRIX2,
|
||||
TEXTURE_MATRIX3,
|
||||
OBJECT_PLANE_S,
|
||||
OBJECT_PLANE_T,
|
||||
VIEWPORT,
|
||||
LIGHT_POSITION,
|
||||
LIGHT_DIRECTION,
|
||||
@@ -164,6 +166,45 @@ public:
|
||||
DEFERRED_LIGHT,
|
||||
DEFERRED_BLOOM,
|
||||
DEFERRED_PROJECTION,
|
||||
DEFERRED_NORM_MATRIX,
|
||||
|
||||
AVATAR_MATRIX,
|
||||
WATER_SCREENTEX,
|
||||
WATER_SCREENDEPTH,
|
||||
WATER_REFTEX,
|
||||
WATER_EYEVEC,
|
||||
WATER_TIME,
|
||||
WATER_WAVE_DIR1,
|
||||
WATER_WAVE_DIR2,
|
||||
WATER_LIGHT_DIR,
|
||||
WATER_SPECULAR,
|
||||
WATER_SPECULAR_EXP,
|
||||
WATER_FOGCOLOR,
|
||||
WATER_FOGDENSITY,
|
||||
WATER_FOGKS,
|
||||
WATER_REFSCALE,
|
||||
WATER_WATERHEIGHT,
|
||||
WATER_WATERPLANE,
|
||||
WATER_NORM_SCALE,
|
||||
WATER_FRESNEL_SCALE,
|
||||
WATER_FRESNEL_OFFSET,
|
||||
WATER_BLUR_MULTIPLIER,
|
||||
WATER_SUN_ANGLE,
|
||||
WATER_SCALED_ANGLE,
|
||||
WATER_SUN_ANGLE2,
|
||||
|
||||
WL_CAMPOSLOCAL,
|
||||
|
||||
AVATAR_WIND,
|
||||
AVATAR_SINWAVE,
|
||||
AVATAR_GRAVITY,
|
||||
|
||||
TERRAIN_DETAIL0,
|
||||
TERRAIN_DETAIL1,
|
||||
TERRAIN_DETAIL2,
|
||||
TERRAIN_DETAIL3,
|
||||
TERRAIN_ALPHARAMP,
|
||||
SHINY_ORIGIN,
|
||||
END_RESERVED_UNIFORMS
|
||||
} eGLSLReservedUniforms;
|
||||
|
||||
@@ -176,7 +217,7 @@ public:
|
||||
void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE);
|
||||
BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE);
|
||||
BOOL validateProgramObject(GLhandleARB obj);
|
||||
GLhandleARB loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, S32 texture_index_channels = -1);
|
||||
GLhandleARB loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map<std::string, std::string>* defines = NULL, S32 texture_index_channels = -1);
|
||||
|
||||
// Implemented in the application to actually point to the shader directory.
|
||||
virtual std::string getShaderDirPrefix(void) = 0; // Pure Virtual
|
||||
|
||||
Reference in New Issue
Block a user