Public Member Functions | Public Attributes

FBShaderManager Class Reference

Search for all occurrences

Detailed Description

Shader manager.

This class provides access to the list of available shaders, both system shaders and user shaders. The list comes in two versions:

  1. ShaderTypeNames : which gives the internal names of the shaders,
  2. ShaderTypeNamesLocalized : uses the GUI names of the shaders.

Both of these lists will have the same number of elements. The strings at position i in the lists refer to the same shader type. In cases where there is no localized version of the shader name, the internal name will be used in ShaderTypeNamesLocalized, thus ensuring consistency between the two lists.

It also provides a generic shader creation method that uses the shader type name, internal or localized, to create the new shader instance.

The destruction of shaders is achieved by calling the FBDelete method of a shader instance.

The list of all the instantiated shaders can be obtained from instances of classes FBSystem or FBScene. Both classes have a Shaders property which lists the existing shader instances.

Strings are used instead of enum, define or typedef values to refer to shader types as this proves to be more flexible.

Warning:
The system has a default shader of type 'Lighted'. Do not attempt to destroy it.
The use of localized names in shader creation is non portable as it is dependent of the current language used by the application. The name may also change from one version to another. Using the internal name is the only way to ensure portable shader creation.

Sample C++ code:

    // This could be a constant value in the code, coming from a custom
    // registry or simply coming from one of the list ShaderTypeNames
    // or ShaderTypeNamesLocalized.
    char* lDesiredShaderTypeName = "MyShader";

    // Shader creation.
    HFBShader lShader = NULL;
    FBShaderManager lShaderManager;

    if( lShaderManager.ShaderTypeNames.Find( lDesiredShaderTypeName ) != -1 ||
        lShaderManager.ShaderTypeNamesLocalized.Find( lDesiredShaderTypeName ) != -1 )
    {
        lShader = lShaderManager.CreateShader( lDesiredShaderTypeName );

        // Change its name, as the default name will be the type name.
        if( lShader )
        {
            lShader->Name = "My new shader";
        }
        else
        {
            // Warn about creation failure on a correctly registered
            // shader type.
        }
    }
    else
    {
        // Warn about an unknown shader type.
    }

    //
    // Do some work with the shader...
    // 

    if( lShader )
    {
        lShader->FBDelete();
    }
Note:
In the previous code sample, the lookup in the manager list is not necessary, as the call to CreateShader would have failed nonetheless and returned a NULL pointer.

Sample Python code:

    from pyfbsdk import *

    lShaderManager = FBShaderManager()

    # This code will create one instance of each of the
    # available shader type, changing its name to add the
    # 'My ' prefix.
    for lShaderTypeName in lShaderManager.ShaderTypeNames:
        lShader = lShaderManager.CreateShader( lShaderTypeName )
        if lShader:
            lShader.Name = "My %s" % lShader.Name
            print "Created new shader '%s'" % lShader.Name
        else:
            print "Unable to create shader of type '%s'" % lShaderTypeName

Definition at line 219 of file fbshader.h.

#include <fbshader.h>

List of all members.

Public Member Functions

  FBShaderManager ()
  Constructor.
  ~FBShaderManager ()
  Destructor.
HFBShader  CreateShader (const char *pShaderTypeName)
  Creates a shader according to the shader type provided.

Public Attributes

FBStringList  ShaderTypeNames
  List of available shaders.
FBStringList  ShaderTypeNamesLocalized
  List of available shaders.

Constructor & Destructor Documentation

Constructor.

Destructor.

Warning:
The destructor is non-virtual, meaning that this class is not meant to be used as a base class.

Member Function Documentation

HFBShader CreateShader ( const char *  pShaderTypeName )

Creates a shader according to the shader type provided.

This method provides a generic way of creating shaders using the type name, internal or localized. The name of the new shader will be the same as the type name used, subject to changes according to the system's unique name policy.

Parameters:
pShaderTypeName Name of the type of shader desired.
Returns:
A pointer to the newly created shader object, or a NULL pointer if the type name was not recognised.

Member Data Documentation

List of available shaders.

This list does provide the complete list of available shaders, both system defined and user defined.

Warning:
This list should not be modified. Changes to its value will not affect the shaders supported.

Definition at line 266 of file fbshader.h.

List of available shaders.

This list also provides the complete list of available shaders, but uses the localized named, as they can be seen in the GUI.

The names in this list are a direct match to the items in the list ShaderTypeNames for a given index.

This list is provided as a convenience, to avoid having to use the localization mechanism to match internal and GUI name.

Warning:
Using localized names is potentially non portable as the name lookup is not done across all the supported languages. It is only done for the current language. In other words, using the English name to create a shader when the current language is not English will probably not succeed.
This list should not be modified. Changes to its value will not affect the shaders supported.

Definition at line 289 of file fbshader.h.


The documentation for this class was generated from the following file:

FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager
FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager FBShaderManager