Brenta Engine 1.2
Loading...
Searching...
No Matches
ubo.cpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#include <brenta/renderer/opengl/ubo.hpp>
7#include <brenta/logger.hpp>
8
9using namespace brenta;
10
11void Ubo::init(Shader& shader,
12 std::string uniform_name,
13 unsigned int binding_point,
14 size_t size)
15{
16 GLuint block_index =
17 glGetUniformBlockIndex(shader.get_id(), uniform_name.c_str());
18 if (block_index == GL_INVALID_INDEX)
19 {
20 ERROR("Particles::init: error settings uniform block index");
21 return;
22 }
23
24 this->target = Buffer::Target::Uniform;
25 glGenBuffers(1, &id);
26
27 this->bind();
28 glUniformBlockBinding(shader.get_id(), block_index, 3);
29 glBindBufferBase(GL_UNIFORM_BUFFER, binding_point, id);
30 glBindBufferRange(GL_UNIFORM_BUFFER, binding_point, id, 0,
31 size);
32
33 EVENT(Logger::Event::Lifetime, "ubo: initialized {}", this->id);
34 this->unbind();
35 return;
36}