Brenta Engine 1.2
Loading...
Searching...
No Matches
buffer.cpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#include <brenta/buffer.hpp>
7#include <brenta/logger.hpp>
8
9using namespace brenta;
10using namespace brenta::types;
11
12buffer::buffer(GLenum input_target)
13{
14 this->init(input_target);
15}
16
17buffer::~buffer()
18{
19 this->destroy();
20}
21
22void buffer::copy_data(GLsizeiptr size, const void *data, GLenum usage)
23{
24 glBufferData(this->target, size, data, usage);
25}
26
27void buffer::copy_indices(GLsizeiptr size, const void *data, GLenum usage)
28{
29 if (this->target != GL_ELEMENT_ARRAY_BUFFER)
30 return;
31
32 this->bind();
33 glBufferData(this->target, size, data, usage);
34}
35
36void buffer::copy_vertices(GLsizeiptr size, const void *data, GLenum usage)
37{
38 if (this->target == GL_ELEMENT_ARRAY_BUFFER)
39 return;
40
41 this->bind();
42 glBufferData(this->target, size, data, usage);
43}
44
45void buffer::init(GLenum input_target)
46{
47 this->target = input_target;
48 glGenBuffers(1, &id);
49
50 DEBUG("buffer: initialized");
51}
52
53void buffer::destroy()
54{
55 if (this->id == 0) return;
56
57 glDeleteBuffers(1, &this->id);
58 this->id = 0;
59
60 DEBUG("buffer: destroyed");
61}
62
63void buffer::bind()
64{
65 if (this->id == 0)
66 {
67 ERROR("buffer::bind: not initialized");
68 return;
69 }
70 glBindBuffer(this->target, this->id);
71}
72
73void buffer::unbind()
74{
75 glBindBuffer(this->target, 0);
76}
77
78int buffer::get_id()
79{
80 return this->id;
81}
82
83GLenum buffer::get_target()
84{
85 return this->target;
86}
87
88void buffer::set_id(unsigned int id)
89{
90 this->id = id;
91}
92
93void buffer::set_target(GLenum target)
94{
95 this->target = target;
96}
void copy_indices(GLsizeiptr size, const void *data, GLenum usage)
Copy data to the buffer object.
Definition buffer.cpp:27
void copy_vertices(GLsizeiptr size, const void *data, GLenum usage)
Copy data to the buffer object.
Definition buffer.cpp:36
void copy_data(GLsizeiptr size, const void *data, GLenum usage)
Copy data to the buffer object.
Definition buffer.cpp:22
buffer()
Default constructor, does nothing.
Definition buffer.hpp:38
unsigned int id
Buffer object id, generated by OpenGL.
Definition buffer.hpp:28
GLenum target
Buffer object target (like GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER...)
Definition buffer.hpp:33