2 #include "deviceinfo.h"
3 #include "uniformblock.h"
10 UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
11 UniformBlockBackend(info.bind_point>=0),
15 unsigned UniformBlock::get_alignment() const
17 return DeviceInfo::get_global().limits.uniform_buffer_alignment;
20 void UniformBlock::store(const ReflectData::UniformInfo &info, unsigned array_size, const void *value)
22 array_size = min(array_size, max(info.array_size, 1U));
26 if(info.block->bind_point<0)
31 store_ptr = data.data()+info.location*16;
36 store_ptr = data.data()+info.offset;
37 if(array_size!=1 && info.array_stride!=get_type_size(info.type))
39 else if(is_matrix(info.type))
40 packed = (info.matrix_stride==get_type_size(get_matrix_column_type(info.type)));
45 const char *value_ptr = static_cast<const char *>(value);
48 const char *data_end = value_ptr+array_size*get_type_size(info.type);
49 copy(value_ptr, data_end, store_ptr);
51 else if(is_matrix(info.type))
53 unsigned col_size = get_type_size(get_matrix_column_type(info.type));
54 unsigned cols = get_type_size(info.type)/col_size;
55 for(unsigned i=0; i<array_size; ++i)
57 char *elem_ptr = store_ptr;
58 for(unsigned j=0; j<cols; ++j)
60 copy(value_ptr, value_ptr+col_size, elem_ptr);
61 value_ptr += col_size;
62 elem_ptr += info.matrix_stride;
64 store_ptr += info.array_stride;
69 unsigned elem_size = get_type_size(info.type);
70 for(unsigned i=0; i<array_size; ++i)
72 copy(value_ptr, value_ptr+elem_size, store_ptr);
73 value_ptr += elem_size;
74 store_ptr += info.array_stride;