create_index_vbo.cpp 1.4 KB

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