IShaderManager Class Reference
 
 
 
IShaderManager Class Reference

This reference page is linked to from the following overview topics: Implementing Advanced Material and Texture Map Plug-ins with Nitrous, Material Plug-in Display Interface.


#include <IShaderManager.h>

Inheritance diagram for IShaderManager:
BaseInterface InterfaceServer MaxHeapOperators

Class Description

Represents the programmable shader associated with a material or texture map plug-in.

Materials and texture maps can use programmable shaders to describe their appearance when displayed in the Nitrous viewport and rendered with Quicksilver. Programmable shaders allow for a more realistic and complex visual appearance than ISimpleMaterial does. Note that 3ds Max 2012 only supports MetaSL shaders.

Plug-ins do not need to derive from IShaderManager. They rather need to create instances of it using IShaderManagerCreator::CreateShaderManager(), one for each shader they support. 3ds Max will query the plug-in for its IShaderManager via a request for the interface identified by ISHADER_MANAGER_INTERFACE_ID. Typically a plug-in would create an instance of IShaderManager in response to this request in its override of Animatable::GetInterface(Interface_ID) and delete it in its destructor by calling IShaderManagerCreator::DeleteShaderManager(). The following code snippet illustrates how a plug-in manages its IShaderManager instance:

        #include <graphics/IShaderManager.h>
        // A material plug-in that has a shader
        class MyMtlPlugin : public MtlBase {
        private:
                IShaderManager* mShaderManager;
        public:
                MyMtlPlugin() : mShaderManager(NULL) { 
                        // It's not recommended to create the IShaderManager in the plug-in's constructor 
                        // since the shader manager needs a pointer to the plug-in, which hasn't been
                        // fully constructed yet. Therefore calls the shader manager may make to 
                        // virtual methods of the plug-in may lead to a crash.
                }
                ~MyMtlPlugin() {
                        // Do not call the delete operator in mShaderManager, ask IShaderManagerCreator 
                        // to destroy it properly.
                        IShaderManagerCreator::GetInstance()->DeleteShaderManager(mpManager);
                        mpManager = NULL;
                }

                BaseInterface* GetInterface(Interface_ID iid) {
                        if (ISHADER_MANAGER_INTERFACE_ID == iid)
                                // In case the plug-in may have several shaders with one IShaderManager 
                                // instance for each, it will need to make sure that the IShaderManager
                                // interface pointer that is returned corresponds to the currently active 
                                // shader.
                                return GetShaderManager();
                        else
                                return MtlBase::GetInterface(iid);
                }

                IShaderManager* GetShaderManager() {
                        if (mpManager == NULL) {
                                mpManager = IShaderManagerCreator::GetInstance()->CreateShaderManager(
                                        IShaderManager::ShaderTypeMetaSL, 
                                        _M("MetaSL shader class name"), // same class name as found in the shader file
                                        _M("Fully qualified shader file path") // Full path to a xmsl shader file
                                        this);
                        }
                        return mpManager;
                }
        };

The parameters of the shader need to be fed with values from the parameters of the material or texture map plug-in. This process is facilitated by class IParameterTranslator that plug-ins need to implement.

See also:
IParameterTranslator

Public Types

enum   ShaderType { ShaderTypeMetaSL = 0 }
  Supported shader types. More...

Public Member Functions

virtual Interface_ID  GetID ()
  Retrieves the interface ID of IShaderManager.
virtual ShaderType  GetShaderType () const =0
  Retrieves the shader's type.
virtual const MCHAR *  GetShaderClassName () const =0
  Retrieves the shader's class name.
virtual const MCHAR *  GetShaderFile () const =0
  Retrieves the fully qualified path of the shader file.

Member Enumeration Documentation

Supported shader types.

Enumerator:
ShaderTypeMetaSL 

MetaSL shader.

        {
                ShaderTypeMetaSL = 0, 
        };

Member Function Documentation

virtual Interface_ID GetID ( ) [inline, virtual]

Retrieves the interface ID of IShaderManager.

Reimplemented from BaseInterface.

virtual ShaderType GetShaderType ( ) const [pure virtual]

Retrieves the shader's type.

virtual const MCHAR* GetShaderClassName ( ) const [pure virtual]

Retrieves the shader's class name.

virtual const MCHAR* GetShaderFile ( ) const [pure virtual]

Retrieves the fully qualified path of the shader file.