CmBlendState.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmResource.h"
  4. #include "CmCommonEnums.h"
  5. namespace CamelotFramework
  6. {
  7. struct CM_EXPORT RENDER_TARGET_BLEND_STATE_DESC
  8. {
  9. RENDER_TARGET_BLEND_STATE_DESC()
  10. : blendEnable(false)
  11. , srcBlend(BF_ONE)
  12. , dstBlend(BF_ZERO)
  13. , blendOp(BO_ADD)
  14. , srcBlendAlpha(BF_ONE)
  15. , dstBlendAlpha(BF_ZERO)
  16. , blendOpAlpha(BO_ADD)
  17. , renderTargetWriteMask(0xFF)
  18. { }
  19. bool blendEnable;
  20. BlendFactor srcBlend;
  21. BlendFactor dstBlend;
  22. BlendOperation blendOp;
  23. BlendFactor srcBlendAlpha;
  24. BlendFactor dstBlendAlpha;
  25. BlendOperation blendOpAlpha;
  26. // Enable write to RGBA channels separately by setting first four bits (0 - R, 1 - G, 2 - B, 3 - A)
  27. UINT8 renderTargetWriteMask;
  28. };
  29. struct CM_EXPORT BLEND_STATE_DESC
  30. {
  31. BLEND_STATE_DESC()
  32. : alphaToCoverageEnable(false)
  33. , independantBlendEnable(false)
  34. { }
  35. bool alphaToCoverageEnable;
  36. bool independantBlendEnable;
  37. RENDER_TARGET_BLEND_STATE_DESC renderTargetDesc[CM_MAX_MULTIPLE_RENDER_TARGETS];
  38. };
  39. // TODO Low priority - Write doc explaining various states
  40. class CM_EXPORT BlendState : public Resource
  41. {
  42. public:
  43. virtual ~BlendState() {}
  44. bool getAlphaToCoverageEnabled() const { return mData.alphaToCoverageEnable; }
  45. bool getIndependantBlendEnable() const { return mData.independantBlendEnable; }
  46. bool getBlendEnabled(UINT32 renderTargetIdx) const;
  47. BlendFactor getSrcBlend(UINT32 renderTargetIdx) const;
  48. BlendFactor getDstBlend(UINT32 renderTargetIdx) const;
  49. BlendOperation getBlendOperation(UINT32 renderTargetIdx) const;
  50. BlendFactor getAlphaSrcBlend(UINT32 renderTargetIdx) const;
  51. BlendFactor getAlphaDstBlend(UINT32 renderTargetIdx) const;
  52. BlendOperation getAlphaBlendOperation(UINT32 renderTargetIdx) const;
  53. UINT8 getRenderTargetWriteMask(UINT32 renderTargetIdx) const;
  54. static HBlendState create(const BLEND_STATE_DESC& desc);
  55. /**
  56. * @brief Returns the default blend state;
  57. */
  58. static const BlendStatePtr& getDefault();
  59. protected:
  60. friend class RenderStateManager;
  61. virtual void initialize(const BLEND_STATE_DESC& desc);
  62. BLEND_STATE_DESC mData;
  63. /************************************************************************/
  64. /* RTTI */
  65. /************************************************************************/
  66. public:
  67. friend class BlendStateRTTI;
  68. static RTTITypeBase* getRTTIStatic();
  69. virtual RTTITypeBase* getRTTI() const;
  70. };
  71. }