X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogram.cpp;h=d962751994d38fe1e7fd93550bb51a545eaec9f6;hb=18878df418035445ba5146fcde3d647d7aa8c054;hp=8892bcf1ed7861b632c7c0bc5089ed53e61b4756;hpb=3f7b09b2e12830eb439889b300f0d6591c4952ac;p=libs%2Fgl.git diff --git a/source/program.cpp b/source/program.cpp index 8892bcf1..d9627519 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -254,6 +254,8 @@ void Program::link() info.block = 0; info.name = name; info.size = size; + info.array_stride = 0; + info.matrix_stride = 0; info.type = type; uniforms_by_index[i] = &info; } @@ -295,9 +297,12 @@ void Program::link() for(vector::iterator j=indices.begin(); j!=indices.end(); ++j) if(uniforms_by_index[*j]->size>1) indices2.push_back(*j); - glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]); - for(unsigned j=0; jarray_stride = values[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) @@ -308,10 +313,14 @@ void Program::link() t==GL_FLOAT_MAT3x4 || t==GL_FLOAT_MAT4x2 || t==GL_FLOAT_MAT4x3) indices2.push_back(*j); } - glGetActiveUniformsiv(id, indices2.size(), &indices2[0], GL_UNIFORM_MATRIX_STRIDE, &values[0]); - for(unsigned j=0; jmatrix_stride = values[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); info.bind_point = info.layout_hash%BufferRange::get_n_uniform_buffer_bindings(); glUniformBlockBinding(id, i, info.bind_point); @@ -337,6 +346,11 @@ unsigned Program::compute_layout_hash(const vector &uniform return hash32(layout_descriptor); } +bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInfo *uni2) +{ + return uni1->locationlocation; +} + string Program::get_info_log() const { GLsizei len = 0; @@ -373,14 +387,14 @@ int Program::get_uniform_location(const string &n) const add an offset. */ unsigned offset = lexical_cast(n.substr(open_bracket+1, n.size()-2-open_bracket)); i = uniforms.find(n.substr(0, open_bracket)+"[0]"); - if(i!=uniforms.end() && offsetsecond.size) + if(i!=uniforms.end() && !i->second.block && offsetsecond.size) return i->second.location+offset; } } return -1; } - return i->second.location; + return i->second.block ? -1 : i->second.location; } void Program::bind() const