renderTexTargetBinManager.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 _TEXTARGETBIN_MGR_H_
  23. #define _TEXTARGETBIN_MGR_H_
  24. #ifndef _RENDERBINMANAGER_H_
  25. #include "renderInstance/renderBinManager.h"
  26. #endif
  27. #ifndef _MATTEXTURETARGET_H_
  28. #include "materials/matTextureTarget.h"
  29. #endif
  30. class ConditionerFeature;
  31. class RenderTexTargetBinManager : public RenderBinManager
  32. {
  33. typedef RenderBinManager Parent;
  34. public:
  35. static const GFXFormat DefaultTargetFormat = GFXFormatR8G8B8A8;
  36. static const U32 DefaultTargetChainLength = 1;
  37. static const U32 DefaultTargetSize = 256;
  38. enum TargetSizeType
  39. {
  40. WindowSize = 0,
  41. WindowSizeScaled,
  42. FixedSize
  43. };
  44. public:
  45. RenderTexTargetBinManager( const RenderInstType &ritype = RenderPassManager::RIT_Mesh,
  46. F32 renderOrder = 1.0f,
  47. F32 processAddOrder = 1.0f,
  48. const GFXFormat targetFormat = DefaultTargetFormat,
  49. const Point2I &targetSize = Point2I(DefaultTargetSize, DefaultTargetSize),
  50. const U32 targetChainLength = DefaultTargetChainLength);
  51. virtual ~RenderTexTargetBinManager();
  52. virtual bool setTargetSize(const Point2I &newTargetSize);
  53. virtual GFXTextureObject* getTargetTexture( U32 mrtIndex, S32 chainIndex = -1 ) const;
  54. /// Force a target update
  55. virtual bool updateTargets() { return _updateTargets(); }
  56. void setTargetFormatConsole(const S32 &fmt) { setTargetFormat(GFXFormat(fmt)); }
  57. virtual bool setTargetFormat(const GFXFormat &newTargetFormat);
  58. S32 getTargetFormatConsole() { return getTargetFormat(); }
  59. virtual const GFXFormat &getTargetFormat() const { return mTargetFormat; }
  60. virtual void setTargetChainLength(const U32 chainLength);
  61. virtual U32 getTargetChainLength() const { return mTargetChainLength; }
  62. DECLARE_CONOBJECT(RenderTexTargetBinManager);
  63. static void initPersistFields();
  64. virtual bool onAdd();
  65. protected:
  66. NamedTexTarget mNamedTarget;
  67. GFXFormat mTargetFormat;
  68. Point2I mTargetSize;
  69. Point2F mTargetScale;
  70. //RectI mTargetViewport;
  71. TargetSizeType mTargetSizeType;
  72. U32 mTargetChainLength;
  73. U32 mTargetChainIdx;
  74. U32 mNumRenderTargets;
  75. GFXTextureTargetRef *mTargetChain;
  76. GFXTexHandle **mTargetChainTextures;
  77. #ifndef TORQUE_SHIPPING
  78. bool m_NeedsOnPostRender;
  79. #endif
  80. bool mPreserve;
  81. virtual bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event);
  82. virtual GFXTextureTargetRef _getTextureTarget(const U32 idx = 0);
  83. /// Pushes the active render target, and sets itself as a render target. The
  84. /// target is then cleared using 'mTargetClearColor', viewport is set properly,
  85. /// and true is returned, and '_onPostRender' must be called after rendering
  86. /// is complete. If the return value is false, than '_onPostRender'
  87. /// should not be called.
  88. ///
  89. /// @param preserve If set to true, the contents of the current render target
  90. // will be the same when _onPostRender is called. Otherwise
  91. // the contents are undefined on console platforms.
  92. virtual bool _onPreRender(SceneRenderState * state, bool preserve = false);
  93. /// Resolves the active render target, pops the render target from _onPreRender, and sets debug info.
  94. virtual void _onPostRender();
  95. virtual bool _updateTargets();
  96. virtual bool _setupTargets();
  97. virtual void _teardownTargets();
  98. /// The callback used to get texture events.
  99. /// @see GFXTextureManager::addEventDelegate
  100. void _onTextureEvent( GFXTexCallbackCode code );
  101. };
  102. typedef RenderTexTargetBinManager::TargetSizeType RenderTexTargetSize;
  103. DefineEnumType( RenderTexTargetSize );
  104. #endif // _TEXTARGETBIN_MGR_H_