Guest User

stategroup.h

a guest
May 6th, 2016
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.34 KB | None | 0 0
  1.  
  2. struct StateGroup
  3. {
  4.     u32 SizeInBytes();
  5.     void Release();
  6. };
  7.  
  8. typedef bool bool4[4];
  9.  
  10. struct DepthStencilState
  11. {
  12.     struct DepthState
  13.     {
  14.         bool enable, write;
  15.         ComparisonFunc::Type func;
  16.         bool depthBoundsTest;
  17.         float depthBoundsMin, depthBoundsMax;
  18.     } depth;
  19.     struct StencilState
  20.     {
  21.         bool enable, twoSided;
  22.         u8 ref, writeMask, readMask;
  23.         struct Face
  24.         {
  25.             ComparisonFunc::Type func;
  26.             StencilOperation::Type pass;
  27.             StencilOperation::Type fail;
  28.             StencilOperation::Type zFail;
  29.         } front, back;
  30.     } stencil;
  31. };
  32.  
  33. struct BlendState
  34. {
  35.     bool4 writeMask;
  36.     bool blendEnable;
  37.     bool separateAlpha;
  38.     struct BlendConfig
  39.     {
  40.         BlendFactor::Type src;
  41.         BlendFactor::Type dst;
  42.         BlendEquation::Type op;
  43.     } color, alpha;
  44.     Color4f constant;
  45.     u32 customSampleMask;//0 is treated as 0xffffffff
  46.     bool alphaToCoverage;
  47. };
  48.  
  49. struct MrtBlendState
  50. {
  51.     u32 numTargets;
  52.     bool4 writeMask[8];
  53.     struct MrtConfig
  54.     {
  55.         bool blendEnable;
  56.         bool separateAlpha;
  57.         BlendState::BlendConfig color, alpha;
  58.     };
  59.     MrtConfig configs[8];
  60.     Color4f constant;
  61.     u32 customSampleMask;//0 is treated as 0xffffffff
  62.     bool alphaToCoverage;
  63.     PlatformBlendState platform;
  64. };
  65.  
  66. struct VertexState
  67. {
  68.     StreamFormatId format;
  69.     BufferId streams[eiGX_MAX_VERTEX_STREAMS];
  70.     u8       strides[eiGX_MAX_VERTEX_STREAMS];
  71.     u32      offsets[eiGX_MAX_VERTEX_STREAMS];
  72.     u32      numBuffers;
  73.     BufferId indices;
  74.     bool  fatIndices;
  75. };
  76.  
  77. struct InstanceState
  78. {
  79.     u32 instanceCount; // How many instances to draw.
  80.     BufferId streams[eiGX_MAX_VERTEX_STREAMS];
  81.     u8 strides[eiGX_MAX_VERTEX_STREAMS];
  82.     u32 offsets[eiGX_MAX_VERTEX_STREAMS];
  83.     u32 numBuffers;
  84. };
  85.  
  86. struct StreamOutState
  87. {
  88.     BufferId streams[4];
  89.     u32 numBuffers;
  90. };
  91.  
  92. struct RasterState
  93. {
  94.     CullMode::Type cullMode;
  95.     FillMode::Type fillMode;
  96.     float depthBias, slopeScale, depthBiasClamp;
  97.     // The interpretation of the depth-bias values depends on the depth target format.
  98.     //  For integer depth buffers (these don't exist on PS4/Xbone!):
  99.     //      Bias = slopeScale * max(|dzdx|,|dzdy|) + depthBias * 1/2^bits_in_z_format
  100.     //  For floating point depth buffers:
  101.     //      Bias = slopeScale * max(|dzdx|,|dzdy|) + depthBias * 2^(exponent(max z in primitive) - mantissa_bits_in_z_format)
  102.     //  If depthBiasClamp is >0, FinalBias = min(Bias, depthBiasClamp)
  103.     //  If depthBiasClamp is <0, FinalBias = max(Bias, depthBiasClamp)
  104. };
  105.  
  106. struct SamplerState
  107. {
  108.     Filter::Type minFilter, magFilter, mipFilter;
  109.     AddressMode::Type addressU, addressV, addressW;
  110.     u8 maxAnisotropy;
  111.     u8 minLod;
  112.     u8 maxLod;
  113.     float mipLodBias;
  114.     Color4f border;
  115.     ComparisonFunc::Type depthCompare;
  116. };
  117.  
  118. class StateGroupWriter : NonCopyable
  119. {
  120. public:
  121.     StateGroupWriter();
  122.     ~StateGroupWriter();
  123.  
  124.     static StateGroup* CreateMerged( GpuDevice& gpu, Scope&, u32 count, const StateGroup*const* );
  125.     static StateGroup* CreateMerged( GpuDevice& gpu, Persistent_tag, u32 count, const StateGroup*const* );
  126.  
  127.     // Either pass a Scope allocator, or pass 'Persistent'.
  128.     // In the Persistent case: the resulting StateGroup must have it's Release function called.
  129.     // In the Scope case: the StateGroup will be released automatically by the supplied Scope. Do not call Release on it.
  130.     void Begin( GpuDevice&, Scope& );
  131.     void Begin( GpuDevice&, Persistent_tag );
  132.     StateGroup* End();
  133.  
  134.     //Shader program
  135.     void SetShader( ShaderTechniqueId technique );
  136.     void SetShaderOptions( u32 userFlags, u32 mask );
  137.     //Render states
  138.     void SetBlend( const BlendState& );
  139.     void SetBlend( const MrtBlendState& );
  140.     void SetDepthStencil( const DepthStencilState& );
  141.     void SetRaster( const RasterState& );
  142.     void SetScissor( const ScissorRect& );
  143.     // Resource bindings
  144.     void SetVertices( const VertexState& );
  145.     void SetInstances( const InstanceState& );
  146.     void SetConstantBuffer( int slot, ConstantBufferId );
  147.     void SetResourceList( int slot, TextureId ); //helper for case where a ResourceList only contains one TextureId
  148.     void SetResourceList( int slot, ResourceListId );
  149.     void SetSampler( int slot, const SamplerState& );
  150.     void SetStreamOut( const StreamOutState& );
  151.     void SetRwResourceList( int slot, TextureId ); //helper for case where a ResourceList only contains one TextureId
  152.     void SetRwResourceList( int slot, ResourceListId );
  153. private:
  154.     Scope* m_alloc;
  155.     GpuDevice* m_gpu;
  156.     u8 _state[StateGroupWriterState_Size];
  157.     StateGroupWriterState& State() { return *(StateGroupWriterState*)_state; }
  158. };
Add Comment
Please, Sign In to add comment