gfxStateBlock.h
Engine/source/gfx/gfxStateBlock.h
Classes:
class
class
class
GFXStateBlockDesc defines a render state, which is then used to create a GFXStateBlock instance.
Public Typedefs
GFXStateBlockRef
Detailed Description
Public Typedefs
typedef StrongRefPtr< GFXStateBlock > GFXStateBlockRef
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _GFXSTATEBLOCK_H_ 25#define _GFXSTATEBLOCK_H_ 26 27#ifndef _REFBASE_H_ 28#include "core/util/refBase.h" 29#endif 30#ifndef _GFXENUMS_H_ 31#include "gfx/gfxEnums.h" 32#endif 33#ifndef _GFXRESOURCE_H_ 34#include "gfx/gfxResource.h" 35#endif 36#ifndef _COLOR_H_ 37#include "core/color.h" 38#endif 39 40 41struct GFXSamplerStateDesc 42{ 43 GFXTextureAddressMode addressModeU; 44 GFXTextureAddressMode addressModeV; 45 GFXTextureAddressMode addressModeW; 46 47 GFXTextureFilterType magFilter; 48 GFXTextureFilterType minFilter; 49 GFXTextureFilterType mipFilter; 50 51 GFXCmpFunc samplerFunc; 52 53 /// The maximum anisotropy used when one of the filter types 54 /// is set to anisotropic. 55 /// 56 /// Defaults to 1. 57 /// 58 /// @see GFXTextureFilterType 59 U32 maxAnisotropy; 60 61 /// Used to offset the mipmap selection by whole or 62 /// fractional amounts either postively or negatively. 63 /// 64 /// Defaults to zero. 65 F32 mipLODBias; 66 67 GFXSamplerStateDesc(); 68 69 /// Returns an modulate, wrap, and linear sampled state. 70 static GFXSamplerStateDesc getWrapLinear(); 71 72 /// Returns an modulate, wrap, and point sampled state. 73 static GFXSamplerStateDesc getWrapPoint(); 74 75 /// Returns an modulate, clamp, and linear sampled state. 76 static GFXSamplerStateDesc getClampLinear(); 77 78 /// Returns an modulate, clamp, and point sampled state. 79 static GFXSamplerStateDesc getClampPoint(); 80 81 bool operator==(const GFXSamplerStateDesc &b) const 82 { 83 return !dMemcmp(this, &b, sizeof(GFXSamplerStateDesc)); 84 } 85}; 86 87/// GFXStateBlockDesc defines a render state, which is then used to create a GFXStateBlock instance. 88struct GFXStateBlockDesc 89{ 90 // Blending 91 bool blendDefined; 92 bool blendEnable; 93 GFXBlend blendSrc; 94 GFXBlend blendDest; 95 GFXBlendOp blendOp; 96 97 /// @name Separate Alpha Blending 98 /// @{ 99 bool separateAlphaBlendDefined; 100 bool separateAlphaBlendEnable; 101 GFXBlend separateAlphaBlendSrc; 102 GFXBlend separateAlphaBlendDest; 103 GFXBlendOp separateAlphaBlendOp; 104 /// @} 105 106 // Alpha test 107 bool alphaDefined; 108 bool alphaTestEnable; 109 S32 alphaTestRef; 110 GFXCmpFunc alphaTestFunc; 111 112 // Color Writes 113 bool colorWriteDefined; 114 bool colorWriteRed; 115 bool colorWriteBlue; 116 bool colorWriteGreen; 117 bool colorWriteAlpha; 118 119 // Rasterizer 120 bool cullDefined; 121 GFXCullMode cullMode; 122 123 // Depth 124 bool zDefined; 125 bool zEnable; 126 bool zWriteEnable; 127 GFXCmpFunc zFunc; 128 F32 zBias; 129 F32 zSlopeBias; 130 131 // Stencil 132 bool stencilDefined; 133 bool stencilEnable; 134 GFXStencilOp stencilFailOp; 135 GFXStencilOp stencilZFailOp; 136 GFXStencilOp stencilPassOp; 137 GFXCmpFunc stencilFunc; 138 U32 stencilRef; 139 U32 stencilMask; 140 U32 stencilWriteMask; 141 142 bool vertexColorEnable; 143 144 GFXFillMode fillMode; 145 146 // Sampler states 147 bool samplersDefined; 148 GFXSamplerStateDesc samplers[GFX_TEXTURE_STAGE_COUNT]; 149 ColorI textureFactor; 150 151 GFXStateBlockDesc(); 152 153 /// Returns the hash value of this state description 154 U32 getHashValue() const; 155 156 /// Adds data from desc to this description, uses *defined parameters in desc to figure out 157 /// what blocks of state to actually copy from desc. 158 void addDesc( const GFXStateBlockDesc& desc ); 159 160 /// Returns a string that describes the options set (used by GFXStateBlock::describeSelf) 161 const String describeSelf() const; 162 163 /// Utility functions to make setting up stateblock descriptions less wordy. 164 void setCullMode( GFXCullMode m ); 165 166 /// Helpers for setting the fill modes. 167 void setFillModePoint() { fillMode = GFXFillPoint; } 168 void setFillModeWireframe() { fillMode = GFXFillWireframe; } 169 void setFillModeSolid() { fillMode = GFXFillSolid; } 170 171 void setZReadWrite( bool read, bool write = true ); 172 173 void setAlphaTest( bool enable, 174 GFXCmpFunc func = GFXCmpGreaterEqual, 175 S32 alphaRef = 0 ); 176 177 void setBlend( bool enable, 178 GFXBlend src = GFXBlendSrcAlpha, 179 GFXBlend dest = GFXBlendInvSrcAlpha, 180 GFXBlendOp op = GFXBlendOpAdd ); 181 182 void setSeparateAlphaBlend( bool enable, 183 GFXBlend src = GFXBlendOne, 184 GFXBlend dest = GFXBlendZero, 185 GFXBlendOp op = GFXBlendOpAdd ); 186 187 188 /// 189 void setColorWrites( bool red, bool green, bool blue, bool alpha ); 190}; 191 192class GFXStateBlock : public StrongRefBase, public GFXResource 193{ 194public: 195 virtual ~GFXStateBlock() { } 196 197 /// Returns the hash value of the desc that created this block 198 virtual U32 getHashValue() const = 0; 199 200 /// Returns a GFXStateBlockDesc that this block represents 201 virtual const GFXStateBlockDesc& getDesc() const = 0; 202 203 /// Default implementation for GFXResource::describeSelf 204 virtual const String describeSelf() const; 205}; 206 207typedef StrongRefPtr<GFXStateBlock> GFXStateBlockRef; 208 209#endif 210