From d4d0520f38f59c4f60da098da9c2217ca6e45d65 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 20 Sep 2017 14:29:36 -0700 Subject: Cleanup inside GLSLShader for uniform mapping. --- indra/llrender/llglslshader.cpp | 319 +++++++++++++++------------------------- indra/llrender/llglslshader.h | 29 +++- 2 files changed, 145 insertions(+), 203 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 5d669fb955..79421e6bdc 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -154,8 +154,7 @@ void LLGLSLShader::clearStats() mSamplesDrawn = 0; mDrawCalls = 0; mTextureStateFetched = false; - mTextureMagFilter.clear(); - mTextureMinFilter.clear(); + mTextureMagMinFilter.clear(); } void LLGLSLShader::dumpStats() @@ -168,14 +167,16 @@ void LLGLSLShader::dumpStats() { LL_INFOS() << mShaderFiles[i].first << LL_ENDL; } - for (U32 i = 0; i < mTexture.size(); ++i) + for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it) { - GLint idx = mTexture[i]; + S32 i = (*it).first; + GLint idx = (*it).second; if (idx >= 0) { GLint uniform_idx = getUniformLocation(i); - LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << mTextureMagFilter[i] << "/" << mTextureMinFilter[i] << std::dec << LL_ENDL; + magmin_filter_t::iterator it = mTextureMagMinFilter.find(i); + LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << (*it).second.second << "/" << (*it).second.first << std::dec << LL_ENDL; } } LL_INFOS() << "=============================================" << LL_ENDL; @@ -232,14 +233,13 @@ void LLGLSLShader::placeProfileQuery() if (!mTextureStateFetched) { mTextureStateFetched = true; - mTextureMagFilter.resize(mTexture.size()); - mTextureMinFilter.resize(mTexture.size()); U32 cur_active = gGL.getCurrentTexUnitIndex(); - for (U32 i = 0; i < mTexture.size(); ++i) + for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it) { - GLint idx = mTexture[i]; + S32 i = (*it).first; + GLint idx = (*it).second; if (idx >= 0) { @@ -253,8 +253,7 @@ void LLGLSLShader::placeProfileQuery() glGetTexParameteriv(type, GL_TEXTURE_MAG_FILTER, (GLint*) &mag); glGetTexParameteriv(type, GL_TEXTURE_MIN_FILTER, (GLint*) &min); - mTextureMagFilter[i] = mag; - mTextureMinFilter[i] = min; + mTextureMagMinFilter[i] = magmin_values_t(mag, min); } } @@ -470,13 +469,14 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } S32 cur_tex = channel_count; //adjust any texture channels that might have been overwritten - for (U32 i = 0; i < mTexture.size(); i++) + for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it) { - if (mTexture[i] > -1 && mTexture[i] < channel_count) + int i = (*it).first; + if (((*it).second >= 0) && ((*it).second < channel_count)) { llassert(cur_tex < gGLManager.mNumTextureImageUnits); uniform1i(i, cur_tex); - mTexture[i] = cur_tex++; + (*it).second = cur_tex++; } } unbind(); @@ -655,13 +655,16 @@ void LLGLSLShader::mapUniform(GLint index, const vector * //find the index of this uniform for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) { - if ( (mUniform[i] == -1) - && (LLShaderMgr::instance()->mReservedUniforms[i] == name)) + if (LLShaderMgr::instance()->mReservedUniforms[i] == name) { - //found it - mUniform[i] = location; - mTexture[i] = mapUniformTextureChannel(location, type); - return; + std::pair result; + + result = mUniform.insert(uniforms_index_t::value_type(i, location)); + if (result.second) + { + mTexture[i] = mapUniformTextureChannel(location, type); + return; + } } } @@ -669,13 +672,17 @@ void LLGLSLShader::mapUniform(GLint index, const vector * { for (U32 i = 0; i < uniforms->size(); i++) { - if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) - && ((*uniforms)[i].String() == name)) + std::pair result; + S32 index = i + LLShaderMgr::instance()->mReservedUniforms.size(); + + if ((*uniforms)[i].String() == name) { - //found it - mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; - mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type); - return; + result = mUniform.insert(uniforms_index_t::value_type(index, location)); + if (result.second) + { + mTexture[index] = mapUniformTextureChannel(location, type); + return; + } } } } @@ -715,10 +722,6 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) mUniformNameMap.clear(); mTexture.clear(); mValue.clear(); - //initialize arrays - U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); - mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); bind(); @@ -910,20 +913,14 @@ S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LL 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]; + GLint channel = getTexChannelForIndex(uniform); - if (uniform > -1) + if (channel > -1) { - gGL.getTexUnit(uniform)->bind(texture, mode); + gGL.getTexUnit(channel)->bind(texture, mode); } - return uniform; + return channel; } S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureType mode) @@ -936,82 +933,64 @@ S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureT 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) + GLint channel = getTexChannelForIndex(uniform); + + if (channel > -1) { - gGL.getTexUnit(uniform)->unbind(mode); + gGL.getTexUnit(channel)->unbind(mode); } - return uniform; + return channel; } S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) { - if (uniform < 0 || uniform >= (S32)mTexture.size()) - { - UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; - return -1; - } - S32 index = mTexture[uniform]; - if (index != -1) + GLint channel = getTexChannelForIndex(uniform); + + if (channel != -1) { - gGL.getTexUnit(index)->activate(); - gGL.getTexUnit(index)->enable(mode); + gGL.getTexUnit(channel)->activate(); + gGL.getTexUnit(channel)->enable(mode); } - return index; + return channel; } S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) { - if (uniform < 0 || uniform >= (S32)mTexture.size()) - { - 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) + GLint channel = getTexChannelForIndex(uniform); + + if (channel != -1 && gGL.getTexUnit(channel)->getCurrType() != LLTexUnit::TT_NONE) { - if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode) + if (gDebugGL && gGL.getTexUnit(channel)->getCurrType() != mode) { if (gDebugSession) { - gFailLog << "Texture channel " << index << " texture type corrupted." << std::endl; + gFailLog << "Texture channel " << channel << " texture type corrupted." << std::endl; ll_fail("LLGLSLShader::disableTexture failed"); } else { - LL_ERRS() << "Texture channel " << index << " texture type corrupted." << LL_ENDL; + LL_ERRS() << "Texture channel " << channel << " texture type corrupted." << LL_ENDL; } } - gGL.getTexUnit(index)->disable(); + gGL.getTexUnit(channel)->disable(); } - return index; + return channel; } void LLGLSLShader::uniform1i(U32 index, GLint x) { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + std::map::iterator iter = mValue.find(location); if (iter == mValue.end() || iter->second.mV[0] != x) { - glUniform1iARB(mUniform[index], x); - mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); + glUniform1iARB(location, x); + mValue[location] = LLVector4(x,0.f,0.f,0.f); } } } @@ -1021,19 +1000,15 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + std::map::iterator iter = mValue.find(location); if (iter == mValue.end() || iter->second.mV[0] != x) { - glUniform1fARB(mUniform[index], x); - mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); + glUniform1fARB(location, x); + mValue[location] = LLVector4(x,0.f,0.f,0.f); } } } @@ -1043,20 +1018,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + std::map::iterator iter = mValue.find(location); 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; + glUniform2fARB(location, x, y); + mValue[location] = vec; } } } @@ -1066,20 +1037,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + std::map::iterator iter = mValue.find(location); 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; + glUniform3fARB(location, x, y, z); + mValue[location] = vec; } } } @@ -1089,20 +1056,16 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + std::map::iterator iter = mValue.find(location); 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; + glUniform4fARB(location, x, y, z, w); + mValue[location] = vec; } } } @@ -1112,20 +1075,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + 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) { - glUniform1ivARB(mUniform[index], count, v); - mValue[mUniform[index]] = vec; + glUniform1ivARB(location, count, v); + mValue[location] = vec; } } } @@ -1135,20 +1094,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + 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(mUniform[index], count, v); - mValue[mUniform[index]] = vec; + glUniform1fvARB(location, count, v); + mValue[location] = vec; } } } @@ -1158,20 +1113,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + 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(mUniform[index], count, v); - mValue[mUniform[index]] = vec; + glUniform2fvARB(location, count, v); + mValue[location] = vec; } } } @@ -1181,20 +1132,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + 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(mUniform[index], count, v); - mValue[mUniform[index]] = vec; + glUniform3fvARB(location, count, v); + mValue[location] = vec; } } } @@ -1204,20 +1151,16 @@ 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; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - std::map::iterator iter = mValue.find(mUniform[index]); + std::map::iterator iter = mValue.find(location); 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; + glUniform4fvARB(location, count, v); + mValue[location] = vec; } } } @@ -1227,15 +1170,11 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - glUniformMatrix2fvARB(mUniform[index], count, transpose, v); + glUniformMatrix2fvARB(location, count, transpose, v); } } } @@ -1244,15 +1183,11 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - glUniformMatrix3fvARB(mUniform[index], count, transpose, v); + glUniformMatrix3fvARB(location, count, transpose, v); } } } @@ -1261,15 +1196,11 @@ void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - glUniformMatrix3x4fv(mUniform[index], count, transpose, v); + glUniformMatrix3x4fv(location, count, transpose, v); } } } @@ -1278,15 +1209,11 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c { if (mProgramObject > 0) { - if (mUniform.size() <= index) - { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; - return; - } + GLint location = getLocationForIndex(index); - if (mUniform[index] >= 0) + if (location >= 0) { - glUniformMatrix4fvARB(mUniform[index], count, transpose, v); + glUniformMatrix4fvARB(location, count, transpose, v); } } } @@ -1317,14 +1244,8 @@ GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform) GLint LLGLSLShader::getUniformLocation(U32 index) { - GLint ret = -1; - if (mProgramObject > 0) - { - llassert(index < mUniform.size()); - return mUniform[index]; - } - - return ret; + /*TODO: flatten this... change calls to gUL(U32) */ + return getLocationForIndex(index); } GLint LLGLSLShader::getAttribLocation(U32 attrib) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 6f10d122cb..75cb6cf757 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -166,14 +166,20 @@ public: U32 mMatHash[LLRender::NUM_MATRIX_MODES]; U32 mLightHash; + typedef std::map uniforms_index_t; + typedef std::pair magmin_values_t; + + typedef std::map < S32, magmin_values_t> magmin_filter_t; + GLhandleARB mProgramObject; std::vector 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 mUniform; //lookup table of uniform enum to uniform location + uniforms_index_t mUniform; + uniforms_index_t mTexture; + 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; S32 mTotalUniformSize; S32 mActiveTextureChannels; S32 mShaderLevel; @@ -197,11 +203,26 @@ public: static U32 sTotalDrawCalls; bool mTextureStateFetched; - std::vector mTextureMagFilter; - std::vector mTextureMinFilter; + magmin_filter_t mTextureMagMinFilter; private: void unloadInternal(); + + inline GLint getLocationForIndex(S32 index) + { + uniforms_index_t::iterator it = mUniform.find(index); + if (it == mUniform.end()) + return -1; + return (*it).second; + } + + inline GLint getTexChannelForIndex(S32 index) + { + uniforms_index_t::iterator it = mTexture.find(index); + if (it == mTexture.end()) + return -1; + return (*it).second; + } }; //UI shader (declared here so llui_libtest will link properly) -- cgit v1.2.3 From 0d414c1fb579dffc122c4d021a84cd126c612e54 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Tue, 26 Sep 2017 09:19:20 -0700 Subject: Clouds still funky but better. --- indra/llrender/llglslshader.cpp | 2 +- indra/llrender/llshadermgr.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index e7457826a3..bba94a976f 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -406,7 +406,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, for ( ; fileIter != mShaderFiles.end(); fileIter++ ) { GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); - LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; + LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << " shaderhandle=" << shaderhandle << LL_ENDL; if (shaderhandle) { attachObject(shaderhandle); diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index e721ad93fa..4e9a1f5de5 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -953,7 +953,8 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade // Add shader file to map mShaderObjects[filename] = ret; shader_level = try_gpu_class; - } + LL_WARNS("RIDER") << "Shader '" << filename << "' loaded with handle=" << ret << LL_ENDL; + } else { if (shader_level > 1) -- cgit v1.2.3 From e97c52bdd3cfdf12c3eb2e423b193979de816f34 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 4 Oct 2017 14:36:41 -0700 Subject: Rename uniform "sunlight_color_copy" to sunlight_color in shader. --- indra/llrender/llshadermgr.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 4e9a1f5de5..b010a4ae64 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -953,7 +953,6 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade // Add shader file to map mShaderObjects[filename] = ret; shader_level = try_gpu_class; - LL_WARNS("RIDER") << "Shader '" << filename << "' loaded with handle=" << ret << LL_ENDL; } else { @@ -1118,7 +1117,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("cloude_noise_texture"); mReservedUniforms.push_back("fullbright"); mReservedUniforms.push_back("lightnorm"); - mReservedUniforms.push_back("sunlight_color_copy"); + mReservedUniforms.push_back("sunlight_color"); mReservedUniforms.push_back("ambient"); mReservedUniforms.push_back("blue_horizon"); mReservedUniforms.push_back("blue_density"); -- cgit v1.2.3 From e4b035d0cd3eaa76fd82643c17e3631c67387a54 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 5 Oct 2017 15:40:48 -0700 Subject: Skys settings object active. --- indra/llrender/llshadermgr.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 394b38f832..7bdd97200d 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -30,6 +30,11 @@ #include "llgl.h" #include "llglslshader.h" +/*RIDER: TODO: + * This should use the LL Singleton<> template... but not a quick conversion. + * (llviewershadermgr derives from this) + */ + class LLShaderMgr { public: @@ -215,7 +220,7 @@ public: TERRAIN_ALPHARAMP, SHINY_ORIGIN, -DISPLAY_GAMMA, + DISPLAY_GAMMA, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From 99b82d944937ce321f64aa91fb18ab2aedd3992a Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Sun, 18 Feb 2018 15:52:23 +0000 Subject: Atmospherics WIP libatmosphere integrated in indra/llrender/llatmosphere.cpp Still working on runtime shaders to use libatmosphere precomputed atmospherics textures --- indra/llrender/CMakeLists.txt | 7 +- indra/llrender/llgl.cpp | 15 ++- indra/llrender/llglslshader.cpp | 5 + indra/llrender/llglslshader.h | 2 + indra/llrender/llgltexture.cpp | 198 +++++++++++++++++++++------------------- indra/llrender/llgltexture.h | 10 +- indra/llrender/llimagegl.cpp | 39 ++++++-- indra/llrender/llimagegl.h | 9 +- indra/llrender/llrender.cpp | 4 +- indra/llrender/llrender.h | 10 +- indra/llrender/llshadermgr.cpp | 28 ++++-- indra/llrender/llshadermgr.h | 11 +++ indra/llrender/lltexture.cpp | 12 +++ indra/llrender/lltexture.h | 22 ++--- 14 files changed, 239 insertions(+), 133 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 331f988382..89451a072c 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -13,6 +13,7 @@ include(LLVFS) include(LLWindow) include(LLXML) include(LLVFS) +include(Atmosphere) include_directories( ${FREETYPE_INCLUDE_DIRS} @@ -24,6 +25,7 @@ include_directories( ${LLWINDOW_INCLUDE_DIRS} ${LLXML_INCLUDE_DIRS} ${LLVFS_INCLUDE_DIRS} + ${ATMOSPHERE_INCLUDE_DIR} ) include_directories(SYSTEM ${LLCOMMON_SYSTEM_INCLUDE_DIRS} @@ -31,6 +33,7 @@ include_directories(SYSTEM ) set(llrender_SOURCE_FILES + llatmosphere.cpp llcubemap.cpp llfontbitmapcache.cpp llfontfreetype.cpp @@ -56,6 +59,7 @@ set(llrender_SOURCE_FILES set(llrender_HEADER_FILES CMakeLists.txt + llatmosphere.h llcubemap.h llfontgl.h llfontfreetype.h @@ -126,5 +130,6 @@ target_link_libraries(llrender ${LLVFS_LIBRARIES} ${LLWINDOW_LIBRARIES} ${FREETYPE_LIBRARIES} - ${OPENGL_LIBRARIES}) + ${OPENGL_LIBRARIES} + ${ATMOSPHERE_LIBRARIES}) diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 155c2402bd..2f78b6e104 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -1348,8 +1348,19 @@ void LLGLManager::initExtensions() if (mHasVertexShader) { LL_INFOS() << "initExtensions() VertexShader-related procs..." << LL_ENDL; - glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); - glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); + + // nSight doesn't support use of ARB funcs that have been normalized in the API + if (!LLRender::sNsightDebugSupport) + { + glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); + glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); + } + else + { + glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocation"); + glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocation"); + } + glGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveAttribARB"); glVertexAttrib1dARB = (PFNGLVERTEXATTRIB1DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dARB"); glVertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dvARB"); diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index bba94a976f..b09ec53bc0 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -401,6 +401,11 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, mDefines["OLD_SELECT"] = "1"; #endif + if (mExtraLinkObject) + { + attachObject(mExtraLinkObject); + } + //compile new source vector< pair >::iterator fileIter = mShaderFiles.begin(); for ( ; fileIter != mShaderFiles.end(); fileIter++ ) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 8e9c29ea4c..a7a9e27fcd 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -205,6 +205,8 @@ public: bool mTextureStateFetched; magmin_filter_t mTextureMagMinFilter; + GLhandleARB mExtraLinkObject = 0; + private: void unloadInternal(); diff --git a/indra/llrender/llgltexture.cpp b/indra/llrender/llgltexture.cpp index 3a6eebebba..c0e5477cea 100644 --- a/indra/llrender/llgltexture.cpp +++ b/indra/llrender/llgltexture.cpp @@ -30,20 +30,20 @@ // static S32 LLGLTexture::getTotalNumOfCategories() { - return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2 ; + return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2; } // static //index starts from zero. S32 LLGLTexture::getIndexFromCategory(S32 category) { - return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1 ; + return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1; } //static S32 LLGLTexture::getCategoryFromIndex(S32 index) { - return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1 ; + return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1; } LLGLTexture::LLGLTexture(BOOL usemipmaps) @@ -55,19 +55,19 @@ LLGLTexture::LLGLTexture(BOOL usemipmaps) LLGLTexture::LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) { init(); - mFullWidth = width ; - mFullHeight = height ; + mFullWidth = width; + mFullHeight = height; mUseMipMaps = usemipmaps; - mComponents = components ; + mComponents = components; setTexelsPerImage(); } LLGLTexture::LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps) { init(); - mUseMipMaps = usemipmaps ; + mUseMipMaps = usemipmaps; // Create an empty image of the specified size and width - mGLTexturep = new LLImageGL(raw, usemipmaps) ; + mGLTexturep = new LLImageGL(raw, usemipmaps); } LLGLTexture::~LLGLTexture() @@ -81,13 +81,13 @@ void LLGLTexture::init() mFullWidth = 0; mFullHeight = 0; - mTexelsPerImage = 0 ; - mUseMipMaps = FALSE ; - mComponents = 0 ; + mTexelsPerImage = 0; + mUseMipMaps = FALSE; + mComponents = 0; - mTextureState = NO_DELETE ; + mTextureState = NO_DELETE; mDontDiscard = FALSE; - mNeedsGLTexture = FALSE ; + mNeedsGLTexture = FALSE; } void LLGLTexture::cleanup() @@ -111,287 +111,301 @@ void LLGLTexture::setBoostLevel(S32 level) { if(mBoostLevel != level) { - mBoostLevel = level ; + mBoostLevel = level; if(mBoostLevel != LLGLTexture::BOOST_NONE && mBoostLevel != LLGLTexture::BOOST_ICON) { - setNoDelete() ; + setNoDelete(); } } } void LLGLTexture::forceActive() { - mTextureState = ACTIVE ; + mTextureState = ACTIVE; } void LLGLTexture::setActive() { if(mTextureState != NO_DELETE) { - mTextureState = ACTIVE ; + mTextureState = ACTIVE; } } //set the texture to stay in memory void LLGLTexture::setNoDelete() { - mTextureState = NO_DELETE ; + mTextureState = NO_DELETE; } void LLGLTexture::generateGLTexture() { if(mGLTexturep.isNull()) { - mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ; + mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps); } } LLImageGL* LLGLTexture::getGLTexture() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep ; + return mGLTexturep; } BOOL LLGLTexture::createGLTexture() { if(mGLTexturep.isNull()) { - generateGLTexture() ; + generateGLTexture(); } - return mGLTexturep->createGLTexture() ; + return mGLTexturep->createGLTexture(); } BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category) ; + BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category); if(ret) { - mFullWidth = mGLTexturep->getCurrentWidth() ; - mFullHeight = mGLTexturep->getCurrentHeight() ; - mComponents = mGLTexturep->getComponents() ; + mFullWidth = mGLTexturep->getCurrentWidth(); + mFullHeight = mGLTexturep->getCurrentHeight(); + mComponents = mGLTexturep->getComponents(); setTexelsPerImage(); } - return ret ; + return ret; } void LLGLTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ; + mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes); } void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode) { - llassert(mGLTexturep.notNull()) ; - mGLTexturep->setAddressMode(mode) ; + llassert(mGLTexturep.notNull()); + mGLTexturep->setAddressMode(mode); } void LLGLTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option) { - llassert(mGLTexturep.notNull()) ; - mGLTexturep->setFilteringOption(option) ; + llassert(mGLTexturep.notNull()); + mGLTexturep->setFilteringOption(option); } //virtual S32 LLGLTexture::getWidth(S32 discard_level) const { - llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getWidth(discard_level) ; + llassert(mGLTexturep.notNull()); + return mGLTexturep->getWidth(discard_level); } //virtual S32 LLGLTexture::getHeight(S32 discard_level) const { - llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getHeight(discard_level) ; + llassert(mGLTexturep.notNull()); + return mGLTexturep->getHeight(discard_level); } S32 LLGLTexture::getMaxDiscardLevel() const { - llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getMaxDiscardLevel() ; + llassert(mGLTexturep.notNull()); + return mGLTexturep->getMaxDiscardLevel(); } S32 LLGLTexture::getDiscardLevel() const { - llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getDiscardLevel() ; + llassert(mGLTexturep.notNull()); + return mGLTexturep->getDiscardLevel(); } S8 LLGLTexture::getComponents() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getComponents() ; + return mGLTexturep->getComponents(); } LLGLuint LLGLTexture::getTexName() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getTexName() ; + return mGLTexturep->getTexName(); } BOOL LLGLTexture::hasGLTexture() const { if(mGLTexturep.notNull()) { - return mGLTexturep->getHasGLTexture() ; + return mGLTexturep->getHasGLTexture(); } - return FALSE ; + return FALSE; } BOOL LLGLTexture::getBoundRecently() const { if(mGLTexturep.notNull()) { - return mGLTexturep->getBoundRecently() ; + return mGLTexturep->getBoundRecently(); } - return FALSE ; + return FALSE; } LLTexUnit::eTextureType LLGLTexture::getTarget(void) const { - llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getTarget() ; + llassert(mGLTexturep.notNull()); + return mGLTexturep->getTarget(); } BOOL LLGLTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height) ; + return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height); } BOOL LLGLTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height) ; + return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height); } void LLGLTexture::setGLTextureCreated (bool initialized) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - mGLTexturep->setGLTextureCreated (initialized) ; + mGLTexturep->setGLTextureCreated (initialized); } void LLGLTexture::setCategory(S32 category) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); + + mGLTexturep->setCategory(category); +} - mGLTexturep->setCategory(category) ; +void LLGLTexture::setTexName(LLGLuint texName) +{ + llassert(mGLTexturep.notNull()); + return mGLTexturep->setTexName(texName); +} + +void LLGLTexture::setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target) +{ + llassert(mGLTexturep.notNull()); + return mGLTexturep->setTarget(target, bind_target); } LLTexUnit::eTextureAddressMode LLGLTexture::getAddressMode(void) const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getAddressMode() ; + return mGLTexturep->getAddressMode(); } S32Bytes LLGLTexture::getTextureMemory() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->mTextureMemory ; + return mGLTexturep->mTextureMemory; } LLGLenum LLGLTexture::getPrimaryFormat() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getPrimaryFormat() ; + return mGLTexturep->getPrimaryFormat(); } BOOL LLGLTexture::getIsAlphaMask() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getIsAlphaMask() ; + return mGLTexturep->getIsAlphaMask(); } BOOL LLGLTexture::getMask(const LLVector2 &tc) { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getMask(tc) ; + return mGLTexturep->getMask(tc); } F32 LLGLTexture::getTimePassedSinceLastBound() { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getTimePassedSinceLastBound() ; + return mGLTexturep->getTimePassedSinceLastBound(); } BOOL LLGLTexture::getMissed() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getMissed() ; + return mGLTexturep->getMissed(); } BOOL LLGLTexture::isJustBound() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->isJustBound() ; + return mGLTexturep->isJustBound(); } void LLGLTexture::forceUpdateBindStats(void) const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->forceUpdateBindStats() ; + return mGLTexturep->forceUpdateBindStats(); } U32 LLGLTexture::getTexelsInAtlas() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getTexelsInAtlas() ; + return mGLTexturep->getTexelsInAtlas(); } U32 LLGLTexture::getTexelsInGLTexture() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getTexelsInGLTexture() ; + return mGLTexturep->getTexelsInGLTexture(); } BOOL LLGLTexture::isGLTextureCreated() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->isGLTextureCreated() ; + return mGLTexturep->isGLTextureCreated(); } S32 LLGLTexture::getDiscardLevelInAtlas() const { - llassert(mGLTexturep.notNull()) ; + llassert(mGLTexturep.notNull()); - return mGLTexturep->getDiscardLevelInAtlas() ; + return mGLTexturep->getDiscardLevelInAtlas(); } void LLGLTexture::destroyGLTexture() { if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture()) { - mGLTexturep->destroyGLTexture() ; - mTextureState = DELETED ; + mGLTexturep->destroyGLTexture(); + mTextureState = DELETED; } } void LLGLTexture::setTexelsPerImage() { - S32 fullwidth = llmin(mFullWidth,(S32)MAX_IMAGE_SIZE_DEFAULT); - S32 fullheight = llmin(mFullHeight,(S32)MAX_IMAGE_SIZE_DEFAULT); - mTexelsPerImage = (F32)fullwidth * fullheight; + U32 fullwidth = llmin(mFullWidth, (U32)MAX_IMAGE_SIZE_DEFAULT); + U32 fullheight = llmin(mFullHeight, (U32)MAX_IMAGE_SIZE_DEFAULT); + mTexelsPerImage = (U32)fullwidth * fullheight; } +static LLUUID sStubUUID; +const LLUUID& LLGLTexture::getID() const { return sStubUUID; } \ No newline at end of file diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h index 45592ee077..a57e48ffad 100644 --- a/indra/llrender/llgltexture.h +++ b/indra/llrender/llgltexture.h @@ -103,7 +103,7 @@ public: virtual void dump(); // debug info to LL_INFOS() - virtual const LLUUID& getID() const = 0; + virtual const LLUUID& getID() const; void setBoostLevel(S32 level); S32 getBoostLevel() { return mBoostLevel; } @@ -132,6 +132,8 @@ public: BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height); void setGLTextureCreated (bool initialized); void setCategory(S32 category) ; + void setTexName(LLGLuint); // for forcing w/ externally created textures only + void setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target); LLTexUnit::eTextureAddressMode getAddressMode(void) const ; S32 getMaxDiscardLevel() const; @@ -178,11 +180,11 @@ protected: protected: S32 mBoostLevel; // enum describing priority level - S32 mFullWidth; - S32 mFullHeight; + U32 mFullWidth; + U32 mFullHeight; BOOL mUseMipMaps; S8 mComponents; - F32 mTexelsPerImage; // Texels per image. + U32 mTexelsPerImage; // Texels per image. mutable S8 mNeedsGLTexture; //GL texture diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 20cba68f84..75f6cd405a 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -352,10 +352,9 @@ BOOL LLImageGL::create(LLPointer& dest, const LLImageRaw* imageraw, B } //---------------------------------------------------------------------------- - LLImageGL::LLImageGL(BOOL usemipmaps) : LLTrace::MemTrackable("LLImageGL"), - mSaveData(0) + mSaveData(0), mExternalTexture(FALSE) { init(usemipmaps); setSize(0, 0, 0); @@ -365,7 +364,7 @@ LLImageGL::LLImageGL(BOOL usemipmaps) LLImageGL::LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps) : LLTrace::MemTrackable("LLImageGL"), - mSaveData(0) + mSaveData(0), mExternalTexture(FALSE) { llassert( components <= 4 ); init(usemipmaps); @@ -376,7 +375,7 @@ LLImageGL::LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps) LLImageGL::LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps) : LLTrace::MemTrackable("LLImageGL"), - mSaveData(0) + mSaveData(0), mExternalTexture(FALSE) { init(usemipmaps); setSize(0, 0, 0); @@ -386,12 +385,36 @@ LLImageGL::LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps) createGLTexture(0, imageraw); } +LLImageGL::LLImageGL( + LLGLuint texName, + U32 components, + LLGLenum target, + LLGLint formatInternal, + LLGLenum formatPrimary, + LLGLenum formatType, + LLTexUnit::eTextureAddressMode addressMode) + : LLTrace::MemTrackable("LLImageGL"), mSaveData(0), mExternalTexture(TRUE) +{ + init(false); + mTexName = texName; + mTarget = target; + mComponents = components; + mAddressMode = addressMode; + mFormatType = formatType; + mFormatInternal = formatInternal; + mFormatPrimary = formatPrimary; +} + + LLImageGL::~LLImageGL() { - LLImageGL::cleanup(); - sImageList.erase(this); - freePickMask(); - sCount--; + if (!mExternalTexture) + { + LLImageGL::cleanup(); + sImageList.erase(this); + freePickMask(); + sCount--; + } } void LLImageGL::init(BOOL usemipmaps) diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index ad2aea9067..bb0284a166 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -84,7 +84,10 @@ public: LLImageGL(BOOL usemipmaps = TRUE); LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps = TRUE); LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps = TRUE); - + + // For wrapping textures created via GL elsewhere with our API only. Use with caution. + LLImageGL(LLGLuint mTexName, U32 components, LLGLenum target, LLGLint formatInternal, LLGLenum formatPrimary, LLGLenum formatType, LLTexUnit::eTextureAddressMode addressMode); + protected: virtual ~LLImageGL(); @@ -234,6 +237,8 @@ protected: LLGLenum mFormatType; BOOL mFormatSwapBytes;// if true, use glPixelStorei(GL_UNPACK_SWAP_BYTES, 1) + BOOL mExternalTexture; + // STATICS public: static std::set sImageList; @@ -279,6 +284,8 @@ public: void setCategory(S32 category) {mCategory = category;} S32 getCategory()const {return mCategory;} + void setTexName(GLuint texName) { mTexName = texName; } + //for debug use: show texture size distribution //---------------------------------------- static S32 sCurTexSizeBar ; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 76f28bb43f..a8f622d3ff 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -49,6 +49,7 @@ U32 LLRender::sUICalls = 0; U32 LLRender::sUIVerts = 0; U32 LLTexUnit::sWhiteTexture = 0; bool LLRender::sGLCoreProfile = false; +bool LLRender::sNsightDebugSupport = false; static const U32 LL_NUM_TEXTURE_LAYERS = 32; static const U32 LL_NUM_LIGHT_UNITS = 8; @@ -58,7 +59,8 @@ static const GLenum sGLTextureType[] = GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_CUBE_MAP_ARB, - GL_TEXTURE_2D_MULTISAMPLE + GL_TEXTURE_2D_MULTISAMPLE, + GL_TEXTURE_3D }; static const GLint sGLAddressMode[] = diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index a67fb8da52..9ad3a6e593 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -61,10 +61,11 @@ public: typedef enum { TT_TEXTURE = 0, // Standard 2D Texture - TT_RECT_TEXTURE, // Non power of 2 texture - TT_CUBE_MAP, // 6-sided cube map texture + TT_RECT_TEXTURE, // Non power of 2 texture + TT_CUBE_MAP, // 6-sided cube map texture TT_MULTISAMPLE_TEXTURE, // see GL_ARB_texture_multisample - TT_NONE // No texture type is currently enabled + TT_TEXTURE_3D, // standard 3D Texture + TT_NONE, // No texture type is currently enabled } eTextureType; typedef enum @@ -438,7 +439,8 @@ public: static U32 sUICalls; static U32 sUIVerts; static bool sGLCoreProfile; - + static bool sNsightDebugSupport; + private: friend class LLLightState; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index b010a4ae64..287f22783f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -512,16 +512,16 @@ static std::string get_object_log(GLhandleARB ret) void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename) { std::string log = get_object_log(ret); + std::string fname = filename; + if (filename.empty()) + { + fname = "unknown shader file"; + } - if (log.length() > 0 || warns) + if (log.length() > 0) { - LL_DEBUGS("ShaderLoading") << "Shader loading "; - - if (!filename.empty()) - { - LL_CONT << "From " << filename << ":\n"; - } - LL_CONT << log << LL_ENDL; + LL_INFOS() << "Shader loading from " << fname << ":\n" << LL_ENDL; + LL_INFOS() << log << LL_ENDL; } } @@ -1114,7 +1114,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("specularMap"); mReservedUniforms.push_back("bumpMap"); mReservedUniforms.push_back("environmentMap"); - mReservedUniforms.push_back("cloude_noise_texture"); + mReservedUniforms.push_back("cloud_noise_texture"); mReservedUniforms.push_back("fullbright"); mReservedUniforms.push_back("lightnorm"); mReservedUniforms.push_back("sunlight_color"); @@ -1267,6 +1267,16 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("origin"); mReservedUniforms.push_back("display_gamma"); + + mReservedUniforms.push_back("inscatter"); + mReservedUniforms.push_back("sun_size"); + mReservedUniforms.push_back("fog_color"); + + mReservedUniforms.push_back("transmittance_texture"); + mReservedUniforms.push_back("scattering_texture"); + mReservedUniforms.push_back("irradiance_texture"); + mReservedUniforms.push_back("single_mie_scattering_texture"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 7bdd97200d..ac3f7d58d5 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -221,6 +221,17 @@ public: SHINY_ORIGIN, DISPLAY_GAMMA, + + INSCATTER_RT, + SUN_SIZE, + FOG_COLOR, + + // precomputed textures from libatmosphere + TRANSMITTANCE_TEX, + SCATTER_TEX, + ILLUMINANCE_TEX, + SINGLE_MIE_SCATTER_TEX, + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; diff --git a/indra/llrender/lltexture.cpp b/indra/llrender/lltexture.cpp index 90fbcec2be..787a09a159 100644 --- a/indra/llrender/lltexture.cpp +++ b/indra/llrender/lltexture.cpp @@ -29,3 +29,15 @@ LLTexture::~LLTexture() { } + +S8 LLTexture::getType() const { llassert(false); return 0; } +void LLTexture::setKnownDrawSize(S32 width, S32 height) { llassert(false); } +bool LLTexture::bindDefaultImage(const S32 stage) { llassert(false); return false; } +bool LLTexture::bindDebugImage(const S32 stage) { llassert(false); return false; } +void LLTexture::forceImmediateUpdate() { llassert(false); } +void LLTexture::setActive() { llassert(false); } +S32 LLTexture::getWidth(S32 discard_level) const { llassert(false); return 0; } +S32 LLTexture::getHeight(S32 discard_level) const { llassert(false); return 0; } +bool LLTexture::isActiveFetching() { llassert(false); return false; } +LLImageGL* LLTexture::getGLTexture() const { llassert(false); return nullptr; } +void LLTexture::updateBindStatsForTester() { } \ No newline at end of file diff --git a/indra/llrender/lltexture.h b/indra/llrender/lltexture.h index 9fca8b8cd3..41481fb8a7 100644 --- a/indra/llrender/lltexture.h +++ b/indra/llrender/lltexture.h @@ -58,21 +58,21 @@ public: // //interfaces to access LLGLTexture // - virtual S8 getType() const = 0 ; - virtual void setKnownDrawSize(S32 width, S32 height) = 0 ; - virtual bool bindDefaultImage(const S32 stage = 0) = 0 ; - virtual bool bindDebugImage(const S32 stage = 0) = 0; - virtual void forceImmediateUpdate() = 0 ; - virtual void setActive() = 0 ; - virtual S32 getWidth(S32 discard_level = -1) const = 0 ; - virtual S32 getHeight(S32 discard_level = -1) const = 0 ; - virtual bool isActiveFetching() = 0; + virtual S8 getType() const; + virtual void setKnownDrawSize(S32 width, S32 height); + virtual bool bindDefaultImage(const S32 stage = 0); + virtual bool bindDebugImage(const S32 stage = 0); + virtual void forceImmediateUpdate(); + virtual void setActive(); + virtual S32 getWidth(S32 discard_level = -1) const; + virtual S32 getHeight(S32 discard_level = -1) const; + virtual bool isActiveFetching(); private: //note: do not make this function public. - virtual LLImageGL* getGLTexture() const = 0 ; + virtual LLImageGL* getGLTexture() const; - virtual void updateBindStatsForTester() = 0 ; + virtual void updateBindStatsForTester(); }; #endif -- cgit v1.2.3 From 6cc4a091b3ba4dd4842cc06e3b34af3d04dc5796 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Thu, 22 Feb 2018 00:35:24 +0000 Subject: Add settings/validations for new advanced atmo settings. --- indra/llrender/CMakeLists.txt | 7 +- indra/llrender/llatmosphere.cpp | 218 ++++++++++++++++++++++++++++++++++++++++ indra/llrender/llatmosphere.h | 72 +++++++++++++ indra/llrender/llgltexture.h | 2 +- 4 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 indra/llrender/llatmosphere.cpp create mode 100644 indra/llrender/llatmosphere.h (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 89451a072c..dcfbd71dec 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -107,7 +107,9 @@ if (BUILD_HEADLESS) ${LLXML_LIBRARIES} ${LLVFS_LIBRARIES} ${LLWINDOW_HEADLESS_LIBRARIES} - ${OPENGL_HEADLESS_LIBRARIES}) + ${LIBATMOSPHERE_LIBRARIES} + ${OPENGL_HEADLESS_LIBRARIES} + ) endif (BUILD_HEADLESS) @@ -130,6 +132,7 @@ target_link_libraries(llrender ${LLVFS_LIBRARIES} ${LLWINDOW_LIBRARIES} ${FREETYPE_LIBRARIES} + ${LIBATMOSPHERE_LIBRARIES} ${OPENGL_LIBRARIES} - ${ATMOSPHERE_LIBRARIES}) + ) diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp new file mode 100644 index 0000000000..fb159a3e47 --- /dev/null +++ b/indra/llrender/llatmosphere.cpp @@ -0,0 +1,218 @@ +/** + * @file llatmosphere.cpp + * @brief LLAtmosphere integration impl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llatmosphere.h" +#include "llfasttimer.h" +#include "llsys.h" +#include "llglheaders.h" +#include "llrender.h" +#include "llshadermgr.h" +#include "llglslshader.h" + +LLAtmosphere* gAtmosphere = nullptr; + +void LLAtmosphere::initClass() +{ + if (!gAtmosphere) + { + gAtmosphere = new LLAtmosphere; + } +} + +void LLAtmosphere::cleanupClass() +{ + if(gAtmosphere) + { + delete gAtmosphere; + } + gAtmosphere = NULL; +} + +LLAtmosphere::LLAtmosphere() +{ + // Init libatmosphere model + m_config.num_scattering_orders = 4; + + // Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column + // (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), + // summed and averaged in each bin (e.g. the value for 360nm is the average + // of the ASTM G-173 values for all wavelengths between 360 and 370nm). + // Values in W.m^-2. + const int kLambdaMin = 360; + const int kLambdaMax = 830; + const double kSolarIrradiance[48] = { + 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, + 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, + 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, + 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, + 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, + 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 + }; + + // Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ + // referencespectra/o3spectra2011/index.html for 233K, summed and averaged in + // each bin (e.g. the value for 360nm is the average of the original values + // for all wavelengths between 360 and 370nm). Values in m^2. + const double kOzoneCrossSection[48] = { + 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, + 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, + 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, + 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, + 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, + 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, + 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 + }; + + // From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. + const double kDobsonUnit = 2.687e20; + + // Maximum number density of ozone molecules, in m^-3 (computed so at to get + // 300 Dobson units of ozone - for this we divide 300 DU by the integral of + // the ozone density profile defined below, which is equal to 15km). + const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; + + const double kSunAngularRadius = 0.00935 / 2.0; + const double kBottomRadius = 6360000.0; + const double kTopRadius = 6420000.0; + const double kRayleigh = 1.24062e-6; + const double kRayleighScaleHeight = 8000.0; + const double kMieScaleHeight = 1200.0; + const double kMieAngstromAlpha = 0.0; + const double kMieAngstromBeta = 5.328e-3; + const double kMieSingleScatteringAlbedo = 0.9; + const double kMiePhaseFunctionG = 0.8; + const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; + + atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); + atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); + + // Density profile increasing linearly from 0 to 1 between 10 and 25km, and + // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate + // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ + // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). + std::vector ozone_density; + ozone_density.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); + ozone_density.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); + + std::vector wavelengths; + std::vector solar_irradiance; + std::vector rayleigh_scattering; + std::vector mie_scattering; + std::vector mie_extinction; + std::vector absorption_extinction; + std::vector ground_albedo; + + for (int l = kLambdaMin; l <= kLambdaMax; l += 10) + { + double lambda = static_cast(l) * 1e-3; // micro-meters + double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); + wavelengths.push_back(l); + solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); + rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); + mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); + mie_extinction.push_back(mie); + absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); + ground_albedo.push_back(0.1f); + } + + m_model = new atmosphere::Model( + wavelengths, + solar_irradiance, + kSunAngularRadius, + kBottomRadius, + kTopRadius, + {rayleigh_density}, + rayleigh_scattering, + {mie_density}, + mie_scattering, + mie_extinction, + kMiePhaseFunctionG, + ozone_density, + absorption_extinction, + ground_albedo, + max_sun_zenith_angle, + 1000.0, + 15, + false, + true); + + m_model->Init(m_config, m_textures); + + m_transmittance = new LLGLTexture; + m_scattering = new LLGLTexture; + m_mie_scattering = new LLGLTexture; + + m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_transmittance->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); + m_transmittance->setTexName(m_textures.transmittance_texture); + m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); + + m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_scattering->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); + m_scattering->setTexName(m_textures.transmittance_texture); + m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + + m_mie_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_mie_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_mie_scattering->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); + m_mie_scattering->setTexName(m_textures.transmittance_texture); + m_mie_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); +}; + +LLAtmosphere::~LLAtmosphere() +{ + // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. + m_transmittance->setTexName(0); + m_scattering->setTexName(0); + m_mie_scattering->setTexName(0); + + delete m_model; + m_model = nullptr; +} + +LLGLTexture* LLAtmosphere::getTransmittance() const +{ + return m_transmittance; +} + +LLGLTexture* LLAtmosphere::getScattering() const +{ + return m_scattering; +} + +LLGLTexture* LLAtmosphere::getMieScattering() const +{ + return m_mie_scattering; +} + +GLuint LLAtmosphere::getAtmosphericShaderForLink() const +{ + return m_model ? m_model->GetShader() : 0; +} diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h new file mode 100644 index 0000000000..4aa36be27f --- /dev/null +++ b/indra/llrender/llatmosphere.h @@ -0,0 +1,72 @@ +/** + * @file llatmosphere.h + * @brief LLAtmosphere class for integration with libatmosphere + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_ATMOSPHERE_H +#define LL_ATMOSPHERE_H + +#include "llglheaders.h" +#include "llgltexture.h" +#include "libatmosphere/model.h" + +class LLAtmosphere +{ +public: + LLAtmosphere(); + ~LLAtmosphere(); + + static void initClass(); + static void cleanupClass(); + + const LLAtmosphere& operator=(const LLAtmosphere& rhs) + { + LL_ERRS() << "Illegal operation!" << LL_ENDL; + return *this; + } + + LLGLTexture* getTransmittance() const; + LLGLTexture* getScattering() const; + LLGLTexture* getMieScattering() const; + + GLuint getAtmosphericShaderForLink() const; + +protected: + LLAtmosphere(const LLAtmosphere& rhs) + { + *this = rhs; + } + + atmosphere::ModelConfig m_config; + atmosphere::PrecomputedTextures m_textures; + atmosphere::Model* m_model = nullptr; + + LLPointer m_transmittance; + LLPointer m_scattering; + LLPointer m_mie_scattering; +}; + +extern LLAtmosphere* gAtmosphere; + +#endif // LL_ATMOSPHERE_H diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h index a57e48ffad..b8d646ed15 100644 --- a/indra/llrender/llgltexture.h +++ b/indra/llrender/llgltexture.h @@ -133,7 +133,7 @@ public: void setGLTextureCreated (bool initialized); void setCategory(S32 category) ; void setTexName(LLGLuint); // for forcing w/ externally created textures only - void setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target); + void setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target); LLTexUnit::eTextureAddressMode getAddressMode(void) const ; S32 getMaxDiscardLevel() const; -- cgit v1.2.3 From 6303ef5763393021d35c55a012cacfa7ee8c650e Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 26 Feb 2018 16:38:50 +0000 Subject: Redo advanced atmo shader integration with SL. --- indra/llrender/llatmosphere.cpp | 3 +++ indra/llrender/llglslshader.cpp | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index fb159a3e47..8840f49454 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -167,18 +167,21 @@ LLAtmosphere::LLAtmosphere() m_scattering = new LLGLTexture; m_mie_scattering = new LLGLTexture; + m_transmittance->generateGLTexture(); m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); m_transmittance->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); m_transmittance->setTexName(m_textures.transmittance_texture); m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); + m_scattering->generateGLTexture(); m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); m_scattering->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); m_scattering->setTexName(m_textures.transmittance_texture); m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + m_mie_scattering->generateGLTexture(); m_mie_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_mie_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); m_mie_scattering->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b09ec53bc0..a5939a6eb9 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -374,6 +374,8 @@ void LLGLSLShader::unloadInternal() stop_glerror(); } +#pragma optimize("", off) + BOOL LLGLSLShader::createShader(std::vector * attributes, std::vector * uniforms, U32 varying_count, @@ -490,6 +492,8 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, return success; } +#pragma optimize("", on) + BOOL LLGLSLShader::attachObject(std::string object) { if (LLShaderMgr::instance()->mShaderObjects.count(object) > 0) -- cgit v1.2.3 From 98862a53a77cd1ce9a2cae596a743669cc32a2af Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Sat, 3 Mar 2018 00:53:39 +0000 Subject: Fix 16F enum for compat w/ SL gl headers on Mac. Make density profile/layer parsing handle when LLSD heard you liked arrays so it put an array in your array. --- indra/llrender/llatmosphere.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 8840f49454..a8557e82da 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -170,21 +170,21 @@ LLAtmosphere::LLAtmosphere() m_transmittance->generateGLTexture(); m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_transmittance->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); + m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); m_transmittance->setTexName(m_textures.transmittance_texture); m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); m_scattering->generateGLTexture(); m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_scattering->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); + m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); m_scattering->setTexName(m_textures.transmittance_texture); m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); m_mie_scattering->generateGLTexture(); m_mie_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_mie_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_mie_scattering->setExplicitFormat(GL_RGB16F, GL_RGB, GL_FLOAT); + m_mie_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); m_mie_scattering->setTexName(m_textures.transmittance_texture); m_mie_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); }; -- cgit v1.2.3 From 5517eb3f6f06226fba0ffe510334f519a8a7d7b7 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Sat, 3 Mar 2018 01:08:58 +0000 Subject: Remove MSVC pragmas breaking OSX build. --- indra/llrender/llglslshader.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index a5939a6eb9..b09ec53bc0 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -374,8 +374,6 @@ void LLGLSLShader::unloadInternal() stop_glerror(); } -#pragma optimize("", off) - BOOL LLGLSLShader::createShader(std::vector * attributes, std::vector * uniforms, U32 varying_count, @@ -492,8 +490,6 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, return success; } -#pragma optimize("", on) - BOOL LLGLSLShader::attachObject(std::string object) { if (LLShaderMgr::instance()->mShaderObjects.count(object) > 0) -- cgit v1.2.3 From 7ba03ede49a0850016c0b3f97863c0ec9944b251 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Tue, 6 Mar 2018 17:42:54 +0000 Subject: Modify use of linkable shader from libatmosphere. Update to use latest 3p-libatmo build packages. --- indra/llrender/llatmosphere.cpp | 2 +- indra/llrender/llatmosphere.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index a8557e82da..6ce5292839 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -215,7 +215,7 @@ LLGLTexture* LLAtmosphere::getMieScattering() const return m_mie_scattering; } -GLuint LLAtmosphere::getAtmosphericShaderForLink() const +GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const { return m_model ? m_model->GetShader() : 0; } diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h index 4aa36be27f..6a9d1a4438 100644 --- a/indra/llrender/llatmosphere.h +++ b/indra/llrender/llatmosphere.h @@ -50,7 +50,7 @@ public: LLGLTexture* getScattering() const; LLGLTexture* getMieScattering() const; - GLuint getAtmosphericShaderForLink() const; + GLhandleARB getAtmosphericShaderForLink() const; protected: LLAtmosphere(const LLAtmosphere& rhs) -- cgit v1.2.3 From 1d522aca8a5d5205f6d6150699ce5b9b8425c007 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Tue, 6 Mar 2018 19:20:52 +0000 Subject: Reference updated libatmosphere package. --- indra/llrender/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index dcfbd71dec..26aaf10d07 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -132,7 +132,7 @@ target_link_libraries(llrender ${LLVFS_LIBRARIES} ${LLWINDOW_LIBRARIES} ${FREETYPE_LIBRARIES} - ${LIBATMOSPHERE_LIBRARIES} + ${LIBATMOSPHERE_LIBRARIES} ${OPENGL_LIBRARIES} ) -- cgit v1.2.3 From cf460b13bee894684d0ca1bcb5bbc9eb38df719c Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 16:24:16 +0100 Subject: De-duplicate sRGB conversion funcs from many shaders and unify on using the version that works on OSX. Add more logging to shader loading about fallbacks and loading succcess. Add frag shaders for sharing sRGB and normal encode/decode via GL shader linkage. --- indra/llrender/llglslshader.cpp | 1 + indra/llrender/llglslshader.h | 1 + indra/llrender/llshadermgr.cpp | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b09ec53bc0..6bea2e7a76 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -84,6 +84,7 @@ LLShaderFeatures::LLShaderFeatures() , hasObjectSkinning(false) , hasAtmospherics(false) , hasGamma(false) + , hasSrgb(false) , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index a7a9e27fcd..b6c54a0bf8 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -48,6 +48,7 @@ public: bool hasObjectSkinning; bool hasAtmospherics; bool hasGamma; + bool hasSrgb; S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 287f22783f..6c816d0dc4 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -41,6 +41,8 @@ #define UNIFORM_ERRS LL_ERRS("Shader") #endif +#pragma optimize("", off) + // Lots of STL stuff in here, using namespace std to keep things more readable using std::vector; using std::pair; @@ -202,7 +204,15 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) return FALSE; } } - + + if (features->hasSrgb) + { + if (!shader->attachObject("environment/srgbF.glsl")) + { + return FALSE; + } + } + if (features->hasAtmospherics) { if (!shader->attachObject("windlight/atmosphericsF.glsl")) -- cgit v1.2.3 From 98b2fed85fd459012ed2b859ea40a3f56d27c0e8 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 17:52:04 +0100 Subject: De-duplicate shader code for encoding and decoding normals to/from gbuffer format. --- indra/llrender/llglslshader.cpp | 2 ++ indra/llrender/llglslshader.h | 2 ++ indra/llrender/llshadermgr.cpp | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 6bea2e7a76..73ab95cf3b 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -85,6 +85,8 @@ LLShaderFeatures::LLShaderFeatures() , hasAtmospherics(false) , hasGamma(false) , hasSrgb(false) + , encodesNormal(false) + , decodesNormal(false) , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index b6c54a0bf8..562cbdcba9 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -49,6 +49,8 @@ public: bool hasAtmospherics; bool hasGamma; bool hasSrgb; + bool encodesNormal; + bool decodesNormal; S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 6c816d0dc4..3bac545b5f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -213,6 +213,22 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } + if (features->encodesNormal) + { + if (!shader->attachObject("environment/encodeNormF.glsl")) + { + return FALSE; + } + } + + if (features->decodesNormal) + { + if (!shader->attachObject("environment/decodeNormF.glsl")) + { + return FALSE; + } + } + if (features->hasAtmospherics) { if (!shader->attachObject("windlight/atmosphericsF.glsl")) -- cgit v1.2.3 From afa7c1861ebf19fe5d6effde0d80f7eedde2bfb6 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 17:52:49 +0100 Subject: Remove optimize pragma. --- indra/llrender/llshadermgr.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 3bac545b5f..129c915139 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -41,8 +41,6 @@ #define UNIFORM_ERRS LL_ERRS("Shader") #endif -#pragma optimize("", off) - // Lots of STL stuff in here, using namespace std to keep things more readable using std::vector; using std::pair; -- cgit v1.2.3 From 4f6682ca29cefb83ac2307657d8605f96051da19 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 22:26:22 +0100 Subject: De-duplicate deferred shader code for atmospherics and transport. --- indra/llrender/llshadermgr.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 129c915139..60cbbd942f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -98,7 +98,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } - if (features->calculatesLighting || features->atmosphericHelpers) + if (features->calculatesLighting || features->calculatesAtmospherics) { if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) { @@ -194,6 +194,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } + if (features->calculatesLighting || features->calculatesAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) + { + return FALSE; + } + } + // NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->hasGamma) { -- cgit v1.2.3 From 79e4a8c28ad29b028ddb907a6ea01f4ef71e822a Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Wed, 14 Mar 2018 00:11:19 +0100 Subject: Fix up atmospheric helpers and transport shader for adv atmo path. Basic hook-up of sky settings to llatmosphere model. Moved mie aniso to be a top-level setting instead of a per-mie-layer setting. --- indra/llrender/llatmosphere.cpp | 505 +++++++++++++++++++++++----------------- indra/llrender/llatmosphere.h | 48 +++- 2 files changed, 332 insertions(+), 221 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 6ce5292839..6a4745eb95 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -1,221 +1,292 @@ -/** - * @file llatmosphere.cpp - * @brief LLAtmosphere integration impl - * - * $LicenseInfo:firstyear=2018&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2018, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "llatmosphere.h" -#include "llfasttimer.h" -#include "llsys.h" -#include "llglheaders.h" -#include "llrender.h" -#include "llshadermgr.h" -#include "llglslshader.h" - -LLAtmosphere* gAtmosphere = nullptr; - -void LLAtmosphere::initClass() -{ - if (!gAtmosphere) - { - gAtmosphere = new LLAtmosphere; - } -} - -void LLAtmosphere::cleanupClass() +/** + * @file llatmosphere.cpp + * @brief LLAtmosphere integration impl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llatmosphere.h" +#include "llfasttimer.h" +#include "llsys.h" +#include "llglheaders.h" +#include "llrender.h" +#include "llshadermgr.h" +#include "llglslshader.h" + +LLAtmosphere* gAtmosphere = nullptr; + +// Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column +// (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), +// summed and averaged in each bin (e.g. the value for 360nm is the average +// of the ASTM G-173 values for all wavelengths between 360 and 370nm). +// Values in W.m^-2. +const int kLambdaMin = 360; +const int kLambdaMax = 830; +const double kSolarIrradiance[48] = { + 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, + 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, + 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, + 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, + 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, + 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 +}; + +// Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ +// referencespectra/o3spectra2011/index.html for 233K, summed and averaged in +// each bin (e.g. the value for 360nm is the average of the original values +// for all wavelengths between 360 and 370nm). Values in m^2. +const double kOzoneCrossSection[48] = { + 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, + 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, + 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, + 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, + 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, + 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, + 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 +}; + +// From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. +const double kDobsonUnit = 2.687e20; +// Maximum number density of ozone molecules, in m^-3 (computed so at to get +// 300 Dobson units of ozone - for this we divide 300 DU by the integral of +// the ozone density profile defined below, which is equal to 15km). +const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; +const double kSunAngularRadius = 0.00935 / 2.0; +const double kBottomRadius = 6360000.0; +const double kTopRadius = 6420000.0; +const double kRayleigh = 1.24062e-6; +const double kRayleighScaleHeight = 8000.0; +const double kMieScaleHeight = 1200.0; +const double kMieAngstromAlpha = 0.0; +const double kMieAngstromBeta = 5.328e-3; +const double kMieSingleScatteringAlbedo = 0.9; +const double kMiePhaseFunctionG = 0.8; +const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; + +AtmosphericModelSettings::AtmosphericModelSettings() + : m_skyBottomRadius(6360.0f) + , m_skyTopRadius(6420.0f) + , m_sunArcRadians(0.00045f) + , m_mieAnisotropy(0.8f) +{ + atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); + atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); + + m_rayleighProfile.push_back(rayleigh_density); + m_mieProfile.push_back(mie_density); + + // Density profile increasing linearly from 0 to 1 between 10 and 25km, and + // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate + // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ + // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). + m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); + m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); +} + +AtmosphericModelSettings::AtmosphericModelSettings( + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile) +: m_skyBottomRadius(6360.0f) +, m_skyTopRadius(6420.0f) +, m_rayleighProfile(rayleighProfile) +, m_mieProfile(mieProfile) +, m_absorptionProfile(absorptionProfile) +, m_sunArcRadians(0.00045f) +, m_mieAnisotropy(0.8f) { - if(gAtmosphere) - { - delete gAtmosphere; - } - gAtmosphere = NULL; } -LLAtmosphere::LLAtmosphere() +AtmosphericModelSettings::AtmosphericModelSettings( + F32 skyBottomRadius, + F32 skyTopRadius, + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile, + F32 sunArcRadians, + F32 mieAniso) +: m_skyBottomRadius(skyBottomRadius) +, m_skyTopRadius(skyTopRadius) +, m_rayleighProfile(rayleighProfile) +, m_mieProfile(mieProfile) +, m_absorptionProfile(absorptionProfile) +, m_sunArcRadians(sunArcRadians) +, m_mieAnisotropy(mieAniso) { - // Init libatmosphere model - m_config.num_scattering_orders = 4; - - // Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column - // (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), - // summed and averaged in each bin (e.g. the value for 360nm is the average - // of the ASTM G-173 values for all wavelengths between 360 and 370nm). - // Values in W.m^-2. - const int kLambdaMin = 360; - const int kLambdaMax = 830; - const double kSolarIrradiance[48] = { - 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, - 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, - 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, - 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, - 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, - 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 - }; - - // Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ - // referencespectra/o3spectra2011/index.html for 233K, summed and averaged in - // each bin (e.g. the value for 360nm is the average of the original values - // for all wavelengths between 360 and 370nm). Values in m^2. - const double kOzoneCrossSection[48] = { - 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, - 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, - 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, - 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, - 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, - 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, - 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 - }; - - // From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. - const double kDobsonUnit = 2.687e20; - - // Maximum number density of ozone molecules, in m^-3 (computed so at to get - // 300 Dobson units of ozone - for this we divide 300 DU by the integral of - // the ozone density profile defined below, which is equal to 15km). - const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; - - const double kSunAngularRadius = 0.00935 / 2.0; - const double kBottomRadius = 6360000.0; - const double kTopRadius = 6420000.0; - const double kRayleigh = 1.24062e-6; - const double kRayleighScaleHeight = 8000.0; - const double kMieScaleHeight = 1200.0; - const double kMieAngstromAlpha = 0.0; - const double kMieAngstromBeta = 5.328e-3; - const double kMieSingleScatteringAlbedo = 0.9; - const double kMiePhaseFunctionG = 0.8; - const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; - - atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); - atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); - - // Density profile increasing linearly from 0 to 1 between 10 and 25km, and - // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate - // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ - // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). - std::vector ozone_density; - ozone_density.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); - ozone_density.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); - - std::vector wavelengths; - std::vector solar_irradiance; - std::vector rayleigh_scattering; - std::vector mie_scattering; - std::vector mie_extinction; - std::vector absorption_extinction; - std::vector ground_albedo; - - for (int l = kLambdaMin; l <= kLambdaMax; l += 10) - { - double lambda = static_cast(l) * 1e-3; // micro-meters - double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); - wavelengths.push_back(l); - solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); - rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); - mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); - mie_extinction.push_back(mie); - absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); - ground_albedo.push_back(0.1f); - } - - m_model = new atmosphere::Model( - wavelengths, - solar_irradiance, - kSunAngularRadius, - kBottomRadius, - kTopRadius, - {rayleigh_density}, - rayleigh_scattering, - {mie_density}, - mie_scattering, - mie_extinction, - kMiePhaseFunctionG, - ozone_density, - absorption_extinction, - ground_albedo, - max_sun_zenith_angle, - 1000.0, - 15, - false, - true); - - m_model->Init(m_config, m_textures); - - m_transmittance = new LLGLTexture; - m_scattering = new LLGLTexture; - m_mie_scattering = new LLGLTexture; - - m_transmittance->generateGLTexture(); - m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_transmittance->setTexName(m_textures.transmittance_texture); - m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); - - m_scattering->generateGLTexture(); - m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_scattering->setTexName(m_textures.transmittance_texture); - m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); - - m_mie_scattering->generateGLTexture(); - m_mie_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_mie_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_mie_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_mie_scattering->setTexName(m_textures.transmittance_texture); - m_mie_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); -}; - -LLAtmosphere::~LLAtmosphere() -{ - // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. - m_transmittance->setTexName(0); - m_scattering->setTexName(0); - m_mie_scattering->setTexName(0); - - delete m_model; - m_model = nullptr; -} - -LLGLTexture* LLAtmosphere::getTransmittance() const -{ - return m_transmittance; -} - -LLGLTexture* LLAtmosphere::getScattering() const -{ - return m_scattering; -} - -LLGLTexture* LLAtmosphere::getMieScattering() const -{ - return m_mie_scattering; -} - -GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const -{ - return m_model ? m_model->GetShader() : 0; -} +} + +void LLAtmosphere::initClass() +{ + if (!gAtmosphere) + { + gAtmosphere = new LLAtmosphere; + } +} + +void LLAtmosphere::cleanupClass() +{ + if(gAtmosphere) + { + delete gAtmosphere; + } + gAtmosphere = NULL; +} + +LLAtmosphere::LLAtmosphere() +{ + for (int l = kLambdaMin; l <= kLambdaMax; l += 10) + { + double lambda = static_cast(l) * 1e-3; // micro-meters + double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); + m_wavelengths.push_back(l); + m_solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); + m_rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); + m_mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); + m_mie_extinction.push_back(mie); + m_absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); + m_ground_albedo.push_back(0.6f); + } + + AtmosphericModelSettings defaults; + configureAtmosphericModel(defaults); +} + +LLAtmosphere::~LLAtmosphere() +{ + // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. + if (m_transmittance) + { + m_transmittance->setTexName(0); + } + + if (m_scattering) + { + m_scattering->setTexName(0); + } + + if (m_mie_scatter_texture) + { + m_mie_scatter_texture->setTexName(0); + } + + delete m_model; + m_model = nullptr; +} + +bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) +{ +// Advanced Atmospherics TODO +// Make this store a hash of the precomputed data +// and avoid redundant calcs for identical settings + + if (m_model) + { + delete m_model; + } + m_model = nullptr; + getTransmittance()->setTexName(0); + getScattering()->setTexName(0); + getMieScattering()->setTexName(0); + + // Init libatmosphere model + m_config.num_scattering_orders = 4; + + m_model = new atmosphere::Model( + m_wavelengths, + m_solar_irradiance, + settings.m_sunArcRadians, + settings.m_skyBottomRadius * 1000.0f, + settings.m_skyTopRadius * 1000.0f, + settings.m_rayleighProfile, + m_rayleigh_scattering, + settings.m_mieProfile, + m_mie_scattering, + m_mie_extinction, + settings.m_mieAnisotropy, + settings.m_absorptionProfile, + m_absorption_extinction, + m_ground_albedo, + max_sun_zenith_angle, + 1000.0, + 15, + false, + true); + + if (m_model) + { + m_model->Init(m_config, m_textures); + getTransmittance()->setTexName(m_textures.transmittance_texture); + getScattering()->setTexName(m_textures.transmittance_texture); + getMieScattering()->setTexName(m_textures.transmittance_texture); + } + + return m_model != nullptr; +} + +LLGLTexture* LLAtmosphere::getTransmittance() +{ + if (!m_transmittance) + { + m_transmittance = new LLGLTexture; + m_transmittance->generateGLTexture(); + m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); + } + return m_transmittance; +} + +LLGLTexture* LLAtmosphere::getScattering() +{ + if (!m_scattering) + { + m_scattering = new LLGLTexture; + m_scattering->generateGLTexture(); + m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + } + return m_scattering; +} + +LLGLTexture* LLAtmosphere::getMieScattering() +{ + if (!m_mie_scatter_texture) + { + m_mie_scatter_texture = new LLGLTexture; + m_mie_scatter_texture->generateGLTexture(); + m_mie_scatter_texture->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_mie_scatter_texture->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_mie_scatter_texture->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_mie_scatter_texture->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + } + return m_mie_scatter_texture; +} + +GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const +{ + return m_model ? m_model->GetShader() : 0; +} diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h index 6a9d1a4438..53dc1dd354 100644 --- a/indra/llrender/llatmosphere.h +++ b/indra/llrender/llatmosphere.h @@ -31,6 +31,36 @@ #include "llgltexture.h" #include "libatmosphere/model.h" +typedef std::vector DensityProfile; + +class AtmosphericModelSettings +{ +public: + AtmosphericModelSettings(); + + AtmosphericModelSettings( + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile); + + AtmosphericModelSettings( + F32 skyBottomRadius, + F32 skyTopRadius, + DensityProfile& rayleighProfile, + DensityProfile& mieProfile, + DensityProfile& absorptionProfile, + F32 sunArcRadians, + F32 mieAniso); + + F32 m_skyBottomRadius; + F32 m_skyTopRadius; + DensityProfile m_rayleighProfile; + DensityProfile m_mieProfile; + DensityProfile m_absorptionProfile; + F32 m_sunArcRadians; + F32 m_mieAnisotropy; +}; + class LLAtmosphere { public: @@ -46,12 +76,14 @@ public: return *this; } - LLGLTexture* getTransmittance() const; - LLGLTexture* getScattering() const; - LLGLTexture* getMieScattering() const; + LLGLTexture* getTransmittance(); + LLGLTexture* getScattering(); + LLGLTexture* getMieScattering(); GLhandleARB getAtmosphericShaderForLink() const; + bool configureAtmosphericModel(AtmosphericModelSettings& settings); + protected: LLAtmosphere(const LLAtmosphere& rhs) { @@ -64,7 +96,15 @@ protected: LLPointer m_transmittance; LLPointer m_scattering; - LLPointer m_mie_scattering; + LLPointer m_mie_scatter_texture; + + std::vector m_wavelengths; + std::vector m_solar_irradiance; + std::vector m_rayleigh_scattering; + std::vector m_mie_scattering; + std::vector m_mie_extinction; + std::vector m_absorption_extinction; + std::vector m_ground_albedo; }; extern LLAtmosphere* gAtmosphere; -- cgit v1.2.3 From 6e6c7ef9a1dba10dd3608fed329dba43dd7ed453 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Wed, 14 Mar 2018 00:38:17 +0100 Subject: Remove constants that are unused as of hooking up external data path. --- indra/llrender/llatmosphere.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 6a4745eb95..eca129cfe9 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -72,16 +72,12 @@ const double kDobsonUnit = 2.687e20; // 300 Dobson units of ozone - for this we divide 300 DU by the integral of // the ozone density profile defined below, which is equal to 15km). const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; -const double kSunAngularRadius = 0.00935 / 2.0; -const double kBottomRadius = 6360000.0; -const double kTopRadius = 6420000.0; const double kRayleigh = 1.24062e-6; const double kRayleighScaleHeight = 8000.0; const double kMieScaleHeight = 1200.0; const double kMieAngstromAlpha = 0.0; const double kMieAngstromBeta = 5.328e-3; const double kMieSingleScatteringAlbedo = 0.9; -const double kMiePhaseFunctionG = 0.8; const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; AtmosphericModelSettings::AtmosphericModelSettings() -- cgit v1.2.3 From 2fe4b5169f5d8846b1c6cd4e2aaaf2f41a7b7629 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 18 Apr 2018 09:40:16 -0700 Subject: Correct EOL for last line of files. --- indra/llrender/llgltexture.cpp | 2 +- indra/llrender/lltexture.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgltexture.cpp b/indra/llrender/llgltexture.cpp index c0e5477cea..e9a39d8acb 100644 --- a/indra/llrender/llgltexture.cpp +++ b/indra/llrender/llgltexture.cpp @@ -408,4 +408,4 @@ void LLGLTexture::setTexelsPerImage() static LLUUID sStubUUID; -const LLUUID& LLGLTexture::getID() const { return sStubUUID; } \ No newline at end of file +const LLUUID& LLGLTexture::getID() const { return sStubUUID; } diff --git a/indra/llrender/lltexture.cpp b/indra/llrender/lltexture.cpp index 787a09a159..6eef36216c 100644 --- a/indra/llrender/lltexture.cpp +++ b/indra/llrender/lltexture.cpp @@ -40,4 +40,4 @@ S32 LLTexture::getWidth(S32 discard_level) const { llassert(false); return 0; } S32 LLTexture::getHeight(S32 discard_level) const { llassert(false); return 0; } bool LLTexture::isActiveFetching() { llassert(false); return false; } LLImageGL* LLTexture::getGLTexture() const { llassert(false); return nullptr; } -void LLTexture::updateBindStatsForTester() { } \ No newline at end of file +void LLTexture::updateBindStatsForTester() { } -- cgit v1.2.3 From 0d7fa932d579f3fb6140658db7efb01fcd8f5ceb Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 20 Apr 2018 18:14:29 +0100 Subject: Move class3 sky/cloud shaders to where they need to be to get picked up by ALM. Modify autobuild.xml to use new libatmo w/ state save/restore fixes (addresses font render glitch). Put in nSight debug support. --- indra/llrender/llatmosphere.cpp | 516 ++++++++++++++++++++-------------------- indra/llrender/llshadermgr.cpp | 4 +- indra/llrender/llshadermgr.h | 2 +- 3 files changed, 262 insertions(+), 260 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index eca129cfe9..29a5d4be08 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -1,105 +1,105 @@ -/** - * @file llatmosphere.cpp - * @brief LLAtmosphere integration impl - * - * $LicenseInfo:firstyear=2018&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2018, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "llatmosphere.h" -#include "llfasttimer.h" -#include "llsys.h" -#include "llglheaders.h" -#include "llrender.h" -#include "llshadermgr.h" -#include "llglslshader.h" - -LLAtmosphere* gAtmosphere = nullptr; - -// Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column -// (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), -// summed and averaged in each bin (e.g. the value for 360nm is the average -// of the ASTM G-173 values for all wavelengths between 360 and 370nm). -// Values in W.m^-2. -const int kLambdaMin = 360; -const int kLambdaMax = 830; -const double kSolarIrradiance[48] = { - 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, - 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, - 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, - 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, - 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, - 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 -}; - -// Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ -// referencespectra/o3spectra2011/index.html for 233K, summed and averaged in -// each bin (e.g. the value for 360nm is the average of the original values -// for all wavelengths between 360 and 370nm). Values in m^2. -const double kOzoneCrossSection[48] = { - 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, - 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, - 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, - 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, - 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, - 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, - 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 -}; - -// From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. -const double kDobsonUnit = 2.687e20; -// Maximum number density of ozone molecules, in m^-3 (computed so at to get -// 300 Dobson units of ozone - for this we divide 300 DU by the integral of -// the ozone density profile defined below, which is equal to 15km). -const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; -const double kRayleigh = 1.24062e-6; -const double kRayleighScaleHeight = 8000.0; -const double kMieScaleHeight = 1200.0; -const double kMieAngstromAlpha = 0.0; -const double kMieAngstromBeta = 5.328e-3; -const double kMieSingleScatteringAlbedo = 0.9; -const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; - -AtmosphericModelSettings::AtmosphericModelSettings() - : m_skyBottomRadius(6360.0f) - , m_skyTopRadius(6420.0f) - , m_sunArcRadians(0.00045f) - , m_mieAnisotropy(0.8f) -{ - atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); - atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); - - m_rayleighProfile.push_back(rayleigh_density); - m_mieProfile.push_back(mie_density); - - // Density profile increasing linearly from 0 to 1 between 10 and 25km, and - // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate - // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ - // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). - m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); - m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); -} - +/** + * @file llatmosphere.cpp + * @brief LLAtmosphere integration impl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llatmosphere.h" +#include "llfasttimer.h" +#include "llsys.h" +#include "llglheaders.h" +#include "llrender.h" +#include "llshadermgr.h" +#include "llglslshader.h" + +LLAtmosphere* gAtmosphere = nullptr; + +// Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column +// (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), +// summed and averaged in each bin (e.g. the value for 360nm is the average +// of the ASTM G-173 values for all wavelengths between 360 and 370nm). +// Values in W.m^-2. +const int kLambdaMin = 360; +const int kLambdaMax = 830; +const double kSolarIrradiance[48] = { + 1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, + 1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, + 1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, + 1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, + 1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, + 1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 +}; + +// Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ +// referencespectra/o3spectra2011/index.html for 233K, summed and averaged in +// each bin (e.g. the value for 360nm is the average of the original values +// for all wavelengths between 360 and 370nm). Values in m^2. +const double kOzoneCrossSection[48] = { + 1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, + 8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, + 1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, + 4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, + 2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, + 6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, + 2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 +}; + +// From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. +const double kDobsonUnit = 2.687e20; +// Maximum number density of ozone molecules, in m^-3 (computed so at to get +// 300 Dobson units of ozone - for this we divide 300 DU by the integral of +// the ozone density profile defined below, which is equal to 15km). +const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; +const double kRayleigh = 1.24062e-6; +const double kRayleighScaleHeight = 8000.0; +const double kMieScaleHeight = 1200.0; +const double kMieAngstromAlpha = 0.0; +const double kMieAngstromBeta = 5.328e-3; +const double kMieSingleScatteringAlbedo = 0.9; +const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; + +AtmosphericModelSettings::AtmosphericModelSettings() + : m_skyBottomRadius(6360.0f) + , m_skyTopRadius(6420.0f) + , m_sunArcRadians(0.00045f) + , m_mieAnisotropy(0.8f) +{ + atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); + atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); + + m_rayleighProfile.push_back(rayleigh_density); + m_mieProfile.push_back(mie_density); + + // Density profile increasing linearly from 0 to 1 between 10 and 25km, and + // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate + // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ + // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). + m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); + m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); +} + AtmosphericModelSettings::AtmosphericModelSettings( DensityProfile& rayleighProfile, DensityProfile& mieProfile, @@ -130,159 +130,159 @@ AtmosphericModelSettings::AtmosphericModelSettings( , m_sunArcRadians(sunArcRadians) , m_mieAnisotropy(mieAniso) { -} - -void LLAtmosphere::initClass() -{ - if (!gAtmosphere) - { - gAtmosphere = new LLAtmosphere; - } -} - -void LLAtmosphere::cleanupClass() -{ - if(gAtmosphere) - { - delete gAtmosphere; - } - gAtmosphere = NULL; -} - -LLAtmosphere::LLAtmosphere() -{ - for (int l = kLambdaMin; l <= kLambdaMax; l += 10) - { - double lambda = static_cast(l) * 1e-3; // micro-meters - double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); - m_wavelengths.push_back(l); - m_solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); - m_rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); - m_mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); - m_mie_extinction.push_back(mie); - m_absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); - m_ground_albedo.push_back(0.6f); - } - - AtmosphericModelSettings defaults; - configureAtmosphericModel(defaults); -} - -LLAtmosphere::~LLAtmosphere() -{ - // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. - if (m_transmittance) - { - m_transmittance->setTexName(0); - } - - if (m_scattering) - { - m_scattering->setTexName(0); - } - - if (m_mie_scatter_texture) - { - m_mie_scatter_texture->setTexName(0); - } - - delete m_model; - m_model = nullptr; -} - -bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) -{ -// Advanced Atmospherics TODO -// Make this store a hash of the precomputed data -// and avoid redundant calcs for identical settings - - if (m_model) - { - delete m_model; - } - m_model = nullptr; - getTransmittance()->setTexName(0); - getScattering()->setTexName(0); - getMieScattering()->setTexName(0); - - // Init libatmosphere model - m_config.num_scattering_orders = 4; - - m_model = new atmosphere::Model( - m_wavelengths, - m_solar_irradiance, - settings.m_sunArcRadians, - settings.m_skyBottomRadius * 1000.0f, - settings.m_skyTopRadius * 1000.0f, - settings.m_rayleighProfile, - m_rayleigh_scattering, - settings.m_mieProfile, - m_mie_scattering, - m_mie_extinction, - settings.m_mieAnisotropy, - settings.m_absorptionProfile, - m_absorption_extinction, - m_ground_albedo, - max_sun_zenith_angle, - 1000.0, - 15, - false, - true); - - if (m_model) - { - m_model->Init(m_config, m_textures); - getTransmittance()->setTexName(m_textures.transmittance_texture); - getScattering()->setTexName(m_textures.transmittance_texture); - getMieScattering()->setTexName(m_textures.transmittance_texture); - } - - return m_model != nullptr; -} - -LLGLTexture* LLAtmosphere::getTransmittance() -{ - if (!m_transmittance) - { - m_transmittance = new LLGLTexture; - m_transmittance->generateGLTexture(); - m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); - } - return m_transmittance; -} - -LLGLTexture* LLAtmosphere::getScattering() -{ - if (!m_scattering) - { - m_scattering = new LLGLTexture; - m_scattering->generateGLTexture(); - m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); - } - return m_scattering; -} - -LLGLTexture* LLAtmosphere::getMieScattering() -{ - if (!m_mie_scatter_texture) - { - m_mie_scatter_texture = new LLGLTexture; - m_mie_scatter_texture->generateGLTexture(); - m_mie_scatter_texture->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); - m_mie_scatter_texture->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_mie_scatter_texture->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); - m_mie_scatter_texture->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); - } - return m_mie_scatter_texture; -} - -GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const -{ - return m_model ? m_model->GetShader() : 0; -} +} + +void LLAtmosphere::initClass() +{ + if (!gAtmosphere) + { + gAtmosphere = new LLAtmosphere; + } +} + +void LLAtmosphere::cleanupClass() +{ + if(gAtmosphere) + { + delete gAtmosphere; + } + gAtmosphere = NULL; +} + +LLAtmosphere::LLAtmosphere() +{ + for (int l = kLambdaMin; l <= kLambdaMax; l += 10) + { + double lambda = static_cast(l) * 1e-3; // micro-meters + double mie = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); + m_wavelengths.push_back(l); + m_solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); + m_rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); + m_mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); + m_mie_extinction.push_back(mie); + m_absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); + m_ground_albedo.push_back(0.6f); + } + + AtmosphericModelSettings defaults; + configureAtmosphericModel(defaults); +} + +LLAtmosphere::~LLAtmosphere() +{ + // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. + if (m_transmittance) + { + m_transmittance->setTexName(0); + } + + if (m_scattering) + { + m_scattering->setTexName(0); + } + + if (m_mie_scatter_texture) + { + m_mie_scatter_texture->setTexName(0); + } + + delete m_model; + m_model = nullptr; +} + +bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) +{ +// Advanced Atmospherics TODO +// Make this store a hash of the precomputed data +// and avoid redundant calcs for identical settings + + if (m_model) + { + delete m_model; + } + m_model = nullptr; + getTransmittance()->setTexName(0); + getScattering()->setTexName(0); + getMieScattering()->setTexName(0); + + // Init libatmosphere model + m_config.num_scattering_orders = 4; + + m_model = new atmosphere::Model( + m_wavelengths, + m_solar_irradiance, + settings.m_sunArcRadians, + settings.m_skyBottomRadius * 1000.0f, + settings.m_skyTopRadius * 1000.0f, + settings.m_rayleighProfile, + m_rayleigh_scattering, + settings.m_mieProfile, + m_mie_scattering, + m_mie_extinction, + settings.m_mieAnisotropy, + settings.m_absorptionProfile, + m_absorption_extinction, + m_ground_albedo, + max_sun_zenith_angle, + 1000.0, + 15, + false, + true); + + if (m_model) + { + m_model->Init(m_config, m_textures); + getTransmittance()->setTexName(m_textures.transmittance_texture); + getScattering()->setTexName(m_textures.scattering_texture); + getMieScattering()->setTexName(m_textures.single_mie_scattering_texture); + } + + return m_model != nullptr; +} + +LLGLTexture* LLAtmosphere::getTransmittance() +{ + if (!m_transmittance) + { + m_transmittance = new LLGLTexture; + m_transmittance->generateGLTexture(); + m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); + } + return m_transmittance; +} + +LLGLTexture* LLAtmosphere::getScattering() +{ + if (!m_scattering) + { + m_scattering = new LLGLTexture; + m_scattering->generateGLTexture(); + m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + } + return m_scattering; +} + +LLGLTexture* LLAtmosphere::getMieScattering() +{ + if (!m_mie_scatter_texture) + { + m_mie_scatter_texture = new LLGLTexture; + m_mie_scatter_texture->generateGLTexture(); + m_mie_scatter_texture->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_mie_scatter_texture->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_mie_scatter_texture->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_mie_scatter_texture->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + } + return m_mie_scatter_texture; +} + +GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const +{ + return m_model ? m_model->GetShader() : 0; +} diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 60cbbd942f..0c1fbfb2d7 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -35,6 +35,8 @@ #include "OpenGL/OpenGL.h" #endif +#pragma optimize("", off) + #ifdef LL_RELEASE_FOR_DOWNLOAD #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") #else @@ -1306,8 +1308,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("transmittance_texture"); mReservedUniforms.push_back("scattering_texture"); - mReservedUniforms.push_back("irradiance_texture"); mReservedUniforms.push_back("single_mie_scattering_texture"); + mReservedUniforms.push_back("irradiance_texture"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index ac3f7d58d5..9418849f32 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -229,8 +229,8 @@ public: // precomputed textures from libatmosphere TRANSMITTANCE_TEX, SCATTER_TEX, - ILLUMINANCE_TEX, SINGLE_MIE_SCATTER_TEX, + ILLUMINANCE_TEX, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From 6dfa720e75cd61e6b502c30d15511d2b447f7eb4 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 20 Apr 2018 18:52:41 +0100 Subject: Remove optimize pragmas necessary for working with RWDI in MSVC, but toxic to Clang. --- indra/llrender/llshadermgr.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 0c1fbfb2d7..603f26afd3 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -35,8 +35,6 @@ #include "OpenGL/OpenGL.h" #endif -#pragma optimize("", off) - #ifdef LL_RELEASE_FOR_DOWNLOAD #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") #else -- cgit v1.2.3 From 3116416fcb8dfd54ef2807e9e75959429c946d79 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Tue, 1 May 2018 00:10:11 +0100 Subject: Le Merge --- indra/llrender/llatmosphere.cpp | 17 +++++ indra/llrender/llatmosphere.h | 2 + indra/llrender/llglslshader.cpp | 7 ++- indra/llrender/llglslshader.h | 2 + indra/llrender/llrender.cpp | 129 ++++++++++++++++++++++++++++++++++---- indra/llrender/llrender.h | 20 ++++++ indra/llrender/llshadermgr.cpp | 3 + indra/llrender/llshadermgr.h | 1 + indra/llrender/llvertexbuffer.cpp | 2 +- 9 files changed, 167 insertions(+), 16 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 29a5d4be08..644e102a15 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -201,9 +201,11 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) delete m_model; } m_model = nullptr; + getTransmittance()->setTexName(0); getScattering()->setTexName(0); getMieScattering()->setTexName(0); + getIlluminance()->setTexName(0); // Init libatmosphere model m_config.num_scattering_orders = 4; @@ -235,6 +237,7 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) getTransmittance()->setTexName(m_textures.transmittance_texture); getScattering()->setTexName(m_textures.scattering_texture); getMieScattering()->setTexName(m_textures.single_mie_scattering_texture); + getIlluminance()->setTexName(m_textures.illuminance_texture); } return m_model != nullptr; @@ -282,6 +285,20 @@ LLGLTexture* LLAtmosphere::getMieScattering() return m_mie_scatter_texture; } +LLGLTexture* LLAtmosphere::getIlluminance() +{ + if (!m_illuminance) + { + m_illuminance = new LLGLTexture; + m_illuminance->generateGLTexture(); + m_illuminance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); + m_illuminance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); + m_illuminance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_illuminance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); + } + return m_illuminance; +} + GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const { return m_model ? m_model->GetShader() : 0; diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h index 53dc1dd354..0d62a069ac 100644 --- a/indra/llrender/llatmosphere.h +++ b/indra/llrender/llatmosphere.h @@ -79,6 +79,7 @@ public: LLGLTexture* getTransmittance(); LLGLTexture* getScattering(); LLGLTexture* getMieScattering(); + LLGLTexture* getIlluminance(); GLhandleARB getAtmosphericShaderForLink() const; @@ -97,6 +98,7 @@ protected: LLPointer m_transmittance; LLPointer m_scattering; LLPointer m_mie_scatter_texture; + LLPointer m_illuminance; std::vector m_wavelengths; std::vector m_solar_irradiance; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 73ab95cf3b..95e1274c16 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -33,6 +33,8 @@ #include "llrender.h" #include "llvertexbuffer.h" +#pragma optimize("", off) + #if LL_DARWIN #include "OpenGL/OpenGL.h" #endif @@ -659,7 +661,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * mUniformMap[hashedName] = location; LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL; - + //find the index of this uniform for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) { @@ -683,7 +685,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * std::pair result; S32 index = i + LLShaderMgr::instance()->mReservedUniforms.size(); - if ((*uniforms)[i].String() == name) + if ((*uniforms)[i] == hashedName) { result = mUniform.insert(uniforms_index_t::value_type(index, location)); if (result.second) @@ -1218,7 +1220,6 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c if (mProgramObject) { GLint location = getLocationForIndex(index); - if (location >= 0) { glUniformMatrix4fvARB(location, count, transpose, v); diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 562cbdcba9..3857dc0519 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -31,6 +31,8 @@ #include "llrender.h" #include "llstaticstringtable.h" +#pragma optimize("", off) + class LLShaderFeatures { public: diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index a8f622d3ff..9067a17baf 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1191,6 +1191,7 @@ void LLRender::syncMatrices() LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; static glh::matrix4f cached_mvp; + static glh::matrix4f cached_inv_mdv; static U32 cached_mvp_mdv_hash = 0xFFFFFFFF; static U32 cached_mvp_proj_hash = 0xFFFFFFFF; @@ -1204,12 +1205,18 @@ void LLRender::syncMatrices() bool mvp_done = false; U32 i = MM_MODELVIEW; - if (mMatHash[i] != shader->mMatHash[i]) + if (mMatHash[MM_MODELVIEW] != shader->mMatHash[MM_MODELVIEW]) { //update modelview, normal, and MVP - glh::matrix4f& mat = mMatrix[i][mMatIdx[i]]; + glh::matrix4f& mat = mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]]; - shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mat.m); - shader->mMatHash[i] = mMatHash[i]; + // if MDV has changed, update the cached inverse as well + if (cached_mvp_mdv_hash != mMatHash[MM_MODELVIEW]) + { + cached_inv_mdv = mat.inverse(); + } + + shader->uniformMatrix4fv(name[MM_MODELVIEW], 1, GL_FALSE, mat.m); + shader->mMatHash[MM_MODELVIEW] = mMatHash[MM_MODELVIEW]; //update normal matrix S32 loc = shader->getUniformLocation(LLShaderMgr::NORMAL_MATRIX); @@ -1217,7 +1224,7 @@ void LLRender::syncMatrices() { if (cached_normal_hash != mMatHash[i]) { - cached_normal = mat.inverse().transpose(); + cached_normal = cached_inv_mdv.transpose(); cached_normal_hash = mMatHash[i]; } @@ -1233,6 +1240,17 @@ void LLRender::syncMatrices() shader->uniformMatrix3fv(LLShaderMgr::NORMAL_MATRIX, 1, GL_FALSE, norm_mat); } + if (shader->getUniformLocation(LLShaderMgr::INVERSE_MODELVIEW_MATRIX)) + { + glh::matrix4f ogl_to_cfr = copy_matrix((F32*)OGL_TO_CFR_ROTATION); + glh::matrix4f modelview = ogl_to_cfr.inverse() * get_current_modelview(); + + glh::matrix4f inv_modelview = modelview.inverse(); + shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, FALSE, inv_modelview.m); + } + + shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, cached_inv_mdv.m); + //update MVP matrix mvp_done = true; loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX); @@ -1249,17 +1267,22 @@ void LLRender::syncMatrices() } shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.m); - } + } } - i = MM_PROJECTION; - if (mMatHash[i] != shader->mMatHash[i]) + if (mMatHash[MM_PROJECTION] != shader->mMatHash[MM_PROJECTION]) { //update projection matrix, normal, and MVP - glh::matrix4f& mat = mMatrix[i][mMatIdx[i]]; + glh::matrix4f& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]]; - shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mat.m); - shader->mMatHash[i] = mMatHash[i]; + if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX)) + { + glh::matrix4f inv_proj = mat.inverse(); + shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m); + } + + shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, mat.m); + shader->mMatHash[MM_PROJECTION] = mMatHash[MM_PROJECTION]; if (!mvp_done) { @@ -1267,7 +1290,7 @@ void LLRender::syncMatrices() S32 loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX); if (loc > -1) { - if (cached_mvp_mdv_hash != mMatHash[i] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION]) + if (cached_mvp_mdv_hash != mMatHash[MM_PROJECTION] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION]) { U32 mdv = MM_MODELVIEW; cached_mvp = mat; @@ -2332,3 +2355,85 @@ void LLRender::debugTexUnits(void) LL_INFOS("TextureUnit") << "Active TexUnit Enabled : " << active_enabled << LL_ENDL; } + + +glh::matrix4f copy_matrix(F32* src) +{ + glh::matrix4f ret; + ret.set_value(src); + return ret; +} + +glh::matrix4f get_current_modelview() +{ + return copy_matrix(gGLModelView); +} + +glh::matrix4f get_current_projection() +{ + return copy_matrix(gGLProjection); +} + +glh::matrix4f get_last_modelview() +{ + return copy_matrix(gGLLastModelView); +} + +glh::matrix4f get_last_projection() +{ + return copy_matrix(gGLLastProjection); +} + +void copy_matrix(const glh::matrix4f& src, F32* dst) +{ + for (U32 i = 0; i < 16; i++) + { + dst[i] = src.m[i]; + } +} + +void set_current_modelview(const glh::matrix4f& mat) +{ + copy_matrix(mat, gGLModelView); +} + +void set_current_projection(glh::matrix4f& mat) +{ + copy_matrix(mat, gGLProjection); +} + +glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar) +{ + glh::matrix4f ret( + 2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left), + 0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom), + 0.f, 0.f, -2.f/(zfar-znear), -(zfar+znear)/(zfar-znear), + 0.f, 0.f, 0.f, 1.f); + + return ret; +} + +glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) +{ + GLfloat f = 1.f/tanf(DEG_TO_RAD*fovy/2.f); + + return glh::matrix4f(f/aspect, 0, 0, 0, + 0, f, 0, 0, + 0, 0, (zFar+zNear)/(zNear-zFar), (2.f*zFar*zNear)/(zNear-zFar), + 0, 0, -1.f, 0); +} + +glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up) +{ + LLVector3 f = center-eye; + f.normVec(); + up.normVec(); + LLVector3 s = f % up; + LLVector3 u = s % f; + + return glh::matrix4f(s[0], s[1], s[2], 0, + u[0], u[1], u[2], 0, + -f[0], -f[1], -f[2], 0, + 0, 0, 0, 1); + +} \ No newline at end of file diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 9ad3a6e593..d6be5bd0d0 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -489,4 +489,24 @@ extern S32 gGLViewport[4]; extern LLRender gGL; +// This rotation matrix moves the default OpenGL reference frame +// (-Z at, Y up) to Cory's favorite reference frame (X at, Z up) +const F32 OGL_TO_CFR_ROTATION[16] = { 0.f, 0.f, -1.f, 0.f, // -Z becomes X + -1.f, 0.f, 0.f, 0.f, // -X becomes Y + 0.f, 1.f, 0.f, 0.f, // Y becomes Z + 0.f, 0.f, 0.f, 1.f }; + +glh::matrix4f copy_matrix(F32* src); +glh::matrix4f get_current_modelview(); +glh::matrix4f get_current_projection(); +glh::matrix4f get_last_modelview(); +glh::matrix4f get_last_projection(); + +void copy_matrix(const glh::matrix4f& src, F32* dst); +void set_current_modelview(const glh::matrix4f& mat); +void set_current_projection(glh::matrix4f& mat); + +glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar); +glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar); +glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up); #endif diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 603f26afd3..f1ddbed956 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -31,6 +31,8 @@ #include "llfile.h" #include "llrender.h" +#pragma optimize("", off) + #if LL_DARWIN #include "OpenGL/OpenGL.h" #endif @@ -1101,6 +1103,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("projection_matrix"); mReservedUniforms.push_back("inv_proj"); mReservedUniforms.push_back("modelview_projection_matrix"); + mReservedUniforms.push_back("inv_modelview"); mReservedUniforms.push_back("normal_matrix"); mReservedUniforms.push_back("texture_matrix0"); mReservedUniforms.push_back("texture_matrix1"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 9418849f32..fa2a9f03be 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -47,6 +47,7 @@ public: PROJECTION_MATRIX, INVERSE_PROJECTION_MATRIX, MODELVIEW_PROJECTION_MATRIX, + INVERSE_MODELVIEW_MATRIX, NORMAL_MATRIX, TEXTURE_MATRIX0, TEXTURE_MATRIX1, diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f10301b42d..637dedd9f6 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -195,7 +195,7 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } else { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); + glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); } glBindBufferARB(mType, 0); -- cgit v1.2.3 From 190fa8614c5630f7f360ce028ed08879af308511 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 18 May 2018 23:16:56 +0100 Subject: Remove MSVC debug pragmas and comment out code to dump example grids.xml file w/ hard-coded grids. --- indra/llrender/llglslshader.cpp | 2 -- indra/llrender/llglslshader.h | 2 -- indra/llrender/llshadermgr.cpp | 2 -- 3 files changed, 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 95e1274c16..9bdbc9c80a 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -33,8 +33,6 @@ #include "llrender.h" #include "llvertexbuffer.h" -#pragma optimize("", off) - #if LL_DARWIN #include "OpenGL/OpenGL.h" #endif diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 3857dc0519..562cbdcba9 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -31,8 +31,6 @@ #include "llrender.h" #include "llstaticstringtable.h" -#pragma optimize("", off) - class LLShaderFeatures { public: diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index f1ddbed956..4d0e0f2249 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -31,8 +31,6 @@ #include "llfile.h" #include "llrender.h" -#pragma optimize("", off) - #if LL_DARWIN #include "OpenGL/OpenGL.h" #endif -- cgit v1.2.3 From 64302d3000b69b31e72eb6a3bd8a981c80cb88de Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Jun 2018 00:18:36 +0100 Subject: Modify use of sky settings, reduce complexity, and name funcs to indicate coord systems in use. Fix class2 softenLightF shader. --- indra/llrender/llrender.h | 5 +++++ indra/llrender/llshadermgr.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 113909c1c6..ceebc7000b 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -503,6 +503,11 @@ const F32 OGL_TO_CFR_ROTATION[16] = { 0.f, 0.f, -1.f, 0.f, // -Z becomes X 0.f, 1.f, 0.f, 0.f, // Y becomes Z 0.f, 0.f, 0.f, 1.f }; +const F32 XYZ_TO_OGL_ROTATION[16] = { 1.f, 0.f, 0.f, 0.f, // X stays X + 0.f, 0.f, -1.f, 0.f, // Z becomes -Y + 0.f, 1.f, 0.f, 0.f, // Y becomes Z + 0.f, 0.f, 0.f, 1.f }; + glh::matrix4f copy_matrix(F32* src); glh::matrix4f get_current_modelview(); glh::matrix4f get_current_projection(); diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 4d0e0f2249..aa54a5f040 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -35,6 +35,8 @@ #include "OpenGL/OpenGL.h" #endif +#pragma optimize("", off) + #ifdef LL_RELEASE_FOR_DOWNLOAD #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") #else @@ -552,8 +554,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& if (log.length() > 0) { - LL_INFOS() << "Shader loading from " << fname << ":\n" << LL_ENDL; - LL_INFOS() << log << LL_ENDL; + LL_INFOS("ShaderErrors") << "Shader loading from " << fname << ":\n" << LL_ENDL; + LL_INFOS("ShaderErrors") << log << LL_ENDL; } } -- cgit v1.2.3 From 8dd85013865cc5b426234cd71b605d7208bcfe01 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Jun 2018 15:50:25 +0100 Subject: Fix mis-merge of LLSettingsBase and remove optimize pragmas. --- indra/llrender/llshadermgr.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index aa54a5f040..544a4f00aa 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -35,8 +35,6 @@ #include "OpenGL/OpenGL.h" #endif -#pragma optimize("", off) - #ifdef LL_RELEASE_FOR_DOWNLOAD #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") #else -- cgit v1.2.3 From 8cfdc07e790a557e881fadaa1b6258e5b16751f4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Jun 2018 23:32:30 +0100 Subject: Code cleanup and move to using typedefs of S64Seconds/F64Seconds for ease in sync w/ sim side which has not llunits types. --- indra/llrender/llglslshader.cpp | 332 ++++++++++++++++++++++++-------------- indra/llrender/llglslshader.h | 33 +--- indra/llrender/llrender.cpp | 2 +- indra/llrender/llrender.h | 7 +- indra/llrender/llshadermgr.cpp | 4 +- indra/llrender/llshadermgr.h | 5 - indra/llrender/llvertexbuffer.cpp | 2 +- 7 files changed, 219 insertions(+), 166 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b027a24017..37bcf0c163 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -157,7 +157,8 @@ void LLGLSLShader::clearStats() mSamplesDrawn = 0; mDrawCalls = 0; mTextureStateFetched = false; - mTextureMagMinFilter.clear(); + mTextureMagFilter.clear(); + mTextureMinFilter.clear(); } void LLGLSLShader::dumpStats() @@ -170,16 +171,14 @@ void LLGLSLShader::dumpStats() { LL_INFOS() << mShaderFiles[i].first << LL_ENDL; } - for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it) + for (U32 i = 0; i < mTexture.size(); ++i) { - S32 i = (*it).first; - GLint idx = (*it).second; + GLint idx = mTexture[i]; if (idx >= 0) { GLint uniform_idx = getUniformLocation(i); - magmin_filter_t::iterator it = mTextureMagMinFilter.find(i); - LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << (*it).second.second << "/" << (*it).second.first << std::dec << LL_ENDL; + LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << mTextureMagFilter[i] << "/" << mTextureMinFilter[i] << std::dec << LL_ENDL; } } LL_INFOS() << "=============================================" << LL_ENDL; @@ -236,13 +235,14 @@ void LLGLSLShader::placeProfileQuery() if (!mTextureStateFetched) { mTextureStateFetched = true; + mTextureMagFilter.resize(mTexture.size()); + mTextureMinFilter.resize(mTexture.size()); U32 cur_active = gGL.getCurrentTexUnitIndex(); - for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it) + for (U32 i = 0; i < mTexture.size(); ++i) { - S32 i = (*it).first; - GLint idx = (*it).second; + GLint idx = mTexture[i]; if (idx >= 0) { @@ -256,7 +256,8 @@ void LLGLSLShader::placeProfileQuery() glGetTexParameteriv(type, GL_TEXTURE_MAG_FILTER, (GLint*) &mag); glGetTexParameteriv(type, GL_TEXTURE_MIN_FILTER, (GLint*) &min); - mTextureMagMinFilter[i] = magmin_values_t(mag, min); + mTextureMagFilter[i] = mag; + mTextureMinFilter[i] = min; } } @@ -414,7 +415,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, for ( ; fileIter != mShaderFiles.end(); fileIter++ ) { GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); - LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << " shaderhandle=" << shaderhandle << LL_ENDL; + LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; if (shaderhandle) { attachObject(shaderhandle); @@ -477,14 +478,13 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } S32 cur_tex = channel_count; //adjust any texture channels that might have been overwritten - for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it) + for (U32 i = 0; i < mTexture.size(); i++) { - int i = (*it).first; - if (((*it).second >= 0) && ((*it).second < channel_count)) + if (mTexture[i] > -1 && mTexture[i] < channel_count) { llassert(cur_tex < gGLManager.mNumTextureImageUnits); uniform1i(i, cur_tex); - (*it).second = cur_tex++; + mTexture[i] = cur_tex++; } } unbind(); @@ -545,7 +545,11 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri mAttribute.clear(); U32 numAttributes = (attributes == NULL) ? 0 : attributes->size(); +#if LL_RELEASE_WITH_DEBUG_INFO + mAttribute.resize(LLShaderMgr::instance()->mReservedAttribs.size() + numAttributes, { -1, NULL }); +#else mAttribute.resize(LLShaderMgr::instance()->mReservedAttribs.size() + numAttributes, -1); +#endif if (res) { //read back channel locations @@ -559,7 +563,11 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri S32 index = glGetAttribLocationARB(mProgramObject, (const GLcharARB *)name); if (index != -1) { +#if LL_RELEASE_WITH_DEBUG_INFO + mAttribute[i] = { index, name }; +#else mAttribute[i] = index; +#endif mAttributeMask |= 1 << i; LL_DEBUGS("ShaderLoading") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; } @@ -659,20 +667,17 @@ void LLGLSLShader::mapUniform(GLint index, const vector * mUniformMap[hashedName] = location; LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL; - + //find the index of this uniform for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) { - if (LLShaderMgr::instance()->mReservedUniforms[i] == name) + if ( (mUniform[i] == -1) + && (LLShaderMgr::instance()->mReservedUniforms[i] == name)) { - std::pair result; - - result = mUniform.insert(uniforms_index_t::value_type(i, location)); - if (result.second) - { - mTexture[i] = mapUniformTextureChannel(location, type); - return; - } + //found it + mUniform[i] = location; + mTexture[i] = mapUniformTextureChannel(location, type); + return; } } @@ -680,17 +685,13 @@ void LLGLSLShader::mapUniform(GLint index, const vector * { for (U32 i = 0; i < uniforms->size(); i++) { - std::pair result; - S32 index = i + LLShaderMgr::instance()->mReservedUniforms.size(); - - if ((*uniforms)[i] == hashedName) + if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) + && ((*uniforms)[i].String() == name)) { - result = mUniform.insert(uniforms_index_t::value_type(index, location)); - if (result.second) - { - mTexture[index] = mapUniformTextureChannel(location, type); - return; - } + //found it + mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; + mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type); + return; } } } @@ -730,6 +731,10 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) mUniformNameMap.clear(); mTexture.clear(); mValue.clear(); + //initialize arrays + U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); + mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); bind(); @@ -929,14 +934,20 @@ S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LL S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode) { - GLint channel = getTexChannelForIndex(uniform); + if (uniform < 0 || uniform >= (S32)mTexture.size()) + { + UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + return -1; + } - if (channel > -1) + uniform = mTexture[uniform]; + + if (uniform > -1) { - gGL.getTexUnit(channel)->bind(texture, mode); + gGL.getTexUnit(uniform)->bind(texture, mode); } - return channel; + return uniform; } S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureType mode) @@ -949,64 +960,82 @@ S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureT S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode) { - GLint channel = getTexChannelForIndex(uniform); - - if (channel > -1) + if (uniform < 0 || uniform >= (S32)mTexture.size()) { - gGL.getTexUnit(channel)->unbind(mode); + UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + return -1; + } + + uniform = mTexture[uniform]; + + if (uniform > -1) + { + gGL.getTexUnit(uniform)->unbind(mode); } - return channel; + return uniform; } S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) { - GLint channel = getTexChannelForIndex(uniform); - - if (channel != -1) + if (uniform < 0 || uniform >= (S32)mTexture.size()) + { + UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + return -1; + } + S32 index = mTexture[uniform]; + if (index != -1) { - gGL.getTexUnit(channel)->activate(); - gGL.getTexUnit(channel)->enable(mode); + gGL.getTexUnit(index)->activate(); + gGL.getTexUnit(index)->enable(mode); } - return channel; + return index; } S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) { - GLint channel = getTexChannelForIndex(uniform); - - if (channel != -1 && gGL.getTexUnit(channel)->getCurrType() != LLTexUnit::TT_NONE) + if (uniform < 0 || uniform >= (S32)mTexture.size()) + { + 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(channel)->getCurrType() != mode) + if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode) { if (gDebugSession) { - gFailLog << "Texture channel " << channel << " texture type corrupted." << std::endl; + gFailLog << "Texture channel " << index << " texture type corrupted." << std::endl; ll_fail("LLGLSLShader::disableTexture failed"); } else { - LL_ERRS() << "Texture channel " << channel << " texture type corrupted." << LL_ENDL; + LL_ERRS() << "Texture channel " << index << " texture type corrupted." << LL_ENDL; } } - gGL.getTexUnit(channel)->disable(); + gGL.getTexUnit(index)->disable(); } - return channel; + return index; } void LLGLSLShader::uniform1i(U32 index, GLint x) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + std::map::iterator iter = mValue.find(mUniform[index]); if (iter == mValue.end() || iter->second.mV[0] != x) { - glUniform1iARB(location, x); - mValue[location] = LLVector4(x,0.f,0.f,0.f); + glUniform1iARB(mUniform[index], x); + mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); } } } @@ -1016,15 +1045,19 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + std::map::iterator iter = mValue.find(mUniform[index]); if (iter == mValue.end() || iter->second.mV[0] != x) { - glUniform1fARB(location, x); - mValue[location] = LLVector4(x,0.f,0.f,0.f); + glUniform1fARB(mUniform[index], x); + mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); } } } @@ -1034,16 +1067,20 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + 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(location, x, y); - mValue[location] = vec; + glUniform2fARB(mUniform[index], x, y); + mValue[mUniform[index]] = vec; } } } @@ -1053,16 +1090,20 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + std::map::iterator iter = mValue.find(mUniform[index]); LLVector4 vec(x,y,z,0.f); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform3fARB(location, x, y, z); - mValue[location] = vec; + glUniform3fARB(mUniform[index], x, y, z); + mValue[mUniform[index]] = vec; } } } @@ -1072,16 +1113,20 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + std::map::iterator iter = mValue.find(mUniform[index]); LLVector4 vec(x,y,z,w); if (iter == mValue.end() || shouldChange(iter->second,vec)) { - glUniform4fARB(location, x, y, z, w); - mValue[location] = vec; + glUniform4fARB(mUniform[index], x, y, z, w); + mValue[mUniform[index]] = vec; } } } @@ -1091,16 +1136,20 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + 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(location, count, v); - mValue[location] = vec; + glUniform1ivARB(mUniform[index], count, v); + mValue[mUniform[index]] = vec; } } } @@ -1110,16 +1159,20 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + 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(location, count, v); - mValue[location] = vec; + glUniform1fvARB(mUniform[index], count, v); + mValue[mUniform[index]] = vec; } } } @@ -1129,16 +1182,20 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + 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(location, count, v); - mValue[location] = vec; + glUniform2fvARB(mUniform[index], count, v); + mValue[mUniform[index]] = vec; } } } @@ -1148,16 +1205,20 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + 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(location, count, v); - mValue[location] = vec; + glUniform3fvARB(mUniform[index], count, v); + mValue[mUniform[index]] = vec; } } } @@ -1167,16 +1228,20 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - std::map::iterator iter = mValue.find(location); + 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(location, count, v); - mValue[location] = vec; + glUniform4fvARB(mUniform[index], count, v); + mValue[mUniform[index]] = vec; } } } @@ -1186,11 +1251,15 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - glUniformMatrix2fvARB(location, count, transpose, v); + glUniformMatrix2fvARB(mUniform[index], count, transpose, v); } } } @@ -1199,11 +1268,15 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - glUniformMatrix3fvARB(location, count, transpose, v); + glUniformMatrix3fvARB(mUniform[index], count, transpose, v); } } } @@ -1212,11 +1285,15 @@ void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, { if (mProgramObject) { - GLint location = getLocationForIndex(index); + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } - if (location >= 0) + if (mUniform[index] >= 0) { - glUniformMatrix3x4fv(location, count, transpose, v); + glUniformMatrix3x4fv(mUniform[index], count, transpose, v); } } } @@ -1225,10 +1302,15 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c { if (mProgramObject) { - GLint location = getLocationForIndex(index); - if (location >= 0) + if (mUniform.size() <= index) + { + UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + return; + } + + if (mUniform[index] >= 0) { - glUniformMatrix4fvARB(location, count, transpose, v); + glUniformMatrix4fvARB(mUniform[index], count, transpose, v); } } } @@ -1259,8 +1341,14 @@ GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform) GLint LLGLSLShader::getUniformLocation(U32 index) { - /*TODO: flatten this... change calls to gUL(U32) */ - return getLocationForIndex(index); + GLint ret = -1; + if (mProgramObject) + { + llassert(index < mUniform.size()); + return mUniform[index]; + } + + return ret; } GLint LLGLSLShader::getAttribLocation(U32 attrib) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 59edd7b36f..0934ceba30 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -169,11 +169,6 @@ public: U32 mMatHash[LLRender::NUM_MATRIX_MODES]; U32 mLightHash; - typedef std::map uniforms_index_t; - typedef std::pair magmin_values_t; - - typedef std::map < S32, magmin_values_t> magmin_filter_t; - GLhandleARB mProgramObject; #if LL_RELEASE_WITH_DEBUG_INFO struct attr_name @@ -188,12 +183,11 @@ public: std::vector mAttribute; //lookup table of attribute enum to attribute channel #endif U32 mAttributeMask; //mask of which reserved attributes are set (lines up with LLVertexBuffer::getTypeMask()) - uniforms_index_t mUniform; - uniforms_index_t mTexture; - + 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; S32 mTotalUniformSize; S32 mActiveTextureChannels; S32 mShaderLevel; @@ -217,32 +211,13 @@ public: static U32 sTotalDrawCalls; bool mTextureStateFetched; - magmin_filter_t mTextureMagMinFilter; + std::vector mTextureMagFilter; + std::vector mTextureMinFilter; GLhandleARB mExtraLinkObject = 0; private: void unloadInternal(); - - inline GLint getLocationForIndex(S32 index) - { - if (!mProgramObject) - return -1; - uniforms_index_t::iterator it = mUniform.find(index); - if (it == mUniform.end()) - return -1; - return (*it).second; - } - - inline GLint getTexChannelForIndex(S32 index) - { - if (!mProgramObject) - return -1; - uniforms_index_t::iterator it = mTexture.find(index); - if (it == mTexture.end()) - return -1; - return (*it).second; - } }; //UI shader (declared here so llui_libtest will link properly) diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 9067a17baf..5e16aded30 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1267,7 +1267,7 @@ void LLRender::syncMatrices() } shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.m); - } + } } i = MM_PROJECTION; diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index ceebc7000b..1bc5e89eac 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -446,7 +446,7 @@ public: static U32 sUICalls; static U32 sUIVerts; static bool sGLCoreProfile; - static bool sNsightDebugSupport; + static bool sNsightDebugSupport; private: friend class LLLightState; @@ -503,11 +503,6 @@ const F32 OGL_TO_CFR_ROTATION[16] = { 0.f, 0.f, -1.f, 0.f, // -Z becomes X 0.f, 1.f, 0.f, 0.f, // Y becomes Z 0.f, 0.f, 0.f, 1.f }; -const F32 XYZ_TO_OGL_ROTATION[16] = { 1.f, 0.f, 0.f, 0.f, // X stays X - 0.f, 0.f, -1.f, 0.f, // Z becomes -Y - 0.f, 1.f, 0.f, 0.f, // Y becomes Z - 0.f, 0.f, 0.f, 1.f }; - glh::matrix4f copy_matrix(F32* src); glh::matrix4f get_current_modelview(); glh::matrix4f get_current_projection(); diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 544a4f00aa..1eb1cb56a8 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -985,7 +985,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade // Add shader file to map mShaderObjects[filename] = ret; shader_level = try_gpu_class; - } + } else { if (shader_level > 1) @@ -1150,7 +1150,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("cloud_noise_texture"); mReservedUniforms.push_back("fullbright"); mReservedUniforms.push_back("lightnorm"); - mReservedUniforms.push_back("sunlight_color"); + mReservedUniforms.push_back("sunlight_color_copy"); mReservedUniforms.push_back("ambient"); mReservedUniforms.push_back("blue_horizon"); mReservedUniforms.push_back("blue_density"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index fa2a9f03be..9919dbe31a 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -30,11 +30,6 @@ #include "llgl.h" #include "llglslshader.h" -/*RIDER: TODO: - * This should use the LL Singleton<> template... but not a quick conversion. - * (llviewershadermgr derives from this) - */ - class LLShaderMgr { public: diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index a33f84518f..e3e605d040 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -198,7 +198,7 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } else { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); + glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); } glBindBufferARB(mType, 0); -- cgit v1.2.3 From 610a793aa8fb9f918fc25eeab02b7415ac18b33b Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Tue, 5 Jun 2018 11:19:22 -0700 Subject: EOL in llsetingssky.cpp and llrender.cpp. const on ptr_t & in llenvironment --- indra/llrender/llrender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 5e16aded30..c42d2799d7 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -2436,4 +2436,4 @@ glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up) -f[0], -f[1], -f[2], 0, 0, 0, 0, 1); -} \ No newline at end of file +} -- cgit v1.2.3 From b6b9094d26933c41cc917901fcf4847275ff4ca5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 5 Jun 2018 20:20:43 +0100 Subject: Fix sunlight != sunlight_color_copy and remove hack disable of clouds. --- indra/llrender/llshadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 1eb1cb56a8..fd187b99ee 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1150,7 +1150,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("cloud_noise_texture"); mReservedUniforms.push_back("fullbright"); mReservedUniforms.push_back("lightnorm"); - mReservedUniforms.push_back("sunlight_color_copy"); + mReservedUniforms.push_back("sunlight_color"); mReservedUniforms.push_back("ambient"); mReservedUniforms.push_back("blue_horizon"); mReservedUniforms.push_back("blue_density"); -- cgit v1.2.3 From 507c4921826e73635f6ae31087ab0e6cd1280f43 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 8 Jun 2018 22:22:20 +0100 Subject: Add specific shader for the moon to allow different rendering at day vs night. Add MouseMoon positioning ala MouseSun debug setting and accessors to use it. --- indra/llrender/llshadermgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index fd187b99ee..f00d97cd47 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -552,8 +552,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& if (log.length() > 0) { - LL_INFOS("ShaderErrors") << "Shader loading from " << fname << ":\n" << LL_ENDL; - LL_INFOS("ShaderErrors") << log << LL_ENDL; + LL_DEBUGS() << "Shader loading from " << fname << ":\n" << LL_ENDL; + LL_DEBUGS() << log << LL_ENDL; } } -- cgit v1.2.3 From a0598b12656cdcf22ba95cacd01b5ff36f8f1b26 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 11 Jun 2018 17:46:16 +0100 Subject: Fix water fog consolidation in underwater shaders. Add plumbing facilities to allow current and next moon textures to be passed to moon shader. Modify moon shader to blend between current and next moon textures by blend factor. --- indra/llrender/llglslshader.cpp | 11 +++++++++-- indra/llrender/llrender.h | 9 +++++---- indra/llrender/llshadermgr.cpp | 6 ++++-- indra/llrender/llshadermgr.h | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 37bcf0c163..ff79efcc5b 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -767,18 +767,19 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) S32 diffuseMap = glGetUniformLocationARB(mProgramObject, "diffuseMap"); S32 specularMap = glGetUniformLocationARB(mProgramObject, "specularMap"); S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); + S32 altDiffuseMap = glGetUniformLocationARB(mProgramObject, "altDiffuseMap"); S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); std::set skip_index; - if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap)) + if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) { GLenum type; GLsizei length; GLint size = -1; char name[1024]; - diffuseMap = specularMap = bumpMap = environmentMap = -1; + diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; for (S32 i = 0; i < activeCount; i++) { @@ -815,6 +816,12 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) environmentMap = i; continue; } + + if (-1 == altDiffuseMap && std::string(name) == "altDiffuseMap") + { + altDiffuseMap = i; + continue; + } } bool specularDiff = specularMap < diffuseMap && -1 != specularMap; diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 1bc5e89eac..62cd526550 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -265,10 +265,11 @@ public: enum eTexIndex { - DIFFUSE_MAP = 0, - NORMAL_MAP, - SPECULAR_MAP, - NUM_TEXTURE_CHANNELS, + DIFFUSE_MAP = 0, + ALTERNATE_DIFFUSE_MAP = 1, + NORMAL_MAP = 1, + SPECULAR_MAP = 2, + NUM_TEXTURE_CHANNELS = 3, }; enum eVolumeTexIndex diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index f00d97cd47..ebdfbd89b2 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -552,8 +552,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& if (log.length() > 0) { - LL_DEBUGS() << "Shader loading from " << fname << ":\n" << LL_ENDL; - LL_DEBUGS() << log << LL_ENDL; + LL_WARNS("ShaderLoading") << "Shader loading from " << fname << ":\n" << LL_ENDL; + LL_WARNS("ShaderLoading") << log << LL_ENDL; } } @@ -1144,6 +1144,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("color"); mReservedUniforms.push_back("diffuseMap"); + mReservedUniforms.push_back("altDiffuseMap"); mReservedUniforms.push_back("specularMap"); mReservedUniforms.push_back("bumpMap"); mReservedUniforms.push_back("environmentMap"); @@ -1309,6 +1310,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("scattering_texture"); mReservedUniforms.push_back("single_mie_scattering_texture"); mReservedUniforms.push_back("irradiance_texture"); + mReservedUniforms.push_back("blend_factor"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 9919dbe31a..3fac21883f 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -74,6 +74,7 @@ public: PROJECTOR_AMBIENT_LOD, DIFFUSE_COLOR, DIFFUSE_MAP, + ALTERNATE_DIFFUSE_MAP, SPECULAR_MAP, BUMP_MAP, ENVIRONMENT_MAP, @@ -227,6 +228,7 @@ public: SCATTER_TEX, SINGLE_MIE_SCATTER_TEX, ILLUMINANCE_TEX, + BLEND_FACTOR, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From fc8d0de673da0e02915556008a365aca67472eba Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 11 Jun 2018 22:39:57 +0100 Subject: Make cloud rendering use textures defined in sky settings and add code to shaders to lerp between current and next cloud texture. --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index ebdfbd89b2..716ec8750a 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1149,6 +1149,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("bumpMap"); mReservedUniforms.push_back("environmentMap"); mReservedUniforms.push_back("cloud_noise_texture"); + mReservedUniforms.push_back("cloud_noise_texture_next"); mReservedUniforms.push_back("fullbright"); mReservedUniforms.push_back("lightnorm"); mReservedUniforms.push_back("sunlight_color"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 3fac21883f..9bb6660e54 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -79,6 +79,7 @@ public: BUMP_MAP, ENVIRONMENT_MAP, CLOUD_NOISE_MAP, + CLOUD_NOISE_MAP_NEXT, FULLBRIGHT, LIGHTNORM, SUNLIGHT_COLOR, -- cgit v1.2.3 From 67ab0084f87c40bf31d7fadded55cc9ea6299ca2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 12 Jun 2018 18:42:07 +0100 Subject: Fix env panel forward action. Make env panel update environment when jumping frame to frame. Add separate funcs for sun/moon vectors in various coord systems. Make haze glow only pay attention to sun (i.e. fix sun glow when moon is near horizon in daytime). --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 716ec8750a..037786ec49 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1212,6 +1212,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("spot_shadow_bias"); mReservedUniforms.push_back("spot_shadow_offset"); mReservedUniforms.push_back("sun_dir"); + mReservedUniforms.push_back("moon_dir"); mReservedUniforms.push_back("shadow_res"); mReservedUniforms.push_back("proj_shadow_res"); mReservedUniforms.push_back("depth_cutoff"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 9bb6660e54..53d59dbbf8 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -134,6 +134,7 @@ public: DEFERRED_SPOT_SHADOW_BIAS, DEFERRED_SPOT_SHADOW_OFFSET, DEFERRED_SUN_DIR, + DEFERRED_MOON_DIR, DEFERRED_SHADOW_RES, DEFERRED_PROJ_SHADOW_RES, DEFERRED_DEPTH_CUTOFF, -- cgit v1.2.3 From 34865c4bb5cd12219606f44748159fe7cbeea264 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Jun 2018 00:51:39 +0100 Subject: Mods to hook up water settings to water normals for rendering with support for current to next blending. Modify LLSettingsFoo::buildDefaultFoo to use a static and avoid re-validation of default sky/water/daycycle settings. Remove all references to gSun/MoonTextureId globals (they should come from sky settings now). --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 037786ec49..0e79430468 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1147,6 +1147,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("altDiffuseMap"); mReservedUniforms.push_back("specularMap"); mReservedUniforms.push_back("bumpMap"); + mReservedUniforms.push_back("bumpMap2"); mReservedUniforms.push_back("environmentMap"); mReservedUniforms.push_back("cloud_noise_texture"); mReservedUniforms.push_back("cloud_noise_texture_next"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 53d59dbbf8..342f5d5507 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -77,6 +77,7 @@ public: ALTERNATE_DIFFUSE_MAP, SPECULAR_MAP, BUMP_MAP, + BUMP_MAP2, ENVIRONMENT_MAP, CLOUD_NOISE_MAP, CLOUD_NOISE_MAP_NEXT, -- cgit v1.2.3 From 71a0d3e9597415a86185d7683710252326da7b7a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Jun 2018 23:31:03 +0100 Subject: Fix OSX bug from OLD_SELECT GLSL work-around define not being used with automatically linked feature shaders. Add LL_RELEASE_FOR_DOWNLOAD ifdef around launcher nag. Fix OSX 10.14 SDK compile issue from unused var in scroll list. --- indra/llrender/llshadermgr.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 0e79430468..78aed5eef6 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -35,11 +35,7 @@ #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; @@ -559,6 +555,15 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, boost::unordered_map* defines, S32 texture_index_channels) { + +// endsure work-around for missing GLSL funcs gets propogated to feature shader files (e.g. srgbF.glsl) +#if LL_DARWIN + if (defines) + { + (*defines)["OLD_SELECT"] = "1"; + } +#endif + GLenum error = GL_NO_ERROR; if (gDebugGL) { -- cgit v1.2.3 From d5c465b4ab263e568761f6197534f7ddcda8a5ee Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 29 Jun 2018 20:15:10 +0100 Subject: MAINT-8817 remove automatic update of inv_proj matrix so sunLightF which expects it not to match the projection mat works again Fix misspellinging in missing settings asset notification string Fix moon quat conversion to get proper directional rotation Add early out so attempting to set parcel env settings doesn't crash --- indra/llrender/llrender.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index c42d2799d7..67898f1258 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1275,11 +1275,13 @@ void LLRender::syncMatrices() { //update projection matrix, normal, and MVP glh::matrix4f& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]]; - if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX)) - { - glh::matrix4f inv_proj = mat.inverse(); - shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m); - } + // it would be nice to have this automatically track the state of the proj matrix + // but certain render paths require it to be mismatched *sigh* + //if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX)) + //{ + // glh::matrix4f inv_proj = mat.inverse(); + // shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m); + //} shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, mat.m); shader->mMatHash[MM_PROJECTION] = mMatHash[MM_PROJECTION]; -- cgit v1.2.3 From ffdd6c3d7dad87e9873067a923d4e7ce9e6d4d2c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 10 Jul 2018 23:26:35 +0100 Subject: Make advanced atmo sky shader compile again. Make atmospheric model avoid redundant work when settings don't change. Point autobuild.xml at libatmosphere with op== to compare density profiles. --- indra/llrender/llatmosphere.cpp | 47 ++++++++++++++++++++++++++++++++++++++--- indra/llrender/llatmosphere.h | 4 ++++ 2 files changed, 48 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 644e102a15..4edfd9efe9 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -132,6 +132,46 @@ AtmosphericModelSettings::AtmosphericModelSettings( { } +bool AtmosphericModelSettings::operator==(const AtmosphericModelSettings& rhs) const +{ + if (m_skyBottomRadius != rhs.m_skyBottomRadius) + { + return false; + } + + if (m_skyTopRadius != rhs.m_skyTopRadius) + { + return false; + } + + if (m_sunArcRadians != rhs.m_sunArcRadians) + { + return false; + } + + if (m_mieAnisotropy != rhs.m_mieAnisotropy) + { + return false; + } + + if (m_rayleighProfile != rhs.m_rayleighProfile) + { + return false; + } + + if (m_mieProfile != rhs.m_mieProfile) + { + return false; + } + + if (m_absorptionProfile != rhs.m_absorptionProfile) + { + return false; + } + + return true; +} + void LLAtmosphere::initClass() { if (!gAtmosphere) @@ -192,9 +232,10 @@ LLAtmosphere::~LLAtmosphere() bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) { -// Advanced Atmospherics TODO -// Make this store a hash of the precomputed data -// and avoid redundant calcs for identical settings + if ((m_model != nullptr) && (settings == m_settings)) + { + return true; + } if (m_model) { diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h index 0d62a069ac..a010803595 100644 --- a/indra/llrender/llatmosphere.h +++ b/indra/llrender/llatmosphere.h @@ -52,6 +52,8 @@ public: F32 sunArcRadians, F32 mieAniso); + bool operator==(const AtmosphericModelSettings& rhs) const; + F32 m_skyBottomRadius; F32 m_skyTopRadius; DensityProfile m_rayleighProfile; @@ -107,6 +109,8 @@ protected: std::vector m_mie_extinction; std::vector m_absorption_extinction; std::vector m_ground_albedo; + + AtmosphericModelSettings m_settings; }; extern LLAtmosphere* gAtmosphere; -- cgit v1.2.3 From 6dd9dd3ab63cb0daa7682a400ff0408fd894ba77 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 30 Aug 2018 17:54:59 +0100 Subject: MAINT-9064 Fix binding of current/next sun/moon textures. Remove redundant code in GLSLShader determination of tex uniform bindings. Unhack mix calls in sun/moon shaders to reverse sense of blending (was working around reversed bindings). --- indra/llrender/llglslshader.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index ff79efcc5b..639033f143 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -799,12 +799,6 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) continue; } - if (-1 == specularMap && std::string(name) == "specularMap") - { - specularMap = i; - continue; - } - if (-1 == bumpMap && std::string(name) == "bumpMap") { bumpMap = i; -- cgit v1.2.3 From 2e55eae9cc6ebff303c8f322c71fec9c20e42bd8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 4 Sep 2018 23:08:20 +0100 Subject: Merge and fix MAINT-9087 and MAINT-9084 --- indra/llrender/llglslshader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 639033f143..c03d33080f 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -569,7 +569,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri mAttribute[i] = index; #endif mAttributeMask |= 1 << i; - LL_DEBUGS("ShaderLoading") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; + LL_DEBUGS("ShaderUniform") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; } } if (attributes != NULL) @@ -581,7 +581,7 @@ BOOL LLGLSLShader::mapAttributes(const std::vector * attri if (index != -1) { mAttribute[LLShaderMgr::instance()->mReservedAttribs.size() + i] = index; - LL_DEBUGS("ShaderLoading") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; + LL_DEBUGS("ShaderUniform") << "Attribute " << name << " assigned to channel " << index << LL_ENDL; } } } @@ -666,7 +666,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector * mUniformNameMap[location] = name; mUniformMap[hashedName] = location; - LL_DEBUGS("ShaderLoading") << "Uniform " << name << " is at location " << location << LL_ENDL; + LL_DEBUGS("ShaderUniform") << "Uniform " << name << " is at location " << location << LL_ENDL; //find the index of this uniform for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) @@ -714,7 +714,7 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type) type == GL_SAMPLER_2D_MULTISAMPLE) { //this here is a texture glUniform1iARB(location, mActiveTextureChannels); - LL_DEBUGS("ShaderLoading") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; + LL_DEBUGS("ShaderUniform") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; return mActiveTextureChannels++; } return -1; @@ -858,7 +858,7 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) unbind(); - LL_DEBUGS("ShaderLoading") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; + LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; return res; } -- cgit v1.2.3 From 32631f09a57548c2bbf7e09211a2053ff2e4e47d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 4 Sep 2018 23:41:36 +0100 Subject: 8283/4 WIP --- indra/llrender/llatmosphere.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 4edfd9efe9..4fd9764e07 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -34,6 +34,8 @@ #include "llshadermgr.h" #include "llglslshader.h" +#pragma optimize("", off) + LLAtmosphere* gAtmosphere = nullptr; // Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column @@ -78,6 +80,8 @@ const double kMieScaleHeight = 1200.0; const double kMieAngstromAlpha = 0.0; const double kMieAngstromBeta = 5.328e-3; const double kMieSingleScatteringAlbedo = 0.9; +const double kGroundAlbedo = 0.1; + const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; AtmosphericModelSettings::AtmosphericModelSettings() @@ -201,7 +205,7 @@ LLAtmosphere::LLAtmosphere() m_mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); m_mie_extinction.push_back(mie); m_absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); - m_ground_albedo.push_back(0.6f); + m_ground_albedo.push_back(kGroundAlbedo); } AtmosphericModelSettings defaults; @@ -268,7 +272,7 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) m_ground_albedo, max_sun_zenith_angle, 1000.0, - 15, + 3, false, true); -- cgit v1.2.3 From 451ab80ca65a7ae75316442086f42b6553ea6bbe Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Sep 2018 22:50:26 +0100 Subject: Fix tex format mismatch between what libatmosphere was generating and what we were claiming to use in rendering. First pass at sky shader using libatmosphere sky radiance lookup. Add atmo density controls to ext daycycle floater tabs. --- indra/llrender/llatmosphere.cpp | 45 +++++++++++++++++++++++++++++++++++------ indra/llrender/llrender.cpp | 10 ++------- 2 files changed, 41 insertions(+), 14 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 4fd9764e07..aaa1ff65e1 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -34,8 +34,6 @@ #include "llshadermgr.h" #include "llglslshader.h" -#pragma optimize("", off) - LLAtmosphere* gAtmosphere = nullptr; // Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column @@ -234,6 +232,26 @@ LLAtmosphere::~LLAtmosphere() m_model = nullptr; } +#if DEBUG_ATMO_TEX_GEN +uint8_t* GetTexture2d(int width, int height, int components, GLuint texture) +{ + glActiveTextureARB(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, texture); + uint8_t* storage = (uint8_t*)malloc(width * height * components * sizeof(float)); + glGetTexImage(GL_TEXTURE_2D, 0, components == 3 ? GL_RGB : GL_RGBA, GL_FLOAT, storage); + return storage; +} + +uint8_t* GetTexture3d(int width, int height, int depth, int components, GLuint texture) +{ + glActiveTextureARB(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_3D, texture); + uint8_t* storage = (uint8_t*)malloc(width * height * depth * components * sizeof(float)); + glGetTexImage(GL_TEXTURE_3D, 0, components == 3 ? GL_RGB : GL_RGBA, GL_FLOAT, storage); + return storage; +} +#endif + bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) { if ((m_model != nullptr) && (settings == m_settings)) @@ -256,6 +274,7 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) m_config.num_scattering_orders = 4; m_model = new atmosphere::Model( + m_config, m_wavelengths, m_solar_irradiance, settings.m_sunArcRadians, @@ -273,8 +292,9 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) max_sun_zenith_angle, 1000.0, 3, - false, - true); + false, // do not combine_scattering...we want indep textures + false, // use 32F for 2d textures to avoid artifacts + true); // use 16F for 3d textures to reduce footprint if (m_model) { @@ -283,6 +303,19 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) getScattering()->setTexName(m_textures.scattering_texture); getMieScattering()->setTexName(m_textures.single_mie_scattering_texture); getIlluminance()->setTexName(m_textures.illuminance_texture); + +#if DEBUG_ATMO_TEX_GEN + // for debug only... + U8* transmittance = GetTexture2d(m_config.transmittanceTextureWidth, m_config.transmittanceTextureHeight, 3, m_textures.transmittance_texture); + U8* scattering = GetTexture3d(m_config.scatteringTextureWidth, m_config.scatteringTextureHeight, m_config.scatteringTextureDepth, 3, m_textures.scattering_texture); + U8* single_mie_scattering = GetTexture3d(m_config.scatteringTextureWidth, m_config.scatteringTextureHeight, m_config.scatteringTextureDepth, 3, m_textures.single_mie_scattering_texture); + U8* illuminance = GetTexture2d(m_config.illuminanceTextureWidth, m_config.illuminanceTextureHeight, 3, m_textures.illuminance_texture); + free(transmittance); + free(scattering); + free(single_mie_scattering); + free(illuminance); +#endif + } return m_model != nullptr; @@ -296,7 +329,7 @@ LLGLTexture* LLAtmosphere::getTransmittance() m_transmittance->generateGLTexture(); m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_transmittance->setExplicitFormat(GL_RGB32F_ARB, GL_RGB, GL_FLOAT); m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); } return m_transmittance; @@ -338,7 +371,7 @@ LLGLTexture* LLAtmosphere::getIlluminance() m_illuminance->generateGLTexture(); m_illuminance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); m_illuminance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); - m_illuminance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); + m_illuminance->setExplicitFormat(GL_RGB32F_ARB, GL_RGB, GL_FLOAT); m_illuminance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); } return m_illuminance; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 67898f1258..251c02dd77 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1241,16 +1241,10 @@ void LLRender::syncMatrices() } if (shader->getUniformLocation(LLShaderMgr::INVERSE_MODELVIEW_MATRIX)) - { - glh::matrix4f ogl_to_cfr = copy_matrix((F32*)OGL_TO_CFR_ROTATION); - glh::matrix4f modelview = ogl_to_cfr.inverse() * get_current_modelview(); - - glh::matrix4f inv_modelview = modelview.inverse(); - shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, FALSE, inv_modelview.m); + { + shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, cached_inv_mdv.m); } - shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, cached_inv_mdv.m); - //update MVP matrix mvp_done = true; loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX); -- cgit v1.2.3 From 4bd2b8b98ba1c562dfd65975a87ef5ee3db35633 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 7 Sep 2018 17:24:29 +0100 Subject: Fix createDensityProfileLayer dropping passed in values. Enable sky density panel to update advanced atmo precomputed textures. Take wild stab at appropriate ranges for density parameters in edit panel UI. Clean up debug-only code that isn't necessary anymore. Point autobuild at latest version of libatmosphere package. --- indra/llrender/llatmosphere.cpp | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index aaa1ff65e1..12c6685354 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -232,26 +232,6 @@ LLAtmosphere::~LLAtmosphere() m_model = nullptr; } -#if DEBUG_ATMO_TEX_GEN -uint8_t* GetTexture2d(int width, int height, int components, GLuint texture) -{ - glActiveTextureARB(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture); - uint8_t* storage = (uint8_t*)malloc(width * height * components * sizeof(float)); - glGetTexImage(GL_TEXTURE_2D, 0, components == 3 ? GL_RGB : GL_RGBA, GL_FLOAT, storage); - return storage; -} - -uint8_t* GetTexture3d(int width, int height, int depth, int components, GLuint texture) -{ - glActiveTextureARB(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_3D, texture); - uint8_t* storage = (uint8_t*)malloc(width * height * depth * components * sizeof(float)); - glGetTexImage(GL_TEXTURE_3D, 0, components == 3 ? GL_RGB : GL_RGBA, GL_FLOAT, storage); - return storage; -} -#endif - bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) { if ((m_model != nullptr) && (settings == m_settings)) @@ -271,8 +251,6 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) getIlluminance()->setTexName(0); // Init libatmosphere model - m_config.num_scattering_orders = 4; - m_model = new atmosphere::Model( m_config, m_wavelengths, @@ -303,19 +281,7 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) getScattering()->setTexName(m_textures.scattering_texture); getMieScattering()->setTexName(m_textures.single_mie_scattering_texture); getIlluminance()->setTexName(m_textures.illuminance_texture); - -#if DEBUG_ATMO_TEX_GEN - // for debug only... - U8* transmittance = GetTexture2d(m_config.transmittanceTextureWidth, m_config.transmittanceTextureHeight, 3, m_textures.transmittance_texture); - U8* scattering = GetTexture3d(m_config.scatteringTextureWidth, m_config.scatteringTextureHeight, m_config.scatteringTextureDepth, 3, m_textures.scattering_texture); - U8* single_mie_scattering = GetTexture3d(m_config.scatteringTextureWidth, m_config.scatteringTextureHeight, m_config.scatteringTextureDepth, 3, m_textures.single_mie_scattering_texture); - U8* illuminance = GetTexture2d(m_config.illuminanceTextureWidth, m_config.illuminanceTextureHeight, 3, m_textures.illuminance_texture); - free(transmittance); - free(scattering); - free(single_mie_scattering); - free(illuminance); -#endif - + m_settings = settings; } return m_model != nullptr; -- cgit v1.2.3 From 8a162bc59cefc246da80d66f223a5cd545ff1dd3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Sep 2018 20:41:10 +0100 Subject: Pull fname out of class loop so we can see which actual shader file we were trying to load while debugging. --- indra/llrender/llshadermgr.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 78aed5eef6..20d32612f8 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -588,10 +588,11 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade S32 try_gpu_class = shader_level; S32 gpu_class; + std::stringstream fname; + //find the most relevant file for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) - { //search from the current gpu class down to class 1 to find the most relevant shader - std::stringstream fname; + { //search from the current gpu class down to class 1 to find the most relevant shader fname << getShaderDirPrefix(); fname << gpu_class << "/" << filename; -- cgit v1.2.3 From ef2c61275eafa7d1fd3afa3f0eb76397632f12c9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Sep 2018 21:18:37 +0100 Subject: Move fname back inside class loop. grumble stringstream grumble. Fix sky depth-testing with advanced atmospherics. --- indra/llrender/llshadermgr.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 20d32612f8..78aed5eef6 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -588,11 +588,10 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade S32 try_gpu_class = shader_level; S32 gpu_class; - std::stringstream fname; - //find the most relevant file for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) - { //search from the current gpu class down to class 1 to find the most relevant shader + { //search from the current gpu class down to class 1 to find the most relevant shader + std::stringstream fname; fname << getShaderDirPrefix(); fname << gpu_class << "/" << filename; -- cgit v1.2.3 From 1df7760d315430766bba44d4d4c64480b4a6138f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 14 Sep 2018 21:52:52 +0100 Subject: SL-9632 add uniform and code to supress atmospherics in all shaders that could be used by HUDs Make sky and cloud shaders use common scaleSoftClip implementation in gammaF.glsl --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 78aed5eef6..3c25d6aaa8 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1319,6 +1319,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("single_mie_scattering_texture"); mReservedUniforms.push_back("irradiance_texture"); mReservedUniforms.push_back("blend_factor"); + mReservedUniforms.push_back("no_atmo"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 342f5d5507..7898b2d90a 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -233,6 +233,7 @@ public: ILLUMINANCE_TEX, BLEND_FACTOR, + NO_ATMO, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From 5eed233618abd7020e130799be2abe0f986543f6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Oct 2018 21:32:42 +0100 Subject: SL-1925 More settings for rainbow/halo atmospheric effects, final default asset UUIDs, and shader mods. --- indra/llrender/llshadermgr.cpp | 5 +++++ indra/llrender/llshadermgr.h | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 3c25d6aaa8..153cef0317 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1320,6 +1320,11 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("irradiance_texture"); mReservedUniforms.push_back("blend_factor"); mReservedUniforms.push_back("no_atmo"); + mReservedUniforms.push_back("moisture_level"); + mReservedUniforms.push_back("droplet_radius"); + mReservedUniforms.push_back("ice_level"); + mReservedUniforms.push_back("rainbow_map"); + mReservedUniforms.push_back("halo_map"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 7898b2d90a..ffdd2da529 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -234,6 +234,11 @@ public: BLEND_FACTOR, NO_ATMO, + MOISTURE_LEVEL, + DROPLET_RADIUS, + ICE_LEVEL, + RAINBOW_MAP, + HALO_MAP, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From ffc6393309d06446f9d1361f0f0282b2110768ae Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Oct 2018 22:08:35 +0100 Subject: SL-9751 Add optional moon brightness setting --- indra/llrender/llshadermgr.cpp | 2 ++ indra/llrender/llshadermgr.h | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 153cef0317..3927632dbe 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1325,6 +1325,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("ice_level"); mReservedUniforms.push_back("rainbow_map"); mReservedUniforms.push_back("halo_map"); + mReservedUniforms.push_back("moon_brightness"); + mReservedUniforms.push_back("moon_phase"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index ffdd2da529..489caa49ae 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -239,6 +239,10 @@ public: ICE_LEVEL, RAINBOW_MAP, HALO_MAP, + + MOON_BRIGHTNESS, + MOON_PHASE, + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From f8aac192378462b5824d28808ed84833e2cbfe0f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 9 Oct 2018 18:44:43 +0100 Subject: SL-1289 add cloud_variance control for randomized perturbance of clouds to break up tiling monotony --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 2 ++ 2 files changed, 3 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 3927632dbe..e483f723f0 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1327,6 +1327,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("halo_map"); mReservedUniforms.push_back("moon_brightness"); mReservedUniforms.push_back("moon_phase"); + mReservedUniforms.push_back("cloud_variance"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 489caa49ae..af34c70c54 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -243,6 +243,8 @@ public: MOON_BRIGHTNESS, MOON_PHASE, + CLOUD_VARIANCE, + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From 79d33f9d19a0c6e5ed34ffbd01a31cb2625e1ecc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Oct 2018 18:44:03 +0100 Subject: Fix names of WATER_BLUR_MULTIPILER. Give wave direction uniforms more meaningful names in shaders. Add comments on glow size/focus conversions for clarity. --- indra/llrender/llshadermgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index e483f723f0..8617b58d2e 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1276,8 +1276,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("refTex"); mReservedUniforms.push_back("eyeVec"); mReservedUniforms.push_back("time"); - mReservedUniforms.push_back("d1"); - mReservedUniforms.push_back("d2"); + mReservedUniforms.push_back("waveDir1"); + mReservedUniforms.push_back("waveDir2"); mReservedUniforms.push_back("lightDir"); mReservedUniforms.push_back("specular"); mReservedUniforms.push_back("lightExp"); -- cgit v1.2.3 From 536799d07e4298ff8157ef51ed00040e10a5ba65 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 29 Oct 2018 23:02:20 +0100 Subject: SL-9977 SL-9973 --- indra/llrender/llgl.cpp | 63 +++++++++++++++++++++++++++++++++++++---- indra/llrender/llgl.h | 9 ++++-- indra/llrender/llglslshader.cpp | 50 ++++++++++++++------------------ indra/llrender/llglstates.h | 24 +++++++++++++--- indra/llrender/llrender.cpp | 2 +- indra/llrender/llrender.h | 9 ++++++ indra/llrender/llshadermgr.cpp | 63 ++++++++++++++++++++++++++++------------- indra/llrender/llshadermgr.h | 6 +++- 8 files changed, 165 insertions(+), 61 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 2f78b6e104..a55a72c18f 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -36,6 +36,7 @@ #include "llsys.h" #include "llgl.h" +#include "llglstates.h" #include "llrender.h" #include "llerror.h" @@ -2478,27 +2479,45 @@ void LLGLDepthTest::checkState() } } -LLGLSquashToFarClip::LLGLSquashToFarClip(glh::matrix4f P, U32 layer) +LLGLSquashToFarClip::LLGLSquashToFarClip() +{ + glh::matrix4f proj = get_current_projection(); + setProjectionMatrix(proj, 0); +} + +LLGLSquashToFarClip::LLGLSquashToFarClip(glh::matrix4f& P, U32 layer) +{ + setProjectionMatrix(P, layer); +} + + +void LLGLSquashToFarClip::setProjectionMatrix(glh::matrix4f& projection, U32 layer) { F32 depth = 0.99999f - 0.0001f * layer; for (U32 i = 0; i < 4; i++) { - P.element(2, i) = P.element(3, i) * depth; + projection.element(2, i) = projection.element(3, i) * depth; } + U32 last_matrix_mode = gGL.getMatrixMode(); + gGL.matrixMode(LLRender::MM_PROJECTION); gGL.pushMatrix(); - gGL.loadMatrix(P.m); - gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.loadMatrix(projection.m); + + gGL.matrixMode(last_matrix_mode); } LLGLSquashToFarClip::~LLGLSquashToFarClip() { + U32 last_matrix_mode = gGL.getMatrixMode(); + gGL.matrixMode(LLRender::MM_PROJECTION); gGL.popMatrix(); - gGL.matrixMode(LLRender::MM_MODELVIEW); + + gGL.matrixMode(last_matrix_mode); } @@ -2561,5 +2580,39 @@ void LLGLSyncFence::wait() #endif } +LLGLSPipelineSkyBox::LLGLSPipelineSkyBox() +: mAlphaTest(GL_ALPHA_TEST) +, mCullFace(GL_CULL_FACE) +, mSquashClip() +{ + if (!LLGLSLShader::sNoFixedFunction) + { + glDisable(GL_LIGHTING); + glDisable(GL_FOG); + glDisable(GL_CLIP_PLANE0); + } +} +LLGLSPipelineSkyBox::~LLGLSPipelineSkyBox() +{ + if (!LLGLSLShader::sNoFixedFunction) + { + glEnable(GL_LIGHTING); + glEnable(GL_FOG); + glEnable(GL_CLIP_PLANE0); + } +} +LLGLSPipelineDepthTestSkyBox::LLGLSPipelineDepthTestSkyBox(bool depth_test, bool depth_write) +: LLGLSPipelineSkyBox() +, mDepth(depth_test ? GL_TRUE : GL_FALSE, depth_write ? GL_TRUE : GL_FALSE, GL_LEQUAL) +{ + +} + +LLGLSPipelineBlendSkyBox::LLGLSPipelineBlendSkyBox(bool depth_test, bool depth_write) +: LLGLSPipelineDepthTestSkyBox(depth_test, depth_write) +, mBlend(GL_BLEND) +{ + gGL.setSceneBlendType(LLRender::BT_ALPHA); +} diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 4c4302d05b..96cbf2e3c2 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -360,14 +360,17 @@ private: Modify and load projection matrix to push depth values to far clip plane. Restores projection matrix on destruction. - GL_MODELVIEW_MATRIX is active whenever program execution - leaves this class. + Saves/restores matrix mode around projection manipulation. Does not stack. */ class LLGLSquashToFarClip { public: - LLGLSquashToFarClip(glh::matrix4f projection, U32 layer = 0); + LLGLSquashToFarClip(); + LLGLSquashToFarClip(glh::matrix4f& projection, U32 layer = 0); + + void setProjectionMatrix(glh::matrix4f& projection, U32 layer); + ~LLGLSquashToFarClip(); }; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index c03d33080f..f0cc9acc06 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -37,12 +37,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; @@ -456,12 +450,12 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, } if( !success ) { - LL_WARNS("ShaderLoading") << "Failed to link shader: " << mName << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Failed to link shader: " << mName << LL_ENDL; // Try again using a lower shader level; if (mShaderLevel > 0) { - LL_WARNS("ShaderLoading") << "Failed to link using shader level " << mShaderLevel << " trying again using shader level " << (mShaderLevel - 1) << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Failed to link using shader level " << mShaderLevel << " trying again using shader level " << (mShaderLevel - 1) << LL_ENDL; mShaderLevel--; return createShader(attributes,uniforms); } @@ -504,7 +498,7 @@ BOOL LLGLSLShader::attachObject(std::string object) } else { - LL_WARNS("ShaderLoading") << "Attempting to attach shader object that hasn't been compiled: " << object << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Attempting to attach shader object that hasn't been compiled: " << object << LL_ENDL; return FALSE; } } @@ -519,7 +513,7 @@ void LLGLSLShader::attachObject(GLhandleARB object) } else { - LL_WARNS("ShaderLoading") << "Attempting to attach non existing shader object. " << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Attempting to attach non existing shader object. " << LL_ENDL; } } @@ -937,7 +931,7 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextu { if (uniform < 0 || uniform >= (S32)mTexture.size()) { - UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } @@ -963,7 +957,7 @@ S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { - UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } @@ -981,7 +975,7 @@ S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { - UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } S32 index = mTexture[uniform]; @@ -997,7 +991,7 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { - UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL; return -1; } S32 index = mTexture[uniform]; @@ -1026,7 +1020,7 @@ void LLGLSLShader::uniform1i(U32 index, GLint x) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1048,7 +1042,7 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1070,7 +1064,7 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1093,7 +1087,7 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1116,7 +1110,7 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1139,7 +1133,7 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1162,7 +1156,7 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1185,7 +1179,7 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1208,7 +1202,7 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1231,7 +1225,7 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v) { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1254,7 +1248,7 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1271,7 +1265,7 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1288,7 +1282,7 @@ void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } @@ -1305,7 +1299,7 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c { if (mUniform.size() <= index) { - UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; + LL_SHADER_UNIFORM_ERRS() << "Uniform index out of bounds." << LL_ENDL; return; } diff --git a/indra/llrender/llglstates.h b/indra/llrender/llglstates.h index 0e2c3bcb44..a4924eba14 100644 --- a/indra/llrender/llglstates.h +++ b/indra/llrender/llglstates.h @@ -208,11 +208,27 @@ public: class LLGLSPipelineSkyBox { protected: - LLGLDisable mAlphaTest, mCullFace, mFog; + LLGLDisable mAlphaTest; + LLGLDisable mCullFace; + LLGLSquashToFarClip mSquashClip; public: - LLGLSPipelineSkyBox() - : mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG) - { } + LLGLSPipelineSkyBox(); + ~LLGLSPipelineSkyBox(); +}; + +class LLGLSPipelineDepthTestSkyBox : public LLGLSPipelineSkyBox +{ +public: + LLGLSPipelineDepthTestSkyBox(bool depth_test, bool depth_write); + + LLGLDepthTest mDepth; +}; + +class LLGLSPipelineBlendSkyBox : public LLGLSPipelineDepthTestSkyBox +{ +public: + LLGLSPipelineBlendSkyBox(bool depth_test, bool depth_write); + LLGLEnable mBlend; }; class LLGLSTracker diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 251c02dd77..5733a18f47 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1270,7 +1270,7 @@ void LLRender::syncMatrices() glh::matrix4f& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]]; // it would be nice to have this automatically track the state of the proj matrix - // but certain render paths require it to be mismatched *sigh* + // but certain render paths (deferred lighting) require it to be mismatched *sigh* //if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX)) //{ // glh::matrix4f inv_proj = mat.inverse(); diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 62cd526550..a79db80ebe 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -517,4 +517,13 @@ void set_current_projection(glh::matrix4f& mat); glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar); glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar); glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up); + +#if LL_RELEASE_FOR_DOWNLOAD + #define LL_SHADER_LOADING_WARNS(...) LL_WARNS_ONCE("ShaderLoading") + #define LL_SHADER_UNIFORM_ERRS(...) LL_WARNS_ONCE("Shader") +#else + #define LL_SHADER_LOADING_WARNS(...) LL_WARNS() + #define LL_SHADER_UNIFORM_ERRS(...) LL_ERRS("Shader") +#endif + #endif diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 8617b58d2e..9da705bb2d 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -25,18 +25,14 @@ */ #include "linden_common.h" - #include "llshadermgr.h" - -#include "llfile.h" #include "llrender.h" +#include "llfile.h" #if LL_DARWIN #include "OpenGL/OpenGL.h" #endif -#define UNIFORM_ERRS LL_WARNS_ONCE("Shader") - // Lots of STL stuff in here, using namespace std to keep things more readable using std::vector; using std::pair; @@ -537,6 +533,16 @@ static std::string get_object_log(GLhandleARB ret) return res; } +//dump shader source for debugging +void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text) +{ + for (GLuint i = 0; i < shader_code_count; i++) + { + LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; + } + LL_SHADER_LOADING_WARNS() << LL_ENDL; +} + void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename) { std::string log = get_object_log(ret); @@ -548,8 +554,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& if (log.length() > 0) { - LL_WARNS("ShaderLoading") << "Shader loading from " << fname << ":\n" << LL_ENDL; - LL_WARNS("ShaderLoading") << log << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << ":\n" << LL_ENDL; + LL_SHADER_LOADING_WARNS() << log << LL_ENDL; } } @@ -570,11 +576,11 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade error = glGetError(); if (error != GL_NO_ERROR) { - LL_WARNS("ShaderLoading") << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; } } - LL_DEBUGS("ShaderLoading") << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; + //LL_SHADER_LOADING_WARNS() << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; if (filename.empty()) { @@ -588,6 +594,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade S32 try_gpu_class = shader_level; S32 gpu_class; + std::string open_file_name; //find the most relevant file for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) { //search from the current gpu class down to class 1 to find the most relevant shader @@ -595,18 +602,33 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade fname << getShaderDirPrefix(); fname << gpu_class << "/" << filename; - LL_DEBUGS("ShaderLoading") << "Looking in " << fname.str() << LL_ENDL; - file = LLFile::fopen(fname.str(), "r"); /* Flawfinder: ignore */ + open_file_name = fname.str(); + + /* + Would be awesome, if we didn't have shaders that re-use files + with different environments to say, add skinning, etc + can't depend on cached version to have evaluate ifdefs identically... + if we can define a deterministic hash for the shader based on + all the inputs, maybe we can save some time here. + if (mShaderObjects.count(filename) > 0) + { + return mShaderObjects[filename]; + } + + */ + + LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL; + file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */ if (file) { - LL_DEBUGS("ShaderLoading") << "Loading file: shaders/class" << gpu_class << "/" << filename << " (Want class " << gpu_class << ")" << LL_ENDL; + LL_DEBUGS("ShaderLoading") << "Loading file: shaders/class" << gpu_class << "/" << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; break; // done } } if (file == NULL) { - LL_WARNS("ShaderLoading") << "GLSL Shader file not found: " << filename << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << filename << LL_ENDL; return 0; } @@ -685,7 +707,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade extra_code_text[extra_code_count++] = strdup("#define texture2D texture\n"); extra_code_text[extra_code_count++] = strdup("#define textureCube texture\n"); extra_code_text[extra_code_count++] = strdup("#define texture2DLod textureLod\n"); - extra_code_text[extra_code_count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); + extra_code_text[extra_code_count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); if (major_version > 1 || minor_version >= 40) { //GLSL 1.40 replaces texture2DRect et al with texture @@ -1012,7 +1034,7 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) if (!suppress_errors && success == GL_FALSE) { //an error occured, print log - LL_WARNS("ShaderLoading") << "GLSL Linker Error:" << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GLSL Linker Error:" << LL_ENDL; } #if LL_DARWIN @@ -1045,7 +1067,7 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); if (!fragmentGPUProcessing || !vertexGPUProcessing) { - LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; success = GL_FALSE; suppress_errors = FALSE; } @@ -1056,7 +1078,7 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) LLStringUtil::toLower(log); if (log.find("software") != std::string::npos) { - LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; success = GL_FALSE; suppress_errors = FALSE; } @@ -1072,7 +1094,7 @@ BOOL LLShaderMgr::validateProgramObject(GLhandleARB obj) glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); if (success == GL_FALSE) { - LL_WARNS("ShaderLoading") << "GLSL program not valid: " << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL; dumpObjectLog(obj); } else @@ -1326,9 +1348,12 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("rainbow_map"); mReservedUniforms.push_back("halo_map"); mReservedUniforms.push_back("moon_brightness"); - mReservedUniforms.push_back("moon_phase"); mReservedUniforms.push_back("cloud_variance"); + mReservedUniforms.push_back("sh_input_r"); + mReservedUniforms.push_back("sh_input_g"); + mReservedUniforms.push_back("sh_input_b"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index af34c70c54..c22fe44750 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -241,10 +241,13 @@ public: HALO_MAP, MOON_BRIGHTNESS, - MOON_PHASE, CLOUD_VARIANCE, + SH_INPUT_L1R, + SH_INPUT_L1G, + SH_INPUT_L1B, + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; @@ -255,6 +258,7 @@ public: BOOL attachShaderFeatures(LLGLSLShader * shader); void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE, const std::string& filename = ""); + void dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text); BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE); BOOL validateProgramObject(GLhandleARB obj); GLhandleARB loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, boost::unordered_map* defines = NULL, S32 texture_index_channels = -1); -- cgit v1.2.3 From fb335cc243581925bb772a1f10112ec493db8552 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 18:26:24 +0100 Subject: SL-10000 fix storing of ambient value when converting legacy settings --- indra/llrender/llglslshader.cpp | 8 ++++---- indra/llrender/llshadermgr.cpp | 38 ++++---------------------------------- 2 files changed, 8 insertions(+), 38 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index f0cc9acc06..de15d1d75b 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -487,18 +487,18 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, return success; } -BOOL LLGLSLShader::attachObject(std::string object) +BOOL LLGLSLShader::attachObject(std::string object_path) { - if (LLShaderMgr::instance()->mShaderObjects.count(object) > 0) + if (LLShaderMgr::instance()->mShaderObjects.count(object_path) > 0) { stop_glerror(); - glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mShaderObjects[object]); + glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mShaderObjects[object_path]); stop_glerror(); return TRUE; } else { - LL_SHADER_LOADING_WARNS() << "Attempting to attach shader object that hasn't been compiled: " << object << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Attempting to attach shader object: '" << object_path << "' that hasn't been compiled." << LL_ENDL; return FALSE; } } diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 9da705bb2d..d6fe35e2ca 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -628,7 +628,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (file == NULL) { - LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << filename << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << open_file_name << LL_ENDL; return 0; } @@ -958,38 +958,8 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade { //an error occured, print log LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL; - dumpObjectLog(ret, TRUE, filename); -#if LL_WINDOWS - std::stringstream ostr; - //dump shader source for debugging - for (GLuint i = 0; i < shader_code_count; i++) - { - ostr << i << ": " << shader_code_text[i]; - - if (i % 128 == 0) - { //dump every 128 lines - - LL_WARNS("ShaderLoading") << "\n" << ostr.str() << LL_ENDL; - ostr = std::stringstream(); - } - - } - - LL_WARNS("ShaderLoading") << "\n" << ostr.str() << LL_ENDL; -#else - std::string str; - - for (GLuint i = 0; i < shader_code_count; i++) { - str.append(shader_code_text[i]); - - if (i % 128 == 0) - { - LL_WARNS("ShaderLoading") << str << LL_ENDL; - str = ""; - } - } -#endif - + dumpObjectLog(ret, TRUE, open_file_name); + dumpShaderSource(shader_code_count, shader_code_text); ret = 0; } } @@ -1018,7 +988,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (shader_level > 1) { shader_level--; - return loadShaderFile(filename,shader_level,type, defines, texture_index_channels); + return loadShaderFile(filename, shader_level, type, defines, texture_index_channels); } LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; } -- cgit v1.2.3 From 2929998982f37221a58b9fa8037748a2e905f4b1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 6 Nov 2018 19:33:04 +0000 Subject: Move to using a shared deferredUtil object for getting pos/norm from gbuffer. Eliminate 20+ callsites with copy-paste of getPosition and/or getNorm code. Make pipeline use getShadowTarget/releaseShadowTarget consistently. --- indra/llrender/llglslshader.cpp | 3 +++ indra/llrender/llglslshader.h | 4 +++- indra/llrender/llshadermgr.cpp | 14 +++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index de15d1d75b..585f8f6504 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -81,6 +81,9 @@ LLShaderFeatures::LLShaderFeatures() , hasSrgb(false) , encodesNormal(false) , decodesNormal(false) + , isDeferred(false) + , hasIndirect(false) + , hasShadows(false) , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 0934ceba30..ed13106bfd 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -48,9 +48,12 @@ public: bool hasObjectSkinning; bool hasAtmospherics; bool hasGamma; + bool hasShadows; bool hasSrgb; bool encodesNormal; bool decodesNormal; + bool isDeferred; + bool hasIndirect; S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; @@ -227,5 +230,4 @@ extern LLGLSLShader gSolidColorProgram; //Alpha mask shader (declared here so llappearance can access properly) extern LLGLSLShader gAlphaMaskProgram; - #endif diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index d6fe35e2ca..55e4ecda2a 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -186,15 +186,23 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } - if (features->calculatesLighting || features->calculatesAtmospherics) + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->isDeferred || features->hasShadows) { - if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) + if (!shader->attachObject("deferred/deferredUtil.glsl")) + { + return FALSE; + } + } + + if (features->hasIndirect) + { + if (!shader->attachObject("deferred/indirect.glsl")) { return FALSE; } } - // NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->hasGamma) { if (!shader->attachObject("windlight/gammaF.glsl")) -- cgit v1.2.3 From db270df7cc00c1e2519749831e7e98c2c10e3ee6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 18:31:29 +0000 Subject: Back out changes causing broken shadows and other render shenanigans. --- indra/llrender/llshadermgr.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 55e4ecda2a..d6fe35e2ca 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -186,23 +186,15 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->isDeferred || features->hasShadows) - { - if (!shader->attachObject("deferred/deferredUtil.glsl")) - { - return FALSE; - } - } - - if (features->hasIndirect) + if (features->calculatesLighting || features->calculatesAtmospherics) { - if (!shader->attachObject("deferred/indirect.glsl")) + if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) { return FALSE; } } + // NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->hasGamma) { if (!shader->attachObject("windlight/gammaF.glsl")) -- cgit v1.2.3 From d614bf11357d9ff1fef59c7ff11eff73b211dcac Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 21:11:37 +0000 Subject: Yes, Maurice, baby steps. --- indra/llrender/llshadermgr.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index d6fe35e2ca..e128979a76 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -171,6 +171,8 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) // Attach Fragment Shader Features Next /////////////////////////////////////// +// NOTE order of shader object attaching is VERY IMPORTANT!!! + if(features->calculatesAtmospherics) { if (features->hasWaterFog) @@ -194,7 +196,22 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } - // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->isDeferred || features->hasShadows) + { + if (!shader->attachObject("deferred/deferredUtil.glsl")) + { + return FALSE; + } + } + + if (features->hasIndirect) + { + if (!shader->attachObject("deferred/indirect.glsl")) + { + return FALSE; + } + } + if (features->hasGamma) { if (!shader->attachObject("windlight/gammaF.glsl")) -- cgit v1.2.3 From bdf4442e216273bb32eeb607857efdad2336ee81 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 22:55:41 +0000 Subject: Add missing new shader files. --- indra/llrender/llshadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index e128979a76..ae91567334 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -638,7 +638,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */ if (file) { - LL_DEBUGS("ShaderLoading") << "Loading file: shaders/class" << gpu_class << "/" << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; + LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; break; // done } } -- cgit v1.2.3 From a49e2b604e6b505e083e24b10e39053196d917c1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Nov 2018 15:54:53 -0800 Subject: SL-10044 SL-10045 Fix class 1 and 2 transport/gamma funcs and made usage consistent across all shaders. Fix class1\environment\waterV reverting to old d1/d2 names for wave directions. --- indra/llrender/llglslshader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 585f8f6504..15a018a0bb 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -864,7 +864,7 @@ BOOL LLGLSLShader::link(BOOL suppress_errors) { BOOL success = LLShaderMgr::instance()->linkProgramObject(mProgramObject, suppress_errors); - if (!suppress_errors) + if (!success && !suppress_errors) { LLShaderMgr::instance()->dumpObjectLog(mProgramObject, !success, mName); } -- cgit v1.2.3 From 429bef3cf6361c10c99418d419939279747ceb24 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 15 Nov 2018 08:11:05 -0800 Subject: Remove compilation and linkage of deferredUtil and indirect GLSL helper objects (current source of Intel ig4icd driver crash). --- indra/llrender/llshadermgr.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index ae91567334..3a80ff0144 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -196,6 +196,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } +#if USE_DEFERRED_SHADER_API if (features->isDeferred || features->hasShadows) { if (!shader->attachObject("deferred/deferredUtil.glsl")) @@ -211,6 +212,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) return FALSE; } } +#endif if (features->hasGamma) { -- cgit v1.2.3 From 7e9033821a96a9d6e80b58fafb4c7da63807b9d4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Dec 2018 10:59:11 -0800 Subject: De-duplicate deferred gbuffer access for getPosition/getNorm. De-duplicate ambient occlusion shader code and move to new aoUtil.glsl Split shared shadow tap funcs into shadowUtil.glsl --- indra/llrender/llglslshader.cpp | 1 + indra/llrender/llglslshader.h | 1 + indra/llrender/llshadermgr.cpp | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 15a018a0bb..4dae61e185 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -84,6 +84,7 @@ LLShaderFeatures::LLShaderFeatures() , isDeferred(false) , hasIndirect(false) , hasShadows(false) + , hasAmbientOcclusion(false) , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index ed13106bfd..56d322fe6c 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -49,6 +49,7 @@ public: bool hasAtmospherics; bool hasGamma; bool hasShadows; + bool hasAmbientOcclusion; bool hasSrgb; bool encodesNormal; bool decodesNormal; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 3a80ff0144..29d120a135 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -196,8 +196,8 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } -#if USE_DEFERRED_SHADER_API - if (features->isDeferred || features->hasShadows) + // we want this BEFORE shadows and AO because those facilities use pos/norm access + if (features->isDeferred || features->hasShadows || features->hasAmbientOcclusion) { if (!shader->attachObject("deferred/deferredUtil.glsl")) { @@ -205,6 +205,22 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } + if (features->hasShadows) + { + if (!shader->attachObject("deferred/shadowUtil.glsl")) + { + return FALSE; + } + } + + if (features->hasAmbientOcclusion) + { + if (!shader->attachObject("deferred/aoUtil.glsl")) + { + return FALSE; + } + } + if (features->hasIndirect) { if (!shader->attachObject("deferred/indirect.glsl")) @@ -212,7 +228,6 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) return FALSE; } } -#endif if (features->hasGamma) { -- cgit v1.2.3 From 966dc7fc8fb1fade861e8070e9c5fbbfe4d0cb45 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 24 Jan 2019 14:54:11 -0800 Subject: SL-10276 SL-9851 Fix cloud shaders to ignore clouds when cloud_scale is 0. Fix creation of heavenly body geo to avoid degenerate vector math and not randomly flip orientation when crossing zenith. Add sun_up_factor to eliminate sun glow around moon when sun is down. --- indra/llrender/llshadermgr.cpp | 2 ++ indra/llrender/llshadermgr.h | 1 + 2 files changed, 3 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 29d120a135..9db8fd1f05 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1358,6 +1358,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sh_input_g"); mReservedUniforms.push_back("sh_input_b"); + mReservedUniforms.push_back("sun_up_factor"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index c22fe44750..0b1a97d880 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -248,6 +248,7 @@ public: SH_INPUT_L1G, SH_INPUT_L1B, + SUN_UP_FACTOR, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From acbc7f4cddd6ad999c2bc7690c10b85a414a8102 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 08:37:07 -0800 Subject: SL-10415, SL-10434 Further tweaking of directional shadow sampling to balance between peter-panning and shadow acne. Move stars to just this side of the sky some to reduce parallax. Remove decodeNormF and uses of decode_normal in favor of unified use of getNorm (try to help the Intel HD x000 compiler learn to link correctly). --- indra/llrender/llglslshader.cpp | 1 - indra/llrender/llglslshader.h | 1 - indra/llrender/llshadermgr.cpp | 8 -------- 3 files changed, 10 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 4dae61e185..528f23b3ee 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -80,7 +80,6 @@ LLShaderFeatures::LLShaderFeatures() , hasGamma(false) , hasSrgb(false) , encodesNormal(false) - , decodesNormal(false) , isDeferred(false) , hasIndirect(false) , hasShadows(false) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 56d322fe6c..c06668eb43 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -52,7 +52,6 @@ public: bool hasAmbientOcclusion; bool hasSrgb; bool encodesNormal; - bool decodesNormal; bool isDeferred; bool hasIndirect; S32 mIndexedTextureChannels; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 9db8fd1f05..2076947a00 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -253,14 +253,6 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } } - if (features->decodesNormal) - { - if (!shader->attachObject("environment/decodeNormF.glsl")) - { - return FALSE; - } - } - if (features->hasAtmospherics) { if (!shader->attachObject("windlight/atmosphericsF.glsl")) -- cgit v1.2.3 From 08440def112395487d57a9d6e719c7700d7134b5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 12:34:20 -0800 Subject: WIP for 10374 (reduce number of shaders linking against deferredUtil). Prepare for using ifdef to conditionally engage using gl_FragDepth in water shaders (because GL requires that writing to gl_FragDepth on any path means you need to write a depth value on every path). --- indra/llrender/llshadermgr.cpp | 1 + indra/llrender/llshadermgr.h | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 2076947a00..6c8cdb094b 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1351,6 +1351,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sh_input_b"); mReservedUniforms.push_back("sun_up_factor"); + mReservedUniforms.push_back("water_edge"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 0b1a97d880..8651265834 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -249,6 +249,7 @@ public: SH_INPUT_L1B, SUN_UP_FACTOR, + WATER_EDGE_FACTOR, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From deb6110098569fb90ca7e5073c2e98fabbb23a82 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 13:26:35 -0800 Subject: Eliminate helper GLSL modules depending on further GLSL modules to give Intel HD x000 compiler a fighting chance. More WIP for edge-specific water shader for 9996. --- indra/llrender/llshadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 6c8cdb094b..807e41dc97 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -197,7 +197,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) } // we want this BEFORE shadows and AO because those facilities use pos/norm access - if (features->isDeferred || features->hasShadows || features->hasAmbientOcclusion) + if (features->isDeferred) { if (!shader->attachObject("deferred/deferredUtil.glsl")) { -- cgit v1.2.3 From 50b383e5aa333d453e906ae2beb28fe1da549bef Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 09:45:07 -0800 Subject: Fix issue with OSX shader compiler not implementing #if correctly (nice job, Timmy). --- indra/llrender/llrendertarget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index cd484b4fe9..08924dd536 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -286,7 +286,7 @@ bool LLRenderTarget::allocateDepth() U32 internal_type = LLTexUnit::getInternalType(mUsage); stop_glerror(); clear_glerror(); - LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); + LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT32F, mResX, mResY, GL_DEPTH_COMPONENT, GL_FLOAT, NULL, false); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); } @@ -465,6 +465,7 @@ void LLRenderTarget::clear(U32 mask_in) U32 mask = GL_COLOR_BUFFER_BIT; if (mUseDepth) { + glClearDepth(1.25f); mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; } if (mFBO) -- cgit v1.2.3 From db97bb51489dc610fd748b73c321a08e7388d668 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 09:49:55 -0800 Subject: Roll back attempted fix for 9996 on ALM which has unacceptable knock-on effects. --- indra/llrender/llrendertarget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 08924dd536..c6596338e0 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -286,7 +286,7 @@ bool LLRenderTarget::allocateDepth() U32 internal_type = LLTexUnit::getInternalType(mUsage); stop_glerror(); clear_glerror(); - LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT32F, mResX, mResY, GL_DEPTH_COMPONENT, GL_FLOAT, NULL, false); + LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); } -- cgit v1.2.3 From 6716e543a160dd50913309834e7bd2d00034854c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 09:53:36 -0800 Subject: Remove one more piece of attempted 9996 fix on ALM. --- indra/llrender/llrendertarget.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index c6596338e0..cd484b4fe9 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -465,7 +465,6 @@ void LLRenderTarget::clear(U32 mask_in) U32 mask = GL_COLOR_BUFFER_BIT; if (mUseDepth) { - glClearDepth(1.25f); mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; } if (mFBO) -- cgit v1.2.3 From 5a8610ccb7e1f5a0e4d54170ac922e6820ce3acb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 13:41:31 -0800 Subject: SL-9996, SL-1130, SL-5546 Fix bug with setting texture matrix for rigged mesh. Fix z-fighting between sea and sky in ALM by cheating sky, stars, and moon using gl_FragDepth. Fix handling of atmospheric haze glow w.r.t independent sun/moon positioning (we can no longer depend on them being mutex to each other). --- indra/llrender/llshadermgr.cpp | 2 +- indra/llrender/llshadermgr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 807e41dc97..3989c1e2e4 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1350,7 +1350,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sh_input_g"); mReservedUniforms.push_back("sh_input_b"); - mReservedUniforms.push_back("sun_up_factor"); + mReservedUniforms.push_back("sun_moon_glow_factor"); mReservedUniforms.push_back("water_edge"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 8651265834..ef6f33f2e5 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -248,7 +248,7 @@ public: SH_INPUT_L1G, SH_INPUT_L1B, - SUN_UP_FACTOR, + SUN_MOON_GLOW_FACTOR, WATER_EDGE_FACTOR, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From 9a007cceeffb1b960ba495cd0e3d592698a52a99 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Feb 2019 12:56:11 -0800 Subject: SL-10461 Pass projector ambiance as the .w element of the light_attenuation uniform so that alpha shader can emulate the behavior of proper spot projectors. --- indra/llrender/llrender.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 5733a18f47..173444f708 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1151,7 +1151,7 @@ void LLRender::syncLightState() LLVector4 position[8]; LLVector3 direction[8]; - LLVector3 attenuation[8]; + LLVector4 attenuation[8]; LLVector3 diffuse[8]; for (U32 i = 0; i < 8; i++) @@ -1160,13 +1160,13 @@ void LLRender::syncLightState() position[i] = light->mPosition; direction[i] = light->mSpotDirection; - attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[3]); + attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[2], light->mSpecular.mV[3]); diffuse[i].set(light->mDiffuse.mV); } shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); - shader->uniform3fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); + shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); //HACK -- duplicate sunlight color for compatibility with drivers that can't deal with multiple shader objects referencing the same uniform -- cgit v1.2.3 From 8890c3238ab4ae8bbf1bc123284f9c6d4db4f9d6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 6 Feb 2019 16:42:23 -0800 Subject: SL-10478 Fix side-effects of having both sun and moon as potential directional light contributors. We pass an int to the shader indicating which to prefer instead of making per-pixel decisions and pass the moonlight color/di independently. Obsolete llsettingssky fade color which was unused elsewhere and cached for no reason. --- indra/llrender/llrender.cpp | 13 ++++++++++++- indra/llrender/llrender.h | 2 ++ indra/llrender/llshadermgr.cpp | 2 ++ indra/llrender/llshadermgr.h | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 173444f708..6e15f52866 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -895,6 +895,15 @@ void LLLightState::setDiffuse(const LLColor4& diffuse) } } +void LLLightState::setDiffuseB(const LLColor4& diffuse) +{ + if (mDiffuseB != diffuse) + { + ++gGL.mLightHash; + mDiffuseB = diffuse; + } +} + void LLLightState::setAmbient(const LLColor4& ambient) { if (mAmbient != ambient) @@ -1153,6 +1162,7 @@ void LLRender::syncLightState() LLVector3 direction[8]; LLVector4 attenuation[8]; LLVector3 diffuse[8]; + LLVector3 diffuseB[8]; for (U32 i = 0; i < 8; i++) { @@ -1162,6 +1172,7 @@ void LLRender::syncLightState() direction[i] = light->mSpotDirection; attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[2], light->mSpecular.mV[3]); diffuse[i].set(light->mDiffuse.mV); + diffuseB[i].set(light->mDiffuseB.mV); } shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); @@ -1169,8 +1180,8 @@ void LLRender::syncLightState() shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); - //HACK -- duplicate sunlight color for compatibility with drivers that can't deal with multiple shader objects referencing the same uniform shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); + shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuseB[0].mV); } } diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index a79db80ebe..012a8da4ce 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -229,6 +229,7 @@ public: void enable(); void disable(); void setDiffuse(const LLColor4& diffuse); + void setDiffuseB(const LLColor4& diffuse); void setAmbient(const LLColor4& ambient); void setSpecular(const LLColor4& specular); void setPosition(const LLVector4& position); @@ -245,6 +246,7 @@ protected: S32 mIndex; bool mEnabled; LLColor4 mDiffuse; + LLColor4 mDiffuseB; LLColor4 mAmbient; LLColor4 mSpecular; LLVector4 mPosition; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 3989c1e2e4..11e84d8785 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1352,6 +1352,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sun_moon_glow_factor"); mReservedUniforms.push_back("water_edge"); + mReservedUniforms.push_back("sun_up_factor"); + mReservedUniforms.push_back("moonlight_color"); llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index ef6f33f2e5..497c3eb231 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -250,6 +250,8 @@ public: SUN_MOON_GLOW_FACTOR, WATER_EDGE_FACTOR, + SUN_UP_FACTOR, + MOONLIGHT_COLOR, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; -- cgit v1.2.3 From 90f9078d1f931774b5a6e866e26f4e0294f1e2d1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Feb 2019 16:00:21 -0800 Subject: SL-10486, SL-10501, SL-10487 Make moon texture from default daycycle the default moon texture id and use it for the default and blank assets in the picker. Fix handling of MM_TEXTURE to correctly detect when texture units outside the range 0-3 are used with texture matrix ops to prevent mem overwrite bug and/or asserts. --- indra/llrender/llrender.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 173444f708..de04ea601a 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1477,6 +1477,13 @@ void LLRender::matrixMode(U32 mode) { if (mode == MM_TEXTURE) { + U32 tex_index = gGL.getCurrentTexUnitIndex(); + // the shaders don't actually reference anything beyond texture_matrix0/1 + if (tex_index > 3) + { + LL_WARNS_ONCE("render") << "Cannot use texture matrix with texture unit " << tex_index << " forcing texture matrix 3!" << LL_ENDL; + tex_index = 3; + } mode = MM_TEXTURE0 + gGL.getCurrentTexUnitIndex(); } -- cgit v1.2.3 From 0a7bc35335666cc310ef900d4e4144c658b92522 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 8 Feb 2019 13:19:45 -0800 Subject: Replace funcs dropped in merge. --- indra/llrender/llrender.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index de04ea601a..dc9affb596 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -895,6 +895,15 @@ void LLLightState::setDiffuse(const LLColor4& diffuse) } } +void LLLightState::setDiffuseB(const LLColor4& diffuse) +{ + if (mDiffuseB != diffuse) + { + ++gGL.mLightHash; + mDiffuseB = diffuse; + } +} + void LLLightState::setAmbient(const LLColor4& ambient) { if (mAmbient != ambient) @@ -1153,6 +1162,7 @@ void LLRender::syncLightState() LLVector3 direction[8]; LLVector4 attenuation[8]; LLVector3 diffuse[8]; + LLVector3 diffuseB[8]; for (U32 i = 0; i < 8; i++) { @@ -1162,6 +1172,7 @@ void LLRender::syncLightState() direction[i] = light->mSpotDirection; attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[2], light->mSpecular.mV[3]); diffuse[i].set(light->mDiffuse.mV); + diffuseB[i].set(light->mDiffuseB.mV); } shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); @@ -1169,8 +1180,8 @@ void LLRender::syncLightState() shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); - //HACK -- duplicate sunlight color for compatibility with drivers that can't deal with multiple shader objects referencing the same uniform shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); + shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuseB[0].mV); } } -- cgit v1.2.3 From 65927e0a76aaf8ff4dc268acdb12007265ff3a14 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Feb 2019 13:09:14 -0800 Subject: SL-10181, SL-10546 Fix distortion map rendering in deferred mode not including underwater fog effects. Fix distortion map rendering not including post-deferred content at all. Fix distortion map rendering not including anything but sky when camera is underwater. Update sun_up_factor/sunmoon_glow_factor uniforms even when sun disc isn't in use. --- indra/llrender/llgl.cpp | 18 ++++++++++++------ indra/llrender/llgl.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index a55a72c18f..490e1a8c2f 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -2268,6 +2268,17 @@ LLGLUserClipPlane::LLGLUserClipPlane(const LLPlane& p, const glh::matrix4f& mode } } +void LLGLUserClipPlane::disable() +{ + if (mApply) + { + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } + mApply = false; +} + void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d) { glh::matrix4f& P = mProjection; @@ -2296,12 +2307,7 @@ void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d) LLGLUserClipPlane::~LLGLUserClipPlane() { - if (mApply) - { - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.popMatrix(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - } + disable(); } LLGLNamePool::LLGLNamePool() diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 96cbf2e3c2..362fda5fb1 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -348,6 +348,7 @@ public: ~LLGLUserClipPlane(); void setPlane(F32 a, F32 b, F32 c, F32 d); + void disable(); private: bool mApply; -- cgit v1.2.3 From 788a108384a27abf343a1e9ebf5f2437a75552a2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 21 Feb 2019 16:03:46 -0800 Subject: SL-10501 Fix broken matrix management code causing modelview mats to be used as tex anim mats (do not depend on default matrix mode already being set). Give the deferred terrain shader a name. Make LLRender use the eMatrixMode enum instead of ints. --- indra/llrender/llgl.cpp | 4 ++-- indra/llrender/llrender.cpp | 20 ++++++++------------ indra/llrender/llrender.h | 6 +++--- 3 files changed, 13 insertions(+), 17 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 490e1a8c2f..b6300578e6 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -2507,7 +2507,7 @@ void LLGLSquashToFarClip::setProjectionMatrix(glh::matrix4f& projection, U32 lay projection.element(2, i) = projection.element(3, i) * depth; } - U32 last_matrix_mode = gGL.getMatrixMode(); + LLRender::eMatrixMode last_matrix_mode = gGL.getMatrixMode(); gGL.matrixMode(LLRender::MM_PROJECTION); gGL.pushMatrix(); @@ -2518,7 +2518,7 @@ void LLGLSquashToFarClip::setProjectionMatrix(glh::matrix4f& projection, U32 lay LLGLSquashToFarClip::~LLGLSquashToFarClip() { - U32 last_matrix_mode = gGL.getMatrixMode(); + LLRender::eMatrixMode last_matrix_mode = gGL.getMatrixMode(); gGL.matrixMode(LLRender::MM_PROJECTION); gGL.popMatrix(); diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index dc9affb596..e3bb9298cb 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1338,7 +1338,7 @@ void LLRender::syncMatrices() GL_TEXTURE, }; - for (U32 i = 0; i < 2; ++i) + for (U32 i = 0; i < MM_TEXTURE0; ++i) { if (mMatHash[i] != mCurMatHash[i]) { @@ -1348,11 +1348,11 @@ void LLRender::syncMatrices() } } - for (U32 i = 2; i < NUM_MATRIX_MODES; ++i) + for (U32 i = MM_TEXTURE0; i < NUM_MATRIX_MODES; ++i) { if (mMatHash[i] != mCurMatHash[i]) { - gGL.getTexUnit(i-2)->activate(); + gGL.getTexUnit(i-MM_TEXTURE0)->activate(); glMatrixMode(mode[i]); glLoadMatrixf(mMatrix[i][mMatIdx[i]].m); mCurMatHash[i] = mMatHash[i]; @@ -1484,25 +1484,21 @@ void LLRender::multMatrix(const GLfloat* m) } } -void LLRender::matrixMode(U32 mode) +void LLRender::matrixMode(eMatrixMode mode) { if (mode == MM_TEXTURE) { U32 tex_index = gGL.getCurrentTexUnitIndex(); - // the shaders don't actually reference anything beyond texture_matrix0/1 - if (tex_index > 3) - { - LL_WARNS_ONCE("render") << "Cannot use texture matrix with texture unit " << tex_index << " forcing texture matrix 3!" << LL_ENDL; - tex_index = 3; - } - mode = MM_TEXTURE0 + gGL.getCurrentTexUnitIndex(); + // the shaders don't actually reference anything beyond texture_matrix0/1 outside of terrain rendering + llassert_always(tex_index <= 3); + mode = eMatrixMode(MM_TEXTURE0 + gGL.getCurrentTexUnitIndex()); } llassert(mode < NUM_MATRIX_MODES); mMatrixMode = mode; } -U32 LLRender::getMatrixMode() +LLRender::eMatrixMode LLRender::getMatrixMode() { if (mMatrixMode >= MM_TEXTURE0 && mMatrixMode <= MM_TEXTURE3) { //always return MM_TEXTURE if current matrix mode points at any texture matrix diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 012a8da4ce..3f2d5eb35d 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -364,8 +364,8 @@ public: void loadMatrix(const GLfloat* m); void loadIdentity(); void multMatrix(const GLfloat* m); - void matrixMode(U32 mode); - U32 getMatrixMode(); + void matrixMode(eMatrixMode mode); + eMatrixMode getMatrixMode(); const glh::matrix4f& getModelviewMatrix(); const glh::matrix4f& getProjectionMatrix(); @@ -454,7 +454,7 @@ public: private: friend class LLLightState; - U32 mMatrixMode; + eMatrixMode mMatrixMode; U32 mMatIdx[NUM_MATRIX_MODES]; U32 mMatHash[NUM_MATRIX_MODES]; glh::matrix4f mMatrix[NUM_MATRIX_MODES][LL_MATRIX_STACK_DEPTH]; -- cgit v1.2.3 From d8eff424a5fb340b828802351e2b7f6b63bfa30f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 2 Mar 2019 07:17:46 -0800 Subject: SL-10664 --- indra/llrender/CMakeLists.txt | 2 -- indra/llrender/llatmosphere.cpp | 69 ++++---------------------------------- indra/llrender/llatmosphere.h | 73 ++++++++++++++++++++++++++++++++++++----- indra/llrender/llshadermgr.h | 2 +- 4 files changed, 71 insertions(+), 75 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index bcb5a847f6..0a23b6c041 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -13,7 +13,6 @@ include(LLVFS) include(LLWindow) include(LLXML) include(LLVFS) -include(Atmosphere) include_directories( ${FREETYPE_INCLUDE_DIRS} @@ -25,7 +24,6 @@ include_directories( ${LLWINDOW_INCLUDE_DIRS} ${LLXML_INCLUDE_DIRS} ${LLVFS_INCLUDE_DIRS} - ${ATMOSPHERE_INCLUDE_DIR} ) include_directories(SYSTEM ${LLCOMMON_SYSTEM_INCLUDE_DIRS} diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index 12c6685354..a0b92564c3 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -88,8 +88,8 @@ AtmosphericModelSettings::AtmosphericModelSettings() , m_sunArcRadians(0.00045f) , m_mieAnisotropy(0.8f) { - atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); - atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); + DensityLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); + DensityLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); m_rayleighProfile.push_back(rayleigh_density); m_mieProfile.push_back(mie_density); @@ -98,8 +98,8 @@ AtmosphericModelSettings::AtmosphericModelSettings() // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). - m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); - m_absorptionProfile.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); + m_absorptionProfile.push_back(DensityLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); + m_absorptionProfile.push_back(DensityLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); } AtmosphericModelSettings::AtmosphericModelSettings( @@ -227,64 +227,12 @@ LLAtmosphere::~LLAtmosphere() { m_mie_scatter_texture->setTexName(0); } - - delete m_model; - m_model = nullptr; } bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings) { - if ((m_model != nullptr) && (settings == m_settings)) - { - return true; - } - - if (m_model) - { - delete m_model; - } - m_model = nullptr; - - getTransmittance()->setTexName(0); - getScattering()->setTexName(0); - getMieScattering()->setTexName(0); - getIlluminance()->setTexName(0); - - // Init libatmosphere model - m_model = new atmosphere::Model( - m_config, - m_wavelengths, - m_solar_irradiance, - settings.m_sunArcRadians, - settings.m_skyBottomRadius * 1000.0f, - settings.m_skyTopRadius * 1000.0f, - settings.m_rayleighProfile, - m_rayleigh_scattering, - settings.m_mieProfile, - m_mie_scattering, - m_mie_extinction, - settings.m_mieAnisotropy, - settings.m_absorptionProfile, - m_absorption_extinction, - m_ground_albedo, - max_sun_zenith_angle, - 1000.0, - 3, - false, // do not combine_scattering...we want indep textures - false, // use 32F for 2d textures to avoid artifacts - true); // use 16F for 3d textures to reduce footprint - - if (m_model) - { - m_model->Init(m_config, m_textures); - getTransmittance()->setTexName(m_textures.transmittance_texture); - getScattering()->setTexName(m_textures.scattering_texture); - getMieScattering()->setTexName(m_textures.single_mie_scattering_texture); - getIlluminance()->setTexName(m_textures.illuminance_texture); - m_settings = settings; - } - - return m_model != nullptr; + // TBD + return true; } LLGLTexture* LLAtmosphere::getTransmittance() @@ -342,8 +290,3 @@ LLGLTexture* LLAtmosphere::getIlluminance() } return m_illuminance; } - -GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const -{ - return m_model ? m_model->GetShader() : 0; -} diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h index a010803595..572365d864 100644 --- a/indra/llrender/llatmosphere.h +++ b/indra/llrender/llatmosphere.h @@ -1,6 +1,6 @@ /** * @file llatmosphere.h - * @brief LLAtmosphere class for integration with libatmosphere + * @brief LLAtmosphere class * * $LicenseInfo:firstyear=2018&license=viewerlgpl$ * Second Life Viewer Source Code @@ -29,9 +29,70 @@ #include "llglheaders.h" #include "llgltexture.h" -#include "libatmosphere/model.h" -typedef std::vector DensityProfile; +// An atmosphere layer of width 'width' (in m), and whose density is defined as +// 'exp_term' * exp('exp_scale' * h) + 'linear_term' * h + 'constant_term', +// clamped to [0,1], and where h is the altitude (in m). 'exp_term' and +// 'constant_term' are unitless, while 'exp_scale' and 'linear_term' are in +// m^-1. +class DensityLayer { + public: + DensityLayer() + : width(0.0f) + , exp_term(0.0f) + , exp_scale(0.0f) + , linear_term(0.0f) + , constant_term(0.0f) + { + } + + DensityLayer(float width, float exp_term, float exp_scale, float linear_term, float constant_term) + : width(width) + , exp_term(exp_term) + , exp_scale(exp_scale) + , linear_term(linear_term) + , constant_term(constant_term) + { + } + + bool operator==(const DensityLayer& rhs) const + { + if (width != rhs.width) + { + return false; + } + + if (exp_term != rhs.exp_term) + { + return false; + } + + if (exp_scale != rhs.exp_scale) + { + return false; + } + + if (linear_term != rhs.linear_term) + { + return false; + } + + if (constant_term != rhs.constant_term) + { + return false; + } + + return true; + } + + float width = 1024.0f; + float exp_term = 1.0f; + float exp_scale = 1.0f; + float linear_term = 1.0f; + float constant_term = 0.0f; +}; + +typedef std::vector DensityProfile; class AtmosphericModelSettings { @@ -83,8 +144,6 @@ public: LLGLTexture* getMieScattering(); LLGLTexture* getIlluminance(); - GLhandleARB getAtmosphericShaderForLink() const; - bool configureAtmosphericModel(AtmosphericModelSettings& settings); protected: @@ -93,10 +152,6 @@ protected: *this = rhs; } - atmosphere::ModelConfig m_config; - atmosphere::PrecomputedTextures m_textures; - atmosphere::Model* m_model = nullptr; - LLPointer m_transmittance; LLPointer m_scattering; LLPointer m_mie_scatter_texture; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 497c3eb231..e0a67e6198 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -226,7 +226,7 @@ public: SUN_SIZE, FOG_COLOR, - // precomputed textures from libatmosphere + // precomputed textures TRANSMITTANCE_TEX, SCATTER_TEX, SINGLE_MIE_SCATTER_TEX, -- cgit v1.2.3 From 45a541d2d5ccff4279441c715d3f80890e71beb9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 08:04:18 -0800 Subject: SL-10566 Disable pre-cull of water causing refraction/reflection map generation more than is necessary. Re-org alpha draws to limit state changes based on render type. --- indra/llrender/llatmosphere.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp index a0b92564c3..ffc17c89f8 100644 --- a/indra/llrender/llatmosphere.cpp +++ b/indra/llrender/llatmosphere.cpp @@ -80,8 +80,6 @@ const double kMieAngstromBeta = 5.328e-3; const double kMieSingleScatteringAlbedo = 0.9; const double kGroundAlbedo = 0.1; -const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; - AtmosphericModelSettings::AtmosphericModelSettings() : m_skyBottomRadius(6360.0f) , m_skyTopRadius(6420.0f) -- cgit v1.2.3 From f488e5855a310d0db55baac758da5c2f8621d2ee Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 6 Mar 2019 11:23:07 -0800 Subject: Remove refs to libatmo libraries (not pulled into cmake anymore). --- indra/llrender/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 0a23b6c041..0a81c1c6dd 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -107,7 +107,6 @@ if (BUILD_HEADLESS) ${LLXML_LIBRARIES} ${LLVFS_LIBRARIES} ${LLWINDOW_HEADLESS_LIBRARIES} - ${LIBATMOSPHERE_LIBRARIES} ${OPENGL_HEADLESS_LIBRARIES} ) @@ -132,7 +131,6 @@ target_link_libraries(llrender ${LLVFS_LIBRARIES} ${LLWINDOW_LIBRARIES} ${FREETYPE_LIBRARIES} - ${LIBATMOSPHERE_LIBRARIES} ${OPENGL_LIBRARIES} ) -- cgit v1.2.3 From 423fa1ac297e39c9395f45490278b8751188b6db Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Mar 2019 10:56:26 -0800 Subject: SL-10618, SL-10698 Fix reflection/distortion map culling planes again. Fix broken handling of shadow disables in ALM forward shaders. --- indra/llrender/llglslshader.cpp | 5 +++++ indra/llrender/llglslshader.h | 1 + indra/llrender/llshadermgr.cpp | 7 +------ 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 528f23b3ee..9a4eeb59df 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -695,6 +695,11 @@ void LLGLSLShader::mapUniform(GLint index, const vector * } } +void LLGLSLShader::clearPermutations() +{ + mDefines.clear(); +} + void LLGLSLShader::addPermutation(std::string name, std::string value) { mDefines[name] = value; diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index c06668eb43..e5110fe1c4 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -145,6 +145,7 @@ public: GLint getAttribLocation(U32 attrib); GLint mapUniformTextureChannel(GLint location, GLenum type); + void clearPermutations(); void addPermutation(std::string name, std::string value); void removePermutation(std::string name); diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 11e84d8785..ec8f05e4ca 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -791,7 +791,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } */ - extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP 1\n"); + extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n"); //uniform declartion for (S32 i = 0; i < texture_index_channels; ++i) @@ -850,11 +850,6 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL; } } - else - { - extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP 0\n"); - } - //copy file into memory enum { -- cgit v1.2.3 From 53f3755a4629206754a5695de233d88062a54d3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Mar 2019 15:09:34 -0800 Subject: Fix tabs. --- indra/llrender/llglslshader.cpp | 258 ++--- indra/llrender/llglslshader.h | 336 +++--- indra/llrender/llshadermgr.cpp | 2304 +++++++++++++++++++-------------------- 3 files changed, 1449 insertions(+), 1449 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 9a4eeb59df..5659bd327b 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -724,144 +724,144 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type) BOOL LLGLSLShader::mapUniforms(const vector * uniforms) { - BOOL res = TRUE; - - mTotalUniformSize = 0; - mActiveTextureChannels = 0; - mUniform.clear(); - mUniformMap.clear(); - mUniformNameMap.clear(); - mTexture.clear(); - mValue.clear(); - //initialize arrays - U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); - mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - - bind(); - - //get the number of active uniforms - GLint activeCount; - glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); - - //........................................................................................................................................ - //........................................................................................ - - /* - EXPLANATION: - This is part of code is temporary because as the final result the mapUniform() should be rewrited. - But it's a huge a volume of work which is need to be a more carefully performed for avoid possible - regression's (i.e. it should be formalized a separate ticket in JIRA). - - RESON: - The reason of this code is that SL engine is very sensitive to fact that "diffuseMap" should be appear - first as uniform parameter which is should get 0-"texture channel" index (see mapUniformTextureChannel() and mActiveTextureChannels) - it influence to which is texture matrix will be updated during rendering. - - But, order of indexe's of uniform variables is not defined and GLSL compiler can change it as want - , even if the "diffuseMap" will be appear and use first in shader code. - - As example where this situation appear see: "Deferred Material Shader 28/29/30/31" - And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 - */ - - - S32 diffuseMap = glGetUniformLocationARB(mProgramObject, "diffuseMap"); - S32 specularMap = glGetUniformLocationARB(mProgramObject, "specularMap"); - S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); + BOOL res = TRUE; + + mTotalUniformSize = 0; + mActiveTextureChannels = 0; + mUniform.clear(); + mUniformMap.clear(); + mUniformNameMap.clear(); + mTexture.clear(); + mValue.clear(); + //initialize arrays + U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); + mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + + bind(); + + //get the number of active uniforms + GLint activeCount; + glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); + + //........................................................................................................................................ + //........................................................................................ + + /* + EXPLANATION: + This is part of code is temporary because as the final result the mapUniform() should be rewrited. + But it's a huge a volume of work which is need to be a more carefully performed for avoid possible + regression's (i.e. it should be formalized a separate ticket in JIRA). + + RESON: + The reason of this code is that SL engine is very sensitive to fact that "diffuseMap" should be appear + first as uniform parameter which is should get 0-"texture channel" index (see mapUniformTextureChannel() and mActiveTextureChannels) + it influence to which is texture matrix will be updated during rendering. + + But, order of indexe's of uniform variables is not defined and GLSL compiler can change it as want + , even if the "diffuseMap" will be appear and use first in shader code. + + As example where this situation appear see: "Deferred Material Shader 28/29/30/31" + And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 + */ + + + S32 diffuseMap = glGetUniformLocationARB(mProgramObject, "diffuseMap"); + S32 specularMap = glGetUniformLocationARB(mProgramObject, "specularMap"); + S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); S32 altDiffuseMap = glGetUniformLocationARB(mProgramObject, "altDiffuseMap"); - S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); + S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); - std::set skip_index; + std::set skip_index; - if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) - { - GLenum type; - GLsizei length; - GLint size = -1; - char name[1024]; + if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) + { + GLenum type; + GLsizei length; + GLint size = -1; + char name[1024]; - diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; + diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; - for (S32 i = 0; i < activeCount; i++) - { - name[0] = '\0'; + for (S32 i = 0; i < activeCount; i++) + { + name[0] = '\0'; - glGetActiveUniformARB(mProgramObject, i, 1024, &length, &size, &type, (GLcharARB *)name); + glGetActiveUniformARB(mProgramObject, i, 1024, &length, &size, &type, (GLcharARB *)name); - if (-1 == diffuseMap && std::string(name) == "diffuseMap") - { - diffuseMap = i; - continue; - } + if (-1 == diffuseMap && std::string(name) == "diffuseMap") + { + diffuseMap = i; + continue; + } - if (-1 == specularMap && std::string(name) == "specularMap") - { - specularMap = i; - continue; - } + if (-1 == specularMap && std::string(name) == "specularMap") + { + specularMap = i; + continue; + } - if (-1 == bumpMap && std::string(name) == "bumpMap") - { - bumpMap = i; - continue; - } + if (-1 == bumpMap && std::string(name) == "bumpMap") + { + bumpMap = i; + continue; + } - if (-1 == environmentMap && std::string(name) == "environmentMap") - { - environmentMap = i; - continue; - } + if (-1 == environmentMap && std::string(name) == "environmentMap") + { + environmentMap = i; + continue; + } if (-1 == altDiffuseMap && std::string(name) == "altDiffuseMap") - { - altDiffuseMap = i; - continue; - } - } + { + altDiffuseMap = i; + continue; + } + } - bool specularDiff = specularMap < diffuseMap && -1 != specularMap; - bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; - bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; + bool specularDiff = specularMap < diffuseMap && -1 != specularMap; + bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; + bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; - if (specularDiff || bumpLessDiff || envLessDiff) - { - mapUniform(diffuseMap, uniforms); - skip_index.insert(diffuseMap); + if (specularDiff || bumpLessDiff || envLessDiff) + { + mapUniform(diffuseMap, uniforms); + skip_index.insert(diffuseMap); - if (-1 != specularMap) { - mapUniform(specularMap, uniforms); - skip_index.insert(specularMap); - } + if (-1 != specularMap) { + mapUniform(specularMap, uniforms); + skip_index.insert(specularMap); + } - if (-1 != bumpMap) { - mapUniform(bumpMap, uniforms); - skip_index.insert(bumpMap); - } + if (-1 != bumpMap) { + mapUniform(bumpMap, uniforms); + skip_index.insert(bumpMap); + } - if (-1 != environmentMap) { - mapUniform(environmentMap, uniforms); - skip_index.insert(environmentMap); - } - } - } + if (-1 != environmentMap) { + mapUniform(environmentMap, uniforms); + skip_index.insert(environmentMap); + } + } + } - //........................................................................................ + //........................................................................................ - for (S32 i = 0; i < activeCount; i++) - { - //........................................................................................ - if (skip_index.end() != skip_index.find(i)) continue; - //........................................................................................ + for (S32 i = 0; i < activeCount; i++) + { + //........................................................................................ + if (skip_index.end() != skip_index.find(i)) continue; + //........................................................................................ - mapUniform(i, uniforms); - } - //........................................................................................................................................ + mapUniform(i, uniforms); + } + //........................................................................................................................................ - unbind(); + unbind(); - LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; - return res; + LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; + return res; } @@ -1286,19 +1286,19 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { - 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); - } - } + 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) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index e5110fe1c4..9c3effadbe 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -34,201 +34,201 @@ class LLShaderFeatures { public: - bool atmosphericHelpers; - bool calculatesLighting; - bool calculatesAtmospherics; - bool hasLighting; // implies no transport (it's possible to have neither though) - bool isAlphaLighting; // indicates lighting shaders need not be linked in (lighting performed directly in alpha shader to match deferred lighting functions) - bool isShiny; - bool isFullbright; // implies no lighting - bool isSpecular; - bool hasWaterFog; // implies no gamma - bool hasTransport; // implies no lighting (it's possible to have neither though) - bool hasSkinning; - bool hasObjectSkinning; - bool hasAtmospherics; - bool hasGamma; + bool atmosphericHelpers; + bool calculatesLighting; + bool calculatesAtmospherics; + bool hasLighting; // implies no transport (it's possible to have neither though) + bool isAlphaLighting; // indicates lighting shaders need not be linked in (lighting performed directly in alpha shader to match deferred lighting functions) + bool isShiny; + bool isFullbright; // implies no lighting + bool isSpecular; + bool hasWaterFog; // implies no gamma + bool hasTransport; // implies no lighting (it's possible to have neither though) + bool hasSkinning; + bool hasObjectSkinning; + bool hasAtmospherics; + bool hasGamma; bool hasShadows; bool hasAmbientOcclusion; - bool hasSrgb; + bool hasSrgb; bool encodesNormal; bool isDeferred; bool hasIndirect; - S32 mIndexedTextureChannels; - bool disableTextureIndex; - bool hasAlphaMask; - bool attachNothing; - - // char numLights; - - LLShaderFeatures(); + S32 mIndexedTextureChannels; + bool disableTextureIndex; + bool hasAlphaMask; + bool attachNothing; + + // char numLights; + + LLShaderFeatures(); }; class LLGLSLShader { public: - enum - { - SG_DEFAULT = 0, - SG_SKY, - SG_WATER - }; - - static std::set sInstances; - static bool sProfileEnabled; - - LLGLSLShader(); - ~LLGLSLShader(); - - static GLhandleARB sCurBoundShader; - static LLGLSLShader* sCurBoundShaderPtr; - static S32 sIndexedTextureChannels; - static bool sNoFixedFunction; - - static void initProfile(); - static void finishProfile(bool emit_report = true); - - static void startProfile(); - static void stopProfile(U32 count, U32 mode); - - void unload(); - void clearStats(); - void dumpStats(); - void placeProfileQuery(); - void readProfileQuery(U32 count, U32 mode); - - BOOL createShader(std::vector * attributes, - std::vector * 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 * 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); - - 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(U32 index); - - GLint getAttribLocation(U32 attrib); - GLint mapUniformTextureChannel(GLint location, GLenum type); - + enum + { + SG_DEFAULT = 0, + SG_SKY, + SG_WATER + }; + + static std::set sInstances; + static bool sProfileEnabled; + + LLGLSLShader(); + ~LLGLSLShader(); + + static GLhandleARB sCurBoundShader; + static LLGLSLShader* sCurBoundShaderPtr; + static S32 sIndexedTextureChannels; + static bool sNoFixedFunction; + + static void initProfile(); + static void finishProfile(bool emit_report = true); + + static void startProfile(); + static void stopProfile(U32 count, U32 mode); + + void unload(); + void clearStats(); + void dumpStats(); + void placeProfileQuery(); + void readProfileQuery(U32 count, U32 mode); + + BOOL createShader(std::vector * attributes, + std::vector * 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 * 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); + + 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(U32 index); + + GLint getAttribLocation(U32 attrib); + GLint mapUniformTextureChannel(GLint location, GLenum type); + void clearPermutations(); - 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 - //returns channel texture is enabled in from [0-MAX) - 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); - + 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 + //returns channel texture is enabled in from [0-MAX) + 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(); + void bind(); + void unbind(); - // Unbinds any previously bound shader by explicitly binding no shader. - static void bindNoShader(void); + // Unbinds any previously bound shader by explicitly binding no shader. + static void bindNoShader(void); - U32 mMatHash[LLRender::NUM_MATRIX_MODES]; - U32 mLightHash; + U32 mMatHash[LLRender::NUM_MATRIX_MODES]; + U32 mLightHash; - GLhandleARB mProgramObject; + GLhandleARB mProgramObject; #if LL_RELEASE_WITH_DEBUG_INFO - struct attr_name - { - GLint loc; - const char *name; - void operator = (GLint _loc) { loc = _loc; } - operator GLint () { return loc; } - }; - std::vector mAttribute; //lookup table of attribute enum to attribute channel + struct attr_name + { + GLint loc; + const char *name; + void operator = (GLint _loc) { loc = _loc; } + operator GLint () { return loc; } + }; + std::vector mAttribute; //lookup table of attribute enum to attribute channel #else - std::vector mAttribute; //lookup table of attribute enum to attribute channel + std::vector mAttribute; //lookup table of attribute enum to attribute channel #endif - 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; - S32 mTotalUniformSize; - S32 mActiveTextureChannels; - S32 mShaderLevel; - S32 mShaderGroup; - BOOL mUniformsDirty; - LLShaderFeatures mFeatures; - std::vector< std::pair< std::string, GLenum > > mShaderFiles; - std::string mName; - boost::unordered_map mDefines; - - //statistcis for profiling shader performance - U32 mTimerQuery; - U32 mSamplesQuery; - U64 mTimeElapsed; - static U64 sTotalTimeElapsed; - U32 mTrianglesDrawn; - static U32 sTotalTrianglesDrawn; - U64 mSamplesDrawn; - static U64 sTotalSamplesDrawn; - U32 mDrawCalls; - static U32 sTotalDrawCalls; - - bool mTextureStateFetched; - std::vector mTextureMagFilter; - std::vector mTextureMinFilter; + 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; + S32 mTotalUniformSize; + S32 mActiveTextureChannels; + S32 mShaderLevel; + S32 mShaderGroup; + BOOL mUniformsDirty; + LLShaderFeatures mFeatures; + std::vector< std::pair< std::string, GLenum > > mShaderFiles; + std::string mName; + boost::unordered_map mDefines; + + //statistcis for profiling shader performance + U32 mTimerQuery; + U32 mSamplesQuery; + U64 mTimeElapsed; + static U64 sTotalTimeElapsed; + U32 mTrianglesDrawn; + static U32 sTotalTrianglesDrawn; + U64 mSamplesDrawn; + static U64 sTotalSamplesDrawn; + U32 mDrawCalls; + static U32 sTotalDrawCalls; + + bool mTextureStateFetched; + std::vector mTextureMagFilter; + std::vector mTextureMinFilter; GLhandleARB mExtraLinkObject = 0; private: - void unloadInternal(); + void unloadInternal(); }; //UI shader (declared here so llui_libtest will link properly) -extern LLGLSLShader gUIProgram; +extern LLGLSLShader gUIProgram; //output vec4(color.rgb,color.a*tex0[tc0].a) -extern LLGLSLShader gSolidColorProgram; +extern LLGLSLShader gSolidColorProgram; //Alpha mask shader (declared here so llappearance can access properly) -extern LLGLSLShader gAlphaMaskProgram; +extern LLGLSLShader gAlphaMaskProgram; #endif diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index ec8f05e4ca..5b96667f9f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -53,489 +53,489 @@ LLShaderMgr::~LLShaderMgr() // static LLShaderMgr * LLShaderMgr::instance() { - if(NULL == sInstance) - { - LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL; - } + if(NULL == sInstance) + { + LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL; + } - return sInstance; + return sInstance; } BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { - llassert_always(shader != NULL); - LLShaderFeatures *features = & shader->mFeatures; - - if (features->attachNothing) - { - return TRUE; - } - ////////////////////////////////////// - // Attach Vertex Shader Features First - ////////////////////////////////////// - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->calculatesAtmospherics) - { - if (features->hasWaterFog) - { - if (!shader->attachObject("windlight/atmosphericsVarsWaterV.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("windlight/atmosphericsVarsV.glsl")) - { - return FALSE; - } - } - - if (features->calculatesLighting || features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) - { - return FALSE; - } - } - - if (features->calculatesLighting) - { - if (features->isSpecular) - { - if (!shader->attachObject("lighting/lightFuncSpecularV.glsl")) - { - return FALSE; - } - - if (!features->isAlphaLighting) - { - if (!shader->attachObject("lighting/sumLightsSpecularV.glsl")) - { - return FALSE; - } - } - - if (!shader->attachObject("lighting/lightSpecularV.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFuncV.glsl")) - { - return FALSE; - } - - if (!features->isAlphaLighting) - { - if (!shader->attachObject("lighting/sumLightsV.glsl")) - { - return FALSE; - } - } - - if (!shader->attachObject("lighting/lightV.glsl")) - { - return FALSE; - } - } - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsV.glsl")) - { - return FALSE; - } - } - - if (features->hasSkinning) - { - if (!shader->attachObject("avatar/avatarSkinV.glsl")) - { - return FALSE; - } - } - - if (features->hasObjectSkinning) - { - if (!shader->attachObject("avatar/objectSkinV.glsl")) - { - return FALSE; - } - } - - /////////////////////////////////////// - // Attach Fragment Shader Features Next - /////////////////////////////////////// + llassert_always(shader != NULL); + LLShaderFeatures *features = & shader->mFeatures; + + if (features->attachNothing) + { + return TRUE; + } + ////////////////////////////////////// + // Attach Vertex Shader Features First + ////////////////////////////////////// + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->calculatesAtmospherics) + { + if (features->hasWaterFog) + { + if (!shader->attachObject("windlight/atmosphericsVarsWaterV.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("windlight/atmosphericsVarsV.glsl")) + { + return FALSE; + } + } + + if (features->calculatesLighting || features->calculatesAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) + { + return FALSE; + } + } + + if (features->calculatesLighting) + { + if (features->isSpecular) + { + if (!shader->attachObject("lighting/lightFuncSpecularV.glsl")) + { + return FALSE; + } + + if (!features->isAlphaLighting) + { + if (!shader->attachObject("lighting/sumLightsSpecularV.glsl")) + { + return FALSE; + } + } + + if (!shader->attachObject("lighting/lightSpecularV.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFuncV.glsl")) + { + return FALSE; + } + + if (!features->isAlphaLighting) + { + if (!shader->attachObject("lighting/sumLightsV.glsl")) + { + return FALSE; + } + } + + if (!shader->attachObject("lighting/lightV.glsl")) + { + return FALSE; + } + } + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->calculatesAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsV.glsl")) + { + return FALSE; + } + } + + if (features->hasSkinning) + { + if (!shader->attachObject("avatar/avatarSkinV.glsl")) + { + return FALSE; + } + } + + if (features->hasObjectSkinning) + { + if (!shader->attachObject("avatar/objectSkinV.glsl")) + { + return FALSE; + } + } + + /////////////////////////////////////// + // Attach Fragment Shader Features Next + /////////////////////////////////////// // NOTE order of shader object attaching is VERY IMPORTANT!!! - if(features->calculatesAtmospherics) - { - if (features->hasWaterFog) - { - if (!shader->attachObject("windlight/atmosphericsVarsWaterF.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("windlight/atmosphericsVarsF.glsl")) - { - return FALSE; - } - } + if(features->calculatesAtmospherics) + { + if (features->hasWaterFog) + { + if (!shader->attachObject("windlight/atmosphericsVarsWaterF.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("windlight/atmosphericsVarsF.glsl")) + { + return FALSE; + } + } if (features->calculatesLighting || features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) + { + return FALSE; + } + } // we want this BEFORE shadows and AO because those facilities use pos/norm access if (features->isDeferred) - { - if (!shader->attachObject("deferred/deferredUtil.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/deferredUtil.glsl")) + { + return FALSE; + } + } if (features->hasShadows) - { - if (!shader->attachObject("deferred/shadowUtil.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/shadowUtil.glsl")) + { + return FALSE; + } + } if (features->hasAmbientOcclusion) - { - if (!shader->attachObject("deferred/aoUtil.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/aoUtil.glsl")) + { + return FALSE; + } + } if (features->hasIndirect) - { - if (!shader->attachObject("deferred/indirect.glsl")) - { - return FALSE; - } - } - - if (features->hasGamma) - { - if (!shader->attachObject("windlight/gammaF.glsl")) - { - return FALSE; - } - } - - if (features->hasSrgb) - { - if (!shader->attachObject("environment/srgbF.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/indirect.glsl")) + { + return FALSE; + } + } + + if (features->hasGamma) + { + if (!shader->attachObject("windlight/gammaF.glsl")) + { + return FALSE; + } + } + + if (features->hasSrgb) + { + if (!shader->attachObject("environment/srgbF.glsl")) + { + return FALSE; + } + } if (features->encodesNormal) - { - if (!shader->attachObject("environment/encodeNormF.glsl")) - { - return FALSE; - } - } - - if (features->hasAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsF.glsl")) - { - return FALSE; - } - } - - if (features->hasTransport) - { - if (!shader->attachObject("windlight/transportF.glsl")) - { - return FALSE; - } - - // Test hasFullbright and hasShiny and attach fullbright and - // fullbright shiny atmos transport if we split them out. - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->hasWaterFog) - { - if (!shader->attachObject("environment/waterFogF.glsl")) - { - return FALSE; - } - } - - if (features->hasLighting) - { - if (features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightWaterAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightWaterF.glsl")) - { - return FALSE; - } - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else - { - if (features->disableTextureIndex) - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightAlphaMaskNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightNonIndexedF.glsl")) - { - return FALSE; - } - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightF.glsl")) - { - return FALSE; - } - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - else if (features->isFullbright) - { - - if (features->isShiny && features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightShinyWaterF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - else if (features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightWaterAlphaMaskF.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else if (features->isShiny) - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightFullbrightShinyNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightShinyF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else - { - if (features->disableTextureIndex) - { - - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl")) - { - return FALSE; - } - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightF.glsl")) - { - return FALSE; - } - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - else if (features->isShiny) - { - - if (features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightShinyWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightShinyWaterF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightShinyNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightShinyF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - } - - if (features->mIndexedTextureChannels <= 1) - { - if (!shader->attachObject("objects/nonindexedTextureV.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("objects/indexedTextureV.glsl")) - { - return FALSE; - } - } - - return TRUE; + { + if (!shader->attachObject("environment/encodeNormF.glsl")) + { + return FALSE; + } + } + + if (features->hasAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsF.glsl")) + { + return FALSE; + } + } + + if (features->hasTransport) + { + if (!shader->attachObject("windlight/transportF.glsl")) + { + return FALSE; + } + + // Test hasFullbright and hasShiny and attach fullbright and + // fullbright shiny atmos transport if we split them out. + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->hasWaterFog) + { + if (!shader->attachObject("environment/waterFogF.glsl")) + { + return FALSE; + } + } + + if (features->hasLighting) + { + if (features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightWaterAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightWaterF.glsl")) + { + return FALSE; + } + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else + { + if (features->disableTextureIndex) + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightAlphaMaskNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightNonIndexedF.glsl")) + { + return FALSE; + } + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightF.glsl")) + { + return FALSE; + } + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + else if (features->isFullbright) + { + + if (features->isShiny && features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightShinyWaterF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + else if (features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightWaterAlphaMaskF.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else if (features->isShiny) + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightFullbrightShinyNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightShinyF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else + { + if (features->disableTextureIndex) + { + + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl")) + { + return FALSE; + } + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightF.glsl")) + { + return FALSE; + } + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + else if (features->isShiny) + { + + if (features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightShinyWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightShinyWaterF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightShinyNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightShinyF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + } + + if (features->mIndexedTextureChannels <= 1) + { + if (!shader->attachObject("objects/nonindexedTextureV.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("objects/indexedTextureV.glsl")) + { + return FALSE; + } + } + + return TRUE; } //============================================================================ @@ -543,46 +543,46 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) static std::string get_object_log(GLhandleARB ret) { - std::string res; - - //get log length - GLint length; - glGetObjectParameterivARB(ret, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); - if (length > 0) - { - //the log could be any size, so allocate appropriately - GLcharARB* log = new GLcharARB[length]; - glGetInfoLogARB(ret, length, &length, log); - res = std::string((char *)log); - delete[] log; - } - return res; + std::string res; + + //get log length + GLint length; + glGetObjectParameterivARB(ret, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); + if (length > 0) + { + //the log could be any size, so allocate appropriately + GLcharARB* log = new GLcharARB[length]; + glGetInfoLogARB(ret, length, &length, log); + res = std::string((char *)log); + delete[] log; + } + return res; } //dump shader source for debugging void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text) -{ - for (GLuint i = 0; i < shader_code_count; i++) - { - LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; - } +{ + for (GLuint i = 0; i < shader_code_count; i++) + { + LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; + } LL_SHADER_LOADING_WARNS() << LL_ENDL; } void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename) { - std::string log = get_object_log(ret); + std::string log = get_object_log(ret); std::string fname = filename; if (filename.empty()) { fname = "unknown shader file"; } - if (log.length() > 0) - { + if (log.length() > 0) + { LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << ":\n" << LL_ENDL; LL_SHADER_LOADING_WARNS() << log << LL_ENDL; - } + } } GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, boost::unordered_map* defines, S32 texture_index_channels) @@ -596,38 +596,38 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } #endif - GLenum error = GL_NO_ERROR; - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; - } - } - - //LL_SHADER_LOADING_WARNS() << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; + GLenum error = GL_NO_ERROR; + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; + } + } + + //LL_SHADER_LOADING_WARNS() << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; - if (filename.empty()) - { - return 0; - } + if (filename.empty()) + { + return 0; + } - //read in from file - LLFILE* file = NULL; + //read in from file + LLFILE* file = NULL; - S32 try_gpu_class = shader_level; - S32 gpu_class; + S32 try_gpu_class = shader_level; + S32 gpu_class; std::string open_file_name; - //find the most relevant file - for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) - { //search from the current gpu class down to class 1 to find the most relevant shader - std::stringstream fname; - fname << getShaderDirPrefix(); - fname << gpu_class << "/" << filename; - + //find the most relevant file + for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) + { //search from the current gpu class down to class 1 to find the most relevant shader + std::stringstream fname; + fname << getShaderDirPrefix(); + fname << gpu_class << "/" << filename; + open_file_name = fname.str(); /* @@ -643,23 +643,23 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade */ - LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL; - file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */ - if (file) - { - LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; - break; // done - } - } - - if (file == NULL) - { - LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << open_file_name << LL_ENDL; - return 0; - } - - //we can't have any lines longer than 1024 characters - //or any shaders longer than 4096 lines... deal - DaveP + LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL; + file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */ + if (file) + { + LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; + break; // done + } + } + + if (file == NULL) + { + LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << open_file_name << LL_ENDL; + return 0; + } + + //we can't have any lines longer than 1024 characters + //or any shaders longer than 4096 lines... deal - DaveP GLcharARB buff[1024]; GLcharARB *extra_code_text[1024]; GLcharARB *shader_code_text[4096 + LL_ARRAY_SIZE(extra_code_text)] = { NULL }; @@ -667,661 +667,661 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade BOOST_STATIC_ASSERT(LL_ARRAY_SIZE(extra_code_text) < LL_ARRAY_SIZE(shader_code_text)); - S32 major_version = gGLManager.mGLSLVersionMajor; - S32 minor_version = gGLManager.mGLSLVersionMinor; - - if (major_version == 1 && minor_version < 30) - { - if (minor_version < 10) - { - //should NEVER get here -- if major version is 1 and minor version is less than 10, - // viewer should never attempt to use shaders, continuing will result in undefined behavior - LL_ERRS() << "Unsupported GLSL Version." << LL_ENDL; - } - - if (minor_version <= 19) - { - shader_code_text[shader_code_count++] = strdup("#version 110\n"); - extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); - } - else if (minor_version <= 29) - { - //set version to 1.20 - shader_code_text[shader_code_count++] = strdup("#version 120\n"); - extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_120 1\n"); - extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n"); - extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); - } - } - else - { - if (major_version < 4) - { - //set version to 1.30 - shader_code_text[shader_code_count++] = strdup("#version 130\n"); - //some implementations of GLSL 1.30 require integer precision be explicitly declared - extra_code_text[extra_code_count++] = strdup("precision mediump int;\n"); - extra_code_text[extra_code_count++] = strdup("precision highp float;\n"); - } - else - { //set version to 400 - shader_code_text[shader_code_count++] = strdup("#version 400\n"); - } - - extra_code_text[extra_code_count++] = strdup("#define DEFINE_GL_FRAGCOLOR 1\n"); - extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n"); - - extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE in\n"); - - if (type == GL_VERTEX_SHADER_ARB) - { //"varying" state is "out" in a vertex program, "in" in a fragment program - // ("varying" is deprecated after version 1.20) - extra_code_text[extra_code_count++] = strdup("#define VARYING out\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat out\n"); - } - else - { - extra_code_text[extra_code_count++] = strdup("#define VARYING in\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat in\n"); - } - - //backwards compatibility with legacy texture lookup syntax - extra_code_text[extra_code_count++] = strdup("#define texture2D texture\n"); - extra_code_text[extra_code_count++] = strdup("#define textureCube texture\n"); - extra_code_text[extra_code_count++] = strdup("#define texture2DLod textureLod\n"); - extra_code_text[extra_code_count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); - - if (major_version > 1 || minor_version >= 40) - { //GLSL 1.40 replaces texture2DRect et al with texture - extra_code_text[extra_code_count++] = strdup("#define texture2DRect texture\n"); - extra_code_text[extra_code_count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); - } - } - - if (defines) - { - for (boost::unordered_map::iterator iter = defines->begin(); iter != defines->end(); ++iter) - { - std::string define = "#define " + iter->first + " " + iter->second + "\n"; - extra_code_text[extra_code_count++] = (GLcharARB *) strdup(define.c_str()); - } - } - - if( gGLManager.mIsATI ) - { - extra_code_text[extra_code_count++] = strdup( "#define IS_AMD_CARD 1\n" ); - } - - if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER_ARB) - { - //use specified number of texture channels for indexed texture rendering - - /* prepend shader code that looks like this: - - uniform sampler2D tex0; - uniform sampler2D tex1; - uniform sampler2D tex2; - . - . - . - uniform sampler2D texN; - - VARYING_FLAT ivec4 vary_texture_index; - - vec4 ret = vec4(1,0,1,1); - - vec4 diffuseLookup(vec2 texcoord) - { - switch (vary_texture_index.r)) - { - case 0: ret = texture2D(tex0, texcoord); break; - case 1: ret = texture2D(tex1, texcoord); break; - case 2: ret = texture2D(tex2, texcoord); break; - . - . - . - case N: return texture2D(texN, texcoord); break; - } - - return ret; - } - */ - - extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n"); - - //uniform declartion - for (S32 i = 0; i < texture_index_channels; ++i) - { - std::string decl = llformat("uniform sampler2D tex%d;\n", i); - extra_code_text[extra_code_count++] = strdup(decl.c_str()); - } - - if (texture_index_channels > 1) - { - extra_code_text[extra_code_count++] = strdup("VARYING_FLAT int vary_texture_index;\n"); - } - - extra_code_text[extra_code_count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); - extra_code_text[extra_code_count++] = strdup("{\n"); - - - if (texture_index_channels == 1) - { //don't use flow control, that's silly - extra_code_text[extra_code_count++] = strdup("return texture2D(tex0, texcoord);\n"); - extra_code_text[extra_code_count++] = strdup("}\n"); - } - else if (major_version > 1 || minor_version >= 30) - { //switches are supported in GLSL 1.30 and later - if (gGLManager.mIsNVIDIA) - { //switches are unreliable on some NVIDIA drivers - for (U32 i = 0; i < texture_index_channels; ++i) - { - std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture2D(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i); - extra_code_text[extra_code_count++] = strdup(if_string.c_str()); - } - extra_code_text[extra_code_count++] = strdup("\treturn vec4(1,0,1,1);\n"); - extra_code_text[extra_code_count++] = strdup("}\n"); - } - else - { - extra_code_text[extra_code_count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); - extra_code_text[extra_code_count++] = strdup("\tswitch (vary_texture_index)\n"); - extra_code_text[extra_code_count++] = strdup("\t{\n"); - - //switch body - for (S32 i = 0; i < texture_index_channels; ++i) - { - std::string case_str = llformat("\t\tcase %d: return texture2D(tex%d, texcoord);\n", i, i); - extra_code_text[extra_code_count++] = strdup(case_str.c_str()); - } - - extra_code_text[extra_code_count++] = strdup("\t}\n"); - extra_code_text[extra_code_count++] = strdup("\treturn ret;\n"); - extra_code_text[extra_code_count++] = strdup("}\n"); - } - } - else - { //should never get here. Indexed texture rendering requires GLSL 1.30 or later - // (for passing integers between vertex and fragment shaders) - LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL; - } - } + S32 major_version = gGLManager.mGLSLVersionMajor; + S32 minor_version = gGLManager.mGLSLVersionMinor; + + if (major_version == 1 && minor_version < 30) + { + if (minor_version < 10) + { + //should NEVER get here -- if major version is 1 and minor version is less than 10, + // viewer should never attempt to use shaders, continuing will result in undefined behavior + LL_ERRS() << "Unsupported GLSL Version." << LL_ENDL; + } + + if (minor_version <= 19) + { + shader_code_text[shader_code_count++] = strdup("#version 110\n"); + extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); + } + else if (minor_version <= 29) + { + //set version to 1.20 + shader_code_text[shader_code_count++] = strdup("#version 120\n"); + extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_120 1\n"); + extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n"); + extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); + } + } + else + { + if (major_version < 4) + { + //set version to 1.30 + shader_code_text[shader_code_count++] = strdup("#version 130\n"); + //some implementations of GLSL 1.30 require integer precision be explicitly declared + extra_code_text[extra_code_count++] = strdup("precision mediump int;\n"); + extra_code_text[extra_code_count++] = strdup("precision highp float;\n"); + } + else + { //set version to 400 + shader_code_text[shader_code_count++] = strdup("#version 400\n"); + } + + extra_code_text[extra_code_count++] = strdup("#define DEFINE_GL_FRAGCOLOR 1\n"); + extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n"); + + extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE in\n"); + + if (type == GL_VERTEX_SHADER_ARB) + { //"varying" state is "out" in a vertex program, "in" in a fragment program + // ("varying" is deprecated after version 1.20) + extra_code_text[extra_code_count++] = strdup("#define VARYING out\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat out\n"); + } + else + { + extra_code_text[extra_code_count++] = strdup("#define VARYING in\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat in\n"); + } + + //backwards compatibility with legacy texture lookup syntax + extra_code_text[extra_code_count++] = strdup("#define texture2D texture\n"); + extra_code_text[extra_code_count++] = strdup("#define textureCube texture\n"); + extra_code_text[extra_code_count++] = strdup("#define texture2DLod textureLod\n"); + extra_code_text[extra_code_count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); + + if (major_version > 1 || minor_version >= 40) + { //GLSL 1.40 replaces texture2DRect et al with texture + extra_code_text[extra_code_count++] = strdup("#define texture2DRect texture\n"); + extra_code_text[extra_code_count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); + } + } + + if (defines) + { + for (boost::unordered_map::iterator iter = defines->begin(); iter != defines->end(); ++iter) + { + std::string define = "#define " + iter->first + " " + iter->second + "\n"; + extra_code_text[extra_code_count++] = (GLcharARB *) strdup(define.c_str()); + } + } + + if( gGLManager.mIsATI ) + { + extra_code_text[extra_code_count++] = strdup( "#define IS_AMD_CARD 1\n" ); + } + + if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER_ARB) + { + //use specified number of texture channels for indexed texture rendering + + /* prepend shader code that looks like this: + + uniform sampler2D tex0; + uniform sampler2D tex1; + uniform sampler2D tex2; + . + . + . + uniform sampler2D texN; + + VARYING_FLAT ivec4 vary_texture_index; + + vec4 ret = vec4(1,0,1,1); + + vec4 diffuseLookup(vec2 texcoord) + { + switch (vary_texture_index.r)) + { + case 0: ret = texture2D(tex0, texcoord); break; + case 1: ret = texture2D(tex1, texcoord); break; + case 2: ret = texture2D(tex2, texcoord); break; + . + . + . + case N: return texture2D(texN, texcoord); break; + } + + return ret; + } + */ + + extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n"); + + //uniform declartion + for (S32 i = 0; i < texture_index_channels; ++i) + { + std::string decl = llformat("uniform sampler2D tex%d;\n", i); + extra_code_text[extra_code_count++] = strdup(decl.c_str()); + } + + if (texture_index_channels > 1) + { + extra_code_text[extra_code_count++] = strdup("VARYING_FLAT int vary_texture_index;\n"); + } + + extra_code_text[extra_code_count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); + extra_code_text[extra_code_count++] = strdup("{\n"); + + + if (texture_index_channels == 1) + { //don't use flow control, that's silly + extra_code_text[extra_code_count++] = strdup("return texture2D(tex0, texcoord);\n"); + extra_code_text[extra_code_count++] = strdup("}\n"); + } + else if (major_version > 1 || minor_version >= 30) + { //switches are supported in GLSL 1.30 and later + if (gGLManager.mIsNVIDIA) + { //switches are unreliable on some NVIDIA drivers + for (U32 i = 0; i < texture_index_channels; ++i) + { + std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture2D(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i); + extra_code_text[extra_code_count++] = strdup(if_string.c_str()); + } + extra_code_text[extra_code_count++] = strdup("\treturn vec4(1,0,1,1);\n"); + extra_code_text[extra_code_count++] = strdup("}\n"); + } + else + { + extra_code_text[extra_code_count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); + extra_code_text[extra_code_count++] = strdup("\tswitch (vary_texture_index)\n"); + extra_code_text[extra_code_count++] = strdup("\t{\n"); + + //switch body + for (S32 i = 0; i < texture_index_channels; ++i) + { + std::string case_str = llformat("\t\tcase %d: return texture2D(tex%d, texcoord);\n", i, i); + extra_code_text[extra_code_count++] = strdup(case_str.c_str()); + } + + extra_code_text[extra_code_count++] = strdup("\t}\n"); + extra_code_text[extra_code_count++] = strdup("\treturn ret;\n"); + extra_code_text[extra_code_count++] = strdup("}\n"); + } + } + else + { //should never get here. Indexed texture rendering requires GLSL 1.30 or later + // (for passing integers between vertex and fragment shaders) + LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL; + } + } + + //copy file into memory + enum { + flag_write_to_out_of_extra_block_area = 0x01 + , flag_extra_block_marker_was_found = 0x02 + }; + + unsigned char flags = flag_write_to_out_of_extra_block_area; + + GLuint out_of_extra_block_counter = 0, start_shader_code = shader_code_count, file_lines_count = 0; - //copy file into memory - enum { - flag_write_to_out_of_extra_block_area = 0x01 - , flag_extra_block_marker_was_found = 0x02 - }; - - unsigned char flags = flag_write_to_out_of_extra_block_area; - - GLuint out_of_extra_block_counter = 0, start_shader_code = shader_code_count, file_lines_count = 0; - - while(NULL != fgets((char *)buff, 1024, file) - && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text))) - { - file_lines_count++; - - bool extra_block_area_found = NULL != strstr((const char*)buff, "[EXTRA_CODE_HERE]"); - - if(extra_block_area_found && !(flag_extra_block_marker_was_found & flags)) - { - if(!(flag_write_to_out_of_extra_block_area & flags)) - { - //shift - for(GLuint to = start_shader_code, from = extra_code_count + start_shader_code; - from < shader_code_count; ++to, ++from) - { - shader_code_text[to] = shader_code_text[from]; - } - - shader_code_count -= extra_code_count; - } - - //copy extra code - for(GLuint n = 0; n < extra_code_count - && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)); ++n) - { - shader_code_text[shader_code_count++] = extra_code_text[n]; - } - - extra_code_count = 0; - - flags &= ~flag_write_to_out_of_extra_block_area; - flags |= flag_extra_block_marker_was_found; - } + while(NULL != fgets((char *)buff, 1024, file) + && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text))) + { + file_lines_count++; + + bool extra_block_area_found = NULL != strstr((const char*)buff, "[EXTRA_CODE_HERE]"); + + if(extra_block_area_found && !(flag_extra_block_marker_was_found & flags)) + { + if(!(flag_write_to_out_of_extra_block_area & flags)) + { + //shift + for(GLuint to = start_shader_code, from = extra_code_count + start_shader_code; + from < shader_code_count; ++to, ++from) + { + shader_code_text[to] = shader_code_text[from]; + } + + shader_code_count -= extra_code_count; + } + + //copy extra code + for(GLuint n = 0; n < extra_code_count + && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)); ++n) + { + shader_code_text[shader_code_count++] = extra_code_text[n]; + } + + extra_code_count = 0; + + flags &= ~flag_write_to_out_of_extra_block_area; + flags |= flag_extra_block_marker_was_found; + } else { shader_code_text[shader_code_count] = (GLcharARB *)strdup((char *)buff); - + if(flag_write_to_out_of_extra_block_area & flags) { shader_code_text[extra_code_count + start_shader_code + out_of_extra_block_counter] = shader_code_text[shader_code_count]; out_of_extra_block_counter++; - + if(out_of_extra_block_counter == extra_code_count) { shader_code_count += extra_code_count; flags &= ~flag_write_to_out_of_extra_block_area; } } - + ++shader_code_count; - } - } //while - - if(!(flag_extra_block_marker_was_found & flags)) - { - for(GLuint n = start_shader_code; n < extra_code_count + start_shader_code; ++n) - { - shader_code_text[n] = extra_code_text[n - start_shader_code]; - } - - if (file_lines_count < extra_code_count) - { - shader_code_count += extra_code_count; - } - - extra_code_count = 0; - } - - fclose(file); - - //create shader object - GLhandleARB ret = glCreateShaderObjectARB(type); - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShaderObjectARB: " << error << LL_ENDL; - } - } - - //load source - glShaderSourceARB(ret, shader_code_count, (const GLcharARB**) shader_code_text, NULL); - - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL; - } - } - - //compile source - glCompileShaderARB(ret); - - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL; - } - } - - if (error == GL_NO_ERROR) - { - //check for errors - GLint success = GL_TRUE; - glGetObjectParameterivARB(ret, GL_OBJECT_COMPILE_STATUS_ARB, &success); - if (gDebugGL || success == GL_FALSE) - { - error = glGetError(); - if (error != GL_NO_ERROR || success == GL_FALSE) - { - //an error occured, print log - LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL; - dumpObjectLog(ret, TRUE, open_file_name); + } + } //while + + if(!(flag_extra_block_marker_was_found & flags)) + { + for(GLuint n = start_shader_code; n < extra_code_count + start_shader_code; ++n) + { + shader_code_text[n] = extra_code_text[n - start_shader_code]; + } + + if (file_lines_count < extra_code_count) + { + shader_code_count += extra_code_count; + } + + extra_code_count = 0; + } + + fclose(file); + + //create shader object + GLhandleARB ret = glCreateShaderObjectARB(type); + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShaderObjectARB: " << error << LL_ENDL; + } + } + + //load source + glShaderSourceARB(ret, shader_code_count, (const GLcharARB**) shader_code_text, NULL); + + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL; + } + } + + //compile source + glCompileShaderARB(ret); + + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL; + } + } + + if (error == GL_NO_ERROR) + { + //check for errors + GLint success = GL_TRUE; + glGetObjectParameterivARB(ret, GL_OBJECT_COMPILE_STATUS_ARB, &success); + if (gDebugGL || success == GL_FALSE) + { + error = glGetError(); + if (error != GL_NO_ERROR || success == GL_FALSE) + { + //an error occured, print log + LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL; + dumpObjectLog(ret, TRUE, open_file_name); dumpShaderSource(shader_code_count, shader_code_text); - ret = 0; - } - } - } - else - { - ret = 0; - } - stop_glerror(); - - //free memory - for (GLuint i = 0; i < shader_code_count; i++) - { - free(shader_code_text[i]); - } - - //successfully loaded, save results - if (ret) - { - // Add shader file to map - mShaderObjects[filename] = ret; - shader_level = try_gpu_class; - } - else - { - if (shader_level > 1) - { - shader_level--; - return loadShaderFile(filename, shader_level, type, defines, texture_index_channels); - } - LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; - } - return ret; + ret = 0; + } + } + } + else + { + ret = 0; + } + stop_glerror(); + + //free memory + for (GLuint i = 0; i < shader_code_count; i++) + { + free(shader_code_text[i]); + } + + //successfully loaded, save results + if (ret) + { + // Add shader file to map + mShaderObjects[filename] = ret; + shader_level = try_gpu_class; + } + else + { + if (shader_level > 1) + { + shader_level--; + return loadShaderFile(filename, shader_level, type, defines, texture_index_channels); + } + LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; + } + return ret; } BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) { - //check for errors - glLinkProgramARB(obj); - GLint success = GL_TRUE; - glGetObjectParameterivARB(obj, GL_OBJECT_LINK_STATUS_ARB, &success); - if (!suppress_errors && success == GL_FALSE) - { - //an error occured, print log - LL_SHADER_LOADING_WARNS() << "GLSL Linker Error:" << LL_ENDL; - } + //check for errors + glLinkProgramARB(obj); + GLint success = GL_TRUE; + glGetObjectParameterivARB(obj, GL_OBJECT_LINK_STATUS_ARB, &success); + if (!suppress_errors && success == GL_FALSE) + { + //an error occured, print log + LL_SHADER_LOADING_WARNS() << "GLSL Linker Error:" << LL_ENDL; + } #if LL_DARWIN - // For some reason this absolutely kills the frame rate when VBO's are enabled - if (0) - { - // Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software - // per Apple's suggestion - LLGLSLShader::sNoFixedFunction = false; - - glUseProgramObjectARB(obj); - - gGL.begin(LLRender::TRIANGLES); - gGL.vertex3f(0.0f, 0.0f, 0.0f); - gGL.vertex3f(0.0f, 0.0f, 0.0f); - gGL.vertex3f(0.0f, 0.0f, 0.0f); - gGL.end(); - gGL.flush(); - - glUseProgramObjectARB(0); - - LLGLSLShader::sNoFixedFunction = true; - - // Query whether the shader can or cannot run in hardware - // http://developer.apple.com/qa/qa2007/qa1502.html - GLint vertexGPUProcessing, fragmentGPUProcessing; - CGLContextObj ctx = CGLGetCurrentContext(); - CGLGetParameter(ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing); - CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); - if (!fragmentGPUProcessing || !vertexGPUProcessing) - { - LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; - success = GL_FALSE; - suppress_errors = FALSE; - } - } + // For some reason this absolutely kills the frame rate when VBO's are enabled + if (0) + { + // Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software + // per Apple's suggestion + LLGLSLShader::sNoFixedFunction = false; + + glUseProgramObjectARB(obj); + + gGL.begin(LLRender::TRIANGLES); + gGL.vertex3f(0.0f, 0.0f, 0.0f); + gGL.vertex3f(0.0f, 0.0f, 0.0f); + gGL.vertex3f(0.0f, 0.0f, 0.0f); + gGL.end(); + gGL.flush(); + + glUseProgramObjectARB(0); + + LLGLSLShader::sNoFixedFunction = true; + + // Query whether the shader can or cannot run in hardware + // http://developer.apple.com/qa/qa2007/qa1502.html + GLint vertexGPUProcessing, fragmentGPUProcessing; + CGLContextObj ctx = CGLGetCurrentContext(); + CGLGetParameter(ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing); + CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); + if (!fragmentGPUProcessing || !vertexGPUProcessing) + { + LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; + success = GL_FALSE; + suppress_errors = FALSE; + } + } #else - std::string log = get_object_log(obj); - LLStringUtil::toLower(log); - if (log.find("software") != std::string::npos) - { - LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; - success = GL_FALSE; - suppress_errors = FALSE; - } + std::string log = get_object_log(obj); + LLStringUtil::toLower(log); + if (log.find("software") != std::string::npos) + { + LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; + success = GL_FALSE; + suppress_errors = FALSE; + } #endif - return success; + return success; } BOOL LLShaderMgr::validateProgramObject(GLhandleARB obj) { - //check program validity against current GL - glValidateProgramARB(obj); - GLint success = GL_TRUE; - glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); - if (success == GL_FALSE) - { - LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL; - dumpObjectLog(obj); - } - else - { - dumpObjectLog(obj, FALSE); - } - - return success; + //check program validity against current GL + glValidateProgramARB(obj); + GLint success = GL_TRUE; + glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); + if (success == GL_FALSE) + { + LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL; + dumpObjectLog(obj); + } + else + { + dumpObjectLog(obj, FALSE); + } + + return success; } //virtual void LLShaderMgr::initAttribsAndUniforms() { - //MUST match order of enum in LLVertexBuffer.h - mReservedAttribs.push_back("position"); - mReservedAttribs.push_back("normal"); - mReservedAttribs.push_back("texcoord0"); - mReservedAttribs.push_back("texcoord1"); - mReservedAttribs.push_back("texcoord2"); - mReservedAttribs.push_back("texcoord3"); - mReservedAttribs.push_back("diffuse_color"); - mReservedAttribs.push_back("emissive"); - mReservedAttribs.push_back("tangent"); - mReservedAttribs.push_back("weight"); - mReservedAttribs.push_back("weight4"); - mReservedAttribs.push_back("clothing"); - mReservedAttribs.push_back("texture_index"); - - //matrix state - mReservedUniforms.push_back("modelview_matrix"); - mReservedUniforms.push_back("projection_matrix"); - mReservedUniforms.push_back("inv_proj"); - mReservedUniforms.push_back("modelview_projection_matrix"); + //MUST match order of enum in LLVertexBuffer.h + mReservedAttribs.push_back("position"); + mReservedAttribs.push_back("normal"); + mReservedAttribs.push_back("texcoord0"); + mReservedAttribs.push_back("texcoord1"); + mReservedAttribs.push_back("texcoord2"); + mReservedAttribs.push_back("texcoord3"); + mReservedAttribs.push_back("diffuse_color"); + mReservedAttribs.push_back("emissive"); + mReservedAttribs.push_back("tangent"); + mReservedAttribs.push_back("weight"); + mReservedAttribs.push_back("weight4"); + mReservedAttribs.push_back("clothing"); + mReservedAttribs.push_back("texture_index"); + + //matrix state + mReservedUniforms.push_back("modelview_matrix"); + mReservedUniforms.push_back("projection_matrix"); + mReservedUniforms.push_back("inv_proj"); + mReservedUniforms.push_back("modelview_projection_matrix"); mReservedUniforms.push_back("inv_modelview"); - mReservedUniforms.push_back("normal_matrix"); - mReservedUniforms.push_back("texture_matrix0"); - mReservedUniforms.push_back("texture_matrix1"); - mReservedUniforms.push_back("texture_matrix2"); - mReservedUniforms.push_back("texture_matrix3"); - mReservedUniforms.push_back("object_plane_s"); - mReservedUniforms.push_back("object_plane_t"); - llassert(mReservedUniforms.size() == LLShaderMgr::OBJECT_PLANE_T+1); - - mReservedUniforms.push_back("viewport"); - - mReservedUniforms.push_back("light_position"); - mReservedUniforms.push_back("light_direction"); - mReservedUniforms.push_back("light_attenuation"); - mReservedUniforms.push_back("light_diffuse"); - mReservedUniforms.push_back("light_ambient"); - mReservedUniforms.push_back("light_count"); - mReservedUniforms.push_back("light"); - mReservedUniforms.push_back("light_col"); - mReservedUniforms.push_back("far_z"); - - llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1); - - - mReservedUniforms.push_back("proj_mat"); - mReservedUniforms.push_back("proj_near"); - mReservedUniforms.push_back("proj_p"); - mReservedUniforms.push_back("proj_n"); - mReservedUniforms.push_back("proj_origin"); - mReservedUniforms.push_back("proj_range"); - mReservedUniforms.push_back("proj_ambiance"); - mReservedUniforms.push_back("proj_shadow_idx"); - mReservedUniforms.push_back("shadow_fade"); - mReservedUniforms.push_back("proj_focus"); - mReservedUniforms.push_back("proj_lod"); - mReservedUniforms.push_back("proj_ambient_lod"); - - llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1); - - mReservedUniforms.push_back("color"); - - mReservedUniforms.push_back("diffuseMap"); + mReservedUniforms.push_back("normal_matrix"); + mReservedUniforms.push_back("texture_matrix0"); + mReservedUniforms.push_back("texture_matrix1"); + mReservedUniforms.push_back("texture_matrix2"); + mReservedUniforms.push_back("texture_matrix3"); + mReservedUniforms.push_back("object_plane_s"); + mReservedUniforms.push_back("object_plane_t"); + llassert(mReservedUniforms.size() == LLShaderMgr::OBJECT_PLANE_T+1); + + mReservedUniforms.push_back("viewport"); + + mReservedUniforms.push_back("light_position"); + mReservedUniforms.push_back("light_direction"); + mReservedUniforms.push_back("light_attenuation"); + mReservedUniforms.push_back("light_diffuse"); + mReservedUniforms.push_back("light_ambient"); + mReservedUniforms.push_back("light_count"); + mReservedUniforms.push_back("light"); + mReservedUniforms.push_back("light_col"); + mReservedUniforms.push_back("far_z"); + + llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1); + + + mReservedUniforms.push_back("proj_mat"); + mReservedUniforms.push_back("proj_near"); + mReservedUniforms.push_back("proj_p"); + mReservedUniforms.push_back("proj_n"); + mReservedUniforms.push_back("proj_origin"); + mReservedUniforms.push_back("proj_range"); + mReservedUniforms.push_back("proj_ambiance"); + mReservedUniforms.push_back("proj_shadow_idx"); + mReservedUniforms.push_back("shadow_fade"); + mReservedUniforms.push_back("proj_focus"); + mReservedUniforms.push_back("proj_lod"); + mReservedUniforms.push_back("proj_ambient_lod"); + + llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1); + + mReservedUniforms.push_back("color"); + + mReservedUniforms.push_back("diffuseMap"); mReservedUniforms.push_back("altDiffuseMap"); - mReservedUniforms.push_back("specularMap"); - mReservedUniforms.push_back("bumpMap"); + mReservedUniforms.push_back("specularMap"); + mReservedUniforms.push_back("bumpMap"); mReservedUniforms.push_back("bumpMap2"); - mReservedUniforms.push_back("environmentMap"); - mReservedUniforms.push_back("cloud_noise_texture"); + mReservedUniforms.push_back("environmentMap"); + mReservedUniforms.push_back("cloud_noise_texture"); mReservedUniforms.push_back("cloud_noise_texture_next"); - mReservedUniforms.push_back("fullbright"); - mReservedUniforms.push_back("lightnorm"); - mReservedUniforms.push_back("sunlight_color"); - mReservedUniforms.push_back("ambient"); - mReservedUniforms.push_back("blue_horizon"); - mReservedUniforms.push_back("blue_density"); - mReservedUniforms.push_back("haze_horizon"); - mReservedUniforms.push_back("haze_density"); - mReservedUniforms.push_back("cloud_shadow"); - mReservedUniforms.push_back("density_multiplier"); - mReservedUniforms.push_back("distance_multiplier"); - mReservedUniforms.push_back("max_y"); - mReservedUniforms.push_back("glow"); - mReservedUniforms.push_back("cloud_color"); - mReservedUniforms.push_back("cloud_pos_density1"); - mReservedUniforms.push_back("cloud_pos_density2"); - mReservedUniforms.push_back("cloud_scale"); - mReservedUniforms.push_back("gamma"); - mReservedUniforms.push_back("scene_light_strength"); - - llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1); - - mReservedUniforms.push_back("center"); - mReservedUniforms.push_back("size"); - mReservedUniforms.push_back("falloff"); - - mReservedUniforms.push_back("box_center"); - mReservedUniforms.push_back("box_size"); - - - mReservedUniforms.push_back("minLuminance"); - mReservedUniforms.push_back("maxExtractAlpha"); - mReservedUniforms.push_back("lumWeights"); - mReservedUniforms.push_back("warmthWeights"); - mReservedUniforms.push_back("warmthAmount"); - mReservedUniforms.push_back("glowStrength"); - mReservedUniforms.push_back("glowDelta"); - - llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_DELTA+1); - - - mReservedUniforms.push_back("minimum_alpha"); - mReservedUniforms.push_back("emissive_brightness"); - - mReservedUniforms.push_back("shadow_matrix"); - mReservedUniforms.push_back("env_mat"); - mReservedUniforms.push_back("shadow_clip"); - mReservedUniforms.push_back("sun_wash"); - mReservedUniforms.push_back("shadow_noise"); - mReservedUniforms.push_back("blur_size"); - mReservedUniforms.push_back("ssao_radius"); - mReservedUniforms.push_back("ssao_max_radius"); - mReservedUniforms.push_back("ssao_factor"); - mReservedUniforms.push_back("ssao_factor_inv"); - mReservedUniforms.push_back("ssao_effect_mat"); - mReservedUniforms.push_back("screen_res"); - mReservedUniforms.push_back("near_clip"); - mReservedUniforms.push_back("shadow_offset"); - mReservedUniforms.push_back("shadow_bias"); - mReservedUniforms.push_back("spot_shadow_bias"); - mReservedUniforms.push_back("spot_shadow_offset"); - mReservedUniforms.push_back("sun_dir"); + mReservedUniforms.push_back("fullbright"); + mReservedUniforms.push_back("lightnorm"); + mReservedUniforms.push_back("sunlight_color"); + mReservedUniforms.push_back("ambient"); + mReservedUniforms.push_back("blue_horizon"); + mReservedUniforms.push_back("blue_density"); + mReservedUniforms.push_back("haze_horizon"); + mReservedUniforms.push_back("haze_density"); + mReservedUniforms.push_back("cloud_shadow"); + mReservedUniforms.push_back("density_multiplier"); + mReservedUniforms.push_back("distance_multiplier"); + mReservedUniforms.push_back("max_y"); + mReservedUniforms.push_back("glow"); + mReservedUniforms.push_back("cloud_color"); + mReservedUniforms.push_back("cloud_pos_density1"); + mReservedUniforms.push_back("cloud_pos_density2"); + mReservedUniforms.push_back("cloud_scale"); + mReservedUniforms.push_back("gamma"); + mReservedUniforms.push_back("scene_light_strength"); + + llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1); + + mReservedUniforms.push_back("center"); + mReservedUniforms.push_back("size"); + mReservedUniforms.push_back("falloff"); + + mReservedUniforms.push_back("box_center"); + mReservedUniforms.push_back("box_size"); + + + mReservedUniforms.push_back("minLuminance"); + mReservedUniforms.push_back("maxExtractAlpha"); + mReservedUniforms.push_back("lumWeights"); + mReservedUniforms.push_back("warmthWeights"); + mReservedUniforms.push_back("warmthAmount"); + mReservedUniforms.push_back("glowStrength"); + mReservedUniforms.push_back("glowDelta"); + + llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_DELTA+1); + + + mReservedUniforms.push_back("minimum_alpha"); + mReservedUniforms.push_back("emissive_brightness"); + + mReservedUniforms.push_back("shadow_matrix"); + mReservedUniforms.push_back("env_mat"); + mReservedUniforms.push_back("shadow_clip"); + mReservedUniforms.push_back("sun_wash"); + mReservedUniforms.push_back("shadow_noise"); + mReservedUniforms.push_back("blur_size"); + mReservedUniforms.push_back("ssao_radius"); + mReservedUniforms.push_back("ssao_max_radius"); + mReservedUniforms.push_back("ssao_factor"); + mReservedUniforms.push_back("ssao_factor_inv"); + mReservedUniforms.push_back("ssao_effect_mat"); + mReservedUniforms.push_back("screen_res"); + mReservedUniforms.push_back("near_clip"); + mReservedUniforms.push_back("shadow_offset"); + mReservedUniforms.push_back("shadow_bias"); + mReservedUniforms.push_back("spot_shadow_bias"); + mReservedUniforms.push_back("spot_shadow_offset"); + mReservedUniforms.push_back("sun_dir"); mReservedUniforms.push_back("moon_dir"); - mReservedUniforms.push_back("shadow_res"); - mReservedUniforms.push_back("proj_shadow_res"); - mReservedUniforms.push_back("depth_cutoff"); - mReservedUniforms.push_back("norm_cutoff"); - mReservedUniforms.push_back("shadow_target_width"); - - llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH+1); - - mReservedUniforms.push_back("tc_scale"); - mReservedUniforms.push_back("rcp_screen_res"); - mReservedUniforms.push_back("rcp_frame_opt"); - mReservedUniforms.push_back("rcp_frame_opt2"); - - mReservedUniforms.push_back("focal_distance"); - mReservedUniforms.push_back("blur_constant"); - mReservedUniforms.push_back("tan_pixel_angle"); - mReservedUniforms.push_back("magnification"); - mReservedUniforms.push_back("max_cof"); - mReservedUniforms.push_back("res_scale"); - mReservedUniforms.push_back("dof_width"); - mReservedUniforms.push_back("dof_height"); - - mReservedUniforms.push_back("depthMap"); - mReservedUniforms.push_back("shadowMap0"); - mReservedUniforms.push_back("shadowMap1"); - mReservedUniforms.push_back("shadowMap2"); - mReservedUniforms.push_back("shadowMap3"); - mReservedUniforms.push_back("shadowMap4"); - mReservedUniforms.push_back("shadowMap5"); - - llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1); - - mReservedUniforms.push_back("normalMap"); - mReservedUniforms.push_back("positionMap"); - mReservedUniforms.push_back("diffuseRect"); - mReservedUniforms.push_back("specularRect"); - mReservedUniforms.push_back("noiseMap"); - mReservedUniforms.push_back("lightFunc"); - mReservedUniforms.push_back("lightMap"); - mReservedUniforms.push_back("bloomMap"); - mReservedUniforms.push_back("projectionMap"); - mReservedUniforms.push_back("norm_mat"); - - mReservedUniforms.push_back("global_gamma"); - mReservedUniforms.push_back("texture_gamma"); - - mReservedUniforms.push_back("specular_color"); - mReservedUniforms.push_back("env_intensity"); - - mReservedUniforms.push_back("matrixPalette"); - mReservedUniforms.push_back("translationPalette"); - - mReservedUniforms.push_back("screenTex"); - mReservedUniforms.push_back("screenDepth"); - mReservedUniforms.push_back("refTex"); - mReservedUniforms.push_back("eyeVec"); - mReservedUniforms.push_back("time"); - mReservedUniforms.push_back("waveDir1"); - mReservedUniforms.push_back("waveDir2"); - 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"); - mReservedUniforms.push_back("display_gamma"); + mReservedUniforms.push_back("shadow_res"); + mReservedUniforms.push_back("proj_shadow_res"); + mReservedUniforms.push_back("depth_cutoff"); + mReservedUniforms.push_back("norm_cutoff"); + mReservedUniforms.push_back("shadow_target_width"); + + llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH+1); + + mReservedUniforms.push_back("tc_scale"); + mReservedUniforms.push_back("rcp_screen_res"); + mReservedUniforms.push_back("rcp_frame_opt"); + mReservedUniforms.push_back("rcp_frame_opt2"); + + mReservedUniforms.push_back("focal_distance"); + mReservedUniforms.push_back("blur_constant"); + mReservedUniforms.push_back("tan_pixel_angle"); + mReservedUniforms.push_back("magnification"); + mReservedUniforms.push_back("max_cof"); + mReservedUniforms.push_back("res_scale"); + mReservedUniforms.push_back("dof_width"); + mReservedUniforms.push_back("dof_height"); + + mReservedUniforms.push_back("depthMap"); + mReservedUniforms.push_back("shadowMap0"); + mReservedUniforms.push_back("shadowMap1"); + mReservedUniforms.push_back("shadowMap2"); + mReservedUniforms.push_back("shadowMap3"); + mReservedUniforms.push_back("shadowMap4"); + mReservedUniforms.push_back("shadowMap5"); + + llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1); + + mReservedUniforms.push_back("normalMap"); + mReservedUniforms.push_back("positionMap"); + mReservedUniforms.push_back("diffuseRect"); + mReservedUniforms.push_back("specularRect"); + mReservedUniforms.push_back("noiseMap"); + mReservedUniforms.push_back("lightFunc"); + mReservedUniforms.push_back("lightMap"); + mReservedUniforms.push_back("bloomMap"); + mReservedUniforms.push_back("projectionMap"); + mReservedUniforms.push_back("norm_mat"); + + mReservedUniforms.push_back("global_gamma"); + mReservedUniforms.push_back("texture_gamma"); + + mReservedUniforms.push_back("specular_color"); + mReservedUniforms.push_back("env_intensity"); + + mReservedUniforms.push_back("matrixPalette"); + mReservedUniforms.push_back("translationPalette"); + + mReservedUniforms.push_back("screenTex"); + mReservedUniforms.push_back("screenDepth"); + mReservedUniforms.push_back("refTex"); + mReservedUniforms.push_back("eyeVec"); + mReservedUniforms.push_back("time"); + mReservedUniforms.push_back("waveDir1"); + mReservedUniforms.push_back("waveDir2"); + 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"); + mReservedUniforms.push_back("display_gamma"); mReservedUniforms.push_back("inscatter"); mReservedUniforms.push_back("sun_size"); @@ -1350,17 +1350,17 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sun_up_factor"); mReservedUniforms.push_back("moonlight_color"); - llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); - std::set dupe_check; + std::set dupe_check; - for (U32 i = 0; i < mReservedUniforms.size(); ++i) - { - if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end()) - { - LL_ERRS() << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << LL_ENDL; - } - dupe_check.insert(mReservedUniforms[i]); - } + for (U32 i = 0; i < mReservedUniforms.size(); ++i) + { + if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end()) + { + LL_ERRS() << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << LL_ENDL; + } + dupe_check.insert(mReservedUniforms[i]); + } } -- cgit v1.2.3 From 15270f697a0e6a4f14944ac20382f8bbcc8ea86b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 12 Mar 2019 10:52:00 -0700 Subject: Tab restoration project. 'warn-on-failure:no-tabs' --- indra/llrender/llglslshader.cpp | 258 ++--- indra/llrender/llglslshader.h | 338 +++--- indra/llrender/llshadermgr.cpp | 2304 +++++++++++++++++++-------------------- 3 files changed, 1449 insertions(+), 1451 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 5659bd327b..9a4eeb59df 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -724,144 +724,144 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type) BOOL LLGLSLShader::mapUniforms(const vector * uniforms) { - BOOL res = TRUE; - - mTotalUniformSize = 0; - mActiveTextureChannels = 0; - mUniform.clear(); - mUniformMap.clear(); - mUniformNameMap.clear(); - mTexture.clear(); - mValue.clear(); - //initialize arrays - U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); - mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); - - bind(); - - //get the number of active uniforms - GLint activeCount; - glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); - - //........................................................................................................................................ - //........................................................................................ - - /* - EXPLANATION: - This is part of code is temporary because as the final result the mapUniform() should be rewrited. - But it's a huge a volume of work which is need to be a more carefully performed for avoid possible - regression's (i.e. it should be formalized a separate ticket in JIRA). - - RESON: - The reason of this code is that SL engine is very sensitive to fact that "diffuseMap" should be appear - first as uniform parameter which is should get 0-"texture channel" index (see mapUniformTextureChannel() and mActiveTextureChannels) - it influence to which is texture matrix will be updated during rendering. - - But, order of indexe's of uniform variables is not defined and GLSL compiler can change it as want - , even if the "diffuseMap" will be appear and use first in shader code. - - As example where this situation appear see: "Deferred Material Shader 28/29/30/31" - And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 - */ - - - S32 diffuseMap = glGetUniformLocationARB(mProgramObject, "diffuseMap"); - S32 specularMap = glGetUniformLocationARB(mProgramObject, "specularMap"); - S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); + BOOL res = TRUE; + + mTotalUniformSize = 0; + mActiveTextureChannels = 0; + mUniform.clear(); + mUniformMap.clear(); + mUniformNameMap.clear(); + mTexture.clear(); + mValue.clear(); + //initialize arrays + U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); + mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); + + bind(); + + //get the number of active uniforms + GLint activeCount; + glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); + + //........................................................................................................................................ + //........................................................................................ + + /* + EXPLANATION: + This is part of code is temporary because as the final result the mapUniform() should be rewrited. + But it's a huge a volume of work which is need to be a more carefully performed for avoid possible + regression's (i.e. it should be formalized a separate ticket in JIRA). + + RESON: + The reason of this code is that SL engine is very sensitive to fact that "diffuseMap" should be appear + first as uniform parameter which is should get 0-"texture channel" index (see mapUniformTextureChannel() and mActiveTextureChannels) + it influence to which is texture matrix will be updated during rendering. + + But, order of indexe's of uniform variables is not defined and GLSL compiler can change it as want + , even if the "diffuseMap" will be appear and use first in shader code. + + As example where this situation appear see: "Deferred Material Shader 28/29/30/31" + And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437 + */ + + + S32 diffuseMap = glGetUniformLocationARB(mProgramObject, "diffuseMap"); + S32 specularMap = glGetUniformLocationARB(mProgramObject, "specularMap"); + S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap"); S32 altDiffuseMap = glGetUniformLocationARB(mProgramObject, "altDiffuseMap"); - S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); + S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap"); - std::set skip_index; + std::set skip_index; - if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) - { - GLenum type; - GLsizei length; - GLint size = -1; - char name[1024]; + if (-1 != diffuseMap && (-1 != specularMap || -1 != bumpMap || -1 != environmentMap || -1 != altDiffuseMap)) + { + GLenum type; + GLsizei length; + GLint size = -1; + char name[1024]; - diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; + diffuseMap = altDiffuseMap = specularMap = bumpMap = environmentMap = -1; - for (S32 i = 0; i < activeCount; i++) - { - name[0] = '\0'; + for (S32 i = 0; i < activeCount; i++) + { + name[0] = '\0'; - glGetActiveUniformARB(mProgramObject, i, 1024, &length, &size, &type, (GLcharARB *)name); + glGetActiveUniformARB(mProgramObject, i, 1024, &length, &size, &type, (GLcharARB *)name); - if (-1 == diffuseMap && std::string(name) == "diffuseMap") - { - diffuseMap = i; - continue; - } + if (-1 == diffuseMap && std::string(name) == "diffuseMap") + { + diffuseMap = i; + continue; + } - if (-1 == specularMap && std::string(name) == "specularMap") - { - specularMap = i; - continue; - } + if (-1 == specularMap && std::string(name) == "specularMap") + { + specularMap = i; + continue; + } - if (-1 == bumpMap && std::string(name) == "bumpMap") - { - bumpMap = i; - continue; - } + if (-1 == bumpMap && std::string(name) == "bumpMap") + { + bumpMap = i; + continue; + } - if (-1 == environmentMap && std::string(name) == "environmentMap") - { - environmentMap = i; - continue; - } + if (-1 == environmentMap && std::string(name) == "environmentMap") + { + environmentMap = i; + continue; + } if (-1 == altDiffuseMap && std::string(name) == "altDiffuseMap") - { - altDiffuseMap = i; - continue; - } - } + { + altDiffuseMap = i; + continue; + } + } - bool specularDiff = specularMap < diffuseMap && -1 != specularMap; - bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; - bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; + bool specularDiff = specularMap < diffuseMap && -1 != specularMap; + bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap; + bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap; - if (specularDiff || bumpLessDiff || envLessDiff) - { - mapUniform(diffuseMap, uniforms); - skip_index.insert(diffuseMap); + if (specularDiff || bumpLessDiff || envLessDiff) + { + mapUniform(diffuseMap, uniforms); + skip_index.insert(diffuseMap); - if (-1 != specularMap) { - mapUniform(specularMap, uniforms); - skip_index.insert(specularMap); - } + if (-1 != specularMap) { + mapUniform(specularMap, uniforms); + skip_index.insert(specularMap); + } - if (-1 != bumpMap) { - mapUniform(bumpMap, uniforms); - skip_index.insert(bumpMap); - } + if (-1 != bumpMap) { + mapUniform(bumpMap, uniforms); + skip_index.insert(bumpMap); + } - if (-1 != environmentMap) { - mapUniform(environmentMap, uniforms); - skip_index.insert(environmentMap); - } - } - } + if (-1 != environmentMap) { + mapUniform(environmentMap, uniforms); + skip_index.insert(environmentMap); + } + } + } - //........................................................................................ + //........................................................................................ - for (S32 i = 0; i < activeCount; i++) - { - //........................................................................................ - if (skip_index.end() != skip_index.find(i)) continue; - //........................................................................................ + for (S32 i = 0; i < activeCount; i++) + { + //........................................................................................ + if (skip_index.end() != skip_index.find(i)) continue; + //........................................................................................ - mapUniform(i, uniforms); - } - //........................................................................................................................................ + mapUniform(i, uniforms); + } + //........................................................................................................................................ - unbind(); + unbind(); - LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; - return res; + LL_DEBUGS("ShaderUniform") << "Total Uniform Size: " << mTotalUniformSize << LL_ENDL; + return res; } @@ -1286,19 +1286,19 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v) { - 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); - } - } + 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) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 9c3effadbe..830bad2aef 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -34,201 +34,199 @@ class LLShaderFeatures { public: - bool atmosphericHelpers; - bool calculatesLighting; - bool calculatesAtmospherics; - bool hasLighting; // implies no transport (it's possible to have neither though) - bool isAlphaLighting; // indicates lighting shaders need not be linked in (lighting performed directly in alpha shader to match deferred lighting functions) - bool isShiny; - bool isFullbright; // implies no lighting - bool isSpecular; - bool hasWaterFog; // implies no gamma - bool hasTransport; // implies no lighting (it's possible to have neither though) - bool hasSkinning; - bool hasObjectSkinning; - bool hasAtmospherics; - bool hasGamma; + bool atmosphericHelpers; + bool calculatesLighting; + bool calculatesAtmospherics; + bool hasLighting; // implies no transport (it's possible to have neither though) + bool isAlphaLighting; // indicates lighting shaders need not be linked in (lighting performed directly in alpha shader to match deferred lighting functions) + bool isShiny; + bool isFullbright; // implies no lighting + bool isSpecular; + bool hasWaterFog; // implies no gamma + bool hasTransport; // implies no lighting (it's possible to have neither though) + bool hasSkinning; + bool hasObjectSkinning; + bool hasAtmospherics; + bool hasGamma; bool hasShadows; bool hasAmbientOcclusion; - bool hasSrgb; + bool hasSrgb; bool encodesNormal; bool isDeferred; bool hasIndirect; - S32 mIndexedTextureChannels; - bool disableTextureIndex; - bool hasAlphaMask; - bool attachNothing; - - // char numLights; - - LLShaderFeatures(); + S32 mIndexedTextureChannels; + bool disableTextureIndex; + bool hasAlphaMask; + bool attachNothing; + + // char numLights; + + LLShaderFeatures(); }; class LLGLSLShader { public: - enum - { - SG_DEFAULT = 0, - SG_SKY, - SG_WATER - }; - - static std::set sInstances; - static bool sProfileEnabled; - - LLGLSLShader(); - ~LLGLSLShader(); - - static GLhandleARB sCurBoundShader; - static LLGLSLShader* sCurBoundShaderPtr; - static S32 sIndexedTextureChannels; - static bool sNoFixedFunction; - - static void initProfile(); - static void finishProfile(bool emit_report = true); - - static void startProfile(); - static void stopProfile(U32 count, U32 mode); - - void unload(); - void clearStats(); - void dumpStats(); - void placeProfileQuery(); - void readProfileQuery(U32 count, U32 mode); - - BOOL createShader(std::vector * attributes, - std::vector * 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 * 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); - - 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(U32 index); - - GLint getAttribLocation(U32 attrib); - GLint mapUniformTextureChannel(GLint location, GLenum type); - + enum + { + SG_DEFAULT = 0, + SG_SKY, + SG_WATER + }; + + static std::set sInstances; + static bool sProfileEnabled; + + LLGLSLShader(); + ~LLGLSLShader(); + + static GLhandleARB sCurBoundShader; + static LLGLSLShader* sCurBoundShaderPtr; + static S32 sIndexedTextureChannels; + static bool sNoFixedFunction; + + static void initProfile(); + static void finishProfile(bool emit_report = true); + + static void startProfile(); + static void stopProfile(U32 count, U32 mode); + + void unload(); + void clearStats(); + void dumpStats(); + void placeProfileQuery(); + void readProfileQuery(U32 count, U32 mode); + + BOOL createShader(std::vector * attributes, + std::vector * 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 * 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); + + 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(U32 index); + + GLint getAttribLocation(U32 attrib); + GLint mapUniformTextureChannel(GLint location, GLenum type); + void clearPermutations(); - 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 - //returns channel texture is enabled in from [0-MAX) - 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); - + 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 + //returns channel texture is enabled in from [0-MAX) + 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(); + void bind(); + void unbind(); - // Unbinds any previously bound shader by explicitly binding no shader. - static void bindNoShader(void); + // Unbinds any previously bound shader by explicitly binding no shader. + static void bindNoShader(void); - U32 mMatHash[LLRender::NUM_MATRIX_MODES]; - U32 mLightHash; + U32 mMatHash[LLRender::NUM_MATRIX_MODES]; + U32 mLightHash; - GLhandleARB mProgramObject; + GLhandleARB mProgramObject; #if LL_RELEASE_WITH_DEBUG_INFO - struct attr_name - { - GLint loc; - const char *name; - void operator = (GLint _loc) { loc = _loc; } - operator GLint () { return loc; } - }; - std::vector mAttribute; //lookup table of attribute enum to attribute channel + struct attr_name + { + GLint loc; + const char *name; + void operator = (GLint _loc) { loc = _loc; } + operator GLint () { return loc; } + }; + std::vector mAttribute; //lookup table of attribute enum to attribute channel #else - std::vector mAttribute; //lookup table of attribute enum to attribute channel + std::vector mAttribute; //lookup table of attribute enum to attribute channel #endif - 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; - S32 mTotalUniformSize; - S32 mActiveTextureChannels; - S32 mShaderLevel; - S32 mShaderGroup; - BOOL mUniformsDirty; - LLShaderFeatures mFeatures; - std::vector< std::pair< std::string, GLenum > > mShaderFiles; - std::string mName; - boost::unordered_map mDefines; - - //statistcis for profiling shader performance - U32 mTimerQuery; - U32 mSamplesQuery; - U64 mTimeElapsed; - static U64 sTotalTimeElapsed; - U32 mTrianglesDrawn; - static U32 sTotalTrianglesDrawn; - U64 mSamplesDrawn; - static U64 sTotalSamplesDrawn; - U32 mDrawCalls; - static U32 sTotalDrawCalls; - - bool mTextureStateFetched; - std::vector mTextureMagFilter; - std::vector mTextureMinFilter; - - GLhandleARB mExtraLinkObject = 0; + 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; + S32 mTotalUniformSize; + S32 mActiveTextureChannels; + S32 mShaderLevel; + S32 mShaderGroup; + BOOL mUniformsDirty; + LLShaderFeatures mFeatures; + std::vector< std::pair< std::string, GLenum > > mShaderFiles; + std::string mName; + boost::unordered_map mDefines; + + //statistcis for profiling shader performance + U32 mTimerQuery; + U32 mSamplesQuery; + U64 mTimeElapsed; + static U64 sTotalTimeElapsed; + U32 mTrianglesDrawn; + static U32 sTotalTrianglesDrawn; + U64 mSamplesDrawn; + static U64 sTotalSamplesDrawn; + U32 mDrawCalls; + static U32 sTotalDrawCalls; + + bool mTextureStateFetched; + std::vector mTextureMagFilter; + std::vector mTextureMinFilter; private: - void unloadInternal(); + void unloadInternal(); }; //UI shader (declared here so llui_libtest will link properly) -extern LLGLSLShader gUIProgram; +extern LLGLSLShader gUIProgram; //output vec4(color.rgb,color.a*tex0[tc0].a) -extern LLGLSLShader gSolidColorProgram; +extern LLGLSLShader gSolidColorProgram; //Alpha mask shader (declared here so llappearance can access properly) -extern LLGLSLShader gAlphaMaskProgram; +extern LLGLSLShader gAlphaMaskProgram; #endif diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 5b96667f9f..ec8f05e4ca 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -53,489 +53,489 @@ LLShaderMgr::~LLShaderMgr() // static LLShaderMgr * LLShaderMgr::instance() { - if(NULL == sInstance) - { - LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL; - } + if(NULL == sInstance) + { + LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL; + } - return sInstance; + return sInstance; } BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { - llassert_always(shader != NULL); - LLShaderFeatures *features = & shader->mFeatures; - - if (features->attachNothing) - { - return TRUE; - } - ////////////////////////////////////// - // Attach Vertex Shader Features First - ////////////////////////////////////// - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->calculatesAtmospherics) - { - if (features->hasWaterFog) - { - if (!shader->attachObject("windlight/atmosphericsVarsWaterV.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("windlight/atmosphericsVarsV.glsl")) - { - return FALSE; - } - } - - if (features->calculatesLighting || features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) - { - return FALSE; - } - } - - if (features->calculatesLighting) - { - if (features->isSpecular) - { - if (!shader->attachObject("lighting/lightFuncSpecularV.glsl")) - { - return FALSE; - } - - if (!features->isAlphaLighting) - { - if (!shader->attachObject("lighting/sumLightsSpecularV.glsl")) - { - return FALSE; - } - } - - if (!shader->attachObject("lighting/lightSpecularV.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFuncV.glsl")) - { - return FALSE; - } - - if (!features->isAlphaLighting) - { - if (!shader->attachObject("lighting/sumLightsV.glsl")) - { - return FALSE; - } - } - - if (!shader->attachObject("lighting/lightV.glsl")) - { - return FALSE; - } - } - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsV.glsl")) - { - return FALSE; - } - } - - if (features->hasSkinning) - { - if (!shader->attachObject("avatar/avatarSkinV.glsl")) - { - return FALSE; - } - } - - if (features->hasObjectSkinning) - { - if (!shader->attachObject("avatar/objectSkinV.glsl")) - { - return FALSE; - } - } - - /////////////////////////////////////// - // Attach Fragment Shader Features Next - /////////////////////////////////////// + llassert_always(shader != NULL); + LLShaderFeatures *features = & shader->mFeatures; + + if (features->attachNothing) + { + return TRUE; + } + ////////////////////////////////////// + // Attach Vertex Shader Features First + ////////////////////////////////////// + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->calculatesAtmospherics) + { + if (features->hasWaterFog) + { + if (!shader->attachObject("windlight/atmosphericsVarsWaterV.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("windlight/atmosphericsVarsV.glsl")) + { + return FALSE; + } + } + + if (features->calculatesLighting || features->calculatesAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) + { + return FALSE; + } + } + + if (features->calculatesLighting) + { + if (features->isSpecular) + { + if (!shader->attachObject("lighting/lightFuncSpecularV.glsl")) + { + return FALSE; + } + + if (!features->isAlphaLighting) + { + if (!shader->attachObject("lighting/sumLightsSpecularV.glsl")) + { + return FALSE; + } + } + + if (!shader->attachObject("lighting/lightSpecularV.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFuncV.glsl")) + { + return FALSE; + } + + if (!features->isAlphaLighting) + { + if (!shader->attachObject("lighting/sumLightsV.glsl")) + { + return FALSE; + } + } + + if (!shader->attachObject("lighting/lightV.glsl")) + { + return FALSE; + } + } + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->calculatesAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsV.glsl")) + { + return FALSE; + } + } + + if (features->hasSkinning) + { + if (!shader->attachObject("avatar/avatarSkinV.glsl")) + { + return FALSE; + } + } + + if (features->hasObjectSkinning) + { + if (!shader->attachObject("avatar/objectSkinV.glsl")) + { + return FALSE; + } + } + + /////////////////////////////////////// + // Attach Fragment Shader Features Next + /////////////////////////////////////// // NOTE order of shader object attaching is VERY IMPORTANT!!! - if(features->calculatesAtmospherics) - { - if (features->hasWaterFog) - { - if (!shader->attachObject("windlight/atmosphericsVarsWaterF.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("windlight/atmosphericsVarsF.glsl")) - { - return FALSE; - } - } + if(features->calculatesAtmospherics) + { + if (features->hasWaterFog) + { + if (!shader->attachObject("windlight/atmosphericsVarsWaterF.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("windlight/atmosphericsVarsF.glsl")) + { + return FALSE; + } + } if (features->calculatesLighting || features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) + { + return FALSE; + } + } // we want this BEFORE shadows and AO because those facilities use pos/norm access if (features->isDeferred) - { - if (!shader->attachObject("deferred/deferredUtil.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/deferredUtil.glsl")) + { + return FALSE; + } + } if (features->hasShadows) - { - if (!shader->attachObject("deferred/shadowUtil.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/shadowUtil.glsl")) + { + return FALSE; + } + } if (features->hasAmbientOcclusion) - { - if (!shader->attachObject("deferred/aoUtil.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/aoUtil.glsl")) + { + return FALSE; + } + } if (features->hasIndirect) - { - if (!shader->attachObject("deferred/indirect.glsl")) - { - return FALSE; - } - } - - if (features->hasGamma) - { - if (!shader->attachObject("windlight/gammaF.glsl")) - { - return FALSE; - } - } - - if (features->hasSrgb) - { - if (!shader->attachObject("environment/srgbF.glsl")) - { - return FALSE; - } - } + { + if (!shader->attachObject("deferred/indirect.glsl")) + { + return FALSE; + } + } + + if (features->hasGamma) + { + if (!shader->attachObject("windlight/gammaF.glsl")) + { + return FALSE; + } + } + + if (features->hasSrgb) + { + if (!shader->attachObject("environment/srgbF.glsl")) + { + return FALSE; + } + } if (features->encodesNormal) - { - if (!shader->attachObject("environment/encodeNormF.glsl")) - { - return FALSE; - } - } - - if (features->hasAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsF.glsl")) - { - return FALSE; - } - } - - if (features->hasTransport) - { - if (!shader->attachObject("windlight/transportF.glsl")) - { - return FALSE; - } - - // Test hasFullbright and hasShiny and attach fullbright and - // fullbright shiny atmos transport if we split them out. - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - if (features->hasWaterFog) - { - if (!shader->attachObject("environment/waterFogF.glsl")) - { - return FALSE; - } - } - - if (features->hasLighting) - { - if (features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightWaterAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightWaterF.glsl")) - { - return FALSE; - } - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else - { - if (features->disableTextureIndex) - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightAlphaMaskNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightNonIndexedF.glsl")) - { - return FALSE; - } - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightF.glsl")) - { - return FALSE; - } - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - else if (features->isFullbright) - { - - if (features->isShiny && features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightShinyWaterF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - else if (features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightWaterAlphaMaskF.glsl")) - { - return FALSE; - } - } - else if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else if (features->isShiny) - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightFullbrightShinyNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightShinyF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else - { - if (features->disableTextureIndex) - { - - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl")) - { - return FALSE; - } - } - } - else - { - if (features->hasAlphaMask) - { - if (!shader->attachObject("lighting/lightFullbrightAlphaMaskF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightFullbrightF.glsl")) - { - return FALSE; - } - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - } - - // NOTE order of shader object attaching is VERY IMPORTANT!!! - else if (features->isShiny) - { - - if (features->hasWaterFog) - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightShinyWaterNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightShinyWaterF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - - else - { - if (features->disableTextureIndex) - { - if (!shader->attachObject("lighting/lightShinyNonIndexedF.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("lighting/lightShinyF.glsl")) - { - return FALSE; - } - shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); - } - } - } - - if (features->mIndexedTextureChannels <= 1) - { - if (!shader->attachObject("objects/nonindexedTextureV.glsl")) - { - return FALSE; - } - } - else - { - if (!shader->attachObject("objects/indexedTextureV.glsl")) - { - return FALSE; - } - } - - return TRUE; + { + if (!shader->attachObject("environment/encodeNormF.glsl")) + { + return FALSE; + } + } + + if (features->hasAtmospherics) + { + if (!shader->attachObject("windlight/atmosphericsF.glsl")) + { + return FALSE; + } + } + + if (features->hasTransport) + { + if (!shader->attachObject("windlight/transportF.glsl")) + { + return FALSE; + } + + // Test hasFullbright and hasShiny and attach fullbright and + // fullbright shiny atmos transport if we split them out. + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + if (features->hasWaterFog) + { + if (!shader->attachObject("environment/waterFogF.glsl")) + { + return FALSE; + } + } + + if (features->hasLighting) + { + if (features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightWaterAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightWaterF.glsl")) + { + return FALSE; + } + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else + { + if (features->disableTextureIndex) + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightAlphaMaskNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightNonIndexedF.glsl")) + { + return FALSE; + } + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightF.glsl")) + { + return FALSE; + } + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + else if (features->isFullbright) + { + + if (features->isShiny && features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightShinyWaterF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + else if (features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightWaterAlphaMaskF.glsl")) + { + return FALSE; + } + } + else if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else if (features->isShiny) + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightFullbrightShinyNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightShinyF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else + { + if (features->disableTextureIndex) + { + + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl")) + { + return FALSE; + } + } + } + else + { + if (features->hasAlphaMask) + { + if (!shader->attachObject("lighting/lightFullbrightAlphaMaskF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightFullbrightF.glsl")) + { + return FALSE; + } + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + } + + // NOTE order of shader object attaching is VERY IMPORTANT!!! + else if (features->isShiny) + { + + if (features->hasWaterFog) + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightShinyWaterNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightShinyWaterF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + + else + { + if (features->disableTextureIndex) + { + if (!shader->attachObject("lighting/lightShinyNonIndexedF.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("lighting/lightShinyF.glsl")) + { + return FALSE; + } + shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels-1, 1); + } + } + } + + if (features->mIndexedTextureChannels <= 1) + { + if (!shader->attachObject("objects/nonindexedTextureV.glsl")) + { + return FALSE; + } + } + else + { + if (!shader->attachObject("objects/indexedTextureV.glsl")) + { + return FALSE; + } + } + + return TRUE; } //============================================================================ @@ -543,46 +543,46 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) static std::string get_object_log(GLhandleARB ret) { - std::string res; - - //get log length - GLint length; - glGetObjectParameterivARB(ret, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); - if (length > 0) - { - //the log could be any size, so allocate appropriately - GLcharARB* log = new GLcharARB[length]; - glGetInfoLogARB(ret, length, &length, log); - res = std::string((char *)log); - delete[] log; - } - return res; + std::string res; + + //get log length + GLint length; + glGetObjectParameterivARB(ret, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); + if (length > 0) + { + //the log could be any size, so allocate appropriately + GLcharARB* log = new GLcharARB[length]; + glGetInfoLogARB(ret, length, &length, log); + res = std::string((char *)log); + delete[] log; + } + return res; } //dump shader source for debugging void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text) -{ - for (GLuint i = 0; i < shader_code_count; i++) - { - LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; - } +{ + for (GLuint i = 0; i < shader_code_count; i++) + { + LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; + } LL_SHADER_LOADING_WARNS() << LL_ENDL; } void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename) { - std::string log = get_object_log(ret); + std::string log = get_object_log(ret); std::string fname = filename; if (filename.empty()) { fname = "unknown shader file"; } - if (log.length() > 0) - { + if (log.length() > 0) + { LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << ":\n" << LL_ENDL; LL_SHADER_LOADING_WARNS() << log << LL_ENDL; - } + } } GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, boost::unordered_map* defines, S32 texture_index_channels) @@ -596,38 +596,38 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } #endif - GLenum error = GL_NO_ERROR; - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; - } - } - - //LL_SHADER_LOADING_WARNS() << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; + GLenum error = GL_NO_ERROR; + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << LL_ENDL; + } + } + + //LL_SHADER_LOADING_WARNS() << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; - if (filename.empty()) - { - return 0; - } + if (filename.empty()) + { + return 0; + } - //read in from file - LLFILE* file = NULL; + //read in from file + LLFILE* file = NULL; - S32 try_gpu_class = shader_level; - S32 gpu_class; + S32 try_gpu_class = shader_level; + S32 gpu_class; std::string open_file_name; - //find the most relevant file - for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) - { //search from the current gpu class down to class 1 to find the most relevant shader - std::stringstream fname; - fname << getShaderDirPrefix(); - fname << gpu_class << "/" << filename; - + //find the most relevant file + for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--) + { //search from the current gpu class down to class 1 to find the most relevant shader + std::stringstream fname; + fname << getShaderDirPrefix(); + fname << gpu_class << "/" << filename; + open_file_name = fname.str(); /* @@ -643,23 +643,23 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade */ - LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL; - file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */ - if (file) - { - LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; - break; // done - } - } - - if (file == NULL) - { - LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << open_file_name << LL_ENDL; - return 0; - } - - //we can't have any lines longer than 1024 characters - //or any shaders longer than 4096 lines... deal - DaveP + LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL; + file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */ + if (file) + { + LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL; + break; // done + } + } + + if (file == NULL) + { + LL_SHADER_LOADING_WARNS() << "GLSL Shader file not found: " << open_file_name << LL_ENDL; + return 0; + } + + //we can't have any lines longer than 1024 characters + //or any shaders longer than 4096 lines... deal - DaveP GLcharARB buff[1024]; GLcharARB *extra_code_text[1024]; GLcharARB *shader_code_text[4096 + LL_ARRAY_SIZE(extra_code_text)] = { NULL }; @@ -667,661 +667,661 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade BOOST_STATIC_ASSERT(LL_ARRAY_SIZE(extra_code_text) < LL_ARRAY_SIZE(shader_code_text)); - S32 major_version = gGLManager.mGLSLVersionMajor; - S32 minor_version = gGLManager.mGLSLVersionMinor; - - if (major_version == 1 && minor_version < 30) - { - if (minor_version < 10) - { - //should NEVER get here -- if major version is 1 and minor version is less than 10, - // viewer should never attempt to use shaders, continuing will result in undefined behavior - LL_ERRS() << "Unsupported GLSL Version." << LL_ENDL; - } - - if (minor_version <= 19) - { - shader_code_text[shader_code_count++] = strdup("#version 110\n"); - extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); - } - else if (minor_version <= 29) - { - //set version to 1.20 - shader_code_text[shader_code_count++] = strdup("#version 120\n"); - extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_120 1\n"); - extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n"); - extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); - } - } - else - { - if (major_version < 4) - { - //set version to 1.30 - shader_code_text[shader_code_count++] = strdup("#version 130\n"); - //some implementations of GLSL 1.30 require integer precision be explicitly declared - extra_code_text[extra_code_count++] = strdup("precision mediump int;\n"); - extra_code_text[extra_code_count++] = strdup("precision highp float;\n"); - } - else - { //set version to 400 - shader_code_text[shader_code_count++] = strdup("#version 400\n"); - } - - extra_code_text[extra_code_count++] = strdup("#define DEFINE_GL_FRAGCOLOR 1\n"); - extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n"); - - extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE in\n"); - - if (type == GL_VERTEX_SHADER_ARB) - { //"varying" state is "out" in a vertex program, "in" in a fragment program - // ("varying" is deprecated after version 1.20) - extra_code_text[extra_code_count++] = strdup("#define VARYING out\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat out\n"); - } - else - { - extra_code_text[extra_code_count++] = strdup("#define VARYING in\n"); - extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat in\n"); - } - - //backwards compatibility with legacy texture lookup syntax - extra_code_text[extra_code_count++] = strdup("#define texture2D texture\n"); - extra_code_text[extra_code_count++] = strdup("#define textureCube texture\n"); - extra_code_text[extra_code_count++] = strdup("#define texture2DLod textureLod\n"); - extra_code_text[extra_code_count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); - - if (major_version > 1 || minor_version >= 40) - { //GLSL 1.40 replaces texture2DRect et al with texture - extra_code_text[extra_code_count++] = strdup("#define texture2DRect texture\n"); - extra_code_text[extra_code_count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); - } - } - - if (defines) - { - for (boost::unordered_map::iterator iter = defines->begin(); iter != defines->end(); ++iter) - { - std::string define = "#define " + iter->first + " " + iter->second + "\n"; - extra_code_text[extra_code_count++] = (GLcharARB *) strdup(define.c_str()); - } - } - - if( gGLManager.mIsATI ) - { - extra_code_text[extra_code_count++] = strdup( "#define IS_AMD_CARD 1\n" ); - } - - if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER_ARB) - { - //use specified number of texture channels for indexed texture rendering - - /* prepend shader code that looks like this: - - uniform sampler2D tex0; - uniform sampler2D tex1; - uniform sampler2D tex2; - . - . - . - uniform sampler2D texN; - - VARYING_FLAT ivec4 vary_texture_index; - - vec4 ret = vec4(1,0,1,1); - - vec4 diffuseLookup(vec2 texcoord) - { - switch (vary_texture_index.r)) - { - case 0: ret = texture2D(tex0, texcoord); break; - case 1: ret = texture2D(tex1, texcoord); break; - case 2: ret = texture2D(tex2, texcoord); break; - . - . - . - case N: return texture2D(texN, texcoord); break; - } - - return ret; - } - */ - - extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n"); - - //uniform declartion - for (S32 i = 0; i < texture_index_channels; ++i) - { - std::string decl = llformat("uniform sampler2D tex%d;\n", i); - extra_code_text[extra_code_count++] = strdup(decl.c_str()); - } - - if (texture_index_channels > 1) - { - extra_code_text[extra_code_count++] = strdup("VARYING_FLAT int vary_texture_index;\n"); - } - - extra_code_text[extra_code_count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); - extra_code_text[extra_code_count++] = strdup("{\n"); - - - if (texture_index_channels == 1) - { //don't use flow control, that's silly - extra_code_text[extra_code_count++] = strdup("return texture2D(tex0, texcoord);\n"); - extra_code_text[extra_code_count++] = strdup("}\n"); - } - else if (major_version > 1 || minor_version >= 30) - { //switches are supported in GLSL 1.30 and later - if (gGLManager.mIsNVIDIA) - { //switches are unreliable on some NVIDIA drivers - for (U32 i = 0; i < texture_index_channels; ++i) - { - std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture2D(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i); - extra_code_text[extra_code_count++] = strdup(if_string.c_str()); - } - extra_code_text[extra_code_count++] = strdup("\treturn vec4(1,0,1,1);\n"); - extra_code_text[extra_code_count++] = strdup("}\n"); - } - else - { - extra_code_text[extra_code_count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); - extra_code_text[extra_code_count++] = strdup("\tswitch (vary_texture_index)\n"); - extra_code_text[extra_code_count++] = strdup("\t{\n"); - - //switch body - for (S32 i = 0; i < texture_index_channels; ++i) - { - std::string case_str = llformat("\t\tcase %d: return texture2D(tex%d, texcoord);\n", i, i); - extra_code_text[extra_code_count++] = strdup(case_str.c_str()); - } - - extra_code_text[extra_code_count++] = strdup("\t}\n"); - extra_code_text[extra_code_count++] = strdup("\treturn ret;\n"); - extra_code_text[extra_code_count++] = strdup("}\n"); - } - } - else - { //should never get here. Indexed texture rendering requires GLSL 1.30 or later - // (for passing integers between vertex and fragment shaders) - LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL; - } - } - - //copy file into memory - enum { - flag_write_to_out_of_extra_block_area = 0x01 - , flag_extra_block_marker_was_found = 0x02 - }; - - unsigned char flags = flag_write_to_out_of_extra_block_area; - - GLuint out_of_extra_block_counter = 0, start_shader_code = shader_code_count, file_lines_count = 0; + S32 major_version = gGLManager.mGLSLVersionMajor; + S32 minor_version = gGLManager.mGLSLVersionMinor; + + if (major_version == 1 && minor_version < 30) + { + if (minor_version < 10) + { + //should NEVER get here -- if major version is 1 and minor version is less than 10, + // viewer should never attempt to use shaders, continuing will result in undefined behavior + LL_ERRS() << "Unsupported GLSL Version." << LL_ENDL; + } + + if (minor_version <= 19) + { + shader_code_text[shader_code_count++] = strdup("#version 110\n"); + extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); + } + else if (minor_version <= 29) + { + //set version to 1.20 + shader_code_text[shader_code_count++] = strdup("#version 120\n"); + extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_120 1\n"); + extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n"); + extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n"); + } + } + else + { + if (major_version < 4) + { + //set version to 1.30 + shader_code_text[shader_code_count++] = strdup("#version 130\n"); + //some implementations of GLSL 1.30 require integer precision be explicitly declared + extra_code_text[extra_code_count++] = strdup("precision mediump int;\n"); + extra_code_text[extra_code_count++] = strdup("precision highp float;\n"); + } + else + { //set version to 400 + shader_code_text[shader_code_count++] = strdup("#version 400\n"); + } + + extra_code_text[extra_code_count++] = strdup("#define DEFINE_GL_FRAGCOLOR 1\n"); + extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n"); + + extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE in\n"); + + if (type == GL_VERTEX_SHADER_ARB) + { //"varying" state is "out" in a vertex program, "in" in a fragment program + // ("varying" is deprecated after version 1.20) + extra_code_text[extra_code_count++] = strdup("#define VARYING out\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat out\n"); + } + else + { + extra_code_text[extra_code_count++] = strdup("#define VARYING in\n"); + extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT flat in\n"); + } + + //backwards compatibility with legacy texture lookup syntax + extra_code_text[extra_code_count++] = strdup("#define texture2D texture\n"); + extra_code_text[extra_code_count++] = strdup("#define textureCube texture\n"); + extra_code_text[extra_code_count++] = strdup("#define texture2DLod textureLod\n"); + extra_code_text[extra_code_count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); + + if (major_version > 1 || minor_version >= 40) + { //GLSL 1.40 replaces texture2DRect et al with texture + extra_code_text[extra_code_count++] = strdup("#define texture2DRect texture\n"); + extra_code_text[extra_code_count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); + } + } + + if (defines) + { + for (boost::unordered_map::iterator iter = defines->begin(); iter != defines->end(); ++iter) + { + std::string define = "#define " + iter->first + " " + iter->second + "\n"; + extra_code_text[extra_code_count++] = (GLcharARB *) strdup(define.c_str()); + } + } + + if( gGLManager.mIsATI ) + { + extra_code_text[extra_code_count++] = strdup( "#define IS_AMD_CARD 1\n" ); + } + + if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER_ARB) + { + //use specified number of texture channels for indexed texture rendering + + /* prepend shader code that looks like this: + + uniform sampler2D tex0; + uniform sampler2D tex1; + uniform sampler2D tex2; + . + . + . + uniform sampler2D texN; + + VARYING_FLAT ivec4 vary_texture_index; + + vec4 ret = vec4(1,0,1,1); + + vec4 diffuseLookup(vec2 texcoord) + { + switch (vary_texture_index.r)) + { + case 0: ret = texture2D(tex0, texcoord); break; + case 1: ret = texture2D(tex1, texcoord); break; + case 2: ret = texture2D(tex2, texcoord); break; + . + . + . + case N: return texture2D(texN, texcoord); break; + } + + return ret; + } + */ + + extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n"); + + //uniform declartion + for (S32 i = 0; i < texture_index_channels; ++i) + { + std::string decl = llformat("uniform sampler2D tex%d;\n", i); + extra_code_text[extra_code_count++] = strdup(decl.c_str()); + } + + if (texture_index_channels > 1) + { + extra_code_text[extra_code_count++] = strdup("VARYING_FLAT int vary_texture_index;\n"); + } + + extra_code_text[extra_code_count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); + extra_code_text[extra_code_count++] = strdup("{\n"); + + + if (texture_index_channels == 1) + { //don't use flow control, that's silly + extra_code_text[extra_code_count++] = strdup("return texture2D(tex0, texcoord);\n"); + extra_code_text[extra_code_count++] = strdup("}\n"); + } + else if (major_version > 1 || minor_version >= 30) + { //switches are supported in GLSL 1.30 and later + if (gGLManager.mIsNVIDIA) + { //switches are unreliable on some NVIDIA drivers + for (U32 i = 0; i < texture_index_channels; ++i) + { + std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture2D(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i); + extra_code_text[extra_code_count++] = strdup(if_string.c_str()); + } + extra_code_text[extra_code_count++] = strdup("\treturn vec4(1,0,1,1);\n"); + extra_code_text[extra_code_count++] = strdup("}\n"); + } + else + { + extra_code_text[extra_code_count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); + extra_code_text[extra_code_count++] = strdup("\tswitch (vary_texture_index)\n"); + extra_code_text[extra_code_count++] = strdup("\t{\n"); + + //switch body + for (S32 i = 0; i < texture_index_channels; ++i) + { + std::string case_str = llformat("\t\tcase %d: return texture2D(tex%d, texcoord);\n", i, i); + extra_code_text[extra_code_count++] = strdup(case_str.c_str()); + } + + extra_code_text[extra_code_count++] = strdup("\t}\n"); + extra_code_text[extra_code_count++] = strdup("\treturn ret;\n"); + extra_code_text[extra_code_count++] = strdup("}\n"); + } + } + else + { //should never get here. Indexed texture rendering requires GLSL 1.30 or later + // (for passing integers between vertex and fragment shaders) + LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL; + } + } - while(NULL != fgets((char *)buff, 1024, file) - && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text))) - { - file_lines_count++; - - bool extra_block_area_found = NULL != strstr((const char*)buff, "[EXTRA_CODE_HERE]"); - - if(extra_block_area_found && !(flag_extra_block_marker_was_found & flags)) - { - if(!(flag_write_to_out_of_extra_block_area & flags)) - { - //shift - for(GLuint to = start_shader_code, from = extra_code_count + start_shader_code; - from < shader_code_count; ++to, ++from) - { - shader_code_text[to] = shader_code_text[from]; - } - - shader_code_count -= extra_code_count; - } - - //copy extra code - for(GLuint n = 0; n < extra_code_count - && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)); ++n) - { - shader_code_text[shader_code_count++] = extra_code_text[n]; - } - - extra_code_count = 0; - - flags &= ~flag_write_to_out_of_extra_block_area; - flags |= flag_extra_block_marker_was_found; - } + //copy file into memory + enum { + flag_write_to_out_of_extra_block_area = 0x01 + , flag_extra_block_marker_was_found = 0x02 + }; + + unsigned char flags = flag_write_to_out_of_extra_block_area; + + GLuint out_of_extra_block_counter = 0, start_shader_code = shader_code_count, file_lines_count = 0; + + while(NULL != fgets((char *)buff, 1024, file) + && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text))) + { + file_lines_count++; + + bool extra_block_area_found = NULL != strstr((const char*)buff, "[EXTRA_CODE_HERE]"); + + if(extra_block_area_found && !(flag_extra_block_marker_was_found & flags)) + { + if(!(flag_write_to_out_of_extra_block_area & flags)) + { + //shift + for(GLuint to = start_shader_code, from = extra_code_count + start_shader_code; + from < shader_code_count; ++to, ++from) + { + shader_code_text[to] = shader_code_text[from]; + } + + shader_code_count -= extra_code_count; + } + + //copy extra code + for(GLuint n = 0; n < extra_code_count + && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)); ++n) + { + shader_code_text[shader_code_count++] = extra_code_text[n]; + } + + extra_code_count = 0; + + flags &= ~flag_write_to_out_of_extra_block_area; + flags |= flag_extra_block_marker_was_found; + } else { shader_code_text[shader_code_count] = (GLcharARB *)strdup((char *)buff); - + if(flag_write_to_out_of_extra_block_area & flags) { shader_code_text[extra_code_count + start_shader_code + out_of_extra_block_counter] = shader_code_text[shader_code_count]; out_of_extra_block_counter++; - + if(out_of_extra_block_counter == extra_code_count) { shader_code_count += extra_code_count; flags &= ~flag_write_to_out_of_extra_block_area; } } - + ++shader_code_count; - } - } //while - - if(!(flag_extra_block_marker_was_found & flags)) - { - for(GLuint n = start_shader_code; n < extra_code_count + start_shader_code; ++n) - { - shader_code_text[n] = extra_code_text[n - start_shader_code]; - } - - if (file_lines_count < extra_code_count) - { - shader_code_count += extra_code_count; - } - - extra_code_count = 0; - } - - fclose(file); - - //create shader object - GLhandleARB ret = glCreateShaderObjectARB(type); - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShaderObjectARB: " << error << LL_ENDL; - } - } - - //load source - glShaderSourceARB(ret, shader_code_count, (const GLcharARB**) shader_code_text, NULL); - - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL; - } - } - - //compile source - glCompileShaderARB(ret); - - if (gDebugGL) - { - error = glGetError(); - if (error != GL_NO_ERROR) - { - LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL; - } - } - - if (error == GL_NO_ERROR) - { - //check for errors - GLint success = GL_TRUE; - glGetObjectParameterivARB(ret, GL_OBJECT_COMPILE_STATUS_ARB, &success); - if (gDebugGL || success == GL_FALSE) - { - error = glGetError(); - if (error != GL_NO_ERROR || success == GL_FALSE) - { - //an error occured, print log - LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL; - dumpObjectLog(ret, TRUE, open_file_name); + } + } //while + + if(!(flag_extra_block_marker_was_found & flags)) + { + for(GLuint n = start_shader_code; n < extra_code_count + start_shader_code; ++n) + { + shader_code_text[n] = extra_code_text[n - start_shader_code]; + } + + if (file_lines_count < extra_code_count) + { + shader_code_count += extra_code_count; + } + + extra_code_count = 0; + } + + fclose(file); + + //create shader object + GLhandleARB ret = glCreateShaderObjectARB(type); + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShaderObjectARB: " << error << LL_ENDL; + } + } + + //load source + glShaderSourceARB(ret, shader_code_count, (const GLcharARB**) shader_code_text, NULL); + + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL; + } + } + + //compile source + glCompileShaderARB(ret); + + if (gDebugGL) + { + error = glGetError(); + if (error != GL_NO_ERROR) + { + LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL; + } + } + + if (error == GL_NO_ERROR) + { + //check for errors + GLint success = GL_TRUE; + glGetObjectParameterivARB(ret, GL_OBJECT_COMPILE_STATUS_ARB, &success); + if (gDebugGL || success == GL_FALSE) + { + error = glGetError(); + if (error != GL_NO_ERROR || success == GL_FALSE) + { + //an error occured, print log + LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL; + dumpObjectLog(ret, TRUE, open_file_name); dumpShaderSource(shader_code_count, shader_code_text); - ret = 0; - } - } - } - else - { - ret = 0; - } - stop_glerror(); - - //free memory - for (GLuint i = 0; i < shader_code_count; i++) - { - free(shader_code_text[i]); - } - - //successfully loaded, save results - if (ret) - { - // Add shader file to map - mShaderObjects[filename] = ret; - shader_level = try_gpu_class; - } - else - { - if (shader_level > 1) - { - shader_level--; - return loadShaderFile(filename, shader_level, type, defines, texture_index_channels); - } - LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; - } - return ret; + ret = 0; + } + } + } + else + { + ret = 0; + } + stop_glerror(); + + //free memory + for (GLuint i = 0; i < shader_code_count; i++) + { + free(shader_code_text[i]); + } + + //successfully loaded, save results + if (ret) + { + // Add shader file to map + mShaderObjects[filename] = ret; + shader_level = try_gpu_class; + } + else + { + if (shader_level > 1) + { + shader_level--; + return loadShaderFile(filename, shader_level, type, defines, texture_index_channels); + } + LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; + } + return ret; } BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) { - //check for errors - glLinkProgramARB(obj); - GLint success = GL_TRUE; - glGetObjectParameterivARB(obj, GL_OBJECT_LINK_STATUS_ARB, &success); - if (!suppress_errors && success == GL_FALSE) - { - //an error occured, print log - LL_SHADER_LOADING_WARNS() << "GLSL Linker Error:" << LL_ENDL; - } + //check for errors + glLinkProgramARB(obj); + GLint success = GL_TRUE; + glGetObjectParameterivARB(obj, GL_OBJECT_LINK_STATUS_ARB, &success); + if (!suppress_errors && success == GL_FALSE) + { + //an error occured, print log + LL_SHADER_LOADING_WARNS() << "GLSL Linker Error:" << LL_ENDL; + } #if LL_DARWIN - // For some reason this absolutely kills the frame rate when VBO's are enabled - if (0) - { - // Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software - // per Apple's suggestion - LLGLSLShader::sNoFixedFunction = false; - - glUseProgramObjectARB(obj); - - gGL.begin(LLRender::TRIANGLES); - gGL.vertex3f(0.0f, 0.0f, 0.0f); - gGL.vertex3f(0.0f, 0.0f, 0.0f); - gGL.vertex3f(0.0f, 0.0f, 0.0f); - gGL.end(); - gGL.flush(); - - glUseProgramObjectARB(0); - - LLGLSLShader::sNoFixedFunction = true; - - // Query whether the shader can or cannot run in hardware - // http://developer.apple.com/qa/qa2007/qa1502.html - GLint vertexGPUProcessing, fragmentGPUProcessing; - CGLContextObj ctx = CGLGetCurrentContext(); - CGLGetParameter(ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing); - CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); - if (!fragmentGPUProcessing || !vertexGPUProcessing) - { - LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; - success = GL_FALSE; - suppress_errors = FALSE; - } - } + // For some reason this absolutely kills the frame rate when VBO's are enabled + if (0) + { + // Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software + // per Apple's suggestion + LLGLSLShader::sNoFixedFunction = false; + + glUseProgramObjectARB(obj); + + gGL.begin(LLRender::TRIANGLES); + gGL.vertex3f(0.0f, 0.0f, 0.0f); + gGL.vertex3f(0.0f, 0.0f, 0.0f); + gGL.vertex3f(0.0f, 0.0f, 0.0f); + gGL.end(); + gGL.flush(); + + glUseProgramObjectARB(0); + + LLGLSLShader::sNoFixedFunction = true; + + // Query whether the shader can or cannot run in hardware + // http://developer.apple.com/qa/qa2007/qa1502.html + GLint vertexGPUProcessing, fragmentGPUProcessing; + CGLContextObj ctx = CGLGetCurrentContext(); + CGLGetParameter(ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing); + CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing); + if (!fragmentGPUProcessing || !vertexGPUProcessing) + { + LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; + success = GL_FALSE; + suppress_errors = FALSE; + } + } #else - std::string log = get_object_log(obj); - LLStringUtil::toLower(log); - if (log.find("software") != std::string::npos) - { - LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; - success = GL_FALSE; - suppress_errors = FALSE; - } + std::string log = get_object_log(obj); + LLStringUtil::toLower(log); + if (log.find("software") != std::string::npos) + { + LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL; + success = GL_FALSE; + suppress_errors = FALSE; + } #endif - return success; + return success; } BOOL LLShaderMgr::validateProgramObject(GLhandleARB obj) { - //check program validity against current GL - glValidateProgramARB(obj); - GLint success = GL_TRUE; - glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); - if (success == GL_FALSE) - { - LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL; - dumpObjectLog(obj); - } - else - { - dumpObjectLog(obj, FALSE); - } - - return success; + //check program validity against current GL + glValidateProgramARB(obj); + GLint success = GL_TRUE; + glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); + if (success == GL_FALSE) + { + LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL; + dumpObjectLog(obj); + } + else + { + dumpObjectLog(obj, FALSE); + } + + return success; } //virtual void LLShaderMgr::initAttribsAndUniforms() { - //MUST match order of enum in LLVertexBuffer.h - mReservedAttribs.push_back("position"); - mReservedAttribs.push_back("normal"); - mReservedAttribs.push_back("texcoord0"); - mReservedAttribs.push_back("texcoord1"); - mReservedAttribs.push_back("texcoord2"); - mReservedAttribs.push_back("texcoord3"); - mReservedAttribs.push_back("diffuse_color"); - mReservedAttribs.push_back("emissive"); - mReservedAttribs.push_back("tangent"); - mReservedAttribs.push_back("weight"); - mReservedAttribs.push_back("weight4"); - mReservedAttribs.push_back("clothing"); - mReservedAttribs.push_back("texture_index"); - - //matrix state - mReservedUniforms.push_back("modelview_matrix"); - mReservedUniforms.push_back("projection_matrix"); - mReservedUniforms.push_back("inv_proj"); - mReservedUniforms.push_back("modelview_projection_matrix"); + //MUST match order of enum in LLVertexBuffer.h + mReservedAttribs.push_back("position"); + mReservedAttribs.push_back("normal"); + mReservedAttribs.push_back("texcoord0"); + mReservedAttribs.push_back("texcoord1"); + mReservedAttribs.push_back("texcoord2"); + mReservedAttribs.push_back("texcoord3"); + mReservedAttribs.push_back("diffuse_color"); + mReservedAttribs.push_back("emissive"); + mReservedAttribs.push_back("tangent"); + mReservedAttribs.push_back("weight"); + mReservedAttribs.push_back("weight4"); + mReservedAttribs.push_back("clothing"); + mReservedAttribs.push_back("texture_index"); + + //matrix state + mReservedUniforms.push_back("modelview_matrix"); + mReservedUniforms.push_back("projection_matrix"); + mReservedUniforms.push_back("inv_proj"); + mReservedUniforms.push_back("modelview_projection_matrix"); mReservedUniforms.push_back("inv_modelview"); - mReservedUniforms.push_back("normal_matrix"); - mReservedUniforms.push_back("texture_matrix0"); - mReservedUniforms.push_back("texture_matrix1"); - mReservedUniforms.push_back("texture_matrix2"); - mReservedUniforms.push_back("texture_matrix3"); - mReservedUniforms.push_back("object_plane_s"); - mReservedUniforms.push_back("object_plane_t"); - llassert(mReservedUniforms.size() == LLShaderMgr::OBJECT_PLANE_T+1); - - mReservedUniforms.push_back("viewport"); - - mReservedUniforms.push_back("light_position"); - mReservedUniforms.push_back("light_direction"); - mReservedUniforms.push_back("light_attenuation"); - mReservedUniforms.push_back("light_diffuse"); - mReservedUniforms.push_back("light_ambient"); - mReservedUniforms.push_back("light_count"); - mReservedUniforms.push_back("light"); - mReservedUniforms.push_back("light_col"); - mReservedUniforms.push_back("far_z"); - - llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1); - - - mReservedUniforms.push_back("proj_mat"); - mReservedUniforms.push_back("proj_near"); - mReservedUniforms.push_back("proj_p"); - mReservedUniforms.push_back("proj_n"); - mReservedUniforms.push_back("proj_origin"); - mReservedUniforms.push_back("proj_range"); - mReservedUniforms.push_back("proj_ambiance"); - mReservedUniforms.push_back("proj_shadow_idx"); - mReservedUniforms.push_back("shadow_fade"); - mReservedUniforms.push_back("proj_focus"); - mReservedUniforms.push_back("proj_lod"); - mReservedUniforms.push_back("proj_ambient_lod"); - - llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1); - - mReservedUniforms.push_back("color"); - - mReservedUniforms.push_back("diffuseMap"); + mReservedUniforms.push_back("normal_matrix"); + mReservedUniforms.push_back("texture_matrix0"); + mReservedUniforms.push_back("texture_matrix1"); + mReservedUniforms.push_back("texture_matrix2"); + mReservedUniforms.push_back("texture_matrix3"); + mReservedUniforms.push_back("object_plane_s"); + mReservedUniforms.push_back("object_plane_t"); + llassert(mReservedUniforms.size() == LLShaderMgr::OBJECT_PLANE_T+1); + + mReservedUniforms.push_back("viewport"); + + mReservedUniforms.push_back("light_position"); + mReservedUniforms.push_back("light_direction"); + mReservedUniforms.push_back("light_attenuation"); + mReservedUniforms.push_back("light_diffuse"); + mReservedUniforms.push_back("light_ambient"); + mReservedUniforms.push_back("light_count"); + mReservedUniforms.push_back("light"); + mReservedUniforms.push_back("light_col"); + mReservedUniforms.push_back("far_z"); + + llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1); + + + mReservedUniforms.push_back("proj_mat"); + mReservedUniforms.push_back("proj_near"); + mReservedUniforms.push_back("proj_p"); + mReservedUniforms.push_back("proj_n"); + mReservedUniforms.push_back("proj_origin"); + mReservedUniforms.push_back("proj_range"); + mReservedUniforms.push_back("proj_ambiance"); + mReservedUniforms.push_back("proj_shadow_idx"); + mReservedUniforms.push_back("shadow_fade"); + mReservedUniforms.push_back("proj_focus"); + mReservedUniforms.push_back("proj_lod"); + mReservedUniforms.push_back("proj_ambient_lod"); + + llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1); + + mReservedUniforms.push_back("color"); + + mReservedUniforms.push_back("diffuseMap"); mReservedUniforms.push_back("altDiffuseMap"); - mReservedUniforms.push_back("specularMap"); - mReservedUniforms.push_back("bumpMap"); + mReservedUniforms.push_back("specularMap"); + mReservedUniforms.push_back("bumpMap"); mReservedUniforms.push_back("bumpMap2"); - mReservedUniforms.push_back("environmentMap"); - mReservedUniforms.push_back("cloud_noise_texture"); + mReservedUniforms.push_back("environmentMap"); + mReservedUniforms.push_back("cloud_noise_texture"); mReservedUniforms.push_back("cloud_noise_texture_next"); - mReservedUniforms.push_back("fullbright"); - mReservedUniforms.push_back("lightnorm"); - mReservedUniforms.push_back("sunlight_color"); - mReservedUniforms.push_back("ambient"); - mReservedUniforms.push_back("blue_horizon"); - mReservedUniforms.push_back("blue_density"); - mReservedUniforms.push_back("haze_horizon"); - mReservedUniforms.push_back("haze_density"); - mReservedUniforms.push_back("cloud_shadow"); - mReservedUniforms.push_back("density_multiplier"); - mReservedUniforms.push_back("distance_multiplier"); - mReservedUniforms.push_back("max_y"); - mReservedUniforms.push_back("glow"); - mReservedUniforms.push_back("cloud_color"); - mReservedUniforms.push_back("cloud_pos_density1"); - mReservedUniforms.push_back("cloud_pos_density2"); - mReservedUniforms.push_back("cloud_scale"); - mReservedUniforms.push_back("gamma"); - mReservedUniforms.push_back("scene_light_strength"); - - llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1); - - mReservedUniforms.push_back("center"); - mReservedUniforms.push_back("size"); - mReservedUniforms.push_back("falloff"); - - mReservedUniforms.push_back("box_center"); - mReservedUniforms.push_back("box_size"); - - - mReservedUniforms.push_back("minLuminance"); - mReservedUniforms.push_back("maxExtractAlpha"); - mReservedUniforms.push_back("lumWeights"); - mReservedUniforms.push_back("warmthWeights"); - mReservedUniforms.push_back("warmthAmount"); - mReservedUniforms.push_back("glowStrength"); - mReservedUniforms.push_back("glowDelta"); - - llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_DELTA+1); - - - mReservedUniforms.push_back("minimum_alpha"); - mReservedUniforms.push_back("emissive_brightness"); - - mReservedUniforms.push_back("shadow_matrix"); - mReservedUniforms.push_back("env_mat"); - mReservedUniforms.push_back("shadow_clip"); - mReservedUniforms.push_back("sun_wash"); - mReservedUniforms.push_back("shadow_noise"); - mReservedUniforms.push_back("blur_size"); - mReservedUniforms.push_back("ssao_radius"); - mReservedUniforms.push_back("ssao_max_radius"); - mReservedUniforms.push_back("ssao_factor"); - mReservedUniforms.push_back("ssao_factor_inv"); - mReservedUniforms.push_back("ssao_effect_mat"); - mReservedUniforms.push_back("screen_res"); - mReservedUniforms.push_back("near_clip"); - mReservedUniforms.push_back("shadow_offset"); - mReservedUniforms.push_back("shadow_bias"); - mReservedUniforms.push_back("spot_shadow_bias"); - mReservedUniforms.push_back("spot_shadow_offset"); - mReservedUniforms.push_back("sun_dir"); + mReservedUniforms.push_back("fullbright"); + mReservedUniforms.push_back("lightnorm"); + mReservedUniforms.push_back("sunlight_color"); + mReservedUniforms.push_back("ambient"); + mReservedUniforms.push_back("blue_horizon"); + mReservedUniforms.push_back("blue_density"); + mReservedUniforms.push_back("haze_horizon"); + mReservedUniforms.push_back("haze_density"); + mReservedUniforms.push_back("cloud_shadow"); + mReservedUniforms.push_back("density_multiplier"); + mReservedUniforms.push_back("distance_multiplier"); + mReservedUniforms.push_back("max_y"); + mReservedUniforms.push_back("glow"); + mReservedUniforms.push_back("cloud_color"); + mReservedUniforms.push_back("cloud_pos_density1"); + mReservedUniforms.push_back("cloud_pos_density2"); + mReservedUniforms.push_back("cloud_scale"); + mReservedUniforms.push_back("gamma"); + mReservedUniforms.push_back("scene_light_strength"); + + llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1); + + mReservedUniforms.push_back("center"); + mReservedUniforms.push_back("size"); + mReservedUniforms.push_back("falloff"); + + mReservedUniforms.push_back("box_center"); + mReservedUniforms.push_back("box_size"); + + + mReservedUniforms.push_back("minLuminance"); + mReservedUniforms.push_back("maxExtractAlpha"); + mReservedUniforms.push_back("lumWeights"); + mReservedUniforms.push_back("warmthWeights"); + mReservedUniforms.push_back("warmthAmount"); + mReservedUniforms.push_back("glowStrength"); + mReservedUniforms.push_back("glowDelta"); + + llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_DELTA+1); + + + mReservedUniforms.push_back("minimum_alpha"); + mReservedUniforms.push_back("emissive_brightness"); + + mReservedUniforms.push_back("shadow_matrix"); + mReservedUniforms.push_back("env_mat"); + mReservedUniforms.push_back("shadow_clip"); + mReservedUniforms.push_back("sun_wash"); + mReservedUniforms.push_back("shadow_noise"); + mReservedUniforms.push_back("blur_size"); + mReservedUniforms.push_back("ssao_radius"); + mReservedUniforms.push_back("ssao_max_radius"); + mReservedUniforms.push_back("ssao_factor"); + mReservedUniforms.push_back("ssao_factor_inv"); + mReservedUniforms.push_back("ssao_effect_mat"); + mReservedUniforms.push_back("screen_res"); + mReservedUniforms.push_back("near_clip"); + mReservedUniforms.push_back("shadow_offset"); + mReservedUniforms.push_back("shadow_bias"); + mReservedUniforms.push_back("spot_shadow_bias"); + mReservedUniforms.push_back("spot_shadow_offset"); + mReservedUniforms.push_back("sun_dir"); mReservedUniforms.push_back("moon_dir"); - mReservedUniforms.push_back("shadow_res"); - mReservedUniforms.push_back("proj_shadow_res"); - mReservedUniforms.push_back("depth_cutoff"); - mReservedUniforms.push_back("norm_cutoff"); - mReservedUniforms.push_back("shadow_target_width"); - - llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH+1); - - mReservedUniforms.push_back("tc_scale"); - mReservedUniforms.push_back("rcp_screen_res"); - mReservedUniforms.push_back("rcp_frame_opt"); - mReservedUniforms.push_back("rcp_frame_opt2"); - - mReservedUniforms.push_back("focal_distance"); - mReservedUniforms.push_back("blur_constant"); - mReservedUniforms.push_back("tan_pixel_angle"); - mReservedUniforms.push_back("magnification"); - mReservedUniforms.push_back("max_cof"); - mReservedUniforms.push_back("res_scale"); - mReservedUniforms.push_back("dof_width"); - mReservedUniforms.push_back("dof_height"); - - mReservedUniforms.push_back("depthMap"); - mReservedUniforms.push_back("shadowMap0"); - mReservedUniforms.push_back("shadowMap1"); - mReservedUniforms.push_back("shadowMap2"); - mReservedUniforms.push_back("shadowMap3"); - mReservedUniforms.push_back("shadowMap4"); - mReservedUniforms.push_back("shadowMap5"); - - llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1); - - mReservedUniforms.push_back("normalMap"); - mReservedUniforms.push_back("positionMap"); - mReservedUniforms.push_back("diffuseRect"); - mReservedUniforms.push_back("specularRect"); - mReservedUniforms.push_back("noiseMap"); - mReservedUniforms.push_back("lightFunc"); - mReservedUniforms.push_back("lightMap"); - mReservedUniforms.push_back("bloomMap"); - mReservedUniforms.push_back("projectionMap"); - mReservedUniforms.push_back("norm_mat"); - - mReservedUniforms.push_back("global_gamma"); - mReservedUniforms.push_back("texture_gamma"); - - mReservedUniforms.push_back("specular_color"); - mReservedUniforms.push_back("env_intensity"); - - mReservedUniforms.push_back("matrixPalette"); - mReservedUniforms.push_back("translationPalette"); - - mReservedUniforms.push_back("screenTex"); - mReservedUniforms.push_back("screenDepth"); - mReservedUniforms.push_back("refTex"); - mReservedUniforms.push_back("eyeVec"); - mReservedUniforms.push_back("time"); - mReservedUniforms.push_back("waveDir1"); - mReservedUniforms.push_back("waveDir2"); - 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"); - mReservedUniforms.push_back("display_gamma"); + mReservedUniforms.push_back("shadow_res"); + mReservedUniforms.push_back("proj_shadow_res"); + mReservedUniforms.push_back("depth_cutoff"); + mReservedUniforms.push_back("norm_cutoff"); + mReservedUniforms.push_back("shadow_target_width"); + + llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH+1); + + mReservedUniforms.push_back("tc_scale"); + mReservedUniforms.push_back("rcp_screen_res"); + mReservedUniforms.push_back("rcp_frame_opt"); + mReservedUniforms.push_back("rcp_frame_opt2"); + + mReservedUniforms.push_back("focal_distance"); + mReservedUniforms.push_back("blur_constant"); + mReservedUniforms.push_back("tan_pixel_angle"); + mReservedUniforms.push_back("magnification"); + mReservedUniforms.push_back("max_cof"); + mReservedUniforms.push_back("res_scale"); + mReservedUniforms.push_back("dof_width"); + mReservedUniforms.push_back("dof_height"); + + mReservedUniforms.push_back("depthMap"); + mReservedUniforms.push_back("shadowMap0"); + mReservedUniforms.push_back("shadowMap1"); + mReservedUniforms.push_back("shadowMap2"); + mReservedUniforms.push_back("shadowMap3"); + mReservedUniforms.push_back("shadowMap4"); + mReservedUniforms.push_back("shadowMap5"); + + llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1); + + mReservedUniforms.push_back("normalMap"); + mReservedUniforms.push_back("positionMap"); + mReservedUniforms.push_back("diffuseRect"); + mReservedUniforms.push_back("specularRect"); + mReservedUniforms.push_back("noiseMap"); + mReservedUniforms.push_back("lightFunc"); + mReservedUniforms.push_back("lightMap"); + mReservedUniforms.push_back("bloomMap"); + mReservedUniforms.push_back("projectionMap"); + mReservedUniforms.push_back("norm_mat"); + + mReservedUniforms.push_back("global_gamma"); + mReservedUniforms.push_back("texture_gamma"); + + mReservedUniforms.push_back("specular_color"); + mReservedUniforms.push_back("env_intensity"); + + mReservedUniforms.push_back("matrixPalette"); + mReservedUniforms.push_back("translationPalette"); + + mReservedUniforms.push_back("screenTex"); + mReservedUniforms.push_back("screenDepth"); + mReservedUniforms.push_back("refTex"); + mReservedUniforms.push_back("eyeVec"); + mReservedUniforms.push_back("time"); + mReservedUniforms.push_back("waveDir1"); + mReservedUniforms.push_back("waveDir2"); + 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"); + mReservedUniforms.push_back("display_gamma"); mReservedUniforms.push_back("inscatter"); mReservedUniforms.push_back("sun_size"); @@ -1350,17 +1350,17 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sun_up_factor"); mReservedUniforms.push_back("moonlight_color"); - llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); - std::set dupe_check; + std::set dupe_check; - for (U32 i = 0; i < mReservedUniforms.size(); ++i) - { - if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end()) - { - LL_ERRS() << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << LL_ENDL; - } - dupe_check.insert(mReservedUniforms[i]); - } + for (U32 i = 0; i < mReservedUniforms.size(); ++i) + { + if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end()) + { + LL_ERRS() << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << LL_ENDL; + } + dupe_check.insert(mReservedUniforms[i]); + } } -- cgit v1.2.3 From 868cd32e5e229e503f1b5b1d5ec543fd6f76cb7f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 12 Mar 2019 11:07:23 -0700 Subject: More tab restoration. Also fix ref to removed extra GLSL link module. 'warn-on-failure:no-tabs' --- indra/llrender/llglslshader.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 9a4eeb59df..471d73febf 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -401,11 +401,6 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, // work-around missing mix(vec3,vec3,bvec3) mDefines["OLD_SELECT"] = "1"; #endif - - if (mExtraLinkObject) - { - attachObject(mExtraLinkObject); - } //compile new source vector< pair >::iterator fileIter = mShaderFiles.begin(); -- cgit v1.2.3 From 898c9f44218353b3bf71b78ffce02662b4927625 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Mar 2019 13:21:48 -0700 Subject: Mods to make merge with viewer-release have less whitespace-only change and fix diffs between EEP and VR. --- indra/llrender/CMakeLists.txt | 6 +- indra/llrender/llgl.cpp | 4 +- indra/llrender/llglslshader.cpp | 2 +- indra/llrender/llglslshader.h | 1 + indra/llrender/llgltexture.cpp | 182 ++++++++++++++++++++-------------------- indra/llrender/llimagegl.cpp | 1 + 6 files changed, 98 insertions(+), 98 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 0a81c1c6dd..589cf86745 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -107,8 +107,7 @@ if (BUILD_HEADLESS) ${LLXML_LIBRARIES} ${LLVFS_LIBRARIES} ${LLWINDOW_HEADLESS_LIBRARIES} - ${OPENGL_HEADLESS_LIBRARIES} - ) + ${OPENGL_HEADLESS_LIBRARIES}) endif (BUILD_HEADLESS) @@ -131,6 +130,5 @@ target_link_libraries(llrender ${LLVFS_LIBRARIES} ${LLWINDOW_LIBRARIES} ${FREETYPE_LIBRARIES} - ${OPENGL_LIBRARIES} - ) + ${OPENGL_LIBRARIES}) diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index b6300578e6..54a41c9d23 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -1353,8 +1353,8 @@ void LLGLManager::initExtensions() // nSight doesn't support use of ARB funcs that have been normalized in the API if (!LLRender::sNsightDebugSupport) { - glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); - glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); + glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); + glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); } else { diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 471d73febf..8f3a56e1cf 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -401,7 +401,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, // work-around missing mix(vec3,vec3,bvec3) mDefines["OLD_SELECT"] = "1"; #endif - + //compile new source vector< pair >::iterator fileIter = mShaderFiles.begin(); for ( ; fileIter != mShaderFiles.end(); fileIter++ ) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 830bad2aef..c1ce3d3aad 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -229,4 +229,5 @@ extern LLGLSLShader gSolidColorProgram; //Alpha mask shader (declared here so llappearance can access properly) extern LLGLSLShader gAlphaMaskProgram; + #endif diff --git a/indra/llrender/llgltexture.cpp b/indra/llrender/llgltexture.cpp index e9a39d8acb..ad501687ed 100644 --- a/indra/llrender/llgltexture.cpp +++ b/indra/llrender/llgltexture.cpp @@ -30,20 +30,20 @@ // static S32 LLGLTexture::getTotalNumOfCategories() { - return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2; + return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2 ; } // static //index starts from zero. S32 LLGLTexture::getIndexFromCategory(S32 category) { - return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1; + return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1 ; } //static S32 LLGLTexture::getCategoryFromIndex(S32 index) { - return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1; + return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1 ; } LLGLTexture::LLGLTexture(BOOL usemipmaps) @@ -55,19 +55,19 @@ LLGLTexture::LLGLTexture(BOOL usemipmaps) LLGLTexture::LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) { init(); - mFullWidth = width; - mFullHeight = height; + mFullWidth = width ; + mFullHeight = height ; mUseMipMaps = usemipmaps; - mComponents = components; + mComponents = components ; setTexelsPerImage(); } LLGLTexture::LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps) { init(); - mUseMipMaps = usemipmaps; + mUseMipMaps = usemipmaps ; // Create an empty image of the specified size and width - mGLTexturep = new LLImageGL(raw, usemipmaps); + mGLTexturep = new LLImageGL(raw, usemipmaps) ; } LLGLTexture::~LLGLTexture() @@ -81,13 +81,13 @@ void LLGLTexture::init() mFullWidth = 0; mFullHeight = 0; - mTexelsPerImage = 0; - mUseMipMaps = FALSE; - mComponents = 0; + mTexelsPerImage = 0 ; + mUseMipMaps = FALSE ; + mComponents = 0 ; - mTextureState = NO_DELETE; + mTextureState = NO_DELETE ; mDontDiscard = FALSE; - mNeedsGLTexture = FALSE; + mNeedsGLTexture = FALSE ; } void LLGLTexture::cleanup() @@ -111,181 +111,181 @@ void LLGLTexture::setBoostLevel(S32 level) { if(mBoostLevel != level) { - mBoostLevel = level; + mBoostLevel = level ; if(mBoostLevel != LLGLTexture::BOOST_NONE && mBoostLevel != LLGLTexture::BOOST_ICON) { - setNoDelete(); + setNoDelete() ; } } } void LLGLTexture::forceActive() { - mTextureState = ACTIVE; + mTextureState = ACTIVE ; } void LLGLTexture::setActive() { if(mTextureState != NO_DELETE) { - mTextureState = ACTIVE; + mTextureState = ACTIVE ; } } //set the texture to stay in memory void LLGLTexture::setNoDelete() { - mTextureState = NO_DELETE; + mTextureState = NO_DELETE ; } void LLGLTexture::generateGLTexture() { if(mGLTexturep.isNull()) { - mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps); + mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ; } } LLImageGL* LLGLTexture::getGLTexture() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep; + return mGLTexturep ; } BOOL LLGLTexture::createGLTexture() { if(mGLTexturep.isNull()) { - generateGLTexture(); + generateGLTexture() ; } - return mGLTexturep->createGLTexture(); + return mGLTexturep->createGLTexture() ; } BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category); + BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category) ; if(ret) { - mFullWidth = mGLTexturep->getCurrentWidth(); - mFullHeight = mGLTexturep->getCurrentHeight(); - mComponents = mGLTexturep->getComponents(); + mFullWidth = mGLTexturep->getCurrentWidth() ; + mFullHeight = mGLTexturep->getCurrentHeight() ; + mComponents = mGLTexturep->getComponents() ; setTexelsPerImage(); } - return ret; + return ret ; } void LLGLTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes); + mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ; } void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode) { - llassert(mGLTexturep.notNull()); - mGLTexturep->setAddressMode(mode); + llassert(mGLTexturep.notNull()) ; + mGLTexturep->setAddressMode(mode) ; } void LLGLTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option) { - llassert(mGLTexturep.notNull()); - mGLTexturep->setFilteringOption(option); + llassert(mGLTexturep.notNull()) ; + mGLTexturep->setFilteringOption(option) ; } //virtual S32 LLGLTexture::getWidth(S32 discard_level) const { - llassert(mGLTexturep.notNull()); - return mGLTexturep->getWidth(discard_level); + llassert(mGLTexturep.notNull()) ; + return mGLTexturep->getWidth(discard_level) ; } //virtual S32 LLGLTexture::getHeight(S32 discard_level) const { - llassert(mGLTexturep.notNull()); - return mGLTexturep->getHeight(discard_level); + llassert(mGLTexturep.notNull()) ; + return mGLTexturep->getHeight(discard_level) ; } S32 LLGLTexture::getMaxDiscardLevel() const { - llassert(mGLTexturep.notNull()); - return mGLTexturep->getMaxDiscardLevel(); + llassert(mGLTexturep.notNull()) ; + return mGLTexturep->getMaxDiscardLevel() ; } S32 LLGLTexture::getDiscardLevel() const { - llassert(mGLTexturep.notNull()); - return mGLTexturep->getDiscardLevel(); + llassert(mGLTexturep.notNull()) ; + return mGLTexturep->getDiscardLevel() ; } S8 LLGLTexture::getComponents() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getComponents(); + return mGLTexturep->getComponents() ; } LLGLuint LLGLTexture::getTexName() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getTexName(); + return mGLTexturep->getTexName() ; } BOOL LLGLTexture::hasGLTexture() const { if(mGLTexturep.notNull()) { - return mGLTexturep->getHasGLTexture(); + return mGLTexturep->getHasGLTexture() ; } - return FALSE; + return FALSE ; } BOOL LLGLTexture::getBoundRecently() const { if(mGLTexturep.notNull()) { - return mGLTexturep->getBoundRecently(); + return mGLTexturep->getBoundRecently() ; } - return FALSE; + return FALSE ; } LLTexUnit::eTextureType LLGLTexture::getTarget(void) const { - llassert(mGLTexturep.notNull()); - return mGLTexturep->getTarget(); + llassert(mGLTexturep.notNull()) ; + return mGLTexturep->getTarget() ; } BOOL LLGLTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height); + return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height) ; } BOOL LLGLTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height); + return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height) ; } void LLGLTexture::setGLTextureCreated (bool initialized) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - mGLTexturep->setGLTextureCreated (initialized); + mGLTexturep->setGLTextureCreated (initialized) ; } void LLGLTexture::setCategory(S32 category) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - mGLTexturep->setCategory(category); + mGLTexturep->setCategory(category) ; } void LLGLTexture::setTexName(LLGLuint texName) @@ -302,107 +302,107 @@ void LLGLTexture::setTarget(const LLGLenum target, const LLTexUnit::eTextureType LLTexUnit::eTextureAddressMode LLGLTexture::getAddressMode(void) const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getAddressMode(); + return mGLTexturep->getAddressMode() ; } S32Bytes LLGLTexture::getTextureMemory() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->mTextureMemory; + return mGLTexturep->mTextureMemory ; } LLGLenum LLGLTexture::getPrimaryFormat() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getPrimaryFormat(); + return mGLTexturep->getPrimaryFormat() ; } BOOL LLGLTexture::getIsAlphaMask() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getIsAlphaMask(); + return mGLTexturep->getIsAlphaMask() ; } BOOL LLGLTexture::getMask(const LLVector2 &tc) { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getMask(tc); + return mGLTexturep->getMask(tc) ; } F32 LLGLTexture::getTimePassedSinceLastBound() { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getTimePassedSinceLastBound(); + return mGLTexturep->getTimePassedSinceLastBound() ; } BOOL LLGLTexture::getMissed() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getMissed(); + return mGLTexturep->getMissed() ; } BOOL LLGLTexture::isJustBound() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->isJustBound(); + return mGLTexturep->isJustBound() ; } void LLGLTexture::forceUpdateBindStats(void) const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->forceUpdateBindStats(); + return mGLTexturep->forceUpdateBindStats() ; } U32 LLGLTexture::getTexelsInAtlas() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getTexelsInAtlas(); + return mGLTexturep->getTexelsInAtlas() ; } U32 LLGLTexture::getTexelsInGLTexture() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getTexelsInGLTexture(); + return mGLTexturep->getTexelsInGLTexture() ; } BOOL LLGLTexture::isGLTextureCreated() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->isGLTextureCreated(); + return mGLTexturep->isGLTextureCreated() ; } S32 LLGLTexture::getDiscardLevelInAtlas() const { - llassert(mGLTexturep.notNull()); + llassert(mGLTexturep.notNull()) ; - return mGLTexturep->getDiscardLevelInAtlas(); + return mGLTexturep->getDiscardLevelInAtlas() ; } void LLGLTexture::destroyGLTexture() { if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture()) { - mGLTexturep->destroyGLTexture(); - mTextureState = DELETED; + mGLTexturep->destroyGLTexture() ; + mTextureState = DELETED ; } } void LLGLTexture::setTexelsPerImage() { - U32 fullwidth = llmin(mFullWidth, (U32)MAX_IMAGE_SIZE_DEFAULT); - U32 fullheight = llmin(mFullHeight, (U32)MAX_IMAGE_SIZE_DEFAULT); + U32 fullwidth = llmin(mFullWidth,U32(MAX_IMAGE_SIZE_DEFAULT)); + U32 fullheight = llmin(mFullHeight,U32(MAX_IMAGE_SIZE_DEFAULT)); mTexelsPerImage = (U32)fullwidth * fullheight; } diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 25ec493fa2..7d8f512c93 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -352,6 +352,7 @@ BOOL LLImageGL::create(LLPointer& dest, const LLImageRaw* imageraw, B } //---------------------------------------------------------------------------- + LLImageGL::LLImageGL(BOOL usemipmaps) : LLTrace::MemTrackable("LLImageGL"), mSaveData(0), mExternalTexture(FALSE) -- cgit v1.2.3 From a10ec81e82d79bd79d5b058fda1b370073bfb480 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 08:13:04 -0700 Subject: SL-10743, SL-10744 Don't step on SUNLIGHT_COLOR uniform w/ syncLightState competing set. Put drawpool alpha render loop lighting setup changes as they were (this will give back some performance and possibly require reopening 10566). --- indra/llrender/llrender.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index e3bb9298cb..dc662bf898 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1180,8 +1180,6 @@ void LLRender::syncLightState() shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); - shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); - shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuseB[0].mV); } } -- cgit v1.2.3 From 446afe2d1a081a0e10a34749bbe1e4475075dae0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Mar 2019 08:21:53 -0700 Subject: Make whether the sun or moon is primary part of llrender light state so we can set uniforms for shaders along with other light params. Fix atten calcs to not use abs val. --- indra/llrender/llrender.cpp | 20 ++++++++++++++++++-- indra/llrender/llrender.h | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index dc662bf898..2bf7ad9902 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -850,9 +850,12 @@ LLLightState::LLLightState(S32 index) if (mIndex == 0) { mDiffuse.set(1,1,1,1); + mDiffuseB.set(0,0,0,0); mSpecular.set(1,1,1,1); } + mSunIsPrimary = true; + mAmbient.set(0,0,0,1); mPosition.set(0,0,1,0); mSpotDirection.set(0,0,-1); @@ -904,6 +907,15 @@ void LLLightState::setDiffuseB(const LLColor4& diffuse) } } +void LLLightState::setSunPrimary(bool v) +{ + if (mSunIsPrimary != v) + { + ++gGL.mLightHash; + mSunIsPrimary = v; + } +} + void LLLightState::setAmbient(const LLColor4& ambient) { if (mAmbient != ambient) @@ -1162,7 +1174,8 @@ void LLRender::syncLightState() LLVector3 direction[8]; LLVector4 attenuation[8]; LLVector3 diffuse[8]; - LLVector3 diffuseB[8]; + LLVector3 diffuse_b[8]; + bool sun_primary[8]; for (U32 i = 0; i < 8; i++) { @@ -1172,7 +1185,8 @@ void LLRender::syncLightState() direction[i] = light->mSpotDirection; attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[2], light->mSpecular.mV[3]); diffuse[i].set(light->mDiffuse.mV); - diffuseB[i].set(light->mDiffuseB.mV); + diffuse_b[i].set(light->mDiffuseB.mV); + sun_primary[i] = light->mSunIsPrimary; } shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); @@ -1180,6 +1194,8 @@ void LLRender::syncLightState() shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); + shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); + shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } } diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 3f2d5eb35d..ad9cd11283 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -239,6 +239,7 @@ public: void setSpotExponent(const F32& exponent); void setSpotCutoff(const F32& cutoff); void setSpotDirection(const LLVector3& direction); + void setSunPrimary(bool v); protected: friend class LLRender; @@ -247,6 +248,7 @@ protected: bool mEnabled; LLColor4 mDiffuse; LLColor4 mDiffuseB; + bool mSunIsPrimary; LLColor4 mAmbient; LLColor4 mSpecular; LLVector4 mPosition; -- cgit v1.2.3 From 3fa8b844c39311a2e4e319a8d4f7ab2c848ae140 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 02:51:41 -0700 Subject: Fixing gamma correction in EEP Step 1: Thou shall always read the sky cubemap as sRGB using hardware sampling. --- indra/llrender/llcubemap.cpp | 18 ++++++++++------- indra/llrender/llcubemap.h | 3 ++- indra/llrender/llimagegl.cpp | 47 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 12 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index af4e3fdda0..fcac016ed7 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -53,10 +53,11 @@ const BOOL use_cube_mipmaps = FALSE; //current build works best without cube mi bool LLCubeMap::sUseCubeMaps = true; -LLCubeMap::LLCubeMap() +LLCubeMap::LLCubeMap(bool init_as_srgb) : mTextureStage(0), mTextureCoordStage(0), - mMatrixStage(0) + mMatrixStage(0), + mIssRGB(init_as_srgb) { mTargets[0] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB; mTargets[1] = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB; @@ -82,12 +83,15 @@ void LLCubeMap::initGL() U32 texname = 0; LLImageGL::generateTextures(1, &texname); - + for (int i = 0; i < 6; i++) { - mImages[i] = new LLImageGL(64, 64, 4, (use_cube_mipmaps? TRUE : FALSE)); + mImages[i] = new LLImageGL(RESOLUTION, RESOLUTION, 4, FALSE); + if (mIssRGB) { + mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); - mRawImages[i] = new LLImageRaw(64, 64, 4); + mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4); mImages[i]->createGLTexture(0, mRawImages[i], texname); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname); @@ -154,7 +158,7 @@ void LLCubeMap::initGLData() { for (int i = 0; i < 6; i++) { - mImages[i]->setSubImage(mRawImages[i], 0, 0, 64, 64); + mImages[i]->setSubImage(mRawImages[i], 0, 0, RESOLUTION, RESOLUTION); } } @@ -484,7 +488,7 @@ void LLCubeMap::paintIn(LLVector3 dir[4], const LLColor4U& col) td[offset + cc] = U8((td[offset + cc] + col.mV[cc]) * 0.5); } } - mImages[side]->setSubImage(mRawImages[side], 0, 0, 64, 64); + mImages[side]->setSubImage(mRawImages[side], 0, 0, RESOLUTION, RESOLUTION); } } diff --git a/indra/llrender/llcubemap.h b/indra/llrender/llcubemap.h index ee2c41e026..95b6d12099 100644 --- a/indra/llrender/llcubemap.h +++ b/indra/llrender/llcubemap.h @@ -36,8 +36,9 @@ class LLVector3; // Environment map hack! class LLCubeMap : public LLRefCount { + bool mIssRGB; public: - LLCubeMap(); + LLCubeMap(bool init_as_srgb); void init(const std::vector >& rawimages); void initGL(); void initRawData(const std::vector >& rawimages); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 7d8f512c93..d3f8431654 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -187,15 +187,20 @@ S32 LLImageGL::dataFormatBits(S32 dataformat) switch (dataformat) { case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8; case GL_LUMINANCE: return 8; case GL_ALPHA: return 8; case GL_COLOR_INDEX: return 8; case GL_LUMINANCE_ALPHA: return 16; case GL_RGB: return 24; + case GL_SRGB: return 24; case GL_RGB8: return 24; case GL_RGBA: return 32; + case GL_SRGB_ALPHA: return 32; case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac default: LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; @@ -206,11 +211,19 @@ S32 LLImageGL::dataFormatBits(S32 dataformat) //static S32 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height) { - if (dataformat >= GL_COMPRESSED_RGB_S3TC_DXT1_EXT && - dataformat <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) + switch (dataformat) { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: if (width < 4) width = 4; if (height < 4) height = 4; + break; + default: + break; } S32 bytes ((width*height*dataFormatBits(dataformat)+7)>>3); S32 aligned = (bytes+3)&~3; @@ -223,14 +236,19 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat) switch (dataformat) { case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 3; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 3; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 4; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 4; case GL_LUMINANCE: return 1; case GL_ALPHA: return 1; case GL_COLOR_INDEX: return 1; case GL_LUMINANCE_ALPHA: return 2; case GL_RGB: return 3; + case GL_SRGB: return 3; case GL_RGBA: return 4; + case GL_SRGB_ALPHA: return 4; case GL_BGRA: return 4; // Used for QuickTime media textures on the Mac default: LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; @@ -650,9 +668,19 @@ BOOL LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) { LL_RECORD_BLOCK_TIME(FTM_SET_IMAGE); bool is_compressed = false; - if (mFormatPrimary >= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT && mFormatPrimary <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) + + switch (mFormatPrimary) { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: is_compressed = true; + break; + default: + break; } @@ -1227,10 +1255,18 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt case GL_RGB8: intformat = GL_COMPRESSED_RGB; break; + case GL_SRGB: + case GL_SRGB8: + intformat = GL_COMPRESSED_SRGB; + break; case GL_RGBA: case GL_RGBA8: intformat = GL_COMPRESSED_RGBA; break; + case GL_SRGB_ALPHA: + case GL_SRGB8_ALPHA8: + intformat = GL_COMPRESSED_SRGB_ALPHA; + break; case GL_LUMINANCE: case GL_LUMINANCE8: intformat = GL_COMPRESSED_LUMINANCE; @@ -1798,10 +1834,12 @@ void LLImageGL::calcAlphaChannelOffsetAndStride() mAlphaStride = 2; break; case GL_RGB: + case GL_SRGB: mNeedsAlphaAndPickMask = FALSE ; mIsMask = FALSE; return ; //no alpha channel. case GL_RGBA: + case GL_SRGB_ALPHA: mAlphaStride = 4; break; case GL_BGRA_EXT: @@ -1993,7 +2031,8 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) freePickMask(); if (mFormatType != GL_UNSIGNED_BYTE || - mFormatPrimary != GL_RGBA) + mFormatPrimary != GL_RGBA || + mFormatPrimary != GL_SRGB_ALPHA) { //cannot generate a pick mask for this texture return; -- cgit v1.2.3 From 57d88a8a98ef8663b9064b12143beb4068e58f86 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 08:11:56 -0700 Subject: Gamma correction pass 2: Make sure lights are in the correct color space. Bonus: cache the sRGB color in setLightColor on point and spot lights. Frees up a pow and some multiplies on the CPU every frame. --- indra/llrender/llrender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 2bf7ad9902..fe6010fabd 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1193,7 +1193,7 @@ void LLRender::syncLightState() shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); - shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); + shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, srgbColor4(mAmbientLightColor).mV); shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } -- cgit v1.2.3 From 0272c47e5a31cf972e02fbf14cb2642f86f75d78 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 11:57:45 -0700 Subject: Tweaked naming a bit, also white space. Will wait for a response from @graham_linden regarding moving the sRGB conversion functions in llmath.h to llrender. --- indra/llrender/llcubemap.cpp | 6 +- indra/llrender/llimagegl.cpp | 176 +++++++++++++++++++++---------------------- indra/llrender/llrender.cpp | 2 +- 3 files changed, 92 insertions(+), 92 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index fcac016ed7..14d0a744bb 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -87,9 +87,9 @@ void LLCubeMap::initGL() for (int i = 0; i < 6; i++) { mImages[i] = new LLImageGL(RESOLUTION, RESOLUTION, 4, FALSE); - if (mIssRGB) { - mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); - } + if (mIssRGB) { + mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4); mImages[i]->createGLTexture(0, mRawImages[i], texname); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index d3f8431654..2d526a2113 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -184,47 +184,47 @@ void LLImageGL::cleanupClass() //static S32 LLImageGL::dataFormatBits(S32 dataformat) { - switch (dataformat) - { - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4; - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4; - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8; - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8; - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8; - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8; - case GL_LUMINANCE: return 8; - case GL_ALPHA: return 8; - case GL_COLOR_INDEX: return 8; - case GL_LUMINANCE_ALPHA: return 16; - case GL_RGB: return 24; - case GL_SRGB: return 24; - case GL_RGB8: return 24; - case GL_RGBA: return 32; - case GL_SRGB_ALPHA: return 32; - case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac - default: - LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; - return 0; - } + switch (dataformat) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8; + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8; + case GL_LUMINANCE: return 8; + case GL_ALPHA: return 8; + case GL_COLOR_INDEX: return 8; + case GL_LUMINANCE_ALPHA: return 16; + case GL_RGB: return 24; + case GL_SRGB: return 24; + case GL_RGB8: return 24; + case GL_RGBA: return 32; + case GL_SRGB_ALPHA: return 32; + case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac + default: + LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; + return 0; + } } //static S32 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height) { - switch (dataformat) - { - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - if (width < 4) width = 4; - if (height < 4) height = 4; - break; - default: - break; - } + switch (dataformat) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + if (width < 4) width = 4; + if (height < 4) height = 4; + break; + default: + break; + } S32 bytes ((width*height*dataFormatBits(dataformat)+7)>>3); S32 aligned = (bytes+3)&~3; return aligned; @@ -669,19 +669,19 @@ BOOL LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) LL_RECORD_BLOCK_TIME(FTM_SET_IMAGE); bool is_compressed = false; - switch (mFormatPrimary) - { - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - is_compressed = true; - break; - default: - break; - } + switch (mFormatPrimary) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + is_compressed = true; + break; + default: + break; + } @@ -1255,18 +1255,18 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt case GL_RGB8: intformat = GL_COMPRESSED_RGB; break; - case GL_SRGB: - case GL_SRGB8: - intformat = GL_COMPRESSED_SRGB; - break; + case GL_SRGB: + case GL_SRGB8: + intformat = GL_COMPRESSED_SRGB; + break; case GL_RGBA: case GL_RGBA8: intformat = GL_COMPRESSED_RGBA; break; - case GL_SRGB_ALPHA: - case GL_SRGB8_ALPHA8: - intformat = GL_COMPRESSED_SRGB_ALPHA; - break; + case GL_SRGB_ALPHA: + case GL_SRGB8_ALPHA8: + intformat = GL_COMPRESSED_SRGB_ALPHA; + break; case GL_LUMINANCE: case GL_LUMINANCE8: intformat = GL_COMPRESSED_LUMINANCE; @@ -1824,30 +1824,30 @@ void LLImageGL::calcAlphaChannelOffsetAndStride() } mAlphaStride = -1 ; - switch (mFormatPrimary) - { - case GL_LUMINANCE: - case GL_ALPHA: - mAlphaStride = 1; - break; - case GL_LUMINANCE_ALPHA: - mAlphaStride = 2; - break; - case GL_RGB: - case GL_SRGB: - mNeedsAlphaAndPickMask = FALSE ; - mIsMask = FALSE; - return ; //no alpha channel. - case GL_RGBA: - case GL_SRGB_ALPHA: - mAlphaStride = 4; - break; - case GL_BGRA_EXT: - mAlphaStride = 4; - break; - default: - break; - } + switch (mFormatPrimary) + { + case GL_LUMINANCE: + case GL_ALPHA: + mAlphaStride = 1; + break; + case GL_LUMINANCE_ALPHA: + mAlphaStride = 2; + break; + case GL_RGB: + case GL_SRGB: + mNeedsAlphaAndPickMask = FALSE; + mIsMask = FALSE; + return; //no alpha channel. + case GL_RGBA: + case GL_SRGB_ALPHA: + mAlphaStride = 4; + break; + case GL_BGRA_EXT: + mAlphaStride = 4; + break; + default: + break; + } mAlphaOffset = -1 ; if (mFormatType == GL_UNSIGNED_BYTE) @@ -2030,13 +2030,13 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) freePickMask(); - if (mFormatType != GL_UNSIGNED_BYTE || - mFormatPrimary != GL_RGBA || - mFormatPrimary != GL_SRGB_ALPHA) - { - //cannot generate a pick mask for this texture - return; - } + if (mFormatType != GL_UNSIGNED_BYTE || + mFormatPrimary != GL_RGBA || + mFormatPrimary != GL_SRGB_ALPHA) + { + //cannot generate a pick mask for this texture + return; + } #ifdef SHOW_ASSERT const U32 pickSize = createPickMask(width, height); diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index fe6010fabd..2bf7ad9902 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1193,7 +1193,7 @@ void LLRender::syncLightState() shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); - shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, srgbColor4(mAmbientLightColor).mV); + shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } -- cgit v1.2.3 From 12495d46a43b7d8a47ca8f304b15cf055eb86433 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 29 Mar 2019 13:12:33 -0700 Subject: OSX is very picky about unused variables. --- indra/llrender/llcubemap.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index 14d0a744bb..d425b8fa2d 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -43,14 +43,6 @@ const F32 epsilon = 1e-7f; const U16 RESOLUTION = 64; -#if LL_DARWIN -// mipmap generation on cubemap textures seems to be broken on the Mac for at least some cards. -// Since the cubemap is small (64x64 per face) and doesn't have any fine detail, turning off mipmaps is a usable workaround. -const BOOL use_cube_mipmaps = FALSE; -#else -const BOOL use_cube_mipmaps = FALSE; //current build works best without cube mipmaps -#endif - bool LLCubeMap::sUseCubeMaps = true; LLCubeMap::LLCubeMap(bool init_as_srgb) -- cgit v1.2.3 From 2513aa0ed1331ca022fb8bbd7442b1ba750ead4d Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 30 Mar 2019 03:18:02 -0700 Subject: Additional gamma correction work: start moving over to EXT_texture_sRGB_decode. --- indra/llrender/llglslshader.cpp | 7 ++++--- indra/llrender/llglslshader.h | 4 ++-- indra/llrender/llimagegl.cpp | 4 ++-- indra/llrender/llrender.cpp | 14 ++++++++++++++ indra/llrender/llrender.h | 11 +++++++++++ 5 files changed, 33 insertions(+), 7 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 8f3a56e1cf..f8b5dd0559 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -974,7 +974,7 @@ S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode) return uniform; } -S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { @@ -986,11 +986,12 @@ S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) { gGL.getTexUnit(index)->activate(); gGL.getTexUnit(index)->enable(mode); + gGL.getTexUnit(index)->setTextureColorSpace(space); } return index; } -S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { @@ -1000,7 +1001,7 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) S32 index = mTexture[uniform]; if (index != -1 && gGL.getTexUnit(index)->getCurrType() != LLTexUnit::TT_NONE) { - if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode) + if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode && gGL.getTexUnit(index)->getCurrColorSpace() != space) { if (gDebugSession) { diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index c1ce3d3aad..974d0ea005 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -153,8 +153,8 @@ public: //if given texture uniform is active in the shader, //the corresponding channel will be active upon return //returns channel texture is enabled in from [0-MAX) - S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE); - S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE); + S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR); + S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR); // bindTexture returns the texture unit we've bound the texture to. // You can reuse the return value to unbind a texture when required. diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 2d526a2113..8b51bf4b9f 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1385,12 +1385,12 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S mFormatType = GL_UNSIGNED_BYTE; break; case 3: - mFormatInternal = GL_RGB8; + mFormatInternal = GL_SRGB8; mFormatPrimary = GL_RGB; mFormatType = GL_UNSIGNED_BYTE; break; case 4: - mFormatInternal = GL_RGBA8; + mFormatInternal = GL_SRGB8_ALPHA8; mFormatPrimary = GL_RGBA; mFormatType = GL_UNSIGNED_BYTE; break; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 2bf7ad9902..53a30a63c4 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -838,6 +838,20 @@ void LLTexUnit::debugTextureUnit(void) } } +void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) { + mTexColorSpace = space; + if (space == TCS_SRGB) { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); + } + else { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } + + if (gDebugGL) { + assert_glerror(); + } +} + LLLightState::LLLightState(S32 index) : mIndex(index), mEnabled(false), diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index ad9cd11283..2f15edc20e 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -131,6 +131,12 @@ public: TBS_ONE_MINUS_CONST_ALPHA } eTextureBlendSrc; + typedef enum + { + TCS_LINEAR = 0, + TCS_SRGB + } eTextureColorSpace; + LLTexUnit(S32 index); // Refreshes renderer state of the texture unit to the cached values @@ -198,6 +204,10 @@ public: void setHasMipMaps(bool hasMips) { mHasMipMaps = hasMips; } + void setTextureColorSpace(eTextureColorSpace space); + + eTextureColorSpace getCurrColorSpace() { return mTexColorSpace; } + protected: const S32 mIndex; U32 mCurrTexture; @@ -209,6 +219,7 @@ protected: eTextureBlendOp mCurrAlphaOp; eTextureBlendSrc mCurrAlphaSrc1; eTextureBlendSrc mCurrAlphaSrc2; + eTextureColorSpace mTexColorSpace; S32 mCurrColorScale; S32 mCurrAlphaScale; bool mHasMipMaps; -- cgit v1.2.3 From a158c879578822a116e3f6a8c5dbbd1a14bb8c83 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 30 Mar 2019 17:22:54 -0700 Subject: Hide sRGB decode behind a flag, and make sure that sRGB decodes is strictly opt-in. --- indra/llrender/llgl.cpp | 6 ++++++ indra/llrender/llgl.h | 1 + indra/llrender/llrender.cpp | 43 ++++++++++++++++++++++++++++--------------- indra/llrender/llrender.h | 2 +- 4 files changed, 36 insertions(+), 16 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 54a41c9d23..d18512f613 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -999,6 +999,12 @@ void LLGLManager::initExtensions() mHassRGBFramebuffer = ExtensionExists("GL_EXT_framebuffer_sRGB", gGLHExts.mSysExts); #endif +#ifdef GL_EXT_texture_sRGB_decode + mHasTexturesRGBDecode = ExtensionExists("GL_EXT_texture_sRGB_decode", gGLHExts.mSysExts); +#else + mHasTexturesRGBDecode = ExtensionExists("GL_ARB_texture_sRGB_decode", gGLHExts.mSysExts); +#endif + mHasMipMapGeneration = mHasFramebufferObject || mGLVersion >= 1.4f; mHasDrawBuffers = ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts); diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 362fda5fb1..a7faea7d33 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -118,6 +118,7 @@ public: BOOL mHasDebugOutput; BOOL mHassRGBTexture; BOOL mHassRGBFramebuffer; + BOOL mHasTexturesRGBDecode; // Vendor-specific extensions BOOL mIsATI; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 53a30a63c4..5dc61d0e8f 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -105,7 +105,7 @@ LLTexUnit::LLTexUnit(S32 index) mCurrColorOp(TBO_MULT), mCurrAlphaOp(TBO_MULT), mCurrColorSrc1(TBS_TEX_COLOR), mCurrColorSrc2(TBS_PREV_COLOR), mCurrAlphaSrc1(TBS_TEX_ALPHA), mCurrAlphaSrc2(TBS_PREV_ALPHA), - mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0), + mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0), mTexColorSpace(TCS_LINEAR), mHasMipMaps(false), mIndex(index) { @@ -162,6 +162,8 @@ void LLTexUnit::refreshState(void) setTextureCombiner(mCurrColorOp, mCurrColorSrc1, mCurrColorSrc2, false); setTextureCombiner(mCurrAlphaOp, mCurrAlphaSrc1, mCurrAlphaSrc2, true); } + + setTextureColorSpace(mTexColorSpace); } void LLTexUnit::activate(void) @@ -191,7 +193,6 @@ void LLTexUnit::enable(eTextureType type) stop_glerror(); } mCurrTexType = type; - gGL.flush(); if (!LLGLSLShader::sNoFixedFunction && type != LLTexUnit::TT_MULTISAMPLE_TEXTURE && @@ -219,6 +220,8 @@ void LLTexUnit::disable(void) { glDisable(sGLTextureType[mCurrTexType]); } + + setTextureColorSpace(TCS_LINEAR); mCurrTexType = TT_NONE; } @@ -255,7 +258,8 @@ bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind) gl_tex->mTexOptionsDirty = false; setTextureAddressMode(gl_tex->mAddressMode); setTextureFilteringOption(gl_tex->mFilterOption); - } + } + setTextureColorSpace(mTexColorSpace); } } else @@ -330,6 +334,7 @@ bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind) setTextureFilteringOption(texture->mFilterOption); stop_glerror(); } + setTextureColorSpace(mTexColorSpace); } stop_glerror(); @@ -355,7 +360,7 @@ bool LLTexUnit::bind(LLCubeMap* cubeMap) { activate(); enable(LLTexUnit::TT_CUBE_MAP); - mCurrTexture = cubeMap->mImages[0]->getTexName(); + mCurrTexture = cubeMap->mImages[0]->getTexName(); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mCurrTexture); mHasMipMaps = cubeMap->mImages[0]->mHasMipMaps; cubeMap->mImages[0]->updateBindStats(cubeMap->mImages[0]->mTextureMemory); @@ -364,7 +369,8 @@ bool LLTexUnit::bind(LLCubeMap* cubeMap) cubeMap->mImages[0]->mTexOptionsDirty = false; setTextureAddressMode(cubeMap->mImages[0]->mAddressMode); setTextureFilteringOption(cubeMap->mImages[0]->mFilterOption); - } + } + setTextureColorSpace(mTexColorSpace); return true; } else @@ -415,7 +421,8 @@ bool LLTexUnit::bindManual(eTextureType type, U32 texture, bool hasMips) enable(type); mCurrTexture = texture; glBindTexture(sGLTextureType[type], texture); - mHasMipMaps = hasMips; + mHasMipMaps = hasMips; + setTextureColorSpace(mTexColorSpace); } return true; } @@ -435,6 +442,9 @@ void LLTexUnit::unbind(eTextureType type) if (mCurrTexType == type) { mCurrTexture = 0; + + // Always make sure our texture color space is reset to linear. SRGB sampling should be opt-in in the vast majority of cases. Also prevents color space "popping". + mTexColorSpace = TCS_LINEAR; if (LLGLSLShader::sNoFixedFunction && type == LLTexUnit::TT_TEXTURE) { glBindTexture(sGLTextureType[type], sWhiteTexture); @@ -840,15 +850,18 @@ void LLTexUnit::debugTextureUnit(void) void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) { mTexColorSpace = space; - if (space == TCS_SRGB) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); - } - else { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); - } - - if (gDebugGL) { - assert_glerror(); + if (gGLManager.mHasTexturesRGBDecode) { + + if (space == TCS_SRGB) { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); + } + else { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } + + if (gDebugGL) { + assert_glerror(); + } } } diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 2f15edc20e..41f4fe4017 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -159,7 +159,7 @@ public: // Binds the LLImageGL to this texture unit // (automatically enables the unit for the LLImageGL's texture type) bool bind(LLImageGL* texture, bool for_rendering = false, bool forceBind = false); - bool bind(LLTexture* texture, bool for_rendering = false, bool forceBind = false); + bool bind(LLTexture* texture, bool for_rendering = false, bool forceBind = false); // Binds a cubemap to this texture unit // (automatically enables the texture unit for cubemaps) -- cgit v1.2.3 From 0e47ca896d701eeb3c38a3bcb188bcceacaba80b Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 18:34:56 -0700 Subject: Make LLImageGL's loading of assets as sRGB or linear conditional based upon sRGB decode support. --- indra/llrender/llimagegl.cpp | 65 ++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 8b51bf4b9f..16fd6ffe8a 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1370,33 +1370,44 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S if( !mHasExplicitFormat ) { - switch (mComponents) - { - case 1: - // Use luminance alpha (for fonts) - mFormatInternal = GL_LUMINANCE8; - mFormatPrimary = GL_LUMINANCE; - mFormatType = GL_UNSIGNED_BYTE; - break; - case 2: - // Use luminance alpha (for fonts) - mFormatInternal = GL_LUMINANCE8_ALPHA8; - mFormatPrimary = GL_LUMINANCE_ALPHA; - mFormatType = GL_UNSIGNED_BYTE; - break; - case 3: - mFormatInternal = GL_SRGB8; - mFormatPrimary = GL_RGB; - mFormatType = GL_UNSIGNED_BYTE; - break; - case 4: - mFormatInternal = GL_SRGB8_ALPHA8; - mFormatPrimary = GL_RGBA; - mFormatType = GL_UNSIGNED_BYTE; - break; - default: - LL_ERRS() << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL; - } + switch (mComponents) + { + case 1: + // Use luminance alpha (for fonts) + mFormatInternal = GL_LUMINANCE8; + mFormatPrimary = GL_LUMINANCE; + mFormatType = GL_UNSIGNED_BYTE; + break; + case 2: + // Use luminance alpha (for fonts) + mFormatInternal = GL_LUMINANCE8_ALPHA8; + mFormatPrimary = GL_LUMINANCE_ALPHA; + mFormatType = GL_UNSIGNED_BYTE; + break; + case 3: + if (gGLManager.mHasTexturesRGBDecode) + { + mFormatInternal = GL_SRGB8; + } + else { + mFormatInternal = GL_RGB8; + } + mFormatPrimary = GL_RGB; + mFormatType = GL_UNSIGNED_BYTE; + break; + case 4: + if (gGLManager.mHasTexturesRGBDecode) + { + mFormatInternal = GL_SRGB8_ALPHA8; + } + else { + mFormatInternal = GL_RGBA8; + } + mFormatType = GL_UNSIGNED_BYTE; + break; + default: + LL_ERRS() << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL; + } calcAlphaChannelOffsetAndStride() ; } -- cgit v1.2.3 From 3a42d2b94a0f2d27b4baef63abaf49e64139ff01 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 18:51:28 -0700 Subject: Whoops! Always make sure that our primary format is assigned. --- indra/llrender/llimagegl.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 16fd6ffe8a..2f1f702d2c 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1403,6 +1403,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S else { mFormatInternal = GL_RGBA8; } + mFormatPrimary = GL_RGBA; mFormatType = GL_UNSIGNED_BYTE; break; default: -- cgit v1.2.3 From accd83cc7e87aff3136c53025ac1eb4bece49d90 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 14:42:06 -0700 Subject: Fix missing EOL on last line. --- indra/llrender/llgl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index df36738604..c555f556fa 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -2635,4 +2635,5 @@ extern "C" { _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; } -#endif \ No newline at end of file +#endif + -- cgit v1.2.3 From dcd8117b85f45886f78a1a2e9756cb1709d6572a Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 9 Apr 2019 22:35:40 -0700 Subject: First stab at moving atmospheric var calcs to its own utility shader. Still some work to go here. Largely related to how certain values (i.e., SSAO mix values) are supplied. But so far, so good. --HG-- branch : OPEN-340 --- indra/llrender/llshadermgr.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 4303c3ed11..071f40d924 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -96,6 +96,10 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { return FALSE; } + + if (!shader->attachObject("windlight/atmosphericsFuncs.glsl")) { + return FALSE; + } } if (features->calculatesLighting) @@ -194,6 +198,10 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { return FALSE; } + + if (!shader->attachObject("windlight/atmosphericsFuncs.glsl")) { + return FALSE; + } } // we want this BEFORE shadows and AO because those facilities use pos/norm access -- cgit v1.2.3 From 08812cbe060e62cb8b61e91bc2f878a74a0015e5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 10 Apr 2019 02:11:07 -0700 Subject: Separate out vertex program objects from fragment program objects and use it. Given that mShaderObjects only ever expects one copy of a given shader object (leading to lots of "shaderV" and "shaderF"), it made having utility shaders a bit more difficult to incorporate. This change makes sure the two are separated. Using this over a multimap largely for readibility. Also, actually, you know, use this functionality. --HG-- branch : OPEN-340 --- indra/llrender/llglslshader.cpp | 21 ++++++- indra/llrender/llglslshader.h | 3 +- indra/llrender/llshadermgr.cpp | 129 +++++++++++++++++++++------------------- indra/llrender/llshadermgr.h | 3 +- 4 files changed, 89 insertions(+), 67 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index f8b5dd0559..babf649ece 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -485,12 +485,27 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, return success; } -BOOL LLGLSLShader::attachObject(std::string object_path) +BOOL LLGLSLShader::attachVertexObject(std::string object_path) { + if (LLShaderMgr::instance()->mVertexShaderObjects.count(object_path) > 0) + { + stop_glerror(); + glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mVertexShaderObjects[object_path]); + stop_glerror(); + return TRUE; + } + else + { + LL_SHADER_LOADING_WARNS() << "Attempting to attach shader object: '" << object_path << "' that hasn't been compiled." << LL_ENDL; + return FALSE; + } +} + +BOOL LLGLSLShader::attachFragmentObject(std::string object_path) { - if (LLShaderMgr::instance()->mShaderObjects.count(object_path) > 0) + if (LLShaderMgr::instance()->mFragmentShaderObjects.count(object_path) > 0) { stop_glerror(); - glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mShaderObjects[object_path]); + glAttachObjectARB(mProgramObject, LLShaderMgr::instance()->mFragmentShaderObjects[object_path]); stop_glerror(); return TRUE; } diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 974d0ea005..38dc980a97 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -102,7 +102,8 @@ public: std::vector * uniforms, U32 varying_count = 0, const char** varyings = NULL); - BOOL attachObject(std::string object); + BOOL attachFragmentObject(std::string object); + BOOL attachVertexObject(std::string object); void attachObject(GLhandleARB object); void attachObjects(GLhandleARB* objects = NULL, S32 count = 0); BOOL mapAttributes(const std::vector * attributes); diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 071f40d924..27f9e36f0f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -79,12 +79,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasWaterFog) { - if (!shader->attachObject("windlight/atmosphericsVarsWaterV.glsl")) + if (!shader->attachVertexObject("windlight/atmosphericsVarsWaterV.glsl")) { return FALSE; } } - else if (!shader->attachObject("windlight/atmosphericsVarsV.glsl")) + else if (!shader->attachVertexObject("windlight/atmosphericsVarsV.glsl")) { return FALSE; } @@ -92,54 +92,50 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->calculatesLighting || features->calculatesAtmospherics) { - if (!shader->attachObject("windlight/atmosphericsHelpersV.glsl")) + if (!shader->attachVertexObject("windlight/atmosphericsHelpersV.glsl")) { return FALSE; } - - if (!shader->attachObject("windlight/atmosphericsFuncs.glsl")) { - return FALSE; - } } if (features->calculatesLighting) { if (features->isSpecular) { - if (!shader->attachObject("lighting/lightFuncSpecularV.glsl")) + if (!shader->attachVertexObject("lighting/lightFuncSpecularV.glsl")) { return FALSE; } if (!features->isAlphaLighting) { - if (!shader->attachObject("lighting/sumLightsSpecularV.glsl")) + if (!shader->attachVertexObject("lighting/sumLightsSpecularV.glsl")) { return FALSE; } } - if (!shader->attachObject("lighting/lightSpecularV.glsl")) + if (!shader->attachVertexObject("lighting/lightSpecularV.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightFuncV.glsl")) + if (!shader->attachVertexObject("lighting/lightFuncV.glsl")) { return FALSE; } if (!features->isAlphaLighting) { - if (!shader->attachObject("lighting/sumLightsV.glsl")) + if (!shader->attachVertexObject("lighting/sumLightsV.glsl")) { return FALSE; } } - if (!shader->attachObject("lighting/lightV.glsl")) + if (!shader->attachVertexObject("lighting/lightV.glsl")) { return FALSE; } @@ -148,8 +144,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) // NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->calculatesAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsV.glsl")) + { + if (!shader->attachVertexObject("windlight/atmosphericsFuncs.glsl")) { + return FALSE; + } + + if (!shader->attachVertexObject("windlight/atmosphericsV.glsl")) { return FALSE; } @@ -157,7 +157,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasSkinning) { - if (!shader->attachObject("avatar/avatarSkinV.glsl")) + if (!shader->attachVertexObject("avatar/avatarSkinV.glsl")) { return FALSE; } @@ -165,7 +165,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasObjectSkinning) { - if (!shader->attachObject("avatar/objectSkinV.glsl")) + if (!shader->attachVertexObject("avatar/objectSkinV.glsl")) { return FALSE; } @@ -181,12 +181,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasWaterFog) { - if (!shader->attachObject("windlight/atmosphericsVarsWaterF.glsl")) + if (!shader->attachFragmentObject("windlight/atmosphericsVarsWaterF.glsl")) { return FALSE; } } - else if (!shader->attachObject("windlight/atmosphericsVarsF.glsl")) + else if (!shader->attachFragmentObject("windlight/atmosphericsVarsF.glsl")) { return FALSE; } @@ -194,20 +194,16 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->calculatesLighting || features->calculatesAtmospherics) { - if (!shader->attachObject("windlight/atmosphericsHelpersF.glsl")) + if (!shader->attachFragmentObject("windlight/atmosphericsHelpersF.glsl")) { return FALSE; } - - if (!shader->attachObject("windlight/atmosphericsFuncs.glsl")) { - return FALSE; - } } // we want this BEFORE shadows and AO because those facilities use pos/norm access if (features->isDeferred) { - if (!shader->attachObject("deferred/deferredUtil.glsl")) + if (!shader->attachFragmentObject("deferred/deferredUtil.glsl")) { return FALSE; } @@ -215,7 +211,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasShadows) { - if (!shader->attachObject("deferred/shadowUtil.glsl")) + if (!shader->attachFragmentObject("deferred/shadowUtil.glsl")) { return FALSE; } @@ -223,7 +219,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasAmbientOcclusion) { - if (!shader->attachObject("deferred/aoUtil.glsl")) + if (!shader->attachFragmentObject("deferred/aoUtil.glsl")) { return FALSE; } @@ -231,7 +227,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasIndirect) { - if (!shader->attachObject("deferred/indirect.glsl")) + if (!shader->attachFragmentObject("deferred/indirect.glsl")) { return FALSE; } @@ -239,7 +235,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasGamma) { - if (!shader->attachObject("windlight/gammaF.glsl")) + if (!shader->attachFragmentObject("windlight/gammaF.glsl")) { return FALSE; } @@ -247,7 +243,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasSrgb) { - if (!shader->attachObject("environment/srgbF.glsl")) + if (!shader->attachFragmentObject("environment/srgbF.glsl")) { return FALSE; } @@ -255,15 +251,19 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->encodesNormal) { - if (!shader->attachObject("environment/encodeNormF.glsl")) + if (!shader->attachFragmentObject("environment/encodeNormF.glsl")) { return FALSE; } } if (features->hasAtmospherics) - { - if (!shader->attachObject("windlight/atmosphericsF.glsl")) + { + if (!shader->attachFragmentObject("windlight/atmosphericsFuncs.glsl")) { + return FALSE; + } + + if (!shader->attachFragmentObject("windlight/atmosphericsF.glsl")) { return FALSE; } @@ -271,7 +271,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasTransport) { - if (!shader->attachObject("windlight/transportF.glsl")) + if (!shader->attachFragmentObject("windlight/transportF.glsl")) { return FALSE; } @@ -283,7 +283,7 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) // NOTE order of shader object attaching is VERY IMPORTANT!!! if (features->hasWaterFog) { - if (!shader->attachObject("environment/waterFogF.glsl")) + if (!shader->attachFragmentObject("environment/waterFogF.glsl")) { return FALSE; } @@ -297,14 +297,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightWaterNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightWaterNonIndexedF.glsl")) { return FALSE; } @@ -314,14 +314,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightWaterAlphaMaskF.glsl")) + if (!shader->attachFragmentObject("lighting/lightWaterAlphaMaskF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightWaterF.glsl")) + if (!shader->attachFragmentObject("lighting/lightWaterF.glsl")) { return FALSE; } @@ -336,14 +336,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightAlphaMaskNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightAlphaMaskNonIndexedF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightNonIndexedF.glsl")) { return FALSE; } @@ -353,14 +353,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightAlphaMaskF.glsl")) + if (!shader->attachFragmentObject("lighting/lightAlphaMaskF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightF.glsl")) + if (!shader->attachFragmentObject("lighting/lightF.glsl")) { return FALSE; } @@ -378,14 +378,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->disableTextureIndex) { - if (!shader->attachObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightFullbrightShinyWaterF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightShinyWaterF.glsl")) { return FALSE; } @@ -398,12 +398,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl")) { return FALSE; } } - else if (!shader->attachObject("lighting/lightFullbrightWaterNonIndexedF.glsl")) + else if (!shader->attachFragmentObject("lighting/lightFullbrightWaterNonIndexedF.glsl")) { return FALSE; } @@ -412,12 +412,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightFullbrightWaterAlphaMaskF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightWaterAlphaMaskF.glsl")) { return FALSE; } } - else if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl")) + else if (!shader->attachFragmentObject("lighting/lightFullbrightWaterF.glsl")) { return FALSE; } @@ -429,14 +429,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->disableTextureIndex) { - if (!shader->attachObject("lighting/lightFullbrightShinyNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightShinyNonIndexedF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightFullbrightShinyF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightShinyF.glsl")) { return FALSE; } @@ -451,14 +451,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightFullbrightNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightNonIndexedF.glsl")) { return FALSE; } @@ -468,14 +468,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->hasAlphaMask) { - if (!shader->attachObject("lighting/lightFullbrightAlphaMaskF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightAlphaMaskF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightFullbrightF.glsl")) + if (!shader->attachFragmentObject("lighting/lightFullbrightF.glsl")) { return FALSE; } @@ -493,14 +493,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->disableTextureIndex) { - if (!shader->attachObject("lighting/lightShinyWaterNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightShinyWaterNonIndexedF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightShinyWaterF.glsl")) + if (!shader->attachFragmentObject("lighting/lightShinyWaterF.glsl")) { return FALSE; } @@ -512,14 +512,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) { if (features->disableTextureIndex) { - if (!shader->attachObject("lighting/lightShinyNonIndexedF.glsl")) + if (!shader->attachFragmentObject("lighting/lightShinyNonIndexedF.glsl")) { return FALSE; } } else { - if (!shader->attachObject("lighting/lightShinyF.glsl")) + if (!shader->attachFragmentObject("lighting/lightShinyF.glsl")) { return FALSE; } @@ -530,14 +530,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->mIndexedTextureChannels <= 1) { - if (!shader->attachObject("objects/nonindexedTextureV.glsl")) + if (!shader->attachVertexObject("objects/nonindexedTextureV.glsl")) { return FALSE; } } else { - if (!shader->attachObject("objects/indexedTextureV.glsl")) + if (!shader->attachVertexObject("objects/indexedTextureV.glsl")) { return FALSE; } @@ -1007,7 +1007,12 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (ret) { // Add shader file to map - mShaderObjects[filename] = ret; + if (type == GL_VERTEX_SHADER_ARB) { + mVertexShaderObjects[filename] = ret; + } + else if (type == GL_FRAGMENT_SHADER_ARB) { + mFragmentShaderObjects[filename] = ret; + } shader_level = try_gpu_class; } else diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index e0a67e6198..98caa9295e 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -275,7 +275,8 @@ public: public: // Map of shader names to compiled - std::map mShaderObjects; + std::map mVertexShaderObjects; + std::map mFragmentShaderObjects; //global (reserved slot) shader parameters std::vector mReservedAttribs; -- cgit v1.2.3 From c4032528aff8ef1938e897ec583bbf25a3e713e1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 2 May 2019 13:49:35 -0700 Subject: Roll back sRGB decode changes from contrib for now. Fix direct light matching across alpha/blended-material/deferred. Get diffuse lighting to match from Low to Ultra. --- indra/llrender/llcubemap.cpp | 2 ++ indra/llrender/llglslshader.cpp | 7 ++++--- indra/llrender/llglslshader.h | 4 ++-- indra/llrender/llimagegl.cpp | 10 ++++++++-- indra/llrender/llrender.cpp | 6 ++++++ indra/llrender/llrendertarget.cpp | 19 ++++++++++++++++++- indra/llrender/llrendertarget.h | 2 +- 7 files changed, 41 insertions(+), 9 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index d425b8fa2d..5947bca670 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -79,9 +79,11 @@ void LLCubeMap::initGL() for (int i = 0; i < 6; i++) { mImages[i] = new LLImageGL(RESOLUTION, RESOLUTION, 4, FALSE); + #if USE_SRGB_DECODE if (mIssRGB) { mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); } + #endif mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4); mImages[i]->createGLTexture(0, mRawImages[i], texname); diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index babf649ece..902c08b6ba 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -937,15 +937,15 @@ void LLGLSLShader::bindNoShader(void) } } -S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace) { S32 channel = 0; channel = getUniformLocation(uniform); - return bindTexture(channel, texture, mode); + return bindTexture(channel, texture, mode, colorspace); } -S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { @@ -958,6 +958,7 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextu if (uniform > -1) { gGL.getTexUnit(uniform)->bind(texture, mode); + gGL.getTexUnit(uniform)->setTextureColorSpace(colorspace); } return uniform; diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 38dc980a97..7cf6d3c941 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -159,8 +159,8 @@ public: // 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 bindTexture(const std::string& uniform, LLTexture *texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR); + S32 bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR); S32 unbindTexture(const std::string& uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE); S32 unbindTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 2f1f702d2c..790ba25112 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1385,22 +1385,28 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S mFormatType = GL_UNSIGNED_BYTE; break; case 3: + #if USE_SRGB_DECODE if (gGLManager.mHasTexturesRGBDecode) { mFormatInternal = GL_SRGB8; } - else { + else + #endif + { mFormatInternal = GL_RGB8; } mFormatPrimary = GL_RGB; mFormatType = GL_UNSIGNED_BYTE; break; case 4: + #if USE_SRGB_DECODE if (gGLManager.mHasTexturesRGBDecode) { mFormatInternal = GL_SRGB8_ALPHA8; } - else { + else + #endif + { mFormatInternal = GL_RGBA8; } mFormatPrimary = GL_RGBA; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 5dc61d0e8f..f3771f3bf2 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -193,6 +193,7 @@ void LLTexUnit::enable(eTextureType type) stop_glerror(); } mCurrTexType = type; + gGL.flush(); if (!LLGLSLShader::sNoFixedFunction && type != LLTexUnit::TT_MULTISAMPLE_TEXTURE && @@ -850,6 +851,8 @@ void LLTexUnit::debugTextureUnit(void) void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) { mTexColorSpace = space; + +#if USE_SRGB_DECODE if (gGLManager.mHasTexturesRGBDecode) { if (space == TCS_SRGB) { @@ -863,6 +866,9 @@ void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) { assert_glerror(); } } +#endif + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } LLLightState::LLLightState(S32 index) diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index cd484b4fe9..9fb4f7f2b0 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -502,9 +502,26 @@ U32 LLRenderTarget::getNumTextures() const } -void LLRenderTarget::bindTexture(U32 index, S32 channel) +void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options) { gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index)); + + bool isSRGB = false; + llassert(mInternalFormat.size() > index); + switch (mInternalFormat[index]) + { + case GL_SRGB_ALPHA: + case GL_SRGB: + case GL_SRGB8_ALPHA8: + isSRGB = true; + break; + + default: + break; + } + + gGL.getTexUnit(channel)->setTextureFilteringOption(filter_options); + gGL.getTexUnit(channel)->setTextureColorSpace(isSRGB ? LLTexUnit::TCS_SRGB : LLTexUnit::TCS_LINEAR); } void LLRenderTarget::flush(bool fetch_depth) diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index 6dc84d978d..6c07ac5b1c 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -120,7 +120,7 @@ public: U32 getDepth(void) const { return mDepth; } bool hasStencil() const { return mStencil; } - void bindTexture(U32 index, S32 channel); + void bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options = LLTexUnit::TFO_BILINEAR); //flush rendering operations //must be called when rendering is complete -- cgit v1.2.3 From a1e8042c1f2f1ab0ed5b6040535348974e659556 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 7 May 2019 15:36:43 -0700 Subject: SL-11055, SL-10966, SL-11087 Make haze look more like WL. Make lack of sun and moon mean black and fixed dir to prevent spooky underlighting. --- indra/llrender/llrender.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index f3771f3bf2..c536b403ef 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1228,6 +1228,7 @@ void LLRender::syncLightState() shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); + shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } } -- cgit v1.2.3 From fe734ddf07009734fcf031b7f27f57d813b12b7f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 9 May 2019 13:14:24 -0700 Subject: SL-11056 Make OpenGL 3.3 cards not false alarm on version 140 shader reqs. Makes deferred rendering work on low-end GPUs more often. --- indra/llrender/llshadermgr.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 27f9e36f0f..6cd9a93ddd 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -705,7 +705,31 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } else { - if (major_version < 4) + if (major_version >= 4) + { + //set version to 400 + shader_code_text[shader_code_count++] = strdup("#version 400\n"); + } + else if (major_version == 3) + { + if (minor_version < 10) + { + shader_code_text[shader_code_count++] = strdup("#version 300\n"); + } + else if (minor_version <= 19) + { + shader_code_text[shader_code_count++] = strdup("#version 310\n"); + } + else if (minor_version <= 29) + { + shader_code_text[shader_code_count++] = strdup("#version 320\n"); + } + else + { + shader_code_text[shader_code_count++] = strdup("#version 330\n"); + } + } + else { //set version to 1.30 shader_code_text[shader_code_count++] = strdup("#version 130\n"); @@ -713,10 +737,6 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade extra_code_text[extra_code_count++] = strdup("precision mediump int;\n"); extra_code_text[extra_code_count++] = strdup("precision highp float;\n"); } - else - { //set version to 400 - shader_code_text[shader_code_count++] = strdup("#version 400\n"); - } extra_code_text[extra_code_count++] = strdup("#define DEFINE_GL_FRAGCOLOR 1\n"); extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n"); -- cgit v1.2.3 From e9dbee00262a437e4b3f971b37ea636e92032133 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 21 May 2019 16:00:45 -0700 Subject: SL-11238 Fix ambient light inputs to the renderer. Fix 3rd sky shader w/ mistaken density mod conversion. Make ambient clamp apply to all modes. Tune ALM ambient clamp to match non-ALM. --- indra/llrender/llrender.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index c536b403ef..f4b5d88529 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1228,6 +1228,7 @@ void LLRender::syncLightState() shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); + shader->uniform4fv(LLShaderMgr::AMBIENT, 1, mAmbientLightColor.mV); shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } -- cgit v1.2.3 From 16d3279995bcb4a4766b721d0897b3d2199971d5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 3 Jun 2019 11:30:41 -0700 Subject: SL-10966 Fix light atten and transmittance calcs breaking ambient color contrib to fog. Needs to be tested on DRTSIM-415 or better to get legacy viewer settings that match EEP. --- indra/llrender/llshadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 6cd9a93ddd..026301d914 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1203,7 +1203,7 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("fullbright"); mReservedUniforms.push_back("lightnorm"); mReservedUniforms.push_back("sunlight_color"); - mReservedUniforms.push_back("ambient"); + mReservedUniforms.push_back("ambient_color"); mReservedUniforms.push_back("blue_horizon"); mReservedUniforms.push_back("blue_density"); mReservedUniforms.push_back("haze_horizon"); -- cgit v1.2.3 From b659e5596e6612d83ce41dd6ce44228103851875 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 28 Jun 2019 08:45:07 -0700 Subject: SL-11514 Convince Geenzo code to get a little DeMorgan in it. Trophy Unlocked: make all alpha textures partcipate in picking. --- indra/llrender/llimagegl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 790ba25112..ff74380217 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -2049,8 +2049,8 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) freePickMask(); if (mFormatType != GL_UNSIGNED_BYTE || - mFormatPrimary != GL_RGBA || - mFormatPrimary != GL_SRGB_ALPHA) + ((mFormatPrimary != GL_RGBA) + && (mFormatPrimary != GL_SRGB_ALPHA))) { //cannot generate a pick mask for this texture return; -- cgit v1.2.3 From 11331604767b2dcf50c7a84f24843ce8e531a409 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2019 13:26:02 -0700 Subject: SL-11109 Make shadowAlphaMask shader ignore vertex alpha before discards iff we're a fullbright object. Keep llappearance from stuffing dangling pointers into the alpha cache (crash iff you're using nSight debugging and disable readbacks). --- indra/llrender/llvertexbuffer.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 1312f6afda..0c53d48c08 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -942,15 +942,15 @@ S32 LLVertexBuffer::determineUsage(S32 usage) { //only stream_draw and dynamic_draw are supported when using VBOs, dynamic draw is the default if (ret_usage != GL_DYNAMIC_COPY_ARB) { - if (sDisableVBOMapping) - { //always use stream draw if VBO mapping is disabled - ret_usage = GL_STREAM_DRAW_ARB; - } - else - { - ret_usage = GL_DYNAMIC_DRAW_ARB; - } - } + if (sDisableVBOMapping) + { //always use stream draw if VBO mapping is disabled + ret_usage = GL_STREAM_DRAW_ARB; + } + else + { + ret_usage = GL_DYNAMIC_DRAW_ARB; + } + } } return ret_usage; @@ -1506,10 +1506,10 @@ bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) llassert(newnverts >= 0); llassert(newnindices >= 0); - bool sucsess = true; + bool success = true; - sucsess &= updateNumVerts(newnverts); - sucsess &= updateNumIndices(newnindices); + success &= updateNumVerts(newnverts); + success &= updateNumIndices(newnindices); if (useVBOs()) { @@ -1521,7 +1521,7 @@ bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) } } - return sucsess; + return success; } bool LLVertexBuffer::useVBOs() const -- cgit v1.2.3 From ddf703611dd6ae7081b12e5be70bc69d44e6a3a2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Jul 2019 10:33:16 -0700 Subject: SL-10761 Add code to force a usage hint when VBOs are disabled and make useBVOs reflect that as well. --- indra/llrender/llgl.cpp | 3 ++- indra/llrender/llvertexbuffer.cpp | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index c555f556fa..c01c15391d 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -2051,7 +2051,8 @@ LLGLState::LLGLState(LLGLenum state, S32 enabled) : if (mState) { mWasEnabled = sStateMap[state]; - llassert(mWasEnabled == glIsEnabled(state)); + // we can't actually assert on this as queued changes to state are not reflected by glIsEnabled + //llassert(mWasEnabled == glIsEnabled(state)); setEnabled(enabled); stop_glerror(); } diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0c53d48c08..1b910d91b2 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -953,6 +953,17 @@ S32 LLVertexBuffer::determineUsage(S32 usage) } } + if (ret_usage == 0) + { + if (sDisableVBOMapping) + { //always use stream draw if VBO mapping is disabled + ret_usage = GL_STREAM_DRAW_ARB; + } + else + { + ret_usage = GL_DYNAMIC_DRAW_ARB; + } + } return ret_usage; } @@ -982,6 +993,8 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) mMappable(false), mFence(NULL) { + llassert(mUsage != 0); + mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping); //zero out offsets @@ -1527,7 +1540,7 @@ bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) bool LLVertexBuffer::useVBOs() const { //it's generally ineffective to use VBO for things that are streaming on apple - return (mUsage != 0); + return sEnableVBOs && (mUsage != 0); } //---------------------------------------------------------------------------- -- cgit v1.2.3 From 5bae46b357cd4d7700ed4289fc3b3ddf00860ec9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Jul 2019 08:22:34 -0700 Subject: Add more asserts to try to catch 10761 before the driver kabooms. --- indra/llrender/llvertexbuffer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 1b910d91b2..2ac17127be 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -660,6 +660,9 @@ void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVecto void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const { + llassert(start < (U32)mNumVerts); + llassert(end < (U32)mNumVerts); + if (start >= (U32) mNumVerts || end >= (U32) mNumVerts) { @@ -679,6 +682,9 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of U16* idx = ((U16*) getIndicesPointer())+indices_offset; for (U32 i = 0; i < count; ++i) { + llassert(idx[i] >= start); + llassert(idx[i] <= end); + if (idx[i] < start || idx[i] > end) { LL_ERRS() << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << LL_ENDL; @@ -697,6 +703,7 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of for (U32 i = start; i < end; i++) { S32 idx = (S32) (v[i][3]+0.25f); + llassert(idx >= 0); if (idx < 0 || idx >= shader->mFeatures.mIndexedTextureChannels) { LL_ERRS() << "Bad texture index found in vertex data stream." << LL_ENDL; @@ -754,6 +761,8 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; + llassert(idx); + stop_glerror(); LLGLSLShader::startProfile(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, -- cgit v1.2.3 From 00590defe4f525229c392b6f345695a09ac6b679 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Jul 2019 10:40:01 -0700 Subject: SL-11605 Fix broken throttling of sky/envmap updates. --- indra/llrender/llvertexbuffer.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 2ac17127be..f498526367 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -761,8 +761,6 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; - llassert(idx); - stop_glerror(); LLGLSLShader::startProfile(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, -- cgit v1.2.3 From b3466243073c2693be4c32b3586a191c30095d01 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2019 15:44:35 -0700 Subject: SL-10761 Make vograss objects set their face vert/index counts to 0 when setting the number of blades to 0 to disable rendering so we don't allocate space and then skip setting it up with actual index data in getGeometry. --- indra/llrender/llgl.cpp | 2 ++ indra/llrender/llglheaders.h | 3 +++ indra/llrender/llglslshader.cpp | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index c01c15391d..babaa65c35 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -280,6 +280,7 @@ PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB = NULL; PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL; PFNGLGETHANDLEARBPROC glGetHandleARB = NULL; PFNGLDETACHOBJECTARBPROC glDetachObjectARB = NULL; +PFNGLISSHADERPROC glIsShader = NULL; PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; @@ -1314,6 +1315,7 @@ void LLGLManager::initExtensions() glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteObjectARB"); glGetHandleARB = (PFNGLGETHANDLEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetHandleARB"); glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDetachObjectARB"); + glIsShader = (PFNGLISSHADERPROC) GLH_EXT_GET_PROC_ADDRESS("glIsShader"); glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateShaderObjectARB"); glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glShaderSourceARB"); glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCompileShaderARB"); diff --git a/indra/llrender/llglheaders.h b/indra/llrender/llglheaders.h index 722dd9050b..258d227038 100644 --- a/indra/llrender/llglheaders.h +++ b/indra/llrender/llglheaders.h @@ -129,6 +129,7 @@ extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; +extern PFNGLISSHADERPROC glIsShader; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; @@ -397,6 +398,7 @@ extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; +extern PFNGLISSHADERPROC glIsShader; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; @@ -644,6 +646,7 @@ extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; +extern PFNGLISSHADERPROC glIsShader; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 902c08b6ba..782304ae41 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -344,13 +344,17 @@ void LLGLSLShader::unloadInternal() { GLhandleARB obj[1024]; GLsizei count; + glGetAttachedObjectsARB(mProgramObject, 1024, &count, obj); - glGetAttachedObjectsARB(mProgramObject, sizeof(obj)/sizeof(obj[0]), &count, obj); for (GLsizei i = 0; i < count; i++) { - glDetachObjectARB(mProgramObject, obj[i]); + // avoid opengl errors when multiple programs link a common shader obj + if (glIsShader(obj[i])) + { + glDetachObjectARB(mProgramObject, obj[i]); glDeleteObjectARB(obj[i]); } + } glDeleteObjectARB(mProgramObject); -- cgit v1.2.3 From 230c9b68d81bcf163a6627e8474e545e8ceb2282 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2019 16:24:49 -0700 Subject: Remove binding and use of glIsShader for now (only useful for avoiding warnings about deleting shader objects re-used across programs). --- indra/llrender/llgl.cpp | 2 -- indra/llrender/llglheaders.h | 3 --- indra/llrender/llglslshader.cpp | 8 ++------ 3 files changed, 2 insertions(+), 11 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index babaa65c35..c01c15391d 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -280,7 +280,6 @@ PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB = NULL; PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL; PFNGLGETHANDLEARBPROC glGetHandleARB = NULL; PFNGLDETACHOBJECTARBPROC glDetachObjectARB = NULL; -PFNGLISSHADERPROC glIsShader = NULL; PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; @@ -1315,7 +1314,6 @@ void LLGLManager::initExtensions() glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteObjectARB"); glGetHandleARB = (PFNGLGETHANDLEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetHandleARB"); glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDetachObjectARB"); - glIsShader = (PFNGLISSHADERPROC) GLH_EXT_GET_PROC_ADDRESS("glIsShader"); glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateShaderObjectARB"); glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glShaderSourceARB"); glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCompileShaderARB"); diff --git a/indra/llrender/llglheaders.h b/indra/llrender/llglheaders.h index 258d227038..722dd9050b 100644 --- a/indra/llrender/llglheaders.h +++ b/indra/llrender/llglheaders.h @@ -129,7 +129,6 @@ extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; -extern PFNGLISSHADERPROC glIsShader; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; @@ -398,7 +397,6 @@ extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; -extern PFNGLISSHADERPROC glIsShader; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; @@ -646,7 +644,6 @@ extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; -extern PFNGLISSHADERPROC glIsShader; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 782304ae41..384e5bf99f 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -348,12 +348,8 @@ void LLGLSLShader::unloadInternal() for (GLsizei i = 0; i < count; i++) { - // avoid opengl errors when multiple programs link a common shader obj - if (glIsShader(obj[i])) - { - glDetachObjectARB(mProgramObject, obj[i]); - glDeleteObjectARB(obj[i]); - } + glDetachObjectARB(mProgramObject, obj[i]); + glDeleteObjectARB(obj[i]); } glDeleteObjectARB(mProgramObject); -- cgit v1.2.3 From b507d63566e8896af702dd10f5643dc29068a8a9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2019 11:36:22 -0700 Subject: SL-11621 Remove all references to unused shader var global_gamma. Remove many unused decls for gamma from shaders. Make post-deferred gamma correction use display_gamma. Make setting display_gamma use the correct RenderDeferredDisplayGamma setting. --- indra/llrender/llshadermgr.cpp | 2 -- indra/llrender/llshadermgr.h | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 026301d914..bce3720d3b 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1305,8 +1305,6 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("bloomMap"); mReservedUniforms.push_back("projectionMap"); mReservedUniforms.push_back("norm_mat"); - - mReservedUniforms.push_back("global_gamma"); mReservedUniforms.push_back("texture_gamma"); mReservedUniforms.push_back("specular_color"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 98caa9295e..127b5ce5b6 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -173,10 +173,7 @@ public: DEFERRED_BLOOM, DEFERRED_PROJECTION, DEFERRED_NORM_MATRIX, - - GLOBAL_GAMMA, - TEXTURE_GAMMA, - + TEXTURE_GAMMA, SPECULAR_COLOR, ENVIRONMENT_INTENSITY, -- cgit v1.2.3 From 749eae85ce2b40e8d229be0027a940a44278c1b8 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Mon, 29 Jul 2019 15:44:15 +0300 Subject: SL-11661 Backed out part of changeset 3a84abad1d46 to fix uploader crash --- indra/llrender/llvertexbuffer.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f498526367..e3035c7194 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -960,17 +960,6 @@ S32 LLVertexBuffer::determineUsage(S32 usage) } } - if (ret_usage == 0) - { - if (sDisableVBOMapping) - { //always use stream draw if VBO mapping is disabled - ret_usage = GL_STREAM_DRAW_ARB; - } - else - { - ret_usage = GL_DYNAMIC_DRAW_ARB; - } - } return ret_usage; } @@ -1000,8 +989,6 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) mMappable(false), mFence(NULL) { - llassert(mUsage != 0); - mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping); //zero out offsets @@ -1547,7 +1534,7 @@ bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) bool LLVertexBuffer::useVBOs() const { //it's generally ineffective to use VBO for things that are streaming on apple - return sEnableVBOs && (mUsage != 0); + return (mUsage != 0); } //---------------------------------------------------------------------------- -- cgit v1.2.3 From 76128c4357bc36acd54575153516c6d337fe4263 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 5 Aug 2019 12:04:29 -0700 Subject: SL-10566 Use vector for some high-traffic, low-item count containers instead of list. Provide method of storing joint indices sep from weight data for faster runtime processing. --- indra/llrender/CMakeLists.txt | 1 + indra/llrender/lluiimage.cpp | 89 +++++++------------------------------------ indra/llrender/lluiimage.h | 50 +++++++++++++++--------- indra/llrender/lluiimage.inl | 77 +++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 92 deletions(-) create mode 100644 indra/llrender/lluiimage.inl (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 589cf86745..47e7ad915b 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -80,6 +80,7 @@ set(llrender_HEADER_FILES llshadermgr.h lltexture.h lluiimage.h + lluiimage.inl llvertexbuffer.h llglcommonfunc.h ) diff --git a/indra/llrender/lluiimage.cpp b/indra/llrender/lluiimage.cpp index 5d8f92b2e6..db69806097 100644 --- a/indra/llrender/lluiimage.cpp +++ b/indra/llrender/lluiimage.cpp @@ -31,7 +31,6 @@ // Project includes #include "lluiimage.h" -#include "llrender2dutils.h" LLUIImage::LLUIImage(const std::string& name, LLPointer image) : mName(name), @@ -39,67 +38,29 @@ LLUIImage::LLUIImage(const std::string& name, LLPointer image) mScaleRegion(0.f, 1.f, 1.f, 0.f), mClipRegion(0.f, 1.f, 1.f, 0.f), mImageLoaded(NULL), - mScaleStyle(SCALE_INNER) -{} + mScaleStyle(SCALE_INNER), + mCachedW(-1), + mCachedH(-1) +{ + getTextureWidth(); + getTextureHeight(); +} LLUIImage::~LLUIImage() { delete mImageLoaded; } -void LLUIImage::setClipRegion(const LLRectf& region) +S32 LLUIImage::getWidth() const { - mClipRegion = region; + // return clipped dimensions of actual image area + return ll_round((F32)mImage->getWidth(0) * mClipRegion.getWidth()); } -void LLUIImage::setScaleRegion(const LLRectf& region) +S32 LLUIImage::getHeight() const { - mScaleRegion = region; -} - -void LLUIImage::setScaleStyle(LLUIImage::EScaleStyle style) -{ - mScaleStyle = style; -} - -//TODO: move drawing implementation inside class -void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const -{ - draw(x, y, getWidth(), getHeight(), color); -} - -void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const -{ - gl_draw_scaled_image_with_border( - x, y, - width, height, - mImage, - color, - FALSE, - mClipRegion, - mScaleRegion, - mScaleStyle == SCALE_INNER); -} - -void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const -{ - gl_draw_scaled_image_with_border( - x, y, - width, height, - mImage, - color, - TRUE, - mClipRegion, - mScaleRegion, - mScaleStyle == SCALE_INNER); -} - -void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const -{ - LLRect border_rect; - border_rect.setOriginAndSize(x, y, width, height); - border_rect.stretch(border_width, border_width); - drawSolid(border_rect, color); + // return clipped dimensions of actual image area + return ll_round((F32)mImage->getHeight(0) * mClipRegion.getHeight()); } void LLUIImage::draw3D(const LLVector3& origin_agent, const LLVector3& x_axis, const LLVector3& y_axis, @@ -145,28 +106,7 @@ void LLUIImage::draw3D(const LLVector3& origin_agent, const LLVector3& x_axis, c } LLRender2D::popMatrix(); } - -S32 LLUIImage::getWidth() const -{ - // return clipped dimensions of actual image area - return ll_round((F32)mImage->getWidth(0) * mClipRegion.getWidth()); -} - -S32 LLUIImage::getHeight() const -{ - // return clipped dimensions of actual image area - return ll_round((F32)mImage->getHeight(0) * mClipRegion.getHeight()); -} - -S32 LLUIImage::getTextureWidth() const -{ - return mImage->getWidth(0); -} - -S32 LLUIImage::getTextureHeight() const -{ - return mImage->getHeight(0); -} +//#include "lluiimage.inl" boost::signals2::connection LLUIImage::addLoadedCallback( const image_loaded_signal_t::slot_type& cb ) { @@ -186,7 +126,6 @@ void LLUIImage::onImageLoaded() } } - namespace LLInitParam { void ParamValue::updateValueFromBlock() diff --git a/indra/llrender/lluiimage.h b/indra/llrender/lluiimage.h index 6f47385eb0..e462e19004 100644 --- a/indra/llrender/lluiimage.h +++ b/indra/llrender/lluiimage.h @@ -36,6 +36,7 @@ #include #include "llinitparam.h" #include "lltexture.h" +#include "llrender2dutils.h" extern const LLColor4 UI_VERTEX_COLOR; @@ -53,35 +54,46 @@ public: LLUIImage(const std::string& name, LLPointer image); virtual ~LLUIImage(); - void setClipRegion(const LLRectf& region); - void setScaleRegion(const LLRectf& region); - void setScaleStyle(EScaleStyle style); + LL_FORCE_INLINE void setClipRegion(const LLRectf& region) + { + mClipRegion = region; + } - LLPointer getImage() { return mImage; } - const LLPointer& getImage() const { return mImage; } + LL_FORCE_INLINE void setScaleRegion(const LLRectf& region) + { + mScaleRegion = region; + } - void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const; - void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const; - void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); } + LL_FORCE_INLINE void setScaleStyle(EScaleStyle style) + { + mScaleStyle = style; + } + + LL_FORCE_INLINE LLPointer getImage() { return mImage; } + LL_FORCE_INLINE const LLPointer& getImage() const { return mImage; } + + LL_FORCE_INLINE void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const; + LL_FORCE_INLINE void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const; + LL_FORCE_INLINE void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); } - void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const; - void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); } - void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, getWidth(), getHeight(), color); } + LL_FORCE_INLINE void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const; + LL_FORCE_INLINE void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); } + LL_FORCE_INLINE void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, getWidth(), getHeight(), color); } - void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const; - void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); } - void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, getWidth(), getHeight(), color, border_width); } + LL_FORCE_INLINE void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const; + LL_FORCE_INLINE void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); } + LL_FORCE_INLINE void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, getWidth(), getHeight(), color, border_width); } void draw3D(const LLVector3& origin_agent, const LLVector3& x_axis, const LLVector3& y_axis, const LLRect& rect, const LLColor4& color); - const std::string& getName() const { return mName; } + LL_FORCE_INLINE const std::string& getName() const { return mName; } virtual S32 getWidth() const; virtual S32 getHeight() const; // returns dimensions of underlying textures, which might not be equal to ui image portion - S32 getTextureWidth() const; - S32 getTextureHeight() const; + LL_FORCE_INLINE S32 getTextureWidth() const; + LL_FORCE_INLINE S32 getTextureHeight() const; boost::signals2::connection addLoadedCallback( const image_loaded_signal_t::slot_type& cb ); @@ -95,8 +107,12 @@ protected: LLRectf mClipRegion; LLPointer mImage; EScaleStyle mScaleStyle; + mutable S32 mCachedW; + mutable S32 mCachedH; }; +#include "lluiimage.inl" + namespace LLInitParam { template<> diff --git a/indra/llrender/lluiimage.inl b/indra/llrender/lluiimage.inl new file mode 100644 index 0000000000..3b23d77d62 --- /dev/null +++ b/indra/llrender/lluiimage.inl @@ -0,0 +1,77 @@ +/** + * @file lluiimage.inl + * @brief UI inline func implementation + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const +{ + draw(x, y, getWidth(), getHeight(), color); +} + +void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const +{ + gl_draw_scaled_image_with_border( + x, y, + width, height, + mImage, + color, + FALSE, + mClipRegion, + mScaleRegion, + mScaleStyle == SCALE_INNER); +} + +void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const +{ + gl_draw_scaled_image_with_border( + x, y, + width, height, + mImage, + color, + TRUE, + mClipRegion, + mScaleRegion, + mScaleStyle == SCALE_INNER); +} + +void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const +{ + LLRect border_rect; + border_rect.setOriginAndSize(x, y, width, height); + border_rect.stretch(border_width, border_width); + drawSolid(border_rect, color); +} + +// returns dimensions of underlying textures, which might not be equal to ui image portion +S32 LLUIImage::getTextureWidth() const +{ + mCachedW = (mCachedW == -1) ? getWidth() : mCachedW; + return mCachedW; +} + +S32 LLUIImage::getTextureHeight() const +{ + mCachedH = (mCachedH == -1) ? getHeight() : mCachedH; + return mCachedH; +} -- cgit v1.2.3 From 6fbb35b712d25843d9fe10945a232749a89601c5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2019 14:39:24 -0700 Subject: Fix line-endings on new inline file. --- indra/llrender/lluiimage.inl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/lluiimage.inl b/indra/llrender/lluiimage.inl index 3b23d77d62..f5227556f0 100644 --- a/indra/llrender/lluiimage.inl +++ b/indra/llrender/lluiimage.inl @@ -64,14 +64,14 @@ void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& } // returns dimensions of underlying textures, which might not be equal to ui image portion -S32 LLUIImage::getTextureWidth() const -{ - mCachedW = (mCachedW == -1) ? getWidth() : mCachedW; - return mCachedW; -} - -S32 LLUIImage::getTextureHeight() const -{ - mCachedH = (mCachedH == -1) ? getHeight() : mCachedH; - return mCachedH; -} +S32 LLUIImage::getTextureWidth() const +{ + mCachedW = (mCachedW == -1) ? getWidth() : mCachedW; + return mCachedW; +} + +S32 LLUIImage::getTextureHeight() const +{ + mCachedH = (mCachedH == -1) ? getHeight() : mCachedH; + return mCachedH; +} -- cgit v1.2.3 From bfcecee33d01c67141dfbb5d70c7a744ca0f47b5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 30 Aug 2019 14:02:25 -0700 Subject: Fix names on sentinels to get doxygen to shaddap. --- indra/llrender/llglcommonfunc.h | 2 +- indra/llrender/llgltexture.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llglcommonfunc.h b/indra/llrender/llglcommonfunc.h index f1f8ff7bc4..e6d3755755 100644 --- a/indra/llrender/llglcommonfunc.h +++ b/indra/llrender/llglcommonfunc.h @@ -1,5 +1,5 @@ /** -* @file llphoenixfunc.h +* @file llglcommonfunc.h * @brief File include common opengl code snippets * * $LicenseInfo:firstyear=2003&license=viewerlgpl$ diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h index bdaed05591..071912c2c2 100644 --- a/indra/llrender/llgltexture.h +++ b/indra/llrender/llgltexture.h @@ -1,5 +1,5 @@ /** - * @file llglviewertexture.h + * @file llgltexture.h * @brief Object for managing opengl textures * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ -- cgit v1.2.3 From 18eb8ac90ce409ba620f6fe8ff487e6195d9c3eb Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Fri, 15 Nov 2019 15:45:08 -0800 Subject: QoL fix: remove extra blank lines for every source line when dumping shader source --- indra/llrender/llshadermgr.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index bce3720d3b..dcb34c6761 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -570,9 +570,20 @@ static std::string get_object_log(GLhandleARB ret) //dump shader source for debugging void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text) { - for (GLuint i = 0; i < shader_code_count; i++) + for (U32 i = 0; i < shader_code_count; i++) { + GLcharARB *line = shader_code_text[i]; + size_t len = strlen( line ); + char last = len > 0 ? line[len - 1] : 0; + + // LL_ENDL already outputs a newline so temporarily strip off the end newline to prevent EVERY line outputting an (extra) blank line + if (last == '\n') + line[len - 1] = 0; + LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; + + if (last == '\n') + line[len - 1] = '\n'; } LL_SHADER_LOADING_WARNS() << LL_ENDL; } -- cgit v1.2.3 From bd761b0833923f2fb6d3cd8430ebd3287be861f8 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Fri, 22 Nov 2019 23:41:20 +0000 Subject: Cleanup inconsistent types --- indra/llrender/llshadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index dcb34c6761..896dd566c1 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -574,7 +574,7 @@ void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_cod { GLcharARB *line = shader_code_text[i]; size_t len = strlen( line ); - char last = len > 0 ? line[len - 1] : 0; + GLcharARB last = len > 0 ? line[len - 1] : 0; // LL_ENDL already outputs a newline so temporarily strip off the end newline to prevent EVERY line outputting an (extra) blank line if (last == '\n') -- cgit v1.2.3 From 3d22273726ab4d40f2eb9afc5ceeac37471a9dfa Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Tue, 24 Mar 2020 11:22:01 -0500 Subject: Fix for bad fullbright shiny shininess values and inconsistency between materialF and fullbrightShinyF --- indra/llrender/llrender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index f4b5d88529..ebc4659bcf 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1370,7 +1370,7 @@ void LLRender::syncMatrices() } - if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting) + if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting || shader->mFeatures.calculatesAtmospherics) { //also sync light state syncLightState(); } -- cgit v1.2.3 From 126b91f8ee27f52193a71f8eb01c2f2b3bfb36ba Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 24 Mar 2020 17:22:47 -0600 Subject: DRTVWR-440, make enabling GLdebug flag slightly less infinite-loopy --- indra/llrender/llvertexbuffer.cpp | 53 ++++++++++++++++++++------------------- indra/llrender/llvertexbuffer.h | 4 +-- 2 files changed, 29 insertions(+), 28 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index e3035c7194..94a04d4ddb 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2326,34 +2326,35 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { U32 unsatisfied_mask = (required_mask & ~data_mask); - U32 i = 0; - while (i < TYPE_MAX) - { + for (U32 i = 0; i < TYPE_MAX; i++) + { U32 unsatisfied_flag = unsatisfied_mask & (1 << i); - switch (unsatisfied_flag) - { - case MAP_VERTEX: LL_INFOS() << "Missing vert pos" << LL_ENDL; break; - case MAP_NORMAL: LL_INFOS() << "Missing normals" << LL_ENDL; break; - case MAP_TEXCOORD0: LL_INFOS() << "Missing TC 0" << LL_ENDL; break; - case MAP_TEXCOORD1: LL_INFOS() << "Missing TC 1" << LL_ENDL; break; - case MAP_TEXCOORD2: LL_INFOS() << "Missing TC 2" << LL_ENDL; break; - case MAP_TEXCOORD3: LL_INFOS() << "Missing TC 3" << LL_ENDL; break; - case MAP_COLOR: LL_INFOS() << "Missing vert color" << LL_ENDL; break; - case MAP_EMISSIVE: LL_INFOS() << "Missing emissive" << LL_ENDL; break; - case MAP_TANGENT: LL_INFOS() << "Missing tangent" << LL_ENDL; break; - case MAP_WEIGHT: LL_INFOS() << "Missing weight" << LL_ENDL; break; - case MAP_WEIGHT4: LL_INFOS() << "Missing weightx4" << LL_ENDL; break; - case MAP_CLOTHWEIGHT: LL_INFOS() << "Missing clothweight" << LL_ENDL; break; - case MAP_TEXTURE_INDEX: LL_INFOS() << "Missing tex index" << LL_ENDL; break; - default: LL_INFOS() << "Missing who effin knows: " << unsatisfied_flag << LL_ENDL; - } - } - - if (unsatisfied_mask & (1 << TYPE_INDEX)) - { - LL_INFOS() << "Missing indices" << LL_ENDL; - } + switch (unsatisfied_flag) + { + case 0: break; + case MAP_VERTEX: LL_INFOS() << "Missing vert pos" << LL_ENDL; break; + case MAP_NORMAL: LL_INFOS() << "Missing normals" << LL_ENDL; break; + case MAP_TEXCOORD0: LL_INFOS() << "Missing TC 0" << LL_ENDL; break; + case MAP_TEXCOORD1: LL_INFOS() << "Missing TC 1" << LL_ENDL; break; + case MAP_TEXCOORD2: LL_INFOS() << "Missing TC 2" << LL_ENDL; break; + case MAP_TEXCOORD3: LL_INFOS() << "Missing TC 3" << LL_ENDL; break; + case MAP_COLOR: LL_INFOS() << "Missing vert color" << LL_ENDL; break; + case MAP_EMISSIVE: LL_INFOS() << "Missing emissive" << LL_ENDL; break; + case MAP_TANGENT: LL_INFOS() << "Missing tangent" << LL_ENDL; break; + case MAP_WEIGHT: LL_INFOS() << "Missing weight" << LL_ENDL; break; + case MAP_WEIGHT4: LL_INFOS() << "Missing weightx4" << LL_ENDL; break; + case MAP_CLOTHWEIGHT: LL_INFOS() << "Missing clothweight" << LL_ENDL; break; + case MAP_TEXTURE_INDEX: LL_INFOS() << "Missing tex index" << LL_ENDL; break; + default: LL_INFOS() << "Missing who effin knows: " << unsatisfied_flag << LL_ENDL; + } + } + + // TYPE_INDEX is beyond TYPE_MAX, so check for it individually + if (unsatisfied_mask & (1 << TYPE_INDEX)) + { + LL_INFOS() << "Missing indices" << LL_ENDL; + } LL_ERRS() << "Shader consumption mismatches data provision." << LL_ENDL; } diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index c89d7e3958..9867bd16d6 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -179,8 +179,8 @@ public: TYPE_WEIGHT4, TYPE_CLOTHWEIGHT, TYPE_TEXTURE_INDEX, - TYPE_MAX, - TYPE_INDEX, + TYPE_MAX, // TYPE_MAX is the size/boundary marker for attributes that go in the vertex buffer + TYPE_INDEX, // TYPE_INDEX is beyond _MAX because it lives in a separate (index) buffer }; enum { MAP_VERTEX = (1< Date: Tue, 7 Apr 2020 14:07:45 -0700 Subject: SL-10449 Fix off-by-one line numbers when dumping shader that failed to compile/link --- indra/llrender/llshadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 896dd566c1..8cfccb944c 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -580,7 +580,7 @@ void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_cod if (last == '\n') line[len - 1] = 0; - LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL; + LL_SHADER_LOADING_WARNS() << i+1 << ": " << shader_code_text[i] << LL_ENDL; if (last == '\n') line[len - 1] = '\n'; -- cgit v1.2.3 From 0b717e2d1a0ca19eb8b4e9f20375e3a413ed2879 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 7 Apr 2020 14:22:24 -0700 Subject: SL-10449 Cleanup dumping shader without LOG spam on every line when it fails to compile/link --- indra/llrender/llshadermgr.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 8cfccb944c..86eea458c5 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -572,18 +572,7 @@ void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_cod { for (U32 i = 0; i < shader_code_count; i++) { - GLcharARB *line = shader_code_text[i]; - size_t len = strlen( line ); - GLcharARB last = len > 0 ? line[len - 1] : 0; - - // LL_ENDL already outputs a newline so temporarily strip off the end newline to prevent EVERY line outputting an (extra) blank line - if (last == '\n') - line[len - 1] = 0; - - LL_SHADER_LOADING_WARNS() << i+1 << ": " << shader_code_text[i] << LL_ENDL; - - if (last == '\n') - line[len - 1] = '\n'; + fprintf(stderr, "%4d: %s", i+1, shader_code_text[i]); } LL_SHADER_LOADING_WARNS() << LL_ENDL; } -- cgit v1.2.3 From e4f72db20d4ed2510557449a8f1a66a052c07bea Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 7 Apr 2020 16:21:39 -0700 Subject: SL-10449: Add dumping of shader to log file --- indra/llrender/llshadermgr.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 86eea458c5..539091c1aa 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -569,12 +569,18 @@ static std::string get_object_log(GLhandleARB ret) //dump shader source for debugging void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text) -{ +{ + char num_str[16]; // U32 = max 10 digits + + LL_SHADER_LOADING_WARNS() << "\n"; + for (U32 i = 0; i < shader_code_count; i++) { - fprintf(stderr, "%4d: %s", i+1, shader_code_text[i]); + snprintf(num_str, sizeof(num_str), "%4d: ", i+1); + std::string line_number(num_str); + LL_CONT << line_number << shader_code_text[i]; } - LL_SHADER_LOADING_WARNS() << LL_ENDL; + LL_CONT << LL_ENDL; } void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename) -- cgit v1.2.3 From af7563968c053b5cdce1f01d548c724ca1911e35 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 7 Apr 2020 16:22:25 -0700 Subject: SL-10449: Put first shader error on new line for readability --- indra/llrender/llshadermgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 539091c1aa..1383020873 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -594,8 +594,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& if (log.length() > 0) { - LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << ":\n" << LL_ENDL; - LL_SHADER_LOADING_WARNS() << log << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << LL_ENDL; + LL_SHADER_LOADING_WARNS() << "\n" << log << LL_ENDL; } } -- cgit v1.2.3