create_shader_program.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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 "gl.h"
  12. #include <string>
  13. #include <map>
  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. ///
  22. /// @param[in] geom_source string containing source code of geometry shader (can be
  23. /// "" to mean use default pass-through)
  24. /// @param[in] vert_source string containing source code of vertex shader
  25. /// @param[in] frag_source string containing source code of fragment shader
  26. /// @param[in] attrib map containing table of vertex attribute strings add their
  27. /// correspondingly ids (generated previously using glBindAttribLocation)
  28. /// @param[out] id index id of created shader, set to 0 on error
  29. /// @return true on success, false on error
  30. ///
  31. /// \note Caller is responsible for making sure that current value of id is not
  32. /// leaking a shader (since it will be overwritten)
  33. ///
  34. /// \see destroy_shader_program
  35. IGL_INLINE bool create_shader_program(
  36. const std::string &geom_source,
  37. const std::string &vert_source,
  38. const std::string &frag_source,
  39. const std::map<std::string,GLuint> &attrib,
  40. GLuint & id);
  41. /// \overload
  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. /// \overload
  48. ///
  49. /// @return index id of created shader, set to 0 on error
  50. IGL_INLINE GLuint create_shader_program(
  51. const std::string & geom_source,
  52. const std::string & vert_source,
  53. const std::string & frag_source,
  54. const std::map<std::string,GLuint> &attrib);
  55. /// \overload
  56. ///
  57. /// @return index id of created shader, set to 0 on error
  58. IGL_INLINE GLuint create_shader_program(
  59. const std::string & vert_source,
  60. const std::string & frag_source,
  61. const std::map<std::string,GLuint> &attrib);
  62. }
  63. }
  64. #ifndef IGL_STATIC_LIBRARY
  65. # include "create_shader_program.cpp"
  66. #endif
  67. #endif