I am using OpenGL SC Version 2.0.1 and while doing the functionality of program objects I found something that is not explicitly stated in the specification. glProgramBinary needs to receive a valid program object created by glCreateProgram, however, the specification does not indicate what should the library do in this case. I assume it would be the same case as glBind* commands, these generate INVALID_OPERATION when the object name is not obtained by its corresponding glGen* command.
Any thoughts on this? Did I miss something in the spec? Should I imply the application programmer knows that first glCreateProgram shall be called?
Dear @AgustinParra
That’s a known driver quirk: program binaries aren’t guaranteed, so the driver may report no supported formats.
Check at runtime with glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, …) and read GL_PROGRAM_BINARY_FORMATS if non‑zero. If none are available, fall back to compiling from source. Treat glProgramBinary as an optional optimization; eg. only use it when the driver advertises formats, otherwise keep a reliable compile path so your app runs everywhere.
// Minimal runtime check for program binary support
GLint numFormats = 0;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numFormats);
if (numFormats > 0) {
GLint formats[16];
// Clamp to a safe max in case driver reports many formats
GLsizei count = (numFormats > 16) ? 16 : numFormats;
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, formats);
// You can now use glProgramBinary with one of the supported formats
// e.g. pick formats[0] or match a saved format you previously used
} else {
// No binary formats supported: compile shaders from source as fallback
// Keep your shader compile/link path robust and use program binaries only as an optimization
}
GL;HC;
~p3nGu1nZz
Dear @p3nGu1nZz
First of all, thank you for your response. I’ve been working with this specification for a while, and there isn’t much interaction in forums about it.
I think I didn’t explain myself clearly, or perhaps I misunderstood your point. My question is: what does the glProgramBinary function do if it receives a program object name that was not generated by glCreateProgram, or if it receives the value 0? The OpenGL SC 2.0.1 specification does not provide guidance on this scenario.
@khronos Hi Khronos, any suggestions?
I’m not affiliated with Khronos Group and I know very little about OpenGL SC (at least the SC part).
Couldn’t you just try it out and see what your implementation of the spec does? It does seem like an omission in the spec, but that means different implementations may react differently and you’d have to handle that in your application. In this specific case it seems getting into this situation in the first place is an application bug, so I don’t know what would be the best way to handle it?
You could also file a bug report against the spec at the OpenGL API Issue Tracker.