GL_OES_get_program_binary

Supported Hardware

Series5, Series5XT, Series6, Series6XE, Series6XT

Valid APIs

OpenGL ES 2.0

Description

One of the larger costs of using shaders is that when initialising your application, they need to be compiled by an implementation's default compiler. Mechanisms exist to get the compiled shader binary back from the API after compilation, but there is still a linking stage after this which needs to be performed to create a program. This extension allows users to retrieve the fully compiled and linked program binary from the API, and then load it in on subsequent runs. Using this extension can save additional time on application start up compared to shader binaries as it also includes the attribute location binding and linking stages. It's worth noting that this extension does not itself define any binary formats, this is up to each vendor. For PowerVR hardware, these formats are defined by GL_IMG_program_binary.

Note

This functionality is core to OpenGL ES 3.0.

Registry Link

http://www.khronos.org/registry/gles/extensions/OES/OES_get_program_binary.txt

Example

// Create a shader program object 
GLuint shaderProgram = glCreateProgram(); 
// If there isn't already a binary, create a program 
if (!binaryExists) 
{ 
	// Create shaders, compile them, attach them and link them as per normal, then... 
	// Retrieve the program binary size 
	GLint length=0; 
	glGetProgramiv(shaderProgram, GL_PROGRAM_BINARY_LENGTH, &length); 
	// Pointer to the binary shader program in memory, needs to be allocated with the 
	// right size. 
	GLvoid* programBinaryData = (GLvoid*)malloc(length); 
	// The format that the binary is retrieved in. 
	GLenum binaryFormat=0; 
	// Error checking variable - this should be greater than 0 after 
	// glGetProgramBinaryOES, otherwise there was an error. 
	GLsizei lengthWritten=0; 
	glGetProgramBinaryOES(shaderProgram, length, &lengthWritten, 
						&binaryFormat, programBinaryData); 
} 
else 
{ 
	// Get the binary data, how much data there is, and what format it's in from whatever 
	// cache it is stored in (e.g. a file) 
	// ... 
	// Instead of creating, compiling, attaching and linking shaders, upload a binary 
	// program data from a program that previously underwent all of these stages. 
	glProgramBinaryOES(shaderProgram, binaryFormat, programBinaryData, 
	programBinaryDataLength); 
}