In OpenGL what is the difference between glUseProgram()
and glUseShaderProgram()
?
It seems in MESA and Nvidia provided glext.h
, and in GLEW, both are defined, and both seem to do basically the same thing. I find documentation for glUseProgram()
but not for glUseShaderProgram()
. Are they truly interchangeable?
glUseShaderProgramEXT()
is part of the EXT_separate_shader_objects extension.This extension was changed significantly in the version that gained ARB status as ARB_separate_shader_objects. The idea is still the same, but the API looks quite different. The extension spec comments on that:
The ARB version of the extension was then adopted as core functionality in OpenGL 4.1. If you're interested in using this functionality, using the core entry points in 4.1 is the preferred approach.
What all of this gives you is a way to avoid having to link the shaders for all the stages into a single program. Instead, you can create program objects that contain shaders for only a subset of the stages. You can then mix and match shaders from different programs without having to re-link them. To track which shaders from which programs are used, a new type of object called a "program pipeline" is introduced.
Explaining this in full detail is beyond the scope of this answer. You will use calls like
glCreateProgramPipelines()
,glBindProgramPipeline()
, andglUseProgramStages()
. You can find more details and example code on the OpenGL wiki.