OpenGL_state.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_VIEWER_OPENGL_STATE_H
  9. #define IGL_VIEWER_OPENGL_STATE_H
  10. // Coverts mesh data inside a igl::viewer::ViewerData class in an OpenGL compatible format
  11. // The class includes a shader and the opengl calls to plot the data
  12. #include <igl/igl_inline.h>
  13. #include <igl/viewer/OpenGL_shader.h>
  14. #include <igl/viewer/ViewerData.h>
  15. namespace igl
  16. {
  17. namespace viewer
  18. {
  19. class OpenGL_state
  20. {
  21. public:
  22. typedef unsigned int GLuint;
  23. GLuint vao_mesh;
  24. GLuint vao_overlay_lines;
  25. GLuint vao_overlay_points;
  26. OpenGL_shader shader_mesh;
  27. OpenGL_shader shader_overlay_lines;
  28. OpenGL_shader shader_overlay_points;
  29. GLuint vbo_V; // Vertices of the current mesh (#V x 3)
  30. GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)
  31. GLuint vbo_V_normals; // Vertices of the current mesh (#V x 3)
  32. GLuint vbo_V_ambient; // Ambient material (#V x 3)
  33. GLuint vbo_V_diffuse; // Diffuse material (#V x 3)
  34. GLuint vbo_V_specular; // Specular material (#V x 3)
  35. GLuint vbo_F; // Faces of the mesh (#F x 3)
  36. GLuint vbo_tex; // Texture
  37. GLuint vbo_lines_F; // Indices of the line overlay
  38. GLuint vbo_lines_V; // Vertices of the line overlay
  39. GLuint vbo_lines_V_colors; // Color values of the line overlay
  40. GLuint vbo_points_F; // Indices of the point overlay
  41. GLuint vbo_points_V; // Vertices of the point overlay
  42. GLuint vbo_points_V_colors; // Color values of the point overlay
  43. // Temporary copy of the content of each VBO
  44. Eigen::MatrixXf V_vbo;
  45. Eigen::MatrixXf V_normals_vbo;
  46. Eigen::MatrixXf V_ambient_vbo;
  47. Eigen::MatrixXf V_diffuse_vbo;
  48. Eigen::MatrixXf V_specular_vbo;
  49. Eigen::MatrixXf V_uv_vbo;
  50. Eigen::MatrixXf lines_V_vbo;
  51. Eigen::MatrixXf lines_V_colors_vbo;
  52. Eigen::MatrixXf points_V_vbo;
  53. Eigen::MatrixXf points_V_colors_vbo;
  54. int tex_u;
  55. int tex_v;
  56. Eigen::Matrix<char,Eigen::Dynamic,1> tex;
  57. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> F_vbo;
  58. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> lines_F_vbo;
  59. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> points_F_vbo;
  60. // Marks dirty buffers that need to be uploaded to OpenGL
  61. uint32_t dirty;
  62. // Initialize shaders and buffers
  63. IGL_INLINE void init();
  64. // Release all resources
  65. IGL_INLINE void free();
  66. // Create a new set of OpenGL buffer objects
  67. IGL_INLINE void init_buffers();
  68. // Update contents from a 'Data' instance
  69. IGL_INLINE void set_data(const igl::viewer::ViewerData &data, bool invert_normals);
  70. // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
  71. IGL_INLINE void bind_mesh();
  72. /// Draw the currently buffered mesh (either solid or wireframe)
  73. IGL_INLINE void draw_mesh(bool solid);
  74. // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls
  75. IGL_INLINE void bind_overlay_lines();
  76. /// Draw the currently buffered line overlay
  77. IGL_INLINE void draw_overlay_lines();
  78. // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls
  79. IGL_INLINE void bind_overlay_points();
  80. /// Draw the currently buffered point overlay
  81. IGL_INLINE void draw_overlay_points();
  82. // Release the OpenGL buffer objects
  83. IGL_INLINE void free_buffers();
  84. };
  85. }
  86. }
  87. #ifndef IGL_STATIC_LIBRARY
  88. # include "OpenGL_state.cpp"
  89. #endif
  90. #endif