destroy_shader_program.cpp 949 B

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