Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

# SMaterialLayer.h

Go to the documentation of this file.

    00001 // Copyright (C) 2002-2009 Nikolaus Gebhardt
    00002 // This file is part of the "Irrlicht Engine".
    00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
    00004
    00005 #ifndef __S_MATERIAL_LAYER_H_INCLUDED__
    00006 #define __S_MATERIAL_LAYER_H_INCLUDED__
    00007
    00008 #include "matrix4.h"
    00009 #include "irrAllocator.h"
    00010
    00011 namespace irr
    00012 {
    00013 namespace video
    00014 {
    00015         class ITexture;
    00016
    00018         enum E_TEXTURE_CLAMP
    00019         {
    00021                 ETC_REPEAT = 0,
    00023                 ETC_CLAMP,
    00025                 ETC_CLAMP_TO_EDGE,
    00027                 ETC_CLAMP_TO_BORDER,
    00029                 ETC_MIRROR
    00030         };
    00031         static const char* const aTextureClampNames[] = {
    00032                         "texture_clamp_repeat",
    00033                         "texture_clamp_clamp",
    00034                         "texture_clamp_clamp_to_edge",
    00035                         "texture_clamp_clamp_to_border",
    00036                         "texture_clamp_mirror", 0};
    00037
    00039         class SMaterialLayer
    00040         {
    00041         public:
    00043                 SMaterialLayer()
    00044                         : Texture(0),
    00045                                 TextureWrap(ETC_REPEAT),
    00046                                 BilinearFilter(true),
    00047                                 TrilinearFilter(false),
    00048                                 AnisotropicFilter(0),
    00049                                 LODBias(0),
    00050                                 TextureMatrix(0)
    00051                         {}
    00052
    00054
    00055                 SMaterialLayer(const SMaterialLayer& other)
    00056                 {
    00057                         // This pointer is checked during assignment
    00058                         TextureMatrix = 0;
    00059                         *this = other;
    00060                 }
    00061
    00063                 ~SMaterialLayer()
    00064                 {
    00065                         MatrixAllocator.destruct(TextureMatrix);
    00066                         MatrixAllocator.deallocate(TextureMatrix);
    00067                 }
    00068
    00070
    00072                 SMaterialLayer& operator=(const SMaterialLayer& other)
    00073                 {
    00074                         // Check for self-assignment!
    00075                         if (this == &other)
    00076                                 return *this;
    00077
    00078                         Texture = other.Texture;
    00079                         if (TextureMatrix)
    00080                         {
    00081                                 if (other.TextureMatrix)
    00082                                         *TextureMatrix = *other.TextureMatrix;
    00083                                 else
    00084                                 {
    00085                                         MatrixAllocator.destruct(TextureMatrix);
    00086                                         MatrixAllocator.deallocate(TextureMatrix);
    00087                                         TextureMatrix = 0;
    00088                                 }
    00089                         }
    00090                         else
    00091                         {
    00092                                 if (other.TextureMatrix)
    00093                                 {
    00094                                         TextureMatrix = MatrixAllocator.allocate(1);
    00095                                         MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);
    00096                                 }
    00097                                 else
    00098                                         TextureMatrix = 0;
    00099                         }
    00100                         TextureWrap = other.TextureWrap;
    00101                         BilinearFilter = other.BilinearFilter;
    00102                         TrilinearFilter = other.TrilinearFilter;
    00103                         AnisotropicFilter = other.AnisotropicFilter;
    00104                         LODBias = other.LODBias;
    00105
    00106                         return *this;
    00107                 }
    00108
    00110                 ITexture* Texture;
    00111
    00113                 u8 TextureWrap;
    00114
    00116                 bool BilinearFilter:1;
    00117
    00119
    00121                 bool TrilinearFilter:1;
    00122
    00124
    00130                 u8 AnisotropicFilter;
    00131
    00133
    00137                 s8 LODBias;
    00138
    00140
    00141                 core::matrix4& getTextureMatrix()
    00142                 {
    00143                         if (!TextureMatrix)
    00144                         {
    00145                                 TextureMatrix = MatrixAllocator.allocate(1);
    00146                                 MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);
    00147                         }
    00148                         return *TextureMatrix;
    00149                 }
    00150
    00152
    00153                 const core::matrix4& getTextureMatrix() const
    00154                 {
    00155                         if (TextureMatrix)
    00156                                 return *TextureMatrix;
    00157                         else
    00158                                 return core::IdentityMatrix;
    00159                 }
    00160
    00162
    00163                 void setTextureMatrix(const core::matrix4& mat)
    00164                 {
    00165                         if (!TextureMatrix)
    00166                         {
    00167                                 TextureMatrix = MatrixAllocator.allocate(1);
    00168                                 MatrixAllocator.construct(TextureMatrix,mat);
    00169                         }
    00170                         else
    00171                                 *TextureMatrix = mat;
    00172                 }
    00173
    00175
    00177                 inline bool operator!=(const SMaterialLayer& b) const
    00178                 {
    00179                         bool different =
    00180                                 Texture != b.Texture ||
    00181                                 TextureWrap != b.TextureWrap ||
    00182                                 BilinearFilter != b.BilinearFilter ||
    00183                                 TrilinearFilter != b.TrilinearFilter ||
    00184                                 AnisotropicFilter != b.AnisotropicFilter ||
    00185                                 LODBias != b.LODBias;
    00186                         if (different)
    00187                                 return true;
    00188                         else
    00189                                 different |= (TextureMatrix != b.TextureMatrix) &&
    00190                                         TextureMatrix && b.TextureMatrix &&
    00191                                         (*TextureMatrix != *(b.TextureMatrix));
    00192                         return different;
    00193                 }
    00194
    00196
    00198                 inline bool operator==(const SMaterialLayer& b) const
    00199                 { return !(b!=*this); }
    00200
    00201         private:
    00202                 friend class SMaterial;
    00203                 irr::core::irrAllocator<irr::core::matrix4> MatrixAllocator;
    00204
    00206
    00208                 core::matrix4* TextureMatrix;
    00209         };
    00210
    00211 } // end namespace video
    00212 } // end namespace irr
    00213
    00214 #endif // __S_MATERIAL_LAYER_H_INCLUDED__

| The Irrlicht Engine Documentation © 2003-2009 by Nikolaus Gebhardt. Generated on Sun Jan 10 09:24:05 2010 by Doxygen (1.5.6)