CmPass.cpp 13 KB

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