282 lines
11 KiB
C++
282 lines
11 KiB
C++
#ifndef ShaderManagerWrapper_H
|
|
#define ShaderManagerWrapper_H "$Id:$"
|
|
|
|
#include "CKBaseManager.h"
|
|
#include "CKShader.h" // include for CKShaderManager
|
|
|
|
#include "CKHideContentManager.h"
|
|
|
|
#include "ShaderManagerInterface.h"
|
|
#include "ShaderManagerCG.h"
|
|
#include "ShaderManager.h" //DX9
|
|
|
|
#include "RCKShaderWrapper.h"
|
|
#include "RCKShaderCG.h"
|
|
#include "RCKShader.h" //DX9
|
|
|
|
|
|
#ifdef CompileShader
|
|
#undef CompileShader
|
|
#endif
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Shader Manager Class
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
class ShaderManagerWrapper : public CKShaderManager
|
|
{
|
|
public:
|
|
ShaderManagerWrapper(CKContext *Context);
|
|
virtual ~ShaderManagerWrapper();
|
|
|
|
//--------------------------------------------------------------
|
|
// Methods to implement
|
|
//--------------------------------------------------------------
|
|
|
|
//--- Called to save manager data. return NULL if nothing to save...
|
|
virtual CKStateChunk* SaveData(CKFile* SavedFile);
|
|
|
|
//--- Called to load manager data.
|
|
virtual CKERROR LoadData(CKStateChunk *chunk,CKFile* LoadedFile);
|
|
|
|
//--- Called before the end of a CKContext::ClearAll operation.
|
|
virtual CKERROR PreClearAll();
|
|
|
|
//--- Called at the end of a CKContext::ClearAll operation.
|
|
virtual CKERROR PostClearAll();
|
|
|
|
//--- Called at deletion of a CKContext
|
|
virtual CKERROR OnCKEnd();
|
|
|
|
//--- Called at Play
|
|
virtual CKERROR OnCKPlay();
|
|
|
|
//--- Called at the end of the creation of a CKContext.
|
|
virtual CKERROR OnCKInit();
|
|
|
|
//--- Called at the end of a load operation.
|
|
virtual CKERROR PostLoad() { return CK_OK; }
|
|
|
|
//--- Called at the end of a save operation.
|
|
virtual CKERROR PostSave() { return CK_OK; }
|
|
|
|
virtual CKERROR OnRasterizerEvent(CKRST_EVENTS Event,CKRenderContext* dev);
|
|
|
|
//--- Returns list of functions implemented by the manager.
|
|
virtual CKDWORD GetValidFunctionsMask() {
|
|
return CKShaderManager::GetValidFunctionsMask() |
|
|
CKMANAGER_FUNC_PreClearAll|
|
|
CKMANAGER_FUNC_PostClearAll|
|
|
CKMANAGER_FUNC_OnCKEnd|
|
|
CKMANAGER_FUNC_OnCKPlay|
|
|
CKMANAGER_FUNC_OnCKInit|
|
|
CKMANAGER_FUNC_PostLoad|
|
|
CKMANAGER_FUNC_PostSave|
|
|
CKMANAGER_FUNC_OnRasterizerEvent;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Unused methods
|
|
//--------------------------------------------------------------
|
|
// virtual CKERROR SequenceAddedToScene(CKScene *scn,CK_ID *objids,int count) { return CK_OK; }
|
|
// virtual CKERROR SequenceRemovedFromScene(CKScene *scn,CK_ID *objids,int count){ return CK_OK; }
|
|
// virtual CKERROR OnPostBackToFront(CKRenderContext* dev) { return CK_OK; }
|
|
// virtual CKERROR OnPreBackToFront(CKRenderContext* dev) { return CK_OK; }
|
|
// virtual CKERROR PreClearAll() { return CK_OK; }
|
|
// virtual CKERROR OnPostCopy(CKDependenciesContext& context) { return CK_OK; }
|
|
// virtual CKERROR OnPreCopy(CKDependenciesContext& context) { return CK_OK; }
|
|
// virtual CKERROR SequenceDeleted(CK_ID *objids,int count) { return CK_OK; }
|
|
// virtual CKERROR SequenceToBeDeleted(CK_ID *objids,int count) { return CK_OK; }
|
|
// virtual CKERROR OnPostFullScreen(BOOL Going2Fullscreen,CKRenderContext* dev) { return CK_OK; }
|
|
// virtual CKERROR OnPreFullScreen(BOOL Going2Fullscreen, CKRenderContext* dev) { return CK_OK; }
|
|
// virtual CKERROR PreLoad() { return CK_OK; }
|
|
// virtual CKERROR PostLaunchScene(CKScene* OldScene,CKScene* NewScene) { return CK_OK; }
|
|
// virtual CKERROR PreLaunchScene(CKScene* OldScene,CKScene* NewScene) { return CK_OK; }
|
|
// virtual CKERROR OnCKPause() { return CK_OK; }
|
|
// virtual CKERROR OnCKPlay() { return CK_OK; }
|
|
// virtual CKERROR PostProcess() { return CK_OK; }
|
|
// virtual CKERROR PreProcess() { return CK_OK; }
|
|
// virtual CKERROR OnPostRender(CKRenderContext* dev) { return CK_OK; }
|
|
// virtual CKERROR OnPreRender(CKRenderContext* dev) { return CK_OK; }
|
|
// virtual CKERROR OnCKPostReset() { return CK_OK; }
|
|
// virtual CKERROR OnCKReset() { return CK_OK; }
|
|
// virtual CKERROR PreSave() { return CK_OK; }
|
|
// virtual CKERROR OnPostSpriteRender(CKRenderContext* dev) { return CK_OK; }
|
|
|
|
protected:
|
|
virtual void OnCreateDevice(CKRenderContext* rc);
|
|
virtual void OnDestroyDevice(CKRenderContext* rc);
|
|
virtual void OnLostDevice(CKRenderContext* rc);
|
|
virtual void OnResetDevice(CKRenderContext* rc);
|
|
|
|
//-----------------------------------------------------------------------//
|
|
// Specific accessors to get wanted ShaderManager
|
|
//-----------------------------------------------------------------------//
|
|
public:
|
|
virtual CK_SHADER_MANAGER_TYPE GetCurrentShaderManagerType() const {return m_CurrentShaderManager->m_Type;}
|
|
|
|
ShaderManagerInterface* GetCurrentShaderManager() const { return m_CurrentShaderManager; }
|
|
|
|
ShaderManagerInterface* GetShaderManagerByType(CK_SHADER_MANAGER_TYPE type) const {
|
|
ShaderManagerInterface** begin = m_ShaderManagerArray.Begin();
|
|
ShaderManagerInterface** end = m_ShaderManagerArray.End();
|
|
while ((*begin)->m_Type != type) {
|
|
++begin;
|
|
if (begin == end) return NULL;
|
|
}
|
|
return *begin;
|
|
}
|
|
|
|
protected:
|
|
CKBOOL m_PreCleared;
|
|
ShaderManagerInterface* m_CurrentShaderManager;
|
|
XArray<ShaderManagerInterface*> m_ShaderManagerArray;
|
|
//-----------------------------------------------------------------------//
|
|
// Support
|
|
//-----------------------------------------------------------------------//
|
|
public:
|
|
virtual CKBOOL IsSupported() const;
|
|
virtual CKBOOL IsSupportedAndWarnIfNot();
|
|
virtual void GetVSPSVersion(float& vs, float& ps) const;
|
|
virtual CKBOOL IsPreCleared() const;
|
|
|
|
//-----------------------------------------------------------------------//
|
|
// Shader Compilation & Automatics variables
|
|
//-----------------------------------------------------------------------//
|
|
public:
|
|
virtual CKShader* CreateShader(
|
|
const XString* name = NULL,
|
|
const XString* text = NULL,
|
|
BOOL uniqueName = TRUE );
|
|
|
|
virtual void DeleteShader(CKShader* fx);
|
|
virtual CKShader* CreateShaderFromFile(const CKSTRING filename);
|
|
virtual CKShader* CreateShaderFromFiles(const CKSTRING HLSLfilename, const CKSTRING CgFXfilename = NULL);
|
|
virtual bool SaveShaderToFile(const XString& filename, CKShader* fx);
|
|
|
|
virtual bool CompileShader(CKShader* fx, XClassArray<XString> &output);
|
|
virtual bool CompileShaderOutput(CKShader* fx, const CKSTRING funcname,
|
|
const CKSTRING target, XClassArray<XString> &output, XArray<char>& text);
|
|
|
|
virtual CKShader* GetShaderByName(const XBaseString& name);
|
|
virtual int GetNumShaders() const;
|
|
virtual CKShader* GetShader(int pos);
|
|
|
|
virtual void BeginShaders( CKRenderContext* rc );
|
|
virtual void EndShaders( CKRenderContext* rc );
|
|
|
|
|
|
const XClassArray<XString>& GetSemanticOriginalNames();
|
|
virtual void GetSemanticDesc( int iSemIndex, XString*& oSemDesc );
|
|
|
|
virtual int GetTangentSpaceCreationMode() const { return m_TangentSpaceCreationMode; };
|
|
virtual void SetTangentSpaceCreationMode( ShaderTSCreationMode iTSCreationMode ) { m_TangentSpaceCreationMode = iTSCreationMode; };
|
|
|
|
int m_NextCompID;
|
|
|
|
protected:
|
|
enum {
|
|
ShaderReplacementMode_RenameNew = 0,
|
|
ShaderReplacementMode_ReplaceOldByNew,
|
|
ShaderReplacementMode_KeepOldAndDontUseNew
|
|
};
|
|
int m_ReplacementMode;
|
|
|
|
enum {
|
|
ShaderNMOSavingMode_SaveAllShaders = 0,
|
|
ShaderNMOSavingMode_SaveOnlyUsedShaders,
|
|
ShaderNMOSavingMode_DontSaveAnyShader
|
|
};
|
|
int m_NMOSavingMode;
|
|
|
|
int m_TangentSpaceCreationMode;
|
|
|
|
//public:
|
|
// ShaderDescriptor::Manager& GetDescriptorManager(){ return m_ShaderDescriptorManager; }
|
|
|
|
protected:
|
|
BOOL _ReadStringFromFile(const XString& filename, XString &s) const;
|
|
BOOL _WriteStringToFile(const XString& filename, const XString &s) const;
|
|
|
|
// BOOL _GetShaderTextForType(const XString& iShaderTxt, XString& oShaderTxt, CK_SHADER_MANAGER_TYPE iSMtype) const;
|
|
// BOOL _SetShaderTextForType(const XString& iShaderTxt, XString& ioShaderTxt, CK_SHADER_MANAGER_TYPE iSMtype) const;
|
|
|
|
//-----------------------------------------------------------------------//
|
|
// Default Shader
|
|
//-----------------------------------------------------------------------//
|
|
public:
|
|
virtual CKShader* GetDefaultShader();
|
|
virtual CKShader* GetDefaultShaderI();
|
|
virtual CKShader* GetShadowShader();
|
|
|
|
|
|
//-----------------------------------------------------------------------//
|
|
// Exposed Parameters Management
|
|
//
|
|
// m_hashParamIndex: a hash table for retrieving the index of store CKParams
|
|
// m_paramLinker: array of ExposedLoclalParamsPerRC indexed per RC index.
|
|
// D3DHandleArray:
|
|
//-----------------------------------------------------------------------//
|
|
public:
|
|
// XArray<CKRenderContext*> m_rcList;
|
|
// XHashTable<int, CKParameterLocal*> m_hashParamIndex;
|
|
// XClassArray<ExposedParamMeaningArray> m_paramMeaningLinker;
|
|
public:
|
|
// void _AddRCForExposedParameters();
|
|
// void _RemoveRCForExposedParameters( int rcIndex );
|
|
|
|
// void _UnregisterExposedParameter( CKParameterLocal* p );
|
|
|
|
// D3DXHANDLE _GetRegisteredParamD3DHandle( CKParameterLocal* p, int rcIndex ); // to remove
|
|
|
|
//--- Meaning related
|
|
// void _RegisterExposedParameterMeaning( CKParameterLocal* p, ShaderDescriptor::ExposedParamMeaning* paramMeaning, int rcIndex );
|
|
|
|
// ShaderDescriptor::ExposedParamMeaning* _GetRegisteredParamMeaning( CKParameterLocal* p, int rcIndex );
|
|
|
|
/****************************************************************
|
|
Summary: Gets the render context index.
|
|
Arguments:
|
|
iRc: the render context
|
|
Return Value:
|
|
The render context index or -1 if not found.
|
|
Remarks:
|
|
Gets the render context index among the whole list of render
|
|
context.
|
|
See Also:
|
|
*******************************************************************/
|
|
// int _GetRenderContextIndex( CKRenderContext* rc );
|
|
|
|
/*******************************************************************
|
|
Summary: Called when a RenderContext gets created or destroyed
|
|
to update the Shader Manager's inner list of render contexts
|
|
*******************************************************************/
|
|
virtual void OnRenderContextCreated( CKRenderContext* rc );
|
|
virtual void OnRenderContextDestroyed( CKRenderContext* rc );
|
|
|
|
|
|
/*******************************************************************
|
|
Summary: Retrieve Registered Semantic/Annotation Infos
|
|
*******************************************************************/
|
|
virtual int GetSemanticIndexFromString( XString& iStr );
|
|
|
|
const XClassArray<XString>& GetAnnotationOriginalNames();
|
|
|
|
// virtual const XClassArray<XString>& GetSemanticOriginalNames();
|
|
// virtual void GetSemanticDesc( int iSemIndex, XString*& oSemDesc ) = 0;
|
|
/*********************************************************
|
|
Summary: Retrieves the Include Manager
|
|
***********************************************************/
|
|
virtual void* GetIncludeManager() { return 0; }
|
|
|
|
private:
|
|
// Add a new wrapped shader, from the 'buildFun' method that will be invoked on all sub manager
|
|
CKShader* NewBuiltInShader(const char *name, CKShader *(ShaderManagerInterface::*buildFun) ());
|
|
|
|
};
|
|
|
|
#endif
|
|
|