destroy_shader_program.cpp 1.3 KB

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