OpenGL_shader.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef IGL_OPENGL_SHADER_H
  2. #define IGL_OPENGL_SHADER_H
  3. #include <igl/igl_inline.h>
  4. namespace igl
  5. {
  6. class OpenGL_shader
  7. {
  8. public:
  9. typedef unsigned int GLuint;
  10. typedef int GLint;
  11. GLuint vertex_shader;
  12. GLuint fragment_shader;
  13. GLuint geometry_shader;
  14. GLuint program_shader;
  15. IGL_INLINE OpenGL_shader() : vertex_shader(0), fragment_shader(0),
  16. geometry_shader(0), program_shader(0) { }
  17. // Create a new shader from the specified source strings
  18. IGL_INLINE bool init(const std::string &vertex_shader_string,
  19. const std::string &fragment_shader_string,
  20. const std::string &fragment_data_name,
  21. const std::string &geometry_shader_string = "",
  22. int geometry_shader_max_vertices = 3);
  23. // Create a new shader from the specified files on disk
  24. IGL_INLINE bool init_from_files(const std::string &vertex_shader_filename,
  25. const std::string &fragment_shader_filename,
  26. const std::string &fragment_data_name,
  27. const std::string &geometry_shader_filename = "",
  28. int geometry_shader_max_vertices = 3);
  29. // Select this shader for subsequent draw calls
  30. IGL_INLINE void bind();
  31. // Release all OpenGL objects
  32. IGL_INLINE void free();
  33. // Return the OpenGL handle of a named shader attribute (-1 if it does not exist)
  34. IGL_INLINE GLint attrib(const std::string &name) const;
  35. // Return the OpenGL handle of a uniform attribute (-1 if it does not exist)
  36. IGL_INLINE GLint uniform(const std::string &name) const;
  37. // Bind a per-vertex array attribute and refresh its contents from an Eigen amtrix
  38. IGL_INLINE GLint bindVertexAttribArray(const std::string &name, GLuint bufferID,
  39. const Eigen::MatrixXf &M, bool refresh) const;
  40. IGL_INLINE GLuint create_shader_helper(GLint type, const std::string &shader_string);
  41. };
  42. }
  43. #ifndef IGL_STATIC_LIBRARY
  44. # include "OpenGL_shader.cpp"
  45. #endif
  46. #endif