/
gl_texmanager.h
368 lines (312 loc) · 12.6 KB
/
gl_texmanager.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
366
367
368
/**\file gl_texmanager.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2011 Daniel Swanson <danij@dengine.net>
*
* 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
*/
/**
* Texture Management
*/
#ifndef LIBDENG_TEXTURE_MANAGER_H
#define LIBDENG_TEXTURE_MANAGER_H
#include "r_data.h"
#include "r_model.h"
#include "gl_model.h"
#include "gl_defer.h"
#include "texturevariantspecification.h"
#define TEXQ_BEST 8
#define MINTEXWIDTH 8
#define MINTEXHEIGHT 8
struct image_s;
struct texturecontent_s;
struct texture_s;
struct texturevariant_s;
struct texturevariantspecification_s;
extern int ratioLimit;
extern int mipmapping, filterUI, texQuality, filterSprites;
extern int texMagMode, texAniso;
extern int useSmartFilter;
extern int texMagMode;
extern int monochrome, upscaleAndSharpenPatches;
extern int glmode[6];
extern boolean fillOutlines;
extern boolean noHighResTex;
extern boolean noHighResPatches;
extern boolean highResWithPWAD;
extern byte loadExtAlways;
void GL_TexRegister(void);
/**
* Called before real texture management is up and running, during engine
* early init.
*/
void GL_EarlyInitTextureManager(void);
void GL_InitTextureManager(void);
/**
* Call this if a full cleanup of the textures is required (engine update).
*/
void GL_ResetTextureManager(void);
void GL_ShutdownTextureManager(void);
void GL_DestroyTextures(void);
void GL_TexReset(void);
/**
* Prepares all the system textures (dlight, ptcgens).
*/
void GL_LoadSystemTextures(void);
void GL_ClearTextureMemory(void);
/**
* Runtime textures are not loaded until precached or actually needed.
* They may be cleared, in which case they will be reloaded when needed.
*/
void GL_ClearRuntimeTextures(void);
/**
* System textures are loaded at startup and remain in memory all the time.
* After clearing they must be manually reloaded.
*/
void GL_ClearSystemTextures(void);
/**
* To save texture memory, delete all raw image textures. Raw images are
* used as interlude backgrounds, title screens, etc. Called from
* DD_SetupLevel.
*/
void GL_DeleteRawImages(void);
/**
* Called when changing the value of any cvar affecting texture quality which
* in turn calls GL_TexReset. Added to remove the need for reseting manually.
*/
void GL_DoTexReset(const cvar_t* /*cvar*/);
/**
* Called when changing the value of the texture gamma cvar.
*/
void GL_DoUpdateTexGamma(const cvar_t* /*cvar*/);
/**
* Called when changing the value of any cvar affecting texture quality which
* can be actioned by simply changing texture paramaters i.e. does not require
* flushing GL textures).
*/
void GL_DoUpdateTexParams(const cvar_t* /*cvar*/);
void GL_UpdateTexParams(int mipmode);
/**
* Updates the textures, flats and sprites (gameTex) or the user
* interface textures (patches and raw screens).
*/
void GL_SetTextureParams(int minMode, int gameTex, int uiTex);
/**
* @param glFormat Identifier of the desired GL texture format.
* @param loadFormat Identifier of the GL texture format used during upload.
* @param pixels Texture pixel data to be uploaded.
* @param width Logical width of the texture in pixels.
* @param height Logical height of the texture in pixels.
* @param genMipmaps If negative sets a specific mipmap level, e.g.:
* @c -1, means mipmap level 1.
*
* @return @c true iff successful.
*/
boolean GL_TexImage(int glFormat, int loadFormat, const uint8_t* pixels,
int width, int height, int genMipmaps);
/**
* @param glFormat Identifier of the desired GL texture format.
* @param loadFormat Identifier of the GL texture format used during upload.
* @param pixels Texture pixel data to be uploaded.
* @param width Logical width of the texture in pixels.
* @param height Logical height of the texture in pixels.
* @param grayFactor Strength of the blend where @c 0:none @c 1:full.
*
* @return @c true iff successful.
*/
boolean GL_TexImageGrayMipmap(int glFormat, int loadFormat, const uint8_t* pixels,
int width, int height, float grayFactor);
/**
* Can be rather time-consuming due to scaling operations and mipmap
* generation. The texture parameters will NOT be set here.
*
* @return The name of the texture.
*/
DGLuint GL_UploadTextureContent(const struct texturecontent_s* content);
DGLuint GL_UploadTextureWithParams(const uint8_t* pixels, int width, int height,
dgltexformat_t texFormat, boolean flagGenerateMipmaps,
boolean flagNoStretch, boolean flagNoSmartFilter, int minFilter,
int magFilter, int anisoFilter, int wrapS, int wrapT, int otherFlags);
/**
* @return @c true iff this operation was deferred.
*/
boolean GL_NewTexture(const struct texturecontent_s* content);
DGLuint GL_NewTextureWithParams(dgltexformat_t format, int width, int height,
const uint8_t* pixels, int flags);
DGLuint GL_NewTextureWithParams2(dgltexformat_t format, int width, int height,
const uint8_t* pixels, int flags, int grayMipmap, int minFilter, int magFilter,
int anisoFilter, int wrapS, int wrapT);
DGLuint GL_NewTextureWithParams3(dgltexformat_t format, int width, int height,
const uint8_t* pixels, int flags, int grayMipmap, int minFilter, int magFilter,
int anisoFilter, int wrapS, int wrapT, boolean* didDefer);
/**
* @return The outcome:
* 0 = not prepared
* 1 = found and prepared a lump resource.
* 2 = found and prepared an external resource.
*/
byte GL_LoadRawTex(struct image_s* image, const rawtex_t* r);
/**
* @return The outcome:
* 0 = not prepared
* 2 = found and prepared an external resource.
*/
byte GL_LoadExtTexture(struct image_s* image, const char* name, gfxmode_t mode);
byte GL_LoadExtTextureEX(struct image_s* image, const char* searchPath,
const char* optionalSuffix, boolean silent);
byte GL_LoadFlatLump(struct image_s* image, lumpnum_t lumpNum);
byte GL_LoadPatchLump(struct image_s* image, lumpnum_t lumpNum, int tclass,
int tmap, int border);
byte GL_LoadDetailTextureLump(struct image_s* image, lumpnum_t lumpNum);
byte GL_LoadPatchComposite(struct image_s* image, const struct texture_s* tex);
byte GL_LoadPatchCompositeAsSky(struct image_s* image, const struct texture_s* tex,
boolean zeroMask);
/**
* Set mode to 2 to include an alpha channel. Set to 3 to make the
* actual pixel colors all white.
*/
DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap,
int minFilter, int magFilter, int anisoFilter, int wrapS, int wrapT,
int flags);
/**
* Prepare a texture used in the lighting system. 'which' must be one
* of the LST_* constants.
*/
DGLuint GL_PrepareLSTexture(lightingtexid_t which);
DGLuint GL_PrepareSysFlareTexture(flaretexid_t flare);
/**
* Returns the OpenGL name of the texture.
*/
DGLuint GL_PreparePatch(patchtex_t* patch);
/**
* Returns the OpenGL name of the texture.
*/
DGLuint GL_PrepareRawTex(rawtex_t* rawTex);
DGLuint GL_GetLightMapTexture(const dduri_t* path);
/**
* Attempt to locate and prepare a flare texture.
* Somewhat more complicated than it needs to be due to the fact there
* are two different selection methods.
*
* @param name Name of a flare texture or "0" to "4".
* @param oldIdx Old method of flare texture selection, by id.
*/
DGLuint GL_GetFlareTexture(const dduri_t* path, int oldIdx);
/**
* Determine the optimal size for a texture. Usually the dimensions are
* scaled upwards to the next power of two.
*
* @param noStretch If @c true, the stretching can be skipped.
* @param isMipMapped If @c true, we will require mipmaps (this has an
* effect on the optimal size).
*/
boolean GL_OptimalTextureSize(int width, int height, boolean noStretch,
boolean isMipMapped, int* optWidth, int* optHeight);
/**
* Compare the given TextureVariantSpecifications and determine whether
* they can be considered equal (dependent on current engine state and
* the available features of the GL implementation).
*/
int GL_CompareTextureVariantSpecifications(const texturevariantspecification_t* a,
const texturevariantspecification_t* b);
/**
* Prepare a TextureVariantSpecification according to usage context.
* If incomplete context information is supplied, suitable defaults are
* chosen in their place.
*
* @param tc Usage context.
* @param flags @see textureVariantSpecificationFlags
* @param border Border size in pixels (all edges).
* @param tClass Color palette translation class.
* @param tMap Color palette translation map.
*
* @return Ptr to a rationalized and valid TextureVariantSpecification
* or @c NULL if out of memory.
*/
texturevariantspecification_t* GL_TextureVariantSpecificationForContext(
texturevariantusagecontext_t tc, int flags, byte border, int tClass,
int tMap, int wrapS, int wrapT, int anisoFilter, boolean mipmapped,
boolean gammaCorrection, boolean noStretch, boolean toAlpha);
/**
* Prepare a TextureVariantSpecification according to usage context.
* If incomplete context information is supplied, suitable defaults are
* chosen in their place.
*
* @return Ptr to a rationalized and valid TextureVariantSpecification
* or @c NULL if out of memory.
*/
texturevariantspecification_t* GL_DetailTextureVariantSpecificationForContext(
float contrast);
/**
* Output a human readable representation of TextureVariantSpecification
* to console output.
*
* @param spec Specification to echo.
*/
void GL_PrintTextureVariantSpecification(const texturevariantspecification_t* spec);
void GL_ReleaseGLTexturesForTexture(struct texture_s* tex);
/**
* Given a texture identifier retrieve the associated texture.
* @return Found Texture object else @c NULL
*/
struct texture_s* GL_ToTexture(textureid_t id);
/// Result of a request to prepare a TextureVariant
typedef enum {
PTR_NOTFOUND = 0, /// Failed. No suitable variant could be found/prepared.
PTR_FOUND, /// Success. Reusing a cached resource.
PTR_UPLOADED_ORIGINAL, /// Success. Prepared and cached using an original-game resource.
PTR_UPLOADED_EXTERNAL, /// Success. Prepared and cached using an external-replacement resource.
} preparetextureresult_t;
/**
* Attempt to prepare a variant of Texture which fulfills the specification
* defined by the usage context. If a suitable variant cannot be found a new
* one will be constructed and prepared.
*
* \note If a cache miss occurs texture content data may need to be uploaded
* to GL to satisfy the variant specification. However the actual upload will
* be deferred if possible. This has the side effect that although the variant
* is considered "prepared", attempting to render using the associated texture
* will result in "uninitialized" white texels being used instead.
*
* @param tex Texture from which a prepared variant is desired.
* @param spec Variant specification for the proposed usage context.
* @param returnOutcome If not @c NULL detailed result information for this
* process is written back here.
*
* @return Prepared variant if successful else @c NULL.
*/
const struct texturevariant_s* GL_PrepareTexture2(struct texture_s* tex,
texturevariantspecification_t* spec, preparetextureresult_t* returnOutcome);
const struct texturevariant_s* GL_PrepareTexture(struct texture_s* tex,
texturevariantspecification_t* spec);
const struct texture_s* GL_CreateTexture(const char* name, uint index, texturenamespaceid_t texNamespace);
const struct texture_s* GL_TextureByUri2(const dduri_t* uri, boolean silent);
const struct texture_s* GL_TextureByUri(const dduri_t* uri);
const struct texture_s* GL_TextureByIndex(int index, texturenamespaceid_t texNamespace);
uint GL_TextureIndexForUri2(const dduri_t* uri, boolean silent);
uint GL_TextureIndexForUri(const dduri_t* uri);
/**
* Change the GL minification filter for all prepared TextureVariants.
*/
void GL_SetAllTexturesMinFilter(int minFilter);
/**
* Releases all GL texture objects for all prepared TextureVariants.
*/
void GL_ReleaseGLTexturesByNamespace(texturenamespaceid_t texNamespace);
#endif /* LIBDENG_TEXTURE_MANAGER_H */