2 #include <msp/gl/extensions/arb_shader_objects.h>
3 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
4 #include "deviceinfo.h"
5 #include "uniformblock.h"
12 UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
15 static Require _req(ARB_shader_objects);
16 if(info.bind_point>=0)
17 static Require _req2(ARB_uniform_buffer_object);
20 unsigned UniformBlock::get_alignment() const
22 return DeviceInfo::get_global().limits.uniform_buffer_alignment;
25 void UniformBlock::store(const ReflectData::UniformInfo &info, unsigned array_size, const void *value)
27 array_size = min(array_size, max(info.array_size, 1U));
31 if(info.block->bind_point<0)
36 store_ptr = data.data()+info.location*16;
41 store_ptr = data.data()+info.offset;
42 if(array_size!=1 && info.array_stride!=get_type_size(info.type))
44 else if(is_matrix(info.type))
45 packed = (info.matrix_stride==get_type_size(get_matrix_column_type(info.type)));
50 const char *value_ptr = static_cast<const char *>(value);
53 const char *data_end = value_ptr+array_size*get_type_size(info.type);
54 copy(value_ptr, data_end, store_ptr);
56 else if(is_matrix(info.type))
58 unsigned col_size = get_type_size(get_matrix_column_type(info.type));
59 unsigned cols = get_type_size(info.type)/col_size;
60 for(unsigned i=0; i<array_size; ++i)
62 char *elem_ptr = store_ptr;
63 for(unsigned j=0; j<cols; ++j)
65 copy(value_ptr, value_ptr+col_size, elem_ptr);
66 value_ptr += col_size;
67 elem_ptr += info.matrix_stride;
69 store_ptr += info.array_stride;
74 unsigned elem_size = get_type_size(info.type);
75 for(unsigned i=0; i<array_size; ++i)
77 copy(value_ptr, value_ptr+elem_size, store_ptr);
78 value_ptr += elem_size;
79 store_ptr += info.array_stride;