OpenGL_state.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef IGL_OPENGL_STATE_H
  2. #define IGL_OPENGL_STATE_H
  3. // Coverts mesh data inside a igl::ViewerData class in an OpenGL compatible format
  4. // The class includes a shader and the opengl calls to plot the data
  5. #include <igl/igl_inline.h>
  6. #include <igl/viewer/OpenGL_shader.h>
  7. namespace igl
  8. {
  9. class OpenGL_state
  10. {
  11. public:
  12. typedef unsigned int GLuint;
  13. GLuint vao_mesh;
  14. GLuint vao_overlay_lines;
  15. GLuint vao_overlay_points;
  16. OpenGL_shader shader_mesh;
  17. OpenGL_shader shader_overlay_lines;
  18. OpenGL_shader shader_overlay_points;
  19. GLuint vbo_V; // Vertices of the current mesh (#V x 3)
  20. GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)
  21. GLuint vbo_V_normals; // Vertices of the current mesh (#V x 3)
  22. GLuint vbo_V_ambient; // Ambient material (#V x 3)
  23. GLuint vbo_V_diffuse; // Diffuse material (#V x 3)
  24. GLuint vbo_V_specular; // Specular material (#V x 3)
  25. GLuint vbo_F; // Faces of the mesh (#F x 3)
  26. GLuint vbo_tex; // Texture
  27. GLuint vbo_lines_F; // Indices of the line overlay
  28. GLuint vbo_lines_V; // Vertices of the line overlay
  29. GLuint vbo_lines_V_colors; // Color values of the line overlay
  30. GLuint vbo_points_F; // Indices of the point overlay
  31. GLuint vbo_points_V; // Vertices of the point overlay
  32. GLuint vbo_points_V_colors; // Color values of the point overlay
  33. // Temporary copy of the content of each VBO
  34. Eigen::MatrixXf V_vbo;
  35. Eigen::MatrixXf V_normals_vbo;
  36. Eigen::MatrixXf V_ambient_vbo;
  37. Eigen::MatrixXf V_diffuse_vbo;
  38. Eigen::MatrixXf V_specular_vbo;
  39. Eigen::MatrixXf V_uv_vbo;
  40. Eigen::MatrixXf lines_V_vbo;
  41. Eigen::MatrixXf lines_V_colors_vbo;
  42. Eigen::MatrixXf points_V_vbo;
  43. Eigen::MatrixXf points_V_colors_vbo;
  44. int tex_u;
  45. int tex_v;
  46. Eigen::Matrix<char,Eigen::Dynamic,1> tex;
  47. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> F_vbo;
  48. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> lines_F_vbo;
  49. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> points_F_vbo;
  50. // Marks dirty buffers that need to be uploaded to OpenGL
  51. uint32_t dirty;
  52. // Initialize shaders and buffers
  53. IGL_INLINE void init();
  54. // Release all resources
  55. IGL_INLINE void free();
  56. // Create a new set of OpenGL buffer objects
  57. IGL_INLINE void init_buffers();
  58. // Update contents from a 'Data' instance
  59. IGL_INLINE void set_data(const igl::ViewerData &data, bool face_based, bool invert_normals);
  60. // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
  61. IGL_INLINE void bind_mesh();
  62. /// Draw the currently buffered mesh (either solid or wireframe)
  63. IGL_INLINE void draw_mesh(bool solid);
  64. // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls
  65. IGL_INLINE void bind_overlay_lines();
  66. /// Draw the currently buffered line overlay
  67. IGL_INLINE void draw_overlay_lines();
  68. // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls
  69. IGL_INLINE void bind_overlay_points();
  70. /// Draw the currently buffered point overlay
  71. IGL_INLINE void draw_overlay_points();
  72. // Release the OpenGL buffer objects
  73. IGL_INLINE void free_buffers();
  74. enum DirtyFlags
  75. {
  76. DIRTY_NONE = 0x0000,
  77. DIRTY_POSITION = 0x0001,
  78. DIRTY_UV = 0x0002,
  79. DIRTY_NORMAL = 0x0004,
  80. DIRTY_AMBIENT = 0x0008,
  81. DIRTY_DIFFUSE = 0x0010,
  82. DIRTY_SPECULAR = 0x0020,
  83. DIRTY_TEXTURE = 0x0040,
  84. DIRTY_FACE = 0x0080,
  85. DIRTY_MESH = 0x00FF,
  86. DIRTY_OVERLAY_LINES = 0x0100,
  87. DIRTY_OVERLAY_POINTS = 0x0200,
  88. DIRTY_ALL = 0x03FF
  89. };
  90. };
  91. }
  92. #ifndef IGL_STATIC_LIBRARY
  93. # include "OpenGL_state.cpp"
  94. #endif
  95. #endif