123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "wrapper/VertexBuffer.h"
- VertexBuffer::VertexBuffer() : vertexArray(0), vertexBuffer(0) {
- glGenVertexArrays(1, &vertexArray);
- glGenBuffers(1, &vertexBuffer);
- }
- VertexBuffer::~VertexBuffer() {
- glDeleteBuffers(1, &vertexBuffer);
- glDeleteVertexArrays(1, &vertexArray);
- }
- void VertexBuffer::bindArray() const {
- glBindVertexArray(vertexArray);
- }
- void VertexBuffer::bindBuffer() const {
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- }
- void VertexBuffer::setAttributes(const Attributes& attributes) {
- bindArray();
- bindBuffer();
- attributes.set();
- }
- void VertexBuffer::setData(int size, const void* data, int flag) {
- bindBuffer();
- glBufferData(GL_ARRAY_BUFFER, size, data, flag);
- }
- void VertexBuffer::setStaticData(int size, const void* data) {
- setData(size, data, GL_STATIC_DRAW);
- }
- void VertexBuffer::setStreamData(int size, const void* data) {
- setData(size, data, GL_STREAM_DRAW);
- }
- void VertexBuffer::setDynamicData(int size, const void* data) {
- setData(size, data, GL_DYNAMIC_DRAW);
- }
- void VertexBuffer::updateData(int offset, int size, const void* data) {
- bindBuffer();
- glBufferSubData(GL_ARRAY_BUFFER, offset, size, data);
- }
- void VertexBuffer::draw(int vertices, int mode, int offset) {
- bindArray();
- glDrawArrays(mode, offset, vertices);
- }
- void VertexBuffer::draw(int vertices, int offset) {
- draw(vertices, GL_TRIANGLES, offset);
- }
- void VertexBuffer::drawStrip(int vertices, int offset) {
- draw(vertices, GL_TRIANGLE_STRIP, offset);
- }
|