postEffectManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _POSTEFFECTMANAGER_H_
  23. #define _POSTEFFECTMANAGER_H_
  24. #ifndef _GFXDEVICE_H_
  25. #include "gfx/gfxDevice.h"
  26. #endif
  27. #ifndef _TVECTOR_H_
  28. #include "core/util/tVector.h"
  29. #endif
  30. #ifndef _TDICTIONARY_H_
  31. #include "core/util/tDictionary.h"
  32. #endif
  33. #ifndef _TSINGLETON_H_
  34. #include "core/util/tSingleton.h"
  35. #endif
  36. #ifndef _POSTEFFECTCOMMON_H_
  37. #include "postFx/postEffectCommon.h"
  38. #endif
  39. class PostEffect;
  40. class RenderBinManager;
  41. class SceneRenderState;
  42. class SceneManager;
  43. class PostEffectManager
  44. {
  45. protected:
  46. friend class PostEffect;
  47. typedef Vector<PostEffect*> EffectVector;
  48. typedef Map<String,EffectVector> EffectMap;
  49. /// A global flag for toggling the post effect system. It
  50. /// is tied to the $pref::enablePostEffects preference.
  51. static bool smRenderEffects;
  52. EffectVector mEndOfFrameList;
  53. EffectVector mAfterDiffuseList;
  54. EffectMap mAfterBinMap;
  55. EffectMap mBeforeBinMap;
  56. /// A copy of the last requested back buffer.
  57. GFXTexHandle mBackBufferCopyTex;
  58. //GFXTexHandle mBackBufferFloatCopyTex;
  59. /// The target at the time the last back buffer
  60. /// was copied. Used to detect the need to recopy.
  61. GFXTarget *mLastBackBufferTarget;
  62. // State for current frame and last frame
  63. bool mFrameStateSwitch;
  64. PFXFrameState mFrameState[2];
  65. bool _handleDeviceEvent( GFXDevice::GFXDeviceEventType evt );
  66. void _handleBinEvent( RenderBinManager *bin,
  67. const SceneRenderState* sceneState,
  68. bool isBinStart );
  69. ///
  70. void _onPostRenderPass( SceneManager *sceneGraph, const SceneRenderState *sceneState );
  71. // Helper method
  72. void _updateResources();
  73. ///
  74. static S32 _effectPrioritySort( PostEffect* const*e1, PostEffect* const*e2 );
  75. bool _addEffect( PostEffect *effect );
  76. bool _removeEffect( PostEffect *effect );
  77. public:
  78. PostEffectManager();
  79. virtual ~PostEffectManager();
  80. void renderEffects( const SceneRenderState *state,
  81. const PFXRenderTime effectTiming,
  82. const String &binName = String::EmptyString );
  83. /// Returns the current back buffer texture taking
  84. /// a copy of if the target has changed or the buffer
  85. /// was previously released.
  86. GFXTextureObject* getBackBufferTex();
  87. /// Releases the current back buffer so that a
  88. /// new copy is made on the next request.
  89. void releaseBackBufferTex();
  90. /*
  91. bool submitEffect( PostEffect *effect, const PFXRenderTime renderTime = PFXDefaultRenderTime, const GFXRenderBinTypes afterBin = GFXBin_DefaultPostProcessBin )
  92. {
  93. return _addEntry( effect, false, renderTime, afterBin );
  94. }
  95. */
  96. // State interface
  97. const PFXFrameState &getFrameState() const { return mFrameState[mFrameStateSwitch]; }
  98. const PFXFrameState &getLastFrameState() const { return mFrameState[!mFrameStateSwitch]; }
  99. void setFrameState(const PFXFrameState& newState) { mFrameState[mFrameStateSwitch] = newState; }
  100. void setFrameMatrices( const MatrixF &worldToCamera, const MatrixF &cameraToScreen );
  101. // For ManagedSingleton.
  102. static const char* getSingletonName() { return "PostEffectManager"; }
  103. void dumpActivePostFX();
  104. };
  105. /// Returns the PostEffectManager singleton.
  106. #define PFXMGR ManagedSingleton<PostEffectManager>::instance()
  107. #endif // _POSTEFFECTMANAGER_H_