create_shader_program.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef IGL_OPENGL_CREATE_SHADER_PROGRAM_H
  9. #define IGL_OPENGL_CREATE_SHADER_PROGRAM_H
  10. #include "../igl_inline.h"
  11. #include <string>
  12. #include <map>
  13. #include "OpenGL_convenience.h"
  14. namespace igl
  15. {
  16. namespace opengl
  17. {
  18. // Create a shader program with a vertex and fragments shader loading from
  19. // source strings and vertex attributes assigned from a map before linking the
  20. // shaders to the program, making it ready to use with glUseProgram(id)
  21. // Inputs:
  22. // geom_source string containing source code of geometry shader (can be
  23. // "" to mean use default pass-through)
  24. // vert_source string containing source code of vertex shader
  25. // frag_source string containing source code of fragment shader
  26. // attrib map containing table of vertex attribute strings add their
  27. // correspondingly ids (generated previously using glBindAttribLocation)
  28. // Outputs:
  29. // id index id of created shader, set to 0 on error
  30. // Returns true on success, false on error
  31. //
  32. // Note: Caller is responsible for making sure that current value of id is not
  33. // leaking a shader (since it will be overwritten)
  34. //
  35. // See also: destroy_shader_program
  36. IGL_INLINE bool create_shader_program(
  37. const std::string &geom_source,
  38. const std::string &vert_source,
  39. const std::string &frag_source,
  40. const std::map<std::string,GLuint> &attrib,
  41. GLuint & id);
  42. IGL_INLINE bool create_shader_program(
  43. const std::string &vert_source,
  44. const std::string &frag_source,
  45. const std::map<std::string,GLuint> &attrib,
  46. GLuint & id);
  47. IGL_INLINE GLuint create_shader_program(
  48. const std::string & geom_source,
  49. const std::string & vert_source,
  50. const std::string & frag_source,
  51. const std::map<std::string,GLuint> &attrib);
  52. IGL_INLINE GLuint create_shader_program(
  53. const std::string & vert_source,
  54. const std::string & frag_source,
  55. const std::map<std::string,GLuint> &attrib);
  56. }
  57. }
  58. #ifndef IGL_STATIC_LIBRARY
  59. # include "create_shader_program.cpp"
  60. #endif
  61. #endif