compile_and_link_program.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_and_link_program.h"
  9. #include "compile_shader.h"
  10. #include "report_gl_error.h"
  11. #include <iostream>
  12. #include <cassert>
  13. IGL_INLINE GLuint igl::opengl::compile_and_link_program(
  14. const char * v_str, const char * f_str)
  15. {
  16. GLuint vid = compile_shader(GL_VERTEX_SHADER,v_str);
  17. GLuint fid = compile_shader(GL_FRAGMENT_SHADER,f_str);
  18. GLuint prog_id = glCreateProgram();
  19. assert(prog_id != 0 && "Failed to create shader.");
  20. glAttachShader(prog_id,vid);
  21. report_gl_error("glAttachShader (vid): ");
  22. glAttachShader(prog_id,fid);
  23. report_gl_error("glAttachShader (fid): ");
  24. glLinkProgram(prog_id);
  25. report_gl_error("glLinkProgram: ");
  26. GLint status;
  27. glGetProgramiv(prog_id, GL_LINK_STATUS, &status);
  28. if (status != GL_TRUE)
  29. {
  30. char buffer[512];
  31. glGetProgramInfoLog(prog_id, 512, NULL, buffer);
  32. std::cerr << "Linker error: " << std::endl << buffer << std::endl;
  33. prog_id = 0;
  34. }
  35. return prog_id;
  36. }