create_vector_vbo.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "create_vector_vbo.h"
  2. #include <cassert>
  3. // http://www.songho.ca/opengl/gl_vbo.html#create
  4. template <typename T>
  5. IGL_INLINE void igl::create_vector_vbo(
  6. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & V,
  7. GLuint & V_vbo_id)
  8. {
  9. //// Expects that input is list of 3D vectors along rows
  10. //assert(V.cols() == 3);
  11. // Generate Buffers
  12. glGenBuffers(1,&V_vbo_id);
  13. // Bind Buffers
  14. glBindBuffer(GL_ARRAY_BUFFER,V_vbo_id);
  15. // Copy data to buffers
  16. // We expect a matrix with each vertex position on a row, we then want to
  17. // pass this data to OpenGL reading across rows (row-major)
  18. if(V.Options & Eigen::RowMajor)
  19. {
  20. glBufferData(
  21. GL_ARRAY_BUFFER,
  22. sizeof(T)*V.size(),
  23. V.data(),
  24. GL_STATIC_DRAW);
  25. }else
  26. {
  27. // Create temporary copy of transpose
  28. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> VT = V.transpose();
  29. // If its column major then we need to temporarily store a transpose
  30. glBufferData(
  31. GL_ARRAY_BUFFER,
  32. sizeof(T)*V.size(),
  33. VT.data(),
  34. GL_STATIC_DRAW);
  35. }
  36. // bind with 0, so, switch back to normal pointer operation
  37. glBindBuffer(GL_ARRAY_BUFFER, 0);
  38. }
  39. #ifndef IGL_HEADER_ONLY
  40. // Explicit template specialization
  41. #endif