summaryrefslogtreecommitdiff
path: root/public/movieobjects/dmetexture.h
blob: 5b889a4adedcd57801004494872e49574e3c2fa1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// A class representing a procedural texture
//
//=============================================================================

#ifndef DMETEXTURE_H
#define DMETEXTURE_H
#ifdef _WIN32
#pragma once
#endif

#include "datamodel/dmelement.h"
#include "materialsystem/MaterialSystemUtil.h"
#include "movieobjects/dmeimage.h"


//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class ITexture;
class IMesh;
enum ImageFormat;
class IVTFTexture;


//-----------------------------------------------------------------------------
// Compression types
//-----------------------------------------------------------------------------
enum DmeTextureCompress_t
{
	DMETEXTURE_COMPRESS_DEFAULT = 0,
	DMETEXTURE_COMPRESS_NONE,
	DMETEXTURE_COMPRESS_DXT1,
	DMETEXTURE_COMPRESS_DXT5,
};


//-----------------------------------------------------------------------------
// Filter types
//-----------------------------------------------------------------------------
enum DmeTextureFilter_t
{
	DMETEXTURE_FILTER_DEFAULT = 0,
	DMETEXTURE_FILTER_ANISOTROPIC,
	DMETEXTURE_FILTER_TRILINEAR,
	DMETEXTURE_FILTER_BILINEAR,
	DMETEXTURE_FILTER_POINT,
};


//-----------------------------------------------------------------------------
// Mipmap types
//-----------------------------------------------------------------------------
enum DmeTextureMipmap_t
{
	DMETEXTURE_MIPMAP_DEFAULT = 0,
	DMETEXTURE_MIPMAP_ALL_LEVELS,
	DMETEXTURE_MIPMAP_NONE,
};


//-----------------------------------------------------------------------------
// A base class for textures
//-----------------------------------------------------------------------------
class CDmeBaseTexture : public CDmElement
{
	DEFINE_ELEMENT( CDmeBaseTexture, CDmElement );

public:
	ITexture *GetCachedTexture();

	// Compression type
	void SetCompressionType( DmeTextureCompress_t type );
	DmeTextureCompress_t GetCompressionType() const;

	// Filter type
	void SetFilterType( DmeTextureFilter_t type );
	DmeTextureFilter_t GetFilterType() const;

	// Mipmap type
	void SetMipmapType( DmeTextureMipmap_t type );
	DmeTextureMipmap_t GetMipmapType() const;

public:
	CDmAttributeVar<bool> m_bClampS;
	CDmAttributeVar<bool> m_bClampT;
	CDmAttributeVar<bool> m_bClampU;
	CDmAttributeVar<bool> m_bNoDebugOverride;
	CDmAttributeVar<bool> m_bNoLod;
	CDmAttributeVar<bool> m_bNiceFiltered;
	CDmAttributeVar<bool> m_bNormalMap;
	CDmAttributeVar<float> m_flBumpScale;

protected:
	// Computes texture flags
	int CalcTextureFlags( int nDepth ) const;

	// Computes the desired texture format based on flags
	ImageFormat ComputeDesiredImageFormat( ImageFormat srcFormat, int nWidth, int nHeight, int nDepth, int nFlags );

	CDmAttributeVar<int> m_nCompressType;
	CDmAttributeVar<int> m_nFilterType;
	CDmAttributeVar<int> m_nMipmapType;

	// Computed values
	CTextureReference m_Texture;
	IVTFTexture *m_pVTFTexture;
	Vector m_vecReflectivity;
};


//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline void CDmeBaseTexture::SetCompressionType( DmeTextureCompress_t type )
{
	m_nCompressType = type;
}

inline DmeTextureCompress_t CDmeBaseTexture::GetCompressionType() const
{
	return (DmeTextureCompress_t)m_nCompressType.Get();
}

inline void CDmeBaseTexture::SetFilterType( DmeTextureFilter_t type )
{
	m_nFilterType = type;
}

inline DmeTextureFilter_t CDmeBaseTexture::GetFilterType() const
{
	return (DmeTextureFilter_t)m_nFilterType.Get();
}

inline void CDmeBaseTexture::SetMipmapType( DmeTextureMipmap_t type )
{
	m_nMipmapType = type;
}

inline DmeTextureMipmap_t CDmeBaseTexture::GetMipmapType() const
{
	return (DmeTextureMipmap_t)m_nMipmapType.Get();
}


//-----------------------------------------------------------------------------
// A class representing a texture
//-----------------------------------------------------------------------------
class CDmeTexture : public CDmeBaseTexture
{
	DEFINE_ELEMENT( CDmeTexture, CDmeBaseTexture );

public:
	virtual void Resolve();

private:
	// Array of images in an animated texture
	CDmAttributeVarElementArray< CDmeImage > m_Images;
};


//-----------------------------------------------------------------------------
// A class representing a cube texture
//-----------------------------------------------------------------------------
class CDmeCubeTexture : public CDmeBaseTexture
{
	DEFINE_ELEMENT( CDmeCubeTexture, CDmeBaseTexture );

public:
	virtual void Resolve();

private:
	// Array of images in an animated texture
	CDmAttributeVarElementArray< CDmeImage > m_ImagesPosX;
	CDmAttributeVarElementArray< CDmeImage > m_ImagesNegX;
	CDmAttributeVarElementArray< CDmeImage > m_ImagesPosY;
	CDmAttributeVarElementArray< CDmeImage > m_ImagesNegY;
	CDmAttributeVarElementArray< CDmeImage > m_ImagesPosZ;
	CDmAttributeVarElementArray< CDmeImage > m_ImagesNegZ;
};


#endif // DMETEXTURE_H