State.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_OPENGL_STATE_H
  9. #define IGL_OPENGL_STATE_H
  10. // Coverts mesh data inside a igl::ViewerData class in an OpenGL
  11. // compatible format The class includes a shader and the opengl calls to plot
  12. // the data
  13. // Alec: not sure why this is call "State". It seems this is a drawable mesh
  14. // equipt with its own shaders and dirty flags. "Mesh" would even be more
  15. // appropriate.
  16. #include <igl/igl_inline.h>
  17. #include "../ViewerData.h"
  18. namespace igl
  19. {
  20. namespace opengl
  21. {
  22. class State
  23. {
  24. public:
  25. typedef unsigned int GLuint;
  26. bool is_initialized = false;
  27. GLuint vao_mesh;
  28. GLuint vao_overlay_lines;
  29. GLuint vao_overlay_points;
  30. GLuint shader_mesh;
  31. GLuint shader_overlay_lines;
  32. GLuint shader_overlay_points;
  33. GLuint vbo_V; // Vertices of the current mesh (#V x 3)
  34. GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)
  35. GLuint vbo_V_normals; // Vertices of the current mesh (#V x 3)
  36. GLuint vbo_V_ambient; // Ambient material (#V x 3)
  37. GLuint vbo_V_diffuse; // Diffuse material (#V x 3)
  38. GLuint vbo_V_specular; // Specular material (#V x 3)
  39. GLuint vbo_F; // Faces of the mesh (#F x 3)
  40. GLuint vbo_tex; // Texture
  41. GLuint vbo_lines_F; // Indices of the line overlay
  42. GLuint vbo_lines_V; // Vertices of the line overlay
  43. GLuint vbo_lines_V_colors; // Color values of the line overlay
  44. GLuint vbo_points_F; // Indices of the point overlay
  45. GLuint vbo_points_V; // Vertices of the point overlay
  46. GLuint vbo_points_V_colors; // Color values of the point overlay
  47. // Temporary copy of the content of each VBO
  48. typedef Eigen::Matrix<float,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> RowMatrixXf;
  49. RowMatrixXf V_vbo;
  50. RowMatrixXf V_normals_vbo;
  51. RowMatrixXf V_ambient_vbo;
  52. RowMatrixXf V_diffuse_vbo;
  53. RowMatrixXf V_specular_vbo;
  54. RowMatrixXf V_uv_vbo;
  55. RowMatrixXf lines_V_vbo;
  56. RowMatrixXf lines_V_colors_vbo;
  57. RowMatrixXf points_V_vbo;
  58. RowMatrixXf points_V_colors_vbo;
  59. int tex_u;
  60. int tex_v;
  61. Eigen::Matrix<char,Eigen::Dynamic,1> tex;
  62. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> F_vbo;
  63. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> lines_F_vbo;
  64. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> points_F_vbo;
  65. // Marks dirty buffers that need to be uploaded to OpenGL
  66. uint32_t dirty;
  67. // Initialize shaders and buffers
  68. IGL_INLINE void init();
  69. // Release all resources
  70. IGL_INLINE void free();
  71. // Create a new set of OpenGL buffer objects
  72. IGL_INLINE void init_buffers();
  73. // Update contents from a 'Data' instance
  74. IGL_INLINE void set_data(const igl::ViewerData &data, bool invert_normals);
  75. // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
  76. IGL_INLINE void bind_mesh();
  77. /// Draw the currently buffered mesh (either solid or wireframe)
  78. IGL_INLINE void draw_mesh(bool solid);
  79. // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls
  80. IGL_INLINE void bind_overlay_lines();
  81. /// Draw the currently buffered line overlay
  82. IGL_INLINE void draw_overlay_lines();
  83. // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls
  84. IGL_INLINE void bind_overlay_points();
  85. /// Draw the currently buffered point overlay
  86. IGL_INLINE void draw_overlay_points();
  87. // Release the OpenGL buffer objects
  88. IGL_INLINE void free_buffers();
  89. };
  90. }
  91. }
  92. #ifndef IGL_STATIC_LIBRARY
  93. # include "State.cpp"
  94. #endif
  95. #endif