diff --git a/inc/core/vao.hpp b/inc/core/vao.hpp index fed009d..933de0e 100755 --- a/inc/core/vao.hpp +++ b/inc/core/vao.hpp @@ -4,24 +4,35 @@ #include #include "glad/glad.h" - +namespace core +{ class VAO { private: - unsigned int id; + GLuint id; public: + // Generates a new Vertex Array Object on the GPU VAO(); + // Deletes the VAO from GPU memory ~VAO(); + // Bind this VAO as the current active vertex array + // All subsequent vertex attribute calls will affect this VAO void bind(); + // Unbind the VAO (bind VAO 0) + // This prevents accidental modification of the currently bound VAO void unbind(); + // Define how vertex data is interpreted by OpenGL void setAttributePointer(GLuint index, GLuint size, GLenum type, - GLsizei stride, const void* offset); + GLsizei stride, const void *offset); + // Draw elements using the currently bound EBO (Element Buffer Object) void drawElement(GLenum mode, GLsizei count, GLenum type, - const void* indices); + const void *indices); + // Draw arrays directly from the VBOs (no EBO required) void drawArray(GLenum mode, GLint first, GLsizei count); }; +} // namespace core #endif \ No newline at end of file diff --git a/src/core/vao.cpp b/src/core/vao.cpp index 9944d21..197f639 100755 --- a/src/core/vao.cpp +++ b/src/core/vao.cpp @@ -1,27 +1,30 @@ -#include "vao.hpp" +#include "core/vao.hpp" -VAO::VAO() { glGenVertexArrays(1, &id); } +core::VAO::VAO() { glGenVertexArrays(1, &id); } -VAO::~VAO() { glDeleteVertexArrays(1, &id); } +core::VAO::~VAO() { glDeleteVertexArrays(1, &id); } -void VAO::bind() { glBindVertexArray(id); } +void core::VAO::bind() { glBindVertexArray(id); } -void VAO::unbind() { glBindVertexArray(0); } +void core::VAO::unbind() { glBindVertexArray(0); } -void VAO::setAttributePointer(GLuint index, GLuint size, GLenum type, - GLsizei stride, const void* offset) +void core::VAO::setAttributePointer(GLuint index, GLuint size, GLenum type, + GLsizei stride, const void *offset) { + // Enable the attribute at the given index glEnableVertexAttribArray(index); + + // Define the layout of the vertex attribute glVertexAttribPointer(index, size, type, GL_FALSE, stride, offset); } -void VAO::drawElement(GLenum mode, GLsizei count, GLenum type, - const void* indices) +void core::VAO::drawElement(GLenum mode, GLsizei count, GLenum type, + const void *indices) { glDrawElements(mode, count, type, indices); } -void VAO::drawArray(GLenum mode, GLint first, GLsizei count) +void core::VAO::drawArray(GLenum mode, GLint first, GLsizei count) { glDrawArrays(mode, first, count); } \ No newline at end of file