Help end child hunger

GLSL Tutorial – Cleaning Up

Prev: Troubleshooting: the Infolog Next: Data Types

In a previous subsection a function to attach a shader to a program was presented. A function to detach a shader from a program is also available.

The Syntax is as follows:

[stextbox]void glDetachShader(GLuint program, GLuint shader);


  • program – The program to detach from;
  • shader – The shader to detach.


Only shaders that are not attached can be effectively deleted so this operation is not irrelevant. To delete a shader, or a program, use the following functions:

[stextbox]void glDeleteShader(GLuint id);
void glDeleteProgram(GLuint id);


  • id – The handler of the shader or program to delete.


In the case of a shader that is still attached to some (one or more) programs, the shader is not actually deleted, but only marked for deletion. The delete operation will only be concluded when the shader is no longer attached to any program, i.e. it has been detached from all programs it was attached to.

This makes a case for early deletion of a shader. If an application starts by creating all its programs, and attach all the shaders to create the pipelines, then the shaders can be deleted as soon as they are attached to a program. Being attached prevents the shaders from being actually deleted, marking them for deletion. Once the application starts its shutdown process all that it is required is to delete the programs, and as soon as a shader is no longer attached to a program it will be automatically be deleted. I’m not sure how this is implemented and if it actually works in practice, but it sounds nice on paper 🙂


Prev: Troubleshooting: the Infolog Next: Data Types

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: