12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "rendering/VertexBuffer.h"
- VertexBuffer::VertexBuffer() : vertexArray(0), vertexBuffer(0), size(0) {
- }
- VertexBuffer::~VertexBuffer() {
- GL::deleteBuffer(vertexBuffer);
- GL::deleteVertexArray(vertexArray);
- }
- void VertexBuffer::bindArray() const {
- GL::bindVertexArray(vertexArray);
- }
- void VertexBuffer::bindBuffer() const {
- GL::bindBuffer(vertexBuffer);
- }
- void VertexBuffer::init(const Attributes& attributes) {
- if(vertexArray != 0 || vertexBuffer != 0) {
- return;
- }
- vertexArray = GL::genVertexArray();
- vertexBuffer = GL::genBuffer();
- bindArray();
- bindBuffer();
- attributes.set();
- }
- void VertexBuffer::setStaticData(int size, const void* data) {
- VertexBuffer::size = size;
- bindBuffer();
- GL::bufferDataStatic(size, data);
- }
- void VertexBuffer::setStreamData(int size, const void* data) {
- VertexBuffer::size = size;
- bindBuffer();
- GL::bufferDataStream(size, data);
- }
- void VertexBuffer::setDynamicData(int size, const void* data) {
- VertexBuffer::size = size;
- bindBuffer();
- GL::bufferDataDynamic(size, data);
- }
- void VertexBuffer::updateData(int offset, int size, const void* data) {
- bindBuffer();
- GL::bufferSubData(offset, size, data);
- }
- void VertexBuffer::draw(int vertices, int offset) {
- bindArray();
- GL::drawTriangles(offset, vertices);
- }
- void VertexBuffer::drawStrip(int vertices, int offset) {
- bindArray();
- GL::drawTriangleStrip(offset, vertices);
- }
- void VertexBuffer::drawPoints(int vertices, int offset) {
- bindArray();
- GL::drawPoints(offset, vertices);
- }
- int VertexBuffer::getSize() const {
- return size;
- }
|