CmPass.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #include "CmPass.h"
  2. #include "CmPassRTTI.h"
  3. #include "CmException.h"
  4. #include "CmBlendState.h"
  5. namespace CamelotEngine
  6. {
  7. //-----------------------------------------------------------------------------
  8. Pass::Pass()
  9. : mDepthCheck(true)
  10. , mDepthWrite(true)
  11. , mDepthFunc(CMPF_LESS_EQUAL)
  12. , mDepthBiasConstant(0.0f)
  13. , mDepthBiasSlopeScale(0.0f)
  14. , mDepthBiasPerIteration(0.0f)
  15. , mCullMode(CULL_CLOCKWISE)
  16. , mPolygonMode(PM_SOLID)
  17. {
  18. }
  19. //-----------------------------------------------------------------------------
  20. Pass::Pass(const Pass& oth)
  21. {
  22. *this = oth;
  23. }
  24. //-----------------------------------------------------------------------------
  25. Pass::~Pass()
  26. {
  27. }
  28. //-----------------------------------------------------------------------------
  29. Pass& Pass::operator=(const Pass& oth)
  30. {
  31. // Default blending (overwrite)
  32. mBlendState = oth.mBlendState;
  33. mDepthCheck = oth.mDepthCheck;
  34. mDepthWrite = oth.mDepthWrite;
  35. mDepthFunc = oth.mDepthFunc;
  36. mDepthBiasConstant = oth.mDepthBiasConstant;
  37. mDepthBiasSlopeScale = oth.mDepthBiasSlopeScale;
  38. mDepthBiasPerIteration = oth.mDepthBiasPerIteration;
  39. mCullMode = oth.mCullMode;
  40. mPolygonMode = oth.mPolygonMode;
  41. mVertexProgram = oth.mVertexProgram;
  42. mFragmentProgram = oth.mFragmentProgram;
  43. mGeometryProgram = oth.mGeometryProgram;
  44. return *this;
  45. }
  46. //-----------------------------------------------------------------------
  47. bool Pass::isTransparent(void) const
  48. {
  49. bool transparent = false;
  50. if(mBlendState != nullptr)
  51. {
  52. for(UINT32 i = 0; i < CM_MAX_MULTIPLE_RENDER_TARGETS; i++)
  53. {
  54. // Transparent if destination color is taken into account
  55. if (mBlendState->getDstBlend(i) != SBF_ZERO ||
  56. mBlendState->getSrcBlend(i) == SBF_DEST_COLOUR ||
  57. mBlendState->getSrcBlend(i) == SBF_ONE_MINUS_DEST_COLOUR ||
  58. mBlendState->getSrcBlend(i) == SBF_DEST_ALPHA ||
  59. mBlendState->getSrcBlend(i) == SBF_ONE_MINUS_DEST_ALPHA)
  60. {
  61. transparent = true;
  62. }
  63. }
  64. }
  65. return transparent;
  66. }
  67. //----------------------------------------------------------------------
  68. void Pass::setBlendState(BlendStatePtr blendState)
  69. {
  70. mBlendState = blendState;
  71. }
  72. //----------------------------------------------------------------------
  73. BlendStatePtr Pass::getBlendState() const
  74. {
  75. return mBlendState;
  76. }
  77. //-----------------------------------------------------------------------
  78. void Pass::setDepthCheckEnabled(bool enabled)
  79. {
  80. mDepthCheck = enabled;
  81. }
  82. //-----------------------------------------------------------------------
  83. bool Pass::getDepthCheckEnabled(void) const
  84. {
  85. return mDepthCheck;
  86. }
  87. //-----------------------------------------------------------------------
  88. void Pass::setDepthWriteEnabled(bool enabled)
  89. {
  90. mDepthWrite = enabled;
  91. }
  92. //-----------------------------------------------------------------------
  93. bool Pass::getDepthWriteEnabled(void) const
  94. {
  95. return mDepthWrite;
  96. }
  97. //-----------------------------------------------------------------------
  98. void Pass::setDepthFunction( CompareFunction func)
  99. {
  100. mDepthFunc = func;
  101. }
  102. //-----------------------------------------------------------------------
  103. CompareFunction Pass::getDepthFunction(void) const
  104. {
  105. return mDepthFunc;
  106. }
  107. //-----------------------------------------------------------------------
  108. void Pass::setCullingMode( CullingMode mode)
  109. {
  110. mCullMode = mode;
  111. }
  112. //-----------------------------------------------------------------------
  113. CullingMode Pass::getCullingMode(void) const
  114. {
  115. return mCullMode;
  116. }
  117. //-----------------------------------------------------------------------
  118. void Pass::setPolygonMode(PolygonMode mode)
  119. {
  120. mPolygonMode = mode;
  121. }
  122. //-----------------------------------------------------------------------
  123. PolygonMode Pass::getPolygonMode(void) const
  124. {
  125. return mPolygonMode;
  126. }
  127. //-----------------------------------------------------------------------
  128. void Pass::setDepthBias(float constantBias, float slopeScaleBias)
  129. {
  130. mDepthBiasConstant = constantBias;
  131. mDepthBiasSlopeScale = slopeScaleBias;
  132. }
  133. //-----------------------------------------------------------------------
  134. float Pass::getDepthBiasConstant(void) const
  135. {
  136. return mDepthBiasConstant;
  137. }
  138. //-----------------------------------------------------------------------
  139. float Pass::getDepthBiasSlopeScale(void) const
  140. {
  141. return mDepthBiasSlopeScale;
  142. }
  143. //---------------------------------------------------------------------
  144. void Pass::setIterationDepthBias(float biasPerIteration)
  145. {
  146. mDepthBiasPerIteration = biasPerIteration;
  147. }
  148. //---------------------------------------------------------------------
  149. float Pass::getIterationDepthBias() const
  150. {
  151. return mDepthBiasPerIteration;
  152. }
  153. //-----------------------------------------------------------------------
  154. void Pass::setVertexProgram(GpuProgramHandle gpuProgram)
  155. {
  156. mVertexProgram = gpuProgram;
  157. }
  158. //-----------------------------------------------------------------------
  159. void Pass::setFragmentProgram(GpuProgramHandle gpuProgram)
  160. {
  161. mFragmentProgram = gpuProgram;
  162. }
  163. //-----------------------------------------------------------------------
  164. void Pass::setGeometryProgram(GpuProgramHandle gpuProgram)
  165. {
  166. mGeometryProgram = gpuProgram;
  167. }
  168. //-----------------------------------------------------------------------
  169. const GpuProgramHandle& Pass::getVertexProgram(void) const
  170. {
  171. return mVertexProgram;
  172. }
  173. //-----------------------------------------------------------------------
  174. const GpuProgramHandle& Pass::getFragmentProgram(void) const
  175. {
  176. return mFragmentProgram;
  177. }
  178. //-----------------------------------------------------------------------
  179. const GpuProgramHandle& Pass::getGeometryProgram(void) const
  180. {
  181. return mGeometryProgram;
  182. }
  183. //----------------------------------------------------------------------
  184. RTTITypeBase* Pass::getRTTIStatic()
  185. {
  186. return PassRTTI::instance();
  187. }
  188. //----------------------------------------------------------------------
  189. RTTITypeBase* Pass::getRTTI() const
  190. {
  191. return Pass::getRTTIStatic();
  192. }
  193. }