Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials
SMaterial.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2010 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __S_MATERIAL_H_INCLUDED__
6 #define __S_MATERIAL_H_INCLUDED__
7 
8 #include "SColor.h"
9 #include "matrix4.h"
10 #include "irrArray.h"
11 #include "irrMath.h"
12 #include "EMaterialTypes.h"
13 #include "EMaterialFlags.h"
14 #include "SMaterialLayer.h"
15 
16 namespace irr
17 {
18 namespace video
19 {
20  class ITexture;
21 
24  {
25  EBF_ZERO = 0,
36  };
37 
40  {
44  };
45 
48  {
65  };
66 
69  {
81  ECP_RGB=14,
84  };
85 
87 
90  {
97  };
98 
100 
101  inline f32 pack_texureBlendFunc ( const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE )
102  {
103  const u32 tmp = (alphaSource << 12) | (modulate << 8) | (srcFact << 4) | dstFact;
104  return FR(tmp);
105  }
106 
108 
109  inline void unpack_texureBlendFunc ( E_BLEND_FACTOR &srcFact, E_BLEND_FACTOR &dstFact,
110  E_MODULATE_FUNC &modulo, u32& alphaSource, const f32 param )
111  {
112  const u32 state = IR(param);
113  alphaSource = (state & 0x0000F000) >> 12;
114  modulo = E_MODULATE_FUNC( ( state & 0x00000F00 ) >> 8 );
115  srcFact = E_BLEND_FACTOR ( ( state & 0x000000F0 ) >> 4 );
116  dstFact = E_BLEND_FACTOR ( ( state & 0x0000000F ) );
117  }
118 
120  inline bool textureBlendFunc_hasAlpha ( const E_BLEND_FACTOR factor )
121  {
122  switch ( factor )
123  {
124  case EBF_SRC_ALPHA:
126  case EBF_DST_ALPHA:
129  return true;
130  default:
131  return false;
132  }
133  }
134 
135 
137 
144  {
158 
160  };
161 
163 
170  {
183  };
184 
187 
189  class SMaterial
190  {
191  public:
194  : MaterialType(EMT_SOLID), AmbientColor(255,255,255,255), DiffuseColor(255,255,255,255),
195  EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255),
196  Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f),
199  Wireframe(false), PointCloud(false), GouraudShading(true), Lighting(true), ZWriteEnable(true),
200  BackfaceCulling(true), FrontfaceCulling(false), FogEnable(false), NormalizeNormals(false)
201  { }
202 
204 
205  SMaterial(const SMaterial& other)
206  {
207  // These pointers are checked during assignment
208  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
209  TextureLayer[i].TextureMatrix = 0;
210  *this = other;
211  }
212 
214 
216  {
217  // Check for self-assignment!
218  if (this == &other)
219  return *this;
220 
221  MaterialType = other.MaterialType;
222 
223  AmbientColor = other.AmbientColor;
224  DiffuseColor = other.DiffuseColor;
227  Shininess = other.Shininess;
230  Thickness = other.Thickness;
231  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
232  {
233  TextureLayer[i] = other.TextureLayer[i];
234  }
235 
236  Wireframe = other.Wireframe;
237  PointCloud = other.PointCloud;
239  Lighting = other.Lighting;
240  ZWriteEnable = other.ZWriteEnable;
243  FogEnable = other.FogEnable;
245  ZBuffer = other.ZBuffer;
246  AntiAliasing = other.AntiAliasing;
247  ColorMask = other.ColorMask;
249 
250  return *this;
251  }
252 
255 
258 
260 
264 
266 
268 
271 
273 
276 
278 
308 
310 
313 
315 
317 
320 
322 
324 
326 
330 
332 
337 
339 
345 
347 
350  bool Wireframe:1;
351 
353  bool PointCloud:1;
354 
357 
359  bool Lighting:1;
360 
362 
365  bool ZWriteEnable:1;
366 
369 
372 
374  bool FogEnable:1;
375 
377 
379 
381 
384  {
385  return TextureLayer[i].getTextureMatrix();
386  }
387 
389 
392  {
393  if (i<MATERIAL_MAX_TEXTURES)
394  return TextureLayer[i].getTextureMatrix();
395  else
396  return core::IdentityMatrix;
397  }
398 
400 
402  void setTextureMatrix(u32 i, const core::matrix4& mat)
403  {
404  if (i>=MATERIAL_MAX_TEXTURES)
405  return;
407  }
408 
410 
413  {
414  return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0;
415  }
416 
418 
421  void setTexture(u32 i, ITexture* tex)
422  {
423  if (i>=MATERIAL_MAX_TEXTURES)
424  return;
425  TextureLayer[i].Texture = tex;
426  }
427 
429 
431  void setFlag(E_MATERIAL_FLAG flag, bool value)
432  {
433  switch (flag)
434  {
435  case EMF_WIREFRAME:
436  Wireframe = value; break;
437  case EMF_POINTCLOUD:
438  PointCloud = value; break;
439  case EMF_GOURAUD_SHADING:
440  GouraudShading = value; break;
441  case EMF_LIGHTING:
442  Lighting = value; break;
443  case EMF_ZBUFFER:
444  ZBuffer = value; break;
445  case EMF_ZWRITE_ENABLE:
446  ZWriteEnable = value; break;
448  BackfaceCulling = value; break;
450  FrontfaceCulling = value; break;
451  case EMF_BILINEAR_FILTER:
452  {
453  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
454  TextureLayer[i].BilinearFilter = value;
455  }
456  break;
458  {
459  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
460  TextureLayer[i].TrilinearFilter = value;
461  }
462  break;
464  {
465  if (value)
466  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
467  TextureLayer[i].AnisotropicFilter = 0xFF;
468  else
469  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
470  TextureLayer[i].AnisotropicFilter = 0;
471  }
472  break;
473  case EMF_FOG_ENABLE:
474  FogEnable = value; break;
476  NormalizeNormals = value; break;
477  case EMF_TEXTURE_WRAP:
478  {
479  for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
480  {
483  }
484  }
485  break;
486  case EMF_ANTI_ALIASING:
488  break;
489  case EMF_COLOR_MASK:
490  ColorMask = value?ECP_ALL:ECP_NONE;
491  break;
492  case EMF_COLOR_MATERIAL:
494  break;
495  default:
496  break;
497  }
498  }
499 
501 
503  bool getFlag(E_MATERIAL_FLAG flag) const
504  {
505  switch (flag)
506  {
507  case EMF_WIREFRAME:
508  return Wireframe;
509  case EMF_POINTCLOUD:
510  return PointCloud;
511  case EMF_GOURAUD_SHADING:
512  return GouraudShading;
513  case EMF_LIGHTING:
514  return Lighting;
515  case EMF_ZBUFFER:
516  return ZBuffer!=ECFN_NEVER;
517  case EMF_ZWRITE_ENABLE:
518  return ZWriteEnable;
520  return BackfaceCulling;
522  return FrontfaceCulling;
523  case EMF_BILINEAR_FILTER:
524  return TextureLayer[0].BilinearFilter;
526  return TextureLayer[0].TrilinearFilter;
528  return TextureLayer[0].AnisotropicFilter!=0;
529  case EMF_FOG_ENABLE:
530  return FogEnable;
532  return NormalizeNormals;
533  case EMF_TEXTURE_WRAP:
534  return !(TextureLayer[0].TextureWrapU ||
542  case EMF_ANTI_ALIASING:
543  return (AntiAliasing==1);
544  case EMF_COLOR_MASK:
545  return (ColorMask!=ECP_NONE);
546  case EMF_COLOR_MATERIAL:
547  return (ColorMaterial != ECM_NONE);
548  }
549 
550  return false;
551  }
552 
554 
556  inline bool operator!=(const SMaterial& b) const
557  {
558  bool different =
559  MaterialType != b.MaterialType ||
560  AmbientColor != b.AmbientColor ||
561  DiffuseColor != b.DiffuseColor ||
564  Shininess != b.Shininess ||
567  Thickness != b.Thickness ||
568  Wireframe != b.Wireframe ||
569  PointCloud != b.PointCloud ||
571  Lighting != b.Lighting ||
572  ZBuffer != b.ZBuffer ||
573  ZWriteEnable != b.ZWriteEnable ||
576  FogEnable != b.FogEnable ||
578  AntiAliasing != b.AntiAliasing ||
579  ColorMask != b.ColorMask ||
581  for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)
582  {
583  different |= (TextureLayer[i] != b.TextureLayer[i]);
584  }
585  return different;
586  }
587 
589 
591  inline bool operator==(const SMaterial& b) const
592  { return !(b!=*this); }
593 
594  bool isTransparent() const
595  {
600  }
601  };
602 
604  IRRLICHT_API extern SMaterial IdentityMaterial;
605 
606 } // end namespace video
607 } // end namespace irr
608 
609 #endif

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Tue Jun 5 2012 17:57:14 by Doxygen (1.8.1)