User Tools

Site Tools

Forest Render Interface Initialization

A CForestRI (RI stands for Render Interface) object cannot be instantiated by itself. It is essentially a shell, making graphics calls in the correct sequence, but has no knowledge of any particular graphics system. It is given this knowledge using template parameters. These parameters are known as policy classes (a concept introduced by Andrei Alexandrescu in his 2001 book Modern C++ Design), and they fill out the implementations of the class interfaces defined by CForestRI. Objects like CTextureRI, CRenderStateRI, and CgeometryBufferRI provide the necessary functionality for the Render Interface classes to carry out a full scene render. This technique enables client applications to replace any of the default SpeedTree implementations without changing the SDK library source.

Look at any of the rendering classes (OpenGL, DirectX, etc.) for an example of how a specific object can be defined with the proper template parameters and ultimately instantiated.

Consider the DirectX 9.0c instantiation taken from DirectX9Renderer.h:

//  Class CForestDirectX9
typedef CForestRI CForestDirectX9;

With this concrete object definition, complete with DirectX 9-based render objects, a forest can be created that's capable of rendering to a DirectX 9 device.

There are dozens of configurable parameters for the CForestRI object and most are stored in the SForestRenderInfo structure. Example parameters include the shader filename, fogging data, lighting parameters, shadow values, and more. Once these have been set using CForestRI::SetRenderInfo(), the graphics system is ready to be initialized.

CForestRI::InitGraphics() is the main initialization function that will build vertex buffers, load the shaders, set up wind, load textures, etc. After it is complete, the object is ready to manage rendering chores. See the reference application for an easy to follow example of how to set this up (but keep in mind that the code gets a little long with all the command-line options being used to call almost every possible configuration function).

Note: Once the CForestRI object has been initialized, whatever flags were used for setting wind, grass, and terrain support, cannot be changed.