4172 lines
151 KiB
C++
4172 lines
151 KiB
C++
/////////////////////////////////////////////////////
|
|
// ShaderDescriptor
|
|
/////////////////////////////////////////////////////
|
|
#include "stdafx.h"
|
|
|
|
#ifdef XBOX1
|
|
#include <d3dx8.h>
|
|
#include <d3dx8Effect.h>
|
|
#define D3DXHANDLE DWORD
|
|
#include "CKDX8Rasterizer.h"
|
|
|
|
#include <XGMath.h>
|
|
extern BOOL gRestoreConstantMode;
|
|
|
|
char* FourCC2String(DWORD fcc);
|
|
|
|
|
|
unsigned int g_D3DTypesSizes[] =
|
|
{
|
|
sizeof(DWORD), //D3DXPT_DWORD = 0,
|
|
sizeof(float), //D3DXPT_FLOAT = 1,
|
|
sizeof(D3DVECTOR4), //D3DXPT_VECTOR = 2,
|
|
sizeof(D3DMATRIX), //D3DXPT_MATRIX = 3,
|
|
sizeof(DWORD), //D3DXPT_TEXTURE = 4,
|
|
sizeof(DWORD), //D3DXPT_VERTEXSHADER = 5,
|
|
sizeof(DWORD) //D3DXPT_PIXELSHADER = 6,
|
|
};
|
|
|
|
#define CKTEXTUREDESC CKDX8TextureDesc
|
|
#define DXDEVICE IDirect3DDevice8
|
|
#define DXBASETEXTURE IDirect3DBaseTexture8
|
|
#define DXTEXTURE IDirect3DTexture8
|
|
|
|
#define SetVertexShaderConstantF SetVertexShaderConstantFast
|
|
#define GetInt(a,b) GetDword(a,(DWORD*) b)
|
|
#define SetInt(a,b) SetDword(a,(DWORD)b)
|
|
|
|
DWORD SemanticEnumToFourCC(DWORD iSem);
|
|
#else
|
|
#include <d3dx9effect.h>
|
|
#include "CKDX9Rasterizer.h"
|
|
#define FourCC2String(a) (a)
|
|
#define SemanticEnumToFourCC(a) (a)
|
|
|
|
#define CKTEXTUREDESC CKDX9TextureDesc
|
|
#define DXDEVICE IDirect3DDevice9
|
|
#define DXBASETEXTURE IDirect3DBaseTexture9
|
|
#define DXTEXTURE IDirect3DTexture9
|
|
#endif
|
|
|
|
#include "ShaderDescriptor.h"
|
|
|
|
using namespace ShaderDescriptor;
|
|
|
|
/**************************************************************************/
|
|
/************************* Pre-Declarations *******************************/
|
|
/**************************************************************************/
|
|
|
|
void
|
|
Meaning::PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
m_D3DHandle = iMII.h;
|
|
}
|
|
|
|
/***************************************************************************
|
|
_____ _ _
|
|
| ___| _ _ __ ___| |_(_) ___ _ __
|
|
| |_ | | | | '_ \ / __| __| |/ _ \| '_ \
|
|
| _|| |_| | | | | (__| |_| | (_) | | | |
|
|
|_| \__,_|_| |_|\___|\__|_|\___/|_| |_|
|
|
__ __ _
|
|
| \/ | ___ __ _ _ __ (_)_ __ __ _ ___
|
|
| |\/| |/ _ \/ _` | '_ \| | '_ \ / _` / __|
|
|
| | | | __/ (_| | | | | | | | | (_| \__ \
|
|
|_| |_|\___|\__,_|_| |_|_|_| |_|\__, |___/
|
|
|___/
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Standard FctMeaning
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
FctMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
//--- Selectect the Appropriate FctMeaning
|
|
//... if annot something then inst = (FctMeaning*)Instantiate_Meaning( FctMeaningToExecute );
|
|
|
|
//--- Or return this basic fct meaning
|
|
FctMeaning* inst = new FctMeaning;
|
|
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
FctMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
FctMeaning::PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
Meaning::PostIntantiationCallBack( iMII );
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
m_FunctionDesc = iMII.functionDesc;
|
|
#endif
|
|
}
|
|
|
|
/***************************************************************************
|
|
____ __ __ _
|
|
| _ \ __ _ ___ ___ | \/ | ___ __ _ _ __ (_)_ __ __ _ ___
|
|
| |_) / _` / __/ __| | |\/| |/ _ \/ _` | '_ \| | '_ \ / _` / __|
|
|
| __/ (_| \__ \__ \ | | | | __/ (_| | | | | | | | | (_| \__ \
|
|
|_| \__,_|___/___/ |_| |_|\___|\__,_|_| |_|_|_| |_|\__, |___/
|
|
|___/
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Standard PassMeaning
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
PassMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
//--- Selectect the Appropriate PassMeaning
|
|
//... if annot something then inst = (PassMeaning*)Instantiate_Meaning( PassMeaningToExecute );
|
|
|
|
//--- Or return this basic tech meaning
|
|
PassMeaning* inst = new PassMeaning;
|
|
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
PassMeaning::PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
Meaning::PostIntantiationCallBack( iMII );
|
|
|
|
//--- Store Description
|
|
m_PassDesc = iMII.passDesc;
|
|
|
|
//--- Retrieve the version of shader used
|
|
XString desc;
|
|
|
|
#ifdef XBOX1
|
|
DWORD VSVersion = 0x0101;
|
|
DWORD PSVersion = 0x0101;
|
|
#else
|
|
DWORD VSVersion = m_PassDesc.pVertexShaderFunction ? *(DWORD*)(m_PassDesc.pVertexShaderFunction) : 0;
|
|
DWORD PSVersion = m_PassDesc.pPixelShaderFunction ? *(DWORD*)(m_PassDesc.pPixelShaderFunction) : 0;
|
|
#endif
|
|
if( VSVersion ){
|
|
|
|
m_DescStr.Format("vs%d.%d", (VSVersion >> 8) & 0xFF, VSVersion & 0xFF);
|
|
#if DIRECT3D_VERSION >= 0x0900
|
|
|
|
//--- Retrieve needed shader input stream format
|
|
D3DXSEMANTIC pVSSemantics[MAXD3DDECLLENGTH];
|
|
UINT inSemanticsCount;
|
|
HRESULT res = D3DXGetShaderInputSemantics( m_PassDesc.pVertexShaderFunction, pVSSemantics, &inSemanticsCount );
|
|
for( UINT a=0 ; a<inSemanticsCount ; ++a ){
|
|
|
|
D3DXSEMANTIC& inSemantic = pVSSemantics[a];
|
|
|
|
CKShader* ckShader = iMII.shader->GetCKShader();
|
|
XArray<CKShader::StreamParam>& inputStreamFormats = ckShader->GetInputStreamFormat();
|
|
int b;
|
|
const int biggerParamsCount = inputStreamFormats.Size();
|
|
for( b=0 ; b<biggerParamsCount ; ++b ){
|
|
|
|
CKShader::StreamParam& sp = inputStreamFormats[b];
|
|
if( sp.usage == inSemantic.Usage &&
|
|
sp.usageIndex == inSemantic.UsageIndex ){
|
|
//... should check the size for Dx8 (if size bigger...)
|
|
//... for Dx9 size does not matter
|
|
break;
|
|
}
|
|
}
|
|
//--- If input semantic wasn't used then add it
|
|
if( b == biggerParamsCount ){
|
|
CKShader::StreamParam sp = { inSemantic.Usage, inSemantic.UsageIndex, 0 };
|
|
inputStreamFormats.PushBack( sp );
|
|
}
|
|
}
|
|
#endif // DIRECT3D_VERSION>0x0900
|
|
}
|
|
if (PSVersion)
|
|
{
|
|
desc.Format("ps%d.%d", (PSVersion >> 8) & 0xFF, PSVersion & 0xFF);
|
|
if( m_DescStr.Length() ) m_DescStr += ", ";
|
|
m_DescStr += desc;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
PassMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
}
|
|
|
|
/***************************************************************************
|
|
_____ _ __ __ _
|
|
|_ _|__ ___| |__ | \/ | ___ __ _ _ __ (_)_ __ __ _ ___
|
|
| |/ _ \/ __| '_ \ | |\/| |/ _ \/ _` | '_ \| | '_ \ / _` / __|
|
|
| | __/ (__| | | | | | | | __/ (_| | | | | | | | | (_| \__ \
|
|
|_|\___|\___|_| |_| |_| |_|\___|\__,_|_| |_|_|_| |_|\__, |___/
|
|
|___/
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Standard TechMeaning
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
TechMeaning::TechMeaning() : m_MeshOps( MeshOp_None )
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
TechMeaning::~TechMeaning()
|
|
{
|
|
//--- Parse all Pass Meanings
|
|
const int passCount = m_Passes.Size();
|
|
for( int passIndex=0 ; passIndex<passCount ; ++passIndex ){
|
|
delete m_Passes[passIndex];
|
|
}
|
|
m_Passes.Resize(0);
|
|
|
|
//--- Clear Hash Table
|
|
m_PassIndexFromName.Clear();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
TechMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
//--- Selectect the Appropriate TechMeaning
|
|
//... if annot something then inst = (TechMeaning*)Instantiate_Meaning( TechMeaningToExecute );
|
|
|
|
//--- Or return this basic tech meaning
|
|
TechMeaning* inst = new TechMeaning;
|
|
|
|
//--- Here are the Annotations we are interested in
|
|
bool annotNeedTangentSpace = false;
|
|
bool isAnnotNeedTangentSpaceUsed = false;
|
|
iMII.sdm->ExpectingAnnotation( Annot_NeedTangentSpace, AnnotType_Bool, &annotNeedTangentSpace,
|
|
&isAnnotNeedTangentSpaceUsed );
|
|
|
|
bool annotNeedColorAndNormals = false;
|
|
bool isAnnotNeedColorAndNormalsUsed = false;
|
|
iMII.sdm->ExpectingAnnotation( Annot_NeedColorAndNormal, AnnotType_Bool, &annotNeedColorAndNormals,
|
|
&isAnnotNeedColorAndNormalsUsed );
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.techDesc.Annotations );
|
|
#endif
|
|
//--- Be sure the user explicitly asked to set or remove TANGENT SPACE
|
|
if( isAnnotNeedTangentSpaceUsed ){
|
|
|
|
//--- User asked to build tangent
|
|
if( annotNeedTangentSpace == true ){
|
|
inst->m_MeshOps |= MeshOp_BuildTangentSpace;
|
|
}
|
|
//--- Otherwise user asked to build tangent
|
|
else {
|
|
//inst->m_MeshOps |= MeshOp_RemoveTangentSpace;
|
|
}
|
|
}
|
|
//--- Be sure the user explicitly asked to set or remove USE COLOR AND NORMAL
|
|
if( isAnnotNeedColorAndNormalsUsed ){
|
|
|
|
//--- User asked to build tangent
|
|
if( annotNeedColorAndNormals == true ){
|
|
inst->m_MeshOps |= MeshOp_SetUseColorAndNormal;
|
|
}
|
|
//--- Otherwise user asked to build tangent
|
|
else {
|
|
inst->m_MeshOps |= MeshOp_RemoveUseColorAndNormal;
|
|
}
|
|
}
|
|
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
TechMeaning::PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
Meaning::PostIntantiationCallBack( iMII );
|
|
|
|
//--- Store Description
|
|
m_TechDesc = iMII.techDesc;
|
|
|
|
//--- Validate Technique
|
|
D3DXHANDLE techHandle = iMII.h;
|
|
#if DIRECT3D_VERSION<0x0900
|
|
ID3DXTechnique* tech;
|
|
iMII.fx->GetTechnique(techHandle,&tech);
|
|
XASSERT(tech);
|
|
//m_Validated = SUCCEEDED( tech->Validate());
|
|
m_Validated = true;
|
|
#else
|
|
m_Validated = (iMII.fx->ValidateTechnique( techHandle ) == D3D_OK)? true : false;
|
|
|
|
//--- Due to a DirectX bug, when ValidateTechnique goes wrong it may not call EndPass
|
|
///// so we do it here
|
|
if( !m_Validated ){
|
|
iMII.fx->EndPass();
|
|
}
|
|
|
|
#endif
|
|
m_DescStr = m_Validated ? "Valid":"Invalid";
|
|
|
|
//--- Parse all Passes
|
|
MeaningInstantiatorInfo mii = iMII;
|
|
|
|
const UINT passCount = m_TechDesc.Passes;
|
|
for( UINT passIndex=0 ; passIndex < passCount ; ++passIndex ){
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
D3DXPASS_DESC pDesc;
|
|
tech->GetPassDesc(passIndex,&pDesc);
|
|
mii.h = pDesc.Name;
|
|
#else
|
|
D3DXHANDLE passHandle = iMII.fx->GetPass( techHandle, passIndex );
|
|
mii.h = passHandle;
|
|
#endif
|
|
//--- Generate Pass Meanings
|
|
PassMeaning* passMeaning = iMII.shader->BuildPassMeaning( mii );
|
|
if( passMeaning ){
|
|
|
|
//--- Pass Meaning
|
|
m_Passes.PushBack( passMeaning );
|
|
|
|
//--- Store meaning also in a hash to get it by name
|
|
m_PassIndexFromName.Insert(FourCC2String(passMeaning->m_PassDesc.Name), passIndex );
|
|
|
|
} else {
|
|
//... TODO: Print Message "Can't find meaning for pass"
|
|
}
|
|
}
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
tech->Release();
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
TechMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
//--- If user asked to build tangent space then set the BuildTangentSpace Flag to the mesh
|
|
if( m_MeshOps != MeshOp_None ){
|
|
|
|
CK3dEntity* ent = iMPI.ent;
|
|
if( ent ){
|
|
CKMesh* mesh = ent->GetCurrentMesh();
|
|
if( mesh ){
|
|
|
|
if( m_MeshOps & MeshOp_BuildTangentSpace ){
|
|
mesh->SetFlags( mesh->GetFlags() | VXMESH_GENTANSPACE );
|
|
} else if( m_MeshOps & MeshOp_RemoveTangentSpace ){
|
|
mesh->SetFlags( mesh->GetFlags() & ~VXMESH_GENTANSPACE );
|
|
}
|
|
if( m_MeshOps & MeshOp_SetUseColorAndNormal ){
|
|
mesh->SetFlags( mesh->GetFlags() | VXMESH_USECOLORANDNORMAL );
|
|
} else if( m_MeshOps & MeshOp_RemoveUseColorAndNormal ){
|
|
mesh->SetFlags( mesh->GetFlags() & ~VXMESH_USECOLORANDNORMAL );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//--- Parse all Pass Meanings
|
|
const int passCount = m_Passes.Size();
|
|
for( int passIndex=0 ; passIndex<passCount ; ++passIndex ){
|
|
m_Passes[passIndex]->ProcessCallBack( iMPI );
|
|
}
|
|
}
|
|
|
|
/***************************************************************************
|
|
____ __ __ _
|
|
| _ \ __ _ _ __ __ _ _ __ ___ | \/ | ___ __ _ _ __ (_)_ __ __ _ ___
|
|
| |_) / _` | '__/ _` | '_ ` _ \ | |\/| |/ _ \/ _` | '_ \| | '_ \ / _` / __|
|
|
| __/ (_| | | | (_| | | | | | | | | | | __/ (_| | | | | | | | | (_| \__ \
|
|
|_| \__,_|_| \__,_|_| |_| |_| |_| |_|\___|\__,_|_| |_|_|_| |_|\__, |___/
|
|
|___/
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
Meaning::PostIntantiationCallBack( iMII );
|
|
m_ParamDesc = iMII.paramDesc;
|
|
m_ExpositionType = ExpositionType_Automatic;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueByCastingVectorParam(
|
|
const MeaningProcessingInfo& iMPI, int iInputSize, const void* value )
|
|
{
|
|
#if DIRECT3D_VERSION<0x0900
|
|
if( g_D3DTypesSizes[m_ParamDesc.Type] <= (UINT)iInputSize )
|
|
{
|
|
iMPI.fx->SetVector( m_D3DHandle, (D3DXVECTOR4*) value);
|
|
} else {
|
|
VxVector4 tmpVect(0,0,0,1);
|
|
memcpy( &tmpVect, value, iInputSize );
|
|
|
|
iMPI.fx->SetVector( m_D3DHandle, (D3DXVECTOR4*)&tmpVect);
|
|
}
|
|
#else
|
|
if( m_ParamDesc.Bytes <= (UINT)iInputSize )
|
|
{
|
|
iMPI.fx->SetVector( m_D3DHandle, (D3DXVECTOR4*) value);
|
|
} else {
|
|
VxVector4 tmpVect(0,0,0,1);
|
|
memcpy( &tmpVect, value, iInputSize );
|
|
|
|
iMPI.fx->SetValue( m_D3DHandle, value, m_ParamDesc.Bytes );
|
|
|
|
// Note: we don't use the line beneath, because the following exemple
|
|
// wouldn't work as expected ( emi[0] should receive EMISSIVE )
|
|
// iMPI.fx->SetVector( m_D3DHandle, (D3DXVECTOR4*)&tmpVect);
|
|
//
|
|
// float4 emi[5] : EMISSIVE;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueByMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix )
|
|
{
|
|
#if DIRECT3D_VERSION<0x0900
|
|
D3DXMATRIX tmp;
|
|
D3DXMatrixTranspose(&tmp,(D3DXMATRIX*) (const void*) iMatrix);
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &tmp);
|
|
#else
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) (const void*) iMatrix);
|
|
#endif
|
|
}
|
|
|
|
void
|
|
ParamMeaning::SetValueByTranposingMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix )
|
|
{
|
|
#if DIRECT3D_VERSION<0x0900
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) (const void*) iMatrix);
|
|
#else
|
|
VxMatrix transposeMatrix;
|
|
Vx3DTransposeMatrix( transposeMatrix, iMatrix );
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &transposeMatrix);
|
|
#endif
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueByInversingMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix )
|
|
{
|
|
VxMatrix inverseMatrix;
|
|
Vx3DInverseMatrix( inverseMatrix, iMatrix );
|
|
#if DIRECT3D_VERSION<0x0900
|
|
D3DXMATRIX tmp;
|
|
D3DXMatrixTranspose(&tmp,(D3DXMATRIX*) (const void*) iMPI.rc->GetWorldTransformationMatrix());
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &tmp);
|
|
#else
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &inverseMatrix);
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueByInversingMatrix44( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix )
|
|
{
|
|
VxMatrix inverseMatrix;
|
|
Vx3DInverseMatrix44( inverseMatrix, iMatrix );
|
|
#if DIRECT3D_VERSION<0x0900
|
|
D3DXMATRIX tmp;
|
|
D3DXMatrixTranspose(&tmp,(D3DXMATRIX*) (const void*) iMPI.rc->GetWorldTransformationMatrix());
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &tmp);
|
|
#else
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &inverseMatrix);
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueByInverseTransposingMatrix( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix )
|
|
{
|
|
VxMatrix inverseMatrix;
|
|
Vx3DInverseMatrix( inverseMatrix, iMatrix );
|
|
#if DIRECT3D_VERSION<0x0900
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &inverseMatrix);
|
|
#else
|
|
VxMatrix inverseTransposeMatrix;
|
|
Vx3DTransposeMatrix( inverseTransposeMatrix, inverseMatrix );
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &inverseTransposeMatrix);
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueByInverseTransposingMatrix44( const MeaningProcessingInfo& iMPI, const VxMatrix& iMatrix )
|
|
{
|
|
VxMatrix inverseMatrix;
|
|
Vx3DInverseMatrix44( inverseMatrix, iMatrix );
|
|
#if DIRECT3D_VERSION<0x0900
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &inverseMatrix);
|
|
#else
|
|
VxMatrix inverseTransposeMatrix;
|
|
Vx3DTransposeMatrix( inverseTransposeMatrix, inverseMatrix );
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*) &inverseTransposeMatrix);
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning::SetValueFromCKTexture( const MeaningProcessingInfo& iMPI, CKTexture* iTex )
|
|
{
|
|
DXBASETEXTURE* d3dTex = NULL;
|
|
|
|
if( iTex ){
|
|
iTex->EnsureVideoMemory( iMPI.rc );
|
|
CKTEXTUREDESC* texDesc = (CKTEXTUREDESC*)
|
|
iMPI.rc->GetRasterizerContext()->GetTextureData( iTex->GetRstTextureIndex() );
|
|
if( texDesc ) d3dTex = texDesc->DxCubeTexture;
|
|
}
|
|
|
|
HRESULT hr = iMPI.fx->SetTexture( m_D3DHandle, d3dTex );
|
|
assert( SUCCEEDED(hr) );
|
|
|
|
//--- Set the PreviousTexture variable to point to this texture
|
|
//iMPI.shader->GetManager()->m_PreviousTextureParam = m_D3DHandle;
|
|
}
|
|
|
|
class ExposedFloatSliderParamMeaning;
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Float Slider
|
|
//--------------------------------------------------------------------------------
|
|
class ExposedFloatSliderParamMeaning : public ExposedFloatParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ExposedFloatSliderParamMeaning );
|
|
void CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI ){
|
|
VxVector* paramPtr = (VxVector*)iMPI.param->GetWriteDataPtr();
|
|
iMPI.fx->GetFloat( m_D3DHandle, ¶mPtr->x);
|
|
paramPtr->y = m_UIMin;
|
|
paramPtr->z = m_UIMax;
|
|
};
|
|
float m_UIMin;
|
|
float m_UIMax;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Float
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
ExposedFloatParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
ExposedFloatParamMeaning* inst = NULL;
|
|
|
|
//--- Here are the Annotations we are interested in
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
float annotUIMin = EPSILON;
|
|
float annotUIMax = EPSILON;
|
|
|
|
iMII.sdm->ExpectingAnnotation( Annot_UIMin, AnnotType_Float, &annotUIMin );
|
|
iMII.sdm->ExpectingAnnotation( Annot_UIMax, AnnotType_Float, &annotUIMax );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- UIMin and UIMax ?
|
|
if( annotUIMin!=EPSILON && annotUIMax!=EPSILON ){
|
|
inst = (ExposedFloatSliderParamMeaning*)Instantiate_Meaning( ExposedFloatSliderParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_FLOATSLIDER;
|
|
((ExposedFloatSliderParamMeaning*)inst)->m_UIMin = annotUIMin;
|
|
((ExposedFloatSliderParamMeaning*)inst)->m_UIMax = annotUIMax;
|
|
} else
|
|
#endif // DIRECT3D_VERSION>=0x0900
|
|
{
|
|
inst = new ExposedFloatParamMeaning;
|
|
inst->m_Guid = CKPGUID_FLOAT;
|
|
}
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ExposedFloatParamMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
iMPI.fx->SetFloat( m_D3DHandle, *(float*)iMPI.param->GetReadDataPtr());
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ExposedFloatParamMeaning::CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
iMPI.fx->GetFloat( m_D3DHandle, (float*)iMPI.param->GetWriteDataPtr());
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Dword
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
ExposedDwordParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
ExposedDwordParamMeaning* inst = NULL;
|
|
inst = new ExposedDwordParamMeaning;
|
|
inst->m_Guid = CKPGUID_INT;
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ExposedDwordParamMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
iMPI.fx->SetInt( m_D3DHandle, *(int*)iMPI.param->GetReadDataPtr());
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ExposedDwordParamMeaning::CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
iMPI.fx->GetInt( m_D3DHandle, (int*)iMPI.param->GetWriteDataPtr());
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Standard Params (To Derived)
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ExposedParamMeaning::PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
ParamMeaning::PostIntantiationCallBack( iMII );
|
|
m_ExpositionType = ExpositionType_Exposed;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
ExposedParamMeaning::~ExposedParamMeaning()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExposedParamMeaning::CopyDefaultValueFromShaderToParamCB( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
//--- By default do this, but obviously it's better to define a
|
|
///// real derived method for each kind of exposed parameters
|
|
if( !( iMPI.param->GetGUID() == CKPGUID_3DENTITY
|
|
|| iMPI.param->GetGUID() == CKPGUID_TEXTURE
|
|
|| iMPI.param->GetGUID() == CKPGUID_DATAARRAY ) ){
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
switch(iMPI.param->GetDataSize()){
|
|
case 4:
|
|
iMPI.fx->GetInt( m_D3DHandle, (DWORD*) iMPI.param->GetWriteDataPtr());
|
|
break;
|
|
case 16:
|
|
iMPI.fx->GetVector( m_D3DHandle, (D3DXVECTOR4*) iMPI.param->GetWriteDataPtr());
|
|
break;
|
|
case 64:
|
|
iMPI.fx->GetMatrix( m_D3DHandle, (D3DXMATRIX*) iMPI.param->GetWriteDataPtr());
|
|
break;
|
|
}
|
|
#else
|
|
if( iMPI.param->GetGUID() == CKPGUID_STRING ){
|
|
|
|
const char *tmp;
|
|
iMPI.fx->GetString( m_D3DHandle, &tmp );
|
|
iMPI.param->SetStringValue( (char*)tmp );
|
|
|
|
} else {
|
|
iMPI.fx->GetValue( m_D3DHandle, iMPI.param->GetWriteDataPtr(), iMPI.param->GetDataSize() );
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
static const CKGUID columnMatchingGuid[] = {
|
|
CKGUID(),
|
|
CKPGUID_FLOAT,
|
|
CKPGUID_2DVECTOR,
|
|
CKPGUID_VECTOR,
|
|
CKPGUID_COLOR,
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
Meaning*
|
|
ExposedParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){
|
|
|
|
const D3DXPARAMETER_DESC& desc = iMII.paramDesc;
|
|
|
|
ExposedParamMeaning* inst = NULL;
|
|
|
|
switch( desc.Type )
|
|
{
|
|
case D3DXPT_DWORD:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedDwordParamMeaning, iMII );
|
|
break;
|
|
case D3DXPT_FLOAT:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedFloatParamMeaning, iMII );
|
|
break;
|
|
case D3DXPT_VECTOR:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedXDVectorParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_VECTOR4;
|
|
break;
|
|
case D3DXPT_MATRIX:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedMatrixParamMeaning, iMII );
|
|
break;
|
|
case D3DXPT_TEXTURE:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedTextureParamMeaning, iMII );
|
|
break;
|
|
}
|
|
|
|
return inst;
|
|
}
|
|
#else
|
|
Meaning*
|
|
ExposedParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){
|
|
|
|
const D3DXPARAMETER_DESC& desc = iMII.paramDesc;
|
|
|
|
ExposedParamMeaning* inst = NULL;
|
|
|
|
static CKGUID typemap[] =
|
|
{
|
|
CKGUID(), //D3DXPT_VOID,
|
|
CKPGUID_BOOL, //D3DXPT_BOOL,
|
|
CKPGUID_INT, //D3DXPT_INT,
|
|
CKPGUID_FLOAT, //D3DXPT_FLOAT,
|
|
CKPGUID_STRING, //D3DXPT_STRING,
|
|
CKPGUID_TEXTURE,//D3DXPT_TEXTURE,
|
|
CKPGUID_TEXTURE,//D3DXPT_TEXTURE1D,
|
|
CKPGUID_TEXTURE,//D3DXPT_TEXTURE2D,
|
|
CKPGUID_TEXTURE,//D3DXPT_TEXTURE3D,
|
|
CKPGUID_TEXTURE,//D3DXPT_TEXTURECUBE,
|
|
CKGUID(), //D3DXPT_SAMPLER,
|
|
CKGUID(), //D3DXPT_SAMPLER1D,
|
|
CKGUID(), //D3DXPT_SAMPLER2D,
|
|
CKGUID(), //D3DXPT_SAMPLER3D,
|
|
CKGUID(), //D3DXPT_SAMPLERCUBE,
|
|
CKGUID(), //D3DXPT_PIXELSHADER,
|
|
CKGUID(), //D3DXPT_VERTEXSHADER,
|
|
CKGUID(), //D3DXPT_PIXELFRAGMENT,
|
|
CKGUID() //D3DXPT_VERTEXFRAGMENT,
|
|
};
|
|
|
|
switch( desc.Class )
|
|
{
|
|
case D3DXPC_OBJECT:
|
|
case D3DXPC_SCALAR:
|
|
if( desc.Elements>1 ){
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedArrayParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_DATAARRAY;
|
|
((ExposedArrayParamMeaning*)inst)->m_Guid2 = typemap[desc.Type];
|
|
|
|
} else {
|
|
|
|
CKGUID tmpGuid = typemap[desc.Type];
|
|
if( tmpGuid == CKPGUID_FLOAT ){
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedFloatParamMeaning, iMII );
|
|
} else if( tmpGuid == CKPGUID_INT || tmpGuid == CKPGUID_BOOL ){
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedDwordParamMeaning, iMII );
|
|
if( inst ) inst->m_Guid = tmpGuid;
|
|
} else
|
|
if( tmpGuid == CKPGUID_TEXTURE ) {
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedTextureParamMeaning, iMII );
|
|
}
|
|
}
|
|
break;
|
|
case D3DXPC_MATRIX_ROWS:
|
|
if (desc.Type == D3DXPT_FLOAT){
|
|
if( desc.Elements > 1){
|
|
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedArrayParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_DATAARRAY;
|
|
((ExposedArrayParamMeaning*)inst)->m_Guid2 = CKPGUID_MATRIX;
|
|
|
|
} else {
|
|
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedMatrixParamMeaning, iMII );
|
|
}
|
|
}
|
|
break;
|
|
case D3DXPC_VECTOR:
|
|
if( desc.Type == D3DXPT_FLOAT )
|
|
|
|
if( desc.Elements > 1){
|
|
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedArrayParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_DATAARRAY;
|
|
((ExposedArrayParamMeaning*)inst)->m_Guid2 = CKPGUID_MATRIX;
|
|
|
|
if( desc.Columns>4 || desc.Columns<1 ) break;
|
|
((ExposedArrayParamMeaning*)inst)->m_Guid2 = columnMatchingGuid[ desc.Columns ];
|
|
|
|
//If 4 floats, assigned by default as color, but it can be a vector4D
|
|
//Let's check annotation
|
|
|
|
if(desc.Columns==4)
|
|
{
|
|
XString annotType;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Type, AnnotType_String, &annotType );
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
if((annotType.Length())&&(iMII.sdm->GetAnnotStrValueIndexFromString( annotType )==AnnotStr_Vector))
|
|
((ExposedArrayParamMeaning*)inst)->m_Guid2 = CKPGUID_VECTOR4;
|
|
}
|
|
|
|
} else {
|
|
|
|
switch( desc.Columns )
|
|
{
|
|
case 2:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( Exposed2DVectorParamMeaning, iMII );
|
|
break;
|
|
default:
|
|
inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedXDVectorParamMeaning, iMII );
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
if( !inst ) return NULL;
|
|
|
|
return inst;
|
|
}
|
|
#endif
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Vector Param (To Derived)
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
CLASSIC_INSTANTIATOR_DEFINITION( ExposedVectorizableParamMeaning );
|
|
void
|
|
ExposedVectorizableParamMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
int inputSize = iMPI.param->GetDataSize();
|
|
SetValueByCastingVectorParam( iMPI, inputSize, iMPI.param->GetReadDataPtr() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// TexelSize
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_TexelSize : public ParamMeaning {
|
|
public:
|
|
ParamMeaning_TexelSize() : m_TexParamHandle( 0 ){}
|
|
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){
|
|
|
|
ParamMeaning_TexelSize* inst = new ParamMeaning_TexelSize;
|
|
|
|
//--- Parse previous parameters to find a texture parameter
|
|
for( int a=iMII.paramIndex-1 ; a>=0 ; --a ){
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
D3DXHANDLE previousParamHandle = a;
|
|
#else
|
|
D3DXHANDLE previousParamHandle = iMII.fx->GetParameter( NULL, a );
|
|
XASSERT( previousParamHandle != NULL );
|
|
#endif
|
|
D3DXPARAMETER_DESC desc;
|
|
HRESULT hr = iMII.fx->GetParameterDesc( previousParamHandle, &desc );
|
|
XASSERT( D3D_OK == hr);
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
if( desc.Type == D3DXPT_TEXTURE || desc.Type == D3DXPT_TEXTURE2D || desc.Type == D3DXPT_TEXTURECUBE )
|
|
#else
|
|
if( desc.Type == D3DXPT_TEXTURE)
|
|
#endif
|
|
{
|
|
#if DIRECT3D_VERSION<0x0900
|
|
inst->m_TexParamHandle = desc.Name;
|
|
#else
|
|
inst->m_TexParamHandle = previousParamHandle;
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
|
|
return inst;
|
|
}
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
//--- Initialize texelSize to 0, that way if there's no valid texture,
|
|
///// texelSize won't be undefined (can also be used to test texture validity)
|
|
Vx2DVector texelSize(0,0);
|
|
|
|
do {
|
|
|
|
//--- Check that texture param exists
|
|
if( !m_TexParamHandle ) break;
|
|
|
|
//--- Get interface to d3d base texture From D3DXHANDLE
|
|
DXBASETEXTURE* d3dTexture=NULL;
|
|
iMPI.fx->GetTexture( m_TexParamHandle, &d3dTexture );
|
|
if( !d3dTexture ) break;
|
|
|
|
//--- Get interface to d3d texture
|
|
DXTEXTURE* texture = NULL;
|
|
#ifdef _XBOX
|
|
texture = (DXTEXTURE*) d3dTexture;
|
|
texture->AddRef();
|
|
#else
|
|
d3dTexture->QueryInterface( IID_IDirect3DTexture9, (void**)&texture);
|
|
#endif
|
|
if( !texture ){
|
|
d3dTexture->Release();
|
|
break;
|
|
}
|
|
|
|
//--- Get texture desc
|
|
D3DSURFACE_DESC desc;
|
|
texture->GetLevelDesc( 0, &desc );
|
|
|
|
//--- Compute Texel Size from Texture Width and Height
|
|
texelSize.Set( 1.0f/desc.Width, 1.0f/desc.Height );
|
|
|
|
//--- Release D3D Interfaces
|
|
d3dTexture->Release();
|
|
texture->Release();
|
|
|
|
} while(0);
|
|
|
|
//--- Put Texel Size inside given parameter (the one with the texelsize semantic)
|
|
SetValueByCastingVectorParam( iMPI, sizeof(Vx2DVector), &texelSize );
|
|
}
|
|
|
|
D3DXHANDLE m_TexParamHandle;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// TextureSize
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_TextureSize : public ParamMeaning {
|
|
public:
|
|
ParamMeaning_TextureSize() : m_TexParamHandle( 0 ){}
|
|
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){
|
|
|
|
ParamMeaning_TextureSize* inst = new ParamMeaning_TextureSize;
|
|
|
|
//--- Parse previous parameters to find a texture parameter
|
|
for( int a=iMII.paramIndex-1 ; a>=0 ; --a ){
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
D3DXHANDLE previousParamHandle = a;
|
|
#else
|
|
D3DXHANDLE previousParamHandle = iMII.fx->GetParameter( NULL, a );
|
|
XASSERT( previousParamHandle != NULL );
|
|
#endif
|
|
D3DXPARAMETER_DESC desc;
|
|
HRESULT hr = iMII.fx->GetParameterDesc( previousParamHandle, &desc );
|
|
XASSERT( D3D_OK == hr);
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
if( desc.Type == D3DXPT_TEXTURE || desc.Type == D3DXPT_TEXTURE2D || desc.Type == D3DXPT_TEXTURECUBE )
|
|
#else
|
|
if( desc.Type == D3DXPT_TEXTURE)
|
|
#endif
|
|
{
|
|
#if DIRECT3D_VERSION<0x0900
|
|
inst->m_TexParamHandle = desc.Name;
|
|
#else
|
|
inst->m_TexParamHandle = previousParamHandle;
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
|
|
return inst;
|
|
}
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
//--- Initialize TextureSize to 0, that way if there's no valid texture,
|
|
///// TextureSize won't be undefined (can also be used to test texture validity)
|
|
Vx2DVector TextureSize(0,0);
|
|
|
|
do {
|
|
|
|
//--- Check that texture param exists
|
|
if( !m_TexParamHandle ) break;
|
|
|
|
//--- Get interface to d3d base texture From D3DXHANDLE
|
|
DXBASETEXTURE* d3dTexture=NULL;
|
|
iMPI.fx->GetTexture( m_TexParamHandle, &d3dTexture );
|
|
if( !d3dTexture ) break;
|
|
|
|
//--- Get interface to d3d texture
|
|
DXTEXTURE* texture = NULL;
|
|
#ifdef _XBOX
|
|
texture = (DXTEXTURE*) d3dTexture;
|
|
texture->AddRef();
|
|
#else
|
|
d3dTexture->QueryInterface( IID_IDirect3DTexture9, (void**)&texture);
|
|
#endif
|
|
if( !texture ){
|
|
d3dTexture->Release();
|
|
break;
|
|
}
|
|
|
|
//--- Get texture desc
|
|
D3DSURFACE_DESC desc;
|
|
texture->GetLevelDesc( 0, &desc );
|
|
|
|
//--- Compute Texture Size from Texture Width and Height
|
|
TextureSize.Set( 1.0f/desc.Width, 1.0f/desc.Height );
|
|
|
|
//--- Release D3D Interfaces
|
|
d3dTexture->Release();
|
|
texture->Release();
|
|
|
|
} while(0);
|
|
|
|
//--- Put Texture Size inside given parameter (the one with the Texturesize semantic)
|
|
SetValueByCastingVectorParam( iMPI, sizeof(Vx2DVector), &TextureSize );
|
|
}
|
|
|
|
D3DXHANDLE m_TexParamHandle;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed 2DVector Param (To Derived)
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
|
|
Meaning*
|
|
Exposed2DVectorParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
//--- Here are the Annotations we are interested in
|
|
bool annotIsTexelSize = false;
|
|
|
|
iMII.sdm->ExpectingAnnotation( Annot_IsTexelSize, AnnotType_Bool, &annotIsTexelSize );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- IsTexelSize = true ?
|
|
if( annotIsTexelSize == true ){
|
|
ParamMeaning * inst = (ParamMeaning*)Instantiate_Meaning( ParamMeaning_TexelSize, iMII );
|
|
return inst;
|
|
}
|
|
|
|
//--- Otherwise
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedVectorizableParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_2DVECTOR;
|
|
|
|
return inst;
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Object's Position Param
|
|
//--------------------------------------------------------------------------------
|
|
class ExposedParamMeaning_ObjectPos : public ExposedParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ExposedParamMeaning_ObjectPos );
|
|
ExposedParamMeaning_ObjectPos() :
|
|
m_ReferentialEnum( AnnotStr_Unknown ){}
|
|
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
CK3dEntity* ent = (CK3dEntity*)iMPI.param->GetValueObject(FALSE);
|
|
if( !ent ) return;
|
|
|
|
VxVector objPos;
|
|
|
|
//--- Get referential in which to retrieve light information
|
|
CK3dEntity* referential = (m_ReferentialEnum == AnnotStr_Local)? iMPI.ent:NULL;
|
|
ent->GetPosition( &objPos, referential );
|
|
|
|
// NOTE: we should be able to do just the above, but iMPI.ent is NULL for
|
|
// exposed params, so for the moment we inverse the current world matrix.
|
|
// When there will be PerObjectMeanings iMPI.ent will be correct,
|
|
// and we'll remove this crappy matrix inversion
|
|
if( m_ReferentialEnum == AnnotStr_Local ){
|
|
VxMatrix worldMatrix = iMPI.rc->GetWorldTransformationMatrix();
|
|
VxMatrix invWorldMatrix;
|
|
Vx3DInverseMatrix( invWorldMatrix, worldMatrix );
|
|
Vx3DMultiplyMatrixVector( &objPos, invWorldMatrix, &objPos );
|
|
}
|
|
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &objPos );
|
|
}
|
|
int m_ReferentialEnum;
|
|
};
|
|
#endif // _XBOX
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed XDVector Param (To Derived)
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
ExposedXDVectorParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
#if DIRECT3D_VERSION<0x0900
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedVectorizableParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_VECTOR4;
|
|
#else
|
|
//--- Here are the Annotations we are interested in
|
|
XString annotType;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Type, AnnotType_String, &annotType );
|
|
|
|
XString annotSpace;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Space, AnnotType_String, &annotSpace );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- Space = ?
|
|
int annotSpaceStrValueIndex = AnnotStr_Unknown;
|
|
if( annotSpace.Length() ){
|
|
annotSpaceStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotSpace );
|
|
}
|
|
//--- Type = ?
|
|
if( annotType.Length() ){
|
|
|
|
int annotStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotType );
|
|
switch( annotStrValueIndex ){
|
|
|
|
//--- Type = "3dEntity" ?
|
|
case AnnotStr_Entity3D:
|
|
{
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedParamMeaning_ObjectPos, iMII );
|
|
inst->m_Guid = CKPGUID_3DENTITY;
|
|
((ExposedParamMeaning_ObjectPos*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
return inst;
|
|
} break;
|
|
|
|
//--- Type = "Camera" ?
|
|
case AnnotStr_Camera:
|
|
{
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedParamMeaning_ObjectPos, iMII );
|
|
inst->m_Guid = CKPGUID_CAMERA;
|
|
((ExposedParamMeaning_ObjectPos*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
return inst;
|
|
} break;
|
|
|
|
//--- Type = "Light" ?
|
|
case AnnotStr_Light:
|
|
{
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedParamMeaning_ObjectPos, iMII );
|
|
inst->m_Guid = CKPGUID_LIGHT;
|
|
((ExposedParamMeaning_ObjectPos*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
return inst;
|
|
} break;
|
|
|
|
//--- Type = "vector" ?
|
|
case AnnotStr_Vector:
|
|
{
|
|
if( iMII.paramDesc.Columns == 4 ){
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedVectorizableParamMeaning, iMII );
|
|
inst->m_Guid = CKPGUID_VECTOR4;
|
|
return inst;
|
|
}
|
|
} break;
|
|
}
|
|
}
|
|
//--- Otherwise it's a single ExposedVectorizableParamMeaning
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedVectorizableParamMeaning, iMII );
|
|
if( iMII.paramDesc.Columns>4 || iMII.paramDesc.Columns<1 ) return inst;
|
|
inst->m_Guid = columnMatchingGuid[ iMII.paramDesc.Columns ];
|
|
#endif
|
|
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Object's Matrix Param
|
|
//--------------------------------------------------------------------------------
|
|
class ExposedParamMeaning_ObjectMatrix : public ExposedParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ExposedParamMeaning_ObjectMatrix );
|
|
ExposedParamMeaning_ObjectMatrix() :
|
|
m_ReferentialEnum( AnnotStr_Unknown ){}
|
|
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
CK3dEntity* ent = (CK3dEntity*)iMPI.param->GetValueObject(FALSE);
|
|
if( !ent ) return;
|
|
|
|
//--- Get referential in which to retrieve information
|
|
CK3dEntity* referential = (m_ReferentialEnum == AnnotStr_Local)? iMPI.ent:NULL;
|
|
VxMatrix objMatrix = ent->GetWorldMatrix();
|
|
|
|
if( referential ){
|
|
Vx3DMultiplyMatrix( objMatrix, referential->GetInverseWorldMatrix(), ent->GetWorldMatrix() );
|
|
}
|
|
SetValueByMatrix( iMPI, objMatrix );
|
|
}
|
|
int m_ReferentialEnum;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Matrix Params
|
|
//--------------------------------------------------------------------------------
|
|
Meaning* ExposedMatrixParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--- Here are the Annotations we are interested in
|
|
XString annotType;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Type, AnnotType_String, &annotType );
|
|
|
|
XString annotSpace;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Space, AnnotType_String, &annotSpace );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- Space = ?
|
|
int annotSpaceStrValueIndex = AnnotStr_Unknown;
|
|
if( annotSpace.Length() ){
|
|
annotSpaceStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotSpace );
|
|
}
|
|
//--- Type = ?
|
|
if( annotType.Length() ){
|
|
|
|
int annotStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotType );
|
|
switch( annotStrValueIndex ){
|
|
|
|
//--- Type = "3dEntity" ?
|
|
case AnnotStr_Entity3D:
|
|
{
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedParamMeaning_ObjectMatrix, iMII );
|
|
inst->m_Guid = CKPGUID_3DENTITY;
|
|
((ExposedParamMeaning_ObjectMatrix*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
return inst;
|
|
} break;
|
|
|
|
//--- Type = "Camera" ?
|
|
case AnnotStr_Camera:
|
|
{
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedParamMeaning_ObjectMatrix, iMII );
|
|
inst->m_Guid = CKPGUID_CAMERA;
|
|
((ExposedParamMeaning_ObjectPos*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
return inst;
|
|
} break;
|
|
|
|
//--- Type = "Light" ?
|
|
case AnnotStr_Light:
|
|
{
|
|
ExposedParamMeaning* inst = (ExposedParamMeaning*)Instantiate_Meaning( ExposedParamMeaning_ObjectMatrix, iMII );
|
|
inst->m_Guid = CKPGUID_LIGHT;
|
|
((ExposedParamMeaning_ObjectPos*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
return inst;
|
|
} break;
|
|
|
|
}
|
|
}
|
|
#endif
|
|
ExposedMatrixParamMeaning* inst = new ExposedMatrixParamMeaning;
|
|
inst->m_Guid = CKPGUID_MATRIX;
|
|
return inst;
|
|
}
|
|
|
|
void
|
|
ExposedMatrixParamMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
VxMatrix* matrix = (VxMatrix*)iMPI.param->GetReadDataPtr();
|
|
SetValueByMatrix(iMPI,*matrix);
|
|
}
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Array Params
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------
|
|
CLASSIC_INSTANTIATOR_DEFINITION( ExposedArrayParamMeaning );
|
|
void
|
|
ExposedArrayParamMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
CKDataArray* ar = (CKDataArray*) iMPI.param->GetValueObject();
|
|
if( !ar ) return;
|
|
|
|
int columnCount = ar->GetColumnCount();
|
|
int rowCount = ar->GetRowCount();
|
|
|
|
//--- Do Nothing if destination size is smaller than source size
|
|
if( m_ParamDesc.Elements < (DWORD)( rowCount * columnCount ) ) return;
|
|
|
|
//--- Do Nothing if Columns Types are different from the Shader Array Type
|
|
for( int a=0 ; a<columnCount ; ++a ){
|
|
|
|
CK_ARRAYTYPE columnType = ar->GetColumnType(0);
|
|
CKGUID columnGUID = CKGUID();
|
|
|
|
switch( columnType ){
|
|
case CKARRAYTYPE_INT:
|
|
columnGUID = CKPGUID_INT;
|
|
break;
|
|
case CKARRAYTYPE_FLOAT:
|
|
columnGUID = CKPGUID_FLOAT;
|
|
break;
|
|
case CKARRAYTYPE_STRING:
|
|
columnGUID = CKGUID();
|
|
break;
|
|
case CKARRAYTYPE_OBJECT:
|
|
columnGUID = CKGUID();
|
|
break;
|
|
case CKARRAYTYPE_PARAMETER:
|
|
columnGUID = ar->GetColumnParameterGuid( a );
|
|
break;
|
|
}
|
|
if( columnGUID != m_Guid2 ) return;
|
|
}
|
|
//--- Copy values from CKArray
|
|
BYTE* temp = new BYTE[ m_ParamDesc.Bytes ];
|
|
BYTE* it = temp;
|
|
const DWORD stride = m_ParamDesc.Bytes/m_ParamDesc.Elements;
|
|
|
|
for(int i = 0;i<columnCount;i++){
|
|
|
|
for( int j = 0;j<rowCount ; j++ ){
|
|
ar->GetElementValue(j,i,it);
|
|
it += stride;
|
|
}
|
|
}
|
|
|
|
iMPI.fx->SetValue( m_D3DHandle, temp, m_ParamDesc.Bytes );
|
|
|
|
delete [] temp;
|
|
}
|
|
#endif
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Exposed Texture Params
|
|
//--------------------------------------------------------------------------------
|
|
|
|
D3DFORMAT StringToD3DFormat( LPCSTR pstrFormat );
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
class ParamMeaning_ExistingTexture : public ParamMeaning {
|
|
public:
|
|
//--- This meaning provide to update Direct3D texture handle when virtools existing texture were flushed.
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
if(m_CKID)
|
|
{
|
|
CKTexture* tex = (CKTexture*)iMPI.shader->GetManager()->GetCKContext()->GetObject(m_CKID);
|
|
if (!tex) m_CKID = 0;
|
|
SetValueFromCKTexture( iMPI, tex );
|
|
}
|
|
}
|
|
|
|
CK_ID m_CKID;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
ExposedTextureParamMeaning::MeaningInstantiator( const MeaningInstantiatorInfo& iMII ){
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--- Here are the Annotations we are interested in
|
|
XString annotName;
|
|
XString annotRscName;
|
|
XString annotFunction;
|
|
XString annotTarget;
|
|
XString annotTextureType;
|
|
XString annotFormat;
|
|
|
|
INT annotWidth = D3DX_DEFAULT;
|
|
INT annotHeight= D3DX_DEFAULT;
|
|
INT annotDepth = D3DX_DEFAULT;
|
|
INT annotMipLevels = 1;
|
|
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
|
VxVector4 annotDim( 0, 0, 0, 0 );
|
|
|
|
iMII.sdm->ExpectingAnnotation( Annot_Name, AnnotType_String, &annotName );
|
|
iMII.sdm->ExpectingAnnotation( Annot_ResourceName, AnnotType_String, &annotRscName );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Function, AnnotType_String, &annotFunction );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Target, AnnotType_String, &annotTarget );
|
|
iMII.sdm->ExpectingAnnotation( Annot_ResourceType, AnnotType_String, &annotTextureType );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Format, AnnotType_String, &annotFormat );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Width, AnnotType_Int, &annotWidth );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Height, AnnotType_Int, &annotHeight );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Depth, AnnotType_Int, &annotDepth );
|
|
iMII.sdm->ExpectingAnnotation( Annot_Dimensions, AnnotType_Vector4, &annotDim );
|
|
iMII.sdm->ExpectingAnnotation( Annot_MIPLevels, AnnotType_Int, &annotMipLevels );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- Do the job
|
|
CKContext* ctx = iMII.sdm->GetCKContext();
|
|
CKRenderContext* rc = iMII.shader->GetRenderContext();
|
|
|
|
VxDirectXData *dat = rc->GetDirectXInfo();
|
|
LPDIRECT3DDEVICE9 dev9 = (LPDIRECT3DDEVICE9) dat->D3DDevice;
|
|
LPDIRECT3DBASETEXTURE9 pTex = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
XString strErrors;
|
|
|
|
LPDIRECT3DBASETEXTURE9 existingTex = NULL;
|
|
ParamMeaning_ExistingTexture* instExistingTexture = NULL;
|
|
|
|
//--- Use an Existing CKTexture if Name
|
|
if( annotName.Length() )
|
|
{
|
|
CKTexture* tex = (CKTexture*) ctx->GetObjectByNameAndClass( annotName.Str(), CKCID_TEXTURE );
|
|
if(tex){
|
|
instExistingTexture = new ParamMeaning_ExistingTexture;
|
|
instExistingTexture->m_CKID = tex->GetID();
|
|
|
|
tex->EnsureVideoMemory( rc );
|
|
CKTEXTUREDESC* tdesc = (CKTEXTUREDESC*) tex->GetRstTextureObject();
|
|
if(tdesc){
|
|
existingTex = tdesc->DxTexture;
|
|
iMII.fx->SetTexture( iMII.h, existingTex );
|
|
}
|
|
} else {
|
|
strErrors = "Unknown Texture ";
|
|
strErrors += annotName;
|
|
iMII.sdm->GetShaderManager()->m_Output.PushBack( strErrors );
|
|
}
|
|
}
|
|
|
|
//--- Load a texture file if ResourceName
|
|
if( annotRscName.Length() )
|
|
{
|
|
pTex = NULL;
|
|
ctx->GetPathManager()->ResolveFileName( annotRscName, BITMAP_PATH_IDX );
|
|
|
|
int annotStrValueIndex;
|
|
|
|
//--- There's a Texture Type Specified
|
|
if( annotTextureType.Length() )
|
|
{
|
|
annotStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotTextureType );
|
|
} else
|
|
//--- There's no Texture Type Specified
|
|
{
|
|
annotStrValueIndex = AnnotStr_2d;
|
|
}
|
|
switch( annotStrValueIndex ){
|
|
|
|
case AnnotStr_Volume:
|
|
case AnnotStr_3d:
|
|
{
|
|
LPDIRECT3DVOLUMETEXTURE9 pVolumeTex = NULL;
|
|
if( SUCCEEDED( hr = D3DXCreateVolumeTextureFromFileEx( dev9 , annotRscName.CStr(),
|
|
annotWidth, annotHeight, annotDepth, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
|
|
D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &pVolumeTex ) ) )
|
|
{
|
|
pTex = pVolumeTex;
|
|
}
|
|
else
|
|
{
|
|
strErrors = "Could not load volume texture ";
|
|
strErrors += annotRscName.CStr();
|
|
iMII.sdm->GetShaderManager()->m_Output.PushBack( strErrors );
|
|
}
|
|
} break;
|
|
|
|
case AnnotStr_Cube:
|
|
{
|
|
LPDIRECT3DCUBETEXTURE9 pCubeTex = NULL;
|
|
if( SUCCEEDED( hr = D3DXCreateCubeTextureFromFileEx( dev9 , annotRscName.CStr(),
|
|
annotWidth, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
|
|
D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &pCubeTex ) ) )
|
|
{
|
|
pTex = pCubeTex;
|
|
}
|
|
else
|
|
{
|
|
strErrors = "Could not load cube texture ";
|
|
strErrors += annotRscName.CStr();
|
|
iMII.sdm->GetShaderManager()->m_Output.PushBack( strErrors );
|
|
}
|
|
} break;
|
|
|
|
case AnnotStr_Unknown:
|
|
{
|
|
strErrors = "Unknown Texture Type ";
|
|
strErrors += annotTextureType.CStr();
|
|
iMII.sdm->GetShaderManager()->m_Output.PushBack( strErrors );
|
|
}
|
|
|
|
case AnnotStr_2d:
|
|
{
|
|
LPDIRECT3DTEXTURE9 p2DTex = NULL;
|
|
if( SUCCEEDED( hr = D3DXCreateTextureFromFileEx( dev9 , annotRscName.CStr(),
|
|
annotWidth, annotHeight, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
|
|
D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &p2DTex ) ) )
|
|
{
|
|
pTex = p2DTex;
|
|
}
|
|
else
|
|
{
|
|
strErrors = "Could not load texture ";
|
|
strErrors += annotRscName.CStr();
|
|
iMII.sdm->GetShaderManager()->m_Output.PushBack( strErrors );
|
|
}
|
|
}break;
|
|
}
|
|
|
|
//--- Apply successfully loaded texture to effect
|
|
if( SUCCEEDED(hr) && pTex != NULL )
|
|
{
|
|
iMII.fx->SetTexture( iMII.h, pTex );
|
|
pTex->Release();
|
|
if (instExistingTexture) delete instExistingTexture;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
//--- Procedural texture if Function
|
|
else if( annotFunction.Length() )
|
|
{
|
|
LPD3DXBUFFER pFunction = NULL;
|
|
#ifdef _XBOX
|
|
D3DXVECTOR4* pConstants = NULL;
|
|
UINT nbConstants = 0;
|
|
#else
|
|
LPD3DXTEXTURESHADER pTextureShader = NULL;
|
|
#endif
|
|
LPD3DXCONSTANTTABLE ppConstantTable = NULL;
|
|
|
|
CKShader* shader = iMII.shader->GetCKShader();
|
|
|
|
UINT EffectLength = shader->GetText().Length();
|
|
const char* strEffectA = shader->GetText().CStr();
|
|
|
|
if( !annotTarget.Length() ){
|
|
annotTarget = "tx_1_0";
|
|
}
|
|
|
|
LPD3DXBUFFER pBufferErrors = NULL;
|
|
if( SUCCEEDED( hr = D3DXCompileShader(
|
|
strEffectA, (UINT)strlen(strEffectA), NULL,
|
|
(ID3DXInclude*)iMII.sdm->GetShaderManager()->GetIncludeManager(),
|
|
annotFunction.CStr(), annotTarget.CStr(), 0, &pFunction, &pBufferErrors, &ppConstantTable ) ) )
|
|
{
|
|
#ifdef _XBOX
|
|
if(ppConstantTable){
|
|
ppConstantTable->SetDefaults(dev9);
|
|
pConstants = (D3DXVECTOR4*) ppConstantTable->GetBufferPointer();
|
|
D3DXCONSTANTTABLE_DESC desc;
|
|
ppConstantTable->GetDesc(&desc);
|
|
nbConstants = desc.Constants;
|
|
}
|
|
#else
|
|
if( SUCCEEDED( hr = D3DXCreateTextureShader((DWORD *)pFunction->GetBufferPointer(), &pTextureShader) ) )
|
|
#endif
|
|
{
|
|
//--- Using Existing Texture
|
|
if( existingTex ){
|
|
D3DRESOURCETYPE type = existingTex->GetType();
|
|
switch( type ){
|
|
case D3DRTYPE_CUBETEXTURE:
|
|
#ifdef _XBOX
|
|
hr = D3DXFillCubeTextureTX((LPDIRECT3DCUBETEXTURE9) existingTex, (DWORD*) pFunction->GetBufferPointer(), pConstants, nbConstants );
|
|
#else
|
|
hr = D3DXFillCubeTextureTX((LPDIRECT3DCUBETEXTURE9) existingTex, pTextureShader );
|
|
#endif
|
|
break;
|
|
|
|
case D3DRTYPE_VOLUMETEXTURE:
|
|
#ifdef _XBOX
|
|
hr = D3DXFillVolumeTextureTX((LPDIRECT3DVOLUMETEXTURE9) existingTex, (DWORD*) pFunction->GetBufferPointer(), pConstants, nbConstants );
|
|
#else
|
|
hr = D3DXFillVolumeTextureTX((LPDIRECT3DVOLUMETEXTURE9) existingTex, pTextureShader );
|
|
#endif
|
|
break;
|
|
|
|
default:
|
|
#ifdef _XBOX
|
|
hr = D3DXFillTextureTX((LPDIRECT3DTEXTURE9) existingTex, (DWORD*) pFunction->GetBufferPointer(), pConstants, nbConstants );
|
|
#else
|
|
hr = D3DXFillTextureTX((LPDIRECT3DTEXTURE9) existingTex, pTextureShader );
|
|
#endif
|
|
break;
|
|
}
|
|
} else
|
|
//--- Not Using Existing Texture
|
|
{
|
|
if( annotFormat.Length() ){
|
|
fmt = StringToD3DFormat( annotFormat.CStr() );
|
|
}
|
|
#ifdef _XBOX
|
|
if(ppConstantTable)
|
|
ppConstantTable->SetDefaults(dev9);
|
|
#else
|
|
pTextureShader->SetDefaults();
|
|
#endif
|
|
|
|
if( annotDim.x != 0 ) annotWidth = (UINT)annotDim.x;
|
|
if( annotDim.y != 0 ) annotHeight = (UINT)annotDim.y;
|
|
if( annotDim.z != 0 ) annotDepth = (UINT)annotDim.z;
|
|
|
|
if( annotWidth == D3DX_DEFAULT ) annotWidth = 64;
|
|
if( annotHeight == D3DX_DEFAULT ) annotHeight = 64;
|
|
if( annotDepth == D3DX_DEFAULT ) annotDepth = 64;
|
|
|
|
|
|
int annotStrValueIndex;
|
|
|
|
//--- There's a Texture Type Specified
|
|
if( annotTextureType.Length() )
|
|
{
|
|
annotStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotTextureType );
|
|
} else
|
|
//--- There's no Texture Type Specified
|
|
{
|
|
annotStrValueIndex = AnnotStr_2d;
|
|
}
|
|
|
|
switch( annotStrValueIndex ){
|
|
|
|
case AnnotStr_Volume:
|
|
case AnnotStr_3d:
|
|
{
|
|
LPDIRECT3DVOLUMETEXTURE9 pVolumeTex = NULL;
|
|
if( SUCCEEDED( hr = D3DXCreateVolumeTexture( dev9,
|
|
annotWidth, annotHeight, annotDepth, annotMipLevels, 0, fmt,
|
|
D3DPOOL_MANAGED, &pVolumeTex) ) )
|
|
{
|
|
#ifdef _XBOX
|
|
if( SUCCEEDED( hr = D3DXFillVolumeTextureTX( pVolumeTex,(DWORD*) pFunction->GetBufferPointer(), pConstants, nbConstants ) ) )
|
|
#else
|
|
if( SUCCEEDED( hr = D3DXFillVolumeTextureTX( pVolumeTex, pTextureShader ) ) )
|
|
#endif
|
|
pTex = pVolumeTex;
|
|
}
|
|
} break;
|
|
|
|
case AnnotStr_Cube:
|
|
{
|
|
LPDIRECT3DCUBETEXTURE9 pCubeTex = NULL;
|
|
if( SUCCEEDED( hr = D3DXCreateCubeTexture( dev9,
|
|
annotWidth, annotMipLevels, 0, fmt, D3DPOOL_MANAGED, &pCubeTex) ) )
|
|
{
|
|
#ifdef _XBOX
|
|
if( SUCCEEDED( hr = D3DXFillCubeTextureTX( pCubeTex, (DWORD*) pFunction->GetBufferPointer(), pConstants, nbConstants ) ) )
|
|
#else
|
|
if( SUCCEEDED( hr = D3DXFillCubeTextureTX( pCubeTex, pTextureShader ) ) )
|
|
#endif
|
|
pTex = pCubeTex;
|
|
}
|
|
} break;
|
|
case AnnotStr_2d:
|
|
{
|
|
LPDIRECT3DTEXTURE9 p2DTex = NULL;
|
|
if( SUCCEEDED( hr = D3DXCreateTexture( dev9, annotWidth, annotHeight,
|
|
annotMipLevels, 0, fmt, D3DPOOL_MANAGED, &p2DTex) ) )
|
|
{
|
|
#ifdef _XBOX
|
|
if( SUCCEEDED( hr = D3DXFillTextureTX( p2DTex, (DWORD*) pFunction->GetBufferPointer(), pConstants, nbConstants ) ) )
|
|
#else
|
|
if( SUCCEEDED( hr = D3DXFillTextureTX( p2DTex, pTextureShader ) ) )
|
|
#endif
|
|
pTex = p2DTex;
|
|
}
|
|
} break;
|
|
}
|
|
|
|
iMII.fx->SetTexture( iMII.h, pTex );
|
|
SAFERELEASE(pTex);
|
|
#ifndef _XBOX
|
|
SAFERELEASE(pTextureShader);
|
|
#endif
|
|
SAFERELEASE(ppConstantTable);
|
|
if (instExistingTexture) delete instExistingTexture;
|
|
return NULL;
|
|
}
|
|
}
|
|
SAFERELEASE(pFunction);
|
|
}
|
|
if( pBufferErrors != NULL )
|
|
{
|
|
strErrors = (CHAR*)pBufferErrors->GetBufferPointer();
|
|
iMII.sdm->GetShaderManager()->m_Output.PushBack( strErrors );
|
|
pBufferErrors->Release();
|
|
}
|
|
}
|
|
//--- Do not exposed texture if an existing texture has been found
|
|
///// return NULL has not be called just after existing texture has been found because
|
|
///// this texture can be filled after that by a texture shader.
|
|
if(instExistingTexture){
|
|
return instExistingTexture;
|
|
}
|
|
#endif
|
|
//--- Otherwise, simply Expose a Texture Parameter Meaning
|
|
ExposedTextureParamMeaning* inst = new ExposedTextureParamMeaning;
|
|
inst->m_Guid = CKPGUID_TEXTURE;
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
ExposedTextureParamMeaning::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
CKTexture* tex = (CKTexture*)iMPI.param->GetValueObject( FALSE );
|
|
SetValueFromCKTexture( iMPI, tex );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Ambient
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Ambient : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Ambient );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if(iMPI.mat)
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxColor), &iMPI.mat->GetAmbient() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Emissive
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Emissive : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Emissive );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if(iMPI.mat)
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxColor), &iMPI.mat->GetEmissive() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Diffuse
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Diffuse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Diffuse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if(iMPI.mat)
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxColor), &iMPI.mat->GetDiffuse() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Specular
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Specular : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Specular );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if(iMPI.mat)
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxColor), &iMPI.mat->GetSpecular() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Power
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Power : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Power );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
float power = iMPI.mat->GetPower();
|
|
SetValueByCastingVectorParam( iMPI, sizeof(float), &power );
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Alpha test enabled
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_AlphaTestEnable : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_AlphaTestEnable );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
iMPI.fx->SetBool(m_D3DHandle, iMPI.mat->AlphaTestEnabled());
|
|
}
|
|
};
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Alpha blend enabled
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_AlphaBlendEnable : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_AlphaBlendEnable );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
iMPI.fx->SetBool(m_D3DHandle, iMPI.mat->AlphaBlendEnabled());
|
|
}
|
|
};
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Alpha func
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_AlphaFunc : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_AlphaFunc );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
iMPI.fx->SetInt(m_D3DHandle, (INT) iMPI.mat->GetAlphaFunc());
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Alpha ref value
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_AlphaRef : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_AlphaRef );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
iMPI.fx->SetFloat(m_D3DHandle, iMPI.mat->GetAlphaRef() * (1.f / 255.f));
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Texture
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Texture : public ParamMeaning {
|
|
public:
|
|
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
ParamMeaning_Texture* inst = new ParamMeaning_Texture;
|
|
inst->m_ChannelIndex = iMII.semIndex - Sem_Texture0;
|
|
if( iMII.semIndex <= Sem_Texture ) inst->m_ChannelIndex = -1;
|
|
else if( iMII.semIndex >= Sem_Texture7 ) inst->m_ChannelIndex = 7;
|
|
return inst;
|
|
}
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
CKTexture* tex = NULL;
|
|
|
|
//--- : TEXURE
|
|
if( m_ChannelIndex == -1 ){
|
|
if( iMPI.mat ) tex = iMPI.mat->GetTexture();
|
|
}
|
|
//--- : TEXURE0, TEXURE1, ... or TEXTURE7 (Channels)
|
|
else {
|
|
|
|
//--- Real Channels of a Mesh
|
|
if( iMPI.ent ){
|
|
CKMesh* mesh = iMPI.ent->GetCurrentMesh();
|
|
if( mesh ){
|
|
CKMaterial* channelMat = mesh->GetChannelMaterial( m_ChannelIndex );
|
|
if( channelMat ) tex = channelMat->GetTexture();
|
|
}
|
|
}
|
|
//--- Pseudo-Channels (ex: Combine RTViews BB)
|
|
else {
|
|
tex = iMPI.rc->m_ShaderManager->m_PseudoChannelTexture[ m_ChannelIndex ];
|
|
}
|
|
}
|
|
|
|
//--- Assign Texture
|
|
SetValueFromCKTexture( iMPI, tex );
|
|
}
|
|
|
|
int m_ChannelIndex;
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingBoxMax
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BBoxMax : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BBoxMax );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxVector boxMax(0,0,0);
|
|
if( iMPI.ent ) boxMax = iMPI.ent->GetBoundingBox( TRUE ).Max;
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &boxMax );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingBoxMin
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BBoxMin : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BBoxMin );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxVector boxMin(0,0,0);
|
|
if( iMPI.ent ) boxMin = iMPI.ent->GetBoundingBox( TRUE ).Min;
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &boxMin );
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingBoxSize
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BBoxSize : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BBoxSize );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxVector boxSize(0,0,0);
|
|
if( iMPI.ent )
|
|
boxSize = iMPI.ent->GetBoundingBox( TRUE ).GetSize();
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &boxSize );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingBoxCenter
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BBoxCenter : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BBoxCenter );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxVector boxCenter(0,0,0);
|
|
if( iMPI.ent )
|
|
boxCenter = iMPI.ent->GetBoundingBox( TRUE ).GetCenter();
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &boxCenter );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingSphereRadius
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BoundingSphereRadius : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BoundingSphereRadius );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
float sphereRadius = 0;
|
|
if( iMPI.ent ){
|
|
CKMesh* mesh = iMPI.ent->GetCurrentMesh();
|
|
if( mesh ){
|
|
sphereRadius = mesh->GetRadius();
|
|
}
|
|
}
|
|
SetValueByCastingVectorParam( iMPI, sizeof(float), &sphereRadius );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingSphereMax
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BoundingSphereMax : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BoundingSphereMax );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
float sphereMax = 0;
|
|
if( iMPI.ent )
|
|
sphereMax = iMPI.ent->GetBoundingBox( TRUE ).GetHalfSize().Magnitude();
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &sphereMax );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BoundingSphereMin
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BoundingSphereMin : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BoundingSphereMin );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
float sphereMin = 0;
|
|
if( iMPI.ent )
|
|
sphereMin = Min(iMPI.ent->GetBoundingBox( TRUE ).GetHalfSize());
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &sphereMin );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// EyePos
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_EyePos : public ParamMeaning {
|
|
public:
|
|
ParamMeaning_EyePos() : m_ReferentialEnum( AnnotStr_Unknown ){}
|
|
static Meaning* MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
//--- Here are the Annotations we are interested in
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
XString annotSpace;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Space, AnnotType_String, &annotSpace );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- Space = ?
|
|
int annotSpaceStrValueIndex = AnnotStr_Unknown;
|
|
if( annotSpace.Length() ){
|
|
annotSpaceStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotSpace );
|
|
}
|
|
|
|
ParamMeaning_EyePos* inst = new ParamMeaning_EyePos;
|
|
inst->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
#else
|
|
ParamMeaning_EyePos* inst = new ParamMeaning_EyePos;
|
|
#endif
|
|
return inst;
|
|
}
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
CK3dEntity* referential = (m_ReferentialEnum == AnnotStr_Local)? iMPI.ent:NULL;
|
|
VxVector cameraPos = iMPI.rc->GetViewpoint()->GetWorldMatrix()[3];
|
|
if( referential ) referential->InverseTransform( &cameraPos, &cameraPos );
|
|
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &cameraPos );
|
|
}
|
|
int m_ReferentialEnum;
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// World
|
|
// WorldTranspose
|
|
// WorldInverse
|
|
// WorldInverseTranspose
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_World : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_World );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByMatrix(iMPI,iMPI.rc->GetWorldTransformationMatrix());
|
|
}
|
|
};
|
|
|
|
class ParamMeaning_WorldTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByTranposingMatrix( iMPI, iMPI.rc->GetWorldTransformationMatrix() );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldInverse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldInverse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByInversingMatrix( iMPI, iMPI.rc->GetWorldTransformationMatrix() );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldInverseTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldInverseTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByInverseTransposingMatrix( iMPI, iMPI.rc->GetWorldTransformationMatrix() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// View
|
|
// ViewTranspose
|
|
// ViewInverse
|
|
// ViewInverseTranspose
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_View : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_View );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByMatrix(iMPI,iMPI.rc->GetViewTransformationMatrix());
|
|
}
|
|
};
|
|
class ParamMeaning_ViewTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByTranposingMatrix( iMPI, iMPI.rc->GetViewTransformationMatrix() );
|
|
}
|
|
};
|
|
class ParamMeaning_ViewInverse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewInverse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByInversingMatrix( iMPI, iMPI.rc->GetViewTransformationMatrix() );
|
|
}
|
|
};
|
|
class ParamMeaning_ViewInverseTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewInverseTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByInverseTransposingMatrix( iMPI, iMPI.rc->GetViewTransformationMatrix() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Projection
|
|
// ProjectionTranspose
|
|
// ProjectionInverse
|
|
// ProjectionInverseTranspose
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Projection : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Projection );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByMatrix(iMPI,iMPI.rc->GetProjectionTransformationMatrix());
|
|
}
|
|
};
|
|
class ParamMeaning_ProjectionTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ProjectionTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByTranposingMatrix( iMPI, iMPI.rc->GetProjectionTransformationMatrix() );
|
|
}
|
|
};
|
|
class ParamMeaning_ProjectionInverse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ProjectionInverse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByInversingMatrix44( iMPI, iMPI.rc->GetProjectionTransformationMatrix() );
|
|
}
|
|
};
|
|
class ParamMeaning_ProjectionInverseTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ProjectionInverseTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByInverseTransposingMatrix44( iMPI, iMPI.rc->GetProjectionTransformationMatrix() );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// WorldView
|
|
// WorldViewTranspose
|
|
// WorldViewInverse
|
|
// WorldViewInverseTranspose
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_WorldView : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldView );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByMatrix(iMPI,rstCtx->m_ModelViewMatrix);
|
|
}
|
|
};
|
|
class ParamMeaning_WorldViewTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByTranposingMatrix( iMPI, rstCtx->m_ModelViewMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldViewInverse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewInverse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByInversingMatrix( iMPI, rstCtx->m_ModelViewMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldViewInverseTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewInverseTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByInverseTransposingMatrix( iMPI, rstCtx->m_ModelViewMatrix );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// ViewProjection
|
|
// ViewProjectionTranspose
|
|
// ViewProjectionInverse
|
|
// ViewProjectionInverseTranspose
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_ViewProjection : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewProjection );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxMatrix vpMatrix;
|
|
Vx3DMultiplyMatrix4( vpMatrix, iMPI.rc->GetProjectionTransformationMatrix(), iMPI.rc->GetViewTransformationMatrix() );
|
|
SetValueByMatrix(iMPI,vpMatrix);
|
|
}
|
|
};
|
|
class ParamMeaning_ViewProjectionTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewProjectionTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxMatrix vpMatrix;
|
|
Vx3DMultiplyMatrix4( vpMatrix, iMPI.rc->GetProjectionTransformationMatrix(), iMPI.rc->GetViewTransformationMatrix() );
|
|
SetValueByTranposingMatrix( iMPI, vpMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_ViewProjectionInverse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewProjectionInverse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxMatrix vpMatrix;
|
|
Vx3DMultiplyMatrix4( vpMatrix, iMPI.rc->GetProjectionTransformationMatrix(), iMPI.rc->GetViewTransformationMatrix() );
|
|
SetValueByInversingMatrix44( iMPI, vpMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_ViewProjectionInverseTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewProjectionInverseTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxMatrix vpMatrix;
|
|
Vx3DMultiplyMatrix4( vpMatrix, iMPI.rc->GetProjectionTransformationMatrix(), iMPI.rc->GetViewTransformationMatrix() );
|
|
SetValueByInverseTransposingMatrix44( iMPI, vpMatrix );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// WorldViewProjection
|
|
// WorldViewProjectionTranspose
|
|
// WorldViewProjectionInverse
|
|
// WorldViewProjectionInverseTranspose
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_WorldViewProjection : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewProjection );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByMatrix(iMPI,rstCtx->m_TotalMatrix);
|
|
|
|
}
|
|
};
|
|
class ParamMeaning_WorldViewProjectionTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewProjectionTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByTranposingMatrix( iMPI, rstCtx->m_TotalMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldViewProjectionInverse : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewProjectionInverse );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByInversingMatrix44( iMPI, rstCtx->m_TotalMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldViewProjectionInverseTranspose : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldViewProjectionInverseTranspose );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
SetValueByInverseTransposingMatrix44( iMPI, rstCtx->m_TotalMatrix );
|
|
}
|
|
};
|
|
class ParamMeaning_WorldShadowViewProj : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_WorldShadowViewProj );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
CKRasterizerContext* rstCtx = iMPI.rc->GetRasterizerContext();
|
|
CKMaterialShader *shMat = iMPI.matShader;
|
|
if (shMat)
|
|
{
|
|
VxMatrix mat;
|
|
Vx3DMultiplyMatrix4(mat, shMat->m_ShadowViewProj, rstCtx->m_WorldMatrix);
|
|
SetValueByMatrix( iMPI, mat);
|
|
}
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// ObjectPos
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_ObjectPos : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ObjectPos );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxVector), &iMPI.rc->GetWorldTransformationMatrix()[3] );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Time
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Time : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Time );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKTimeManager* tm = iMPI.rc->GetCKContext()->GetTimeManager();
|
|
const float time = tm->GetAbsoluteTime()*0.001f;
|
|
#if defined(_XBOX) && (_XBOX_VER<200)
|
|
D3DXVECTOR4 v;
|
|
v.x = time;
|
|
v.y = sinf(time);
|
|
v.z = cosf(time);
|
|
v.w = 1.0f;
|
|
iMPI.fx->SetVector( m_D3DHandle, &v);
|
|
#else
|
|
iMPI.fx->SetFloat( m_D3DHandle, time);
|
|
#endif
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// ElapsedTime
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_ElapsedTime : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ElapsedTime );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKTimeManager* tm = iMPI.rc->GetCKContext()->GetTimeManager();
|
|
float elapsedTime = tm->GetLastDeltaTime()*0.001f;
|
|
iMPI.fx->SetFloat( m_D3DHandle, elapsedTime );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// LastTime
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_LastTime : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_LastTime );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
CKTimeManager* tm = iMPI.rc->GetCKContext()->GetTimeManager();
|
|
float lastTime = (tm->GetAbsoluteTime()-tm->GetLastDeltaTime())*0.001f;
|
|
iMPI.fx->SetFloat( m_D3DHandle, lastTime);
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// ViewportPixelSize
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_ViewportPixelSize : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ViewportPixelSize );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxRect rect;
|
|
iMPI.rc->GetViewRect( rect );
|
|
SetValueByCastingVectorParam( iMPI, sizeof(Vx2DVector), &rect.m_BottomRight );
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Random
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_Random : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Random );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
float randomValue = (float)rand()/(float)RAND_MAX;
|
|
iMPI.fx->SetFloat( m_D3DHandle, randomValue);
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// BonesPerVertex
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_BonesPerVertex : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BonesPerVertex );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if( !iMPI.ent ) return;
|
|
if( !(iMPI.ent->GetFlags()&CK_3DENTITY_HWSKINING) ) return;
|
|
CKSkin* sk = iMPI.ent->GetSkin();
|
|
if( !sk ) return;
|
|
int bonesPerVertex = sk->GetMaxBonesPerVertex();
|
|
iMPI.fx->SetInt( m_D3DHandle, bonesPerVertex);
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// Bones
|
|
//--------------------------------------------------------------------------------
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
class ParamMeaning_Bones : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_Bones );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if( !iMPI.ent ) return;
|
|
if( !(iMPI.ent->GetFlags()&CK_3DENTITY_HWSKINING) ) return;
|
|
CKSkin* sk = iMPI.ent->GetSkin();
|
|
if( !sk )
|
|
return;
|
|
iMPI.fx->SetMatrixArray( m_D3DHandle, (const D3DXMATRIX*)sk->GetTransformedBonesArray(), (sk->GetBoneCount()+1) );
|
|
}
|
|
};
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// TBones
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_TBones : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_TBones );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
if( !iMPI.ent ) return;
|
|
if( !(iMPI.ent->GetFlags()&CK_3DENTITY_HWSKINING) ) return;
|
|
CKSkin* sk = iMPI.ent->GetSkin();
|
|
if( !sk )
|
|
return;
|
|
iMPI.fx->SetMatrixTransposeArray( m_D3DHandle, (const D3DXMATRIX*)sk->GetTransformedBonesArray(), (sk->GetBoneCount()+1) );
|
|
}
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// RBones
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_RBones : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_RBones );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
#if defined(_XBOX) && (_XBOX_VER<200)
|
|
gRestoreConstantMode = TRUE;
|
|
D3DDevice::SetShaderConstantMode(D3DSCM_192CONSTANTS);
|
|
#endif
|
|
if( !iMPI.ent )
|
|
return;
|
|
|
|
if( !(iMPI.ent->GetFlags()&CK_3DENTITY_HWSKINING) )
|
|
return;
|
|
|
|
CKSkin* sk = iMPI.ent->GetSkin();
|
|
if( !sk ) return;
|
|
const D3DXMATRIX* buffer = (const D3DXMATRIX*)sk->GetTransformedBonesArray();
|
|
int index = 0;
|
|
iMPI.fx->GetInt( m_D3DHandle, &index );
|
|
|
|
VxDirectXData* dx = iMPI.rc->GetDirectXInfo();
|
|
DXDEVICE* dev = (DXDEVICE*) dx->D3DDevice;
|
|
D3DXMATRIX matrix;
|
|
const DWORD boneCount = sk->GetBoneCount();
|
|
for( DWORD i=0 ; i<boneCount ; i++ ){
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
dev->SetVertexShaderConstantF( index+3*i, buffer[i], 3 );
|
|
#else
|
|
D3DXMatrixTranspose( &matrix, (const D3DXMATRIX *)(((BYTE*)buffer)+i*sizeof(VxMatrix)) );
|
|
dev->SetVertexShaderConstantF( index+3*i, matrix, 3 );
|
|
#endif
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// RTBones
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_RTBones : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_RTBones );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
#if defined(_XBOX) && _XBOX_VER<200
|
|
gRestoreConstantMode = TRUE;
|
|
D3DDevice::SetShaderConstantMode(D3DSCM_192CONSTANTS);
|
|
#endif
|
|
|
|
if( !iMPI.ent )
|
|
return;
|
|
|
|
if( !(iMPI.ent->GetFlags()&CK_3DENTITY_HWSKINING) )
|
|
return;
|
|
|
|
CKSkin* sk = iMPI.ent->GetSkin();
|
|
if( !sk ) return;
|
|
const D3DXMATRIX* buffer = (const D3DXMATRIX*)sk->GetTransformedBonesArray();
|
|
int index = 0;
|
|
iMPI.fx->GetInt( m_D3DHandle, &index );
|
|
|
|
VxDirectXData* dx = iMPI.rc->GetDirectXInfo();
|
|
DXDEVICE* dev = (DXDEVICE*) dx->D3DDevice;
|
|
D3DXMATRIX matrix;
|
|
const DWORD boneCount = sk->GetBoneCount();
|
|
for( DWORD i=0 ; i<boneCount ; i++ ){
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
dev->SetVertexShaderConstantF( index+3*i, buffer[i], 3 );
|
|
#else
|
|
D3DXMatrixTranspose( &matrix, (const D3DXMATRIX *)(((BYTE*)buffer)+i*sizeof(VxMatrix)) );
|
|
dev->SetVertexShaderConstantF( index+3*i, matrix, 3 );
|
|
#endif
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
#if defined(_XBOX) && _XBOX_VER<200
|
|
class ParamMeaning_BonesIndexConstant : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_BonesIndexConstant );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
DWORD idx = 0;
|
|
iMPI.fx->GetDword(m_D3DHandle,&idx);
|
|
XGVECTOR4 v(255.002f,0.0f,0.0f,0.0f);
|
|
D3DDevice::SetVertexShaderConstantFast(idx,&v,1);
|
|
}
|
|
};
|
|
#endif
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// PassCount
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_PassCount : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_PassCount );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
#ifdef XBOX1
|
|
iMPI.fx->SetFloat( m_D3DHandle, (float) iMPI.rc->m_ShaderManager->m_CurrentPassCount);
|
|
#else
|
|
iMPI.fx->SetInt( m_D3DHandle, iMPI.rc->m_ShaderManager->m_CurrentPassCount);
|
|
#endif
|
|
}
|
|
};
|
|
//--------------------------------------------------------------------------------
|
|
// PassIndex
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_PassIndex : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_PassIndex );
|
|
|
|
void PostIntantiationCallBack( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
ParamMeaning::PostIntantiationCallBack( iMII );
|
|
m_ExpositionType = ExpositionType_AutomaticPerPass;
|
|
}
|
|
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
#ifdef XBOX1
|
|
iMPI.fx->SetFloat( m_D3DHandle, (float) iMPI.rc->m_ShaderManager->m_CurrentPassIndex);
|
|
#else
|
|
iMPI.fx->SetInt( m_D3DHandle, iMPI.rc->m_ShaderManager->m_CurrentPassIndex);
|
|
#endif
|
|
}
|
|
};
|
|
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// LightCount
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_LightCount : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_LightCount );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
|
|
Manager* sdm = iMPI.shader->GetManager();
|
|
CKShaderManager* shaderMan = sdm->GetShaderManager();
|
|
|
|
//--- Retrieve lights array
|
|
XArray< CKShaderManager::NearestLight >& nearestLights =
|
|
*shaderMan->GetNearestLights( iMPI.ent, INT_MAX, false );
|
|
int lightCount = ( &nearestLights )? nearestLights.Size():0;
|
|
|
|
iMPI.fx->SetInt( m_D3DHandle, lightCount );
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Activity NearestLight
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_ActivityNearestLight : public ParamMeaning_NearestLight {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ActivityNearestLight );
|
|
|
|
//-----------------------------------------------------------------------------
|
|
virtual int GiveStride( const MeaningProcessingInfo& iMPI ){
|
|
return sizeof(DWORD);
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveDefaultValues( const MeaningProcessingInfo& iMPI,
|
|
void* iTempBuffer, int iFinalArrayCount ){
|
|
|
|
//--- By Default Fill Temp Array With Default Activity
|
|
for( int a=0 ; a<iFinalArrayCount ; ++a ){
|
|
((DWORD*)iTempBuffer)[a] = m_DefaultActivity;
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveValue( const MeaningProcessingInfo& iMPI,
|
|
CKLight& iLight, void* iValueBuf ){
|
|
*(DWORD*)iValueBuf = 0;
|
|
if( iLight.IsVisible() && iLight.GetActivity() ){
|
|
*(DWORD*)iValueBuf = 1;
|
|
}
|
|
}
|
|
DWORD m_DefaultActivity;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Position NearestLight
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_PositionNearestLight : public ParamMeaning_NearestLight {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_PositionNearestLight );
|
|
ParamMeaning_PositionNearestLight() :
|
|
m_ReferentialEnum( AnnotStr_Unknown ),m_Referential( NULL ),m_DirectionalLightScaleHack(0){}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
virtual int GiveStride( const MeaningProcessingInfo& iMPI ){
|
|
return sizeof(VxVector);
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveDefaultValues( const MeaningProcessingInfo& iMPI,
|
|
void* iTempBuffer, int iFinalArrayCount ){
|
|
|
|
//--- Get referential in which to retrieve light information
|
|
m_Referential = (m_ReferentialEnum == AnnotStr_Local)? iMPI.ent:NULL;
|
|
|
|
//--- By Default Fill Temp Array With Current Camera Information
|
|
VxVector cameraPos = iMPI.rc->GetViewpoint()->GetWorldMatrix()[3];
|
|
if( m_Referential ) m_Referential->InverseTransform( &cameraPos, &cameraPos );
|
|
for( int a=0 ; a<iFinalArrayCount ; ++a ){
|
|
((VxVector*)iTempBuffer)[a] = cameraPos;
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveValue( const MeaningProcessingInfo& iMPI,
|
|
CKLight& iLight, void* iValueBuf ){
|
|
iLight.GetPosition( (VxVector*)iValueBuf, m_Referential );
|
|
if( iLight.GetType() == VX_LIGHTDIREC && m_DirectionalLightScaleHack < 0)
|
|
*((VxVector*)iValueBuf) = iLight.GetWorldMatrix()[2] * m_DirectionalLightScaleHack;
|
|
}
|
|
float m_DirectionalLightScaleHack;
|
|
int m_ReferentialEnum;
|
|
CK3dEntity* m_Referential;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Matrix NearestLight
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_MatrixNearestLight : public ParamMeaning_NearestLight {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_MatrixNearestLight );
|
|
ParamMeaning_MatrixNearestLight() :
|
|
m_ReferentialEnum( AnnotStr_Unknown ),m_Referential( NULL ){}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
virtual int GiveStride( const MeaningProcessingInfo& iMPI ){
|
|
return sizeof(VxMatrix);
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveDefaultValues( const MeaningProcessingInfo& iMPI,
|
|
void* iTempBuffer, int iFinalArrayCount ){
|
|
|
|
//--- Get referential in which to retrieve light information
|
|
m_Referential = (m_ReferentialEnum == AnnotStr_Local)? iMPI.ent:NULL;
|
|
|
|
//--- By Default Fill Temp Array With Current Camera Information
|
|
VxMatrix cameraMat;
|
|
if( m_Referential ){
|
|
Vx3DMultiplyMatrix( cameraMat, m_Referential->GetInverseWorldMatrix(), iMPI.rc->GetViewpoint()->GetWorldMatrix() );
|
|
} else {
|
|
cameraMat = iMPI.rc->GetViewpoint()->GetWorldMatrix();
|
|
}
|
|
for( int a=0 ; a<iFinalArrayCount ; ++a ){
|
|
((VxMatrix*)iTempBuffer)[a] = cameraMat;
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveValue( const MeaningProcessingInfo& iMPI,
|
|
CKLight& iLight, void* iValueBuf ){
|
|
if( m_Referential ){
|
|
Vx3DMultiplyMatrix( *(VxMatrix*)iValueBuf, m_Referential->GetInverseWorldMatrix(), iLight.GetWorldMatrix() );
|
|
} else {
|
|
*(VxMatrix*)iValueBuf = iLight.GetWorldMatrix();
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void AssignValues( const MeaningProcessingInfo& iMPI,
|
|
void* iValueBuf, const int iElemCount )
|
|
{
|
|
if (iElemCount > 1)
|
|
{
|
|
iMPI.fx->SetMatrixArray( m_D3DHandle, (D3DXMATRIX*)iValueBuf, iElemCount );
|
|
}
|
|
else
|
|
{
|
|
iMPI.fx->SetMatrix( m_D3DHandle, (D3DXMATRIX*)iValueBuf);
|
|
}
|
|
}
|
|
|
|
int m_ReferentialEnum;
|
|
CK3dEntity* m_Referential;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Color NearestLight
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_ColorNearestLight : public ParamMeaning_NearestLight {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_ColorNearestLight );
|
|
|
|
//-----------------------------------------------------------------------------
|
|
virtual int GiveStride( const MeaningProcessingInfo& iMPI ){
|
|
return sizeof(VxColor);
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveDefaultValues( const MeaningProcessingInfo& iMPI,
|
|
void* iTempBuffer, int iFinalArrayCount ){
|
|
for( int a=0 ; a<iFinalArrayCount ; ++a ){
|
|
((VxColor*)iTempBuffer)[a] = m_DefaultColor;
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveValue( const MeaningProcessingInfo& iMPI,
|
|
CKLight& iLight, void* iValueBuf ){
|
|
*(VxColor*)iValueBuf = iLight.GetColor();
|
|
}
|
|
VxColor m_DefaultColor;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Range NearestLight
|
|
//--------------------------------------------------------------------------------
|
|
class ParamMeaning_RangeNearestLight : public ParamMeaning_NearestLight {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_RangeNearestLight );
|
|
|
|
//-----------------------------------------------------------------------------
|
|
virtual int GiveStride( const MeaningProcessingInfo& iMPI ){
|
|
return sizeof(float);
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveDefaultValues( const MeaningProcessingInfo& iMPI,
|
|
void* iTempBuffer, int iFinalArrayCount ){
|
|
for( int a=0 ; a<iFinalArrayCount ; ++a ){
|
|
((float*)iTempBuffer)[a] = m_DefaultRange;
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
virtual void GiveValue( const MeaningProcessingInfo& iMPI,
|
|
CKLight& iLight, void* iValueBuf ){
|
|
*(VxColor*)iValueBuf = iLight.GetRange();
|
|
}
|
|
float m_DefaultRange;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// NearestLight (Switcher to derive from)
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------------
|
|
Meaning*
|
|
ParamMeaning_NearestLight::MeaningInstantiator( const MeaningInstantiatorInfo& iMII )
|
|
{
|
|
//--- Here are the Annotations we are interested in
|
|
int nearestIndex = 0;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Nearest, AnnotType_Int, &nearestIndex );
|
|
|
|
bool annotSort = true;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Sort, AnnotType_Bool, &annotSort );
|
|
|
|
float annotDefaultRange = 200.0f;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Default, AnnotType_Float, &annotDefaultRange );
|
|
|
|
VxColor annotDefaultColor(0,0,0,1);
|
|
iMII.sdm->ExpectingAnnotation( Annot_Default, AnnotType_Vector4, &annotDefaultColor );
|
|
|
|
bool annotDefaultActivity = false;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Default, AnnotType_Bool, &annotDefaultActivity );
|
|
|
|
XString annotSpace;
|
|
iMII.sdm->ExpectingAnnotation( Annot_Space, AnnotType_String, &annotSpace );
|
|
|
|
bool annotDirectionalHack = false;
|
|
iMII.sdm->ExpectingAnnotation( Annot_DirectionalLightHack, AnnotType_Bool, &annotDirectionalHack );
|
|
|
|
float annotDirectionalScaleHack = 1.f;
|
|
iMII.sdm->ExpectingAnnotation( Annot_DirectionalLightHack, AnnotType_Float, &annotDirectionalScaleHack );
|
|
|
|
//--- Parse Annotations to find expected ones
|
|
iMII.sdm->ParseExpectedAnnotations( iMII.fx, iMII.h, iMII.paramDesc.Annotations );
|
|
|
|
//--- Space = ?
|
|
int annotSpaceStrValueIndex = AnnotStr_Unknown;
|
|
if( annotSpace.Length() ){
|
|
annotSpaceStrValueIndex = iMII.sdm->GetAnnotStrValueIndexFromString( annotSpace );
|
|
}
|
|
//--- Depending on the Parameter Type, switch to the correct Meaning
|
|
const D3DXPARAMETER_DESC& desc = iMII.paramDesc;
|
|
int lightArraySize = 1;
|
|
ParamMeaning_NearestLight* inst = NULL;
|
|
|
|
//--- We Only Deal With FLOAT, or BOOL (see at bottom)
|
|
if( desc.Type == D3DXPT_FLOAT ){
|
|
|
|
//--- Set Wanted Light Array Size if more than 1 Element
|
|
if( desc.Elements > 1){
|
|
lightArraySize = desc.Elements;
|
|
nearestIndex = 0;
|
|
}
|
|
switch( desc.Class )
|
|
{
|
|
//--- float
|
|
case D3DXPC_SCALAR:
|
|
inst = (ParamMeaning_NearestLight*)Instantiate_Meaning( ParamMeaning_RangeNearestLight, iMII );
|
|
((ParamMeaning_RangeNearestLight*)inst)->m_DefaultRange = annotDefaultRange;
|
|
break;
|
|
|
|
//--- float4x4
|
|
case D3DXPC_MATRIX_ROWS:
|
|
inst = (ParamMeaning_NearestLight*)Instantiate_Meaning( ParamMeaning_MatrixNearestLight, iMII );
|
|
((ParamMeaning_MatrixNearestLight*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
break;
|
|
|
|
case D3DXPC_VECTOR:
|
|
{
|
|
switch( desc.Columns )
|
|
{
|
|
//--- float
|
|
case 1:
|
|
inst = (ParamMeaning_NearestLight*)Instantiate_Meaning( ParamMeaning_RangeNearestLight, iMII );
|
|
((ParamMeaning_RangeNearestLight*)inst)->m_DefaultRange = annotDefaultRange;
|
|
break;
|
|
|
|
//--- float4
|
|
case 4:
|
|
inst = (ParamMeaning_NearestLight*)Instantiate_Meaning( ParamMeaning_ColorNearestLight, iMII );
|
|
((ParamMeaning_ColorNearestLight*)inst)->m_DefaultColor = annotDefaultColor;
|
|
break;
|
|
|
|
//--- float3
|
|
default:
|
|
inst = (ParamMeaning_NearestLight*)Instantiate_Meaning( ParamMeaning_PositionNearestLight, iMII );
|
|
((ParamMeaning_PositionNearestLight*)inst)->m_ReferentialEnum = annotSpaceStrValueIndex;
|
|
if ( annotDirectionalHack )
|
|
{
|
|
if (annotDirectionalScaleHack < 1.f)
|
|
annotDirectionalScaleHack = 1.f;
|
|
((ParamMeaning_PositionNearestLight*)inst)->m_DirectionalLightScaleHack = -10000000.f * annotDirectionalScaleHack;
|
|
}
|
|
else
|
|
((ParamMeaning_PositionNearestLight*)inst)->m_DirectionalLightScaleHack = 0;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else if( desc.Type == D3DXPT_BOOL ){
|
|
//--- Set Wanted Light Array Size if more than 1 Element
|
|
if( desc.Elements > 1){
|
|
lightArraySize = desc.Elements;
|
|
nearestIndex = 0;
|
|
}
|
|
inst = (ParamMeaning_NearestLight*)Instantiate_Meaning( ParamMeaning_ActivityNearestLight, iMII );
|
|
((ParamMeaning_ActivityNearestLight*)inst)->m_DefaultActivity = annotDefaultActivity? 1:0;
|
|
}
|
|
|
|
if( !inst ) return NULL;
|
|
|
|
inst->m_WantedLightArraySize = lightArraySize;
|
|
inst->m_NearestIndex = nearestIndex;
|
|
inst->m_Sort = annotSort;
|
|
|
|
return inst;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning_NearestLight::ProcessCallBack( const MeaningProcessingInfo& iMPI )
|
|
{
|
|
//--- Prepare final array
|
|
const int stride = GiveStride( iMPI );
|
|
const int finalArrayCount = m_ParamDesc.Bytes / stride;
|
|
VxScratch tempScratch( m_ParamDesc.Bytes );
|
|
void* tempBuffer = tempScratch.Mem();
|
|
|
|
//--- Get Nearest Lights Array and Range
|
|
int minLightIndex, maxLightIndex;
|
|
XArray< CKShaderManager::NearestLight >& nearestLights =
|
|
*_GetLightsArrayRange( iMPI, minLightIndex, maxLightIndex, m_Sort );
|
|
|
|
//--- By Default Fill Temp Array With Default Values
|
|
GiveDefaultValues( iMPI, tempBuffer, finalArrayCount );
|
|
|
|
//--- Fill Temp Array With Interesting Information From Valid Lights
|
|
if( &nearestLights ){
|
|
int nearestLightIndex = minLightIndex;
|
|
BYTE* valuePtr = (BYTE*)tempBuffer;
|
|
for( int a=0 ; a<finalArrayCount ; ++a, ++nearestLightIndex, valuePtr += stride ){
|
|
|
|
//--- Break If we try to reach a light index greater than valid lights
|
|
if( nearestLightIndex > maxLightIndex ) break;
|
|
|
|
//--- Otherwise Get Information from the light indexed
|
|
CK_ID lightID = nearestLights[nearestLightIndex].lightID;
|
|
CKLight* light = (CKLight*)iMPI.rc->GetCKContext()->GetObject( lightID );
|
|
if( !light ) continue;
|
|
|
|
GiveValue( iMPI, *light, valuePtr );
|
|
}
|
|
}
|
|
//--- Put Relevant Information in the Final Buffer
|
|
AssignValues( iMPI, tempBuffer, finalArrayCount );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
ParamMeaning_NearestLight::AssignValues( const MeaningProcessingInfo& iMPI, void* iValueBuf, const int iElemCount )
|
|
{
|
|
iMPI.fx->SetValue( m_D3DHandle, iValueBuf, m_ParamDesc.Bytes );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Get Lights Array Range
|
|
//
|
|
// Convenient function to retrieve lights array
|
|
// Note: This function is Used by different light meanings
|
|
//
|
|
XArray< CKShaderManager::NearestLight >*
|
|
ParamMeaning_NearestLight::_GetLightsArrayRange( const MeaningProcessingInfo& iMPI,
|
|
int& oMinLightIndex,
|
|
int& oMaxLightIndex,
|
|
bool iSort )
|
|
{
|
|
Manager* sdm = iMPI.shader->GetManager();
|
|
CKShaderManager* shaderMan = sdm->GetShaderManager();
|
|
|
|
//--- Retrieve lights array
|
|
int minLightIndex = m_NearestIndex;
|
|
int maxLightIndex = max( m_WantedLightArraySize-1, m_NearestIndex );
|
|
|
|
XArray< CKShaderManager::NearestLight >& nearestLights =
|
|
*shaderMan->GetNearestLights( iMPI.ent, maxLightIndex+1, iSort );
|
|
if( !&nearestLights ) return NULL;
|
|
|
|
//--- in case there's not enough lights in the scene to fill the destination array,
|
|
///// majorate maxLightIndex to the real count
|
|
maxLightIndex = min( maxLightIndex, nearestLights.Size()-1 );
|
|
if( maxLightIndex < minLightIndex ) return NULL;
|
|
|
|
oMinLightIndex = minLightIndex;
|
|
oMaxLightIndex = maxLightIndex;
|
|
|
|
return &nearestLights;
|
|
}
|
|
#endif
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Global Ambient
|
|
//--------------------------------------------------------------------------------
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
class ParamMeaning_GlobalAmbient : public ParamMeaning {
|
|
public:
|
|
CLASSIC_INSTANTIATOR_DEF_INSIDE( ParamMeaning_GlobalAmbient );
|
|
void ProcessCallBack( const MeaningProcessingInfo& iMPI ){
|
|
VxColor col = iMPI.rc->GetAmbientLight();
|
|
SetValueByCastingVectorParam( iMPI, sizeof(VxColor), &col );
|
|
}
|
|
};
|
|
#endif
|
|
/***************************************************************************
|
|
____ _ _
|
|
/ ___|| |__ __ _ __| | ___ _ __
|
|
\___ \| '_ \ / _` |/ _` |/ _ \ '__|
|
|
___) | | | | (_| | (_| | __/ |
|
|
|____/|_| |_|\__,_|\__,_|\___|_|
|
|
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------------
|
|
Shader::Shader()
|
|
{
|
|
m_SDM = NULL;
|
|
m_DxFX = NULL;
|
|
m_RC = NULL;
|
|
m_Shader = NULL;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Shader::Init( Manager* iShaderManager, ID3DXEffect* iDxFX, CKRenderContext* iRC, CKShader* iShader )
|
|
{
|
|
m_SDM = iShaderManager;
|
|
m_DxFX = iDxFX;
|
|
m_RC = iRC;
|
|
m_Shader = iShader;
|
|
|
|
BuildDescription();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
Shader::~Shader()
|
|
{
|
|
DestroyDescription();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Shader::BuildDescription()
|
|
{
|
|
//--- Make sure everything is cleared before we build the description
|
|
DestroyDescription();
|
|
|
|
D3DXEFFECT_DESC shaderDesc;
|
|
m_DxFX->GetDesc( &shaderDesc );
|
|
|
|
MeaningInstantiatorInfo mii( m_DxFX, NULL, m_SDM, this );
|
|
|
|
//--- Parse all Parameters
|
|
UINT paramIndex;
|
|
for( paramIndex=0 ; paramIndex < shaderDesc.Parameters ; ++paramIndex ){
|
|
|
|
mii.paramIndex = paramIndex;
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
mii.h = paramIndex;
|
|
#else
|
|
mii.h = m_DxFX->GetParameter( NULL, paramIndex );
|
|
#endif
|
|
ParamMeaning* paramMeaning = BuildParamMeaning( mii );
|
|
|
|
if( paramMeaning ){
|
|
|
|
//--- Exposed Params
|
|
if( paramMeaning->m_ExpositionType == ExpositionType_Exposed ){
|
|
|
|
//--- Exposed Param Meanings
|
|
m_ExposedParams.PushBack( (ExposedParamMeaning*)paramMeaning );
|
|
|
|
//--- Store meaning also in a hash to get it by name
|
|
m_ParamMeaningFromName.Insert( FourCC2String(paramMeaning->m_ParamDesc.Name), (ExposedParamMeaning*)paramMeaning );
|
|
|
|
}
|
|
//--- Automatic Params
|
|
else {
|
|
|
|
//--- Automatic Param Meanings Per Pass
|
|
if( paramMeaning->m_ExpositionType == ExpositionType_AutomaticPerPass ){
|
|
m_ParamsPerPass.PushBack( paramMeaning );
|
|
}
|
|
//--- Automatic Param Meanings
|
|
else {
|
|
m_Params.PushBack( paramMeaning );
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
//... TODO: Print Message "Can't find meaning for parameter"
|
|
}
|
|
}
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--- Parse all Functions
|
|
for( UINT fctIndex=0 ; fctIndex < shaderDesc.Functions ; ++fctIndex ){
|
|
|
|
mii.functionIndex = paramIndex;
|
|
mii.h = m_DxFX->GetFunction( fctIndex );
|
|
|
|
FctMeaning* fctMeaning = BuildFctMeaning( mii );
|
|
|
|
if( fctMeaning ){
|
|
|
|
//--- Function Meaning
|
|
m_Functs.PushBack( fctMeaning );
|
|
|
|
//--- Store meaning also in a hash to get it by name
|
|
m_FctMeaningFromName.Insert( fctMeaning->m_FunctionDesc.Name, (FctMeaning*)fctMeaning );
|
|
|
|
} else {
|
|
XASSERT(FALSE);
|
|
//... TODO: Print Message "Can't find meaning for funtion"
|
|
}
|
|
}
|
|
#endif
|
|
|
|
//--- Parse all Techniques
|
|
for( UINT techIndex=0 ; techIndex < shaderDesc.Techniques ; ++techIndex ){
|
|
|
|
mii.techIndex = paramIndex;
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
mii.h = techIndex;
|
|
#else
|
|
D3DXHANDLE techHandle = m_DxFX->GetTechnique( techIndex );
|
|
mii.h = techHandle;
|
|
#endif
|
|
TechMeaning* techMeaning = BuildTechMeaning( mii );
|
|
|
|
if( techMeaning ){
|
|
|
|
//--- Tech Meaning
|
|
m_Techs.PushBack( techMeaning );
|
|
|
|
//--- Store meaning also in a hash to get it by name
|
|
m_TechIndexFromName.Insert(FourCC2String(techMeaning->m_TechDesc.Name), techIndex );
|
|
|
|
} else {
|
|
XASSERT(FALSE);
|
|
//... TODO: Print Message "Can't find meaning for technique"
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Shader::DestroyDescription()
|
|
{
|
|
if( !m_SDM ) return;
|
|
|
|
// m_SDM->m_PreviousTextureParam = NULL;
|
|
|
|
m_ParamMeaningFromName.Clear();
|
|
m_TechIndexFromName.Clear();
|
|
m_FctMeaningFromName.Clear();
|
|
|
|
//--- Parse all Automatic Parameter Meanings
|
|
const int paramCount = m_Params.Size();
|
|
for( int paramIndex=0 ; paramIndex<paramCount ; ++paramIndex ){
|
|
delete m_Params[paramIndex];
|
|
}
|
|
m_Params.Resize(0);
|
|
|
|
//--- Parse all Automatic Per Pass Parameter Meanings
|
|
const int paramPerPassCount = m_ParamsPerPass.Size();
|
|
for( int paramPerPassIndex=0 ; paramPerPassIndex<paramPerPassCount ; ++paramPerPassIndex ){
|
|
delete m_ParamsPerPass[paramPerPassIndex];
|
|
}
|
|
m_ParamsPerPass.Resize(0);
|
|
|
|
//--- Parse all Exposed Parameter Meanings
|
|
const int exposedParamCount = m_ExposedParams.Size();
|
|
for( int exposedParamIndex=0 ; exposedParamIndex<exposedParamCount ; ++exposedParamIndex ){
|
|
delete m_ExposedParams[exposedParamIndex];
|
|
}
|
|
m_ExposedParams.Resize(0);
|
|
|
|
//--- Parse all Function Meanings
|
|
const int fctCount = m_Functs.Size();
|
|
for( int fctIndex=0 ; fctIndex<fctCount ; ++fctIndex ){
|
|
delete m_Functs[fctIndex];
|
|
}
|
|
m_Functs.Resize(0);
|
|
|
|
//--- Parse all Technique Meanings
|
|
const int techCount = m_Techs.Size();
|
|
for( int techIndex=0 ; techIndex<techCount ; ++techIndex ){
|
|
delete m_Techs[techIndex];
|
|
}
|
|
m_Techs.Resize(0);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
ParamMeaning*
|
|
Shader::BuildParamMeaning( MeaningInstantiatorInfo& ioMII )
|
|
{
|
|
MeaningInstantiatorPtr miptr;
|
|
|
|
HRESULT hr = m_DxFX->GetParameterDesc( ioMII.h, &ioMII.paramDesc );
|
|
XASSERT( D3D_OK == hr);
|
|
|
|
//--- ParamMeaning Instantiation is to be found in the correct array
|
|
#if DIRECT3D_VERSION<0x0900
|
|
ioMII.h = ioMII.paramDesc.Name;
|
|
int index = m_SDM->GetSemanticIndexFromFourCC(ioMII.paramDesc.Name);
|
|
if(index!=Sem_Unknown){
|
|
ioMII.semIndex = index;
|
|
miptr = m_SDM->m_MeaningInstantiatorForParamBySemantic[ ioMII.semIndex ];
|
|
} else {
|
|
//--- Otherwise seek it in the Class/Type array
|
|
int typeIndex = ioMII.paramDesc.Type;
|
|
miptr = m_SDM->m_MeaningInstantiatorForParamByType[ typeIndex ];
|
|
}
|
|
#else
|
|
if( ioMII.paramDesc.Semantic ){
|
|
//--- Seek it in the Semantic array (if there's a Semantic)
|
|
XString semanticStr = ioMII.paramDesc.Semantic;
|
|
ioMII.semIndex = m_SDM->GetSemanticIndexFromString( semanticStr );
|
|
miptr = m_SDM->m_MeaningInstantiatorForParamBySemantic[ ioMII.semIndex ];
|
|
} else {
|
|
|
|
//--- Otherwise seek it in the Class/Type array
|
|
int typeIndex = ioMII.paramDesc.Type;
|
|
int classIndex = ioMII.paramDesc.Class;
|
|
miptr = m_SDM->m_MeaningInstantiatorForParamByClassAndType[ classIndex ][ typeIndex ];
|
|
}
|
|
#endif
|
|
//--- Instantiate the Meaning
|
|
return (ParamMeaning*)InstantiateMeaningWithPost( miptr, ioMII );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
FctMeaning*
|
|
Shader::BuildFctMeaning( MeaningInstantiatorInfo& ioMII )
|
|
{
|
|
MeaningInstantiatorPtr miptr;
|
|
|
|
m_DxFX->GetFunctionDesc( ioMII.h, &ioMII.functionDesc );
|
|
|
|
const int fctMeaningInstCount = m_SDM->m_MeaningInstantiatorForFunctions.Size();
|
|
for( int a=0 ; a<fctMeaningInstCount ; ++a ){
|
|
|
|
miptr = m_SDM->m_MeaningInstantiatorForFunctions[a];
|
|
FctMeaning* funcMeaning = (FctMeaning*)InstantiateMeaningWithPost( miptr, ioMII );
|
|
if( funcMeaning ) return funcMeaning;
|
|
}
|
|
return NULL;
|
|
}
|
|
#endif
|
|
//--------------------------------------------------------------------------------
|
|
TechMeaning*
|
|
Shader::BuildTechMeaning( MeaningInstantiatorInfo& ioMII )
|
|
{
|
|
MeaningInstantiatorPtr miptr;
|
|
|
|
m_DxFX->GetTechniqueDesc( ioMII.h, &ioMII.techDesc );
|
|
|
|
const int techMeaningInstCount = m_SDM->m_MeaningInstantiatorForTechniques.Size();
|
|
for( int a=0 ; a<techMeaningInstCount ; ++a ){
|
|
|
|
miptr = m_SDM->m_MeaningInstantiatorForTechniques[a];
|
|
TechMeaning* techMeaning = (TechMeaning*)InstantiateMeaningWithPost( miptr, ioMII );
|
|
|
|
if( techMeaning ) return techMeaning;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
PassMeaning*
|
|
Shader::BuildPassMeaning( MeaningInstantiatorInfo& ioMII )
|
|
{
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
MeaningInstantiatorPtr miptr;
|
|
|
|
ioMII.fx->GetPassDesc( ioMII.h, &ioMII.passDesc );
|
|
|
|
const int passMeaningInstCount = m_SDM->m_MeaningInstantiatorForPasses.Size();
|
|
for( int a=0 ; a<passMeaningInstCount ; ++a ){
|
|
|
|
miptr = m_SDM->m_MeaningInstantiatorForPasses[a];
|
|
PassMeaning* passMeaning = (PassMeaning*)InstantiateMeaningWithPost( miptr, ioMII );
|
|
|
|
if( passMeaning ) return passMeaning;
|
|
}
|
|
#endif
|
|
return NULL;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
Shader::InstantiateMeaning( MeaningInstantiatorPtr iMiptr, const MeaningInstantiatorInfo& iMPI )
|
|
{
|
|
Meaning* meaning = iMiptr( iMPI );
|
|
return meaning;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Meaning*
|
|
Shader::InstantiateMeaningWithPost( MeaningInstantiatorPtr iMiptr, const MeaningInstantiatorInfo& iMPI )
|
|
{
|
|
Meaning* meaning = iMiptr( iMPI );
|
|
if( meaning ){
|
|
meaning->PostIntantiationCallBack( iMPI );
|
|
}
|
|
return meaning;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void
|
|
Shader::ExecuteMeanings( MeaningProcessingInfo& iMPI )
|
|
{
|
|
//--- If there's no m_SDM set, it's certainly the default shader... so don't execute any meaning
|
|
///// Note: there should be any case in which we get there with the default shader.
|
|
if( !m_SDM ) return;
|
|
|
|
//--- Parse all Automatic Parameter Meanings
|
|
const int paramCount = m_Params.Size();
|
|
for( int paramIndex=0 ; paramIndex<paramCount ; ++paramIndex ){
|
|
ParamMeaning* paramMeaning = m_Params[paramIndex];
|
|
paramMeaning->ProcessCallBack( iMPI );
|
|
}
|
|
//--- Parse all Function Meanings
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
const INT fctCount = m_Functs.Size();
|
|
for( int fctIndex=0 ; fctIndex<fctCount ; ++fctIndex ){
|
|
m_Functs[fctIndex]->ProcessCallBack( iMPI );
|
|
}
|
|
//--- Execute Current Technique Meaning
|
|
do {
|
|
|
|
CKMaterial* mat = iMPI.mat;
|
|
if( !mat ) break;
|
|
|
|
CKMaterialShader* mfx = iMPI.matShader;
|
|
if( !mfx ) break;
|
|
|
|
int techIndex = mfx->m_TechIndex;
|
|
if( techIndex == -1 ) break;
|
|
// ro : pour eviter plantage : a laisser
|
|
// car appel de function a suivre
|
|
if( techIndex >= m_Techs.Size() ) {
|
|
break;
|
|
}
|
|
|
|
m_Techs[techIndex]->ProcessCallBack( iMPI );
|
|
|
|
} while(0);
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Shader::ExecutePerPassMeanings( MeaningProcessingInfo& iMPI )
|
|
{
|
|
//--- If there's no m_SDM set, it's certainly the default shader... so don't execute any meaning
|
|
///// Note: there should be any case in which we get there with the default shader.
|
|
if( !m_SDM ) return;
|
|
|
|
//--- Parse all Automatic Parameter Per Pass Meanings
|
|
const int paramCount = m_ParamsPerPass.Size();
|
|
for( int paramIndex=0 ; paramIndex<paramCount ; ++paramIndex ){
|
|
ParamMeaning* paramMeaning = m_ParamsPerPass[paramIndex];
|
|
paramMeaning->ProcessCallBack( iMPI );
|
|
}
|
|
}
|
|
|
|
/***************************************************************************
|
|
__ __
|
|
| \/ | __ _ _ __ __ _ __ _ ___ _ __
|
|
| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
|
|
| | | | (_| | | | | (_| | (_| | __/ |
|
|
|_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
|
|
|___/
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------------
|
|
Manager::Manager() :
|
|
m_EverythinghasAlreadyBeenRegistered( FALSE ),
|
|
m_Context( NULL )
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Semantic Related
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterSemanticName( int iSemanticEnum, const char* iName, const char* iDesc )
|
|
{
|
|
XString name = iName;
|
|
name.ToLower();
|
|
#if DIRECT3D_VERSION<0x0900
|
|
DWORD fcc = SemanticEnumToFourCC(iSemanticEnum);
|
|
m_SemanticHash.Insert( fcc,iSemanticEnum);
|
|
#else
|
|
m_SemanticHash.Insert( name, iSemanticEnum);
|
|
m_SemanticNameString.PushBack( iName );
|
|
if( iDesc )
|
|
RegisterSemanticDesc( iSemanticEnum, iDesc );
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterSemanticDesc( int iSemanticEnum, const char* iDesc )
|
|
{
|
|
//--- Don't add empty descriptions
|
|
if( iDesc && strlen(iDesc) ){
|
|
m_SemanticDescString[ iSemanticEnum ] = iDesc;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::GetSemanticDesc( int iSemanticEnum, XString*& oSemDesc )
|
|
{
|
|
oSemDesc = &m_SemanticDescString[ iSemanticEnum ];
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
const XClassArray<XString>&
|
|
Manager::GetSemanticOriginalNames()
|
|
{
|
|
return m_SemanticNameString;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
#if DIRECT3D_VERSION<0x0900
|
|
int
|
|
Manager::GetSemanticIndexFromFourCC( DWORD iFcc)
|
|
{
|
|
int index = Sem_Unknown;
|
|
m_SemanticHash.LookUp( iFcc, index );
|
|
return index;
|
|
}
|
|
#else
|
|
int
|
|
Manager::GetSemanticIndexFromString( XString& iStr )
|
|
{
|
|
int index = Sem_Unknown;
|
|
XString strLower( iStr );
|
|
strLower.ToLower();
|
|
m_SemanticHash.LookUp( strLower, index );
|
|
return index;
|
|
}
|
|
#endif
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// Annotation Related
|
|
//--------------------------------------------------------------------------------
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--------------------------------------------------------------------------------
|
|
const XClassArray<XString>&
|
|
Manager::GetAnnotationOriginalNames()
|
|
{
|
|
return m_AnnotationNameString;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterAnnotationName( int iAnnotationEnum, const char* iName )
|
|
{
|
|
XString nameLower = iName;
|
|
nameLower.ToLower();
|
|
m_AnnotationHash.Insert( nameLower, iAnnotationEnum );
|
|
m_AnnotationNameString.PushBack( iName );
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterAnnotationStringValues( int iAnnotStrEnum, const char* iValue )
|
|
{
|
|
XString nameLower = iValue;
|
|
nameLower.ToLower();
|
|
m_AnnotStrHash.Insert( nameLower, iAnnotStrEnum );
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
int
|
|
Manager::GetAnnotationIndexFromString( XString& iStr )
|
|
{
|
|
int index = Annot_Unknown;
|
|
XString strLower( iStr );
|
|
strLower.ToLower();
|
|
m_AnnotationHash.LookUp( strLower, index );
|
|
return index;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
int
|
|
Manager::GetAnnotStrValueIndexFromString( XString& iStr )
|
|
{
|
|
int index = AnnotStr_Unknown;
|
|
iStr.ToLower();
|
|
m_AnnotStrHash.LookUp( iStr, index );
|
|
return index;
|
|
}
|
|
#endif
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::ExpectingAnnotation( int iAnnotationEnum, int iAnnotationType, void* iValuePtr, bool* iAnnotIsUsedPtr )
|
|
{
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
if( !iValuePtr ) return;
|
|
AnnotationExpected annotExpected( iAnnotationEnum, iAnnotationType, iValuePtr, iAnnotIsUsedPtr );
|
|
m_AnnotationsExpected.PushBack( annotExpected );
|
|
#endif
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::ParseExpectedAnnotations( ID3DXEffect* iFx,
|
|
D3DXHANDLE iHandle,
|
|
int iNumberOfAnnotationsToRead )
|
|
{
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--- Parse Annotations
|
|
D3DXPARAMETER_DESC annotDesc;
|
|
const UINT numberOfAnnotationsToRead = (UINT)iNumberOfAnnotationsToRead;
|
|
for( UINT annotIndex=0; annotIndex<numberOfAnnotationsToRead; annotIndex++ )
|
|
{
|
|
D3DXHANDLE annotHandle = iFx->GetAnnotation( iHandle, annotIndex );
|
|
iFx->GetParameterDesc( annotHandle, &annotDesc );
|
|
|
|
XString annotationStr = annotDesc.Name;
|
|
int annotationIndex = GetAnnotationIndexFromString( annotationStr );
|
|
|
|
//--- Find Matching Expected Annotation
|
|
const int annotExpectedCount = m_AnnotationsExpected.Size();
|
|
int a;
|
|
for( a=0 ; a<annotExpectedCount ; ++a ){
|
|
|
|
//--- Matching Expected Annotation Found
|
|
if( annotationIndex == m_AnnotationsExpected[ a ].annotEnum ){
|
|
|
|
HRESULT hr = -1;
|
|
bool annotIsUsed = false;
|
|
|
|
switch( m_AnnotationsExpected[ a ].annotType ){
|
|
|
|
case AnnotType_String:
|
|
{
|
|
LPCSTR value = NULL;
|
|
if( FAILED( hr = iFx->GetString( annotHandle, &value ) ) ) break;
|
|
*(XString*)m_AnnotationsExpected[ a ].valuePtr = value;
|
|
annotIsUsed = true;
|
|
} break;
|
|
case AnnotType_Bool:
|
|
{
|
|
BOOL value = NULL;
|
|
if( FAILED( hr = iFx->GetBool( annotHandle, &value ) ) ) break;
|
|
*(bool*)m_AnnotationsExpected[ a ].valuePtr = value? true:false;
|
|
annotIsUsed = true;
|
|
} break;
|
|
case AnnotType_Float:
|
|
{
|
|
float value = NULL;
|
|
if( FAILED( hr = iFx->GetFloat( annotHandle, &value ) ) ) break;
|
|
*(float*)m_AnnotationsExpected[ a ].valuePtr = value;
|
|
annotIsUsed = true;
|
|
} break;
|
|
case AnnotType_Int:
|
|
{
|
|
int value = NULL;
|
|
if( FAILED( hr = iFx->GetInt( annotHandle, &value ) ) ) break;
|
|
*(int*)m_AnnotationsExpected[ a ].valuePtr = value;
|
|
annotIsUsed = true;
|
|
} break;
|
|
case AnnotType_Vector4:
|
|
{
|
|
D3DXVECTOR4 dxVect(0,0,0,1);
|
|
if( FAILED( hr = iFx->GetVector( annotHandle, &dxVect ) ) ) break;
|
|
*(VxVector4*)m_AnnotationsExpected[ a ].valuePtr = (VxVector4)dxVect;
|
|
annotIsUsed = true;
|
|
} break;
|
|
}
|
|
//--- No Need to Continue if an Expected Annotation was Found
|
|
if( annotIsUsed ){
|
|
if( m_AnnotationsExpected[ a ].annotIsUsedPtr ) *(m_AnnotationsExpected[ a ].annotIsUsedPtr) = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
//--- Reset AnnotationsExpected Array
|
|
m_AnnotationsExpected.Resize(0);
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
// General
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterParamMeaningForSemantic( int iSemEnum, MeaningInstantiatorPtr iFctPtr )
|
|
{
|
|
m_MeaningInstantiatorForParamBySemantic[ iSemEnum ] = iFctPtr;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
#if DIRECT3D_VERSION<0x0900
|
|
void
|
|
Manager::RegisterParamMeaningForType( int iType, MeaningInstantiatorPtr iFctPtr )
|
|
{
|
|
m_MeaningInstantiatorForParamByType[ iType ] = iFctPtr;
|
|
}
|
|
#else
|
|
void
|
|
Manager::RegisterParamMeaningForClassAndType( int iClass, int iType, MeaningInstantiatorPtr iFctPtr )
|
|
{
|
|
m_MeaningInstantiatorForParamByClassAndType[ iClass ][ iType ] = iFctPtr;
|
|
}
|
|
#endif
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterFctMeaning( MeaningInstantiatorPtr iFctPtr )
|
|
{
|
|
m_MeaningInstantiatorForFunctions.PushBack( iFctPtr );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterTechMeaning( MeaningInstantiatorPtr iFctPtr )
|
|
{
|
|
m_MeaningInstantiatorForTechniques.PushBack( iFctPtr );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::RegisterPassMeaning( MeaningInstantiatorPtr iPassPtr )
|
|
{
|
|
m_MeaningInstantiatorForPasses.PushBack( iPassPtr );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
void
|
|
Manager::Init( CKContext* iContext )
|
|
{
|
|
m_Context = iContext;
|
|
|
|
if( m_EverythinghasAlreadyBeenRegistered ) return;
|
|
m_EverythinghasAlreadyBeenRegistered = TRUE;
|
|
|
|
m_ShaderManager = (CKShaderManager*)iContext->GetManagerByGuid( ShaderManagerGUID );
|
|
|
|
//--- Register All Semantics Names
|
|
RegisterSemanticName( Sem_Ambient, "Ambient", "Virtools material's ambient color" );
|
|
RegisterSemanticName( Sem_Attenuation, "Attenuation", "" );
|
|
RegisterSemanticName( Sem_BoundingBoxMax, "BoundingBoxMax", "Bounding box maximum x, y, z coordinates (float3, or vector)" );
|
|
RegisterSemanticName( Sem_BoundingBoxMin, "BoundingBoxMin", "Bounding box minimum x, y, z coordinates (float3, or vector)" );
|
|
RegisterSemanticName( Sem_BoundingBoxSize, "BoundingBoxSize", "Bounding box size (float3, or vector)" );
|
|
RegisterSemanticName( Sem_BoundingCenter, "BoundingCenter", "Bounding box center (float3, or vector)" );
|
|
RegisterSemanticName( Sem_BoundingSphereSize, "BoundingSphereSize", "Bounding sphere median radius (float)" );
|
|
RegisterSemanticName( Sem_BoundingSphereMin, "BoundingSphereMin", "Bounding sphere minimum radius (float)" );
|
|
RegisterSemanticName( Sem_BoundingSphereMax, "BoundingSphereMax", "Bounding sphere maximum radius (float)" );
|
|
|
|
RegisterSemanticName( Sem_Diffuse, "Diffuse",
|
|
"- as a Virtools semantic: Virtools material's diffuse color (float4)\n"
|
|
"- as render state: renderstate enum standing for diffuse stage\n"
|
|
"- as a Vertex Shader Input semantic: the input vertex diffuse color" );
|
|
|
|
RegisterSemanticName( Sem_ElapsedTime, "ElapsedTime", "Last Delta time in milliseconds" );
|
|
RegisterSemanticName( Sem_Emissive, "Emissive", "Virtools material's emissive color (float4)" );
|
|
RegisterSemanticName( Sem_EnvironmentNormal, "EnvironmentNormal", "" );
|
|
RegisterSemanticName( Sem_Height, "Height", "" );
|
|
RegisterSemanticName( Sem_Joint, "Joint", "" );
|
|
RegisterSemanticName( Sem_JointWorld, "JointWorld", "" );
|
|
RegisterSemanticName( Sem_JointWorldInverse, "JointWorldInverse", "" );
|
|
RegisterSemanticName( Sem_JointWorldInverseTranspose, "JointWorldInversetranspose", "" );
|
|
RegisterSemanticName( Sem_JointWorldView, "JointWorldView", "" );
|
|
RegisterSemanticName( Sem_JointWorldViewInverse, "JointWorldViewInverse", "" );
|
|
RegisterSemanticName( Sem_JointWorldViewInverseTranspose, "JointWorldViewInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_JointWorldViewProjection, "JointWorldViewProjection", "" );
|
|
RegisterSemanticName( Sem_JointWorldViewProjectionInverse, "JointWorldViewProjectionInverse", "" );
|
|
RegisterSemanticName( Sem_JointWorldViewProjectionInverseTranspose, "JointWorldViewProjectionInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_LastTime, "LastTime", "Last simulation time in seconds (float)" );
|
|
RegisterSemanticName( Sem_Normal, "Normal", "" );
|
|
RegisterSemanticName( Sem_Opacity, "Opacity", "" );
|
|
RegisterSemanticName( Sem_Position, "Position", "Virtools object's position (float3)" );
|
|
RegisterSemanticName( Sem_Projection, "Projection", "Projection matrix (float4x4)" );
|
|
RegisterSemanticName( Sem_ProjectionInverse, "ProjectionInverse", "Inversed Projection matrix (float4x4)" );
|
|
RegisterSemanticName( Sem_ProjectionInverseTranspose, "ProjectionInverseTranspose", "Transposed Inversed Projection matrix (float4x4)" );
|
|
RegisterSemanticName( Sem_Random, "Random", "Random number in range [0.0 - 1.0] (float)" );
|
|
RegisterSemanticName( Sem_Refraction, "Refraction", "" );
|
|
RegisterSemanticName( Sem_RenderColorTarget, "RenderColorTarget", "" );
|
|
RegisterSemanticName( Sem_RenderDepthStencilTarget, "RenderDepthDtencilTarget", "" );
|
|
RegisterSemanticName( Sem_RenderTargetClipping, "RenderTargetClipping", "" );
|
|
RegisterSemanticName( Sem_RenderTargetDimensions, "RenderTargetDimensions", "Size of the viewport in pixels" );
|
|
|
|
RegisterSemanticName( Sem_Specular, "Specular",
|
|
"- as a Virtools semantic: Virtools material's specular color (float4)\n"
|
|
"- as a VS input semantic: the input vertex specular color" );
|
|
|
|
RegisterSemanticName( Sem_SpecularPower, "SpecularPower", "Virtools material's specular power (float)" );
|
|
RegisterSemanticName( Sem_AlphaTestEnable, "AlphaTestEnable", "Virtools material's alpha test checkbox (bool)" );
|
|
RegisterSemanticName( Sem_AlphaBlendEnable, "AlphaBlendEnable", "Virtools material's transparency" );
|
|
RegisterSemanticName( Sem_AlphaFunc, "AlphaFunc", "Virtools material's alpha test function, value can be directly bound to the corresponding render state (int)" );
|
|
RegisterSemanticName( Sem_AlphaRef, "AlphaRef", "Virtools material's alpha test reference value, in the [0, 1] range (float)" );
|
|
|
|
RegisterSemanticName( Sem_StandardsGlobal, "StandardsGlobal", "" );
|
|
RegisterSemanticName( Sem_TextureMatrix, "TextureMatrix", "" );
|
|
RegisterSemanticName( Sem_Time, "Time", "Time elapsed since Virtools play event occured in seconds (float)" );
|
|
RegisterSemanticName( Sem_UnitsScale, "UnitsScale", "" );
|
|
RegisterSemanticName( Sem_View, "View", "" );
|
|
RegisterSemanticName( Sem_ViewInverse, "ViewInverse", "" );
|
|
RegisterSemanticName( Sem_ViewInverseTranspose, "ViewInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_ViewProjection, "ViewProjection", "" );
|
|
RegisterSemanticName( Sem_ViewProjectionInverse, "ViewProjectionInverse", "" );
|
|
RegisterSemanticName( Sem_ViewProjectionInverseTranspose, "ViewProjectionInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_World, "World", "" );
|
|
RegisterSemanticName( Sem_WorldInverse, "WorldInverse", "" );
|
|
RegisterSemanticName( Sem_WorldInverseTranspose, "WorldInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_WorldView, "WorldView", "" );
|
|
RegisterSemanticName( Sem_WorldViewInverse, "WorldViewInverse", "" );
|
|
RegisterSemanticName( Sem_WorldViewInverseTranspose, "WorldViewInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_WorldViewProjection, "WorldViewProjection", "" );
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverse, "WorldViewProjectionInverse", "" );
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverseTranspose, "WorldViewProjectionInverseTranspose", "" );
|
|
RegisterSemanticName( Sem_WorldShadowViewProj, "WorldShadowViewProj", "" );
|
|
|
|
// Some Semantic Synonyms
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverse, "Inv_WorldViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverse, "IWorldViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverse, "WorldViewProjectionI" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverseTranspose, "Inv_TWorldViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverseTranspose, "ITWorldViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewProjectionInverseTranspose, "WorldViewProjectionIT" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldInverse, "Inv_World" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldInverse, "IWorld" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldInverse, "WorldI" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldInverseTranspose, "Inv_TWorld" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldInverseTranspose, "ITWorld" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldInverseTranspose, "WorldIT" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewInverse, "Inv_View" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewInverse, "IView" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewInverse, "ViewI" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewInverseTranspose, "Inv_TView" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewInverseTranspose, "ITView" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewInverseTranspose, "ViewIT" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewInverse, "Inv_WorldView" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewInverse, "IWorldView" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewInverse, "WorldViewI" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewInverseTranspose, "Inv_TWorldView" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewInverseTranspose, "ITWorldView" ); // Synonym
|
|
RegisterSemanticName( Sem_WorldViewInverseTranspose, "WorldViewIT" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewProjectionInverse, "Inv_ViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewProjectionInverse, "IViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewProjectionInverse, "ViewProjectionI" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewProjectionInverseTranspose, "Inv_TViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewProjectionInverseTranspose, "ITViewProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewProjectionInverseTranspose, "ViewProjectionIT" ); // Synonym
|
|
RegisterSemanticName( Sem_ProjectionInverse, "Inv_Projection" ); // Synonym
|
|
RegisterSemanticName( Sem_ProjectionInverse, "IProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ProjectionInverse, "ProjectionI" ); // Synonym
|
|
RegisterSemanticName( Sem_ProjectionInverseTranspose, "Inv_TProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ProjectionInverseTranspose, "ITProjection" ); // Synonym
|
|
RegisterSemanticName( Sem_ProjectionInverseTranspose, "ProjectionIT" ); // Synonym
|
|
|
|
RegisterSemanticName( Sem_SpecularPower, "Power" ); // Synonym
|
|
RegisterSemanticName( Sem_Position, "ObjectPos" ); // Synonym
|
|
|
|
RegisterSemanticName( Sem_BoundingBoxMax, "Local_BBox_Max" ); // Synonym
|
|
RegisterSemanticName( Sem_BoundingBoxMax, "LocalBBoxMax" ); // Synonym
|
|
RegisterSemanticName( Sem_BoundingBoxMin, "Local_BBox_Min" ); // Synonym
|
|
RegisterSemanticName( Sem_BoundingBoxMin, "LocalBBoxMin" ); // Synonym
|
|
RegisterSemanticName( Sem_BoundingBoxSize, "Local_BBox_Size" ); // Synonym
|
|
RegisterSemanticName( Sem_BoundingBoxSize, "LocalBBoxSize" ); // Synonym
|
|
|
|
RegisterSemanticName( Sem_WorldViewProjectionTranspose, "TWorldViewProjection", "" );
|
|
RegisterSemanticName( Sem_WorldTranspose, "TWorld", "" );
|
|
RegisterSemanticName( Sem_ViewTranspose, "TView", "" );
|
|
RegisterSemanticName( Sem_ProjectionTranspose, "TProjection", "" );
|
|
RegisterSemanticName( Sem_WorldViewTranspose, "TWorldView", "" );
|
|
RegisterSemanticName( Sem_ViewProjectionTranspose, "TViewProjection", "" );
|
|
RegisterSemanticName( Sem_EyePos, "EyePos", "Current camera position (float3)" );
|
|
RegisterSemanticName( Sem_EyePos, "CamPos" ); // Synonym
|
|
RegisterSemanticName( Sem_EyePos, "World_Camera_Position" ); // Synonym
|
|
RegisterSemanticName( Sem_EyePos, "WorldCameraPosition" ); // Synonym
|
|
|
|
RegisterSemanticName( Sem_Texture, "Texture",
|
|
"- as a Virtools semantic: Virtools material's texture\n"
|
|
"- as render state: renderstate enum standing for texture stage" );
|
|
|
|
RegisterSemanticName( Sem_Texture0, "Texture0", "Virtools texture of channel 0 of current mesh" );
|
|
RegisterSemanticName( Sem_Texture1, "Texture1", "Virtools texture of channel 1 of current mesh" );
|
|
RegisterSemanticName( Sem_Texture2, "Texture2", "Virtools texture of channel 2 of current mesh" );
|
|
RegisterSemanticName( Sem_Texture3, "Texture3", "Virtools texture of channel 3 of current mesh" );
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
RegisterSemanticName( Sem_Texture4, "Texture4", "Virtools texture of channel 4 of current mesh" );
|
|
RegisterSemanticName( Sem_Texture5, "Texture5", "Virtools texture of channel 5 of current mesh" );
|
|
RegisterSemanticName( Sem_Texture6, "Texture6", "Virtools texture of channel 6 of current mesh" );
|
|
RegisterSemanticName( Sem_Texture7, "Texture7", "Virtools texture of channel 7 of current mesh" );
|
|
#endif
|
|
|
|
RegisterSemanticName( Sem_PassCount, "PassCount", "Shader's pass count (int)" );
|
|
RegisterSemanticName( Sem_PassIndex, "PassIndex", "Current rendering pass index (int)" );
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
RegisterSemanticName( Sem_Bones, "Bones", "Array of bones matrices of the skinned character (float4x4[])" );
|
|
RegisterSemanticName( Sem_Bones, "Joint" ); // Synonym
|
|
#endif
|
|
|
|
RegisterSemanticName( Sem_TBones, "TBones", "Array of transposed bones matrices of the skinned character (float4x4[])" );
|
|
RegisterSemanticName( Sem_TBones, "TJoint" ); // Synonym
|
|
|
|
RegisterSemanticName( Sem_RBones, "RBones", "Index of the register where bones matrices of the skinned character will be copied (int)" );
|
|
RegisterSemanticName( Sem_RBones, "RJoint" ); // Synonym
|
|
RegisterSemanticName( Sem_RTBones, "RTBones", "Index of the register where transposed bones matrices of the skinned character will be copied (int)" );
|
|
RegisterSemanticName( Sem_RTBones, "RTJoint" ); // Synonym
|
|
RegisterSemanticName( Sem_BonesPerVertex, "BonesPerVertex", "Max. number of bones per vertex (int)" );
|
|
RegisterSemanticName( Sem_BonesPerVertex, "JointPerVertex" ); // Synonym
|
|
RegisterSemanticName( Sem_ViewportPixelSize, "ViewportPixelSize", "" );
|
|
RegisterSemanticName( Sem_TexelSize, "TexelSize", "Texel size of the last texture parsed in the shader (float2)" );
|
|
RegisterSemanticName( Sem_TextureSize, "TextureSize", "Texture size of the last texture parsed in the shader (float2)" );
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
RegisterSemanticName( Sem_NearestLight, "NearestLight", "Nearest light\n (float = range, float3 = position, float4 = color, float4x4 = matrix)" );
|
|
RegisterSemanticName( Sem_LightCount, "LightCount", "Number of active lights in the scene (int)" );
|
|
RegisterSemanticName( Sem_GlobalAmbient, "GlobalAmbient", "Global ambient color (float4)" );
|
|
#endif
|
|
|
|
|
|
#if defined(_XBOX) && (_XBOX_VER<200)
|
|
RegisterSemanticName( Sem_TexelSize0, "TexelSize0", "Texel size of the last texture parsed in the shader (float2)" );
|
|
RegisterSemanticName( Sem_TexelSize1, "TexelSize1", "Texel size of the last texture parsed in the shader (float2)" );
|
|
RegisterSemanticName( Sem_TexelSize2, "TexelSize2", "Texel size of the last texture parsed in the shader (float2)" );
|
|
RegisterSemanticName( Sem_TexelSize3, "TexelSize3", "Texel size of the last texture parsed in the shader (float2)" );
|
|
|
|
RegisterSemanticName( Sem_BonesIndexConstant, "Bones Index Constant", "Constant used to convert floats to Vertex Shader Constants Index" );
|
|
#endif
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
//--- Register All Annotations Names
|
|
RegisterAnnotationName( Annot_Name, "Name" );
|
|
RegisterAnnotationName( Annot_Normalize, "Normalize" );
|
|
RegisterAnnotationName( Annot_Object, "Object" );
|
|
RegisterAnnotationName( Annot_Semantic, "Semantic" );
|
|
RegisterAnnotationName( Annot_SemanticType, "SemanticType" );
|
|
RegisterAnnotationName( Annot_Space, "Space" );
|
|
RegisterAnnotationName( Annot_Units, "Units" );
|
|
RegisterAnnotationName( Annot_Usage, "Usage" );
|
|
RegisterAnnotationName( Annot_Dimensions, "Dimensions" );
|
|
RegisterAnnotationName( Annot_Discardable, "Discardable" );
|
|
RegisterAnnotationName( Annot_Format, "Format" );
|
|
RegisterAnnotationName( Annot_Function, "Function" );
|
|
RegisterAnnotationName( Annot_MIPLevels, "MipLevels" );
|
|
RegisterAnnotationName( Annot_ResourceName, "ResourceName" );
|
|
RegisterAnnotationName( Annot_ResourceType, "ResourceType" );
|
|
RegisterAnnotationName( Annot_TargetPS, "TargetPS" );
|
|
RegisterAnnotationName( Annot_TargetVS, "TargetVS" );
|
|
RegisterAnnotationName( Annot_Target, "Target" );
|
|
RegisterAnnotationName( Annot_ViewportRatio,"ViewportRatio" );
|
|
RegisterAnnotationName( Annot_UIHelp, "UIHelp" );
|
|
RegisterAnnotationName( Annot_UIMax, "UIMax" );
|
|
RegisterAnnotationName( Annot_UIMin, "UIMin" );
|
|
RegisterAnnotationName( Annot_UIName, "UIName" );
|
|
RegisterAnnotationName( Annot_UIObject, "UIObject" );
|
|
RegisterAnnotationName( Annot_UIStep, "UIStep" );
|
|
RegisterAnnotationName( Annot_UIStepPower, "UIStepPower" );
|
|
RegisterAnnotationName( Annot_UIWidget, "UIWidget" );
|
|
|
|
RegisterAnnotationName( Annot_Script, "Script" );
|
|
RegisterAnnotationName( Annot_ScriptClass, "ScriptClass" );
|
|
RegisterAnnotationName( Annot_ScriptOrder, "ScriptOrder" );
|
|
RegisterAnnotationName( Annot_ScriptOutput, "ScriptOutput" );
|
|
|
|
RegisterAnnotationName( Annot_IsTexelSize, "IsTexelSize" );
|
|
RegisterAnnotationName( Annot_Name, "Name" );
|
|
RegisterAnnotationName( Annot_Target, "Target" );
|
|
RegisterAnnotationName( Annot_Width, "Width" );
|
|
RegisterAnnotationName( Annot_Height, "Height" );
|
|
RegisterAnnotationName( Annot_Depth, "Depth" );
|
|
RegisterAnnotationName( Annot_Type, "Type" );
|
|
RegisterAnnotationName( Annot_NeedTangentSpace, "NeedTangentSpace" );
|
|
RegisterAnnotationName( Annot_NeedColorAndNormal, "NeedColorAndNormal" );
|
|
|
|
RegisterAnnotationName( Annot_DirectionalLightHack, "ProcessDirectionalLights" );
|
|
|
|
RegisterAnnotationName( Annot_Nearest, "Nearest" );
|
|
RegisterAnnotationName( Annot_Sort, "Sort" );
|
|
RegisterAnnotationName( Annot_Default, "Default" );
|
|
|
|
//--- Register All Annotations String Values
|
|
RegisterAnnotationStringValues( AnnotStr_Volume, "Volume" );
|
|
RegisterAnnotationStringValues( AnnotStr_3d, "3D" );
|
|
RegisterAnnotationStringValues( AnnotStr_2d, "2D" );
|
|
RegisterAnnotationStringValues( AnnotStr_Cube, "Cube" );
|
|
|
|
RegisterAnnotationStringValues( AnnotStr_Entity3D, "Entity3D" );
|
|
RegisterAnnotationStringValues( AnnotStr_Entity3D, "3DEntity" );
|
|
RegisterAnnotationStringValues( AnnotStr_Entity3D, "Geometry" );
|
|
RegisterAnnotationStringValues( AnnotStr_Vector, "Vector" );
|
|
|
|
RegisterAnnotationStringValues( AnnotStr_Light, "Light" );
|
|
RegisterAnnotationStringValues( AnnotStr_Light, "TargetLight" ); //--- Used in 3dsMax
|
|
RegisterAnnotationStringValues( AnnotStr_Light, "PointLight" ); //--- Used in FX Composer
|
|
RegisterAnnotationStringValues( AnnotStr_Camera, "Camera" );
|
|
RegisterAnnotationStringValues( AnnotStr_Local, "Local" );
|
|
RegisterAnnotationStringValues( AnnotStr_World, "World" );
|
|
|
|
#endif
|
|
|
|
//--- Register All Meanings Instanciators For Functions
|
|
RegisterMeaningForFct( FctMeaning );
|
|
|
|
//--- Register All Meanings Instanciators For Techniques
|
|
RegisterMeaningForTech( TechMeaning );
|
|
|
|
//--- Register All Meanings Instanciators For Passes
|
|
RegisterMeaningForPass( PassMeaning );
|
|
|
|
//--- Register All Meanings Instanciators For Params Referenced by a Semantic
|
|
for( int s=0 ; s<SemCount ; ++s ){
|
|
RegisterMeaningBySemantic( s, ExposedParamMeaning );
|
|
}
|
|
RegisterMeaningBySemantic( Sem_Ambient, ParamMeaning_Ambient );
|
|
RegisterMeaningBySemantic( Sem_Emissive, ParamMeaning_Emissive );
|
|
RegisterMeaningBySemantic( Sem_Diffuse, ParamMeaning_Diffuse );
|
|
RegisterMeaningBySemantic( Sem_Specular, ParamMeaning_Specular );
|
|
RegisterMeaningBySemantic( Sem_SpecularPower, ParamMeaning_Power );
|
|
RegisterMeaningBySemantic( Sem_AlphaTestEnable, ParamMeaning_AlphaTestEnable );
|
|
RegisterMeaningBySemantic( Sem_AlphaBlendEnable, ParamMeaning_AlphaBlendEnable );
|
|
RegisterMeaningBySemantic( Sem_AlphaFunc, ParamMeaning_AlphaFunc );
|
|
RegisterMeaningBySemantic( Sem_AlphaRef, ParamMeaning_AlphaRef );
|
|
|
|
|
|
|
|
for( int channelIndex = Sem_Texture ; channelIndex<=Sem_Texture7 ; ++channelIndex ){
|
|
RegisterMeaningBySemantic( channelIndex, ParamMeaning_Texture );
|
|
}
|
|
RegisterMeaningBySemantic( Sem_BoundingBoxMax, ParamMeaning_BBoxMax );
|
|
RegisterMeaningBySemantic( Sem_BoundingBoxMin, ParamMeaning_BBoxMin );
|
|
RegisterMeaningBySemantic( Sem_BoundingBoxSize, ParamMeaning_BBoxSize );
|
|
RegisterMeaningBySemantic( Sem_BoundingCenter, ParamMeaning_BBoxCenter );
|
|
RegisterMeaningBySemantic( Sem_BoundingSphereSize, ParamMeaning_BoundingSphereRadius );
|
|
RegisterMeaningBySemantic( Sem_BoundingSphereMax, ParamMeaning_BoundingSphereMax );
|
|
RegisterMeaningBySemantic( Sem_BoundingSphereMin, ParamMeaning_BoundingSphereMin );
|
|
|
|
RegisterMeaningBySemantic( Sem_EyePos, ParamMeaning_EyePos );
|
|
RegisterMeaningBySemantic( Sem_Position, ParamMeaning_ObjectPos );
|
|
|
|
RegisterMeaningBySemantic( Sem_World, ParamMeaning_World );
|
|
RegisterMeaningBySemantic( Sem_WorldTranspose, ParamMeaning_WorldTranspose );
|
|
RegisterMeaningBySemantic( Sem_WorldInverse, ParamMeaning_WorldInverse );
|
|
RegisterMeaningBySemantic( Sem_WorldInverseTranspose, ParamMeaning_WorldInverseTranspose );
|
|
|
|
RegisterMeaningBySemantic( Sem_View, ParamMeaning_View );
|
|
RegisterMeaningBySemantic( Sem_ViewTranspose, ParamMeaning_ViewTranspose );
|
|
RegisterMeaningBySemantic( Sem_ViewInverse, ParamMeaning_ViewInverse );
|
|
RegisterMeaningBySemantic( Sem_ViewInverseTranspose, ParamMeaning_ViewInverseTranspose );
|
|
|
|
RegisterMeaningBySemantic( Sem_Projection, ParamMeaning_Projection );
|
|
RegisterMeaningBySemantic( Sem_ProjectionTranspose, ParamMeaning_ProjectionTranspose );
|
|
RegisterMeaningBySemantic( Sem_ProjectionInverse, ParamMeaning_ProjectionInverse );
|
|
RegisterMeaningBySemantic( Sem_ProjectionInverseTranspose, ParamMeaning_ProjectionInverseTranspose );
|
|
|
|
RegisterMeaningBySemantic( Sem_WorldView, ParamMeaning_WorldView );
|
|
RegisterMeaningBySemantic( Sem_WorldViewTranspose, ParamMeaning_WorldViewTranspose );
|
|
RegisterMeaningBySemantic( Sem_WorldViewInverse, ParamMeaning_WorldViewInverse );
|
|
RegisterMeaningBySemantic( Sem_WorldViewInverseTranspose, ParamMeaning_WorldViewInverseTranspose );
|
|
|
|
RegisterMeaningBySemantic( Sem_ViewProjection, ParamMeaning_ViewProjection );
|
|
RegisterMeaningBySemantic( Sem_ViewProjectionTranspose, ParamMeaning_ViewProjectionTranspose );
|
|
RegisterMeaningBySemantic( Sem_ViewProjectionInverse, ParamMeaning_ViewProjectionInverse );
|
|
RegisterMeaningBySemantic( Sem_ViewProjectionInverseTranspose, ParamMeaning_ViewProjectionInverseTranspose );
|
|
|
|
RegisterMeaningBySemantic( Sem_WorldViewProjection, ParamMeaning_WorldViewProjection );
|
|
RegisterMeaningBySemantic( Sem_WorldViewProjectionTranspose, ParamMeaning_WorldViewProjectionTranspose );
|
|
RegisterMeaningBySemantic( Sem_WorldViewProjectionInverse, ParamMeaning_WorldViewProjectionInverse );
|
|
RegisterMeaningBySemantic( Sem_WorldViewProjectionInverseTranspose, ParamMeaning_WorldViewProjectionInverseTranspose );
|
|
RegisterMeaningBySemantic( Sem_WorldShadowViewProj, ParamMeaning_WorldShadowViewProj);
|
|
|
|
RegisterMeaningBySemantic( Sem_Time, ParamMeaning_Time );
|
|
RegisterMeaningBySemantic( Sem_ElapsedTime, ParamMeaning_ElapsedTime );
|
|
RegisterMeaningBySemantic( Sem_LastTime, ParamMeaning_LastTime );
|
|
|
|
RegisterMeaningBySemantic( Sem_ViewportPixelSize, ParamMeaning_ViewportPixelSize );
|
|
RegisterMeaningBySemantic( Sem_Random, ParamMeaning_Random );
|
|
|
|
RegisterMeaningBySemantic( Sem_BonesPerVertex, ParamMeaning_BonesPerVertex );
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
RegisterMeaningBySemantic( Sem_Bones, ParamMeaning_Bones );
|
|
RegisterMeaningBySemantic( Sem_TBones, ParamMeaning_TBones );
|
|
#endif
|
|
|
|
RegisterMeaningBySemantic( Sem_RBones, ParamMeaning_RBones );
|
|
RegisterMeaningBySemantic( Sem_RTBones, ParamMeaning_RTBones );
|
|
|
|
RegisterMeaningBySemantic( Sem_PassCount, ParamMeaning_PassCount );
|
|
RegisterMeaningBySemantic( Sem_PassIndex, ParamMeaning_PassIndex );
|
|
|
|
RegisterMeaningBySemantic( Sem_TexelSize, ParamMeaning_TexelSize );
|
|
RegisterMeaningBySemantic( Sem_TextureSize, ParamMeaning_TextureSize );
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
RegisterMeaningBySemantic( Sem_NearestLight, ParamMeaning_NearestLight );
|
|
RegisterMeaningBySemantic( Sem_LightCount, ParamMeaning_LightCount );
|
|
RegisterMeaningBySemantic( Sem_GlobalAmbient, ParamMeaning_GlobalAmbient );
|
|
#endif
|
|
|
|
#if DIRECT3D_VERSION<0x0900
|
|
RegisterMeaningBySemantic( Sem_TexelSize0, ParamMeaning_TexelSize );
|
|
RegisterMeaningBySemantic( Sem_TexelSize1, ParamMeaning_TexelSize );
|
|
RegisterMeaningBySemantic( Sem_TexelSize2, ParamMeaning_TexelSize );
|
|
RegisterMeaningBySemantic( Sem_TexelSize3, ParamMeaning_TexelSize );
|
|
RegisterMeaningBySemantic( Sem_BonesIndexConstant, ParamMeaning_BonesIndexConstant );
|
|
#endif
|
|
//--- Register All Meanings Instanciators For Params Not Referenced by a Semantic
|
|
#if DIRECT3D_VERSION<0x0900
|
|
for( int typ=0 ; typ<ParamTypeCount ; ++typ ){
|
|
RegisterMeaningByType( typ, ExposedParamMeaning );
|
|
}
|
|
#else
|
|
for( int clas=0 ; clas<ParamClassCount ; ++clas ){
|
|
for( int typ=0 ; typ<ParamTypeCount ; ++typ ){
|
|
RegisterMeaningByClassAndType( clas, typ, ExposedParamMeaning );
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/***************************************************************************
|
|
____ _ _
|
|
/ ___|___ _ ____ _____ _ __ (_) ___ _ __ | |_
|
|
| | / _ \| '_ \ \ / / _ \ '_ \| |/ _ \ '_ \| __|
|
|
| |__| (_) | | | \ V / __/ | | | | __/ | | | |_
|
|
\____\___/|_| |_|\_/ \___|_| |_|_|\___|_| |_|\__|
|
|
| ___| _ _ __ ___| |_(_) ___ _ __ ___
|
|
| |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
|
|
| _|| |_| | | | | (__| |_| | (_) | | | \__ \
|
|
|_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
|
|
|
|
***************************************************************************/
|
|
|
|
//--------------------------------------------------------------------------
|
|
struct FMTINFO
|
|
{
|
|
D3DFORMAT fmt;
|
|
const TCHAR* strName;
|
|
};
|
|
|
|
static const TCHAR* TYPE_UNSIGNED = TEXT("Unsigned");
|
|
static const TCHAR* TYPE_SIGNED = TEXT("Signed");
|
|
static const TCHAR* TYPE_MIXED = TEXT("Mixed");
|
|
static const TCHAR* TYPE_FOUR_CC = TEXT("Four CC");
|
|
static const TCHAR* TYPE_FLOAT = TEXT("Floating-Point");
|
|
static const TCHAR* TYPE_IEEE = TEXT("IEEE Floating-Point");
|
|
|
|
#if DIRECT3D_VERSION>=0x0900
|
|
|
|
const FMTINFO fmtInfoArray[] =
|
|
{
|
|
|
|
D3DFMT_A8B8G8R8, TEXT("A8B8G8R8"),
|
|
D3DFMT_A8R8G8B8, TEXT("A8R8G8B8"),
|
|
|
|
D3DFMT_X8B8G8R8, TEXT("X8B8G8R8"),
|
|
D3DFMT_X8R8G8B8, TEXT("X8R8G8B8"),
|
|
D3DFMT_A16B16G16R16, TEXT("A16B16G16R16"),
|
|
|
|
D3DFMT_A1R5G5B5, TEXT("A1R5G5B5"),
|
|
D3DFMT_A4R4G4B4, TEXT("A4R4G4B4"),
|
|
|
|
D3DFMT_R5G6B5, TEXT("R5G6B5"),
|
|
D3DFMT_X1R5G5B5, TEXT("X1R5G5B5"),
|
|
|
|
D3DFMT_R16F, TEXT("R16F"),
|
|
D3DFMT_G16R16F, TEXT("G16R16F"),
|
|
D3DFMT_A16B16G16R16F, TEXT("A16B16G16R16F"),
|
|
|
|
D3DFMT_R32F, TEXT("R32F"),
|
|
D3DFMT_G32R32F, TEXT("G32R32F"),
|
|
D3DFMT_A32B32G32R32F, TEXT("A32B32G32R32F"),
|
|
|
|
D3DFMT_DXT1, TEXT("DXT1"),
|
|
D3DFMT_DXT2, TEXT("DXT2"),
|
|
D3DFMT_DXT3, TEXT("DXT3"),
|
|
D3DFMT_DXT4, TEXT("DXT4"),
|
|
D3DFMT_DXT5, TEXT("DXT5"),
|
|
|
|
D3DFMT_UYVY, TEXT("UYVY"),
|
|
D3DFMT_YUY2, TEXT("YUY2"),
|
|
#ifdef D3DFMT_A4L4
|
|
D3DFMT_A4L4, TEXT("A4L4"),
|
|
#endif
|
|
D3DFMT_A8, TEXT("A8"),
|
|
D3DFMT_L8, TEXT("L8"),
|
|
#ifdef D3DFMT_P8
|
|
D3DFMT_P8, TEXT("P8"),
|
|
#endif
|
|
#ifdef D3DFMT_R3G3B2
|
|
D3DFMT_R3G3B2, TEXT("R3G3B2"),
|
|
#endif
|
|
D3DFMT_A8L8, TEXT("A8L8"),
|
|
#ifdef D3DFMT_A8P8
|
|
D3DFMT_A8P8, TEXT("A8P8"),
|
|
#endif
|
|
#ifdef D3DFMT_A8R3G3B2
|
|
D3DFMT_A8R3G3B2, TEXT("A8R3G3B2"),
|
|
#endif
|
|
D3DFMT_L16, TEXT("L16"),
|
|
|
|
D3DFMT_X4R4G4B4, TEXT("X4R4G4B4"),
|
|
#ifdef D3DFMT_R8G8B8
|
|
D3DFMT_R8G8B8, TEXT("R8G8B8"),
|
|
#endif
|
|
D3DFMT_A2B10G10R10, TEXT("A2B10G10R10"),
|
|
D3DFMT_A2R10G10B10, TEXT("A2R10G10B10"),
|
|
|
|
D3DFMT_G16R16, TEXT("G16R16"),
|
|
|
|
#ifdef D3DFMT_CxV8U8
|
|
D3DFMT_CxV8U8, TEXT("CxV8U8"),
|
|
#endif
|
|
D3DFMT_V8U8, TEXT("V8U8"),
|
|
D3DFMT_Q8W8V8U8, TEXT("Q8W8V8U8"),
|
|
D3DFMT_V16U16, TEXT("V16U16"),
|
|
D3DFMT_Q16W16V16U16, TEXT("Q16W16V16U16"),
|
|
|
|
D3DFMT_L6V5U5, TEXT("L6V5U5"),
|
|
D3DFMT_A2W10V10U10, TEXT("A2W10V10U10"),
|
|
D3DFMT_X8L8V8U8, TEXT("X8L8V8U8"),
|
|
|
|
D3DFMT_G8R8_G8B8, TEXT("G8R8_G8B8"),
|
|
D3DFMT_R8G8_B8G8, TEXT("R8G8_B8G8"),
|
|
|
|
|
|
};
|
|
|
|
const int fmtInfoArraySize = sizeof(fmtInfoArray) / sizeof(fmtInfoArray[0]);
|
|
|
|
D3DFORMAT StringToD3DFormat(LPCSTR pstrFormat){
|
|
for(int i=0;i<fmtInfoArraySize;i++){
|
|
if(0==_strcmpi(pstrFormat,fmtInfoArray[i].strName))
|
|
return fmtInfoArray[i].fmt;
|
|
}
|
|
|
|
return D3DFMT_A8R8G8B8;
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
DWORD g_SemanticEnumToFourCC[SemCount] = {
|
|
'____', // Sem_Unknown = 0,
|
|
'vAMB', // Sem_Ambient,
|
|
'fATT', // Sem_Attenuation,
|
|
'vBMA', // Sem_BoundingBoxMax,
|
|
'vBMI', // Sem_BoundingBoxMin,
|
|
'vBSZ', // Sem_BoundingBoxSize,
|
|
'vBCE', // Sem_BoundingCenter,
|
|
'vBSS', // Sem_BoundingSphereSize,
|
|
'vBSI', // Sem_BoundingSphereMin,
|
|
'vBSA', // Sem_BoundingSphereMax,
|
|
'vDIF', // Sem_Diffuse,
|
|
'fETI', // Sem_ElapsedTime,
|
|
'vEMI', // Sem_Emissive,
|
|
'tENV', // Sem_EnvironmentNormal,
|
|
'fHEI', // Sem_Height,
|
|
'vJOI', // Sem_Joint,
|
|
'JWOR', // Sem_JointWorld,
|
|
'JWIN', // Sem_JointWorldInverse,
|
|
'JWIT', // Sem_JointWorldInverseTranspose,
|
|
'JWOV', // Sem_JointWorldView,
|
|
'JWVI', // Sem_JointWorldViewInverse,
|
|
'JWVY', // Sem_JointWorldViewInverseTranspose,
|
|
'JWVP', // Sem_JointWorldViewProjection,
|
|
'JTIN', // Sem_JointWorldViewProjectionInverse,
|
|
'JTIT', // Sem_JointWorldViewProjectionInverseTranspose,
|
|
'fLAS', // Sem_LastTime,
|
|
'vNOR', // Sem_Normal,
|
|
'vOPA', // Sem_Opacity,
|
|
'vPOS', // Sem_Position,
|
|
'mPRO', // Sem_Projection,
|
|
'mPIN', // Sem_ProjectionInverse,
|
|
'mPIT', // Sem_ProjectionInverseTranspose,
|
|
'fRAN', // Sem_Random,
|
|
'vREF', // Sem_Refraction,
|
|
'tREN', // Sem_RenderColorTarget,
|
|
'tSTE', // Sem_RenderDepthStencilTarget,
|
|
'vCLI', // Sem_RenderTargetClipping,
|
|
'vRTD', // Sem_RenderTargetDimensions,
|
|
'vSPE', // Sem_Specular,
|
|
'fPOW', // Sem_SpecularPower,
|
|
'____', // Sem_StandardsGlobal,
|
|
'mTEX', // Sem_TextureMatrix,
|
|
'fTIM', // Sem_Time,
|
|
'fSCA', // Sem_UnitsScale,
|
|
'mVIE', // Sem_View,
|
|
'mVIN', // Sem_ViewInverse,
|
|
'mVIT', // Sem_ViewInverseTranspose,
|
|
'mVPR', // Sem_ViewProjection,
|
|
'mVPI', // Sem_ViewProjectionInverse,
|
|
'VPIT', // Sem_ViewProjectionInverseTranspose,
|
|
'mWOR', // Sem_World,
|
|
'mWIN', // Sem_WorldInverse,
|
|
'mWIT', // Sem_WorldInverseTranspose,
|
|
'mWVI', // Sem_WorldView,
|
|
'WVIN', // Sem_WorldViewInverse,
|
|
'WVIT', // Sem_WorldViewInverseTranspose,
|
|
'mWVP', // Sem_WorldViewProjection,
|
|
'WVPI', // Sem_WorldViewProjectionInverse,
|
|
'WVPY', // Sem_WorldViewProjectionInverseTranspose,
|
|
'WVPT', // Sem_WorldViewProjectionTranspose,
|
|
'mWOT', // Sem_WorldTranspose,
|
|
'mVTR', // Sem_ViewTranspose,
|
|
'mPRT', // Sem_ProjectionTranspose,
|
|
'mWVT', // Sem_WorldViewTranspose,
|
|
'mVPT', // Sem_ViewProjectionTranspose,
|
|
'vEPO', // Sem_EyePos,
|
|
'tTEX', // Sem_Texture,
|
|
'TEX0', // Sem_Texture0,
|
|
'TEX1', // Sem_Texture1,
|
|
'TEX2', // Sem_Texture2,
|
|
'TEX3', // Sem_Texture3,
|
|
'TEX4', // Sem_Texture4,
|
|
'TEX5', // Sem_Texture5,
|
|
'TEX6', // Sem_Texture6,
|
|
'TEX7', // Sem_Texture7,
|
|
'PASC', // Sem_PassCount,
|
|
'PASI', // Sem_PassIndex,
|
|
'____', // Sem_Bones,
|
|
'____', // Sem_TBones,
|
|
'mBON', // Sem_RBones,
|
|
'mTBO', // Sem_RTBones,
|
|
'iBPV', // Sem_BonesPerVertex,
|
|
'vVPS', // Sem_ViewportPixelSize,
|
|
'tSIZ', // Sem_TexelSize,
|
|
'SIZ0', // Sem_TexelSize0,
|
|
'SIZ1', // Sem_TexelSize1,
|
|
'SIZ2', // Sem_TexelSize2,
|
|
'SIZ3', // Sem_TexelSize3,
|
|
'vBIC' // Sem_BonesIndexConstant
|
|
};
|
|
|
|
DWORD SemanticEnumToFourCC(DWORD iSem){
|
|
DWORD d = g_SemanticEnumToFourCC[iSem];
|
|
DWORD s = ntohl(d);
|
|
return s;
|
|
}
|
|
|
|
#endif
|
|
|