GlistEngine
Loading...
Searching...
No Matches
gUbo.h
Go to the documentation of this file.
1//
2// Created by irrel on 21.12.2023.
3//
4
5#pragma once
6
7#include "gObject.h"
8#include "gRenderer.h"
9#include "gRenderObject.h"
10
11template<typename T>
12class gUbo : public gRenderObject {
13public:
14 template<typename ...Args>
15 gUbo(Args&&... args, int bindingpoint, int usage = GL_DYNAMIC_DRAW) : id(GL_NONE), size(sizeof(T)), bindingpoint(bindingpoint) {
16 data = new T(std::forward<Args>(args)...);
17 id = renderer->genBuffers();
18 renderer->setBufferData(id, nullptr, size, usage);
19 // define the range of the buffer that links to a uniform binding point
20 renderer->setBufferRange(bindingpoint, id, 0, size);
21 update();
22 }
23
25 if (id != GL_NONE) {
27 }
28 delete data;
29 }
30
31 void bind() const {
32 renderer->bindBuffer(GL_UNIFORM_BUFFER, id);
33 }
34
35 void unbind() const {
36 renderer->unbindBuffer(GL_UNIFORM_BUFFER);
37 }
38
39 void update() {
40 update(0, size);
41 }
42
43 void update(int offset, int length) {
44 void* ptr = reinterpret_cast<char*>(data) + offset;
45 renderer->bufSubData(id, offset, length, ptr);
46 }
47
48 T* getData() {
49 return data;
50 }
51
52 void setData(T* newObject) {
53 data = newObject;
54 update();
55 }
56
57 GLuint getId() const {
58 return id;
59 }
60
61 int getBindingPoint() const {
62 return bindingpoint;
63 }
64
65 int getSize() const {
66 return size;
67 }
68private:
69 GLuint id;
70 int size;
71 T* data;
72 int bindingpoint;
73};
Definition gRenderObject.h:25
virtual void setBufferData(GLuint buffer, const void *data, size_t size, int usage)=0
virtual void deleteBuffer(GLuint &buffer)=0
virtual void bindBuffer(GLenum target, GLuint buffer)=0
virtual void unbindBuffer(GLenum target)=0
virtual void bufSubData(GLuint buffer, int offset, int size, const void *data)=0
virtual GLuint genBuffers()=0
virtual void setBufferRange(int index, GLuint buffer, int offset, int size)=0
Definition gUbo.h:12
void bind() const
Definition gUbo.h:31
GLuint getId() const
Definition gUbo.h:57
int getSize() const
Definition gUbo.h:65
void update(int offset, int length)
Definition gUbo.h:43
void setData(T *newObject)
Definition gUbo.h:52
~gUbo()
Definition gUbo.h:24
gUbo(Args &&... args, int bindingpoint, int usage=GL_DYNAMIC_DRAW)
Definition gUbo.h:15
int getBindingPoint() const
Definition gUbo.h:61
void unbind() const
Definition gUbo.h:35
void update()
Definition gUbo.h:39
T * getData()
Definition gUbo.h:48
gRenderer * renderer