LCOV - code coverage report
Current view: top level - usr/include/irrlicht - SMaterialLayer.h (source / functions) Hit Total Coverage
Test: report Lines: 34 48 70.8 %
Date: 2015-07-11 18:23:49 Functions: 4 5 80.0 %

          Line data    Source code
       1             : // Copyright (C) 2002-2012 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_LAYER_H_INCLUDED__
       6             : #define __S_MATERIAL_LAYER_H_INCLUDED__
       7             : 
       8             : #include "matrix4.h"
       9             : #include "irrAllocator.h"
      10             : 
      11             : namespace irr
      12             : {
      13             : namespace video
      14             : {
      15             :         class ITexture;
      16             : 
      17             :         //! Texture coord clamp mode outside [0.0, 1.0]
      18             :         enum E_TEXTURE_CLAMP
      19             :         {
      20             :                 //! Texture repeats
      21             :                 ETC_REPEAT = 0,
      22             :                 //! Texture is clamped to the last pixel
      23             :                 ETC_CLAMP,
      24             :                 //! Texture is clamped to the edge pixel
      25             :                 ETC_CLAMP_TO_EDGE,
      26             :                 //! Texture is clamped to the border pixel (if exists)
      27             :                 ETC_CLAMP_TO_BORDER,
      28             :                 //! Texture is alternatingly mirrored (0..1..0..1..0..)
      29             :                 ETC_MIRROR,
      30             :                 //! Texture is mirrored once and then clamped (0..1..0)
      31             :                 ETC_MIRROR_CLAMP,
      32             :                 //! Texture is mirrored once and then clamped to edge
      33             :                 ETC_MIRROR_CLAMP_TO_EDGE,
      34             :                 //! Texture is mirrored once and then clamped to border
      35             :                 ETC_MIRROR_CLAMP_TO_BORDER
      36             :         };
      37             :         static const char* const aTextureClampNames[] = {
      38             :                         "texture_clamp_repeat",
      39             :                         "texture_clamp_clamp",
      40             :                         "texture_clamp_clamp_to_edge",
      41             :                         "texture_clamp_clamp_to_border",
      42             :                         "texture_clamp_mirror",
      43             :                         "texture_clamp_mirror_clamp",
      44             :                         "texture_clamp_mirror_clamp_to_edge",
      45             :                         "texture_clamp_mirror_clamp_to_border", 0};
      46             : 
      47             :         //! Struct for holding material parameters which exist per texture layer
      48             :         class SMaterialLayer
      49             :         {
      50             :         public:
      51             :                 //! Default constructor
      52     5772551 :                 SMaterialLayer()
      53             :                         : Texture(0),
      54             :                                 TextureWrapU(ETC_REPEAT),
      55             :                                 TextureWrapV(ETC_REPEAT),
      56             :                                 BilinearFilter(true),
      57             :                                 TrilinearFilter(false),
      58             :                                 AnisotropicFilter(0),
      59             :                                 LODBias(0),
      60     5772551 :                                 TextureMatrix(0)
      61     5772555 :                         {}
      62             : 
      63             :                 //! Copy constructor
      64             :                 /** \param other Material layer to copy from. */
      65             :                 SMaterialLayer(const SMaterialLayer& other)
      66             :                 {
      67             :                         // This pointer is checked during assignment
      68             :                         TextureMatrix = 0;
      69             :                         *this = other;
      70             :                 }
      71             : 
      72             :                 //! Destructor
      73     5789458 :                 ~SMaterialLayer()
      74     5789395 :                 {
      75     5789458 :                         MatrixAllocator.destruct(TextureMatrix);
      76     5789429 :                         MatrixAllocator.deallocate(TextureMatrix); 
      77     5789367 :                 }
      78             : 
      79             :                 //! Assignment operator
      80             :                 /** \param other Material layer to copy from.
      81             :                 \return This material layer, updated. */
      82     3720300 :                 SMaterialLayer& operator=(const SMaterialLayer& other)
      83             :                 {
      84             :                         // Check for self-assignment!
      85     3720300 :                         if (this == &other)
      86           0 :                                 return *this;
      87             : 
      88     3720300 :                         Texture = other.Texture;
      89     3720300 :                         if (TextureMatrix)
      90             :                         {
      91           0 :                                 if (other.TextureMatrix)
      92           0 :                                         *TextureMatrix = *other.TextureMatrix;
      93             :                                 else
      94             :                                 {
      95           0 :                                         MatrixAllocator.destruct(TextureMatrix);
      96           0 :                                         MatrixAllocator.deallocate(TextureMatrix); 
      97           0 :                                         TextureMatrix = 0;
      98             :                                 }
      99             :                         }
     100             :                         else
     101             :                         {
     102     3720300 :                                 if (other.TextureMatrix)
     103             :                                 {
     104           0 :                                         TextureMatrix = MatrixAllocator.allocate(1);
     105           0 :                                         MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);
     106             :                                 }
     107             :                                 else
     108     3720300 :                                         TextureMatrix = 0;
     109             :                         }
     110     3720280 :                         TextureWrapU = other.TextureWrapU;
     111     3720280 :                         TextureWrapV = other.TextureWrapV;
     112     3720280 :                         BilinearFilter = other.BilinearFilter;
     113     3720280 :                         TrilinearFilter = other.TrilinearFilter;
     114     3720280 :                         AnisotropicFilter = other.AnisotropicFilter;
     115     3720280 :                         LODBias = other.LODBias;
     116             : 
     117     3720280 :                         return *this;
     118             :                 }
     119             : 
     120             :                 //! Gets the texture transformation matrix
     121             :                 /** \return Texture matrix of this layer. */
     122           0 :                 core::matrix4& getTextureMatrix()
     123             :                 {
     124           0 :                         if (!TextureMatrix)
     125             :                         {
     126           0 :                                 TextureMatrix = MatrixAllocator.allocate(1);
     127           0 :                                 MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);
     128             :                         }
     129           0 :                         return *TextureMatrix;
     130             :                 }
     131             : 
     132             :                 //! Gets the immutable texture transformation matrix
     133             :                 /** \return Texture matrix of this layer. */
     134             :                 const core::matrix4& getTextureMatrix() const
     135             :                 {
     136             :                         if (TextureMatrix)
     137             :                                 return *TextureMatrix;
     138             :                         else
     139             :                                 return core::IdentityMatrix;
     140             :                 }
     141             : 
     142             :                 //! Sets the texture transformation matrix to mat
     143             :                 /** \param mat New texture matrix for this layer. */
     144             :                 void setTextureMatrix(const core::matrix4& mat)
     145             :                 {
     146             :                         if (!TextureMatrix)
     147             :                         {
     148             :                                 TextureMatrix = MatrixAllocator.allocate(1);
     149             :                                 MatrixAllocator.construct(TextureMatrix,mat);
     150             :                         }
     151             :                         else
     152             :                                 *TextureMatrix = mat;
     153             :                 }
     154             : 
     155             :                 //! Inequality operator
     156             :                 /** \param b Layer to compare to.
     157             :                 \return True if layers are different, else false. */
     158     4646660 :                 inline bool operator!=(const SMaterialLayer& b) const
     159             :                 {
     160             :                         bool different =
     161     9293320 :                                 Texture != b.Texture ||
     162     9293320 :                                 TextureWrapU != b.TextureWrapU ||
     163     9293320 :                                 TextureWrapV != b.TextureWrapV ||
     164     9293320 :                                 BilinearFilter != b.BilinearFilter ||
     165     9293320 :                                 TrilinearFilter != b.TrilinearFilter ||
     166    13939980 :                                 AnisotropicFilter != b.AnisotropicFilter ||
     167     9293320 :                                 LODBias != b.LODBias;
     168     4646660 :                         if (different)
     169           0 :                                 return true;
     170             :                         else
     171     4646660 :                                 different |= (TextureMatrix != b.TextureMatrix) &&
     172     4646660 :                                         TextureMatrix && b.TextureMatrix &&
     173     4646660 :                                         (*TextureMatrix != *(b.TextureMatrix));
     174     4646660 :                         return different;
     175             :                 }
     176             : 
     177             :                 //! Equality operator
     178             :                 /** \param b Layer to compare to.
     179             :                 \return True if layers are equal, else false. */
     180             :                 inline bool operator==(const SMaterialLayer& b) const
     181             :                 { return !(b!=*this); }
     182             : 
     183             :                 //! Texture
     184             :                 ITexture* Texture;
     185             : 
     186             :                 //! Texture Clamp Mode
     187             :                 /** Values are taken from E_TEXTURE_CLAMP. */
     188             :                 u8 TextureWrapU:4;
     189             :                 u8 TextureWrapV:4;
     190             : 
     191             :                 //! Is bilinear filtering enabled? Default: true
     192             :                 bool BilinearFilter:1;
     193             : 
     194             :                 //! Is trilinear filtering enabled? Default: false
     195             :                 /** If the trilinear filter flag is enabled,
     196             :                 the bilinear filtering flag is ignored. */
     197             :                 bool TrilinearFilter:1;
     198             : 
     199             :                 //! Is anisotropic filtering enabled? Default: 0, disabled
     200             :                 /** In Irrlicht you can use anisotropic texture filtering
     201             :                 in conjunction with bilinear or trilinear texture
     202             :                 filtering to improve rendering results. Primitives
     203             :                 will look less blurry with this flag switched on. The number gives 
     204             :                 the maximal anisotropy degree, and is often in the range 2-16. 
     205             :                 Value 1 is equivalent to 0, but should be avoided. */
     206             :                 u8 AnisotropicFilter;
     207             : 
     208             :                 //! Bias for the mipmap choosing decision.
     209             :                 /** This value can make the textures more or less blurry than with the
     210             :                 default value of 0. The value (divided by 8.f) is added to the mipmap level
     211             :                 chosen initially, and thus takes a smaller mipmap for a region
     212             :                 if the value is positive. */
     213             :                 s8 LODBias;
     214             : 
     215             :         private:
     216             :                 friend class SMaterial;
     217             :                 irr::core::irrAllocator<irr::core::matrix4> MatrixAllocator;
     218             : 
     219             :                 //! Texture Matrix
     220             :                 /** Do not access this element directly as the internal
     221             :                 ressource management has to cope with Null pointers etc. */
     222             :                 core::matrix4* TextureMatrix;
     223             :         };
     224             : 
     225             : } // end namespace video
     226             : } // end namespace irr
     227             : 
     228             : #endif // __S_MATERIAL_LAYER_H_INCLUDED__

Generated by: LCOV version 1.11