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 /// The maximum anisotropy used when one of the filter types 52 /// is set to anisotropic. 53 /// 54 /// Defaults to 1. 55 /// 56 /// @see GFXTextureFilterType 57 U32 maxAnisotropy; 58 59 /// Used to offset the mipmap selection by whole or 60 /// fractional amounts either postively or negatively. 61 /// 62 /// Defaults to zero. 63 F32 mipLODBias; 64 65 GFXTextureOp textureColorOp; 66 67 GFXTextureOp alphaOp; 68 GFXTextureArgument alphaArg1; 69 GFXTextureArgument alphaArg2; 70 GFXTextureArgument alphaArg3; 71 72 GFXTextureArgument colorArg1; 73 GFXTextureArgument colorArg2; 74 GFXTextureArgument colorArg3; 75 76 GFXTextureArgument resultArg; 77 78 GFXTextureTransformFlags textureTransform; 79 80 GFXSamplerStateDesc(); 81 82 /// Returns an modulate, wrap, and linear sampled state. 83 static GFXSamplerStateDesc getWrapLinear(); 84 85 /// Returns an modulate, wrap, and point sampled state. 86 static GFXSamplerStateDesc getWrapPoint(); 87 88 /// Returns an modulate, clamp, and linear sampled state. 89 static GFXSamplerStateDesc getClampLinear(); 90 91 /// Returns an modulate, clamp, and point sampled state. 92 static GFXSamplerStateDesc getClampPoint(); 93 94 bool operator==(const GFXSamplerStateDesc &b) const 95 { 96 return !dMemcmp(this, &b, sizeof(GFXSamplerStateDesc)); 97 } 98}; 99 100/// GFXStateBlockDesc defines a render state, which is then used to create a GFXStateBlock instance. 101struct GFXStateBlockDesc 102{ 103 // Blending 104 bool blendDefined; 105 bool blendEnable; 106 GFXBlend blendSrc; 107 GFXBlend blendDest; 108 GFXBlendOp blendOp; 109 110 /// @name Separate Alpha Blending 111 /// @{ 112 bool separateAlphaBlendDefined; 113 bool separateAlphaBlendEnable; 114 GFXBlend separateAlphaBlendSrc; 115 GFXBlend separateAlphaBlendDest; 116 GFXBlendOp separateAlphaBlendOp; 117 /// @} 118 119 // Alpha test 120 bool alphaDefined; 121 bool alphaTestEnable; 122 S32 alphaTestRef; 123 GFXCmpFunc alphaTestFunc; 124 125 // Color Writes 126 bool colorWriteDefined; 127 bool colorWriteRed; 128 bool colorWriteBlue; 129 bool colorWriteGreen; 130 bool colorWriteAlpha; 131 132 // Rasterizer 133 bool cullDefined; 134 GFXCullMode cullMode; 135 136 // Depth 137 bool zDefined; 138 bool zEnable; 139 bool zWriteEnable; 140 GFXCmpFunc zFunc; 141 F32 zBias; 142 F32 zSlopeBias; 143 144 // Stencil 145 bool stencilDefined; 146 bool stencilEnable; 147 GFXStencilOp stencilFailOp; 148 GFXStencilOp stencilZFailOp; 149 GFXStencilOp stencilPassOp; 150 GFXCmpFunc stencilFunc; 151 U32 stencilRef; 152 U32 stencilMask; 153 U32 stencilWriteMask; 154 155 // FF lighting 156 bool ffLighting; 157 158 bool vertexColorEnable; 159 160 GFXFillMode fillMode; 161 162 // Sampler states 163 bool samplersDefined; 164 GFXSamplerStateDesc samplers[TEXTURE_STAGE_COUNT]; 165 ColorI textureFactor; 166 167 GFXStateBlockDesc(); 168 169 /// Returns the hash value of this state description 170 U32 getHashValue() const; 171 172 /// Adds data from desc to this description, uses *defined parameters in desc to figure out 173 /// what blocks of state to actually copy from desc. 174 void addDesc( const GFXStateBlockDesc& desc ); 175 176 /// Returns a string that describes the options set (used by GFXStateBlock::describeSelf) 177 const String describeSelf() const; 178 179 /// Utility functions to make setting up stateblock descriptions less wordy. 180 void setCullMode( GFXCullMode m ); 181 182 /// Helpers for setting the fill modes. 183 void setFillModePoint() { fillMode = GFXFillPoint; } 184 void setFillModeWireframe() { fillMode = GFXFillWireframe; } 185 void setFillModeSolid() { fillMode = GFXFillSolid; } 186 187 void setZReadWrite( bool read, bool write = true ); 188 189 void setAlphaTest( bool enable, 190 GFXCmpFunc func = GFXCmpGreaterEqual, 191 S32 alphaRef = 0 ); 192 193 void setBlend( bool enable, 194 GFXBlend src = GFXBlendSrcAlpha, 195 GFXBlend dest = GFXBlendInvSrcAlpha, 196 GFXBlendOp op = GFXBlendOpAdd ); 197 198 void setSeparateAlphaBlend( bool enable, 199 GFXBlend src = GFXBlendOne, 200 GFXBlend dest = GFXBlendZero, 201 GFXBlendOp op = GFXBlendOpAdd ); 202 203 204 /// 205 void setColorWrites( bool red, bool green, bool blue, bool alpha ); 206}; 207 208class GFXStateBlock : public StrongRefBase, public GFXResource 209{ 210public: 211 virtual ~GFXStateBlock() { } 212 213 /// Returns the hash value of the desc that created this block 214 virtual U32 getHashValue() const = 0; 215 216 /// Returns a GFXStateBlockDesc that this block represents 217 virtual const GFXStateBlockDesc& getDesc() const = 0; 218 219 /// Default implementation for GFXResource::describeSelf 220 virtual const String describeSelf() const; 221}; 222 223typedef StrongRefPtr<GFXStateBlock> GFXStateBlockRef; 224 225#endif 226
