3 #include "uniformblock.h"
10 UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
11 UniformBlockBackend(info.bind_point>=0),
15 size_t UniformBlock::get_alignment() const
17 return Device::get_current().get_info().limits.uniform_buffer_alignment;
20 void UniformBlock::store(const ReflectData::UniformInfo &info, size_t array_size, const void *value)
22 array_size = min(array_size, max<size_t>(info.array_size, 1U));
26 if(info.block->bind_point==ReflectData::DEFAULT_BLOCK)
31 store_offset = info.location*16;
36 store_offset = 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 char *store_ptr = data.data()+store_offset;
46 const char *value_ptr = static_cast<const char *>(value);
49 size_t value_size = array_size*get_type_size(info.type);
50 check_store_range(store_offset, value_size);
51 copy(value_ptr, value_ptr+value_size, store_ptr);
53 else if(is_matrix(info.type))
55 unsigned col_size = get_type_size(get_matrix_column_type(info.type));
56 unsigned cols = get_type_size(info.type)/col_size;
57 check_store_range(store_offset, (array_size-1)*info.array_stride+(cols-1)*info.matrix_stride+col_size);
58 for(unsigned i=0; i<array_size; ++i)
60 char *elem_ptr = store_ptr;
61 for(unsigned j=0; j<cols; ++j)
63 copy(value_ptr, value_ptr+col_size, elem_ptr);
64 value_ptr += col_size;
65 elem_ptr += info.matrix_stride;
67 store_ptr += info.array_stride;
72 unsigned elem_size = get_type_size(info.type);
73 check_store_range(store_offset, (array_size-1)*info.array_stride+elem_size);
74 for(unsigned i=0; i<array_size; ++i)
76 copy(value_ptr, value_ptr+elem_size, store_ptr);
77 value_ptr += elem_size;
78 store_ptr += info.array_stride;
85 void UniformBlock::check_store_range(size_t offs, size_t size)
88 if(offs>data.size() || offs+size>data.size())
89 throw out_of_range("UniformBlock::store");