gfxStateBlock.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 _GFXSTATEBLOCK_H_
  23. #define _GFXSTATEBLOCK_H_
  24. #ifndef _REFBASE_H_
  25. #include "core/util/refBase.h"
  26. #endif
  27. #ifndef _GFXENUMS_H_
  28. #include "gfx/gfxEnums.h"
  29. #endif
  30. #ifndef _GFXRESOURCE_H_
  31. #include "gfx/gfxResource.h"
  32. #endif
  33. #ifndef _COLOR_H_
  34. #include "core/color.h"
  35. #endif
  36. struct GFXSamplerStateDesc
  37. {
  38. GFXTextureAddressMode addressModeU;
  39. GFXTextureAddressMode addressModeV;
  40. GFXTextureAddressMode addressModeW;
  41. GFXTextureFilterType magFilter;
  42. GFXTextureFilterType minFilter;
  43. GFXTextureFilterType mipFilter;
  44. /// The maximum anisotropy used when one of the filter types
  45. /// is set to anisotropic.
  46. ///
  47. /// Defaults to 1.
  48. ///
  49. /// @see GFXTextureFilterType
  50. U32 maxAnisotropy;
  51. /// Used to offset the mipmap selection by whole or
  52. /// fractional amounts either postively or negatively.
  53. ///
  54. /// Defaults to zero.
  55. F32 mipLODBias;
  56. GFXTextureOp textureColorOp;
  57. GFXTextureOp alphaOp;
  58. GFXTextureArgument alphaArg1;
  59. GFXTextureArgument alphaArg2;
  60. GFXTextureArgument alphaArg3;
  61. GFXTextureArgument colorArg1;
  62. GFXTextureArgument colorArg2;
  63. GFXTextureArgument colorArg3;
  64. GFXTextureArgument resultArg;
  65. GFXTextureTransformFlags textureTransform;
  66. GFXSamplerStateDesc();
  67. /// Returns an modulate, wrap, and linear sampled state.
  68. static GFXSamplerStateDesc getWrapLinear();
  69. /// Returns an modulate, wrap, and point sampled state.
  70. static GFXSamplerStateDesc getWrapPoint();
  71. /// Returns an modulate, clamp, and linear sampled state.
  72. static GFXSamplerStateDesc getClampLinear();
  73. /// Returns an modulate, clamp, and point sampled state.
  74. static GFXSamplerStateDesc getClampPoint();
  75. };
  76. /// GFXStateBlockDesc defines a render state, which is then used to create a GFXStateBlock instance.
  77. struct GFXStateBlockDesc
  78. {
  79. // Blending
  80. bool blendDefined;
  81. bool blendEnable;
  82. GFXBlend blendSrc;
  83. GFXBlend blendDest;
  84. GFXBlendOp blendOp;
  85. /// @name Separate Alpha Blending
  86. /// @{
  87. bool separateAlphaBlendDefined;
  88. bool separateAlphaBlendEnable;
  89. GFXBlend separateAlphaBlendSrc;
  90. GFXBlend separateAlphaBlendDest;
  91. GFXBlendOp separateAlphaBlendOp;
  92. /// @}
  93. // Alpha test
  94. bool alphaDefined;
  95. bool alphaTestEnable;
  96. S32 alphaTestRef;
  97. GFXCmpFunc alphaTestFunc;
  98. // Color Writes
  99. bool colorWriteDefined;
  100. bool colorWriteRed;
  101. bool colorWriteBlue;
  102. bool colorWriteGreen;
  103. bool colorWriteAlpha;
  104. // Rasterizer
  105. bool cullDefined;
  106. GFXCullMode cullMode;
  107. // Depth
  108. bool zDefined;
  109. bool zEnable;
  110. bool zWriteEnable;
  111. GFXCmpFunc zFunc;
  112. F32 zBias;
  113. F32 zSlopeBias;
  114. // Stencil
  115. bool stencilDefined;
  116. bool stencilEnable;
  117. GFXStencilOp stencilFailOp;
  118. GFXStencilOp stencilZFailOp;
  119. GFXStencilOp stencilPassOp;
  120. GFXCmpFunc stencilFunc;
  121. U32 stencilRef;
  122. U32 stencilMask;
  123. U32 stencilWriteMask;
  124. // FF lighting
  125. bool ffLighting;
  126. bool vertexColorEnable;
  127. GFXFillMode fillMode;
  128. // Sampler states
  129. bool samplersDefined;
  130. GFXSamplerStateDesc samplers[TEXTURE_STAGE_COUNT];
  131. ColorI textureFactor;
  132. GFXStateBlockDesc();
  133. /// Returns the hash value of this state description
  134. U32 getHashValue() const;
  135. /// Adds data from desc to this description, uses *defined parameters in desc to figure out
  136. /// what blocks of state to actually copy from desc.
  137. void addDesc( const GFXStateBlockDesc& desc );
  138. /// Returns a string that describes the options set (used by GFXStateBlock::describeSelf)
  139. const String describeSelf() const;
  140. /// Utility functions to make setting up stateblock descriptions less wordy.
  141. void setCullMode( GFXCullMode m );
  142. /// Helpers for setting the fill modes.
  143. void setFillModePoint() { fillMode = GFXFillPoint; }
  144. void setFillModeWireframe() { fillMode = GFXFillWireframe; }
  145. void setFillModeSolid() { fillMode = GFXFillSolid; }
  146. void setZReadWrite( bool read, bool write = true );
  147. void setAlphaTest( bool enable,
  148. GFXCmpFunc func = GFXCmpGreaterEqual,
  149. S32 alphaRef = 0 );
  150. void setBlend( bool enable,
  151. GFXBlend src = GFXBlendSrcAlpha,
  152. GFXBlend dest = GFXBlendInvSrcAlpha,
  153. GFXBlendOp op = GFXBlendOpAdd );
  154. void setSeparateAlphaBlend( bool enable,
  155. GFXBlend src = GFXBlendOne,
  156. GFXBlend dest = GFXBlendZero,
  157. GFXBlendOp op = GFXBlendOpAdd );
  158. ///
  159. void setColorWrites( bool red, bool green, bool blue, bool alpha );
  160. };
  161. class GFXStateBlock : public StrongRefBase, public GFXResource
  162. {
  163. public:
  164. virtual ~GFXStateBlock() { }
  165. /// Returns the hash value of the desc that created this block
  166. virtual U32 getHashValue() const = 0;
  167. /// Returns a GFXStateBlockDesc that this block represents
  168. virtual const GFXStateBlockDesc& getDesc() const = 0;
  169. /// Default implementation for GFXResource::describeSelf
  170. virtual const String describeSelf() const;
  171. };
  172. typedef StrongRefPtr<GFXStateBlock> GFXStateBlockRef;
  173. #endif