2 #include <msp/gl/extensions/arb_shader_objects.h>
3 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
6 #include "deviceinfo.h"
9 #include "uniformblock.h"
17 UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
20 static Require _req(ARB_shader_objects);
21 if(info.bind_point>=0)
22 static Require _req2(ARB_uniform_buffer_object);
25 unsigned UniformBlock::get_alignment() const
27 return Limits::get_global().uniform_buffer_alignment;
30 void UniformBlock::store(const ReflectData::UniformInfo &info, unsigned array_size, const void *value)
32 array_size = min(array_size, max(info.array_size, 1U));
36 if(info.block->bind_point<0)
41 store_ptr = data.data()+info.location*16;
46 store_ptr = data.data()+info.offset;
47 if(array_size!=1 && info.array_stride!=get_type_size(info.type))
49 else if(is_matrix(info.type))
50 packed = (info.matrix_stride==get_type_size(get_matrix_column_type(info.type)));
55 const char *value_ptr = static_cast<const char *>(value);
58 const char *data_end = value_ptr+array_size*get_type_size(info.type);
59 copy(value_ptr, data_end, store_ptr);
61 else if(is_matrix(info.type))
63 unsigned col_size = get_type_size(get_matrix_column_type(info.type));
64 unsigned cols = get_type_size(info.type)/col_size;
65 for(unsigned i=0; i<array_size; ++i)
67 char *elem_ptr = store_ptr;
68 for(unsigned j=0; j<cols; ++j)
70 copy(value_ptr, value_ptr+col_size, elem_ptr);
71 value_ptr += col_size;
72 elem_ptr += info.matrix_stride;
74 store_ptr += info.array_stride;
79 unsigned elem_size = get_type_size(info.type);
80 for(unsigned i=0; i<array_size; ++i)
82 copy(value_ptr, value_ptr+elem_size, store_ptr);
83 value_ptr += elem_size;
84 store_ptr += info.array_stride;