State.h 3.6 KB

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