Example #1
0
	void PhongShader::enable( unsigned char lightMask, bool useTexture )
	{
		// Computes the identifier of the shader
		unsigned int identifier = computeIdentifier(lightMask, useTexture);
		// Retrieves the shader
		auto it=m_precompiledShaders.find(identifier) ;
		if(it!=m_precompiledShaders.end()) 
		{ 
			it->second->enable() ; 
			return ;
		}
		// The shader has not been compiled... Let's go!
		ShaderProgram * program = compileShaderProgram(lightMask, useTexture );
		m_precompiledShaders[identifier] = program ;
		program->enable() ;
	}
QGLShaderProgram *MGLES2Renderer::getShaderProgram(const QString &frag, const QString &vert)
{
    // First try a direct lookup with the passed-in filenames.  If they are
    // already canonical and the program exists in the cache, the file system
    // access can be skipped altogether.
    QGLShaderProgram *program = d_ptr->m_programCache.value(MGLProgramKey(frag, vert));

    if (!program) {
        const MGLProgramKey key(canonicalFilename(frag), canonicalFilename(vert));
        program = d_ptr->m_programCache.value(key);

        if (!program) {
            program = d_ptr->requestBinaryProgram(key.first, key.second);
            if (!program)
                program = compileShaderProgram(key.first, key.second);
            if (program)
                d_ptr->m_programCache.insert(key, program);
        }
    }
    return program;
}