Sh program objects support introspection, allowing host applications to inspect them in various ways. This is particularily useful for host programs that provide some user interface layer on top of arbitrary Sh programs, such as the shrike application, which provides widgets to control uniform parameters and textures accessed by Sh programs. These introspection methods are also used internally by some of the built in Sh functions, such as the “shader algebra” operators discussed in Section 5.4.
The compilation target assigned to the program at definition time is available by calling the target member function on ShProgram objects, which returns a string such as "gpu:vertex". This string may be empty, which indicates that the program is generic. The generic compilation target is used for glue programs; programs with a generic target need a target assigned before they can be used.
/ Perhaps the most important introspection facilities for programs
are accessors for scanning dependencies: the lists of uniforms, inputs,
outputs, textures, streams, and temporary variables used by every program
object. All of these lists are accessible using STL (standard template
library) iterators. These iterators can be dereferenced, incremented and
compared to one another. The available iterator accessors are given in
Table 5.1.
|
/ Several functions are also available to make setting up program
objects more convenient. These descriptor functions return human readable
strings describing some aspect of an ShProgram. For instance, rather
than trying to figure out the results of the rules for binding a vertex
shader to the vertex attributes in OpenGL, you can just ask the shader to
describe the binding it requires, and it will generate a report that states
which OpenGL vertex attributes will get bound to which vertex shader
inputs.
The descriptor functions are listed in Table 5.2.
|
/ Programs, like most other Sh objects, also have all the metadata provided
by the ShMeta class, as explained in Section 2.7. This is also true for the
variables made available through the iterators listed in Table 5.1. The describers
access this metadata to make a report. A describer function is really querying the
metadata of the objects the program depends on. Note that you have to
actually provide this data, such as names and titles, for the describers to be
useful.
Note: This manual is available as a bound book from AK Peters, including better formatting, in-depth examples, and about 200 pages not available on-line.