My Project
EffectManager.h
1 #pragma once
2 
3 #include "AssetManager.h"
4 #include "effect_file.h"
5 #include "LightManager.h"
6 
7 namespace ParaEngine
8 {
9  class CBaseObject;
10  class CShadowMap;
11  class CGlowEffect;
12  class IScene;
13  class WaveEffect;
14 
16  class EffectManager: public AssetManager<CEffectFile>
17  {
18  public:
19  EffectManager();
20  ~EffectManager();
21 
28  CEffectFile* GetEffectByHandle(int nHandle);
29 
32  int GetEffectHandle(CEffectFile* effectFile);
33 
56  CEffectFile* GetEffectByName(const string& sName);
57 
63  CEffectFile* MapHandleToEffect(int nHandle, CEffectFile* pNewEffect);
64 
65  virtual bool DeleteEntity(AssetEntity* entity);
66  virtual void InitDeviceObjects();
67  virtual void DeleteDeviceObjects();
68  virtual void RestoreDeviceObjects();
69  virtual void InvalidateDeviceObjects();
73  virtual void RendererRecreated();
74 
75  void Cleanup();
76 
81 
88  bool BeginEffect(int nHandle, CEffectFile** pOutEffect = NULL);
90  void EndEffect();
92  CEffectFile* CheckLoadEffect(int nHandle);
93 
96  {
97  S0_POS_TEX0, // all data in stream 0: position and tex0
98  S0_POS_NORM_TEX0, // all data in stream 0: position, normal and tex0
99  S0_POS_NORM_TEX0_INSTANCED, // all data in stream 0: position, normal and tex0, stream1:instanced data
100  S0_POS_TEX0_COLOR, // all data in stream 0: position, tex0 and color
101  S0_POS_NORM_TEX0_COLOR, // all data in stream 0: position, normal, tex0 and color
102  S0_S1_S2_OCEAN_FFT, // for FFT ocean
103  S0_S1_S2_S3_OCEAN_FFT, // for FFT ocean with terrain height field
104  S0_POS_NORM_TEX0_TEX1, // all data in stream 0: position, normal tex0 and tex1
105  S0_POS_TEX0_TEX1, // all data in stream 0: position, tex0 and tex1
106  S0_S1_OCEAN_CLOUD, // stream 0: position; stream 1, height field
107  S0_POS_COLOR, // all data in stream 0: position, and color
108  S0_POS2_COLOR, // all data in stream 0: homogeneous coordinates, and color
109  S0_POS_NORM_COLOR, // all data in stream 0: position, normal, and color
110  S0_POS_NORM_TEX0_COLOR0_COLOR1, // all data in stream 0: position, normal, tex0,color0 and color1
111  S0_POS, // all data in stream 0: position
112  MAX_DECLARATIONS_NUM,
113  };
114 
115 
123  HRESULT SetVertexDeclaration(int nIndex);
124 
133  void SetDefaultEffectMapping(int nLevel);
134  int GetDefaultEffectMapping();
135 
137  {
146  };
153 
154 
155  int GetCurrentTechHandle();
156  CEffectFile* GetCurrentEffectFile();
157 
159  //
160  // The following functions set or retrieve global effect states which are shared by all effect files.
161  // They are designed to look like the fixed pipeline programming interface of DirectX9
162  //
164 
165  HRESULT SetMaterial(ParaMaterial *pMaterial);
166  HRESULT SetLight(DWORD Index, const Para3DLight *pLight);
167  HRESULT LightEnable(DWORD Index, BOOL Enable);
168  HRESULT SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
169  HRESULT SetTexture(DWORD Stage, DeviceTexturePtr_type pTexture);
171  HRESULT SetSamplerState(int nStage, DWORD dwType, DWORD dwValue, bool bForceSet = false);
173  HRESULT GetSamplerState(int nStage, DWORD dwType, DWORD* pValue, bool bForceGet = false);
175  void SetDefaultSamplerState(int nStage, DWORD dwType, DWORD dwValue);
177  DWORD GetDefaultSamplerState(int nStage, DWORD dwType);
178 
179  HRESULT SetTransform(D3DTRANSFORMSTATETYPE State, const Matrix4 *pMatrix);
180  HRESULT GetTransform(D3DTRANSFORMSTATETYPE State,Matrix4 * pMatrix);
181 
184  const Matrix4& GetWorldTransform();
185  const Matrix4& GetViewTransform();
186  const Matrix4& GetProjTransform();
187 
192  void UpdateD3DPipelineTransform(bool pWorld, bool pView,bool pProjection);
193 
195  void EnableFog(bool bEnabled);
196 
199  ClipPlane_Disabled,
200  ClipPlane_Enabled_WorldSpace,
201  ClipPlane_Enabled_ClipSpace,
202  };
203 
210  void EnableClipPlane(bool bEnable);
211 
213  void EnableClipPlaneImmediate(EffectManager::ClipPlaneState newState, int nIndex=0);
215  bool IsClipPlaneEnabled();
216 
224  void SetClipPlane(DWORD Index, const float * pPlane, bool bClipSpace);
225 
231  void applySurfaceMaterial(const ParaMaterial* pSurfaceMaterial, bool bUseGlobalAmbient = true);
232 
236  void applyLocalLightingData(const LightList* lights, int nLightNum);
241  void applyLocalLightingData();
242 
244  void applyFogParameters();
245 
248 
250  void EnableGlobalLighting(bool bEnable);
253 
255  void EnableLocalLighting(bool bEnable);
257  bool IsLocalLightingEnabled();
258 
260  void EnableUsingShadowMap(bool bEnable);
262  bool IsUsingShadowMap();
264  const Matrix4* GetTexViewProjMatrix();
265 
267  void EnableTextures(bool bEnable);
268  bool AreTextureEnabled();
269 
273  void DisableD3DAlphaTesting(bool bDisable);
274 
277 
281  void DisableD3DCulling(bool bDisable);
283  bool IsD3DCullingDisabled();
284 
286  void DisableZWrite(bool bDisable);
288  bool IsZWriteDisabled();
289 
291  void EnableZWrite(bool bZWriteEnabled);
292 
294  void EnableD3DAlphaBlending(bool bEnable);
295 
297  void EnableZTest(bool bEnable, bool bForceSet = false);
299  bool IsZTestEnabled();
300 
304  void SetCullingMode(DWORD dwCullMode);
307  void SetCullingMode(bool bEnable);
308 
310  bool SetD3DFogState();
311 
313  bool IsUsingFullScreenGlow();
314 
316  void EnableFullScreenGlow( bool bEnable);
317 
319  inline bool IsReflectionRenderingEnabled(){return m_bEnableReflectionRendering;};
321  inline void EnableReflectionRendering(bool bEnabled){m_bEnableReflectionRendering = bEnabled;};
322 
327  void SetGlowTechnique(int nTech);
328 
333  int GetGlowTechnique();
334 
340  void SetGlowness(const Vector4& Glowness);
345  //change glowness type to vector4 --clayman 2011.7.19
346  const Vector4& GetGlowness();
347 
348  WaveEffect* GetScreenWaveEffect();
349  bool IsUsingScreenWaveEffect();
350  void EnableScreenWaveEffect(bool enable);
351  void SetScreenWaveTechnique(int nTech);
352  int GetScreenWaveTechnique();
353 
358  void SetMaxLocalLightsNum(int nNum);
359 
364  int GetMaxLocalLightsNum();
365 
367  IScene * GetScene(){return m_pScene;}
368 
370  void SetScene(IScene * pScene){m_pScene = pScene;}
371 
373  bool IsCurrentEffectValid() { return m_bEffectValid; }
374 
375  private:
376  // which scene object the effect manager is current serving
377  IScene * m_pScene;
378 
380  ClipPlaneState GetClipPlaneState();
382  bool BeginEffectFF(int nHandle);
383  bool BeginEffectShader(int nHandle, CEffectFile** pOutEffect = NULL);
384 
386  map<int, CEffectFile*> m_HandleMap;
388  int m_nCurrentEffect;
390  CEffectFile* m_pCurrentEffect;
391 
393  bool m_bEffectValid;
395  /*Matrix4 m_mWorld;
396  Matrix4 m_mView;
397  Matrix4 m_mProj;*/
398 
400  bool m_bEnableLocalLighting;
402  bool m_bUseFog;
404  bool m_bDisableD3DAlphaTesting;
406  bool m_bDisableZWrite;
408  bool m_bZEnable;
410  bool m_bUsingShadowMap;
412  bool m_bIsUsingFullScreenGlow;
413  //-clayman 2011.7.18
414  Vector4 m_colorGlowness;
416  int m_nGlowTechnique;
417 
418  int m_screenWaveTechnique;
419 
421  int m_nMaxLocalLightsNum;
422 
424  bool m_bDisableD3DCulling;
425 
427  bool m_bEnableReflectionRendering;
428 
429  ClipPlaneState m_ClipPlaneState;
430  bool m_bClipPlaneEnabled;
431  static const int MaxClipPlanesNum = 3;
432  Plane m_ClipPlaneWorldSpace[MaxClipPlanesNum];
433  Plane m_ClipPlaneClipSpace[MaxClipPlanesNum];
434 
435  WaveEffect* m_pWaveEffect;
436  bool m_enableScreenWaveEffect;
437 
438  int m_nEffectLevel;
439 
440  DWORD m_lastSamplerStates[8][16];
441  DWORD m_defaultSamplerStates[8][16];
442 
444  VertexDeclarationPtr m_pVertexDeclarations[MAX_DECLARATIONS_NUM];
445  int m_pVertexDeclarations_status[MAX_DECLARATIONS_NUM];
446 
447 //#ifdef USE_DIRECTX_RENDERER
448  CShadowMap* m_pShadowMap;
449 #ifdef USE_DIRECTX_RENDERER
450  CGlowEffect* m_pGlowEffect;
451 #endif
452  };
453 }
CEffectFile * GetEffectByName(const string &sName)
the returned effect may not be valid.
Definition: EffectManager.cpp:2970
void EnableZTest(bool bEnable, bool bForceSet=false)
enable ztest
Definition: EffectManager.cpp:689
EffectTechniques
Definition: EffectManager.h:136
fixed function pipeline
Definition: EffectManager.h:145
bool BeginEffect(int nHandle, CEffectFile **pOutEffect=NULL)
Start effect by handle.
Definition: EffectManager.cpp:1434
VERTEX_DECLARATION
predefined vertex declaration.
Definition: EffectManager.h:95
const Matrix4 & GetWorldTransform()
Get the current world transformation matrix which is used by the effect.
Definition: EffectManager.cpp:985
bool IsClipPlaneEnabled()
whether the clip plane is enabled
Definition: EffectManager.cpp:703
void EnableZWrite(bool bZWriteEnabled)
this function only takes effects when IsZWriteDisabled() is false.
Definition: EffectManager.cpp:681
4-dimensional homogeneous vector.
Definition: ParaVector4.h:10
Definition: combase.h:159
int GetGlowTechnique()
Get the glow technique.
Definition: EffectManager.cpp:362
void EnableD3DAlphaBlending(bool bEnable)
enable the D3D device&#39;s blending state
Definition: EffectManager.cpp:977
bool IsZWriteDisabled()
return true, if the alpha testing have been disabled.
Definition: EffectManager.cpp:676
Basic scene interface: implemented by the CSceneObject and CMiniScenegraph class. ...
Definition: IScene.h:12
int GetEffectHandle(CEffectFile *effectFile)
Get the integer handle to this asset.
Definition: EffectManager.cpp:906
different physics engine has different winding order.
Definition: EventBinding.h:32
void SetCullingMode(DWORD dwCullMode)
set the culling mode of the current effect file or the fixed function pipeline.
Definition: EffectManager.cpp:655
void SetAllEffectsTechnique(EffectTechniques nTech)
set all effect files to a specified technique.If the effect does not have the specified technique not...
Definition: EffectManager.cpp:2641
HRESULT SetVertexDeclaration(int nIndex)
Set declaration by id.
Definition: EffectManager.cpp:722
EffectTechniques GetCurrentEffectTechniqueType()
current technique in the effect file
Definition: EffectManager.cpp:447
void DisableD3DAlphaTesting(bool bDisable)
Definition: EffectManager.cpp:636
bool SetD3DFogState()
set d3d fog for the fixed function pipeline.
Definition: EffectManager.cpp:608
void EnableGlobalLighting(bool bEnable)
enable global sun lighting.
Definition: EffectManager.cpp:967
CShadowMap * GetShadowMap()
get the shadow map object.
Definition: EffectManager.cpp:310
bool IsD3DAlphaTestingDisabled()
return true, if the alpha testing have been disabled.
Definition: EffectManager.cpp:640
void applySurfaceMaterial(const ParaMaterial *pSurfaceMaterial, bool bUseGlobalAmbient=true)
both Fixed function (FF) pipeline and the programmable pipeline can call this function.
Definition: EffectManager.cpp:1063
Definition: minilua.c:225
void SetMaxLocalLightsNum(int nNum)
set maximum number of local lights per object.
Definition: EffectManager.cpp:298
void SetDefaultEffectMapping(int nLevel)
load the default handle to effect file mapping.
Definition: EffectManager.cpp:2667
CEffectFile * MapHandleToEffect(int nHandle, CEffectFile *pNewEffect)
Map a nHandle to effect object.
Definition: EffectManager.cpp:919
void applyFogParameters()
automatically apply fog.
Definition: EffectManager.cpp:1052
void DisableZWrite(bool bDisable)
disable z write.
Definition: EffectManager.cpp:671
AssetManager manages a set of asset entities of a certain type.
Definition: AssetManager.h:13
CEffectFile * CheckLoadEffect(int nHandle)
get a valid effect.
Definition: EffectManager.cpp:1420
rendering the model with shadow map
Definition: EffectManager.h:143
CEffectFile * GetEffectByHandle(int nHandle)
Return the effect object by its handle.
Definition: EffectManager.cpp:942
void EnableClipPlane(bool bEnable)
enable or disable user clip planes.
Definition: EffectManager.cpp:541
HRESULT SetSamplerState(int nStage, DWORD dwType, DWORD dwValue, bool bForceSet=false)
internally it will cache texture stage to prevent direct d3d calls
Definition: EffectManager.cpp:203
void DisableD3DCulling(bool bDisable)
Definition: EffectManager.cpp:645
void Cleanup()
delete all asset item from memory.
Definition: EffectManager.cpp:284
void SetClipPlane(DWORD Index, const float *pPlane, bool bClipSpace)
Sets the coefficients of a user-defined clipping plane for the device.
Definition: EffectManager.cpp:713
bool IsUsingFullScreenGlow()
whether full screen glow effect is used.
Definition: EffectManager.cpp:327
void applyLocalLightingData()
both Fixed function (FF) pipeline and the programmable pipeline can call this function.
Definition: EffectManager.cpp:1130
bool IsGlobalLightingEnabled()
whether global lighting is enabled.
Definition: EffectManager.cpp:973
const Vector4 & GetGlowness()
glowness controls the intensity of the glow in the full screen glow effect.
Definition: EffectManager.cpp:371
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
Definition: RenderCore.h:50
virtual void RendererRecreated()
callback of listening the event that renderer was recreated on Android/WP8 all opengl related id has ...
Definition: EffectManager.cpp:515
Defines a plane in 3D space.
Definition: ParaPlane.h:23
void EndEffect()
end the effect,this function actually does nothing.
Definition: EffectManager.cpp:2367
vertex element
Definition: VertexDeclarationOpenGL.h:21
shadow map generation technique
Definition: EffectManager.h:141
Definition: effect_file.h:323
bool IsD3DCullingDisabled()
return true, if the alpha testing have been disabled.
Definition: EffectManager.cpp:650
IScene * GetScene()
which scene object the effect manager is current serving
Definition: EffectManager.h:367
void EnableFog(bool bEnabled)
enable or disable fog.
Definition: EffectManager.cpp:981
bool IsUsingShadowMap()
whether shadow map is enabled
Definition: EffectManager.cpp:564
bool IsCurrentEffectValid()
if the last call to BeginEffect() returns false, this function will be set to false.
Definition: EffectManager.h:373
implementation of the full screen glow effect.
Definition: GlowEffect.h:10
some functions about shadow map
Definition: ShadowMap.h:8
void EnableReflectionRendering(bool bEnabled)
disable reflection texture, this is used when rendering in to reflection texture
Definition: EffectManager.h:321
bool IsReflectionRenderingEnabled()
disable reflection texture, this is used when rendering in to reflection texture
Definition: EffectManager.h:319
manager all effects file used by the game engine.
Definition: EffectManager.h:16
ClipPlaneState
clip plane state
Definition: EffectManager.h:198
DWORD GetDefaultSamplerState(int nStage, DWORD dwType)
default sampler state.
Definition: EffectManager.cpp:245
virtual bool DeleteEntity(AssetEntity *entity)
decrease the reference count on the entity, and if it is negative, the asset will be unloaded...
Definition: EffectManager.cpp:520
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
void SetDefaultSamplerState(int nStage, DWORD dwType, DWORD dwValue)
default sampler state.
Definition: EffectManager.cpp:241
Definition: RenderCore.h:34
const Matrix4 * GetTexViewProjMatrix()
get the shadow map&#39;s tex view projection matrix
Definition: EffectManager.cpp:569
void applyObjectLocalLighting(CBaseObject *pObj)
automatically apply local lighting to a scene object according to the bounding volume of the object...
Definition: EffectManager.cpp:1137
CGlowEffect * GetGlowEffect()
get the glow effect object.
Definition: EffectManager.cpp:376
int GetMaxLocalLightsNum()
get maximum number of local lights per object.
Definition: EffectManager.cpp:305
void SetGlowness(const Vector4 &Glowness)
glowness controls the intensity of the glow in the full screen glow effect.
Definition: EffectManager.cpp:367
void EnableFullScreenGlow(bool bEnable)
whether full screen glow effect is used.
Definition: EffectManager.cpp:332
void EnableClipPlaneImmediate(EffectManager::ClipPlaneState newState, int nIndex=0)
immediately change the device&#39;s clip plane settings if and only if it is different from the current s...
Definition: EffectManager.cpp:580
void EnableUsingShadowMap(bool bEnable)
enable shadow map
Definition: EffectManager.cpp:559
VertexDeclarationPtr GetVertexDeclaration(int nIndex)
Get declaration by id.
Definition: EffectManager.cpp:732
normal rendering
Definition: EffectManager.h:139
void SetScene(IScene *pScene)
which scene object the effect manager is current serving
Definition: EffectManager.h:370
void EnableLocalLighting(bool bEnable)
enable lighting.
Definition: EffectManager.cpp:958
Definition: WaveEffect.h:9
void UpdateD3DPipelineTransform(bool pWorld, bool pView, bool pProjection)
update the transformation for both the fixed and programmable pipeline.
Definition: EffectManager.cpp:998
void SetGlowTechnique(int nTech)
set the glow technique
Definition: EffectManager.cpp:344
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
bool IsLocalLightingEnabled()
whether lighting is enabled.
Definition: EffectManager.cpp:962
HRESULT GetSamplerState(int nStage, DWORD dwType, DWORD *pValue, bool bForceGet=false)
internally it will cache texture stage to prevent direct d3d calls
Definition: EffectManager.cpp:224
bool IsZTestEnabled()
return true, if the alpha testing have been disabled.
Definition: EffectManager.cpp:698
void EnableTextures(bool bEnable)
one occasion to disable textures is during the shadow pass.
Definition: EffectManager.cpp:628