Deleting program does not delete shaders that are marked

TRAC #12012 Also fixes failure to delete flagged program upon glUseProgram(0). Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Andrew Lewycky git-svn-id: https://angleproject.googlecode.com/svn/trunk@201 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent feba9ba5
...@@ -550,12 +550,13 @@ void Context::useProgram(GLuint program) ...@@ -550,12 +550,13 @@ void Context::useProgram(GLuint program)
{ {
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
GLuint priorProgram = currentProgram;
currentProgram = program; // Must switch before trying to delete, otherwise it only gets flagged.
if (programObject && programObject->isFlaggedForDeletion()) if (programObject && programObject->isFlaggedForDeletion())
{ {
deleteProgram(currentProgram); deleteProgram(priorProgram);
} }
currentProgram = program;
} }
void Context::setFramebufferZero(Framebuffer *buffer) void Context::setFramebufferZero(Framebuffer *buffer)
......
...@@ -58,6 +58,16 @@ Program::Program() ...@@ -58,6 +58,16 @@ Program::Program()
Program::~Program() Program::~Program()
{ {
unlink(true); unlink(true);
if (mVertexShader != NULL)
{
mVertexShader->detach();
}
if (mFragmentShader != NULL)
{
mFragmentShader->detach();
}
} }
bool Program::attachShader(Shader *shader) bool Program::attachShader(Shader *shader)
......
...@@ -185,6 +185,11 @@ void Shader::attach() ...@@ -185,6 +185,11 @@ void Shader::attach()
void Shader::detach() void Shader::detach()
{ {
mAttachCount--; mAttachCount--;
if (mAttachCount == 0 && mDeleteStatus)
{
getContext()->deleteShader(mHandle);
}
} }
bool Shader::isAttached() const bool Shader::isAttached() const
...@@ -192,11 +197,6 @@ bool Shader::isAttached() const ...@@ -192,11 +197,6 @@ bool Shader::isAttached() const
return mAttachCount > 0; return mAttachCount > 0;
} }
bool Shader::isDeletable() const
{
return mDeleteStatus == true && mAttachCount == 0;
}
bool Shader::isFlaggedForDeletion() const bool Shader::isFlaggedForDeletion() const
{ {
return mDeleteStatus; return mDeleteStatus;
......
...@@ -44,7 +44,6 @@ class Shader ...@@ -44,7 +44,6 @@ class Shader
void attach(); void attach();
void detach(); void detach();
bool isAttached() const; bool isAttached() const;
bool isDeletable() const;
bool isFlaggedForDeletion() const; bool isFlaggedForDeletion() const;
void flagForDeletion(); void flagForDeletion();
......
...@@ -1346,11 +1346,6 @@ void __stdcall glDetachShader(GLuint program, GLuint shader) ...@@ -1346,11 +1346,6 @@ void __stdcall glDetachShader(GLuint program, GLuint shader)
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
if (shaderObject->isDeletable())
{
context->deleteShader(shader);
}
} }
} }
catch(std::bad_alloc&) catch(std::bad_alloc&)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment