create_index_vbo.cpp 1.1 KB

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