X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fprogram.cpp;h=b1516e2dc329c95d6d26f7cc1ce6d575f990ef45;hb=052b85720688900bc36f8844a94269cb1c0cdd52;hp=4e09038074613d64f0d5559127e51df305a156c2;hpb=b7f46931a9878b2fd7ec863d520dc22ac89c0baf;p=libs%2Fgl.git diff --git a/source/core/program.cpp b/source/core/program.cpp index 4e090380..b1516e2d 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -1,8 +1,5 @@ #include -#include #include -#include -#include #include #include #include @@ -15,14 +12,28 @@ #include #include #include -#include "buffer.h" #include "error.h" #include "program.h" -#include "resources.h" #include "glsl/compiler.h" using namespace std; +namespace { + +template +void uniform_wrapper(unsigned index, unsigned count, const void *data) +{ + func(index, count, static_cast(data)); +} + +template +void uniform_matrix_wrapper(unsigned index, unsigned count, const void *data) +{ + func(index, count, false, static_cast(data)); +} + +} + namespace Msp { namespace GL { @@ -344,12 +355,62 @@ void Program::query_uniforms() { u.location = glGetUniformLocation(id, u.name.c_str()); u.block = &default_block; + u.array_stride = get_type_size(u.type); + if(is_matrix(u.type)) + u.matrix_stride = get_type_size(get_matrix_column_type(u.type)); default_block.uniforms.push_back(&u); - if(is_image(u.type) && u.location>=0) - glGetUniformiv(id, u.location, &u.binding); + if(u.location>=0) + { + UniformCall::FuncPtr func = 0; + if(u.type==FLOAT) + func = &uniform_wrapper; + else if(u.type==FLOAT_VEC2) + func = &uniform_wrapper; + else if(u.type==FLOAT_VEC3) + func = &uniform_wrapper; + else if(u.type==FLOAT_VEC4) + func = &uniform_wrapper; + else if(u.type==INT) + func = &uniform_wrapper; + else if(u.type==INT_VEC2) + func = &uniform_wrapper; + else if(u.type==INT_VEC3) + func = &uniform_wrapper; + else if(u.type==INT_VEC4) + func = &uniform_wrapper; + else if(u.type==FLOAT_MAT2) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT3) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT4) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT2x3) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT3x2) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT2x4) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT4x2) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT3x4) + func = &uniform_matrix_wrapper; + else if(u.type==FLOAT_MAT4x3) + func = &uniform_matrix_wrapper; + else if(is_image(u.type)) + glGetUniformiv(id, u.location, &u.binding); + + if(func) + uniform_calls.push_back(UniformCall(u.location, u.array_size, func)); + } } + default_block.sort_uniforms(); + if(!default_block.uniforms.empty()) + { + const ReflectData::UniformInfo &uni = *default_block.uniforms.back(); + default_block.data_size = uni.location*16+uni.array_size*get_type_size(uni.type); + } default_block.update_layout_hash(); reflect_data.update_layout_hash(); }