123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #ifndef _GFXSTATEBLOCK_H_
- #define _GFXSTATEBLOCK_H_
- #ifndef _REFBASE_H_
- #include "core/util/refBase.h"
- #endif
- #ifndef _GFXENUMS_H_
- #include "gfx/gfxEnums.h"
- #endif
- #ifndef _GFXRESOURCE_H_
- #include "gfx/gfxResource.h"
- #endif
- #ifndef _COLOR_H_
- #include "core/color.h"
- #endif
- struct GFXSamplerStateDesc
- {
- GFXTextureAddressMode addressModeU;
- GFXTextureAddressMode addressModeV;
- GFXTextureAddressMode addressModeW;
- GFXTextureFilterType magFilter;
- GFXTextureFilterType minFilter;
- GFXTextureFilterType mipFilter;
- GFXCmpFunc samplerFunc;
- /// The maximum anisotropy used when one of the filter types
- /// is set to anisotropic.
- ///
- /// Defaults to 1.
- ///
- /// @see GFXTextureFilterType
- U32 maxAnisotropy;
- /// Used to offset the mipmap selection by whole or
- /// fractional amounts either postively or negatively.
- ///
- /// Defaults to zero.
- F32 mipLODBias;
- GFXSamplerStateDesc();
- /// Returns an modulate, wrap, and linear sampled state.
- static GFXSamplerStateDesc getWrapLinear();
- /// Returns an modulate, wrap, and point sampled state.
- static GFXSamplerStateDesc getWrapPoint();
- /// Returns an modulate, clamp, and linear sampled state.
- static GFXSamplerStateDesc getClampLinear();
- /// Returns an modulate, clamp, and point sampled state.
- static GFXSamplerStateDesc getClampPoint();
- bool operator==(const GFXSamplerStateDesc &b) const
- {
- return !dMemcmp(this, &b, sizeof(GFXSamplerStateDesc));
- }
- };
- /// GFXStateBlockDesc defines a render state, which is then used to create a GFXStateBlock instance.
- struct GFXStateBlockDesc
- {
- // Blending
- bool blendDefined;
- bool blendEnable;
- GFXBlend blendSrc;
- GFXBlend blendDest;
- GFXBlendOp blendOp;
- /// @name Separate Alpha Blending
- /// @{
- bool separateAlphaBlendDefined;
- bool separateAlphaBlendEnable;
- GFXBlend separateAlphaBlendSrc;
- GFXBlend separateAlphaBlendDest;
- GFXBlendOp separateAlphaBlendOp;
- /// @}
- // Alpha test
- bool alphaDefined;
- bool alphaTestEnable;
- S32 alphaTestRef;
- GFXCmpFunc alphaTestFunc;
- // Color Writes
- bool colorWriteDefined;
- bool colorWriteRed;
- bool colorWriteBlue;
- bool colorWriteGreen;
- bool colorWriteAlpha;
- // Rasterizer
- bool cullDefined;
- GFXCullMode cullMode;
- // Depth
- bool zDefined;
- bool zEnable;
- bool zWriteEnable;
- GFXCmpFunc zFunc;
- F32 zBias;
- F32 zSlopeBias;
- // Stencil
- bool stencilDefined;
- bool stencilEnable;
- GFXStencilOp stencilFailOp;
- GFXStencilOp stencilZFailOp;
- GFXStencilOp stencilPassOp;
- GFXCmpFunc stencilFunc;
- U32 stencilRef;
- U32 stencilMask;
- U32 stencilWriteMask;
- bool vertexColorEnable;
- GFXFillMode fillMode;
- // Sampler states
- bool samplersDefined;
- GFXSamplerStateDesc samplers[GFX_TEXTURE_STAGE_COUNT];
- ColorI textureFactor;
- GFXStateBlockDesc();
- /// Returns the hash value of this state description
- U32 getHashValue() const;
- /// Adds data from desc to this description, uses *defined parameters in desc to figure out
- /// what blocks of state to actually copy from desc.
- void addDesc( const GFXStateBlockDesc& desc );
- /// Returns a string that describes the options set (used by GFXStateBlock::describeSelf)
- const String describeSelf() const;
- /// Utility functions to make setting up stateblock descriptions less wordy.
- void setCullMode( GFXCullMode m );
- /// Helpers for setting the fill modes.
- void setFillModePoint() { fillMode = GFXFillPoint; }
- void setFillModeWireframe() { fillMode = GFXFillWireframe; }
- void setFillModeSolid() { fillMode = GFXFillSolid; }
- void setZReadWrite( bool read, bool write = true );
- void setAlphaTest( bool enable,
- GFXCmpFunc func = GFXCmpGreaterEqual,
- S32 alphaRef = 0 );
- void setBlend( bool enable,
- GFXBlend src = GFXBlendSrcAlpha,
- GFXBlend dest = GFXBlendInvSrcAlpha,
- GFXBlendOp op = GFXBlendOpAdd );
- void setSeparateAlphaBlend( bool enable,
- GFXBlend src = GFXBlendOne,
- GFXBlend dest = GFXBlendZero,
- GFXBlendOp op = GFXBlendOpAdd );
- ///
- void setColorWrites( bool red, bool green, bool blue, bool alpha );
- };
- class GFXStateBlock : public StrongRefBase, public GFXResource
- {
- public:
- virtual ~GFXStateBlock() { }
- /// Returns the hash value of the desc that created this block
- virtual U32 getHashValue() const = 0;
- /// Returns a GFXStateBlockDesc that this block represents
- virtual const GFXStateBlockDesc& getDesc() const = 0;
- /// Default implementation for GFXResource::describeSelf
- virtual const String describeSelf() const;
- };
- typedef StrongRefPtr<GFXStateBlock> GFXStateBlockRef;
- #endif
|