Brenta Engine 1.2
Loading...
Searching...
No Matches
vao.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/renderer/opengl/buffer.hpp>
9
10#include <glad/glad.h>
11
12namespace brenta
13{
14
15//
16// Vertex array object
17// -------------------
18//
19// Specifies how to read the data from another buffer, usually the
20// VBO which contains vertex data.
21//
22// Use the `link_buffer` function for this, after having initialized
23// and bound the object.
24//
25// You usually follow this patter:
26//
27// Vao vao;
28// vao.init();
29// vao.bind();
30//
31// Buffer vbo;
32// vbo.init(Buffer::Target::Array);
33// vbo.bind();
34//
35// vbo.copy_data(vertices, sizeof(vertices), Buffer::DataUsage::StaticDraw);
36// vao.link_buffer(vbo, 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
37//
38class Vao
39{
40public:
41
42 Vao() {}
43 constexpr Vao(const Vao& other) = delete;
44 constexpr Vao& operator=(const Vao& other) = delete;
45 constexpr Vao(Vao&& other) noexcept
46 {
47 this->id = other.id;
48 other.id = 0;
49 }
50 constexpr Vao& operator=(Vao&& other) noexcept
51 {
52 this->id = other.id;
53 other.id = 0;
54 return *this;
55 }
56
57 ~Vao();
58
59 void init();
60 void destroy();
61 void bind() const;
62 void unbind() const;
63 unsigned int get_id() const;
64
65 // Specifies the buffer data layout, and makes it accessible in
66 // the [layout_index] location
67 //
68 // Args:
69 // - vbo the buffer containing the vertex data.
70 // - layout_index: the `location` index specified in the shader
71 // (e.g., layout(location = 0))
72 // - components: the number of components per attribute
73 // - type: the data type of each component (e.g. GL_FLOAT)
74 // - normalized: whether the data should be mapped to [0, 1] or
75 // [-1, 1] range
76 // - stride: the byte distance between the start of one
77 // attribute and the next (0 lets OpenGL calculate
78 // it based on 'type' and 'components')
79 // - offset: the byte offset of the first attribute in the buffer
80 void link_buffer(const Buffer &vbo,
81 unsigned int layout_index,
82 GLint components,
83 GLenum type,
84 GLboolean normalized,
85 GLsizei stride,
86 const void *offset);
87
88private:
89
90 unsigned int id = 0;
91
92};
93
94} // namespace brenta