2022-06-04 23:44:54 +00:00
|
|
|
#include "Graphics/Buffer.h"
|
|
|
|
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
int GpuBuffer::getBufferID() {
|
2022-06-04 23:44:54 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void GpuBuffer::createBuffer() {
|
2022-06-04 23:44:54 +00:00
|
|
|
glGenBuffers(1, (GLuint*) &id);
|
|
|
|
}
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
2022-06-04 23:44:54 +00:00
|
|
|
|
|
|
|
if (elementBuffer) {
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void GpuBuffer::Bind(bool elementBuffer = false ) {
|
2022-06-04 23:44:54 +00:00
|
|
|
if (elementBuffer) {
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, id);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void GpuBuffer::Unbind(bool elementBuffer = false) {
|
2022-06-04 23:44:54 +00:00
|
|
|
if (elementBuffer) {
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void GpuBuffer::Delete() {
|
2022-06-04 23:44:54 +00:00
|
|
|
glDeleteBuffers(1, (GLuint*) &id);
|
2022-05-04 13:27:42 +00:00
|
|
|
}
|