destroy_shader_program.cpp 819 B

1234567891011121314151617181920212223242526272829303132
  1. #include "destroy_shader_program.h"
  2. #include <cstdio>
  3. IGL_INLINE bool igl::destroy_shader_program(const GLuint id)
  4. {
  5. // Don't try to destroy id == 0 (no shader program)
  6. if(id == 0)
  7. {
  8. fprintf(stderr,"Error: destroy_shader_program() id = %d"
  9. " but must should be positive\n",id);
  10. return false;
  11. }
  12. // Get each attached shader one by one and detach and delete it
  13. GLsizei count;
  14. // shader id
  15. GLuint s;
  16. do
  17. {
  18. // Try to get at most *1* attached shader
  19. glGetAttachedShaders(id,1,&count,&s);
  20. // Check that we actually got *1*
  21. if(count == 1)
  22. {
  23. // Detach and delete this shader
  24. glDetachShader(id,s);
  25. glDeleteShader(s);
  26. }
  27. }while(count > 0);
  28. // Now that all of the shaders are gone we can just delete the program
  29. glDeleteProgram(id);
  30. return true;
  31. }