AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
buffer.h
1#pragma once
2#include <glad/glad.h>
3
4namespace Aire {
5 class VertexArrayObject;
6
10 class Buffer {
11 private:
12 GLuint handle;
13
14 public:
20 Buffer(GLsizeiptr bufferSize, const void* data, GLbitfield flags = GL_DYNAMIC_STORAGE_BIT);
21
26 void setData(GLintptr offset, GLsizeiptr dataSize, const void* data);
27
33 void bindUniform(GLuint index, GLintptr offset, GLsizeiptr size);
34
39 void bindShaderStorage(GLuint index, GLintptr offset, GLsizeiptr size);
40
45 void bindTransformFeedback(GLuint index, GLintptr offset, GLsizeiptr size);
46
51 void bindAtomicCounter(GLuint index, GLintptr offset, GLsizeiptr size);
52
58 void bindVertAttrib(const VertexArrayObject& vao, GLuint bindingPoint, GLintptr offset, GLsizei stride);
59
62 void bindElementBuffer(const VertexArrayObject& vao);
63
65 GLuint getHandle() const;
66
68 GLint64 getSize() const;
69
71 ~Buffer();
72
73 // Delete copy constructor and assignment operator.
74 Buffer(const Buffer&) = delete;
75 Buffer& operator=(const Buffer&) = delete;
76
77 private:
78 // Utility function to initialize an OpenGL buffer.
79 // @param bufferSize The size of the buffer to be allocated. Cannot be changed later.
80 // @param data A pointer to the data to be copied to the buffer. nullptr if data is not available yet.
81 // @param flags Flags used for buffer creation. See: https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBufferStorage.xhtml
82 void init(GLsizeiptr bufferSize, const void* data, GLbitfield flags);
83
91 void bind(GLenum target, GLuint index, GLintptr offset, GLsizeiptr size);
92 };
93
94 //##########################################//
95 //######## INLINE DEFINITIONS BELOW ########//
96 //##########################################//
97
98 inline void Buffer::bindShaderStorage(GLuint index, GLintptr offset, GLsizeiptr size) {
99 bind(GL_SHADER_STORAGE_BUFFER, index, offset, size);
100 }
101
102 inline void Buffer::bindTransformFeedback(GLuint index, GLintptr offset, GLsizeiptr size) {
103 bind(GL_TRANSFORM_FEEDBACK_BUFFER, index, offset, size);
104 }
105
106 inline void Buffer::bindAtomicCounter(GLuint index, GLintptr offset, GLsizeiptr size) {
107 bind(GL_ATOMIC_COUNTER_BUFFER, index, offset, size);
108 }
109
110 inline GLuint Buffer::getHandle() const {
111 return handle;
112 }
113}
114
Definition buffer.h:10
GLuint getHandle() const
Definition buffer.h:110
GLint64 getSize() const
Definition buffer.cpp:44
void bindShaderStorage(GLuint index, GLintptr offset, GLsizeiptr size)
Definition buffer.h:98
~Buffer()
Destructor frees the associated OpenGL memory automatically.
Definition buffer.cpp:60
Buffer(GLsizeiptr bufferSize, const void *data, GLbitfield flags=GL_DYNAMIC_STORAGE_BIT)
Definition buffer.cpp:14
void bindElementBuffer(const VertexArrayObject &vao)
Definition buffer.cpp:40
void bindVertAttrib(const VertexArrayObject &vao, GLuint bindingPoint, GLintptr offset, GLsizei stride)
Definition buffer.cpp:36
void bindTransformFeedback(GLuint index, GLintptr offset, GLsizeiptr size)
Definition buffer.h:102
void bindAtomicCounter(GLuint index, GLintptr offset, GLsizeiptr size)
Definition buffer.h:106
void setData(GLintptr offset, GLsizeiptr dataSize, const void *data)
Definition buffer.cpp:20
void bindUniform(GLuint index, GLintptr offset, GLsizeiptr size)
Definition buffer.cpp:27
Definition vao.h:8