/
texture.h
365 lines (301 loc) · 10.4 KB
/
texture.h
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/** @file texture.h Logical Texture.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDENG_RESOURCE_TEXTURE_H
#define LIBDENG_RESOURCE_TEXTURE_H
#include "TextureVariantSpec"
#include <de/Error>
#include <QFlag>
#include <QList>
#include <QPoint>
#include <QSize>
namespace de {
class TextureManifest;
/**
* Logical texture resource.
*
* @ingroup resource
*/
class Texture
{
struct Instance; // Needs to be friended by Variant.
public:
/**
* Classification/processing flags.
*/
enum Flag
{
/// Texture is not to be drawn.
NoDraw = 0x1,
/// Texture is "custom" (i.e., not an original game resource).
Custom = 0x2,
/// Apply the monochrome filter to the processed image.
Monochrome = 0x4,
/// Apply the upscaleAndSharpen filter to the processed image.
UpscaleAndSharpen = 0x8
};
Q_DECLARE_FLAGS(Flags, Flag)
/**
* Image analysis identifiers.
*/
enum AnalysisId
{
/// Color palette info.
ColorPaletteAnalysis,
/// Brightest point for automatic light sources.
BrightPointAnalysis,
/// Average color.
AverageColorAnalysis,
/// Average color amplified (max component ==1).
AverageColorAmplifiedAnalysis,
/// Average alpha.
AverageAlphaAnalysis,
/// Average top line color.
AverageTopColorAnalysis,
/// Average bottom line color.
AverageBottomColorAnalysis
};
/**
* Context-specialized variant. Encapsulates all context variant values
* and logics pertaining to a specialized version of the @em superior
* Texture instance.
*
* @see texturevariantspecification_t
*/
class Variant
{
public:
enum Flag
{
/// Texture contains alpha.
Masked = 0x1,
/// Texture has been uploaded to GL.
Uploaded = 0x2
};
Q_DECLARE_FLAGS(Flags, Flag)
private:
/**
* @param generalCase Texture from which this variant is derived.
* @param spec Specification used to derive this variant.
* Ownership is NOT given to the Variant.
*/
Variant(Texture &generalCase, texturevariantspecification_t const &spec);
~Variant();
public:
/**
* Retrieve the general case for this variant. Allows for a variant
* reference to be used in place of a texture (implicit indirection).
*
* @see generalCase()
*/
inline operator Texture &() const {
return generalCase();
}
/// @return Superior texture of which the variant is a derivative.
Texture &generalCase() const;
/// @return Texture variant specification for the variant.
texturevariantspecification_t const &spec() const;
/// @return Source of the variant.
TexSource source() const;
/**
* Change the source of the variant.
* @param newSource New TextureSource.
*/
void setSource(TexSource newSource);
void coords(float *s, float *t) const;
void setCoords(float s, float t);
/// Returns @c true if the variant is flagged as "masked".
inline bool isMasked() const { return flags().testFlag(Masked); }
#ifdef __CLIENT__
/// Returns @c true if the variant is flagged as "uploaded".
inline bool isUploaded() const { return flags().testFlag(Uploaded); }
/// Returns @c true if the variant is "prepared".
inline bool isPrepared() const { return isUploaded() && glName() != 0; }
#endif
/**
* Returns the flags for the variant.
*/
Flags flags() const;
/**
* Change the variant's flags.
*
* @param flagsToChange Flags to change the value of.
* @param set @c true to set, @c false to clear.
*/
void setFlags(Flags flagsToChange, bool set = true);
#ifdef __CLIENT__
/**
* Returns the GL-name of the uploaded texture content for the variant;
* otherwise @c 0 (not uploaded).
*/
uint glName() const;
/**
* Change the GL-name of the uploaded texture content associated with
* the variant.
*
* @param newGLName New GL-name. Can be @c 0.
*/
void setGLName(uint newGLName);
#endif
friend class Texture;
friend struct Texture::Instance;
private:
struct Instance;
Instance *d;
};
/// A list of variants.
typedef QList<Variant *> Variants;
/**
* Logics for selecting a texture variant instance from the candidates.
*
* @see chooseVariant()
*/
enum ChooseVariantMethod
{
/// The variant specification of the candidate must match exactly.
MatchSpec,
/// The variant specification of the candidate must match however
/// certain properties may vary (e.g., quality arguments) if it means
/// we can avoid creating a new variant.
FuzzyMatchSpec
};
public:
/**
* @param manifest Manifest derived to yield the texture.
*/
Texture(TextureManifest &manifest);
~Texture();
/**
* Returns the TextureManifest derived to yield the texture.
*/
TextureManifest &manifest() const;
/// Returns the dimensions of the texture in map coordinate space units.
QSize const &dimensions() const;
/// Returns the world width of the texture in map coordinate space units.
inline int width() const { return dimensions().width(); }
/// Returns the world height of the texture in map coordinate space units.
inline int height() const { return dimensions().height(); }
/**
* Change the world dimensions of the texture.
* @param newDimensions New dimensions in map coordinate space units.
*
* @todo Update any Materials (and thus Surfaces) which reference this.
*/
void setDimensions(QSize const &newDimensions);
/**
* Change the world width of the texture.
* @param newWidth New width in map coordinate space units.
*
* @todo Update any Materials (and thus Surfaces) which reference this.
*/
void setWidth(int newWidth);
/**
* Change the world height of the texture.
* @param newHeight New height in map coordinate space units.
*
* @todo Update any Materials (and thus Surfaces) which reference this.
*/
void setHeight(int newHeight);
/**
* Returns the world origin offset of texture in map coordinate space units.
*/
QPoint const &origin() const;
/**
* Change the world origin offset of the texture.
* @param newOrigin New origin in map coordinate space units.
*/
void setOrigin(QPoint const &newOrigin);
/**
* Returns the flags for the texture.
*/
Flags flags() const;
/**
* Change the texture's flags.
*
* @param flagsToChange Flags to change the value of.
* @param set @c true to set, @c false to clear.
*/
void setFlags(Flags flagsToChange, bool set = true);
/**
* Destroys all derived variants for the texture.
*/
void clearVariants();
/**
* Choose/create a variant of the texture which fulfills @a spec.
*
* @param method Method of selection.
* @param spec Texture specialization specification.
* @param canCreate @c true= Create a new variant if no suitable one exists.
*
* @return Chosen variant; otherwise @c NULL if none suitable and not creating.
*/
Variant *chooseVariant(ChooseVariantMethod method,
texturevariantspecification_t const &spec, bool canCreate = false);
/**
* Provides access to the list of variant instances for efficent traversal.
*/
Variants const &variants() const;
/**
* Returns the number of variants for the texture.
*/
uint variantCount() const;
/**
* Destroys all analyses for the texture.
*/
void clearAnalyses();
/**
* Retrieve the value of an identified @a analysisId data pointer.
* @return Associated data pointer value.
*/
void *analysisDataPointer(AnalysisId analysisId) const;
/**
* Set the value of an identified @a analysisId data pointer. Ownership of
* the data is not given to this instance.
*
* @note If already set the old value will be replaced (so if it points
* to some dynamically constructed data/resource it is the caller's
* responsibility to release it beforehand).
*
* @param analysisId Identifier of the data being attached.
* @param data Data to be attached.
*/
void setAnalysisDataPointer(AnalysisId analysisId, void *data);
/**
* Retrieve the value of the associated user data pointer.
* @return Associated data pointer value.
*/
void *userDataPointer() const;
/**
* Set the user data pointer value. Ownership of the data is not given to
* this instance.
*
* @note If already set the old value will be replaced (so if it points
* to some dynamically constructed data/resource it is the caller's
* responsibility to release it beforehand).
*
* @param userData User data pointer value.
*/
void setUserDataPointer(void *userData);
private:
Instance *d;
};
typedef Texture::Variant TextureVariant;
} // namespace de
struct texture_s; // The texture instance (opaque).
#endif /// LIBDENG_RESOURCE_TEXTURE_H