create_index_vbo.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 "create_index_vbo.h"
  9. // http://www.songho.ca/opengl/gl_vbo.html#create
  10. IGL_INLINE void igl::opengl::create_index_vbo(
  11. const Eigen::MatrixXi & F,
  12. GLuint & F_vbo_id)
  13. {
  14. // Generate Buffers
  15. glGenBuffersARB(1,&F_vbo_id);
  16. // Bind Buffers
  17. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,F_vbo_id);
  18. // Copy data to buffers
  19. // We expect a matrix with each vertex position on a row, we then want to
  20. // pass this data to OpenGL reading across rows (row-major)
  21. if(F.Options & Eigen::RowMajor)
  22. {
  23. glBufferDataARB(
  24. GL_ELEMENT_ARRAY_BUFFER_ARB,
  25. sizeof(int)*F.size(),
  26. F.data(),
  27. GL_STATIC_DRAW_ARB);
  28. }else
  29. {
  30. // Create temporary copy of transpose
  31. Eigen::MatrixXi FT = F.transpose();
  32. // If its column major then we need to temporarily store a transpose
  33. glBufferDataARB(
  34. GL_ELEMENT_ARRAY_BUFFER_ARB,
  35. sizeof(int)*F.size(),
  36. FT.data(),
  37. GL_STATIC_DRAW);
  38. }
  39. // bind with 0, so, switch back to normal pointer operation
  40. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
  41. }
  42. #ifdef IGL_STATIC_LIBRARY
  43. // Explicit template specialization
  44. #endif