Material.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "Material.h"
  23. #include "Types.h"
  24. namespace crown
  25. {
  26. Material::Material() :
  27. mAmbient(0.5f, 0.5f, 0.5f, 1.0f),
  28. mDiffuse(0.5f, 0.5f, 0.5f, 1.0f),
  29. mSpecular(0.5f, 0.5f, 0.5f, 1.0f),
  30. mEmission(0.0f, 0.0f, 0.0f, 1.0f),
  31. mShininess(0),
  32. mLighting(true),
  33. mTexturing(false),
  34. mBackfaceCulling(true),
  35. mSeparateSpecularColor(true),
  36. mDepthTest(true),
  37. mDepthWrite(true),
  38. mRescaleNormals(false),
  39. mBlending(false),
  40. mColorWrite(true),
  41. mFog(false),
  42. mAlphaTest(false),
  43. mPointSprite(false),
  44. mShadingType(ST_SMOOTH),
  45. mPolygonMode(PM_FILL),
  46. mFrontFace(FF_CCW),
  47. mDepthFunc(CF_LEQUAL),
  48. mFogMode(FM_LINEAR),
  49. mFogDensity(1.0f),
  50. mFogStart(0.0f),
  51. mFogEnd(1.0f),
  52. mFogColor(0.0f, 0.0f, 0.0f, 0.0f),
  53. mAlphaFunc(CF_ALWAYS),
  54. mAlphaRef(0.0f),
  55. mPointSize(1.0f),
  56. mPointSizeMin(0.0f),
  57. mPointSizeMax(1.0f),
  58. mBlendEquation(BE_FUNC_ADD),
  59. mBlendSrc(BF_SRC_ALPHA),
  60. mBlendDst(BF_ONE_MINUS_SRC_ALPHA),
  61. mBlendColor(0.0f, 0.0f, 0.0f, 0.0f)
  62. {
  63. for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
  64. {
  65. mTextureLayer[i] = 0;
  66. }
  67. }
  68. Material::~Material()
  69. {
  70. }
  71. const Color4& Material::GetAmbient() const
  72. {
  73. return mAmbient;
  74. }
  75. void Material::SetAmbient(const Color4& ambient)
  76. {
  77. mAmbient = ambient;
  78. }
  79. const Color4& Material::GetDiffuse() const
  80. {
  81. return mDiffuse;
  82. }
  83. void Material::SetDiffuse(const Color4& diffuse)
  84. {
  85. mDiffuse = diffuse;
  86. }
  87. const Color4& Material::GetSpecular() const
  88. {
  89. return mSpecular;
  90. }
  91. void Material::SetSpecular(const Color4& specular)
  92. {
  93. mSpecular = specular;
  94. }
  95. const Color4& Material::GetEmission() const
  96. {
  97. return mEmission;
  98. }
  99. void Material::SetEmission(const Color4& emission)
  100. {
  101. mEmission = emission;
  102. }
  103. int32_t Material::GetShininess() const
  104. {
  105. return mShininess;
  106. }
  107. void Material::SetShininess(int32_t shininess)
  108. {
  109. mShininess = shininess;
  110. }
  111. bool Material::GetLighting() const
  112. {
  113. return mLighting;
  114. }
  115. void Material::SetLighting(bool lighting)
  116. {
  117. mLighting = lighting;
  118. }
  119. bool Material::GetTexturing() const
  120. {
  121. return mTexturing;
  122. }
  123. void Material::SetTexturing(bool texturing)
  124. {
  125. mTexturing = texturing;
  126. }
  127. bool Material::GetBackfaceCulling() const
  128. {
  129. return mBackfaceCulling;
  130. }
  131. void Material::SetBackfaceCulling(bool culling)
  132. {
  133. mBackfaceCulling = culling;
  134. }
  135. bool Material::GetSeparateSpecularColor() const
  136. {
  137. return mSeparateSpecularColor;
  138. }
  139. void Material::SetSeparateSpecularColor(bool separate)
  140. {
  141. mSeparateSpecularColor = separate;
  142. }
  143. bool Material::GetDepthTest() const
  144. {
  145. return mDepthTest;
  146. }
  147. void Material::SetDepthTest(bool test)
  148. {
  149. mDepthTest = test;
  150. }
  151. bool Material::GetDepthWrite() const
  152. {
  153. return mDepthWrite;
  154. }
  155. void Material::SetDepthWrite(bool write)
  156. {
  157. mDepthWrite = write;
  158. }
  159. bool Material::GetRescaleNormals() const
  160. {
  161. return mRescaleNormals;
  162. }
  163. void Material::SetRescaleNormals(bool rescale)
  164. {
  165. mRescaleNormals = rescale;
  166. }
  167. bool Material::GetBlending() const
  168. {
  169. return mBlending;
  170. }
  171. void Material::SetBlending(bool blending)
  172. {
  173. mBlending = blending;
  174. }
  175. bool Material::GetColorWrite() const
  176. {
  177. return mColorWrite;
  178. }
  179. void Material::SetColorWrite(bool write)
  180. {
  181. mColorWrite = write;
  182. }
  183. bool Material::GetFog() const
  184. {
  185. return mFog;
  186. }
  187. void Material::SetFog(bool fog)
  188. {
  189. mFog = fog;
  190. }
  191. bool Material::GetAlphaTest() const
  192. {
  193. return mAlphaTest;
  194. }
  195. void Material::SetAlphaTest(bool test)
  196. {
  197. mAlphaTest = test;
  198. }
  199. bool Material::GetPointSprite() const
  200. {
  201. return mPointSprite;
  202. }
  203. void Material::SetPointSprite(bool sprite)
  204. {
  205. mPointSprite = sprite;
  206. }
  207. ShadingType Material::GetShadingType() const
  208. {
  209. return mShadingType;
  210. }
  211. void Material::SetShadingType(ShadingType type)
  212. {
  213. mShadingType = type;
  214. }
  215. PolygonMode Material::GetPolygonMode() const
  216. {
  217. return mPolygonMode;
  218. }
  219. void Material::SetPolygonMode(PolygonMode mode)
  220. {
  221. mPolygonMode = mode;
  222. }
  223. FrontFace Material::GetFrontFace() const
  224. {
  225. return mFrontFace;
  226. }
  227. void Material::SetFrontFace(FrontFace front)
  228. {
  229. mFrontFace = front;
  230. }
  231. CompareFunction Material::GetDepthFunc() const
  232. {
  233. return mDepthFunc;
  234. }
  235. void Material::SetDepthFunc(CompareFunction func)
  236. {
  237. mDepthFunc = func;
  238. }
  239. FogMode Material::GetFogMode() const
  240. {
  241. return mFogMode;
  242. }
  243. void Material::SetFogMode(FogMode mode)
  244. {
  245. mFogMode = mode;
  246. }
  247. float Material::GetFogDensity() const
  248. {
  249. return mFogDensity;
  250. }
  251. void Material::SetFogDensity(float density)
  252. {
  253. mFogDensity = density;
  254. }
  255. float Material::GetFogStart() const
  256. {
  257. return mFogStart;
  258. }
  259. void Material::SetFogStart(float start)
  260. {
  261. mFogStart = start;
  262. }
  263. float Material::GetFogEnd() const
  264. {
  265. return mFogEnd;
  266. }
  267. void Material::SetFogEnd(float end)
  268. {
  269. mFogEnd = end;
  270. }
  271. const Color4& Material::GetFogColor() const
  272. {
  273. return mFogColor;
  274. }
  275. void Material::SetFogColor(const Color4& color)
  276. {
  277. mFogColor = color;
  278. }
  279. CompareFunction Material::GetAlphaFunc() const
  280. {
  281. return mAlphaFunc;
  282. }
  283. void Material::SetAlphaFunction(CompareFunction func)
  284. {
  285. mAlphaFunc = func;
  286. }
  287. float Material::GetAlphaRef() const
  288. {
  289. return mAlphaRef;
  290. }
  291. void Material::SetAlphaRef(float ref)
  292. {
  293. mAlphaRef = ref;
  294. }
  295. float Material::GetPointSize() const
  296. {
  297. return mPointSize;
  298. }
  299. void Material::SetPointSize(float size)
  300. {
  301. mPointSize = size;
  302. }
  303. float Material::GetPointSizeMin() const
  304. {
  305. return mPointSizeMin;
  306. }
  307. void Material::SetPointSizeMin(float min)
  308. {
  309. mPointSizeMin = min;
  310. }
  311. float Material::GetPointSizeMax() const
  312. {
  313. return mPointSizeMax;
  314. }
  315. void Material::SetPointSizeMax(float max)
  316. {
  317. mPointSizeMax = max;
  318. }
  319. BlendFunction Material::GetSrcBlendFunc() const
  320. {
  321. return mBlendSrc;
  322. }
  323. void Material::SetSrcBlendFunc(BlendFunction src)
  324. {
  325. mBlendSrc = src;
  326. }
  327. BlendFunction Material::GetDstBlendFunc() const
  328. {
  329. return mBlendDst;
  330. }
  331. void Material::SetDstBlendFunc(BlendFunction dst)
  332. {
  333. mBlendDst = dst;
  334. }
  335. void Material::SetBlendFunc(BlendFunction src, BlendFunction dst)
  336. {
  337. mBlendSrc = src;
  338. mBlendDst = dst;
  339. }
  340. Color4& Material::GetBlendColor()
  341. {
  342. return mBlendColor;
  343. }
  344. void Material::SetBlendColor(const Color4& color)
  345. {
  346. mBlendColor = color;
  347. }
  348. bool Material::SetTextureLayer(uint32_t layer, Texture* texture)
  349. {
  350. if (layer >= MAX_TEXTURE_LAYERS)
  351. {
  352. return false;
  353. }
  354. mTextureLayer[layer] = texture;
  355. return true;
  356. }
  357. Texture* Material::GetTextureLayer(uint32_t layer) const
  358. {
  359. if (layer >= MAX_TEXTURE_LAYERS)
  360. {
  361. return 0;
  362. }
  363. return mTextureLayer[layer];
  364. }
  365. void Material::SetTextureMode(TextureMode mode)
  366. {
  367. for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
  368. {
  369. if (mTextureLayer[i] == 0)
  370. continue;
  371. mTextureLayer[i]->SetMode(mode);
  372. }
  373. }
  374. void Material::SetTextureFilter(TextureFilter filter)
  375. {
  376. for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
  377. {
  378. if (mTextureLayer[i] == 0)
  379. continue;
  380. mTextureLayer[i]->SetFilter(filter);
  381. }
  382. }
  383. void Material::SetTextureWrap(TextureWrap wrap)
  384. {
  385. for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
  386. {
  387. if (mTextureLayer[i] == 0)
  388. continue;
  389. mTextureLayer[i]->SetWrap(wrap);
  390. }
  391. }
  392. } // namespace crown