State.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "Shader.h"
  18. #include "../ViewerData.h"
  19. namespace igl
  20. {
  21. namespace opengl
  22. {
  23. class State
  24. {
  25. public:
  26. typedef unsigned int GLuint;
  27. GLuint vao_mesh;
  28. GLuint vao_overlay_lines;
  29. GLuint vao_overlay_points;
  30. Shader shader_mesh;
  31. Shader shader_overlay_lines;
  32. Shader 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. Eigen::MatrixXf V_vbo;
  49. Eigen::MatrixXf V_normals_vbo;
  50. Eigen::MatrixXf V_ambient_vbo;
  51. Eigen::MatrixXf V_diffuse_vbo;
  52. Eigen::MatrixXf V_specular_vbo;
  53. Eigen::MatrixXf V_uv_vbo;
  54. Eigen::MatrixXf lines_V_vbo;
  55. Eigen::MatrixXf lines_V_colors_vbo;
  56. Eigen::MatrixXf points_V_vbo;
  57. Eigen::MatrixXf points_V_colors_vbo;
  58. int tex_u;
  59. int tex_v;
  60. Eigen::Matrix<char,Eigen::Dynamic,1> tex;
  61. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> F_vbo;
  62. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> lines_F_vbo;
  63. Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> points_F_vbo;
  64. // Marks dirty buffers that need to be uploaded to OpenGL
  65. uint32_t dirty;
  66. // Initialize shaders and buffers
  67. IGL_INLINE void init();
  68. // Release all resources
  69. IGL_INLINE void free();
  70. // Create a new set of OpenGL buffer objects
  71. IGL_INLINE void init_buffers();
  72. // Update contents from a 'Data' instance
  73. IGL_INLINE void set_data(const igl::ViewerData &data, bool invert_normals);
  74. // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
  75. IGL_INLINE void bind_mesh();
  76. /// Draw the currently buffered mesh (either solid or wireframe)
  77. IGL_INLINE void draw_mesh(bool solid);
  78. // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls
  79. IGL_INLINE void bind_overlay_lines();
  80. /// Draw the currently buffered line overlay
  81. IGL_INLINE void draw_overlay_lines();
  82. // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls
  83. IGL_INLINE void bind_overlay_points();
  84. /// Draw the currently buffered point overlay
  85. IGL_INLINE void draw_overlay_points();
  86. // Release the OpenGL buffer objects
  87. IGL_INLINE void free_buffers();
  88. };
  89. }
  90. }
  91. #ifndef IGL_STATIC_LIBRARY
  92. # include "State.cpp"
  93. #endif
  94. #endif