create_shader_program.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef IGL_CREATE_SHADER_PROGRAM_H
  2. #define IGL_CREATE_SHADER_PROGRAM_H
  3. #include "igl_inline.h"
  4. #include <string>
  5. #include <map>
  6. #ifdef __APPLE__
  7. # include <OpenGL/gl.h>
  8. #elif defined(_WIN32)
  9. # define NOMINMAX
  10. # include <Windows.h>
  11. # undef NOMINMAX
  12. # include <GL/gl.h>
  13. #else
  14. # define GL_GLEXT_PROTOTYPES
  15. # include <GL/gl.h>
  16. # include <GL/glext.h>
  17. #endif
  18. namespace igl
  19. {
  20. // Create a shader program with a vertex and fragments shader loading from
  21. // source strings and vertex attributes assigned from a map before linking the
  22. // shaders to the program, making it ready to use with glUseProgram(id)
  23. // Inputs:
  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 vert_source,
  38. const std::string frag_source,
  39. const std::map<std::string,GLuint> attrib,
  40. GLuint & id);
  41. }
  42. #ifdef IGL_HEADER_ONLY
  43. # include "create_shader_program.cpp"
  44. #endif
  45. #endif