// This must handle names like "foo.bar[0]".
bool
ShaderValidator::FindUniformByMappedName(const std::string& mappedName,
                                         std::string* const out_userName,
                                         bool* const out_isArray) const
{
    const std::vector<sh::Uniform>& uniforms = *ShGetUniforms(mHandle);
    for (auto itr = uniforms.begin(); itr != uniforms.end(); ++itr) {
        const sh::ShaderVariable* found;
        if (!itr->findInfoByMappedName(mappedName, &found, out_userName))
            continue;

        *out_isArray = found->isArray();
        return true;
    }

    const size_t dotPos = mappedName.find(".");

    const std::vector<sh::InterfaceBlock>& interfaces = *ShGetInterfaceBlocks(mHandle);
    for (const auto& interface : interfaces) {

        std::string mappedFieldName;
        const bool hasInstanceName = !interface.instanceName.empty();

        // If the InterfaceBlock has an instanceName, all variables defined
        // within the block are qualified with the block name, as opposed
        // to being placed in the global scope.
        if (hasInstanceName) {

            // If mappedName has no block name prefix, skip
            if (std::string::npos == dotPos)
                continue;

            // If mappedName has a block name prefix that doesn't match, skip
            const std::string mappedInterfaceBlockName = mappedName.substr(0, dotPos);
            if (interface.mappedName != mappedInterfaceBlockName)
                continue;

            mappedFieldName = mappedName.substr(dotPos + 1);
        } else {
            mappedFieldName = mappedName;
        }

        for (const auto& field : interface.fields) {
            const sh::ShaderVariable* found;

            if (!field.findInfoByMappedName(mappedFieldName, &found, out_userName))
                continue;

            if (hasInstanceName) {
                // Prepend the user name of the interface that matched
                *out_userName = interface.name + "." + *out_userName;
            }

            *out_isArray = found->isArray();
            return true;
        }
    }

    return false;
}
// This must handle names like "foo.bar[0]".
bool
ShaderValidator::FindUniformByMappedName(const std::string& mappedName,
                                         std::string* const out_userName,
                                         bool* const out_isArray) const
{
    const std::vector<sh::Uniform>& uniforms = *ShGetUniforms(mHandle);
    for (auto itr = uniforms.begin(); itr != uniforms.end(); ++itr) {
        const sh::ShaderVariable* found;
        if (!itr->findInfoByMappedName(mappedName, &found, out_userName))
            continue;

        *out_isArray = found->isArray();
        return true;
    }

    const std::vector<sh::InterfaceBlock>& interfaces = *ShGetInterfaceBlocks(mHandle);
    for (const auto& interface : interfaces) {
        for (const auto& field : interface.fields) {
            const sh::ShaderVariable* found;

            if (!field.findInfoByMappedName(mappedName, &found, out_userName))
                continue;

            *out_isArray = found->isArray();
            return true;
        }
    }

    return false;
}
示例#3
0
bool ShaderValidator::FindVaryingByMappedName(const std::string& mappedName,
                                              std::string* const out_userName,
                                              bool* const out_isArray) const {
  const std::vector<sh::Varying>& varyings = *sh::GetVaryings(mHandle);
  for (auto itr = varyings.begin(); itr != varyings.end(); ++itr) {
    const sh::ShaderVariable* found;
    if (!itr->findInfoByMappedName(mappedName, &found, out_userName)) continue;

    *out_isArray = found->isArray();
    return true;
  }

  return false;
}