From 58e4e69e640838076c506a94cd5f8f905d55420a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 2 Apr 2021 12:09:01 +0300 Subject: [PATCH] Rename some things in Program --- source/core/program.cpp | 46 ++++++++++++++++++------------------ source/core/program.h | 6 ++++- source/core/uniformblock.cpp | 2 +- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/source/core/program.cpp b/source/core/program.cpp index 9c296849..f28736bd 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -385,35 +385,35 @@ void Program::query_uniform_blocks(const vector &uniforms_by_inde uniforms_by_index[*j]->block = &info; } - vector indices2(indices.begin(), indices.end()); + vector query_indices(indices.begin(), indices.end()); vector values(indices.size()); - glGetActiveUniformsiv(id, indices.size(), &indices2[0], GL_UNIFORM_OFFSET, &values[0]); + glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_OFFSET, &values[0]); for(unsigned j=0; jlocation = values[j]; + uniforms_by_index[indices[j]]->offset = values[j]; - indices2.clear(); + query_indices.clear(); for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) if(uniforms_by_index[*j]->array_size>1) - indices2.push_back(*j); - if(!indices2.empty()) + query_indices.push_back(*j); + if(!query_indices.empty()) { - glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]); - for(unsigned j=0; jarray_stride = values[j]; + glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]); + for(unsigned j=0; jarray_stride = values[j]; } - indices2.clear(); + query_indices.clear(); for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) { DataType t = uniforms_by_index[*j]->type; if(is_matrix(t)) - indices2.push_back(*j); + query_indices.push_back(*j); } - if(!indices2.empty()) + if(!query_indices.empty()) { - glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_MATRIX_STRIDE, &values[0]); - for(unsigned j=0; jmatrix_stride = values[j]; + glGetActiveUniformsiv(id, query_indices.size(), &query_indices[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); @@ -511,7 +511,7 @@ void Program::collect_block_uniforms(UniformBlockInfo &block, const SpirVModule: UniformInfo &info = uniforms[name]; info.name = name; info.block = █ - info.location = i->offset; + info.offset = i->offset; info.array_size = i->array_size; info.array_stride = i->array_stride; info.matrix_stride = i->matrix_stride; @@ -580,12 +580,12 @@ const Program::UniformInfo &Program::get_uniform_info(const string &name) const return get_item(uniforms, name); } -int Program::get_uniform_location(const string &n) const +int Program::get_uniform_location(const string &name) const { - if(n[n.size()-1]==']') + if(name[name.size()-1]==']') throw invalid_argument("Program::get_uniform_location"); - UniformMap::const_iterator i = uniforms.find(n); + UniformMap::const_iterator i = uniforms.find(name); if(i==uniforms.end()) return -1; @@ -597,12 +597,12 @@ const Program::AttributeInfo &Program::get_attribute_info(const string &name) co return get_item(attributes, name); } -int Program::get_attribute_location(const string &n) const +int Program::get_attribute_location(const string &name) const { - if(n[n.size()-1]==']') + if(name[name.size()-1]==']') throw invalid_argument("Program::get_attribute_location"); - AttributeMap::const_iterator i = attributes.find(n); + AttributeMap::const_iterator i = attributes.find(name); return i!=attributes.end() ? i->second.location : -1; } @@ -628,7 +628,7 @@ void Program::unbind() Program::UniformInfo::UniformInfo(): block(0), - location(0), + location(-1), array_size(0), array_stride(0), matrix_stride(0), diff --git a/source/core/program.h b/source/core/program.h index 5ed61eaa..48c18d0f 100644 --- a/source/core/program.h +++ b/source/core/program.h @@ -63,7 +63,11 @@ public: { std::string name; const UniformBlockInfo *block; - unsigned location; + union + { + int location; + unsigned offset; + }; unsigned array_size; unsigned array_stride; unsigned matrix_stride; diff --git a/source/core/uniformblock.cpp b/source/core/uniformblock.cpp index cc8945cf..6f63e385 100644 --- a/source/core/uniformblock.cpp +++ b/source/core/uniformblock.cpp @@ -60,7 +60,7 @@ void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni) { if(size) { - uni.store(info, &data[info.location]); + uni.store(info, &data[info.offset]); dirty = true; } else -- 2.45.2