OpenGL_shader.h 2.0 KB

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