compile_shader.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "compile_shader.h"
  9. #include "report_gl_error.h"
  10. #include <iostream>
  11. #ifndef IGL_NO_OPENGL
  12. IGL_INLINE GLuint igl::compile_shader(const GLint type, const char * str)
  13. {
  14. GLuint id = glCreateShader(type);
  15. igl::report_gl_error("glCreateShader: ");
  16. glShaderSource(id,1,&str,NULL);
  17. igl::report_gl_error("glShaderSource: ");
  18. glCompileShader(id);
  19. igl::report_gl_error("glCompileShader: ");
  20. GLint status;
  21. glGetShaderiv(id, GL_COMPILE_STATUS, &status);
  22. if (status != GL_TRUE)
  23. {
  24. char buffer[512];
  25. if (type == GL_VERTEX_SHADER)
  26. std::cerr << "Vertex shader:" << std::endl;
  27. else if (type == GL_FRAGMENT_SHADER)
  28. std::cerr << "Fragment shader:" << std::endl;
  29. std::cerr << str << std::endl << std::endl;
  30. glGetShaderInfoLog(id, 512, NULL, buffer);
  31. std::cerr << "Error: " << std::endl << buffer << std::endl;
  32. }
  33. return id;
  34. }
  35. #endif