buffer.h 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <QOpenGLFunctions_3_3_Core>
  3. #include <vector>
  4. namespace Render::GL {
  5. class Buffer : protected QOpenGLFunctions_3_3_Core {
  6. public:
  7. enum class Type { Vertex, Index, Uniform };
  8. enum class Usage { Static, Dynamic, Stream };
  9. Buffer(Type type);
  10. ~Buffer();
  11. void bind();
  12. void unbind();
  13. void setData(const void *data, size_t size, Usage usage = Usage::Static);
  14. template <typename T>
  15. void setData(const std::vector<T> &data, Usage usage = Usage::Static) {
  16. setData(data.data(), data.size() * sizeof(T), usage);
  17. }
  18. private:
  19. GLuint m_buffer = 0;
  20. Type m_type;
  21. GLenum getGLType() const;
  22. GLenum getGLUsage(Usage usage) const;
  23. };
  24. class VertexArray : protected QOpenGLFunctions_3_3_Core {
  25. public:
  26. VertexArray();
  27. ~VertexArray();
  28. void bind();
  29. void unbind();
  30. void addVertexBuffer(Buffer &buffer, const std::vector<int> &layout);
  31. void setIndexBuffer(Buffer &buffer);
  32. private:
  33. GLuint m_vao = 0;
  34. int m_currentAttribIndex = 0;
  35. };
  36. } // namespace Render::GL