renderImposterMgr.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 _IMPOSTERRENDERMGR_H_
  23. #define _IMPOSTERRENDERMGR_H_
  24. #ifndef _RENDERBINMANAGER_H_
  25. #include "renderInstance/renderBinManager.h"
  26. #endif
  27. #ifndef _GFXPRIMITIVEBUFFER_H_
  28. #include "gfx/gfxPrimitiveBuffer.h"
  29. #endif
  30. #ifndef _MATTEXTURETARGET_H_
  31. #include "materials/matTextureTarget.h"
  32. #endif
  33. #ifndef _TSLASTDETAIL_H_
  34. #include "ts/tsLastDetail.h"
  35. #endif
  36. class TSLastDetail;
  37. class GFXTextureObject;
  38. class RenderDeferredMgr;
  39. struct ImposterRenderInst;
  40. /*
  41. GFXDeclareVertexFormat( ImposterCorner )
  42. {
  43. /// billboard corner index
  44. float corner;
  45. };
  46. */
  47. /// This is a special render manager for processing single
  48. /// billboard imposters typically generated by the tsLastDetail
  49. /// class. It tries to render them in large batches with as
  50. /// few state changes as possible. For an example of use see
  51. /// TSLastDetail::render().
  52. class RenderImposterMgr : public RenderBinManager
  53. {
  54. protected:
  55. typedef RenderBinManager Parent;
  56. static const U32 smImposterBatchSize = 1000;
  57. static U32 smRendered;
  58. static U32 smBatches;
  59. static U32 smDrawCalls;
  60. static U32 smPolyCount;
  61. static U32 smRTChanges;
  62. ImposterState mBuffer[smImposterBatchSize*4];
  63. GFXPrimitiveBufferHandle mIB;
  64. //GFXVertexBufferHandle<ImposterCorner> mCornerVB;
  65. void _innerRender( const SceneRenderState *state, RenderDeferredMgr *deferredBin );
  66. void _renderDeferred( const SceneRenderState *state, RenderDeferredMgr *deferredBin, bool startDeferred );
  67. static bool _clearStats( GFXDevice::GFXDeviceEventType type );
  68. public:
  69. static const RenderInstType RIT_Imposter;
  70. static const RenderInstType RIT_ImposterBatch;
  71. RenderImposterMgr( F32 renderOrder = 1.0f, F32 processAddOrder = 1.0f );
  72. virtual ~RenderImposterMgr();
  73. // ConsoleObject
  74. DECLARE_CONOBJECT(RenderImposterMgr);
  75. static void initPersistFields();
  76. // RenderBinManager
  77. virtual void render( SceneRenderState *state );
  78. };
  79. /// This is a shared base render instance type TSLastDetail imposters.
  80. /// @see TSLastDetail
  81. /// @see RenderImposterMgr
  82. struct ImposterBaseRenderInst : public RenderInst
  83. {
  84. /// The material for this imposter.
  85. BaseMatInstance *mat;
  86. };
  87. /// This is a render instance for a single imposter.
  88. struct ImposterRenderInst : public ImposterBaseRenderInst
  89. {
  90. /// The imposter state.
  91. ImposterState state;
  92. /// Helper for setting this instance to a default state.
  93. void clear()
  94. {
  95. dMemset( this, 0, sizeof( ImposterRenderInst ) );
  96. type = RenderImposterMgr::RIT_Imposter;
  97. }
  98. };
  99. /// This is a render instance for a cached multiple imposter batch.
  100. struct ImposterBatchRenderInst : public ImposterBaseRenderInst
  101. {
  102. /// The pre-built vertex buffer batch of imposters.
  103. GFXVertexBufferHandleBase *vertBuff;
  104. /// Helper for setting this instance to a default state.
  105. void clear()
  106. {
  107. dMemset( this, 0, sizeof( ImposterBatchRenderInst ) );
  108. type = RenderImposterMgr::RIT_ImposterBatch;
  109. }
  110. };
  111. #endif // _TSIMPOSTERRENDERMGR_H_