34 lines
953 B
C++
34 lines
953 B
C++
#pragma once
|
|
#include <GL/glew.h>
|
|
|
|
#include "defines.hpp"
|
|
|
|
struct IndexBuffer {
|
|
IndexBuffer(void* data, uint32 numIndices, uint8 elementSize) {
|
|
glGenBuffers(1, &bufferId);
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId);
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*elementSize, data, GL_STATIC_DRAW);
|
|
|
|
// POSITION
|
|
glEnableVertexAttribArray(0);
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,x));
|
|
// COLOR
|
|
glEnableVertexAttribArray(1);
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex,r));
|
|
|
|
glBindVertexArray(0);
|
|
};
|
|
virtual ~IndexBuffer() {
|
|
glDeleteBuffers(1, &bufferId);
|
|
}
|
|
|
|
void bind() {
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId);
|
|
}
|
|
void unbind() {
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
}
|
|
|
|
private:
|
|
GLuint bufferId;
|
|
}; |