CmPass.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #include "CmPass.h"
  2. #include "CmPassRTTI.h"
  3. #include "CmException.h"
  4. namespace CamelotEngine
  5. {
  6. //-----------------------------------------------------------------------------
  7. Pass::Pass()
  8. : mSourceBlendFactor(SBF_ONE)
  9. , mDestBlendFactor(SBF_ZERO)
  10. , mSourceBlendFactorAlpha(SBF_ONE)
  11. , mDestBlendFactorAlpha(SBF_ZERO)
  12. , mSeparateBlend(false)
  13. , mBlendOperation(SBO_ADD)
  14. , mAlphaBlendOperation(SBO_ADD)
  15. , mSeparateBlendOperation(false)
  16. , mDepthCheck(true)
  17. , mDepthWrite(true)
  18. , mDepthFunc(CMPF_LESS_EQUAL)
  19. , mDepthBiasConstant(0.0f)
  20. , mDepthBiasSlopeScale(0.0f)
  21. , mDepthBiasPerIteration(0.0f)
  22. , mColourWrite(true)
  23. , mAlphaRejectFunc(CMPF_ALWAYS_PASS)
  24. , mAlphaRejectVal(0)
  25. , mAlphaToCoverageEnabled(false)
  26. , mCullMode(CULL_CLOCKWISE)
  27. , mPolygonMode(PM_SOLID)
  28. , mPointSize(1.0f)
  29. , mPointMinSize(0.0f)
  30. , mPointMaxSize(0.0f)
  31. {
  32. }
  33. //-----------------------------------------------------------------------------
  34. Pass::Pass(const Pass& oth)
  35. {
  36. *this = oth;
  37. }
  38. //-----------------------------------------------------------------------------
  39. Pass::~Pass()
  40. {
  41. }
  42. //-----------------------------------------------------------------------------
  43. Pass& Pass::operator=(const Pass& oth)
  44. {
  45. // Default blending (overwrite)
  46. mSourceBlendFactor = oth.mSourceBlendFactor;
  47. mDestBlendFactor = oth.mDestBlendFactor;
  48. mSourceBlendFactorAlpha = oth.mSourceBlendFactorAlpha;
  49. mDestBlendFactorAlpha = oth.mDestBlendFactorAlpha;
  50. mSeparateBlend = oth.mSeparateBlend;
  51. mBlendOperation = oth.mBlendOperation;
  52. mAlphaBlendOperation = oth.mAlphaBlendOperation;
  53. mSeparateBlendOperation = oth.mSeparateBlendOperation;
  54. mDepthCheck = oth.mDepthCheck;
  55. mDepthWrite = oth.mDepthWrite;
  56. mAlphaRejectFunc = oth.mAlphaRejectFunc;
  57. mAlphaRejectVal = oth.mAlphaRejectVal;
  58. mAlphaToCoverageEnabled = oth.mAlphaToCoverageEnabled;
  59. mColourWrite = oth.mColourWrite;
  60. mDepthFunc = oth.mDepthFunc;
  61. mDepthBiasConstant = oth.mDepthBiasConstant;
  62. mDepthBiasSlopeScale = oth.mDepthBiasSlopeScale;
  63. mDepthBiasPerIteration = oth.mDepthBiasPerIteration;
  64. mCullMode = oth.mCullMode;
  65. mPolygonMode = oth.mPolygonMode;
  66. mPointSize = oth.mPointSize;
  67. mPointMinSize = oth.mPointMinSize;
  68. mPointMaxSize = oth.mPointMaxSize;
  69. mVertexProgram = oth.mVertexProgram;
  70. mFragmentProgram = oth.mFragmentProgram;
  71. mGeometryProgram = oth.mGeometryProgram;
  72. return *this;
  73. }
  74. //-----------------------------------------------------------------------
  75. void Pass::setPointSize(float ps)
  76. {
  77. mPointSize = ps;
  78. }
  79. //-----------------------------------------------------------------------
  80. void Pass::setPointMinSize(float min)
  81. {
  82. mPointMinSize = min;
  83. }
  84. //-----------------------------------------------------------------------
  85. float Pass::getPointMinSize(void) const
  86. {
  87. return mPointMinSize;
  88. }
  89. //-----------------------------------------------------------------------
  90. void Pass::setPointMaxSize(float max)
  91. {
  92. mPointMaxSize = max;
  93. }
  94. //-----------------------------------------------------------------------
  95. float Pass::getPointMaxSize(void) const
  96. {
  97. return mPointMaxSize;
  98. }
  99. //-----------------------------------------------------------------------
  100. float Pass::getPointSize(void) const
  101. {
  102. return mPointSize;
  103. }
  104. //-----------------------------------------------------------------------
  105. void Pass::setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor)
  106. {
  107. mSourceBlendFactor = sourceFactor;
  108. mDestBlendFactor = destFactor;
  109. mSeparateBlend = false;
  110. }
  111. //-----------------------------------------------------------------------
  112. void Pass::setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha )
  113. {
  114. mSourceBlendFactor = sourceFactor;
  115. mDestBlendFactor = destFactor;
  116. mSourceBlendFactorAlpha = sourceFactorAlpha;
  117. mDestBlendFactorAlpha = destFactorAlpha;
  118. mSeparateBlend = true;
  119. }
  120. //-----------------------------------------------------------------------
  121. SceneBlendFactor Pass::getSourceBlendFactor(void) const
  122. {
  123. return mSourceBlendFactor;
  124. }
  125. //-----------------------------------------------------------------------
  126. SceneBlendFactor Pass::getDestBlendFactor(void) const
  127. {
  128. return mDestBlendFactor;
  129. }
  130. //-----------------------------------------------------------------------
  131. SceneBlendFactor Pass::getSourceBlendFactorAlpha(void) const
  132. {
  133. return mSourceBlendFactorAlpha;
  134. }
  135. //-----------------------------------------------------------------------
  136. SceneBlendFactor Pass::getDestBlendFactorAlpha(void) const
  137. {
  138. return mDestBlendFactorAlpha;
  139. }
  140. //-----------------------------------------------------------------------
  141. bool Pass::hasSeparateSceneBlending() const
  142. {
  143. return mSeparateBlend;
  144. }
  145. //-----------------------------------------------------------------------
  146. void Pass::setSceneBlendingOperation(SceneBlendOperation op)
  147. {
  148. mBlendOperation = op;
  149. mSeparateBlendOperation = false;
  150. }
  151. //-----------------------------------------------------------------------
  152. void Pass::setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp)
  153. {
  154. mBlendOperation = op;
  155. mAlphaBlendOperation = alphaOp;
  156. mSeparateBlendOperation = true;
  157. }
  158. //-----------------------------------------------------------------------
  159. SceneBlendOperation Pass::getSceneBlendingOperation() const
  160. {
  161. return mBlendOperation;
  162. }
  163. //-----------------------------------------------------------------------
  164. SceneBlendOperation Pass::getSceneBlendingOperationAlpha() const
  165. {
  166. return mAlphaBlendOperation;
  167. }
  168. //-----------------------------------------------------------------------
  169. bool Pass::hasSeparateSceneBlendingOperations() const
  170. {
  171. return mSeparateBlendOperation;
  172. }
  173. //-----------------------------------------------------------------------
  174. bool Pass::isTransparent(void) const
  175. {
  176. // Transparent if any of the destination colour is taken into account
  177. if (mDestBlendFactor == SBF_ZERO &&
  178. mSourceBlendFactor != SBF_DEST_COLOUR &&
  179. mSourceBlendFactor != SBF_ONE_MINUS_DEST_COLOUR &&
  180. mSourceBlendFactor != SBF_DEST_ALPHA &&
  181. mSourceBlendFactor != SBF_ONE_MINUS_DEST_ALPHA)
  182. {
  183. return false;
  184. }
  185. else
  186. {
  187. return true;
  188. }
  189. }
  190. //-----------------------------------------------------------------------
  191. void Pass::setDepthCheckEnabled(bool enabled)
  192. {
  193. mDepthCheck = enabled;
  194. }
  195. //-----------------------------------------------------------------------
  196. bool Pass::getDepthCheckEnabled(void) const
  197. {
  198. return mDepthCheck;
  199. }
  200. //-----------------------------------------------------------------------
  201. void Pass::setDepthWriteEnabled(bool enabled)
  202. {
  203. mDepthWrite = enabled;
  204. }
  205. //-----------------------------------------------------------------------
  206. bool Pass::getDepthWriteEnabled(void) const
  207. {
  208. return mDepthWrite;
  209. }
  210. //-----------------------------------------------------------------------
  211. void Pass::setDepthFunction( CompareFunction func)
  212. {
  213. mDepthFunc = func;
  214. }
  215. //-----------------------------------------------------------------------
  216. CompareFunction Pass::getDepthFunction(void) const
  217. {
  218. return mDepthFunc;
  219. }
  220. //-----------------------------------------------------------------------
  221. void Pass::setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage)
  222. {
  223. mAlphaRejectFunc = func;
  224. mAlphaRejectVal = value;
  225. mAlphaToCoverageEnabled = alphaToCoverage;
  226. }
  227. //-----------------------------------------------------------------------
  228. void Pass::setAlphaRejectFunction(CompareFunction func)
  229. {
  230. mAlphaRejectFunc = func;
  231. }
  232. //-----------------------------------------------------------------------
  233. void Pass::setAlphaRejectValue(unsigned char val)
  234. {
  235. mAlphaRejectVal = val;
  236. }
  237. //---------------------------------------------------------------------
  238. void Pass::setAlphaToCoverageEnabled(bool enabled)
  239. {
  240. mAlphaToCoverageEnabled = enabled;
  241. }
  242. //-----------------------------------------------------------------------
  243. void Pass::setColourWriteEnabled(bool enabled)
  244. {
  245. mColourWrite = enabled;
  246. }
  247. //-----------------------------------------------------------------------
  248. bool Pass::getColourWriteEnabled(void) const
  249. {
  250. return mColourWrite;
  251. }
  252. //-----------------------------------------------------------------------
  253. void Pass::setCullingMode( CullingMode mode)
  254. {
  255. mCullMode = mode;
  256. }
  257. //-----------------------------------------------------------------------
  258. CullingMode Pass::getCullingMode(void) const
  259. {
  260. return mCullMode;
  261. }
  262. //-----------------------------------------------------------------------
  263. void Pass::setPolygonMode(PolygonMode mode)
  264. {
  265. mPolygonMode = mode;
  266. }
  267. //-----------------------------------------------------------------------
  268. PolygonMode Pass::getPolygonMode(void) const
  269. {
  270. return mPolygonMode;
  271. }
  272. //-----------------------------------------------------------------------
  273. void Pass::setDepthBias(float constantBias, float slopeScaleBias)
  274. {
  275. mDepthBiasConstant = constantBias;
  276. mDepthBiasSlopeScale = slopeScaleBias;
  277. }
  278. //-----------------------------------------------------------------------
  279. float Pass::getDepthBiasConstant(void) const
  280. {
  281. return mDepthBiasConstant;
  282. }
  283. //-----------------------------------------------------------------------
  284. float Pass::getDepthBiasSlopeScale(void) const
  285. {
  286. return mDepthBiasSlopeScale;
  287. }
  288. //---------------------------------------------------------------------
  289. void Pass::setIterationDepthBias(float biasPerIteration)
  290. {
  291. mDepthBiasPerIteration = biasPerIteration;
  292. }
  293. //---------------------------------------------------------------------
  294. float Pass::getIterationDepthBias() const
  295. {
  296. return mDepthBiasPerIteration;
  297. }
  298. //-----------------------------------------------------------------------
  299. void Pass::setVertexProgram(GpuProgramHandle gpuProgram)
  300. {
  301. mVertexProgram = gpuProgram;
  302. }
  303. //-----------------------------------------------------------------------
  304. void Pass::setFragmentProgram(GpuProgramHandle gpuProgram)
  305. {
  306. mFragmentProgram = gpuProgram;
  307. }
  308. //-----------------------------------------------------------------------
  309. void Pass::setGeometryProgram(GpuProgramHandle gpuProgram)
  310. {
  311. mGeometryProgram = gpuProgram;
  312. }
  313. //-----------------------------------------------------------------------
  314. const GpuProgramHandle& Pass::getVertexProgram(void) const
  315. {
  316. return mVertexProgram;
  317. }
  318. //-----------------------------------------------------------------------
  319. const GpuProgramHandle& Pass::getFragmentProgram(void) const
  320. {
  321. return mFragmentProgram;
  322. }
  323. //-----------------------------------------------------------------------
  324. const GpuProgramHandle& Pass::getGeometryProgram(void) const
  325. {
  326. return mGeometryProgram;
  327. }
  328. //----------------------------------------------------------------------
  329. RTTITypeBase* Pass::getRTTIStatic()
  330. {
  331. return PassRTTI::instance();
  332. }
  333. //----------------------------------------------------------------------
  334. RTTITypeBase* Pass::getRTTI() const
  335. {
  336. return Pass::getRTTIStatic();
  337. }
  338. }