12345678910111213141516171819202122232425262728 |
- #include <GL/glew.h>
- #include <cassert>
- #include "client/rendering/wrapper/StreamBuffer.h"
- StreamBuffer::StreamBuffer(u64 size) : bufferSize(size), offset(size), index(0), buffer(nullptr) {
- }
- void StreamBuffer::reset(u64 size) {
- if(offset + size >= bufferSize) {
- offset = 0;
- glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STREAM_DRAW);
- }
- buffer = static_cast<float*> (glMapBufferRange(GL_ARRAY_BUFFER, offset, size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT));
- assert(buffer != nullptr);
- index = 0;
- }
- StreamBuffer& StreamBuffer::add(float f) {
- buffer[index++] = f;
- return *this;
- }
- void StreamBuffer::draw(uint floatPerVertex) {
- glUnmapBuffer(GL_ARRAY_BUFFER);
- glDrawArrays(GL_TRIANGLE_STRIP, offset / (sizeof (float) * floatPerVertex), index / floatPerVertex);
- offset += index * sizeof(float);
- }
|