Files
deargui-vpl/ref/virtools/Samples/Behaviors/Shader/Sources/ShaderDescriptorCG.h
T

894 lines
35 KiB
C++

/**************************************************************************
/* File: ShaderDescriptorCG.h
/* Author: Guillaume Caurant
/*
/* Virtools SDK
/* Copyright (c) Virtools 2004, All Rights Reserved.
/**************************************************************************/
#ifndef ShaderDescriptorCG_H
#define ShaderDescriptorCG_H "$Id:$"
#if (defined(macintosh) && defined (VIRTOOLS_PLAYER))
#define CG_EXPLICIT
#define CGGL_EXPLICIT
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include "CgFunctions.h"
#else
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#endif
#include "XHashTable.h"
#include "RCKShaderCG.h"
class CachedRenderStateBase;
namespace ShaderDescriptorCG {
using namespace ShaderDescriptor_Base;
class ManagerCG;
class ShaderCG;
//--- Class Enum (refer to D3DXPT enum)
enum {
ParamClassCount = CG_PARAMETERCLASS_OBJECT+1 //D3DXPC_STRUCT+1
};
//--- Type Enum (refer to D3DXPT enum)
enum {
ParamTypeCount = 19 //D3DXPT_VERTEXFRAGMENT+1
};
//--- Structure passed to the Meaning Processing Callback
struct MeaningProcessingInfo {
MeaningProcessingInfo();
MeaningProcessingInfo(CK3dEntity* iEnt,
CKMaterial* iMat,
CGeffect iFx,
CKRenderContext* iRC,
CKMaterialShader* iMatShader,
ShaderCG* iShader,
CKParameter* iParam,
int iTechIndex,
bool iIsPerPassMeanings,
RCKShaderCG::TechniqueStateCache *iTechStateCache
) :
ent(iEnt),
mat(iMat),
fx(iFx),
rc(iRC),
matShader(iMatShader),
shader(iShader),
param(iParam),
techniqueIndex(iTechIndex),
isPerPassMeanings(iIsPerPassMeanings),
techStateCache(iTechStateCache)
{
}
CK3dEntity* ent;
CKMaterial* mat;
CGeffect fx;
CKRenderContext* rc;
CKMaterialShader* matShader; // NB : shaderMat may not be that of 'mat' if mat is a standard material overriden by a shader
// This allow to have access to standard material values such as alpha test settings in a shader
ShaderCG* shader;
CKParameter* param;
int techniqueIndex;
bool isPerPassMeanings;
RCKShaderCG::TechniqueStateCache *techStateCache;
};
//--- Structure passed to the Meaning Instantiator
struct MeaningInstantiatorInfo {
MeaningInstantiatorInfo();
// MeaningInstantiatorInfo( CGeffect iFx, D3DXHANDLE iHandle, ManagerCG* iSDM, ShaderCG* iShader ) :
// fx(iFx), h(iHandle), sdm(iSDM), semIndex(Sem_Unknown), shader(iShader), paramIndex(0) {
// };
MeaningInstantiatorInfo( CGeffect iFx, ManagerCG* iSDM, ShaderCG* iShader ) :
fx(iFx), sdm(iSDM), semIndex(Sem_Unknown), shader(iShader), paramIndex(0) {
};
// MeaningInstantiatorInfo( CGeffect iFx, D3DXHANDLE iHandle, ManagerCG* iSDM, ShaderCG* iShader,
// const D3DXPARAMETER_DESC& iParamDesc )
// {
// MeaningInstantiatorInfo( iFx, iHandle, iSDM, iShader );
// paramDesc = iParamDesc;
// }
MeaningInstantiatorInfo( CGeffect iFx,ManagerCG* iSDM, ShaderCG* iShader,
const CGparameter iParamDesc )
{
MeaningInstantiatorInfo( iFx, iSDM, iShader );
paramDesc = iParamDesc;
}
CGeffect fx;
void* h;
ManagerCG* sdm;
ShaderCG* shader;
int techniqueCount;
union {
int paramIndex;
int functionIndex;
int techIndex;
};
union {
CGparameter paramDesc;
void* functionDesc;
CGtechnique techDesc;
CGpass passDesc;
};
union {
int semIndex;
};
};
/***************************************************************************
__ __ _
| \/ | ___ __ _ _ __ (_)_ __ __ _
| |\/| |/ _ \/ _` | '_ \| | '_ \ / _` |
| | | | __/ (_| | | | | | | | | (_| |
|_| |_|\___|\__,_|_| |_|_|_| |_|\__, |
|___/
***************************************************************************/
class Meaning {
public:
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI ) = 0;
//D3DXHANDLE m_D3DHandle;
void* m_D3DHandle;
union {
CGparameter m_ParamDesc;
void* m_FunctionDesc;
CGtechnique m_TechDesc;
CGpass m_PassDesc;
};
};
/***************************************************************************
____
| _ \ __ _ _ __ __ _ _ __ ___
| |_) / _` | '__/ _` | '_ ` _ \
| __/ (_| | | | (_| | | | | | |
|_|__ \__,_|_| \__,_|_| |_| |_|
**************************************************************************/
//--------------------------------------------------------------------------------
// Standard Param (To Derived)
//--------------------------------------------------------------------------------
class ParamMeaning : public Meaning {
public:
ParamMeaning() : m_BeginShadersCount(0), m_NumRows(1), m_NumCols(1), m_ArrayElementCount(1) {}
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI ){};
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMPI );
// Returns true if this meaning is a sampler meaning
virtual bool IsSampler() const { return false; }
// If this meaning is a sampler, returns true if this sampler has variable texture stage binding
// for the various passes of a shader (for that reason it will always return false for a single pass shader)
virtual bool IsPassDependantSampler(int techniqueIndex) const { return false; }
//
//--- Convenient Function
void SetValueByCastingVectorParam( const MeaningProcessingInfo& iMPI, int iInputSize, const void* value );
void SetValueByMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix );
void SetValueByTranposingMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix );
void SetValueByInversingMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix );
void SetValueByInversingMatrix44( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix );
void SetValueByInverseTransposingMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix );
void SetValueByInverseTransposingMatrix44( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix );
void SetValueFromCKTexture( const MeaningProcessingInfo& iMPI, CKTexture* iTex );
int m_ExpositionType;
#ifdef _DEBUG
XString m_ParameterName;
#endif
// Caching of vector value (per technique)
XArray<VxVector4> m_ValueCache;
DWORD m_BeginShadersCount;
// Dimension for matrix params
int m_NumRows;
int m_NumCols;
// Number of elements in an array (1 for a scalar)
int m_ArrayElementCount;
// constant binding of an effect param into each program domain
class ConstantSetupInfo
{
public:
// constant setup for each domain (vertex, fragment geometry)
int m_ConstantIndex[NUMBER_OF_CG_DOMAIN]; // index of the constant to set (-1 if none for that domain)
int m_RowCount[NUMBER_OF_CG_DOMAIN];
// CG may not allocate a constant for each array ('array' referring to a CG array) entry if some are not used by a shader program.
// The following vector give the mapping to actual constants index (-1 for unused entries)
XArray<int> m_ArrayCellToProgramConstant[NUMBER_OF_CG_DOMAIN];
};
typedef XClassArray<ConstantSetupInfo> PerPassConstantSetup;
class TechniqueConstantSetupInfo
{
public:
// Dependent render states for this technique
XArray<CachedRenderStateBase *> m_DependentRenderStates;
PerPassConstantSetup m_PerPassConstantSetup; // program constants to set for each pass
//
bool m_HasDependentSamplerStates;
bool m_ForceUseCGSetParameter; // When true, use the cgSetParameterxxx function instead of using our wrapper
// This can be necessary in the following situations :
// - There are some profiles we don't know in current technique -> will be true for all parameters in technique
// - The parameter has dependent states *and* set a constant (should be very rare) -> we are forced to call cgSetParameter ..
// -> there may be conflict with our wrapping function (well, actually, only for profiles with no local constant because they are set at the end ...)
// - There are dependent state only (no constant is set ...)
TechniqueConstantSetupInfo() : m_HasDependentSamplerStates(false), m_ForceUseCGSetParameter(false) {}
};
// gives constant setup info for each technique, for each pass
XClassArray<TechniqueConstantSetupInfo> m_PerTechniquePerPassConstantSetup;
// helper : set current parameter matrix, possibly cropping it to match the matrix declared in cg
// Dependant render states are marked as 'modified'
//void SetCroppedMatrix(const MeaningProcessingInfo& iMPI, const VxMatrix &srcMatrix);
// Mark all the dependent render states as modified
void TouchDependentRenderStates(const MeaningProcessingInfo& iMPI);
/** Init the constant info of this parameter for the given technique / pass, by doing lookup into the
* CG program comments (to retrieve that info).
* cstSetupSupportedPerDomain contains true for each domain for which we have constant setup code
*/
virtual void InitConstantSetupInfo(int techniqueIndex,
int passIndex,
const char *programString[NUMBER_OF_CG_DOMAIN],
ShaderConstantStore *cstStore[NUMBER_OF_CG_DOMAIN]
);
/** Bindings into cg 'setParameters' functions
* If we were able to retrieve a parameter constants into cg program, we try to set them ourseleves
* in a fastest way, else we rely on cg code (may happen if there are some dependent state that
* need our parameter)
* All these wrapper funtion will take care of cropping the source dimensions when it is necessary
*/
void WrapCGSetParameter1i(const MeaningProcessingInfo& iMPI, int value);
void WrapCGSetParameter1f(const MeaningProcessingInfo& iMPI, float value);
void WrapCGSetParameter2fv(const MeaningProcessingInfo& iMPI, const float *value);
void WrapCGSetParameter3fv(const MeaningProcessingInfo& iMPI, const float *value);
void WrapCGSetParameter4fv(const MeaningProcessingInfo& iMPI, const float *value);
//
void WrapCGSetParameterArray1f(const MeaningProcessingInfo& iMPI, const float *values, int elemCount);
void WrapCGSetParameterArray2f(const MeaningProcessingInfo& iMPI, const float *values, int elemCount);
void WrapCGSetParameterArray3f(const MeaningProcessingInfo& iMPI, const float *values, int elemCount);
void WrapCGSetParameterArray4f(const MeaningProcessingInfo& iMPI, const float *values, int elemCount);
//
void WrapCGSetMatrixParameter(const MeaningProcessingInfo& iMPI, const VxMatrix &value);
void WrapCGSetMatrixParameterArray(const MeaningProcessingInfo& iMPI, const VxMatrix *values, int matrixCount, bool transpose);
//
void WrapCGSetStateMatrixParameter(const MeaningProcessingInfo& iMPI, CGGLenum matrix, CGGLenum transform);
/** Get max constant index for the given program type in a pass technique, or -1 if no constant is bound for
* NB : max constant index includes the number of row
*/
int GetMaxCstIndex(int techIndex, int passIndex, CGdomain domain) const;
// See if this parameter has dependent render or sample states for the given technique
bool HasDependentStates(int techIndex) const;
// See if this parameter has dependent constants (e.g set a constant in some program) for the current technique
bool HasDependentProgramConstants(int techIndex) const;
// Force all parameters to use the cgSetParameterFunctionxxx for the given technique (instead
// of relying on a constant store)
void DisableProgramConstantsWrapping(int techIndex);
private:
// Set a constant value in all program that requires it inside 'pass'
// The actual constant setup will occur when ShaderConstantObject::Flush is done
// 'private' because terminal call of the WrapCG functions above)
void SetConstants(const ConstantSetupInfo &cstSetupInf, RCKShaderCG::PassStateCache &pass, const float *srcFloats, int rowCount, int colCount, int elemCount);
// Set a constant value in all passes that requires into current selected technique of current effect.
// The actual constant setup will occur when ShaderConstantObject::Flush is done
// 'private' because terminal call of the WrapCG functions above)
void SetConstants(const MeaningProcessingInfo& iMPI, const float *srcFloats, int rowCount, int colCount, int elemCount);
// Result of CG declaration parsing
enum EConstantParseResult
{
ConstantParseResult_NotFound = 0,
ConstantParseResult_Used,
ConstantParseResult_NotUsed,
ConstantParseResult_Unknown,
ConstantParseResult_Count = ConstantParseResult_Unknown
};
// Parse a constant declaration in CG compiled code for the current line (except for fp30 profile which has
// a specific format)
// returns the next line or NULL if finished
// For arrays, arrayElementIndex should be the index to parse (should be called in order else ConstantParseResult_NotFound will be returned),
// or shoumld be 0 if the parameter is not an array
const char *ParseCGConstantDeclarationLine(const char *currPos,
int arrayElementIndex,
EConstantParseResult &constantParseResult,
int &firstConstantIndex,
int &matrixRowCount);
};
//--------------------------------------------------------------------------------
// NearestLight (Switcher to derive from)
//--------------------------------------------------------------------------------
class ParamMeaning_NearestLight : public ParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
//--- Methods One Have To Override
virtual int GiveStride( const MeaningProcessingInfo& iMPI ) = 0;
virtual void GiveDefaultValues( const MeaningProcessingInfo& iMPI,
void* iTempBuffer, int iFinalArrayCount ) = 0;
virtual void GiveValue( const MeaningProcessingInfo& iMPI,
CKLight& iLight, void* iValueBuf ) = 0;
//--- Methods To Overide If Needed
virtual void AssignValues( const MeaningProcessingInfo& iMPI,
void* iValueBuf, const int iElemCount );
int m_NearestIndex;
int m_WantedLightArraySize;
bool m_Sort;
// caching of last values
XArray<BYTE> m_CachedValues;
protected:
//--- Convenient Function
XArray< CKShaderManager::NearestLight >*
_GetLightsArrayRange( const MeaningProcessingInfo& iMII,
int& oMinLightIndex,
int& oMaxLightIndex,
bool iSort = true );
};
//--------------------------------------------------------------------------------
// Exposed Standard Params (To Derived)
//--------------------------------------------------------------------------------
class ExposedParamMeaning : public ParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual ~ExposedParamMeaning();
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMPI );
virtual void CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI );
CKGUID m_Guid;
};
//--------------------------------------------------------------------------------
// Exposed Float Params
//--------------------------------------------------------------------------------
class ExposedFloatParamMeaning : public ExposedParamMeaning {
public:
ExposedFloatParamMeaning() {}
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
virtual void CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI );
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII );
XArray<float> m_ValueCache;
};
//--------------------------------------------------------------------------------
// Exposed Dword Params
//--------------------------------------------------------------------------------
class ExposedDwordParamMeaning : public ExposedParamMeaning {
public:
ExposedDwordParamMeaning() {}
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
virtual void CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI );
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII );
XArray<int> m_ValueCache;
};
//--------------------------------------------------------------------------------
// Exposed Vectorizable Param
//--------------------------------------------------------------------------------
class ExposedVectorizableParamMeaning : public ExposedParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
};
//--------------------------------------------------------------------------------
// Exposed 2DVector Param
//--------------------------------------------------------------------------------
class Exposed2DVectorParamMeaning : public ExposedParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
};
//--------------------------------------------------------------------------------
// Exposed XDVector Param
//--------------------------------------------------------------------------------
class ExposedXDVectorParamMeaning : public ExposedParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
};
//--------------------------------------------------------------------------------
// Exposed Array Params
//--------------------------------------------------------------------------------
class ExposedArrayParamMeaning : public ExposedParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
CKGUID m_Guid2;
};
//--------------------------------------------------------------------------------
// Exposed Matrix Params
//--------------------------------------------------------------------------------
class ExposedMatrixParamMeaning : public ExposedParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
};
//--------------------------------------------------------------------------------
// Exposed Texture Params
//--------------------------------------------------------------------------------
class ExposedTextureParamMeaning : public ExposedParamMeaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
GLuint* m_TexIdPtr;
};
/***************************************************************************
____
| _ \ __ _ ___ ___
| |_) / _` / __/ __|
| __/ (_| \__ \__ \
|_| \__,_|___/___/
***************************************************************************/
class PassMeaning : public Meaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII );
XString m_DescStr;
};
/***************************************************************************
_____ _
|_ _|__ ___| |__
| |/ _ \/ __| '_ \
| | __/ (__| | | |
|_|\___|\___|_| |_|
**************************************************************************/
class TechMeaning : public Meaning {
public:
TechMeaning();
virtual ~TechMeaning();
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII );
inline int GetPassIndexByName( const char* iPassName )
{
int* passMeaningPtr = m_PassIndexFromName.FindPtr( iPassName );
return passMeaningPtr? *passMeaningPtr:-1;
}
bool m_Validated;
XString m_DescStr;
XArray<PassMeaning*> m_Passes;
XHashTable<int, XString> m_PassIndexFromName;
enum EMeshOps {
MeshOp_None = 0,
MeshOp_BuildTangentSpace = 1,
MeshOp_RemoveTangentSpace = 2,
MeshOp_SetUseColorAndNormal = 4,
MeshOp_RemoveUseColorAndNormal = 8
};
int m_MeshOps;
};
/***************************************************************************
_____ _
| ___|__| |_
| |_ / __| __|
| _| (__| |_
|_| \___|\__|
**************************************************************************/
class FctMeaning : public Meaning {
public:
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII );
virtual void ProcessCallBack( const MeaningProcessingInfo& iMPI );
virtual void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII );
};
/***************************************************************************
____ _ _
/ ___|| |__ __ _ __| | ___ _ __
\___ \| '_ \ / _` |/ _` |/ _ \ '__|
___) | | | | (_| | (_| | __/ |
|____/|_| |_|\__,_|\__,_|\___|_|
***************************************************************************/
typedef struct samplerRef {
GLuint** TexIdPtrPtr;
XString TexName;
}samplerRef;
typedef struct textureRef {
GLuint TexId;
GLuint** TexIdPtrPtr;
}textureRef;
typedef Meaning* (*MeaningInstantiatorPtr) ( const MeaningInstantiatorInfo& iMII );
class ShaderCG {
public:
friend class ManagerCG;
friend class TechMeaning;
ShaderCG();
~ShaderCG();
void Init( ManagerCG* iShaderManager, CGeffect iDxFX, CKRenderContext* iRC, CKShader* iShader );
void ExecuteMeanings( MeaningProcessingInfo& iMPI );
void ExecutePerPassMeanings( MeaningProcessingInfo& iMPI );
inline ManagerCG* GetManager(){ return m_SDM; }
inline CKShader* GetCKShader(){ return m_Shader; }
inline CKRenderContext* GetRenderContext(){ return m_RC; }
inline ExposedParamMeaning* GetParamMeaningByName( const XString& iName )
{
ExposedParamMeaning** paramMeaningPtr = m_ParamMeaningFromName.FindPtr( iName );
return paramMeaningPtr? *paramMeaningPtr:NULL;
}
inline TechMeaning* GetTechMeaningByName( const XString& iName )
{
int techIndex = GetTechIndexByName( iName );
if( techIndex == -1 ) return NULL;
return m_Techs[ techIndex ];
}
inline int GetTechIndexByName( const XString& iName )
{
int* techMeaningPtr = m_TechIndexFromName.FindPtr( iName );
return techMeaningPtr? *techMeaningPtr:-1;
}
inline FctMeaning* GetFctMeaningByName( const char* iName )
{
FctMeaning** fctMeaningPtr = m_FctMeaningFromName.FindPtr( iName );
return fctMeaningPtr? *fctMeaningPtr:NULL;
}
inline XArray<ParamMeaning*>& GetParamMeanings(){ return m_Params; }
inline XArray<ParamMeaning*>& GetPerPassParamMeanings(){ return m_Params; }
inline XArray<ExposedParamMeaning*>& GetExposedParamMeanings(){ return m_ExposedParams; }
inline XArray<TechMeaning*>& GetTechMeanings(){ return m_Techs; }
inline XArray<FctMeaning*>& GetFunctMeanings(){ return m_Functs; }
static Meaning* InstantiateMeaning( MeaningInstantiatorPtr iMiptr, const MeaningInstantiatorInfo& iMPI );
static Meaning* InstantiateMeaningWithPost( MeaningInstantiatorPtr iMiptr, const MeaningInstantiatorInfo& iMPI );
XClassArray<samplerRef> m_Samplers;
XHashTable<textureRef, const char*> m_Textures;
// Map each cg effect parameter to the matching param meaning after it has been built
typedef XHashTable<class ParamMeaning *, CGparameter> CGParamToMeaningMap;
CGParamToMeaningMap m_CGParamToMeaning;
/** Precompute 'effect parameters' to 'program constants/uniforms' mapping for a given pass/technique.
* Program string must be given for each domain (vertex, fragment, geometry),
* So that we can retrieve the constant/uniform indices by parsing those string
* (Added as a commentary by the CG compiler)
* cstSetupSupportedPerDomain contains true for each domain for which we have constant setup code
*/
void InitConstantSetupInfo(int techniqueIndex, int passIndex, const char *programString[NUMBER_OF_CG_DOMAIN], ShaderConstantStore *cstStore[NUMBER_OF_CG_DOMAIN]);
/** Compute the max constant index for a given technique / pass and program domain
* (Example : will return 4 for a simple transform vertex shader 'CG_DOMAIN_VERTEX' that uses c[0] ... c[3])
* Return -1 if no constant was found
*/
int ComputeMaxParamMeaningCstIndex(int techIndex, int passIndex, CGdomain domain);
// Force all parameters to use the cgSetParameterFunctionxxx for the given technique (instead
// of relying on a constant store)
void DisableProgramConstantsWrapping(int techIndex);
protected:
void BuildDescription();
void DestroyDescription();
TechMeaning* BuildTechMeaning( MeaningInstantiatorInfo& ioMII );
ParamMeaning* BuildParamMeaning( MeaningInstantiatorInfo& ioMII );
FctMeaning* BuildFctMeaning( MeaningInstantiatorInfo& ioMII );
PassMeaning* BuildPassMeaning( MeaningInstantiatorInfo& ioMII );
typedef XArray<ParamMeaning*> perPassSamplers; // List of samplers that are 'per-pass' for a given technique
// (opposed to samplers that are 'per technique').
// Samplers that are per pass may be bound to a different texture stage
// for different passes and/or may be used only by a subset of the technique passes.
// For this reason they need to be setup 'per-pass', because we don't want cgSetPassState
// to handle texture setup (that is we did a cgGLSetManageTextureParameters(context, CG_FALSE));
// Please note that these pointer are only references to the actual meaning
// (delete is called only on m_Params or m_ParamsPerPass)
XClassArray<perPassSamplers> m_PerTechniquePerPassSamplers; // For each technique, the list of sampler meanings that should be
// set on a 'per-pass' basis
XArray<ParamMeaning*> m_Params;
XArray<ParamMeaning*> m_ParamsPerPass;
XArray<ExposedParamMeaning*> m_ExposedParams;
XArray<TechMeaning*> m_Techs;
XArray<FctMeaning*> m_Functs;
XHashTable<ExposedParamMeaning*, XString> m_ParamMeaningFromName;
XHashTable<int, XString> m_TechIndexFromName;
XHashTable<FctMeaning*, XString> m_FctMeaningFromName;
protected:
CGeffect m_FX;
ManagerCG* m_SDM;
CKRenderContext* m_RC;
CKShader* m_Shader;
private:
// Debug : fill array with 'true' for shader constants used by a param, assert if an overlap is detected
static void DetectShaderConstantOverlap(ParamMeaning &param, int techniqueIndex, int passIndex, int domain, XArray<bool> &usedCst);
// Debug : check that there are no shader constant overlap for the given technique & pass
void CheckConstantSetupInfoValid(int techniqueIndex, int passIndex);
};
/***************************************************************************
__ __
| \/ | __ _ _ __ __ _ __ _ ___ _ __
| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
| | | | (_| | | | | (_| | (_| | __/ |
|_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
|___/
***************************************************************************/
class ManagerCG {
public:
friend class ShaderCG;
ManagerCG();
void Init( CKContext* iContext );
inline CKContext* GetCKContext(){ return m_Context; }
inline CKShaderManager* GetShaderManager(){ return m_ShaderManager; }
virtual int GetSemanticIndexFromString( XString& iStr );
void GetSemanticDesc( int iSemanticEnum, XString*& oSemDesc );
const XClassArray<XString>& GetAnnotationOriginalNames();
int GetAnnotationIndexFromString( XString& iStr );
int GetAnnotStrValueIndexFromString( XString& iStr );
void ExpectingAnnotation( int iAnnotationEnum, int iAnnotationType, void* iValuePtr, bool* iAnnotIsUsedPtr = NULL );
void ParseExpectedAnnotations( CGeffect iFx, CGannotation iFirstAnnotation );
const XClassArray<XString>& GetSemanticOriginalNames();
protected:
void RegisterSemanticName( int iSemanticEnum, const char* iName, const char* iDesc = NULL );
void RegisterSemanticDesc( int iSemanticEnum, const char* iDesc );
void RegisterAnnotationName( int iAnnotationEnum , const char* iName );
void RegisterAnnotationStringValues( int iAnnotStrEnum , const char* iValue );
void RegisterParamMeaningForSemantic( int iSemEnum, MeaningInstantiatorPtr iFctPtr );
void RegisterParamMeaningForClassAndType( int iClass, int iType, MeaningInstantiatorPtr iFctPtr );
void RegisterFctMeaning( MeaningInstantiatorPtr iFctPtr );
void RegisterTechMeaning( MeaningInstantiatorPtr iFctPtr );
void RegisterPassMeaning( MeaningInstantiatorPtr iFctPtr );
protected:
struct AnnotationExpected {
AnnotationExpected()
: annotEnum( Annot_Unknown ), annotType( AnnotType_Unknown ),
valuePtr( NULL ), annotIsUsedPtr( NULL ) {}
AnnotationExpected( int iAnnotationEnum, int iAnnotationType, void* iValuePtr )
: annotEnum( iAnnotationEnum ), annotType( iAnnotationType ),
valuePtr( iValuePtr ), annotIsUsedPtr( NULL ) {}
AnnotationExpected( int iAnnotationEnum, int iAnnotationType, void* iValuePtr, bool* iAnnotIsUsedPtr )
: annotEnum( iAnnotationEnum ), annotType( iAnnotationType ),
valuePtr( iValuePtr ), annotIsUsedPtr( iAnnotIsUsedPtr ) {}
int annotEnum;
int annotType;
void* valuePtr;
bool* annotIsUsedPtr;
};
XArray<AnnotationExpected> m_AnnotationsExpected;
CKBOOL m_EverythinghasAlreadyBeenRegistered;
CKContext* m_Context;
CKShaderManager* m_ShaderManager;
XHashTable<int, XString> m_SemanticHash;
XHashTable<int, XString> m_AnnotationHash;
XHashTable<int, XString> m_AnnotStrHash;
//--- Same description for all semantic (even synonyms... that's why it's a static array)
XString m_SemanticDescString[ShaderDescriptor_Base::SemCount];
//--- Original Names (use by the Shader Editor)
XClassArray<XString> m_AnnotationNameString;
XClassArray<XString> m_SemanticNameString;
//--- Meaning Instantiators
XArray<MeaningInstantiatorPtr> m_MeaningInstantiatorForFunctions;
XArray<MeaningInstantiatorPtr> m_MeaningInstantiatorForTechniques;
XArray<MeaningInstantiatorPtr> m_MeaningInstantiatorForPasses;
MeaningInstantiatorPtr m_MeaningInstantiatorForParamBySemantic[SemCount];
MeaningInstantiatorPtr m_MeaningInstantiatorForParamByClassAndType[ParamClassCount][ParamTypeCount];
};
/***************************************************************************
____ _ _
/ ___|___ _ ____ _____ _ __ (_) ___ _ __ | |_
| | / _ \| '_ \ \ / / _ \ '_ \| |/ _ \ '_ \| __|
| |__| (_) | | | \ V / __/ | | | | __/ | | | |_
\____ \___/|_| |_|\_/ \___|_| |_|_|\___|_| |_|\__|
| ___| _ _ __ ___| |_(_) ___ _ __ ___
| |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
| _|| |_| | | | | (__| |_| | (_) | | | \__ \
|_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
***************************************************************************/
#ifdef macintosh
//--------------------------------------------------------------------------------
#define Instantiate_Meaning_With_PostCG( meaningClass, iMII ) \
ShaderDescriptorCG::ShaderCG::InstantiateMeaningWithPost( meaningClass::MeaningInstantiator, iMII );
//--------------------------------------------------------------------------------
#define Instantiate_MeaningCG( meaningClass, iMII ) \
ShaderDescriptorCG::ShaderCG::InstantiateMeaning( meaningClass::MeaningInstantiator, iMII );
//--------------------------------------------------------------------------------
#define RegisterMeaningBySemanticCG( sem, meaningClass ) \
this->RegisterParamMeaningForSemantic( sem, meaningClass::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningByClassAndTypeCG( clas, typ, meaningClass ) \
this->RegisterParamMeaningForClassAndType( clas, typ, meaningClass::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningByTypeCG( typ, meaningClass ) \
this->RegisterParamMeaningForType( typ, meaningClass::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningForTechCG( meaningClass ) \
this->RegisterTechMeaning( meaningClass::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningForPassCG( meaningClass ) \
this->RegisterPassMeaning( meaningClass::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningForFctCG( meaningClass ) \
this->RegisterFctMeaning( meaningClass::MeaningInstantiator );
#else
//--------------------------------------------------------------------------------
#define Instantiate_Meaning_With_PostCG( meaningClass, iMII ) \
ShaderDescriptorCG::ShaderCG::InstantiateMeaningWithPost( meaningClass##::MeaningInstantiator, iMII );
//--------------------------------------------------------------------------------
#define Instantiate_MeaningCG( meaningClass, iMII ) \
ShaderDescriptorCG::ShaderCG::InstantiateMeaning( meaningClass##::MeaningInstantiator, iMII );
//--------------------------------------------------------------------------------
#define RegisterMeaningBySemanticCG( sem, meaningClass ) \
this->RegisterParamMeaningForSemantic( sem, meaningClass##::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningByClassAndTypeCG( clas, typ, meaningClass ) \
this->RegisterParamMeaningForClassAndType( clas, typ, meaningClass##::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningByTypeCG( typ, meaningClass ) \
this->RegisterParamMeaningForType( typ, meaningClass##::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningForTechCG( meaningClass ) \
this->RegisterTechMeaning( meaningClass##::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningForPassCG( meaningClass ) \
this->RegisterPassMeaning( meaningClass##::MeaningInstantiator );
//--------------------------------------------------------------------------------
#define RegisterMeaningForFctCG( meaningClass ) \
this->RegisterFctMeaning( meaningClass##::MeaningInstantiator );
#endif
//--------------------------------------------------------------------------------
#define CLASSIC_INSTANTIATOR_DEFINITION_CG( meaningClass ) \
Meaning* \
meaningClass::MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){ \
meaningClass* inst = new meaningClass; \
return inst; \
}
//--------------------------------------------------------------------------------
#define CLASSIC_INSTANTIATOR_DEF_INSIDE_CG( meaningClass ) \
static Meaning* \
MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){ \
meaningClass* inst = new meaningClass; \
return inst; \
}
}
#endif