OpenGL_state.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #include <igl/viewer/ViewerData.h>
  8. namespace igl
  9. {
  10. class OpenGL_state
  11. {
  12. public:
  13. typedef unsigned int GLuint;
  14. GLuint vao_mesh;
  15. GLuint vao_overlay_lines;
  16. GLuint vao_overlay_points;
  17. OpenGL_shader shader_mesh;
  18. OpenGL_shader shader_overlay_lines;
  19. OpenGL_shader shader_overlay_points;
  20. GLuint vbo_V; // Vertices of the current mesh (#V x 3)
  21. GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)
  22. GLuint vbo_V_normals; // Vertices of the current mesh (#V x 3)
  23. GLuint vbo_V_ambient; // Ambient material (#V x 3)
  24. GLuint vbo_V_diffuse; // Diffuse material (#V x 3)
  25. GLuint vbo_V_specular; // Specular material (#V x 3)
  26. GLuint vbo_F; // Faces of the mesh (#F x 3)
  27. GLuint vbo_tex; // Texture
  28. GLuint vbo_lines_F; // Indices of the line overlay
  29. GLuint vbo_lines_V; // Vertices of the line overlay
  30. GLuint vbo_lines_V_colors; // Color values of the line overlay
  31. GLuint vbo_points_F; // Indices of the point overlay
  32. GLuint vbo_points_V; // Vertices of the point overlay
  33. GLuint vbo_points_V_colors; // Color values of the point overlay
  34. // Temporary copy of the content of each VBO
  35. Eigen::MatrixXf V_vbo;
  36. Eigen::MatrixXf V_normals_vbo;
  37. Eigen::MatrixXf V_ambient_vbo;
  38. Eigen::MatrixXf V_diffuse_vbo;
  39. Eigen::MatrixXf V_specular_vbo;
  40. Eigen::MatrixXf V_uv_vbo;
  41. Eigen::MatrixXf lines_V_vbo;
  42. Eigen::MatrixXf lines_V_colors_vbo;
  43. Eigen::MatrixXf points_V_vbo;
  44. Eigen::MatrixXf points_V_colors_vbo;
  45. int tex_u;
  46. int tex_v;
  47. Eigen::Matrix<char,Eigen::Dynamic,1> tex;
  48. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> F_vbo;
  49. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> lines_F_vbo;
  50. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> points_F_vbo;
  51. // Marks dirty buffers that need to be uploaded to OpenGL
  52. uint32_t dirty;
  53. // Initialize shaders and buffers
  54. IGL_INLINE void init();
  55. // Release all resources
  56. IGL_INLINE void free();
  57. // Create a new set of OpenGL buffer objects
  58. IGL_INLINE void init_buffers();
  59. // Update contents from a 'Data' instance
  60. IGL_INLINE void set_data(const igl::ViewerData &data, bool invert_normals);
  61. // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
  62. IGL_INLINE void bind_mesh();
  63. /// Draw the currently buffered mesh (either solid or wireframe)
  64. IGL_INLINE void draw_mesh(bool solid);
  65. // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls
  66. IGL_INLINE void bind_overlay_lines();
  67. /// Draw the currently buffered line overlay
  68. IGL_INLINE void draw_overlay_lines();
  69. // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls
  70. IGL_INLINE void bind_overlay_points();
  71. /// Draw the currently buffered point overlay
  72. IGL_INLINE void draw_overlay_points();
  73. // Release the OpenGL buffer objects
  74. IGL_INLINE void free_buffers();
  75. };
  76. }
  77. #ifndef IGL_STATIC_LIBRARY
  78. # include "OpenGL_state.cpp"
  79. #endif
  80. #endif