RTMax.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 *<
00003 FILE: RTMax.h
00004 
00005 DESCRIPTION:    Main Include for DirectX and MS Effect related code
00006                 
00007 CREATED BY:     Neil Hazzard
00008 
00009 HISTORY:        February 2004
00010 
00011 *>  Copyright (c) 2004, All Rights Reserved.
00012 **********************************************************************/
00013 #pragma once
00014 
00015 #include <d3dx9.h>
00016 #include "export.h"
00017 #include "maxheap.h"
00018 #include "stdmat.h"
00019 #include "DeprecatedRealtimeMaterialTexturemapShaderAPI.h"
00020 
00021 
00023 #define SAFE_DELETE(p)          { if (p) { delete (p);      (p)=NULL; } }
00024 #define SAFE_DELETE_ARRAY(p)    { if (p) { delete[] (p);    (p)=NULL; } }
00025 #define SAFE_RELEASE(p)         { if (p) { (p)->Release();  (p)=NULL; } }
00026 
00028 #define SUMMER_SDK
00029 
00030 
00031 
00032 class ILightManager;
00033 class IRenderMesh;
00034 class IEffectParser;
00035 class IParameterManager;
00036 
00037 enum MaxSemantics
00038 {
00039     kSemanticUnknown,
00040     kSemanticDirection,
00041     kSemanticPosition,
00042     kSemanticWorld,
00043     kSemanticView,
00044     kSemanticPerspective,
00045     kSemanticWorldView,
00046     kSemanticProjection,
00047     kSemanticProjectionI,
00048     kSemanticProjectionIT,
00049     kSemanticViewI,
00050     kSemanticWorldI,
00051     kSemanticWorldViewI,
00052     kSemanticWorldViewProj,
00053     kSemanticWorldViewIT,
00054     kSemanticViewIT,
00055     kSemanticWorldIT,
00056     kSemanticWorldViewT,
00057     kSemanticWorldT,
00058     kSemanticViewT,
00059     kSemanticProjectionT,
00060     kSemanticWorldCamPos,
00061     kSemanticLightColor,
00062     kSemanticNormalMap,
00063     kSemanticBumpMap,
00064     kSemanticDiffuseMap,
00065     kSemanticSpecularMap,
00066     kSemanticOpacityMap,
00067     kSemanticLightMap,
00068     kSemanticDisplacementMap,
00069     kSemanticGlobalTime,
00070     kSemanticGlobalBkgrd,
00071     kSemanticLocalBBMin,
00072     kSemanticLocalBBMax,
00073     kSemanticLocalBBSize,
00074     kSemanticRecipLocalBBSize,
00075     kSemanticBitmapOverride,
00076     kSemanticColorOverride,
00077     kSemanticViewportDimensions,
00078     kSemanticATan,
00079     kSemanticDiffuse,
00080     kSemanticAmbient,
00081     kSemanticSpecular,
00082     kSemanticSpecularLevel,
00083     kSemanticGlossLevel,
00084     kSemanticOpacity,
00085     kSemanticEmissive,
00086     kSemanticReflectionMap,
00087     kSemanticLightFallOff,
00088     kSemanticLightHotSpot,
00089     kSemanticDirectionLocal,
00090     kSemanticPositionLocal,
00092     kSemanticLightAttenuation,  
00093     kSemanticPositionView,
00094     kSemanticDirectionView,
00095     kSemanticShadowData
00096 };
00097 
00099 
00104 class IEffectManager: public MaxHeapOperators{
00105 
00106 public:
00107     enum{
00108         kDirectX9,
00109         kDirectX10,
00110     };
00112     virtual ~IEffectManager() {;}
00113 
00124     virtual void SetFloatParam(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName, float val,float min, float max, float step,MaxSemantics semantic )=0;
00125 
00136     virtual void SetIntParam(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName,int val,int min, int max, int step,MaxSemantics semantic )=0;
00137 
00145     virtual void SetColorParam(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName,D3DXVECTOR4 color,MaxSemantics semantic)=0;
00146 
00157     virtual void SetPoint4Param(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName,D3DXVECTOR4 val,float min, float max, float step,MaxSemantics semantic) = 0;
00158 
00166     virtual void SetBooleanParam(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName,BOOL val,MaxSemantics semantic) = 0;
00167     
00177     virtual void SetTextureParam(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName,MCHAR * filename, MaxSemantics semantic, bool mappingEnabled = false, int mappingChannel=1)=0;
00178 
00186     virtual void SetLightParam(D3DXHANDLE handle, MCHAR * paramName, MCHAR * uiName,bool target,MaxSemantics semantic) = 0;
00187 
00192     virtual void SetTransformParam(D3DXHANDLE handle,MaxSemantics semantic)=0;
00193 
00198     virtual void SetGeometryParam(D3DXHANDLE handle,MaxSemantics semantic)=0;
00199 
00205     virtual void SetEnvironmentParam(D3DXHANDLE handle,MaxSemantics semantic)=0;
00206 
00212     virtual void SetTechnique(D3DXHANDLE handle, MCHAR * techniqueName, bool bDefault) =0;
00213 
00215 
00219     virtual UINT GetDirectXVersion()=0;
00220 
00221 };
00223 
00225 class IEffectParser: public MaxHeapOperators
00226 {
00227 public:
00235     virtual bool ParseEffectFile(LPVOID pDevice, const MaxSDK::AssetManagement::AssetUser& file, IEffectManager * em)=0;
00236 
00248     virtual bool LoadTexture(LPVOID pDevice, MCHAR * paramName, MCHAR * filename, bool forceReload, PBBitmap *pBitmap=NULL)=0;
00249 
00251     virtual void DestroyParser()=0;
00252 
00264     virtual bool PreRender(LPVOID pDevice, IRenderMesh * rmesh, ILightManager * lm, IParameterManager * pm, D3DCOLOR bkgColor, int width, int height ) = 0;
00265 
00271     virtual bool Render(LPVOID pDevice, IRenderMesh * rmesh, D3DXHANDLE primaryTechnique)=0;
00272 
00277     virtual void SetMappingChannel(D3DXHANDLE handle, int Channel)=0;
00278 
00280     virtual void SetUseLPRT(bool state){ UNUSED_PARAM(state); };
00281 
00283 
00291     virtual bool LoadEffect(LPVOID pDevice, IEffectManager * em, const MCHAR * effect, bool fileType, bool forceReload) =0;
00292 
00294     virtual const MCHAR * GetLastParserError() =0;
00295 
00297     virtual ~IEffectParser() {}
00298 
00299     
00301 
00305 
00306     virtual int GetNumberOfLightParameters() = 0;
00307 
00309     virtual MaxSemantics GetLightSemantic(int index)=0;
00310 
00312     virtual const MCHAR * GetLightHandle(int index)=0;
00313 
00315     virtual void OnLostDevice() = 0;
00316 
00318     virtual void OnResetDevice() = 0;
00319 
00321 
00326     virtual bool LoadTexture(LPVOID pTexture, const MCHAR* paramName) =0;
00327 
00328 };
00329 
00331 
00333 class ILightingData: public MaxHeapOperators{
00334 public:
00336     virtual ~ILightingData() {;}
00337 
00341     virtual D3DXVECTOR4 GetPosition()=0;
00342 
00346     virtual D3DXVECTOR4 GetDirection()=0;
00347 
00351     virtual D3DXVECTOR4 GetColor()=0;
00352 
00356     virtual float GetFallOff()=0;
00357 
00361     virtual float GetHotSpot()=0;
00362 
00364 
00372     virtual D3DXVECTOR4 GetAttenuation() =0;
00373 
00374 };
00375 
00377 
00379 class IShadowLightData: public MaxHeapOperators
00380 {
00381 public:
00383     virtual ~IShadowLightData() {;}
00384 
00387     virtual void UpdateShadowParam(LPVOID pEffect) = 0;
00390     virtual void ResetShadowData(LPVOID pEffect) = 0;
00391 };
00392 
00394 
00397 class ILightManager: public MaxHeapOperators{
00398 
00399 public:
00401     virtual ~ILightManager() {;}
00402 
00404 
00408     virtual ILightingData * GetLightingData(const MCHAR * paramName)=0;
00409 
00410 };
00412 
00416 class IParameterManager: public MaxHeapOperators{
00417 public:
00418     enum{
00419         kPType_Unknown,
00420         kPType_Float,
00421         kPType_Int,
00422         kPType_Bool,
00423         kPType_Point4,
00424         kPType_Matrix,
00425         kPType_Color,
00426         kPType_Struct,
00427         kPType_Texture,
00428     };
00429 
00431     virtual ~IParameterManager() {;}
00432 
00434 
00437     virtual int GetNumberOfParams()=0;
00438 
00440 
00444     virtual MaxSemantics GetParamSemantics(int index)=0;
00445 
00447 
00451     virtual const MCHAR * GetParamName(int index)=0;
00452 
00454 
00461     virtual bool GetParamData(LPVOID data, int index)=0;
00462     
00464 
00471     virtual bool GetParamData(LPVOID data, const MCHAR * paramName)=0;
00472 
00474 
00479     virtual int GetParamType(int index) = 0;
00480 
00482 
00487     virtual int GetParamType(const MCHAR * parmName) =0;
00488 
00490 
00494     virtual int GetParamSize(int index) = 0;
00495 };
00496 
00497 
00498 
00499 #include "iFnPub.h"
00500 
00501 #define PARSER_LOADER_INTERFACE Interface_ID(0x7fbe42d6, 0x3e7f412b)
00502 
00504 class EffectDescriptor: public MaxHeapOperators
00505 {
00506 public:
00508     virtual ~EffectDescriptor() {;}
00509 
00511 
00514     virtual IEffectParser * CreateParser() = 0;
00515 
00517 
00520     virtual ULONG GetParserID()=0;
00521 
00523 
00525     virtual const MCHAR * GetParserFileFilterName()=0;
00526 
00528 
00531     virtual const MCHAR * GetParserFileExtension()=0;
00532 
00533 };
00534 
00536 class IParserLoader : public FPStaticInterface
00537 {
00538 public:
00539 
00544     virtual int GetNumberOfParsers()=0;
00545 
00547 
00551     virtual IEffectParser * GetParser(ULONG parserID) =0;
00552 
00554     virtual void LoadDLLs()=0;
00555 
00557     virtual void UnloadDLLs()=0;
00558 
00560 
00564     virtual const MCHAR * GetParserFilter(int index)=0;
00565 
00567 
00571     virtual const MCHAR * GetParserExtension(int index) =0;
00572 };
00573 
00574 inline IParserLoader* GetParserLoader() { return (IParserLoader*)GetCOREInterface(PARSER_LOADER_INTERFACE); }
00575 
00577 class IRenderMesh: public MaxHeapOperators
00578 {
00579 
00580 public:
00581 
00582     enum MeshType{
00583         kMesh,
00584         kScreenQuad,
00585     };
00586 
00588     virtual ~IRenderMesh() {;}
00589 
00591     /*
00592     \returns A pointer to the IRenderMesh interface
00593     */
00594     DllExport static IRenderMesh * GetRenderMesh();
00595 
00597 
00600     virtual void SetMeshType(MeshType type)=0;
00601 
00603 
00611     virtual bool Evaluate(LPVOID Device, int width, int height, int texWidth, int texHeight)=0;
00612 
00614 
00621     virtual bool Evaluate(LPVOID Device, Mesh *aMesh, int MatIndex, bool NegScale)=0;
00622 
00624 
00627     virtual void SetMappingData(Tab <int> &map)=0;
00628 
00630 
00634     virtual bool Render(LPVOID Device)=0;
00635 
00638     virtual void Invalidate()=0;
00639 
00641 
00647     virtual bool GetVertexFormat(void ** pFormat, int * itemCount)=0;
00648 };
00649 
00650 
00652 
00655 class IRenderMeshCache: public MaxHeapOperators{
00656 
00657 public:
00659     /*
00660     \returns A pointer to the IRenderMeshCache interface
00661     */
00662     DllExport static  IRenderMeshCache *  GetRenderMeshCache();
00663 
00665 
00668     virtual void SetMeshType(IRenderMesh::MeshType type)=0;
00669 
00671 
00684     virtual int SetCachedMNMesh (MNMesh *mnMesh, INode *node, TimeValue time, bool & meshChanged)=0;
00685 
00687 
00700     virtual int SetCachedMesh (Mesh *mesh, INode *node, TimeValue time, bool & meshChanged)=0;
00701 
00703 
00706     virtual int GetCacheSize()=0;
00707 
00709 
00713     virtual IRenderMesh * GetActiveRenderMesh(int index)=0;
00714 
00719     virtual INode * GetActiveNode(int index)=0;
00720 
00725     virtual Mesh * GetActiveMesh(int index)=0;
00726 
00727     virtual void SetDirectXVersion(UINT version)=0;
00728 
00730     virtual ~IRenderMeshCache() {}
00731 
00733     virtual void Release()=0;
00734 
00736     virtual void DeleteRenderMeshCache(INode * node)=0;
00737 
00738 };
00739 
00740 
00741 
00742 #define EFFECT_FILE_INTERFACE Interface_ID(0xc3d2425, 0x637366bc)
00743 
00744 
00751 class IEffectFile : public BaseInterface
00752 {
00753 public:
00754     // Interface Lifetime
00755     virtual Interface_ID    GetID() { return EFFECT_FILE_INTERFACE; }
00756 
00758 
00762     virtual bool SaveEffectFile(MCHAR * fileName)=0;
00763 
00764 };
00765 
00768 class IValidateNodeCallback: public MaxHeapOperators
00769 {
00770 public:
00772     virtual ~IValidateNodeCallback() {;}
00773 
00779     virtual bool NodeValid(INode * node, ViewExp * vpt)=0;
00780 
00784     virtual void NodeSort(Tab <INode *> & nodeList){ UNUSED_PARAM(nodeList); };
00785 };
00786 
00790 class IDxSceneTransformManager: public MaxHeapOperators
00791 {
00792 public:
00793     enum TransformType{
00794         kWorldXform,
00795         kViewXform,
00796         kProjectionXform
00797     };
00799     virtual ~IDxSceneTransformManager() {;}
00800 
00802 
00807     virtual D3DXMATRIX GetD3DMatrix(TransformType matType)=0;
00808 
00810 
00814     virtual void SetD3DMatrix(MCHAR * paramName)=0;
00815 
00817 
00824     virtual void SetD3DMatrix(D3DXMATRIX mat, TransformType matType)=0;
00825 
00827 
00832     virtual D3DXMATRIX GetD3DMatrix(MCHAR * paramName, TransformType matType) = 0;
00833 
00834 
00835 };
00836 
00838 
00840 class IDxSceneManager: public MaxHeapOperators
00841 {
00842 public:
00844     enum DXEffectType{
00845         kPreEffect, 
00846         kPostEffect,
00847         kEnvEffect 
00848     };
00849 
00853     enum DXPassType{
00854         kStandard, 
00855         kEnvironment, 
00856         kEnvironmentLast,   
00857     };
00858 
00860     virtual ~IDxSceneManager() {;}
00861 
00867     virtual void StoreSceneEffect(Mtl * dxMtl, DXEffectType effectType = kPostEffect, int numberOfPasses=0)=0;
00868 
00873     virtual void StoreSceneEffect(Tab<Mtl*> &dxMtl)=0;
00874 
00879     virtual int GetNumberOfSceneEffects(DXEffectType effectType = kPostEffect) = 0;
00880 
00886     virtual Mtl * GetSceneEffect(int index, DXEffectType effectType = kPostEffect) = 0;
00887 
00889     virtual void ResetSceneEffects()=0;
00890 
00892 
00896     virtual void RemoveSceneEffect(int index, DXEffectType effectType = kPostEffect) =0;
00897     
00901     virtual void StartScene(GraphicsWindow *gw )=0;
00902 
00903     
00907     virtual void EndScene(GraphicsWindow *gw ) = 0;
00908 
00910 
00917     virtual LPDIRECT3DBASETEXTURE9 GetSceneRenderTarget(bool env = false, MCHAR * paramName = NULL)=0;
00918     
00920 
00924     virtual void SetSceneRenderTarget(LPDIRECT3DBASETEXTURE9 texture, MCHAR * paramName)=0;
00925 
00927 
00933     virtual void EnableDebugMode(bool onOff, MCHAR * outputPath, MCHAR * namePrefix) = 0;
00934 
00940     virtual void EnableSceneTraversal(bool state, IValidateNodeCallback * proc)=0;
00941     
00943 
00948     virtual IDxSceneTransformManager * GetTransformManager() = 0;
00949 
00953     virtual void SceneInitialize(GraphicsWindow * gw) =0;
00954 
00958     virtual int GetNumberOfPasses()=0;
00959 
00963     virtual int GetCurrentPassNumber()=0;
00964 
00969     virtual IDxSceneManager::DXPassType GetActivePassType()=0;
00970 
00972 
00976     virtual bool IsSceneEffectValid() = 0;
00977 
00978 
00979 
00981     DllExport static IDxSceneManager * GetIDxSceneManager();
00982 };
00983 
00984 struct DxGeneralFunctions{
00985     DllExport  static MCHAR * GetDXResourceFilename(MCHAR * fileName);
00986 };
00987 
00988