- query_uniforms();
- query_attributes();
- }
- else if(module->get_format()==Module::SPIR_V)
- {
- collect_uniforms();
- collect_attributes();
- }
-
- for(UniformMap::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
- require_type(i->second.type);
- for(AttributeMap::const_iterator i=attributes.begin(); i!=attributes.end(); ++i)
- require_type(i->second.type);
-}
-
-void Program::query_uniforms()
-{
- unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
- vector<UniformInfo *> uniforms_by_index(count);
- for(unsigned i=0; i<count; ++i)
- {
- char name[128];
- int len = 0;
- int size;
- GLenum type;
- glGetActiveUniform(id, i, sizeof(name), &len, &size, &type, name);
- if(len && strncmp(name, "gl_", 3))
- {
- /* Some implementations report the first element of a uniform array,
- others report just the name of the array itself. */
- if(len>3 && !strcmp(name+len-3, "[0]"))
- name[len-3] = 0;
-
- UniformInfo &info = uniforms[name];
- info.block = 0;
- info.name = name;
- info.array_size = size;
- info.array_stride = 0;
- info.matrix_stride = 0;
- info.type = from_gl_type(type);
- uniforms_by_index[i] = &info;
- }
- }
-
- if(ARB_uniform_buffer_object)
- query_uniform_blocks(uniforms_by_index);
-
- UniformBlockInfo &default_block = uniform_blocks[string()];
- default_block.data_size = 0;
- default_block.bind_point = -1;
-
- for(UniformMap::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
- if(!i->second.block)
- {
- i->second.location = glGetUniformLocation(id, i->second.name.c_str());
- i->second.block = &default_block;
- default_block.uniforms.push_back(&i->second);
- }
-
- default_block.layout_hash = compute_layout_hash(default_block.uniforms);
-
- update_layout_hash();
-}
-
-void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_index)
-{
- uniform_blocks.clear();
-
- std::set<unsigned> used_bind_points;
- unsigned count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS);
- for(unsigned i=0; i<count; ++i)
- {
- char name[128];
- int len;
- glGetActiveUniformBlockName(id, i, sizeof(name), &len, name);
- UniformBlockInfo &info = uniform_blocks[name];
- info.name = name;
-
- int value;
- glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_DATA_SIZE, &value);
- info.data_size = value;
-
- glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &value);
- vector<int> indices(value);
- glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]);
- for(vector<int>::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<unsigned> indices2(indices.begin(), indices.end());
- vector<int> values(indices.size());
- glGetActiveUniformsiv(id, indices.size(), &indices2[0], GL_UNIFORM_OFFSET, &values[0]);
- for(unsigned j=0; j<indices.size(); ++j)
- uniforms_by_index[indices[j]]->location = values[j];
-
- indices2.clear();
- for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
- if(uniforms_by_index[*j]->array_size>1)
- indices2.push_back(*j);
- if(!indices2.empty())