Help end child hunger

Cleaning Up

 
Prev: The InfoLog Next: Comm. OpenGL => Shaders
 

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 OpenGL 2.0 syntax is as follows:


void glDetachShader(GLuint program, GLuint shader);

Parameter:

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

And the ARB extension syntax is:


void glDetachObjectARB(GLhandleARB program, GLhandleARB shader);

Parameter:

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

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


void glDeleteShader(GLuint id);
void glDeleteProgram(GLuint id);

Parameter:

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

When using the ARB extensions, there is a single function to delete both shaders and programs:


void glDeleteObjectARB(GLhandleARB id);

Parameter:

  • 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.

 

 

Prev: The InfoLog Next: Comm. OpenGL => Shaders
 

  3 Responses to “Cleaning Up”

  1. You could include information that “marked for deletion” also works on program objects and that you disable a program with glUseProgram(0) or glUseProgram(some_other_program_handle).

    Other than that it’s a really good tutorial :).

  2. Thanks for your great tutorials, they have been very helpful in learning about shaders.

    Btw, i’ve noticed some typos in this article: “hanule(r)” -> “handle(r)” (5 times).

Leave a Reply to ARF Cancel reply

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

%d bloggers like this: