3ds Max C++ API Reference
EffectHandle Class Reference

EffectHandle is a class provides features similar as Effect in Direct3D This class is used for viewport display and Quicksilver. More...

#include <EffectHandle.h>

+ Inheritance diagram for EffectHandle:

Public Member Functions

GraphicsDriverAPI EffectHandle ()
 
GraphicsDriverAPI EffectHandle (const EffectHandle &from)
 
GraphicsDriverAPI EffectHandleoperator= (const EffectHandle &from)
 
virtual GraphicsDriverAPI ~EffectHandle ()
 
GraphicsDriverAPI void Activate (DrawContext &dc)
 Activates the material handle with the specified pipeline context. More...
 
GraphicsDriverAPI void Terminate ()
 Terminates the material handle, performing any cleanup required by the material handle. More...
 
GraphicsDriverAPI unsigned int GetPassCount (DrawContext &dc) const
 Retrieves the number of passes required to render the material handle. More...
 
GraphicsDriverAPI void ActivatePass (DrawContext &dc, unsigned int pass)
 Activates the specified pass of the material handle, at which point it may render geometry as necessary for the pass. More...
 
GraphicsDriverAPI void PassesFinished (DrawContext &dc)
 Called after all of the passes for the material handle have been drawn. More...
 
GraphicsDriverAPI bool InitializeWithFile (const MSTR &fileName)
 Initialize an instance of FXEffectHandle. More...
 
GraphicsDriverAPI bool InitializeWithData (void *data, size_t length, MSTR *errorInfo=nullptr)
 Initialize an instance of FXEffectHandle with shader string. More...
 
GraphicsDriverAPI bool InitializeWithResource (int iShaderID, HINSTANCE hInst, const MSTR &strTypeName, MSTR *errorInfo=nullptr)
 Initialize an instance of FXEffectHandle from resource. More...
 
GraphicsDriverAPI int GetParameterCount () const
 Returns the parameter count of material. More...
 
GraphicsDriverAPI int GetParameterIndex (const MSTR &parameterName) const
 Returns the index of parameter. More...
 
GraphicsDriverAPI void SetActiveTechniqueByName (const MSTR &techniqueName)
 Sets active technique by name Only available for ".fx" based effect. More...
 
GraphicsDriverAPI void SetActiveTechnique (int techIndex)
 Sets active technique by zero-based index Only available for ".fx" based effect. More...
 
GraphicsDriverAPI int GetActiveTechnique ()
 Gets current active technique index. More...
 
GraphicsDriverAPI TechniqueNames GetTechniqueNames ()
 Get a string list of technique names in the effect. More...
 
GraphicsDriverAPI EffectInstanceHandle CreateEffectInstance ()
 Create an new effect instance. More...
 
- Public Member Functions inherited from SmartHandle
virtual GraphicsDriverAPI ~SmartHandle ()
 destructor More...
 
GraphicsDriverAPI bool IsValid () const
 Check if this handle is valid. More...
 
GraphicsDriverAPI void Release ()
 Release the underlying graphics objects. More...
 
GraphicsDriverAPI Identifier GetObjectID () const
 Get the underlying graphics object id. More...
 
GraphicsDriverAPI void SetPointer (IRefObject *pObject)
 
GraphicsDriverAPI IRefObjectGetPointer () const
 Get the underlying graphics object pointer. More...
 
bool operator== (const SmartHandle &rhs) const
 
bool operator!= (const SmartHandle &rhs) const
 
bool operator< (const SmartHandle &rhs) const
 
bool operator<= (const SmartHandle &rhs) const
 
bool operator> (const SmartHandle &rhs) const
 
bool operator>= (const SmartHandle &rhs) const
 
GraphicsDriverAPI SmartHandle (const SmartHandle &)
 
GraphicsDriverAPI SmartHandleoperator= (const SmartHandle &)
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 
- Protected Member Functions inherited from SmartHandle
GraphicsDriverAPI SmartHandle ()
 
- Protected Attributes inherited from SmartHandle
IRefObjectmpObject
 

Detailed Description

EffectHandle is a class provides features similar as Effect in Direct3D This class is used for viewport display and Quicksilver.

It can also be used for realistic material display. See IHLSLMaterialTranslator for more details. Example of use:

//Initialize the effect
EffectHandle hEffect;
EffectInstanceHandle hEffectInstance;
MSTR errorInfo;
hEffect.InitializeWithFile(shaderFileName, &errorInfo);
hEffectInstance = hEffect.CreateEffectInstance();
hEffectInstance.SetFloatParameter(_M("myFloatShaderParam"), floatValue);
...
//Before draw calls:
//Render with the effect
hEffect.Activate(dc); //Activate the effect first
hEffectInstance0.Apply(dc); //Apply values to the effect
for (int i = 0; i < hEffect.GetPassCount(dc); ++i)
{
hEffect.ActivatePass(dc, i); //Apply each pass
pVirtualDevice.Draw(...);
}
hEffect.PassesFinished(dc); Finish this effect instance
hEffectInstance1.Apply(dc); //Apply next instance, which parent effect is same as above.
for (int i = 0; i < hEffect.GetPassCount(dc); ++i)
{
hEffect.ActivatePass(dc, i); //Apply and draw this instance
pVirtualDevice.Draw(...);
}
hEffect.PassesFinished(dc);
hEffect.Terminate(); //End of the effect usage.
GraphicsDriverAPI EffectHandle()
Definition: strclass.h:738
#define _M(x)
Used to wrap string literals.
Definition: strbasic.h:67

Constructor & Destructor Documentation

◆ EffectHandle() [1/2]

◆ EffectHandle() [2/2]

◆ ~EffectHandle()

virtual GraphicsDriverAPI ~EffectHandle ( )
virtual

Member Function Documentation

◆ operator=()

GraphicsDriverAPI EffectHandle& operator= ( const EffectHandle from)

◆ Activate()

GraphicsDriverAPI void Activate ( DrawContext dc)

Activates the material handle with the specified pipeline context.

Parameters
[in]dcThe pipeline context.

◆ Terminate()

GraphicsDriverAPI void Terminate ( )

Terminates the material handle, performing any cleanup required by the material handle.

◆ GetPassCount()

GraphicsDriverAPI unsigned int GetPassCount ( DrawContext dc) const

Retrieves the number of passes required to render the material handle.


Each geometry to be drawn with the effect must be drawn that number of times. This pass count can only be retrieved while the effect is active.

Parameters
[in]dcThe pipeline context.
Returns
Returns pass count.

◆ ActivatePass()

GraphicsDriverAPI void ActivatePass ( DrawContext dc,
unsigned int  pass 
)

Activates the specified pass of the material handle, at which point it may render geometry as necessary for the pass.

Parameters
[in]dcThe pipeline context.
[in]passThe index of pass.

◆ PassesFinished()

GraphicsDriverAPI void PassesFinished ( DrawContext dc)

Called after all of the passes for the material handle have been drawn.

Parameters
[in]dcThe pipeline context.

◆ InitializeWithFile()

GraphicsDriverAPI bool InitializeWithFile ( const MSTR fileName)

Initialize an instance of FXEffectHandle.

A FXEffectHandle should be initialized before it's used.

Parameters
[in]fileNameHLSL shader file name.
Returns
true if successfully initialized, false otherwise.

◆ InitializeWithData()

GraphicsDriverAPI bool InitializeWithData ( void data,
size_t  length,
MSTR errorInfo = nullptr 
)

Initialize an instance of FXEffectHandle with shader string.

A FXEffectHandle should be initialized before it's used.

Parameters
[in]dataHLSL shader content.
[in]lengthThe length of data.
[out]errorInfoA MSTR pointer, return error strings if effect is failed to load. Can be nullptr.
Returns
true if successfully initialized, false otherwise.

◆ InitializeWithResource()

GraphicsDriverAPI bool InitializeWithResource ( int  iShaderID,
HINSTANCE  hInst,
const MSTR strTypeName,
MSTR errorInfo = nullptr 
)

Initialize an instance of FXEffectHandle from resource.

A FXEffectHandle should be initialized before it's used.

Parameters
[in]iShaderIDresource ID of the shader
[in]hInstmodule instance handle
[in]strTypeNameresource block name
[out]errorInfoA MSTR pointer, return error strings if effect is failed to load. Can be nullptr.
Returns
true if successfully initialized, false otherwise.
Note
: This method supports loading a compiled HLSL shader.

◆ GetParameterCount()

GraphicsDriverAPI int GetParameterCount ( ) const

Returns the parameter count of material.

Returns
the parameter count.

◆ GetParameterIndex()

GraphicsDriverAPI int GetParameterIndex ( const MSTR parameterName) const

Returns the index of parameter.

Parameters
[in]parameterNameThe unique parameter name of the parameter.
Returns
valid index if successful, otherwise -1

◆ SetActiveTechniqueByName()

GraphicsDriverAPI void SetActiveTechniqueByName ( const MSTR techniqueName)

Sets active technique by name Only available for ".fx" based effect.

Parameters
[in]techniqueNameName of the technique to activate

◆ SetActiveTechnique()

GraphicsDriverAPI void SetActiveTechnique ( int  techIndex)

Sets active technique by zero-based index Only available for ".fx" based effect.

Parameters
[in]techIndexIndex of the technique to activate

◆ GetActiveTechnique()

GraphicsDriverAPI int GetActiveTechnique ( )

Gets current active technique index.

Returns
the active technique index

◆ GetTechniqueNames()

GraphicsDriverAPI TechniqueNames GetTechniqueNames ( )

Get a string list of technique names in the effect.

Returns
TechniqueNames a list of string contains technique names in the effect

◆ CreateEffectInstance()

GraphicsDriverAPI EffectInstanceHandle CreateEffectInstance ( )

Create an new effect instance.

Returns
new instance of the effect parameter packet. It contains values of all parameters.