bind_vertex_attrib_array.cpp 702 B

123456789101112131415161718192021222324
  1. #include "bind_vertex_attrib_array.h"
  2. IGL_INLINE GLint igl::opengl::bind_vertex_attrib_array(
  3. const GLuint program_shader,
  4. const std::string &name,
  5. GLuint bufferID,
  6. const Eigen::Matrix<float,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> &M,
  7. bool refresh)
  8. {
  9. GLint id = glGetAttribLocation(program_shader, name.c_str());
  10. if (id < 0)
  11. return id;
  12. if (M.size() == 0)
  13. {
  14. glDisableVertexAttribArray(id);
  15. return id;
  16. }
  17. glBindBuffer(GL_ARRAY_BUFFER, bufferID);
  18. if (refresh)
  19. glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW);
  20. glVertexAttribPointer(id, M.cols(), GL_FLOAT, GL_FALSE, 0, 0);
  21. glEnableVertexAttribArray(id);
  22. return id;
  23. }