Brenta Engine 1.2
Loading...
Searching...
No Matches
vao.cpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#include <brenta/logger.hpp>
7#include <brenta/vao.hpp>
8
9using namespace brenta::types;
10
12{
13}
14
15vao::~vao()
16{
17 this->destroy();
18}
19
20void vao::init()
21{
22 glGenVertexArrays(1, &this->vao_id);
23 DEBUG("vao: initialized");
24}
25
26void vao::destroy()
27{
28 if (this->get_id() == 0) return;
29
30 glDeleteVertexArrays(1, &this->vao_id);
31 DEBUG("vao: destroyed");
32}
33
34void vao::bind() const
35{
36 if (this->get_id() == 0)
37 {
38 ERROR("vao::bind: not initialized");
39 return;
40 }
41 glBindVertexArray(this->get_id());
42}
43
44void vao::unbind() const
45{
46 glBindVertexArray(0);
47}
48
49unsigned int vao::get_id() const
50{
51 if (vao_id == 0)
52 return 0;
53 return vao_id;
54}
55
56void vao::set_vertex_data(buffer &buffer, unsigned int index, GLint size,
57 GLenum type, GLboolean normalized, GLsizei stride,
58 const void *pointer)
59{
60 this->bind();
61 buffer.bind();
62 glVertexAttribPointer(index, size, type, normalized, stride, pointer);
63 glEnableVertexAttribArray(index);
64 buffer.unbind();
65 this->unbind();
66}
Buffer wrapper around OpenGL buffer objects.
Definition buffer.hpp:23
vao()
Default constructor, does nothing.
Definition vao.cpp:11
void set_vertex_data(buffer &buffer, unsigned int index, GLint size, GLenum type, GLboolean is_normalized, GLsizei stride, const void *pointer)
Set the vertex data.
Definition vao.cpp:56