Skip to content
Snippets Groups Projects
llglslshader.cpp 44 KiB
Newer Older
    if (uniform < 0 || uniform >= (S32)mTexture.size())
    {
Graham Linden's avatar
Graham Linden committed
        LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL;
        return -1;
    }
    S32 index = mTexture[uniform];
    if (index != -1 && gGL.getTexUnit(index)->getCurrType() != LLTexUnit::TT_NONE)
        if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode && gGL.getTexUnit(index)->getCurrColorSpace() != space)
                gFailLog << "Texture channel " << index << " texture type corrupted." << std::endl;
                ll_fail("LLGLSLShader::disableTexture failed");
            }
            else
            {
                LL_ERRS() << "Texture channel " << index << " texture type corrupted." << LL_ENDL;
void LLGLSLShader::uniform1i(U32 index, GLint x)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]);
            if (iter == mValue.end() || iter->second.mV[0] != x)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform1i(mUniform[index], x);
                mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f);
void LLGLSLShader::uniform1f(U32 index, GLfloat x)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]);
            if (iter == mValue.end() || iter->second.mV[0] != x)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform1f(mUniform[index], x);
                mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f);
}

void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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))
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform2f(mUniform[index], x, y);
}

void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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))
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform3f(mUniform[index], x, y, z);
}

void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]);
            LLVector4 vec(x,y,z,w);
            if (iter == mValue.end() || shouldChange(iter->second,vec))
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform4f(mUniform[index], x, y, z, w);
void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform1iv(mUniform[index], count, v);
void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform1fv(mUniform[index], count, v);
}

void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform2fv(mUniform[index], count, v);
}

void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform3fv(mUniform[index], count, v);
}

void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
            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)
            {
Rye Mutt's avatar
Rye Mutt committed
                glUniform4fv(mUniform[index], count, v);
}

void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
Rye Mutt's avatar
Rye Mutt committed
            glUniformMatrix2fv(mUniform[index], count, transpose, v);
}

void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
Rye Mutt's avatar
Rye Mutt committed
            glUniformMatrix3fv(mUniform[index], count, transpose, v);
void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v)
{
Graham Linden's avatar
Graham Linden committed
	if (mProgramObject)
	{	
		if (mUniform.size() <= index)
		{
			LL_SHADER_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)
{
Graham Linden's avatar
Graham Linden committed
            LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL;
Rye Mutt's avatar
Rye Mutt committed
            glUniformMatrix4fv(mUniform[index], count, transpose, v);
GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform)
    {
        LLStaticStringTable<GLint>::iterator iter = mUniformMap.find(uniform);
        if (iter != mUniformMap.end())
        {
            if (gDebugGL)
            {
                stop_glerror();
Rye Mutt's avatar
Rye Mutt committed
                if (iter->second != glGetUniformLocation(mProgramObject, uniform.String().c_str()))
                {
                    LL_ERRS() << "Uniform does not match." << LL_ENDL;
                }
                stop_glerror();
            }
            ret = iter->second;
        }
    }

    return ret;
}

GLint LLGLSLShader::getUniformLocation(U32 index)
{
    GLint ret = -1;
    if (mProgramObject)
    {
        llassert(index < mUniform.size());
        return mUniform[index];
    }

    return ret;
GLint LLGLSLShader::getAttribLocation(U32 attrib)
{
    if (attrib < mAttribute.size())
    {
        return mAttribute[attrib];
    }
    else
    {
        return -1;
    }
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))
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform1i(location, 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))
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform2i(location, i, j);
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))
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform1f(location, v);
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))
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform2f(location, x,y);
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))
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform3f(location, x,y,z);
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)
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform1fv(location, count, v);
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)
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform2fv(location, count, v);
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)
        {
Rye Mutt's avatar
Rye Mutt committed
            glUniform3fv(location, count, v);
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();
Rye Mutt's avatar
Rye Mutt committed
            glUniform4fv(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();
Rye Mutt's avatar
Rye Mutt committed
        glUniformMatrix4fv(location, count, transpose, v);
}


void LLGLSLShader::vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
    if (mAttribute[index] > 0)
    {
Rye Mutt's avatar
Rye Mutt committed
        glVertexAttrib4f(mAttribute[index], x, y, z, w);
}

void LLGLSLShader::vertexAttrib4fv(U32 index, GLfloat* v)
{
    if (mAttribute[index] > 0)
    {
Rye Mutt's avatar
Rye Mutt committed
        glVertexAttrib4fv(mAttribute[index], v);
void LLGLSLShader::setMinimumAlpha(F32 minimum)
    gGL.flush();
    uniform1f(LLShaderMgr::MINIMUM_ALPHA, minimum);