示例#1
0
std::string StringTemplate::string() const
{
    if (!m_modifiedSource.isValid())
    {
        m_modifiedSource.setValue(modifiedSource());
    }

    return m_modifiedSource.value();
}
示例#2
0
void Shader::buildShader() {
    std::vector<GLuint> shaders;
    std::unordered_map<std::string, GLenum> shaderTypes = {
        { "#define TYPE_VERTEX\n",   GL_VERTEX_SHADER },
        { "#define TYPE_FRAGMENT\n", GL_FRAGMENT_SHADER }
    };

    std::stringstream version;
    version << "#version " << this->version << "\n";

    for (auto& shaderType: shaderTypes) {
        std::string modifiedSource(this->source);
        modifiedSource.replace(modifiedSource.find(TOKEN_VERSION), sizeof(TOKEN_VERSION), version.str());
        modifiedSource.replace(modifiedSource.find(TOKEN_TYPE), sizeof(TOKEN_TYPE), shaderType.first);

        shaders.push_back(this->compile(modifiedSource, shaderType.second));
    }

    this->program = this->link(shaders);
}