imrShaderClassDesc.h

Go to the documentation of this file.
00001 /*==============================================================================
00002 
00003   file:     imrShaderClassDesc.h
00004 
00005   author:   Daniel Levesque
00006 
00007   created:  10feb2003
00008 
00009   description:
00010 
00011       Class descriptor for mental ray shaders.
00012 
00013   modified: 
00014 
00015 
00016 (c) 2003 Autodesk
00017 ==============================================================================*/
00018 #pragma once
00019 
00020 #include "..\iparamb2.h"
00021 // forward declarations
00022 class imrShader;
00023 class mrShaderDesc;
00024 
00025 //==============================================================================
00026 // class imrShaderClassDesc
00027 //
00028 // Class descriptor for a mental ray shader. Dynamically created for each shader
00029 // encountered in the .mi files during startup. 
00030 //
00031 // This class derives from InterfaceServer to allow for future extensions.
00032 //==============================================================================
00033 class imrShaderClassDesc : public ClassDesc2, public InterfaceServer {
00034 
00035 private:
00036 
00037     // Apply types for this shader
00038     enum {
00039         // Types defined by the mental ray API
00040         kApply_Lens,
00041         kApply_Material,
00042         kApply_Light,
00043         kApply_Shadow,
00044         kApply_Environment,
00045         kApply_Volume,
00046         kApply_Texture,
00047         kApply_Photon,
00048         kApply_Geometry,
00049         kApply_Displace,
00050         kApply_PhotonEmitter,
00051         kApply_Output,
00052         kApply_LightMap,
00053         kApply_PhotonVol,
00054         kApply_Other,       
00055 
00056         // Additional types defined by the GUI attributes
00057         kApply_Bump,
00058         kApply_ContourShader,
00059         kApply_ContoutStore,
00060         kApply_ContourContrast,
00061         kApply_ContourOutput,
00062         kApply_Illum,
00063         kApply_PassMerge,
00064 
00065         kApply_MtlPhen,     // Shader is a material phenomenon
00066 
00067         kApply_Count
00068     };
00069 
00070 public:
00071     
00072     // Apply type bits when compined in a single value
00073     enum ApplyFlags {
00074         // Types defined by the mental ray API
00075         kApplyFlag_Lens = (1 << kApply_Lens),
00076         kApplyFlag_Material = (1 << kApply_Material),
00077         kApplyFlag_Light = (1 << kApply_Light),
00078         kApplyFlag_Shadow = (1 << kApply_Shadow),
00079         kApplyFlag_Environment = (1 << kApply_Environment),
00080         kApplyFlag_Volume = (1 << kApply_Volume),
00081         kApplyFlag_Texture = (1 << kApply_Texture),
00082         kApplyFlag_Photon = (1 << kApply_Photon),
00083         kApplyFlag_Geometry = (1 << kApply_Geometry),
00084         kApplyFlag_Displace = (1 << kApply_Displace),
00085         kApplyFlag_PhotonEmitter = (1 << kApply_PhotonEmitter),
00086         kApplyFlag_Output = (1 << kApply_Output),
00087         kApplyFlag_LightMap = (1 << kApply_LightMap),
00088         kApplyFlag_PhotonVol = (1 << kApply_PhotonVol),
00089         kApplyFlag_Other = (1 << kApply_Other),     
00090 
00091         // Additional types defined by the GUI attributes
00092         //kApply_None,      // Probably better remove this...
00093         kApplyFlag_Bump = (1 << kApply_Bump),
00094         kApplyFlag_ContourShader = (1 << kApply_ContourShader),
00095         kApplyFlag_ContourStore = (1 << kApply_ContoutStore),
00096         kApplyFlag_ContourContrast = (1 << kApply_ContourContrast),
00097         kApplyFlag_ContourOutput = (1 << kApply_ContourOutput),
00098         kApplyFlag_Illum = (1 << kApply_Illum),
00099         kApplyFlag_PassMerge = (1 << kApply_PassMerge),
00100         
00101         kApplyFlag_MtlPhen = (1 << kApply_MtlPhen),
00102 
00103         // All except mtl phenomenon
00104         kApplyFlag_All = (~0 & ~kApplyFlag_MtlPhen),
00105         
00106         // Default type accepts texure, material, illum, bump
00107         kApplyFlag_Default = (kApplyFlag_Material | kApplyFlag_Texture | kApplyFlag_Illum | kApplyFlag_Bump),
00108     };
00109 
00110     // Create a shader for the given apply type. The shader's default name will
00111     // match the apply type. Returns NULL if a bad apply type is given
00112     // virtual imrShader* CreateShader(ApplyType applyType) = 0;
00113 
00114     // Same as ClassDesc::Create(), but returns a pointer to a shader instead of a void*
00115     virtual imrShader* CreateShader(bool loading = false) = 0;
00116 
00117     // Get the types to which this shader may be applied (combination of 
00118     // ApplyFlags values).
00119     virtual unsigned int GetApplyTypes() = 0;
00120 
00121     // Get the shader descriptor for this class
00122     virtual mrShaderDesc& GetShaderDesc() = 0;
00123 
00124     // Access to the Parameters PBDesc & sub-PBDescs
00125     virtual ParamBlockDesc2* GetParamPBDesc() = 0;
00126     virtual Tab<ParamBlockDesc2*>& GetParamSubPBDescs() = 0;
00127 
00128     // Access to the Results PBDesc & sub-PBDescs
00129     virtual ParamBlockDesc2* GetResultPBDesc() = 0;
00130     virtual Tab<ParamBlockDesc2*>& GetResultPBDescs() = 0;
00131 
00132     // Access to the Connestions PBDesc & sub-PBDescs
00133     virtual ParamBlockDesc2* GetConnectionPBDesc() = 0;
00134     virtual Tab<ParamBlockDesc2*>& GetConnectionSubPBDescs() = 0;
00135 
00136     // Creates the auto param dialog for this shader
00137     virtual IAutoMParamDlg* CreateShaderParamDlgs(HWND hwMtlEdit, IMtlParams *imp, ReferenceTarget* obj) = 0;
00138 };
00139 
00140 // Pass this command ID to ClassDesc::Execute(). The function will return 
00141 // (GETIMRSHADERCLASSDESC_CMD+1) if the ClassDesc* can safely be cast to a imrShaderClassDesc*
00142 #define GETIMRSHADERCLASSDESC_CMD 0x984a860f
00143 
00144 // Converts, if possible, a ClassDesc* to a imrShaderClassDesc*
00145 inline imrShaderClassDesc* Get_mrShaderClassDesc(ClassDesc* cd) {
00146 
00147     if((cd != NULL) && (cd->Execute(GETIMRSHADERCLASSDESC_CMD) == (GETIMRSHADERCLASSDESC_CMD + 1))) {
00148         return static_cast<imrShaderClassDesc*>(cd);
00149     }
00150     else {
00151         return NULL;
00152     }
00153 }
00154