Graphics Reference
In-Depth Information
make the program active, you use the statement
Do not try to create or link
shader programs within a dis-
play list, because these func-
tions are executed immediately
when they are processed,
rather than being deferred
until the list is called. You
can, however, embed a call to
glUseProgram( ) in a display
list.
glUseProgram( program );
in your application. From this point until you
next call glUseProgram( ) , all graphics process-
ing will use the shader code in this shader pro-
gram.
To go back to using the fixed-function
graphics pipeline, you simply tell the system to
use a null shader program, like this:
glUseProgram( 0 );
If you want to change shader programs, as you may well want to do if
you want to use different shader programs for different parts of your display,
you need not deactivate one shader before you activate another. Simply acti-
vate the new shader program at the point where you want to begin using it.
The shader program being used is simply an atribute of the system; that is,
another part of the OpenGL state.
You may create, compile, link, and activate shader programs at any point
in your application, as long as the resulting active shader programs are com-
plete before you actually use them. In practice, you may want to make this
part of the initialization process for your application, the part that is usually
executed only once when your application begins, and where you set up the
application's graphics environment. You can then activate or deactivate your
shaders whenever you like.
Finally, you can not only deactivate a shader program; you can actually
delete it and all its components. This frees up the memory on the graphics
board for other shader programs or other uses. All of the functions that build
up a shader program have functional inverses, so you can
Detach a shader object from a shader program with
glDetachShader(shader) .
Delete a shader program with glDeleteProgram( program ) .
Delete a shader object with glDeleteShader( shader ) .
You have some protection from incorrect ordering of these functions,
because the actual effect of the function is delayed until it makes sense. If you
ask for a program object to be deleted, but it is part of the current rendering
state, it is not deleted until it is no longer part of the rendering context. If you
ask for a shader to be deleted, but it is still atached to a program object, it is
Search WWH ::




Custom Search