Shader manager.
This class provides access to the list of available shaders, both system shaders and user shaders. The list comes in two versions:
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.
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(); }
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>
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. |
FBShaderManager | ( | ) |
Constructor.
~FBShaderManager | ( | ) |
Destructor.
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.
pShaderTypeName | Name of the type of shader desired. |
List of available shaders.
This list does provide the complete list of available shaders, both system defined and user defined.
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.
Definition at line 289 of file fbshader.h.