Reduced LL's leakage of program/shader objects, drastically.

Re-structured some shader loading/unloading handling.

These changes are pretty experimental. I'll be holding off of tweaking the paramater managers(among other things) until I know if this stuff is working correctly.
This commit is contained in:
Shyotl
2011-02-10 18:21:38 -06:00
parent d0feea7ed7
commit 7d3e9723c3
6 changed files with 151 additions and 216 deletions

View File

@@ -69,9 +69,10 @@ hasGamma(false), hasLighting(false), calculatesAtmospherics(false)
//===============================
// LLGLSL Shader implementation
//===============================
LLGLSLShader::LLGLSLShader()
: mProgramObject(0), mShaderLevel(0), mShaderGroup(SG_DEFAULT)
LLGLSLShader::LLGLSLShader(S32 shader_class)
: mProgramObject(0), mShaderClass(shader_class), mShaderLevel(0), mShaderGroup(SG_DEFAULT)
{
LLShaderMgr::getGlobalShaderList().push_back(this);
}
void LLGLSLShader::unload()
@@ -84,17 +85,18 @@ void LLGLSLShader::unload()
if (mProgramObject)
{
GLhandleARB obj[1024];
//Don't do this! Attached objects are already flagged for deletion.
//They will be deleted when no programs have them attached. (deleting a program auto-detaches them!)
/*GLhandleARB obj[1024];
GLsizei count;
glGetAttachedObjectsARB(mProgramObject, 1024, &count, obj);
for (GLsizei i = 0; i < count; i++)
for (GLsizei i = 0; i < count; i++)
{
glDeleteObjectARB(obj[i]);
}
glDeleteObjectARB(mProgramObject);
}*/
if(mProgramObject)
glDeleteObjectARB(mProgramObject);
mProgramObject = 0;
}
@@ -110,12 +112,17 @@ BOOL LLGLSLShader::createShader(vector<string> * attributes,
llassert_always(!mShaderFiles.empty());
BOOL success = TRUE;
if(mProgramObject) //purge the old program
glDeleteObjectARB(mProgramObject);
// Create program
mProgramObject = glCreateProgramObjectARB();
// Attach existing objects
if (!LLShaderMgr::instance()->attachShaderFeatures(this))
{
if(mProgramObject)
glDeleteObjectARB(mProgramObject);
mProgramObject = 0;
return FALSE;
}
@@ -145,6 +152,10 @@ BOOL LLGLSLShader::createShader(vector<string> * attributes,
}
if( !success )
{
if(mProgramObject)
glDeleteObjectARB(mProgramObject);
mProgramObject = 0;
LL_WARNS("ShaderLoading") << "Failed to link shader: " << mName << LL_ENDL;
// Try again using a lower shader level;

View File

@@ -67,7 +67,7 @@ public:
SG_WATER
};
LLGLSLShader();
LLGLSLShader(S32 shader_class);
void unload();
BOOL createShader(std::vector<std::string> * attributes,
@@ -134,6 +134,7 @@ public:
std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value
std::vector<GLint> mTexture;
S32 mActiveTextureChannels;
S32 mShaderClass;
S32 mShaderLevel;
S32 mShaderGroup;
BOOL mUniformsDirty;

View File

@@ -385,6 +385,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
if (error != GL_NO_ERROR)
{
LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL;
glDeleteObjectARB(ret); //no longer need handle
}
else
{
@@ -394,6 +395,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
if (error != GL_NO_ERROR)
{
LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL;
glDeleteObjectARB(ret); //no longer need handle
}
}
}
@@ -413,6 +415,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
//an error occured, print log
LL_WARNS("ShaderLoading") << "GLSL Compilation Error: (" << error << ") in " << filename << LL_ENDL;
dumpObjectLog(ret);
glDeleteObjectARB(ret); //no longer need handle
ret = 0;
}
}

View File

@@ -71,6 +71,9 @@ protected:
// our parameter manager singleton instance
static LLShaderMgr * sInstance;
public:
static void unloadShaderClass(int shader_class);
static std::vector<LLGLSLShader *> &getGlobalShaderList(); //Holds a list of ALL LLGLSLShader objects.
}; //LLShaderMgr
#endif