OpenGL_state.h 3.5 KB

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