destroy_shader_program.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "destroy_shader_program.h"
  9. #ifndef IGL_NO_OPENGL
  10. #include <cstdio>
  11. #include "report_gl_error.h"
  12. IGL_INLINE bool igl::destroy_shader_program(const GLuint id)
  13. {
  14. // Don't try to destroy id == 0 (no shader program)
  15. if(id == 0)
  16. {
  17. fprintf(stderr,"Error: destroy_shader_program() id = %d"
  18. " but must should be positive\n",id);
  19. return false;
  20. }
  21. // Get each attached shader one by one and detach and delete it
  22. GLsizei count;
  23. // shader id
  24. GLuint s;
  25. do
  26. {
  27. // Try to get at most *1* attached shader
  28. glGetAttachedShaders(id,1,&count,&s);
  29. GLenum err = igl::report_gl_error();
  30. if (GL_NO_ERROR != err)
  31. {
  32. return false;
  33. }
  34. // Check that we actually got *1*
  35. if(count == 1)
  36. {
  37. // Detach and delete this shader
  38. glDetachShader(id,s);
  39. glDeleteShader(s);
  40. }
  41. }while(count > 0);
  42. // Now that all of the shaders are gone we can just delete the program
  43. glDeleteProgram(id);
  44. return true;
  45. }
  46. #endif