7.5. Cleaning Up
Objects should be deleted when they are no longer needed, and deletion can be accomplished with the following commands
void glDeleteShader(GLuint shader) | Frees the memory and invalidates the name associated with the shader object specified by shader. This command effectively undoes the effects of a call to glCreateShader.
If a shader object to be deleted is attached to a program object, it will be flagged for deletion, but it will not be deleted until it is no longer attached to any program object for any rendering context (i.e., it must be detached from wherever it was attached before it can be deleted). A value of 0 for shader is silently ignored.
To determine whether a shader object has been flagged for deletion, call glGetShader with arguments shader and GL_DELETE_STATUS. |
void glDeleteProgram(GLuint program) | Frees the memory and invalidates the name associated with the program object specified by program. This command effectively undoes the effects of a call to glCreateProgram.
If a program object is in use as part of a current rendering state, it will be flagged for deletion, but it will not be deleted until it is no longer part of current state for any rendering context. If a program object to be deleted has shader objects attached to it, those shader objects are automatically detached but not deleted unless they have already been flagged for deletion by a previous call to glDeleteShader.
To determine whether a program object has been flagged for deletion, call glGetProgram with arguments program and GL_DELETE_STATUS. |
When a shader object no longer needs to be attached to a program object, it can be detached with the command
void glDetachShader(GLuint program, GLuint shader) | Detaches the shader object specified by shader from the program object specified by program. This command undoes the effect of the command glAttachShader.
If shader has already been flagged for deletion by a call to glDeleteShader and it is not attached to any other program object, it is deleted after it has been detached. |
A programming tip that might be useful in keeping things orderly is to delete shader objects as soon as they have been attached to a program object. They won't be deleted at this time, but they will be flagged for deletion when they are no longer referenced. To clean up later, the application only needs to delete the program object. All the attached shader objects will be automatically detached, and, because they are flagged for deletion, they will be automatically deleted at that time as well.
|