BsPass.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "BsPass.h"
  2. #include "BsRasterizerState.h"
  3. #include "BsBlendState.h"
  4. #include "BsDepthStencilState.h"
  5. #include "BsPassRTTI.h"
  6. #include "BsMaterial.h"
  7. #include "BsGpuParams.h"
  8. #include "BsFrameAlloc.h"
  9. #include "BsGpuProgram.h"
  10. #include "BsException.h"
  11. namespace BansheeEngine
  12. {
  13. template<bool Core>
  14. TPass<Core>::TPass()
  15. {
  16. mData.stencilRefValue = 0;
  17. }
  18. template<bool Core>
  19. TPass<Core>::TPass(const PassDescType& data)
  20. :mData(data)
  21. {
  22. }
  23. template<bool Core>
  24. bool TPass<Core>::hasBlending() const
  25. {
  26. if (!mData.blendState)
  27. return false;
  28. bool transparent = false;
  29. const BlendProperties& bsProps = mData.blendState->getProperties();
  30. for (UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
  31. {
  32. // Transparent if destination color is taken into account
  33. if (bsProps.getDstBlend(i) != BF_ZERO ||
  34. bsProps.getSrcBlend(i) == BF_DEST_COLOR ||
  35. bsProps.getSrcBlend(i) == BF_INV_DEST_COLOR ||
  36. bsProps.getSrcBlend(i) == BF_DEST_ALPHA ||
  37. bsProps.getSrcBlend(i) == BF_INV_DEST_ALPHA)
  38. {
  39. transparent = true;
  40. }
  41. }
  42. return transparent;
  43. }
  44. template class TPass < false > ;
  45. template class TPass < true >;
  46. PassCore::PassCore(const PASS_DESC_CORE& desc)
  47. :TPass(desc)
  48. { }
  49. SPtr<PassCore> PassCore::create(const PASS_DESC_CORE& desc)
  50. {
  51. PassCore* newPass = new (bs_alloc<PassCore>()) PassCore(desc);
  52. SPtr<PassCore> newPassPtr = bs_shared_ptr<PassCore, GenAlloc>(newPass);
  53. newPassPtr->_setThisPtr(newPassPtr);
  54. newPassPtr->initialize();
  55. return newPassPtr;
  56. }
  57. Pass::Pass(const PASS_DESC& desc)
  58. :TPass(desc)
  59. { }
  60. SPtr<PassCore> Pass::getCore() const
  61. {
  62. return std::static_pointer_cast<PassCore>(mCoreSpecific);
  63. }
  64. SPtr<CoreObjectCore> Pass::createCore() const
  65. {
  66. PASS_DESC_CORE desc;
  67. desc.blendState = mData.blendState.isLoaded() ? mData.blendState->getCore() : nullptr;
  68. desc.rasterizerState = mData.rasterizerState.isLoaded() ? mData.rasterizerState->getCore() : nullptr;
  69. desc.depthStencilState = mData.depthStencilState.isLoaded() ? mData.depthStencilState->getCore() : nullptr;
  70. desc.stencilRefValue = mData.stencilRefValue;
  71. desc.vertexProgram = mData.vertexProgram != nullptr ? mData.vertexProgram->getCore() : nullptr;
  72. desc.fragmentProgram = mData.fragmentProgram != nullptr ? mData.fragmentProgram->getCore() : nullptr;
  73. desc.geometryProgram = mData.geometryProgram != nullptr ? mData.geometryProgram->getCore() : nullptr;
  74. desc.hullProgram = mData.hullProgram != nullptr ? mData.hullProgram->getCore() : nullptr;
  75. desc.domainProgram = mData.domainProgram != nullptr ? mData.domainProgram->getCore() : nullptr;
  76. desc.hullProgram = mData.hullProgram != nullptr ? mData.hullProgram->getCore() : nullptr;
  77. PassCore* pass = new (bs_alloc<PassCore>()) PassCore(desc);
  78. SPtr<PassCore> passPtr = bs_shared_ptr<PassCore, GenAlloc>(pass);
  79. passPtr->_setThisPtr(passPtr);
  80. return passPtr;
  81. }
  82. PassPtr Pass::create(const PASS_DESC& desc)
  83. {
  84. Pass* newPass = new (bs_alloc<Pass>()) Pass(desc);
  85. PassPtr newPassPtr = bs_core_ptr<Pass, GenAlloc>(newPass);
  86. newPassPtr->_setThisPtr(newPassPtr);
  87. newPassPtr->initialize();
  88. return newPassPtr;
  89. }
  90. PassPtr Pass::createEmpty()
  91. {
  92. Pass* newPass = new (bs_alloc<Pass>()) Pass();
  93. PassPtr newPassPtr = bs_core_ptr<Pass, GenAlloc>(newPass);
  94. newPassPtr->_setThisPtr(newPassPtr);
  95. return newPassPtr;
  96. }
  97. RTTITypeBase* Pass::getRTTIStatic()
  98. {
  99. return PassRTTI::instance();
  100. }
  101. RTTITypeBase* Pass::getRTTI() const
  102. {
  103. return Pass::getRTTIStatic();
  104. }
  105. }