My Project
effect_file_DirectX.h
1 #pragma once
2 #include "effect_file.h"
3 
4 namespace ParaEngine
5 {
7  {
8  public:
9  CEffectFileDirectX(const char* filename);
10  CEffectFileDirectX(const AssetKey& key);
11  virtual ~CEffectFileDirectX();
12 
13  // Operators...
14  // Mutators...
15  virtual HRESULT InitDeviceObjects();
16  virtual HRESULT RestoreDeviceObjects();
17  virtual HRESULT InvalidateDeviceObjects();
18  virtual HRESULT DeleteDeviceObjects();
19 
20  bool loadResource(); // load the resource from a file (or NULL to use the resource name)
21  bool saveResource(const char* filename=0); // save the resource to a file (or NULL to use the resource name)
22 
24  void SetFileName(const std::string& filename);
25 
34  bool begin(bool bApplyParam = true, DWORD flag=D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESAMPLERSTATE|D3DXFX_DONOTSAVESHADERSTATE, bool bForceBegin = false);
35  bool BeginPass(int pass,bool bForceBegin = false);
36  void CommitChanges();
37  void EndPass(bool bForceEnd = false);
38  void end(bool bForceEnd = false);
39  void EnableShareMode(bool bEnable);
40  bool IsInShareMode();
41 
44  bool BeginSharePassMode(bool bApplyParam = true, DWORD flag=D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESAMPLERSTATE|D3DXFX_DONOTSAVESHADERSTATE, bool bForceBegin = true);
45 
48  void EndSharePassMode();
49 
51  void OnSwitchInShader();
52 
54  void OnSwitchOutShader();
55 
57  struct TechniqueDescDX : public TechniqueDesc
58  {
59  D3DXHANDLE hTechnique;
60  D3DXTECHNIQUE_DESC techniqueDesc;
61  public:
63  memset(this, 0, sizeof(TechniqueDescDX));
64  }
65  };
66 
79  bool SetTechniqueByIndex(int nIndex);
81  const TechniqueDesc* GetCurrentTechniqueDesc();
87 
88  // Accessors...
89  LPD3DXEFFECT effect()const;
90  int totalPasses()const;
91 
92  bool isParameterUsed(eParameterHandles index)const;
93  bool isMatrixUsed(eParameterHandles index)const;
94  bool isTextureUsed(int index)const;
95  bool isTextureMatrixUsed(int index)const;
96  bool isShadowTextureUsed()const;
97 
98  bool setParameter(eParameterHandles index, const void* data, INT32 size=D3DX_DEFAULT)const;
99  bool setBool(eParameterHandles index, BOOL bBoolean) const;
100  bool setInt(eParameterHandles index, int nValue) const;
101  bool setFloat(eParameterHandles index, float fValue) const;
102  bool setMatrix(eParameterHandles index, const Matrix4* data)const;
103  bool setMatrixArray(eParameterHandles index, const Matrix4* data, UINT32 count)const;
104  bool setMatrixInArray(eParameterHandles index, UINT32 element, const Matrix4* data)const;
105  bool setFloatArray(eParameterHandles index, const float* data, UINT32 count)const;
106  bool setVectorArray(eParameterHandles index,const Vector4* pVector,UINT count)const;
107  bool setFloatInArray(eParameterHandles index, UINT32 element, float data)const;
108  bool setTexture(int index, TextureEntity* data);
109  bool setTexture(int index, LPDIRECT3DTEXTURE9 pTex);
110  bool setTextureInternal(int index, LPDIRECT3DTEXTURE9 pTex);
111  bool setTextureMatrix(int index, const Matrix4* data)const;
112  //bool setShadowTexture(const TextureEntity* data)const;
113  void SetShadowMapSize(int nsize);
115  void SetShadowRadius(float fRadius);
116 
120  void applySurfaceMaterial(const ParaMaterial* pSurfaceMaterial, bool bUseGlobalAmbient = true);
121  void applyCameraMatrices();
122  void applyWorldMatrices();
123  void applyGlobalLightingData(CSunLight& sunlight);
124  void applyLocalLightingData(const LightList* lights, int nLightNum);
125  void applyFogParameters(bool bEnableFog, const Vector4* fogParam, const LinearColor* fogColor);
126  void applyLayersNum(int nLayers);
127  void applyTexWorldViewProj(const Matrix4* mat);
128 
129  // texture alpha operation attribute
131  void EnableAlphaBlending(bool bAlphaBlending);
133  void EnableAlphaTesting(bool bAlphaTesting);
135  void EnableSunLight(bool bEnableSunLight);
137  static void EnableTextures(bool bEnable);
138  static bool AreTextureEnabled();
142  void EnableShadowmap(int nShadowMethod);
143 
148  bool SetBoolean(int nIndex, bool value);
149 
155  bool EnableEnvironmentMapping(bool bEnable);
162  bool EnableReflectionMapping(bool bEnable, float fSurfaceHeight=0.f);
163 
168  void SetReflectFactor(float fFactor);
173  void EnableNormalMap(bool bEnable);
174 
179  void EnableLightMap(bool bEnable);
180 
182  LPD3DXEFFECT GetDXEffect() {return m_pEffect;};
183 
187  virtual CParameterBlock* GetParamBlock(bool bCreateIfNotExist = false);
188 
192  void LockTexture(int nIndex);
196  void UnLockTexture(int nIndex);
197 
201  bool IsTextureLocked(int nIndex) const;
202 
204  D3DXHANDLE& GetTextureHandle(int nIndex);
205 
206  HRESULT SetRawValue(D3DXHANDLE hParameter, LPCVOID pData, UINT ByteOffset, UINT Bytes);
207  bool SetBool(D3DXHANDLE hParameter, BOOL bBoolean);
208  bool SetInt(D3DXHANDLE hParameter, int nValue);
209  bool SetFloat(D3DXHANDLE hParameter, float fValue);
210  bool SetVector2(D3DXHANDLE hParameter, const Vector2& vValue);
211  bool SetVector3(D3DXHANDLE hParameter, const Vector3& vValue);
212  bool SetVector4(D3DXHANDLE hParameter, const Vector4& vValue);
213  bool SetMatrix(D3DXHANDLE hParameter, const Matrix4& data);
214  private:
215  // effect file name
216  string m_filename;
217  // Data Types & Constants...
218  static bool s_bUseHalfPrecision; // set to TRUE to use half-precision floats in all shaders
219 
220  // Private Data...
221  LPD3DXEFFECT m_pEffect;
222  D3DXEFFECT_DESC m_EffectDesc;
223  vector<TechniqueDescDX> m_techniques;
225  vector<bool> m_LockedTextures;
228  vector<void*> m_LastTextures;
229 
230  // the current technique index
231  int m_nTechniqueIndex;
232  bool m_bIsBegin;
234  bool m_bSharedMode;
235  static bool g_bTextureEnabled;
236 
240  CParameterBlock m_SharedParamBlock;
241 
242  D3DXHANDLE m_paramHandle[k_max_param_handles];
243 
244  // Private Functions...
245  void parseParameters();
246  void releaseEffect();
248  int BeginWith(LPCSTR str, LPCSTR searchStr);
250  bool GetNumber(LPCSTR str, int nBeginIndex, int* pOut);
251  };
252 
253  // this is the actually class used externally. it does following:
254  // typedef CEffectFileDirectX CEffectFile;
255  class CEffectFile : public CEffectFileDirectX
256  {
257  public:
258  CEffectFile(const char* filename) :CEffectFileDirectX(filename){};
259  CEffectFile(const AssetKey& key) :CEffectFileDirectX(key){};
260  virtual ~CEffectFile(){};
261  };
262 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
eParameterHandles
Definition: effect_file.h:41
void UnLockTexture(int nIndex)
UnLock a texture at a given index.
LPD3DXEFFECT GetDXEffect()
get directX effect object associated with this object.
Definition: effect_file_DirectX.h:182
4-dimensional homogeneous vector.
Definition: ParaVector4.h:10
void EnableSunLight(bool bEnableSunLight)
whether to enable sun light calculation
void EnableAlphaTesting(bool bAlphaTesting)
whether to enable alpha testing
void EnableNormalMap(bool bEnable)
whether to enable the use of normal map
void EnableShadowmap(int nShadowMethod)
whether to enable rendering with shadow map
bool SetFirstValidTechniqueByCategory(TechniqueCategory nCat)
Set technique if it is different from the current one.
void OnSwitchInShader()
this is called when the shader is selected by the pipeline.
different physics engine has different winding order.
Definition: EventBinding.h:32
void SetFileName(const std::string &filename)
set inner file name, usually at the load time.
TechniqueCategory
The game engine will identified some predefined technique name from the the effect file...
Definition: effect_file.h:27
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc.
Definition: SunLight.h:26
static void EnableTextures(bool bEnable)
one occasion to disable textures is during the shadow pass.
void SetShadowRadius(float fRadius)
set the shadow radius
const TechniqueDesc * GetCurrentTechniqueDesc()
get the current technique description.
int GetCurrentTechniqueIndex()
current technique index.
void EndSharePassMode()
This is a handy function that calls EnableShareMode(false), EndPass(true), end(true).
void LockTexture(int nIndex)
Lock a texture at a given index.
void SetReflectFactor(float fFactor)
set shader parameter "reflectFactor"
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
a technique description
Definition: effect_file_DirectX.h:57
bool SetBoolean(int nIndex, bool value)
set a boolean parameter.
Definition: effect_file_DirectX.h:6
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
bool EnableReflectionMapping(bool bEnable, float fSurfaceHeight=0.f)
enable reflection mapping
bool BeginSharePassMode(bool bApplyParam=true, DWORD flag=D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESAMPLERSTATE|D3DXFX_DONOTSAVESHADERSTATE, bool bForceBegin=true)
This is a handy function that calls EnableShareMode(true), begin() and then BeginPass().
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
virtual CParameterBlock * GetParamBlock(bool bCreateIfNotExist=false)
get effect parameter block with this object.
Definition: RenderCore.h:50
bool SetTechniqueByIndex(int nIndex)
Set technique if it is different from the current one.
Definition: enum_maker.hpp:46
Definition: effect_file.h:323
bool begin(bool bApplyParam=true, DWORD flag=D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESAMPLERSTATE|D3DXFX_DONOTSAVESHADERSTATE, bool bForceBegin=false)
std::string AssetKey
the unique key object for asset entity.
Definition: AssetEntity.h:13
D3DXHANDLE & GetTextureHandle(int nIndex)
get texture handle at the given index.
bool EnableEnvironmentMapping(bool bEnable)
enable environment mapping
void OnSwitchOutShader()
this is called when the shader is deselected by the pipeline.
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
bool IsTextureLocked(int nIndex) const
check whether a given texture is locked at the given index.
void applySurfaceMaterial(const ParaMaterial *pSurfaceMaterial, bool bUseGlobalAmbient=true)
void EnableLightMap(bool bEnable)
whether to enable the use of light map
void EnableAlphaBlending(bool bAlphaBlending)
whether to enable alpha blending in shader.
a list of CParameter{name, value} pairs of anything.
Definition: ParameterBlock.h:108
asset entity: CEffectFile
Definition: effect_file.h:19