Esempio n. 1
0
bool Shader::_parseShaderDefines(const std::string& str, ShaderDefines& defines, unsigned int& index)
{
    OSG_INFO<<"Shader::_parseShaderDefines("<<str<<")"<<std::endl;
    std::string::size_type start_of_parameter = 0;
    bool firstString = true;
    bool indexSet = false;
    do
    {
        // skip spaces, tabs, commans
        start_of_parameter = find_first(str, NoneOf(" \t,"), start_of_parameter);
        if (start_of_parameter==std::string::npos) break;

        // find end of the parameter
        std::string::size_type end_of_parameter = find_first(str, OneOf(" \t,)"), start_of_parameter);

        if (end_of_parameter!=std::string::npos)
        {
            std::string::size_type start_of_open_brackets = find_first(str, EqualTo('('), start_of_parameter);
            if (start_of_open_brackets<end_of_parameter) ++end_of_parameter;
        }
        else
        {
            end_of_parameter = str.size();
        }

        if (start_of_parameter<end_of_parameter)
        {
            std::string parameter = str.substr(start_of_parameter, end_of_parameter-start_of_parameter);

            if (firstString)
            {
                firstString = false;
                if (parameter[0]>='0' && parameter[0]<='9')
                {
                    index = atoi(parameter.c_str());
                    indexSet = false;
                    OSG_INFO<<"   setting index("<<index<<")"<<std::endl;
                }
                else
                {
                    OSG_INFO<<"   defines.insert("<<parameter<<")"<<std::endl;
                    defines.insert(parameter);
                }
            }
            else
            {
                OSG_INFO<<"   defines.insert("<<parameter<<")"<<std::endl;
                defines.insert(parameter);
            }

        }

        start_of_parameter = end_of_parameter+1;

    } while (start_of_parameter<str.size());
    return indexSet;
}
Esempio n. 2
0
void Shader::_parseShaderDefines(const std::string& str, ShaderDefines& defines)
{
    OSG_INFO<<"Shader::_parseShaderDefines("<<str<<")"<<std::endl;
    std::string::size_type start_of_parameter = 0;
    do
    {
        // skip spaces, tabs, commans
        start_of_parameter = str.find_first_not_of(" \t,", start_of_parameter);
        if (start_of_parameter==std::string::npos) break;

        // find end of the parameter
        std::string::size_type end_of_parameter = str.find_first_of(" \t,)", start_of_parameter);

        if (end_of_parameter!=std::string::npos)
        {
            std::string::size_type start_of_open_brackets = str.find_first_of("(", start_of_parameter);
            if (start_of_open_brackets<end_of_parameter) ++end_of_parameter;
        }
        else
        {
            end_of_parameter = str.size();
        }

        if (start_of_parameter<end_of_parameter)
        {
            std::string parameter = str.substr(start_of_parameter, end_of_parameter-start_of_parameter);
            defines.insert(parameter);
            OSG_INFO<<"   defines.insert("<<parameter<<")"<<std::endl;
        }

        start_of_parameter = end_of_parameter+1;

    } while (start_of_parameter<str.size());
}