tsRenderState.h 6.6 KB

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