plight/source/graphics/shader_manager.cpp
unsigned int
    ShaderManager::createProgram(String const& rName)
    {
        // Create shaders
        auto const shaderSourceFileTemplate = String("resource/%.%").arg(rName);
        auto const vertexShaderId = createShaderFromString(readStringFromFile(shaderSourceFileTemplate.arg("glvs")), EShaderType::Vertex);
        auto const fragmentShaderId = createShaderFromString(readStringFromFile(shaderSourceFileTemplate.arg("glfs")), EShaderType::Fragment);

        // Create program
        auto const programId = glCreateProgram();
        glAttachShader(programId, vertexShaderId);
        glAttachShader(programId, fragmentShaderId);

        // Link program
        glLinkProgram(programId);

        // Check program
        auto ok = GL_FALSE;
        glGetProgramiv(programId, GL_LINK_STATUS, &ok);
        if (ok != GL_TRUE)
            throw std::exception(String("Graphics error: %").arg(getProgramLog(programId)).c_str());

        // Clean up
        glDetachShader(programId, vertexShaderId);
        glDetachShader(programId, fragmentShaderId);
        glDeleteShader(vertexShaderId);
        glDeleteShader(fragmentShaderId);

        return programId;
    }
/*
        Creates a shader consisting of a vertex and a fragment shader and creates its program id
    */
Creates a shader consisting of a vertex and a fragment shader and creates its program id
Creates a shader consisting of a vertex and a fragment shader and creates its program id
unsigned int
    ShaderManager::createProgram(String const& rName)
    {
        auto const shaderSourceFileTemplate = String("resource/%.%").arg(rName);
        auto const vertexShaderId = createShaderFromString(readStringFromFile(shaderSourceFileTemplate.arg("glvs")), EShaderType::Vertex);
        auto const fragmentShaderId = createShaderFromString(readStringFromFile(shaderSourceFileTemplate.arg("glfs")), EShaderType::Fragment);
        auto const programId = glCreateProgram();
        glAttachShader(programId, vertexShaderId);
        glAttachShader(programId, fragmentShaderId);
        glLinkProgram(programId);
        auto ok = GL_FALSE;
        glGetProgramiv(programId, GL_LINK_STATUS, &ok);
        if (ok != GL_TRUE)
            throw std::exception(String("Graphics error: %").arg(getProgramLog(programId)).c_str());
        glDetachShader(programId, vertexShaderId);
        glDetachShader(programId, fragmentShaderId);
        glDeleteShader(vertexShaderId);
        glDeleteShader(fragmentShaderId);
        return programId;
    }
unsigned int ShaderManager :: createProgram ( String const & rName ) { auto const shaderSourceFileTemplate = String ( " " ) . arg ( rName ) ; auto const vertexShaderId = createShaderFromString ( readStringFromFile ( shaderSourceFileTemplate . arg ( " " ) ) , EShaderType :: Vertex ) ; auto const fragmentShaderId = createShaderFromString ( readStringFromFile ( shaderSourceFileTemplate . arg ( " " ) ) , EShaderType :: Fragment ) ; auto const programId = glCreateProgram ( ) ; glAttachShader ( programId , vertexShaderId ) ; glAttachShader ( programId , fragmentShaderId ) ; glLinkProgram ( programId ) ; auto ok = GL_FALSE ; glGetProgramiv ( programId , GL_LINK_STATUS , & ok ) ; if ( ok != GL_TRUE ) throw std :: exception ( String ( " " ) . arg ( getProgramLog ( programId ) ) . c_str ( ) ) ; glDetachShader ( programId , vertexShaderId ) ; glDetachShader ( programId , fragmentShaderId ) ; glDeleteShader ( vertexShaderId ) ; glDeleteShader ( fragmentShaderId ) ; return programId ; }
Creates a shader consisting of a vertex and a fragment shader and creates its program id
Creates a shader consisting of a vertex and a fragment shader and creates its program id
// Create shaders // Create program // Link program // Check program // Clean up