create_shader_program.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_CREATE_SHADER_PROGRAM_H
  9. #define IGL_CREATE_SHADER_PROGRAM_H
  10. #ifndef IGL_NO_OPENGL
  11. #include "igl_inline.h"
  12. #include <string>
  13. #include <map>
  14. #include "OpenGL_convenience.h"
  15. namespace igl
  16. {
  17. // Create a shader program with a vertex and fragments shader loading from
  18. // source strings and vertex attributes assigned from a map before linking the
  19. // shaders to the program, making it ready to use with glUseProgram(id)
  20. // Inputs:
  21. // geom_source string containing source code of geometry shader (can be
  22. // "" to mean use default pass-through)
  23. // vert_source string containing source code of vertex shader
  24. // frag_source string containing source code of fragment shader
  25. // attrib map containing table of vertex attribute strings add their
  26. // correspondingly ids (generated previously using glBindAttribLocation)
  27. // Outputs:
  28. // id index id of created shader, set to 0 on error
  29. // Returns 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 also: 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. IGL_INLINE bool create_shader_program(
  42. const std::string &vert_source,
  43. const std::string &frag_source,
  44. const std::map<std::string,GLuint> &attrib,
  45. GLuint & id);
  46. IGL_INLINE GLuint create_shader_program(
  47. const std::string & geom_source,
  48. const std::string & vert_source,
  49. const std::string & frag_source,
  50. const std::map<std::string,GLuint> &attrib);
  51. IGL_INLINE GLuint create_shader_program(
  52. const std::string & vert_source,
  53. const std::string & frag_source,
  54. const std::map<std::string,GLuint> &attrib);
  55. }
  56. #ifndef IGL_STATIC_LIBRARY
  57. # include "create_shader_program.cpp"
  58. #endif
  59. #endif
  60. #endif