tsRenderState.h 5.8 KB

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