CHAPTER 10: OpenGL ES 2, Shaders, and... (^313)
if (logLength > 0)
{
GLchar log = (GLchar )malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log);
NSLog(@"Program link log:\n%s", log);
free(log);
}
#endif
glGetProgramiv(prog, GL_LINK_STATUS, &status);
if (status == 0)
{
return NO;
}
return YES;
}
After linking, it is customary to ‘‘validate’’ the program. Validation is a way for the
OpenGL implementors to return information about any aspects of your code, such as
recommended improvements. You would use this primarily during the development
process, as shown in Listing 10-3. And as before, it is largely error handling.
Listing 10-3. Program Validation
- (BOOL)validateProgram:(GLuint)prog
{
GLint logLength, status;
glValidateProgram(prog);
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar log = (GLchar )malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log);
NSLog(@"Program validate log:\n%s", log);
free(log);
}
glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
if (status == 0)
{
return NO;
}
return YES;
}
The final routine, loadShaders(), as shown in Listing 10-4, ties together the three
routines from earlier and binds our attributes and parameters to the program. That way,
we can pass an array of vertex information or parameters and specify their names on
both sides of the fence.