UniformVar RmPass::searchUniformVariable(QString &name, CodeType codetype) { QString &source = (codetype == FRAGMENT) ? fragment : vertex; int namelen = name.length(); int start = 0; int pos_name, pos_unif; while( (pos_name = source.indexOf(name, start)) != -1) { start += namelen; if ((pos_unif = source.lastIndexOf("uniform", pos_name)) == -1) continue; QString declaration = source.mid(pos_unif, pos_name - pos_unif + namelen + 1); QStringList list = declaration.split(QRegExp("\\s+")); if (list.size() != 3 || list[0] != "uniform" || (list[2] != name && list[2] != name + QString(";"))) continue; return UniformVar(name, list[1], UniformVar::getTypeFromString(list[1])); } return UniformVar(); }
UniformBuffer::UniformVar UniformBuffer::operator [] (const std::string& _name) { // Cannot access unknown attribute! Assert(m_attributes.find(_name) != m_attributes.end(), "Cannot access unknown attribute!"); return UniformVar((uint8*)m_memory + m_attributes[_name], this); }
const UniformBuffer::UniformVar UniformBuffer::operator [] ( const std::string& _name ) const { // Cannot access unknown attribute! Assert(m_attributes.find(_name) != m_attributes.end(), "Cannot access unknown attribute!"); // Give a nullptr instead of a buffer - it is only accessed during write return UniformVar((uint8*)m_memory + m_attributes.at(_name), nullptr); }
UniformVar::List GLProgram::getUniformList() { glCheck("GLProgram::getUniformList"); UniformVar::List list; GLint num = 0, buffer_size = 0; glRun(glGetProgramiv(m_prog, GL_ACTIVE_UNIFORMS, &num)); glRun(glGetProgramiv(m_prog, GL_ACTIVE_UNIFORM_MAX_LENGTH, &buffer_size)); std::vector<GLchar> name(buffer_size); for (GLint i = 0; i < num; i++) { GLsizei length; GLint size; GLenum type; glRun(glGetActiveUniform(m_prog, i, buffer_size, &length, &size, &type, &name[0])); // For now skip build-in uniforms, since those can't be changed the same way as others. if (strncmp(&name[0], "gl_", 3) != 0) list.push_back(UniformVar(shared_from_this(), &name[0], type)); } return list; }