State.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. #include "State.h"
  9. #include "../ViewerData.h"
  10. IGL_INLINE void igl::opengl::State::init_buffers()
  11. {
  12. // Mesh: Vertex Array Object & Buffer objects
  13. glGenVertexArrays(1, &vao_mesh);
  14. glBindVertexArray(vao_mesh);
  15. glGenBuffers(1, &vbo_V);
  16. glGenBuffers(1, &vbo_V_normals);
  17. glGenBuffers(1, &vbo_V_ambient);
  18. glGenBuffers(1, &vbo_V_diffuse);
  19. glGenBuffers(1, &vbo_V_specular);
  20. glGenBuffers(1, &vbo_V_uv);
  21. glGenBuffers(1, &vbo_F);
  22. glGenTextures(1, &vbo_tex);
  23. // Line overlay
  24. glGenVertexArrays(1, &vao_overlay_lines);
  25. glBindVertexArray(vao_overlay_lines);
  26. glGenBuffers(1, &vbo_lines_F);
  27. glGenBuffers(1, &vbo_lines_V);
  28. glGenBuffers(1, &vbo_lines_V_colors);
  29. // Point overlay
  30. glGenVertexArrays(1, &vao_overlay_points);
  31. glBindVertexArray(vao_overlay_points);
  32. glGenBuffers(1, &vbo_points_F);
  33. glGenBuffers(1, &vbo_points_V);
  34. glGenBuffers(1, &vbo_points_V_colors);
  35. dirty = ViewerData::DIRTY_ALL;
  36. }
  37. IGL_INLINE void igl::opengl::State::free_buffers()
  38. {
  39. glDeleteVertexArrays(1, &vao_mesh);
  40. glDeleteVertexArrays(1, &vao_overlay_lines);
  41. glDeleteVertexArrays(1, &vao_overlay_points);
  42. glDeleteBuffers(1, &vbo_V);
  43. glDeleteBuffers(1, &vbo_V_normals);
  44. glDeleteBuffers(1, &vbo_V_ambient);
  45. glDeleteBuffers(1, &vbo_V_diffuse);
  46. glDeleteBuffers(1, &vbo_V_specular);
  47. glDeleteBuffers(1, &vbo_V_uv);
  48. glDeleteBuffers(1, &vbo_F);
  49. glDeleteBuffers(1, &vbo_lines_F);
  50. glDeleteBuffers(1, &vbo_lines_V);
  51. glDeleteBuffers(1, &vbo_lines_V_colors);
  52. glDeleteBuffers(1, &vbo_points_F);
  53. glDeleteBuffers(1, &vbo_points_V);
  54. glDeleteBuffers(1, &vbo_points_V_colors);
  55. glDeleteTextures(1, &vbo_tex);
  56. }
  57. IGL_INLINE void igl::opengl::State::set_data(const igl::ViewerData &data, bool invert_normals)
  58. {
  59. bool per_corner_uv = (data.F_uv.rows() == data.F.rows());
  60. bool per_corner_normals = (data.F_normals.rows() == 3 * data.F.rows());
  61. dirty |= data.dirty;
  62. if (!data.face_based)
  63. {
  64. if (!per_corner_uv)
  65. {
  66. // Vertex positions
  67. if (dirty & ViewerData::DIRTY_POSITION)
  68. V_vbo = (data.V.transpose()).cast<float>();
  69. // Vertex normals
  70. if (dirty & ViewerData::DIRTY_NORMAL)
  71. {
  72. V_normals_vbo = (data.V_normals.transpose()).cast<float>();
  73. if (invert_normals)
  74. V_normals_vbo = -V_normals_vbo;
  75. }
  76. // Per-vertex material settings
  77. if (dirty & ViewerData::DIRTY_AMBIENT)
  78. V_ambient_vbo = (data.V_material_ambient.transpose()).cast<float>();
  79. if (dirty & ViewerData::DIRTY_DIFFUSE)
  80. V_diffuse_vbo = (data.V_material_diffuse.transpose()).cast<float>();
  81. if (dirty & ViewerData::DIRTY_SPECULAR)
  82. V_specular_vbo = (data.V_material_specular.transpose()).cast<float>();
  83. // Face indices
  84. if (dirty & ViewerData::DIRTY_FACE)
  85. F_vbo = (data.F.transpose()).cast<unsigned>();
  86. // Texture coordinates
  87. if (dirty & ViewerData::DIRTY_UV)
  88. V_uv_vbo = (data.V_uv.transpose()).cast<float>();
  89. }
  90. else
  91. {
  92. // Per vertex properties with per corner UVs
  93. if (dirty & ViewerData::DIRTY_POSITION)
  94. {
  95. V_vbo.resize(3,data.F.rows()*3);
  96. for (unsigned i=0; i<data.F.rows();++i)
  97. for (unsigned j=0;j<3;++j)
  98. V_vbo.col(i*3+j) = data.V.row(data.F(i,j)).transpose().cast<float>();
  99. }
  100. if (dirty & ViewerData::DIRTY_AMBIENT)
  101. {
  102. V_ambient_vbo.resize(3,data.F.rows()*3);
  103. for (unsigned i=0; i<data.F.rows();++i)
  104. for (unsigned j=0;j<3;++j)
  105. V_ambient_vbo.col (i*3+j) = data.V_material_ambient.row(data.F(i,j)).transpose().cast<float>();
  106. }
  107. if (dirty & ViewerData::DIRTY_DIFFUSE)
  108. {
  109. V_diffuse_vbo.resize(3,data.F.rows()*3);
  110. for (unsigned i=0; i<data.F.rows();++i)
  111. for (unsigned j=0;j<3;++j)
  112. V_diffuse_vbo.col (i*3+j) = data.V_material_diffuse.row(data.F(i,j)).transpose().cast<float>();
  113. }
  114. if (dirty & ViewerData::DIRTY_SPECULAR)
  115. {
  116. V_specular_vbo.resize(3,data.F.rows()*3);
  117. for (unsigned i=0; i<data.F.rows();++i)
  118. for (unsigned j=0;j<3;++j)
  119. V_specular_vbo.col(i*3+j) = data.V_material_specular.row(data.F(i,j)).transpose().cast<float>();
  120. }
  121. if (dirty & ViewerData::DIRTY_NORMAL)
  122. {
  123. V_normals_vbo.resize(3,data.F.rows()*3);
  124. for (unsigned i=0; i<data.F.rows();++i)
  125. for (unsigned j=0;j<3;++j)
  126. V_normals_vbo.col (i*3+j) = data.V_normals.row(data.F(i,j)).transpose().cast<float>();
  127. if (invert_normals)
  128. V_normals_vbo = -V_normals_vbo;
  129. }
  130. if (dirty & ViewerData::DIRTY_FACE)
  131. {
  132. F_vbo.resize(3,data.F.rows());
  133. for (unsigned i=0; i<data.F.rows();++i)
  134. F_vbo.col(i) << i*3+0, i*3+1, i*3+2;
  135. }
  136. if (dirty & ViewerData::DIRTY_UV)
  137. {
  138. V_uv_vbo.resize(2,data.F.rows()*3);
  139. for (unsigned i=0; i<data.F.rows();++i)
  140. for (unsigned j=0;j<3;++j)
  141. V_uv_vbo.col(i*3+j) = data.V_uv.row(data.F(i,j)).transpose().cast<float>();
  142. }
  143. }
  144. }
  145. else
  146. {
  147. if (dirty & ViewerData::DIRTY_POSITION)
  148. {
  149. V_vbo.resize(3,data.F.rows()*3);
  150. for (unsigned i=0; i<data.F.rows();++i)
  151. for (unsigned j=0;j<3;++j)
  152. V_vbo.col(i*3+j) = data.V.row(data.F(i,j)).transpose().cast<float>();
  153. }
  154. if (dirty & ViewerData::DIRTY_AMBIENT)
  155. {
  156. V_ambient_vbo.resize(4,data.F.rows()*3);
  157. for (unsigned i=0; i<data.F.rows();++i)
  158. for (unsigned j=0;j<3;++j)
  159. V_ambient_vbo.col (i*3+j) = data.F_material_ambient.row(i).transpose().cast<float>();
  160. }
  161. if (dirty & ViewerData::DIRTY_DIFFUSE)
  162. {
  163. V_diffuse_vbo.resize(4,data.F.rows()*3);
  164. for (unsigned i=0; i<data.F.rows();++i)
  165. for (unsigned j=0;j<3;++j)
  166. V_diffuse_vbo.col (i*3+j) = data.F_material_diffuse.row(i).transpose().cast<float>();
  167. }
  168. if (dirty & ViewerData::DIRTY_SPECULAR)
  169. {
  170. V_specular_vbo.resize(4,data.F.rows()*3);
  171. for (unsigned i=0; i<data.F.rows();++i)
  172. for (unsigned j=0;j<3;++j)
  173. V_specular_vbo.col(i*3+j) = data.F_material_specular.row(i).transpose().cast<float>();
  174. }
  175. if (dirty & ViewerData::DIRTY_NORMAL)
  176. {
  177. V_normals_vbo.resize(3,data.F.rows()*3);
  178. for (unsigned i=0; i<data.F.rows();++i)
  179. for (unsigned j=0;j<3;++j)
  180. V_normals_vbo.col (i*3+j) =
  181. per_corner_normals ?
  182. data.F_normals.row(i*3+j).transpose().cast<float>() :
  183. data.F_normals.row(i).transpose().cast<float>();
  184. if (invert_normals)
  185. V_normals_vbo = -V_normals_vbo;
  186. }
  187. if (dirty & ViewerData::DIRTY_FACE)
  188. {
  189. F_vbo.resize(3,data.F.rows());
  190. for (unsigned i=0; i<data.F.rows();++i)
  191. F_vbo.col(i) << i*3+0, i*3+1, i*3+2;
  192. }
  193. if (dirty & ViewerData::DIRTY_UV)
  194. {
  195. V_uv_vbo.resize(2,data.F.rows()*3);
  196. for (unsigned i=0; i<data.F.rows();++i)
  197. for (unsigned j=0;j<3;++j)
  198. V_uv_vbo.col(i*3+j) = data.V_uv.row(per_corner_uv ? data.F_uv(i,j) : data.F(i,j)).transpose().cast<float>();
  199. }
  200. }
  201. if (dirty & ViewerData::DIRTY_TEXTURE)
  202. {
  203. tex_u = data.texture_R.rows();
  204. tex_v = data.texture_R.cols();
  205. tex.resize(data.texture_R.size()*4);
  206. for (unsigned i=0;i<data.texture_R.size();++i)
  207. {
  208. tex(i*4+0) = data.texture_R(i);
  209. tex(i*4+1) = data.texture_G(i);
  210. tex(i*4+2) = data.texture_B(i);
  211. tex(i*4+3) = data.texture_A(i);
  212. }
  213. }
  214. if (dirty & ViewerData::DIRTY_OVERLAY_LINES)
  215. {
  216. lines_V_vbo.resize(3, data.lines.rows()*2);
  217. lines_V_colors_vbo.resize(3, data.lines.rows()*2);
  218. lines_F_vbo.resize(1, data.lines.rows()*2);
  219. for (unsigned i=0; i<data.lines.rows();++i)
  220. {
  221. lines_V_vbo.col(2*i+0) = data.lines.block<1, 3>(i, 0).transpose().cast<float>();
  222. lines_V_vbo.col(2*i+1) = data.lines.block<1, 3>(i, 3).transpose().cast<float>();
  223. lines_V_colors_vbo.col(2*i+0) = data.lines.block<1, 3>(i, 6).transpose().cast<float>();
  224. lines_V_colors_vbo.col(2*i+1) = data.lines.block<1, 3>(i, 6).transpose().cast<float>();
  225. lines_F_vbo(2*i+0) = 2*i+0;
  226. lines_F_vbo(2*i+1) = 2*i+1;
  227. }
  228. }
  229. if (dirty & ViewerData::DIRTY_OVERLAY_POINTS)
  230. {
  231. points_V_vbo.resize(3, data.points.rows());
  232. points_V_colors_vbo.resize(3, data.points.rows());
  233. points_F_vbo.resize(1, data.points.rows());
  234. for (unsigned i=0; i<data.points.rows();++i)
  235. {
  236. points_V_vbo.col(i) = data.points.block<1, 3>(i, 0).transpose().cast<float>();
  237. points_V_colors_vbo.col(i) = data.points.block<1, 3>(i, 3).transpose().cast<float>();
  238. points_F_vbo(i) = i;
  239. }
  240. }
  241. }
  242. IGL_INLINE void igl::opengl::State::bind_mesh()
  243. {
  244. glBindVertexArray(vao_mesh);
  245. shader_mesh.bind();
  246. shader_mesh.bindVertexAttribArray("position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION);
  247. shader_mesh.bindVertexAttribArray("normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL);
  248. shader_mesh.bindVertexAttribArray("Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT);
  249. shader_mesh.bindVertexAttribArray("Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE);
  250. shader_mesh.bindVertexAttribArray("Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR);
  251. shader_mesh.bindVertexAttribArray("texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV);
  252. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_F);
  253. if (dirty & ViewerData::DIRTY_FACE)
  254. glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*F_vbo.size(), F_vbo.data(), GL_DYNAMIC_DRAW);
  255. glActiveTexture(GL_TEXTURE0);
  256. glBindTexture(GL_TEXTURE_2D, vbo_tex);
  257. if (dirty & ViewerData::DIRTY_TEXTURE)
  258. {
  259. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  260. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  261. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  262. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  263. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  264. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_u, tex_v, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data());
  265. }
  266. glUniform1i(shader_mesh.uniform("tex"), 0);
  267. dirty &= ~ViewerData::DIRTY_MESH;
  268. }
  269. IGL_INLINE void igl::opengl::State::bind_overlay_lines()
  270. {
  271. bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_LINES;
  272. glBindVertexArray(vao_overlay_lines);
  273. shader_overlay_lines.bind();
  274. shader_overlay_lines.bindVertexAttribArray("position", vbo_lines_V, lines_V_vbo, is_dirty);
  275. shader_overlay_lines.bindVertexAttribArray("color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty);
  276. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_lines_F);
  277. if (is_dirty)
  278. glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*lines_F_vbo.size(), lines_F_vbo.data(), GL_DYNAMIC_DRAW);
  279. dirty &= ~ViewerData::DIRTY_OVERLAY_LINES;
  280. }
  281. IGL_INLINE void igl::opengl::State::bind_overlay_points()
  282. {
  283. bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_POINTS;
  284. glBindVertexArray(vao_overlay_points);
  285. shader_overlay_points.bind();
  286. shader_overlay_points.bindVertexAttribArray("position", vbo_points_V, points_V_vbo, is_dirty);
  287. shader_overlay_points.bindVertexAttribArray("color", vbo_points_V_colors, points_V_colors_vbo, is_dirty);
  288. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_points_F);
  289. if (is_dirty)
  290. glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*points_F_vbo.size(), points_F_vbo.data(), GL_DYNAMIC_DRAW);
  291. dirty &= ~ViewerData::DIRTY_OVERLAY_POINTS;
  292. }
  293. IGL_INLINE void igl::opengl::State::draw_mesh(bool solid)
  294. {
  295. glPolygonMode(GL_FRONT_AND_BACK, solid ? GL_FILL : GL_LINE);
  296. /* Avoid Z-buffer fighting between filled triangles & wireframe lines */
  297. if (solid)
  298. {
  299. glEnable(GL_POLYGON_OFFSET_FILL);
  300. glPolygonOffset(1.0, 1.0);
  301. }
  302. glDrawElements(GL_TRIANGLES, 3*F_vbo.cols(), GL_UNSIGNED_INT, 0);
  303. glDisable(GL_POLYGON_OFFSET_FILL);
  304. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  305. }
  306. IGL_INLINE void igl::opengl::State::draw_overlay_lines()
  307. {
  308. glDrawElements(GL_LINES, lines_F_vbo.cols(), GL_UNSIGNED_INT, 0);
  309. }
  310. IGL_INLINE void igl::opengl::State::draw_overlay_points()
  311. {
  312. glDrawElements(GL_POINTS, points_F_vbo.cols(), GL_UNSIGNED_INT, 0);
  313. }
  314. IGL_INLINE void igl::opengl::State::init()
  315. {
  316. std::string mesh_vertex_shader_string =
  317. "#version 150\n"
  318. "uniform mat4 model;"
  319. "uniform mat4 view;"
  320. "uniform mat4 proj;"
  321. "in vec3 position;"
  322. "in vec3 normal;"
  323. "out vec3 position_eye;"
  324. "out vec3 normal_eye;"
  325. "in vec4 Ka;"
  326. "in vec4 Kd;"
  327. "in vec4 Ks;"
  328. "in vec2 texcoord;"
  329. "out vec2 texcoordi;"
  330. "out vec4 Kai;"
  331. "out vec4 Kdi;"
  332. "out vec4 Ksi;"
  333. "void main()"
  334. "{"
  335. " position_eye = vec3 (view * model * vec4 (position, 1.0));"
  336. " normal_eye = vec3 (view * model * vec4 (normal, 0.0));"
  337. " normal_eye = normalize(normal_eye);"
  338. " gl_Position = proj * vec4 (position_eye, 1.0);" //proj * view * model * vec4(position, 1.0);"
  339. " Kai = Ka;"
  340. " Kdi = Kd;"
  341. " Ksi = Ks;"
  342. " texcoordi = texcoord;"
  343. "}";
  344. std::string mesh_fragment_shader_string =
  345. "#version 150\n"
  346. "uniform mat4 model;"
  347. "uniform mat4 view;"
  348. "uniform mat4 proj;"
  349. "uniform vec4 fixed_color;"
  350. "in vec3 position_eye;"
  351. "in vec3 normal_eye;"
  352. "uniform vec3 light_position_world;"
  353. "vec3 Ls = vec3 (1, 1, 1);"
  354. "vec3 Ld = vec3 (1, 1, 1);"
  355. "vec3 La = vec3 (1, 1, 1);"
  356. "in vec4 Ksi;"
  357. "in vec4 Kdi;"
  358. "in vec4 Kai;"
  359. "in vec2 texcoordi;"
  360. "uniform sampler2D tex;"
  361. "uniform float specular_exponent;"
  362. "uniform float lighting_factor;"
  363. "uniform float texture_factor;"
  364. "out vec4 outColor;"
  365. "void main()"
  366. "{"
  367. "vec3 Ia = La * vec3(Kai);" // ambient intensity
  368. "vec3 light_position_eye = vec3 (view * vec4 (light_position_world, 1.0));"
  369. "vec3 vector_to_light_eye = light_position_eye - position_eye;"
  370. "vec3 direction_to_light_eye = normalize (vector_to_light_eye);"
  371. "float dot_prod = dot (direction_to_light_eye, normal_eye);"
  372. "float clamped_dot_prod = max (dot_prod, 0.0);"
  373. "vec3 Id = Ld * vec3(Kdi) * clamped_dot_prod;" // Diffuse intensity
  374. "vec3 reflection_eye = reflect (-direction_to_light_eye, normal_eye);"
  375. "vec3 surface_to_viewer_eye = normalize (-position_eye);"
  376. "float dot_prod_specular = dot (reflection_eye, surface_to_viewer_eye);"
  377. "dot_prod_specular = float(abs(dot_prod)==dot_prod) * max (dot_prod_specular, 0.0);"
  378. "float specular_factor = pow (dot_prod_specular, specular_exponent);"
  379. "vec3 Is = Ls * vec3(Ksi) * specular_factor;" // specular intensity
  380. "vec4 color = vec4(lighting_factor * (Is + Id) + Ia + (1.0-lighting_factor) * vec3(Kdi),(Kai.a+Ksi.a+Kdi.a)/3);"
  381. "outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color;"
  382. "if (fixed_color != vec4(0.0)) outColor = fixed_color;"
  383. "}";
  384. std::string overlay_vertex_shader_string =
  385. "#version 150\n"
  386. "uniform mat4 model;"
  387. "uniform mat4 view;"
  388. "uniform mat4 proj;"
  389. "in vec3 position;"
  390. "in vec3 color;"
  391. "out vec3 color_frag;"
  392. "void main()"
  393. "{"
  394. " gl_Position = proj * view * model * vec4 (position, 1.0);"
  395. " color_frag = color;"
  396. "}";
  397. std::string overlay_fragment_shader_string =
  398. "#version 150\n"
  399. "in vec3 color_frag;"
  400. "out vec4 outColor;"
  401. "void main()"
  402. "{"
  403. " outColor = vec4(color_frag, 1.0);"
  404. "}";
  405. std::string overlay_point_fragment_shader_string =
  406. "#version 150\n"
  407. "in vec3 color_frag;"
  408. "out vec4 outColor;"
  409. "void main()"
  410. "{"
  411. " if (length(gl_PointCoord - vec2(0.5)) > 0.5)"
  412. " discard;"
  413. " outColor = vec4(color_frag, 1.0);"
  414. "}";
  415. init_buffers();
  416. shader_mesh.init(mesh_vertex_shader_string,
  417. mesh_fragment_shader_string, "outColor");
  418. shader_overlay_lines.init(overlay_vertex_shader_string,
  419. overlay_fragment_shader_string, "outColor");
  420. shader_overlay_points.init(overlay_vertex_shader_string,
  421. overlay_point_fragment_shader_string, "outColor");
  422. }
  423. IGL_INLINE void igl::opengl::State::free()
  424. {
  425. shader_mesh.free();
  426. shader_overlay_lines.free();
  427. shader_overlay_points.free();
  428. free_buffers();
  429. }