Provides access to MShaderInstance objects for use in Viewport 2.0.
This class generates MShaderInstance objects for use with user-created MRenderItem objects. Any MShaderInstance objects created by this class are owned by the caller.
The methods for adding shader and shader include paths will allow for additional search paths to be used with the "getEffectsFileShader()" method which searches for shader files on disk. The default search path is in the "Cg" and "HLSL" folders found in the runtime directory. It is recommended that user defined shaders not reside at this location to avoid any potential shader conflicts.
When acquiring a shader instance the caller may also specify pre-draw and post-draw callback functions. These functions will be invoked any time a render item that uses the shader instance is about to be drawn. These callbacks are passed an MDrawContext object as well as the render item being drawn and may alter the draw state in order to get different rendering effects. Accessing Maya nodes from within these callbacks is an error and may result in instability.
#include <MShaderManager.h>
Public Types |
|
enum | MStockShader { k3dSolidShader, k3dBlinnShader } |
Name of an available "stock" shader. More... |
|
Public Member Functions |
|
MStatus | addShaderPath (const MString &path) const |
Add a path to the list of shader search
paths. |
|
MStatus | shaderPaths (MStringArray &paths) const |
Query the list of shader search paths.
|
|
MStatus | addShaderIncludePath (const MString &path) const |
Add a path to the list of paths used for
searching for shader include files. |
|
MStatus | shaderIncludePaths (MStringArray &paths) const |
Query the list of search paths user for
searching for shader include files. |
|
MShaderInstance * | getEffectsFileShader (const MString &effectsFileName, const MString &techniqueName, MShaderCompileMacro *macros=0, unsigned int numberOfMacros=0, bool useEffectCache=true, MShaderInstance::DrawCallback preCb=0, MShaderInstance::DrawCallback postCb=0) const |
Get a new instance of a shader generated
from an effects file stored on disk (ie. |
|
MShaderInstance * | getStockShader (MStockShader name, MShaderInstance::DrawCallback preCb=0, MShaderInstance::DrawCallback postCb=0) const |
Get a new instance of a stock shader.
|
|
Static Public Member Functions |
|
static const char * | className () |
Returns the name of this class. |
enum MStockShader |
Name of an available "stock" shader.
Add a path to the list of shader search paths.
[in] | path | Shader search path. |
MStatus shaderPaths | ( | MStringArray & | paths | ) | const |
Query the list of shader search paths.
[out] | paths | A string array which is filled in with search path strings. Each array element will contain one shader path string. |
Add a path to the list of paths used for searching for shader include files.
[in] | path | Shader include path. |
MStatus shaderIncludePaths | ( | MStringArray & | paths | ) | const |
Query the list of search paths user for searching for shader include files.
[out] | paths | A string array which is filled in with search path strings. Each array element will contain one shader include path string. |
MShaderInstance * getEffectsFileShader | ( | const MString & | effectsFileName, |
const MString & | techniqueName, | ||
MShaderCompileMacro * | macros = 0 , |
||
unsigned int | numberOfMacros =
0 , |
||
bool | useEffectCache =
true , |
||
MShaderInstance::DrawCallback | preCb = 0 , |
||
MShaderInstance::DrawCallback | postCb = 0 |
||
) | const |
Get a new instance of a shader generated from an effects file stored on disk (ie.
a CgFx file). Callers of this method assume lifetime management of the returned object.
Optionally, a pre-draw and post-draw callback function may be associated with the shader. The callbacks will be invoked any time a render item using the shader is drawn. Note that it is an error to only specify one of two callbacks. Unless both callbacks are specified, no callbacks will be registered.
[in] | effectsFileName | The effects file |
[in] | techniqueName | The name of a technique in the effects file. If an empty string is specified then the first technique in the effects file will be used. |
[in] | macros | Pointer to an array of shader macros structures. The default value is 0, meaning that no macros are specified. |
[in] | numberOfMacros | Number of macros. The default value is 0. |
[in] | useEffectCache | Use the internal effect cache to prevent reloading the effect file every time it is requested. Unless you are changing the effect, this should always be set to true for maximum performance. |
[in] | preCb | A pointer to the function to be called before render items are drawn with this shader. |
[in] | postCb | A pointer to the function to be called after render items are drawn with this shader. |
MShaderInstance * getStockShader | ( | MStockShader | name, |
MShaderInstance::DrawCallback | preCb = 0 , |
||
MShaderInstance::DrawCallback | postCb = 0 |
||
) | const |
Get a new instance of a stock shader.
Callers of this method assume lifetime management of the returned object.
Optionally, a pre-draw and post-draw callback function may be associated with the shader. The callbacks will be invoked any time a render item using the shader is drawn. Note that it is an error to only specify one of two callbacks. Unless both callbacks are specified, no callbacks will be registered.
[in] | name | Name of stock shader |
[in] | preCb | A pointer to the function to be called before render items are drawn with this shader. |
[in] | postCb | A pointer to the function to be called after render items are drawn with this shader. |
const char * className | ( | ) | [static] |