destroy_shader_program.cpp 978 B

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