AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
vao.h
1#pragma once
2#include <glad/glad.h>
3
4namespace Aire {
9 private:
10 GLuint handle;
11
12 public:
15
17 void bindVAO();
18
20 void unbindVAO();
21
22 // Define a new float-type vertex attribute.
23 // See: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glVertexAttribFormat.xhtml
24 // @param attribIdx Index of the attribute, as specified in the vertex shader.
25 // @param size Number of components
26 // @param type The type of the data stored in the array. See link for possible options.
27 // @param relativeOffset Offset from the start of the attribute block in case of interleaved attributes.
28 // @param normalized True if integer data should be normalized to [-1,1] or [0,1]. False if it should be converted to float as-is.
29 // @param enabled True if the attribute should be enabled automatically and false otherwise.
30 // @param autoBind True if the attribute should be bound to a binding point with the same index as the attribute index.
31 void addAttribF(
32 GLuint attribIdx,
33 GLint size,
34 GLenum type,
35 GLuint relativeOffset,
36 GLboolean normalized = GL_FALSE,
37 bool enabled = true,
38 bool autoBind = true
39 );
40
41 // Define a new integer-type vertex attribute.
42 // See: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glVertexAttribFormat.xhtml
43 // @param attribIdx Index of the attribute, as specified in the vertex shader.
44 // @param size Number of components
45 // @param type The type of the data stored in the array. See link for possible options.
46 // @param relativeOffset Offset from the start of the attribute block in case of interleaved attributes.
47 // @param enabled True if the attribute should be enabled automatically and false otherwise.
48 // @param autoBind True if the attribute should be bound to a binding point with the same index as the attribute index.
49 void addAttribI(GLuint attribIdx, GLint size, GLenum type, GLuint relativeOffset, bool enabled = true, bool autoBind = true);
50
51 // Define a new 64bit double precision vertex attribute. The array data must be of type GL_DOUBLE.
52 // See: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glVertexAttribFormat.xhtml
53 // @param attribIdx Index of the attribute, as specified in the vertex shader.
54 // @param size Number of components
55 // @param relativeOffset Offset from the start of the attribute block in case of interleaved attributes.
56 // @param enabled True if the attribute should be enabled automatically and false otherwise.
57 // @param autoBind True if the attribute should be bound to a binding point with the same index as the attribute index.
58 void addAttribL(GLuint attribIdx, GLint size, GLuint relativeOffset, bool enabled = true, bool autoBind = true);
59
64 void bindAttrib(GLuint attribIdx, GLuint bindingPointIdx);
65
68 void enableAttrib(GLuint attribIdx);
69
72 void disableAttrib(GLuint attribIdx);
73
74 GLuint getHandle() const;
75
77
78 // Delete copy constructor and assignment operator
79 VertexArrayObject(const VertexArrayObject&) = delete;
80 VertexArrayObject& operator=(const VertexArrayObject&) = delete;
81 };
82
83 //##########################################//
84 //######## INLINE DEFINITIONS BELOW ########//
85 //##########################################//
86
88 handle(0)
89 {
90 glCreateVertexArrays(1, &handle);
91 }
92
94 glBindVertexArray(handle);
95 }
96
97 inline void VertexArrayObject::bindAttrib(GLuint attribIdx, GLuint bindingPointIdx) {
98 glVertexArrayAttribBinding(handle, attribIdx, bindingPointIdx);
99 }
100
101 inline void VertexArrayObject::enableAttrib(GLuint attribIdx) {
102 glEnableVertexArrayAttrib(handle, attribIdx);
103 }
104
105 inline void VertexArrayObject::disableAttrib(GLuint attribIdx) {
106 glDisableVertexArrayAttrib(handle, attribIdx);
107 }
108
109 inline GLuint VertexArrayObject::getHandle() const {
110 return handle;
111 }
112}
Definition vao.h:8
void unbindVAO()
Unbind the VAO.
Definition vao.cpp:5
void bindVAO()
Bind the VAO for rendering.
Definition vao.h:93
void enableAttrib(GLuint attribIdx)
Definition vao.h:101
void bindAttrib(GLuint attribIdx, GLuint bindingPointIdx)
Definition vao.h:97
void disableAttrib(GLuint attribIdx)
Definition vao.h:105
VertexArrayObject()
Create a new VAO.
Definition vao.h:87