RAS_IPolygonMaterial.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): none yet.
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. /** \file RAS_IPolygonMaterial.h
  28. * \ingroup bgerast
  29. */
  30. #ifndef __RAS_IPOLYGONMATERIAL_H__
  31. #define __RAS_IPOLYGONMATERIAL_H__
  32. #include "STR_HashedString.h"
  33. #include "MT_Vector3.h"
  34. #ifdef WITH_CXX_GUARDEDALLOC
  35. #include "MEM_guardedalloc.h"
  36. #endif
  37. class RAS_IRasterizer;
  38. struct MTexPoly;
  39. struct Material;
  40. struct Image;
  41. struct Scene;
  42. class SCA_IScene;
  43. struct GameSettings;
  44. enum MaterialProps
  45. {
  46. RAS_ZSORT =1,
  47. RAS_TRANSPARENT =2,
  48. RAS_TRIANGLE =4,
  49. RAS_MULTITEX =8,
  50. RAS_MULTILIGHT =16,
  51. RAS_BLENDERMAT =32,
  52. RAS_GLSHADER =64,
  53. RAS_AUTOGEN =128,
  54. RAS_NORMAL =256,
  55. RAS_DEFMULTI =512,
  56. RAS_BLENDERGLSL =1024,
  57. RAS_CASTSHADOW =2048,
  58. RAS_ONLYSHADOW =4096,
  59. };
  60. /**
  61. * Polygon Material on which the material buckets are sorted
  62. *
  63. */
  64. class RAS_IPolyMaterial
  65. {
  66. //todo: remove these variables from this interface/protocol class
  67. protected:
  68. STR_HashedString m_texturename;
  69. STR_HashedString m_materialname; //also needed for touchsensor
  70. int m_tile;
  71. int m_tilexrep,m_tileyrep;
  72. int m_drawingmode;
  73. int m_alphablend;
  74. bool m_alpha;
  75. bool m_zsort;
  76. bool m_light;
  77. int m_materialindex;
  78. unsigned int m_polymatid;
  79. static unsigned int m_newpolymatid;
  80. // will move...
  81. unsigned int m_flag;//MaterialProps
  82. int m_multimode; // sum of values
  83. public:
  84. MT_Vector3 m_diffuse;
  85. float m_shininess;
  86. MT_Vector3 m_specular;
  87. float m_specularity;
  88. /** Used to store caching information for materials. */
  89. typedef void* TCachingInfo;
  90. // care! these are taken from blender polygonflags, see file DNA_mesh_types.h for #define TF_BILLBOARD etc.
  91. enum MaterialFlags
  92. {
  93. BILLBOARD_SCREENALIGNED = 512, /* GEMAT_HALO */
  94. BILLBOARD_AXISALIGNED = 1024, /* GEMAT_BILLBOARD */
  95. SHADOW =2048 /* GEMAT_SHADOW */
  96. };
  97. RAS_IPolyMaterial();
  98. RAS_IPolyMaterial(const STR_String& texname,
  99. const STR_String& matname,
  100. int materialindex,
  101. int tile,
  102. int tilexrep,
  103. int tileyrep,
  104. int transp,
  105. bool alpha,
  106. bool zsort);
  107. void Initialize(const STR_String& texname,
  108. const STR_String& matname,
  109. int materialindex,
  110. int tile,
  111. int tilexrep,
  112. int tileyrep,
  113. int transp,
  114. bool alpha,
  115. bool zsort,
  116. bool light,
  117. bool image,
  118. struct GameSettings* game);
  119. virtual ~RAS_IPolyMaterial() {}
  120. /**
  121. * Returns the caching information for this material,
  122. * This can be used to speed up the rasterizing process.
  123. * \return The caching information.
  124. */
  125. virtual TCachingInfo GetCachingInfo(void) const { return 0; }
  126. /**
  127. * Activates the material in the rasterizer.
  128. * On entry, the cachingInfo contains info about the last activated material.
  129. * On exit, the cachingInfo should contain updated info about this material.
  130. * \param rasty The rasterizer in which the material should be active.
  131. * \param cachingInfo The information about the material used to speed up rasterizing.
  132. */
  133. virtual bool Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const
  134. {
  135. return false;
  136. }
  137. virtual void ActivateMeshSlot(const class RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const {}
  138. virtual bool Equals(const RAS_IPolyMaterial& lhs) const;
  139. bool Less(const RAS_IPolyMaterial& rhs) const;
  140. //int GetLightLayer() const;
  141. bool IsAlpha() const;
  142. bool IsZSort() const;
  143. unsigned int hash() const;
  144. int GetDrawingMode() const;
  145. const STR_String& GetMaterialName() const;
  146. dword GetMaterialNameHash() const;
  147. const STR_String& GetTextureName() const;
  148. unsigned int GetFlag() const;
  149. int GetMaterialIndex() const;
  150. virtual Material* GetBlenderMaterial() const;
  151. virtual Image* GetBlenderImage() const;
  152. virtual MTexPoly* GetMTexPoly() const;
  153. virtual unsigned int* GetMCol() const;
  154. virtual Scene* GetBlenderScene() const;
  155. virtual void ReleaseMaterial();
  156. virtual void GetMaterialRGBAColor(unsigned char *rgba) const;
  157. virtual bool UsesLighting(RAS_IRasterizer *rasty) const;
  158. virtual bool UsesObjectColor() const;
  159. virtual bool CastsShadows() const;
  160. virtual bool OnlyShadow() const;
  161. virtual void Replace_IScene(SCA_IScene *val) {} /* overridden by KX_BlenderMaterial */
  162. /**
  163. * \return the equivalent drawing mode for the material settings (equivalent to old TexFace tface->mode).
  164. */
  165. int ConvertFaceMode(struct GameSettings *game, bool image) const;
  166. /*
  167. * PreCalculate texture gen
  168. */
  169. virtual void OnConstruction() {}
  170. #ifdef WITH_CXX_GUARDEDALLOC
  171. MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IPolyMaterial")
  172. #endif
  173. };
  174. inline bool operator ==( const RAS_IPolyMaterial & rhs,const RAS_IPolyMaterial & lhs)
  175. {
  176. return ( rhs.Equals(lhs));
  177. }
  178. inline bool operator < ( const RAS_IPolyMaterial & lhs, const RAS_IPolyMaterial & rhs)
  179. {
  180. return lhs.Less(rhs);
  181. }
  182. #endif /* __RAS_IPOLYGONMATERIAL_H__ */