#ifndef __S_MATERIAL_LAYER_H_INCLUDED__
#define __S_MATERIAL_LAYER_H_INCLUDED__
#include "matrix4.h"
#include "irrAllocator.h"
namespace irr
{
namespace video
{
class ITexture;
enum E_TEXTURE_CLAMP
{
ETC_REPEAT = 0,
ETC_CLAMP,
ETC_CLAMP_TO_EDGE,
ETC_CLAMP_TO_BORDER,
ETC_MIRROR,
ETC_MIRROR_CLAMP,
ETC_MIRROR_CLAMP_TO_EDGE,
ETC_MIRROR_CLAMP_TO_BORDER
};
static const char* const aTextureClampNames[] = {
"texture_clamp_repeat",
"texture_clamp_clamp",
"texture_clamp_clamp_to_edge",
"texture_clamp_clamp_to_border",
"texture_clamp_mirror",
"texture_clamp_mirror_clamp",
"texture_clamp_mirror_clamp_to_edge",
"texture_clamp_mirror_clamp_to_border", 0};
class SMaterialLayer
{
public:
SMaterialLayer()
: Texture(0),
TextureWrapU(ETC_REPEAT),
TextureWrapV(ETC_REPEAT),
BilinearFilter(true),
TrilinearFilter(false),
AnisotropicFilter(0),
LODBias(0),
TextureMatrix(0)
{}
SMaterialLayer(const SMaterialLayer& other)
{
TextureMatrix = 0;
*this = other;
}
~SMaterialLayer()
{
MatrixAllocator.destruct(TextureMatrix);
MatrixAllocator.deallocate(TextureMatrix);
}
SMaterialLayer& operator=(const SMaterialLayer& other)
{
if (this == &other)
return *this;
Texture = other.Texture;
if (TextureMatrix)
{
if (other.TextureMatrix)
*TextureMatrix = *other.TextureMatrix;
else
{
MatrixAllocator.destruct(TextureMatrix);
MatrixAllocator.deallocate(TextureMatrix);
TextureMatrix = 0;
}
}
else
{
if (other.TextureMatrix)
{
TextureMatrix = MatrixAllocator.allocate(1);
MatrixAllocator.construct(TextureMatrix,*other.TextureMatrix);
}
else
TextureMatrix = 0;
}
TextureWrapU = other.TextureWrapU;
TextureWrapV = other.TextureWrapV;
BilinearFilter = other.BilinearFilter;
TrilinearFilter = other.TrilinearFilter;
AnisotropicFilter = other.AnisotropicFilter;
LODBias = other.LODBias;
return *this;
}
core::matrix4& getTextureMatrix()
{
if (!TextureMatrix)
{
TextureMatrix = MatrixAllocator.allocate(1);
MatrixAllocator.construct(TextureMatrix,core::IdentityMatrix);
}
return *TextureMatrix;
}
const core::matrix4& getTextureMatrix() const
{
if (TextureMatrix)
return *TextureMatrix;
else
return core::IdentityMatrix;
}
void setTextureMatrix(const core::matrix4& mat)
{
if (!TextureMatrix)
{
TextureMatrix = MatrixAllocator.allocate(1);
MatrixAllocator.construct(TextureMatrix,mat);
}
else
*TextureMatrix = mat;
}
inline bool operator!=(const SMaterialLayer& b) const
{
bool different =
Texture != b.Texture ||
TextureWrapU != b.TextureWrapU ||
TextureWrapV != b.TextureWrapV ||
BilinearFilter != b.BilinearFilter ||
TrilinearFilter != b.TrilinearFilter ||
AnisotropicFilter != b.AnisotropicFilter ||
LODBias != b.LODBias;
if (different)
return true;
else
different |= (TextureMatrix != b.TextureMatrix) &&
TextureMatrix && b.TextureMatrix &&
(*TextureMatrix != *(b.TextureMatrix));
return different;
}
inline bool operator==(const SMaterialLayer& b) const
{ return !(b!=*this); }
ITexture* Texture;
u8 TextureWrapU:4;
u8 TextureWrapV:4;
bool BilinearFilter:1;
bool TrilinearFilter:1;
u8 AnisotropicFilter;
s8 LODBias;
private:
friend class SMaterial;
irr::core::irrAllocator<irr::core::matrix4> MatrixAllocator;
core::matrix4* TextureMatrix;
};
}
}
#endif