12 #include "../core/log.h" 19 void bind(
size_t binding_point);
20 void bind(
size_t binding_point,
size_t offset,
size_t size);
24 void update(
const void *data,
size_t size);
28 std::vector<uint8_t> _aligned_data;
29 ssize_t _aligned_stride = -1;
31 size_t _binding_point = 0;
35 UniformBuffer(
size_t binding_point) : _binding_point(binding_point) {}
36 void update(
const T &value) { UniformBufferBase::update(&value,
sizeof(T)); }
37 template <
class CONTAINER>
void update(
const CONTAINER &data) {
38 if (_aligned_stride < 0) {
39 GLint buffer_alignment = -1;
41 glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &buffer_alignment));
42 if (buffer_alignment < 1) {
43 LOG_ERROR(
"failed to get buffer alignment, using 256");
44 buffer_alignment = 256;
48 ((
sizeof(T) + buffer_alignment - 1) / buffer_alignment) *
51 _aligned_data.resize(_aligned_stride * data.size());
52 for (
size_t index = 0; index < data.size(); index++) {
53 std::memcpy(_aligned_data.data() + index * _aligned_stride,
54 (
const T *)&(data[index]),
sizeof(T));
56 UniformBufferBase::update(_aligned_data.data(), _aligned_data.size());
58 void bind() { UniformBufferBase::bind(_binding_point); }
59 void bind(
size_t index) {
60 UniformBufferBase::bind(_binding_point, _aligned_stride * index,