To save the shader binary, first verify that the driver supports at least one shader binary format:
GLint formats = 0;glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &formats);if( formats < 1 ) { std::cerr << "Driver does not support any binary formats." << std::endl; exit(EXIT_FAILURE);}
Then, assuming at least one binary format is available, use glGetProgramBinary to retrieve the compiled shader code and write it to a file:
// Get the binary lengthGLint length = 0;glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &length);// Retrieve the binary codestd::vector<GLubyte> buffer(length);GLenum format = 0;glGetProgramBinary(program, length, NULL, &format, buffer.data());// Write the binary to a file.std::string fName("shader.bin" ...