create_index_vbo.cpp 1.1 KB

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