tsRenderState.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 _TSRENDERDATA_H_
  23. #define _TSRENDERDATA_H_
  24. #ifndef _MMATRIX_H_
  25. #include "math/mMatrix.h"
  26. #endif
  27. #ifndef _GFXDEVICE_H_
  28. #include "gfx/gfxDevice.h"
  29. #endif
  30. class SceneRenderState;
  31. class GFXCubemap;
  32. class Frustum;
  33. class LightQuery;
  34. class TSShape;
  35. /// A simple class for passing render state through the pre-render pipeline.
  36. ///
  37. /// @section TSRenderState_intro Introduction
  38. ///
  39. /// TSRenderState holds on to certain pieces of data that may be
  40. /// set at the preparation stage of rendering (prepRengerImage etc.)
  41. /// which are needed further along in the process of submitting
  42. /// a render instance for later rendering by the RenderManager.
  43. ///
  44. /// It was created to clean up and refactor the DTS rendering
  45. /// from having a large number of static data that would be used
  46. /// in varying places. These statics were confusing and would often
  47. /// cause problems when not properly cleaned up by various objects after
  48. /// submitting their RenderInstances.
  49. ///
  50. /// @section TSRenderState_functionality What Does TSRenderState Do?
  51. ///
  52. /// TSRenderState is a simple class that performs the function of passing along
  53. /// (from the prep function(s) to the actual submission) the data
  54. /// needed for the desired state of rendering.
  55. ///
  56. /// @section TSRenderState_example Usage Example
  57. ///
  58. /// TSRenderState is very easy to use. Merely create a TSRenderState object (in prepRenderImage usually)
  59. /// and set any of the desired data members (SceneRenderState, camera transform etc.), and pass the address of
  60. /// your TSRenderState to your render function.
  61. ///
  62. class TSRenderState
  63. {
  64. protected:
  65. const SceneRenderState *mState;
  66. GFXCubemap *mCubemap;
  67. /// Used to override the normal
  68. /// fade value of an object.
  69. /// This is multiplied by the current
  70. /// fade value of the instance
  71. /// to gain the resulting visibility fade (see TSMesh::render()).
  72. F32 mFadeOverride;
  73. /// These are used in some places
  74. /// TSShapeInstance::render, however,
  75. /// it appears they are never set to anything
  76. /// other than false. We provide methods
  77. /// for setting them regardless.
  78. bool mNoRenderTranslucent;
  79. bool mNoRenderNonTranslucent;
  80. /// A generic hint value passed from the game
  81. /// code down to the material for use by shader
  82. /// features.
  83. void *mMaterialHint;
  84. /// An optional object space frustum used to cull
  85. /// subobjects within the shape.
  86. const Frustum *mCuller;
  87. /// Use the origin point of the mesh for distance
  88. /// sorting for transparency instead of the nearest
  89. /// bounding box point.
  90. bool mUseOriginSort;
  91. /// The lighting query object used if any materials
  92. /// are forward lit and need lights.
  93. LightQuery *mLightQuery;
  94. // The accumulation texture provided by an accumulation
  95. // volume. This is passed down per-object.
  96. GFXTextureObject* mAccuTex;
  97. /// List of matrices to use for hardware skinning
  98. MatrixF *mNodeTransforms;
  99. /// Count of matrices in the mNodeTransforms list
  100. U32 mNodeTransformCount;
  101. public:
  102. TSRenderState();
  103. TSRenderState( const TSRenderState &state );
  104. /// @name Get/Set methods.
  105. /// @{
  106. ///@see mState
  107. const SceneRenderState* getSceneState() const { return mState; }
  108. void setSceneState( const SceneRenderState *state ) { mState = state; }
  109. ///@see mCubemap
  110. GFXCubemap* getCubemap() const { return mCubemap; }
  111. void setCubemap( GFXCubemap *cubemap ) { mCubemap = cubemap; }
  112. ///@see mFadeOverride
  113. F32 getFadeOverride() const { return mFadeOverride; }
  114. void setFadeOverride( F32 fade ) { mFadeOverride = fade; }
  115. ///@see mNoRenderTranslucent
  116. bool isNoRenderTranslucent() const { return mNoRenderTranslucent; }
  117. void setNoRenderTranslucent( bool noRenderTrans ) { mNoRenderTranslucent = noRenderTrans; }
  118. ///@see mNoRenderNonTranslucent
  119. bool isNoRenderNonTranslucent() const { return mNoRenderNonTranslucent; }
  120. void setNoRenderNonTranslucent( bool noRenderNonTrans ) { mNoRenderNonTranslucent = noRenderNonTrans; }
  121. ///@see mMaterialHint
  122. void* getMaterialHint() const { return mMaterialHint; }
  123. void setMaterialHint( void *materialHint ) { mMaterialHint = materialHint; }
  124. ///@see mCuller
  125. const Frustum* getCuller() const { return mCuller; }
  126. void setCuller( const Frustum *culler ) { mCuller = culler; }
  127. ///@see mUseOriginSort
  128. void setOriginSort( bool enable ) { mUseOriginSort = enable; }
  129. bool useOriginSort() const { return mUseOriginSort; }
  130. ///@see mLightQuery
  131. void setLightQuery( LightQuery *query ) { mLightQuery = query; }
  132. LightQuery* getLightQuery() const { return mLightQuery; }
  133. ///@see mAccuTex
  134. void setAccuTex( GFXTextureObject* query ) { mAccuTex = query; }
  135. GFXTextureObject* getAccuTex() const { return mAccuTex; }
  136. ///@ see mNodeTransforms, mNodeTransformCount
  137. void setNodeTransforms(MatrixF *list, U32 count) { mNodeTransforms = list; mNodeTransformCount = count; }
  138. void getNodeTransforms(MatrixF **list, U32 *count) const { *list = mNodeTransforms; *count = mNodeTransformCount; }
  139. /// @}
  140. };
  141. #endif // _TSRENDERDATA_H_