SimpleEngine/include/simpleengine/gfx/vbo.h

52 lines
1.0 KiB
C
Raw Permalink Normal View History

#pragma once
#include <iostream>
#ifdef __linux__
#include <GL/glew.h>
#include <GL/gl.h>
#else
#include <gl/glew.h>
#include <gl/gl.h>
#endif
namespace simpleengine::gfx {
class VBO {
public:
GLuint handle;
GLint type;
bool dynamic;
VBO(GLuint handle, GLint type, bool dynamic) : type(type), dynamic(dynamic), handle(handle) {
}
~VBO() {
2022-11-11 05:44:41 +00:00
// TODO: Anything to do here?
}
static VBO init(GLint type, bool dynamic) {
GLuint handle;
glGenBuffers(1, &handle);
return VBO(handle, type, dynamic);
}
void destroy() {
glDeleteBuffers(1, &handle);
}
void bind() const {
glBindBuffer(type, handle);
}
2022-09-29 23:13:47 +00:00
void unbind() const {
glBindBuffer(type, 0);
}
2021-11-26 03:28:47 +00:00
void buffer(void *data, size_t offset, size_t size) {
bind();
2021-11-26 03:28:47 +00:00
glBufferData(type, size - offset, data, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
}
};
}