fennec
Loading...
Searching...
No Matches
vertex_array.h
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef FENNEC_RENDERERS_OPENGL_LIB_VERTEX_ARRAY_H
20#define FENNEC_RENDERERS_OPENGL_LIB_VERTEX_ARRAY_H
21
22#include <fennec/renderers/opengl/lib/fwd.h>
23#include <fennec/renderers/opengl/lib/enum.h>
24
25namespace fennec
26{
27
28namespace gl
29{
30
31class vertex_array {
32public:
33 constexpr vertex_array()
34 : _handle(NULL) {
35 glGenVertexArrays(1, &_handle);
36 }
37
38 constexpr ~vertex_array() {
39 glDeleteVertexArrays(1, &_handle);
40 }
41
42 constexpr void start() const {
43 glBindVertexArray(_handle);
44 }
45
46 constexpr void end() const {
47 glBindVertexArray(NULL);
48 }
49
50 constexpr void set_attribute(GLuint i, GLenum type, GLint n, GLintptr offset, GLboolean normalized = false) {
51 glVertexAttribFormat(i, n, type, normalized, offset);
52 glEnableVertexAttribArray(i);
53 }
54
55 constexpr void clear_attribute(GLuint i) {
56 glDisableVertexAttribArray(i);
57 }
58
59private:
60 GLuint _handle;
61};
62
63}
64
65}
66
67#endif // FENNEC_RENDERERS_OPENGL_LIB_VERTEX_ARRAY_H