CmPass.cpp 12 KB

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