Attributes.cpp 883 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <GL/glew.h>
  2. #include "wrapper/Attributes.h"
  3. Attributes& Attributes::addFloat(int count) {
  4. attributes.add({count, sizeof (float), GL_FLOAT, false});
  5. return *this;
  6. }
  7. Attributes& Attributes::addColor4() {
  8. attributes.add({4, sizeof (unsigned char), GL_UNSIGNED_BYTE, true});
  9. return *this;
  10. }
  11. Attributes& Attributes::addSpacer() {
  12. attributes.add({0, 0, -1, false});
  13. return *this;
  14. }
  15. void Attributes::set() const {
  16. int size = 0;
  17. for(const Attribute& a : attributes) {
  18. size += a.count * a.size;
  19. }
  20. int index = 0;
  21. int offset = 0;
  22. for(const Attribute& a : attributes) {
  23. if(a.type != -1) {
  24. glVertexAttribPointer(index, a.count, a.type, a.normalized, size, static_cast<char*> (0) + offset);
  25. glEnableVertexAttribArray(index);
  26. }
  27. offset += a.count * a.size;
  28. index++;
  29. }
  30. }