示例#1
0
    GLuint createProgram(GLenum type, const char* source)
    {
        GLchar	logStr[MAX_INFOLOG_LENGTH];
        GLint	status, length;

        GLuint program = glCreateProgram();

        compileAndAttachShader(program, type, strlen(source), source);

        glLinkProgram(program);
        glGetProgramiv(program, GL_LINK_STATUS, &status);

        if (!status)
        {
            glGetProgramInfoLog(program, MAX_INFOLOG_LENGTH, &length, logStr);
            printf("%s", logStr);
            glDeleteProgram(program);

            return 0;
        }

        glValidateProgram(program);
        glGetProgramiv(program, GL_VALIDATE_STATUS, &status);

        if (!status)
        {
            glGetProgramInfoLog(program, MAX_INFOLOG_LENGTH, &length, logStr);
            printf("%s", logStr);
        }

        return program;
    }
示例#2
0
bool DGLShader::create( bool linkNow )
{   
    _ready = false;

    if( !_programID )
        _programID = glCreateProgram();
    
    // compile and attach the different shader objects
    if( !compileAndAttachShader( _vertexShaderID, GL_VERTEX_SHADER, "Vertex Shader", _vertexShaderFilename, _vertexShaderString ) )
        return false;

    if( !compileAndAttachShader( _geometryShaderID, GL_GEOMETRY_SHADER, "Geometry Shader", _geometryShaderFilename, _geometryShaderString ) )
        return false;

    if( !compileAndAttachShader( _fragmentShaderID, GL_FRAGMENT_SHADER, "Fragment Shader", _fragmentShaderFilename, _fragmentShaderString ) )
        return false;

    if( linkNow )
        return link();

    return true;
}
示例#3
0
文件: shader.cpp 项目: lgarest/42
/*
========================
compileAndLink2
========================
*/
bool CShader::compileAndLink2( void )
{
	bool totalResult = true;

	// clean up old state
	deactivateProgram();
	m_log = QString();

	// create a new program object
	m_program = glCreateProgram();
	if( m_program == 0 )
	{
		m_log += QString( "ERROR: Failed on glCreateProgram()\n" );
		return false;
	}

	// update shaders
	for( int i = 0 ; i < MAX_SHADER_TYPES ; i++ )
	{
		bool result = compileAndAttachShader( i );
		totalResult = totalResult && result;
	}

	// if we have shaders attached, link them to a program.
	if( totalResult )
	{
		bool result = linkAndValidateProgram();
		totalResult = totalResult && result;
	}

	// post processing...
	if( totalResult )
	{
		setupInitialUniforms();
		setupRememberedUniformState();
	}

	return totalResult;
}