-#include <msp/gl/extensions/arb_shader_objects.h>
-#include <msp/gl/extensions/arb_uniform_buffer_object.h>
-#include "buffer.h"
-#include "color.h"
+#include <algorithm>
#include "deviceinfo.h"
-#include "error.h"
-#include "matrix.h"
-#include "uniform.h"
#include "uniformblock.h"
-#include "vector.h"
+
+using namespace std;
namespace Msp {
namespace GL {
UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
+ UniformBlockBackend(info.bind_point>=0),
data(info.data_size)
-{
- static Require _req(ARB_shader_objects);
- if(info.bind_point>=0)
- static Require _req2(ARB_uniform_buffer_object);
-}
+{ }
-unsigned UniformBlock::get_alignment() const
+size_t UniformBlock::get_alignment() const
{
- return Limits::get_global().uniform_buffer_alignment;
+ return DeviceInfo::get_global().limits.uniform_buffer_alignment;
}
-void UniformBlock::store(const ReflectData::UniformInfo &info, const Uniform &uni)
+void UniformBlock::store(const ReflectData::UniformInfo &info, size_t array_size, const void *value)
{
+ array_size = min(array_size, max<size_t>(info.array_size, 1U));
+
+ char *store_ptr;
+ bool packed;
if(info.block->bind_point<0)
{
if(info.location<0)
return;
- uni.store(info, &data[info.location*16]);
+
+ store_ptr = data.data()+info.location*16;
+ packed = true;
+ }
+ else
+ {
+ store_ptr = data.data()+info.offset;
+ if(array_size!=1 && info.array_stride!=get_type_size(info.type))
+ packed = false;
+ else if(is_matrix(info.type))
+ packed = (info.matrix_stride==get_type_size(get_matrix_column_type(info.type)));
+ else
+ packed = true;
+ }
+
+ const char *value_ptr = static_cast<const char *>(value);
+ if(packed)
+ {
+ const char *data_end = value_ptr+array_size*get_type_size(info.type);
+ copy(value_ptr, data_end, store_ptr);
+ }
+ else if(is_matrix(info.type))
+ {
+ unsigned col_size = get_type_size(get_matrix_column_type(info.type));
+ unsigned cols = get_type_size(info.type)/col_size;
+ for(unsigned i=0; i<array_size; ++i)
+ {
+ char *elem_ptr = store_ptr;
+ for(unsigned j=0; j<cols; ++j)
+ {
+ copy(value_ptr, value_ptr+col_size, elem_ptr);
+ value_ptr += col_size;
+ elem_ptr += info.matrix_stride;
+ }
+ store_ptr += info.array_stride;
+ }
}
else
- uni.store(info, &data[info.offset]);
+ {
+ unsigned elem_size = get_type_size(info.type);
+ for(unsigned i=0; i<array_size; ++i)
+ {
+ copy(value_ptr, value_ptr+elem_size, store_ptr);
+ value_ptr += elem_size;
+ store_ptr += info.array_stride;
+ }
+ }
+
dirty = true;
}