Irrlicht 3D Engine
SMaterialLayer.h
Go to the documentation of this file.
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 
19  {
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 
49  {
50  public:
53  : Texture(0),
56  BilinearFilter(true),
57  TrilinearFilter(false),
59  LODBias(0),
60  TextureMatrix(0)
61  {}
62 
64 
66  {
67  // This pointer is checked during assignment
68  TextureMatrix = 0;
69  *this = other;
70  }
71 
74  {
75  MatrixAllocator.destruct(TextureMatrix);
76  MatrixAllocator.deallocate(TextureMatrix);
77  }
78 
80 
83  {
84  // Check for self-assignment!
85  if (this == &other)
86  return *this;
87 
88  Texture = other.Texture;
89  if (TextureMatrix)
90  {
91  if (other.TextureMatrix)
92  *TextureMatrix = *other.TextureMatrix;
93  else
94  {
95  MatrixAllocator.destruct(TextureMatrix);
96  MatrixAllocator.deallocate(TextureMatrix);
97  TextureMatrix = 0;
98  }
99  }
100  else
101  {
102  if (other.TextureMatrix)
103  {
104  TextureMatrix = MatrixAllocator.allocate(1);
105  MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);
106  }
107  else
108  TextureMatrix = 0;
109  }
110  TextureWrapU = other.TextureWrapU;
111  TextureWrapV = other.TextureWrapV;
115  LODBias = other.LODBias;
116 
117  return *this;
118  }
119 
121 
123  {
124  if (!TextureMatrix)
125  {
126  TextureMatrix = MatrixAllocator.allocate(1);
127  MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);
128  }
129  return *TextureMatrix;
130  }
131 
133 
135  {
136  if (TextureMatrix)
137  return *TextureMatrix;
138  else
139  return core::IdentityMatrix;
140  }
141 
143 
145  {
146  if (!TextureMatrix)
147  {
148  TextureMatrix = MatrixAllocator.allocate(1);
149  MatrixAllocator.construct(TextureMatrix,mat);
150  }
151  else
152  *TextureMatrix = mat;
153  }
154 
156 
158  inline bool operator!=(const SMaterialLayer& b) const
159  {
160  bool different =
161  Texture != b.Texture ||
162  TextureWrapU != b.TextureWrapU ||
163  TextureWrapV != b.TextureWrapV ||
167  LODBias != b.LODBias;
168  if (different)
169  return true;
170  else
171  different |= (TextureMatrix != b.TextureMatrix) &&
172  TextureMatrix && b.TextureMatrix &&
173  (*TextureMatrix != *(b.TextureMatrix));
174  return different;
175  }
176 
178 
180  inline bool operator==(const SMaterialLayer& b) const
181  { return !(b!=*this); }
182 
185 
187 
190 
193 
195 
198 
200 
207 
209 
214 
215  private:
216  friend class SMaterial;
218 
220 
222  core::matrix4* TextureMatrix;
223  };
224 
225 } // end namespace video
226 } // end namespace irr
227 
228 #endif // __S_MATERIAL_LAYER_H_INCLUDED__
SMaterialLayer & operator=(const SMaterialLayer &other)
Assignment operator.
SMaterialLayer(const SMaterialLayer &other)
Copy constructor.
IRRLICHT_API const matrix4 IdentityMatrix
global const identity matrix
const core::matrix4 & getTextureMatrix() const
Gets the immutable texture transformation matrix.
Texture is clamped to the border pixel (if exists)
Texture is alternatingly mirrored (0..1..0..1..0..)
bool TrilinearFilter
Is trilinear filtering enabled? Default: false.
u8 TextureWrapU
Texture Clamp Mode.
bool operator==(const SMaterialLayer &b) const
Equality operator.
void destruct(T *ptr)
Destruct an element.
Definition: irrAllocator.h:51
Texture is clamped to the edge pixel.
Texture is clamped to the last pixel.
Everything in the Irrlicht Engine can be found in this namespace.
Definition: aabbox3d.h:12
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:18
SMaterialLayer()
Default constructor.
Texture repeats.
Struct for holding material parameters which exist per texture layer.
core::matrix4 & getTextureMatrix()
Gets the texture transformation matrix.
ITexture * Texture
Texture.
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition: irrAllocator.h:33
signed char s8
8 bit signed variable.
Definition: irrTypes.h:26
u8 AnisotropicFilter
Is anisotropic filtering enabled? Default: 0, disabled.
bool BilinearFilter
Is bilinear filtering enabled? Default: true.
bool operator!=(const SMaterialLayer &b) const
Inequality operator.
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition: matrix4.h:45
void construct(T *ptr, const T &e)
Construct an element.
Definition: irrAllocator.h:45
Interface of a Video Driver dependent Texture.
Definition: ITexture.h:98
s8 LODBias
Bias for the mipmap choosing decision.
Texture is mirrored once and then clamped to edge.
Texture is mirrored once and then clamped (0..1..0)
Texture is mirrored once and then clamped to border.
void deallocate(T *ptr)
Deallocate memory for an array of objects.
Definition: irrAllocator.h:39
Struct for holding parameters for a material renderer.
Definition: SMaterial.h:226
E_TEXTURE_CLAMP
Texture coord clamp mode outside [0.0, 1.0].
void setTextureMatrix(const core::matrix4 &mat)
Sets the texture transformation matrix to mat.