Better robustness when loading shaders. Redundant shaders (eg: "deferred/shadowF.glsl") will only need to be compiled once, and LLShaderMgr::mShaderObjects won't have previous entries mistakenly overwritten as a result.

This commit is contained in:
Shyotl
2012-09-12 02:13:36 -05:00
committed by Siana Gearz
parent 7978f5ebfe
commit afc7c2b449
3 changed files with 21 additions and 5 deletions

View File

@@ -525,6 +525,14 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns)
GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, S32 texture_index_channels)
{
std::pair<std::multimap<std::string, CachedObjectInfo >::iterator, std::multimap<std::string, CachedObjectInfo>::iterator> range;
range = mShaderObjects.equal_range(filename);
for (std::multimap<std::string, CachedObjectInfo>::iterator it = range.first; it != range.second;++it)
{
if((*it).second.mLevel == shader_level && (*it).second.mType == type)
return (*it).second.mHandle;
}
GLenum error = GL_NO_ERROR;
if (gDebugGL)
{
@@ -888,7 +896,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
if (ret)
{
// Add shader file to map
mShaderObjects[filename] = ret;
mShaderObjects.insert(make_pair(filename,CachedObjectInfo(ret,try_gpu_class,type)));
shader_level = try_gpu_class;
}
else

View File

@@ -185,8 +185,16 @@ public:
virtual void updateShaderUniforms(LLGLSLShader * shader) = 0; // Pure Virtual
public:
struct CachedObjectInfo
{
CachedObjectInfo(GLhandleARB handle, U32 level, GLenum type) :
mHandle(handle), mLevel(level), mType(type) {}
GLhandleARB mHandle; //Actual handle of the opengl shader object.
U32 mLevel; //Level /might/ not be needed, but it's stored to ensure there's no change in behavior.
GLenum mType; //GL_VERTEX_SHADER_ARB or GL_FRAGMENT_SHADER_ARB. Tracked because some utility shaders can be loaded as both types (carefully).
};
// Map of shader names to compiled
std::map<std::string, GLhandleARB> mShaderObjects;
std::multimap<std::string, CachedObjectInfo > mShaderObjects; //Singu Note: Packing more info here. Doing such provides capability to skip unneeded duplicate loading..
//global (reserved slot) shader parameters
std::vector<std::string> mReservedAttribs;

View File

@@ -576,10 +576,10 @@ void LLViewerShaderMgr::setShaders()
//Flag base shader objects for deletion
//Don't worry-- they won't be deleted until no programs refrence them.
std::map<std::string, GLhandleARB>::iterator it = mShaderObjects.begin();
std::multimap<std::string, LLShaderMgr::CachedObjectInfo >::iterator it = mShaderObjects.begin();
for(; it!=mShaderObjects.end();++it)
if(it->second)
glDeleteObjectARB(it->second);
if(it->second.mHandle)
glDeleteObjectARB(it->second.mHandle);
mShaderObjects.clear();
}
else