StreamBuffer.h 713 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef STREAMBUFFER_H
  2. #define STREAMBUFFER_H
  3. #include <cstring>
  4. class StreamBuffer final {
  5. public:
  6. StreamBuffer(int size, int bytesPerVertex);
  7. StreamBuffer(const StreamBuffer& other) = delete;
  8. StreamBuffer(StreamBuffer&& other) = delete;
  9. StreamBuffer& operator=(const StreamBuffer& other) = delete;
  10. StreamBuffer& operator=(StreamBuffer&& other) = delete;
  11. void reset(int size);
  12. template<typename T>
  13. StreamBuffer& add(const T& t) {
  14. std::memcpy(buffer + index, &t, sizeof (t));
  15. index += sizeof (t);
  16. return *this;
  17. }
  18. void draw();
  19. private:
  20. int bufferSize;
  21. int offset;
  22. int bytesPerVertex;
  23. int index;
  24. char* buffer;
  25. };
  26. #endif