-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
materials.h
276 lines (230 loc) · 11.4 KB
/
materials.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
/**
* @file materials.h
* Materials collection, schemes, bindings and other management. @ingroup resource
*
* @authors Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2012 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_MATERIALS_H
#define LIBDENG_RESOURCE_MATERIALS_H
#include "def_data.h"
#include "material.h"
#ifdef __cplusplus
extern "C" {
#endif
struct texturevariantspecification_s;
struct materialvariant_s;
struct materialsnapshot_s;
enum materialschemeid_e; // Defined in dd_share.h
/// Material (Usage) Context identifiers.
typedef enum {
MC_UNKNOWN = -1,
MATERIALCONTEXT_FIRST = 0,
MC_UI = MATERIALCONTEXT_FIRST,
MC_MAPSURFACE,
MC_SPRITE,
MC_MODELSKIN,
MC_PSPRITE,
MC_SKYSPHERE,
MATERIALCONTEXT_LAST = MC_SKYSPHERE
} materialcontext_t;
#define MATERIALCONTEXT_COUNT (MATERIALCONTEXT_LAST + 1 - MATERIALCONTEXT_FIRST )
/// @c true= val can be interpreted as a valid material context identifier.
#define VALID_MATERIALCONTEXT(val) ((val) >= MATERIALCONTEXT_FIRST && (val) <= MATERIALCONTEXT_LAST)
/// To be called during init to register the cvars and ccmds for this module.
void Materials_Register(void);
/// Initialize this module.
void Materials_Init(void);
/// Shutdown this module.
void Materials_Shutdown(void);
/**
* Process a tic of length @a elapsed, animating materials and anim-groups.
* @param elapsed Length of tic to be processed.
*/
void Materials_Ticker(timespan_t elapsed);
/// Process all outstanding tasks in the Material cache queue.
void Materials_ProcessCacheQueue(void);
/// Empty the Material cache queue, cancelling all outstanding tasks.
void Materials_PurgeCacheQueue(void);
/// To be called during a definition database reset to clear all links to defs.
void Materials_ClearDefinitionLinks(void);
/**
* Try to interpret a known material scheme identifier from @a str. If found to match
* a known scheme name, return the associated identifier. If the reference @a str is
* not valid (i.e., equal to NULL or is a zero-length string) then the special identifier
* @c MS_ANY is returned. Otherwise @c MS_INVALID.
*/
enum materialschemeid_e Materials_ParseSchemeName(const char* str);
/// @return Name associated with the identified @a schemeId else a zero-length string.
const Str* Materials_SchemeName(enum materialschemeid_e schemeId);
/// @return Total number of unique Materials in the collection.
uint Materials_Size(void);
/// @return Number of unique Materials in the identified @a schemeId.
uint Materials_Count(enum materialschemeid_e schemeId);
/// @return Unique identifier associated with @a material else @c 0.
materialid_t Materials_Id(material_t* material);
/// @return Material associated with unique identifier @a materialId else @c NULL.
material_t* Materials_ToMaterial(materialid_t materialId);
/// @return Unique identifier of the scheme this material is in.
enum materialschemeid_e Materials_Scheme(materialid_t materialId);
/// @return Symbolic name/path-to this material. Must be destroyed with Str_Delete().
AutoStr* Materials_ComposePath(materialid_t materialId);
/// @return Unique name/path-to this material. Must be destroyed with Uri_Delete().
Uri* Materials_ComposeUri(materialid_t materialId);
void Materials_UpdateTextureLinks(materialid_t materialId);
/**
* Update @a material according to the supplied definition @a def.
* To be called after an engine update/reset.
*
* @param material Material to be updated.
* @param def Material definition to update using.
*/
void Materials_Rebuild(material_t* material, ded_material_t* def);
/// @return @c true if one or more light decorations are defined for this material.
boolean Materials_HasDecorations(material_t* material);
/// @return Decoration defintion associated with @a material else @c NULL.
const ded_decor_t* Materials_DecorationDef(material_t* material);
/// @return (Particle) Generator definition associated with @a material else @c NULL.
const ded_ptcgen_t* Materials_PtcGenDef(material_t* material);
/// @return @c true iff @a material is linked to the identified @a animGroupNum.
boolean Materials_IsMaterialInAnimGroup(material_t* material, int animGroupNum);
/**
* Search the Materials collection for a material associated with @a uri.
* @return Found material else @c NOMATERIALID.
*/
materialid_t Materials_ResolveUri2(const Uri* uri, boolean quiet);
materialid_t Materials_ResolveUri(const Uri* uri); /*quiet=!(verbose >= 1)*/
/// Same as Materials::ResolveUri except @a uri is a C-string.
materialid_t Materials_ResolveUriCString2(const char* uri, boolean quiet);
materialid_t Materials_ResolveUriCString(const char* uri); /*quiet=!(verbose >= 1)*/
/**
* Create a new Material unless an existing Material is found at the path
* (and within the same scheme) as that specified in @a def, in which case
* it is returned instead.
*
* @note: May fail on invalid definitions (return= @c NULL).
*
* @param def Material definition to construct from.
* @return The newly-created/existing Material else @c NULL.
*/
material_t* Materials_CreateFromDef(ded_material_t* def);
/// @return Number of animation/precache groups in the collection.
int Materials_AnimGroupCount(void);
/// To be called to reset all animation groups back to their initial state.
void Materials_ResetAnimGroups(void);
/// To be called to destroy all animation groups when they are no longer needed.
void Materials_ClearAnimGroups(void);
/**
* Prepare a MaterialVariantSpecification according to a usage context. If
* incomplete context information is supplied, suitable default values will
* be chosen in their place.
*
* @param materialContext Material (usage) context identifier.
* @param flags @ref textureVariantSpecificationFlags
* @param border Border size in pixels (all edges).
* @param tClass Color palette translation class.
* @param tMap Color palette translation map.
* @param wrapS GL texture wrap/clamp mode on the horizontal axis (texture-space).
* @param wrapT GL texture wrap/clamp mode on the vertical axis (texture-space).
* @param minFilter Logical DGL texture minification level.
* @param magFilter Logical DGL texture magnification level.
* @param anisoFilter @c -1= User preference else a logical DGL anisotropic filter level.
* @param mipmapped @c true= use mipmapping.
* @param gammaCorrection @c true= apply gamma correction to textures.
* @param noStretch @c true= disallow stretching of textures.
* @param toAlpha @c true= convert textures to alpha data.
*
* @return Rationalized (and interned) copy of the final specification.
*/
const struct materialvariantspecification_s* Materials_VariantSpecificationForContext(
materialcontext_t materialContext, int flags, byte border, int tClass,
int tMap, int wrapS, int wrapT, int minFilter, int magFilter, int anisoFilter,
boolean mipmapped, boolean gammaCorrection, boolean noStretch, boolean toAlpha);
/**
* Add a variant of @a material to the cache queue for deferred preparation.
*
* @param material Base Material from which to derive a variant.
* @param spec Specification for the desired derivation of @a material.
* @param smooth @c true= Select the current frame if the material is group-animated.
* @param cacheGroups @c true= variants for all Materials in any applicable
* animation groups are desired, else just this specific Material.
*/
void Materials_Precache2(material_t* material, const struct materialvariantspecification_s* spec, boolean smooth, boolean cacheGroups);
void Materials_Precache(material_t* material, const struct materialvariantspecification_s* spec, boolean smooth); /*cacheGroups=true*/
/**
* Choose/create a variant of @a material which fulfills @a spec and then
* immediately prepare it for render (e.g., upload textures if necessary).
*
* @note A convenient shorthand of the call tree:
* <pre>
* Materials_PrepareVariant( Materials_ChooseVariant( @a material, @a spec, @a smooth, @c true ), @a forceSnapshotUpdate )
* </pre>
*
* @param material Base Material from which to derive a variant.
* @param spec Specification for the derivation of @a material.
* @param smooth @c true= Select the current frame if the material is group-animated.
* @param forceSnapshotUpdate @c true= Force an update of the variant's state snapshot.
*
* @return Snapshot for the chosen and prepared variant of Material.
*/
const struct materialsnapshot_s* Materials_Prepare2(material_t* material, const struct materialvariantspecification_s* spec, boolean smooth, boolean forceSnapshotUpdate);
const struct materialsnapshot_s* Materials_Prepare(material_t* material, const struct materialvariantspecification_s* spec, boolean smooth); /*forceSnapshotUpdate=false*/
/**
* Prepare variant @a material for render (e.g., upload textures if necessary).
*
* @note Same as Materials::Prepare except the caller specifies the variant.
* @see Materials::ChooseVariant
*
* @param material MaterialVariant to be prepared.
* @param forceSnapshotUpdate @c true= Force an update of the variant's state snapshot.
*
* @return Snapshot for the chosen and prepared variant of Material.
*/
const struct materialsnapshot_s* Materials_PrepareVariant2(struct materialvariant_s* material, boolean forceSnapshotUpdate);
const struct materialsnapshot_s* Materials_PrepareVariant(struct materialvariant_s* material); /*forceSnapshotUpdate=false*/
/**
* Choose/create a variant of @a material which fulfills @a spec.
*
* @param material Material to derive the variant from.
* @param spec Specification for the derivation of @a material.
* @param smooth @c true= Select the current frame if the material is group-animated.
* @param canCreate @c true= Create a new variant if a suitable one does exist.
*
* @return Chosen variant else @c NULL if none suitable and not creating.
*/
struct materialvariant_s* Materials_ChooseVariant(material_t* material,
const struct materialvariantspecification_s* spec, boolean smoothed, boolean canCreate);
/**
* Create a new animation group.
* @return Logical (unique) identifier reference associated with the new group.
*/
int Materials_CreateAnimGroup(int flags);
/**
* Append a new @a material frame to the identified @a animGroupNum.
*
* @param animGroupNum Logical identifier reference to the group being modified.
* @param material Material frame to be inserted into the group.
* @param tics Base duration of the new frame in tics.
* @param randomTics Extra frame duration in tics (randomized on each cycle).
*/
void Materials_AddAnimGroupFrame(int animGroupNum, material_t* material, int tics, int randomTics);
/// @todo Refactor; does not fit the current design.
boolean Materials_IsPrecacheAnimGroup(int animGroupNum);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* LIBDENG_RESOURCE_MATERIALS_H */