X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Funiformblock.cpp;fp=source%2Fcore%2Funiformblock.cpp;h=8f85b87f0ba1573e8749b7f8c405382da8201360;hb=729a477b47e97aea41f3f0b5db551f02bf70d1ee;hp=f713bd2af5d320541b27f114b9a4cad719528231;hpb=4e20afbda6adb0008e286bf7fb947438aeb7a97e;p=libs%2Fgl.git diff --git a/source/core/uniformblock.cpp b/source/core/uniformblock.cpp index f713bd2a..8f85b87f 100644 --- a/source/core/uniformblock.cpp +++ b/source/core/uniformblock.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "buffer.h" @@ -5,10 +6,11 @@ #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 { @@ -25,16 +27,64 @@ unsigned UniformBlock::get_alignment() const return Limits::get_global().uniform_buffer_alignment; } -void UniformBlock::store(const ReflectData::UniformInfo &info, const Uniform &uni) +void UniformBlock::store(const ReflectData::UniformInfo &info, unsigned array_size, const void *value) { + array_size = min(array_size, max(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(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