From: Mikko Rasa Date: Thu, 20 Jun 2019 08:38:11 +0000 (+0300) Subject: Split the interface queries from Program::link into separate functions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=edc2ea855300df08d9f68f2e67316385b003dba6;p=libs%2Fgl.git Split the interface queries from Program::link into separate functions --- diff --git a/source/program.cpp b/source/program.cpp index 270dbdc3..c3625f41 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -142,6 +142,12 @@ void Program::link() IO::print("Program link info log:\n%s", info_log); #endif + query_uniforms(); + query_attributes(); +} + +void Program::query_uniforms() +{ unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS); vector uniforms_by_index(count); for(unsigned i=0; i used_bind_points; - count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS); - for(unsigned i=0; i indices(value); - glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]); - for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) - { - if(!uniforms_by_index[*j]) - throw logic_error("Program::link"); - info.uniforms.push_back(uniforms_by_index[*j]); - uniforms_by_index[*j]->block = &info; - } - - vector indices2(indices.begin(), indices.end()); - vector values(indices.size()); - glGetActiveUniformsiv(id, indices.size(), &indices2[0], GL_UNIFORM_OFFSET, &values[0]); - for(unsigned j=0; jlocation = values[j]; - - indices2.clear(); - for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) - if(uniforms_by_index[*j]->size>1) - indices2.push_back(*j); - if(!indices2.empty()) - { - glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]); - for(unsigned j=0; jarray_stride = values[j]; - } - - indices2.clear(); - for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) - { - GLenum t = uniforms_by_index[*j]->type; - if(t==GL_FLOAT_MAT4 || t==GL_FLOAT_MAT3 || t==GL_FLOAT_MAT2 || - t==GL_FLOAT_MAT2x3 || t==GL_FLOAT_MAT2x4 || t==GL_FLOAT_MAT3x2 || - t==GL_FLOAT_MAT3x4 || t==GL_FLOAT_MAT4x2 || t==GL_FLOAT_MAT4x3) - indices2.push_back(*j); - } - if(!indices2.empty()) - { - glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_MATRIX_STRIDE, &values[0]); - for(unsigned j=0; jmatrix_stride = values[j]; - } - - sort(info.uniforms.begin(), info.uniforms.end(), uniform_location_compare); - info.layout_hash = compute_layout_hash(info.uniforms); - unsigned n_bindings = BufferRange::get_n_uniform_buffer_bindings(); - info.bind_point = info.layout_hash%n_bindings; - while(used_bind_points.count(info.bind_point)) - info.bind_point = (info.bind_point+1)%n_bindings; - glUniformBlockBinding(id, i, info.bind_point); - used_bind_points.insert(info.bind_point); - } - } + query_uniform_blocks(uniforms_by_index); UniformBlockInfo &default_block = uniform_blocks[string()]; default_block.data_size = 0; @@ -276,6 +200,94 @@ void Program::link() uniform_layout_hash = hash32(layout_descriptor); } +void Program::query_uniform_blocks(const vector &uniforms_by_index) +{ + uniform_blocks.clear(); + + std::set used_bind_points; + unsigned count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS); + for(unsigned i=0; i indices(value); + glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]); + for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) + { + if(!uniforms_by_index[*j]) + throw logic_error("Program::link"); + info.uniforms.push_back(uniforms_by_index[*j]); + uniforms_by_index[*j]->block = &info; + } + + vector indices2(indices.begin(), indices.end()); + vector values(indices.size()); + glGetActiveUniformsiv(id, indices.size(), &indices2[0], GL_UNIFORM_OFFSET, &values[0]); + for(unsigned j=0; jlocation = values[j]; + + indices2.clear(); + for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) + if(uniforms_by_index[*j]->size>1) + indices2.push_back(*j); + if(!indices2.empty()) + { + glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]); + for(unsigned j=0; jarray_stride = values[j]; + } + + indices2.clear(); + for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) + { + GLenum t = uniforms_by_index[*j]->type; + if(t==GL_FLOAT_MAT4 || t==GL_FLOAT_MAT3 || t==GL_FLOAT_MAT2 || + t==GL_FLOAT_MAT2x3 || t==GL_FLOAT_MAT2x4 || t==GL_FLOAT_MAT3x2 || + t==GL_FLOAT_MAT3x4 || t==GL_FLOAT_MAT4x2 || t==GL_FLOAT_MAT4x3) + indices2.push_back(*j); + } + if(!indices2.empty()) + { + glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_MATRIX_STRIDE, &values[0]); + for(unsigned j=0; jmatrix_stride = values[j]; + } + + sort(info.uniforms.begin(), info.uniforms.end(), uniform_location_compare); + info.layout_hash = compute_layout_hash(info.uniforms); + unsigned n_bindings = BufferRange::get_n_uniform_buffer_bindings(); + info.bind_point = info.layout_hash%n_bindings; + while(used_bind_points.count(info.bind_point)) + info.bind_point = (info.bind_point+1)%n_bindings; + glUniformBlockBinding(id, i, info.bind_point); + used_bind_points.insert(info.bind_point); + } +} + +void Program::query_attributes() +{ + unsigned count = get_program_i(id, GL_ACTIVE_ATTRIBUTES); + for(unsigned i=0; i &uniforms) { string layout_descriptor; diff --git a/source/program.h b/source/program.h index cbb52cd4..826a4963 100644 --- a/source/program.h +++ b/source/program.h @@ -102,6 +102,9 @@ public: void link(); private: + void query_uniforms(); + void query_uniform_blocks(const std::vector &); + void query_attributes(); static LayoutHash compute_layout_hash(const std::vector &); static bool uniform_location_compare(const UniformInfo *, const UniformInfo *); public: