From 8bd3080a84e5f69ef20e529870e52b98a4ae287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Sat, 15 Nov 2025 20:01:08 +0100 Subject: [PATCH] feat(VAO): add VAO config --- inc/VAO.hpp | 23 +++++++++++++++++++++++ src/VAO.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 inc/VAO.hpp create mode 100755 src/VAO.cpp diff --git a/inc/VAO.hpp b/inc/VAO.hpp new file mode 100755 index 0000000..f13cfb7 --- /dev/null +++ b/inc/VAO.hpp @@ -0,0 +1,23 @@ +#ifndef VAO_HPP +#define VAO_HPP + +#include + +class VAO +{ +private: + unsigned int id; + +public: + VAO(); + ~VAO(); + + void bind(); + void unbind(); + + void setAttributePointer(GLuint index, GLuint size, GLenum type, GLsizei stride, const void* offset); + void drawElement(GLenum mode, GLsizei count, GLenum type, const void *indices); + void drawArray(GLenum mode, GLint first, GLsizei count); +}; + +#endif \ No newline at end of file diff --git a/src/VAO.cpp b/src/VAO.cpp new file mode 100755 index 0000000..8164fec --- /dev/null +++ b/src/VAO.cpp @@ -0,0 +1,40 @@ +#include "VAO.hpp" + +VAO::VAO() +{ + glGenVertexArrays(1, &id); +} + +VAO::~VAO() +{ + glDeleteVertexArrays(1, &id); +} + +void VAO::bind() +{ + glBindVertexArray(id); +} + +void VAO::unbind() +{ + glBindVertexArray(0); +} + +void VAO::setAttributePointer(GLuint index, GLuint size, GLenum type, GLsizei stride, const void* offset) +{ + bind(); + glEnableVertexAttribArray(index); + glVertexAttribPointer(index, size, type, GL_FALSE, stride, offset); +} + +void VAO::drawElement(GLenum mode, GLsizei count, GLenum type, const void* indices) +{ + bind(); + glDrawElements(mode, count, type, indices); +} + +void VAO::drawArray(GLenum mode, GLint first, GLsizei count) +{ + bind(); + glDrawArrays(mode, first, count); +} \ No newline at end of file