Example/GLSL Program Link Error Testing: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
Adrian (talk | contribs)
m Simply undoing changes because you can't handle criticism is immature. And initializing a local variable (it should be GL_FALSE btw) that you created purely for the following two lines is redundant.
Flfirsla (talk | contribs)
No edit summary
 
Line 4: Line 4:
GLuint program = glCreateProgram();
GLuint program = glCreateProgram();


//Attach shaders as necessary.
// Attach shaders as necessary.
glAttachShader(program, ...);
glAttachShader(program, ...);
...
...


//Link the program.
// Link the program.
glLinkProgram(program);
glLinkProgram(program);


GLint isLinked = 0;
GLint isLinked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
if(isLinked == GL_FALSE)
if (isLinked == GL_FALSE)
{
{
GLint maxLength = 0;
GLint maxLength = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);


//The maxLength includes the NULL character
// The maxLength includes the NULL character
std::vector<GLchar> infoLog(maxLength);
std::vector<GLchar> infoLog(maxLength);
glGetProgramInfoLog(program, maxLength, &maxLength, &infoLog[0]);
glGetProgramInfoLog(program, maxLength, &maxLength, &infoLog[0]);


//The program is useless now. So delete it.
// The program is useless now. So delete it.
glDeleteProgram(program);
glDeleteProgram(program);


//Provide the infolog in whatever manner you deem best.
// Provide the infolog in whatever manner you deem best.
//Exit with failure.
// Exit with failure.
return;
return;
}
}
</source>
</source>
<noinclude>[[Category:Example Code]]</noinclude>
<noinclude>[[Category:Example Code]]</noinclude>

Latest revision as of 11:10, 3 January 2018

Program Linking error checking.

GLuint program = glCreateProgram();

// Attach shaders as necessary.
glAttachShader(program, ...);
...

// Link the program.
glLinkProgram(program);

GLint isLinked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
if (isLinked == GL_FALSE)
{
	GLint maxLength = 0;
	glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);

	// The maxLength includes the NULL character
	std::vector<GLchar> infoLog(maxLength);
	glGetProgramInfoLog(program, maxLength, &maxLength, &infoLog[0]);

	// The program is useless now. So delete it.
	glDeleteProgram(program);

	// Provide the infolog in whatever manner you deem best.
	// Exit with failure.
	return;
}