1.1 Setup

To use Sh, some setup is required. First, you have to include the Sh header file. Assuming you have set up your include paths correctly, this is usually done as follows:


#include <sh/sh.hpp>
All Sh functions and classes are enclosed in the SH namespace. Explicitly qualifying each class or function in Sh would be rather tedious, but is useful in some circumstances. However, to make it easier to write shaders, you can isolate shader code in particular files and place the following clause in such files right after the inclusion of the header file:


using namespace SH;
Sh names are defined to avoid conflicts with other common libraries, in particular the standard libraries.

Before you can make any other Sh calls you have to initialize the library. This is done by calling the function shInit before making any other Sh calls.1 You can now use Sh for stream computing. If you want to use it for shaders, however, you will need two other calls. First, shBind will load a program into the shading unit given in the program’s definition. The shUpdate function should also be called after textures and uniform parameters have been modified but before rendering with the standard graphics API takes place. This will ensure that the Sh uniform parameters have been synchronized with the graphics API state.

Finally, you have to link your application to the libsh library, which can be used as a shared library.


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.