/
materialvariant.h
188 lines (147 loc) · 6.23 KB
/
materialvariant.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
/**\file materialvariant.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 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
*/
#ifndef LIBDENG_MATERIALVARIANT_H
#define LIBDENG_MATERIALVARIANT_H
#include "r_data.h"
struct texturevariant_s;
struct texturevariantspecification_s;
typedef struct materialvariantspecification_s {
materialcontext_t context;
struct texturevariantspecification_s* primarySpec;
} materialvariantspecification_t;
#define MATERIALVARIANT_MAXLAYERS DDMAX_MATERIAL_LAYERS
// Material texture unit idents:
enum {
MTU_PRIMARY,
MTU_DETAIL,
MTU_REFLECTION,
MTU_REFLECTION_MASK,
NUM_MATERIAL_TEXTURE_UNITS
};
typedef struct materialsnapshot_s {
/// @c true= this material is entirely opaque.
boolean isOpaque;
/// Dimensions in logical world units.
int width, height;
/// Glow strength multiplier.
float glowing;
/// Average colors (for lighting).
vec3_t color;
vec3_t colorAmplified;
/// Average top line color (for sky fadeout).
vec3_t topColor;
/// Minimum sector light color for shiny texturing.
vec3_t shinyMinColor;
/// Textures used on each texture unit.
const struct texturevariant_s* textures[NUM_MATERIAL_TEXTURE_UNITS];
/// Texture unit configuration.
rtexmapunit_t units[NUM_MATERIAL_TEXTURE_UNITS];
} materialsnapshot_t;
// Helper macros for accessing MaterialSnapshot data elements.
#define MST(ms, u) ((ms)->textures[u])
#define MSU(ms, u) ((ms)->units[u])
#define MSU_texture(ms, u) (MST(ms, u)? TextureVariant_GeneralCase(MST(ms, u)) : NULL)
#define MSU_gltexture(ms, u) (MST(ms, u)? TextureVariant_GLName(MST(ms, u)) : 0)
#define MSU_texturespec(ms, u) (MST(ms, u)? TextureVariant_Spec(MST(ms, u)) : NULL)
typedef struct materialvariant_layer_s {
int stage; // -1 => layer not in use.
struct texture_s* texture;
float texOrigin[2]; /// Origin of the texture in material-space.
float glow;
short tics;
} materialvariant_layer_t;
typedef struct materialvariant_s {
materialvariant_layer_t _layers[MATERIALVARIANT_MAXLAYERS];
/// Superior Material of which this is a derivative.
struct material_s* _generalCase;
/// For "smoothed" Material animation:
struct materialvariant_s* _current;
struct materialvariant_s* _next;
float _inter;
/// Specification used to derive this variant.
const materialvariantspecification_t* _spec;
/// Cached copy of current state if any.
materialsnapshot_t* _snapshot;
/// Frame count when MaterialVariant::_snapshot was last prepared/updated.
int _snapshotPrepareFrame;
} materialvariant_t;
materialvariant_t* MaterialVariant_New(struct material_s* generalCase,
const materialvariantspecification_t* spec);
void MaterialVariant_Delete(materialvariant_t* mat);
/**
* Process a system tick event.
* @param ticLength Length of the tick in seconds.
*/
void MaterialVariant_Ticker(materialvariant_t* mat, timespan_t time);
/**
* Reset the staged animation point for this Material.
*/
void MaterialVariant_ResetAnim(materialvariant_t* mat);
/// @return Material from which this variant is derived.
struct material_s* MaterialVariant_GeneralCase(materialvariant_t* mat);
/// @return MaterialVariantSpecification from which this variant is derived.
const materialvariantspecification_t* MaterialVariant_Spec(const materialvariant_t* mat);
/**
* Retrieve a handle for a staged animation layer form this variant.
* @param layer Index of the layer to retrieve.
* @return MaterialVariantLayer for the specified layer index.
*/
const materialvariant_layer_t* MaterialVariant_Layer(materialvariant_t* mat, int layer);
/**
* Attach MaterialSnapshot data to this. MaterialVariant is given ownership of @a materialSnapshot.
* @return Same as @a materialSnapshot for caller convenience.
*/
materialsnapshot_t* MaterialVariant_AttachSnapshot(materialvariant_t* mat, materialsnapshot_t* materialSnapshot);
/**
* Detach MaterialSnapshot data from this. Ownership of the data is relinquished to the caller.
*/
materialsnapshot_t* MaterialVariant_DetachSnapshot(materialvariant_t* mat);
/// @return MaterialSnapshot data associated with this.
materialsnapshot_t* MaterialVariant_Snapshot(const materialvariant_t* mat);
/// @return Frame count when the snapshot was last prepared/updated.
int MaterialVariant_SnapshotPrepareFrame(const materialvariant_t* mat);
/**
* Change the frame when the snapshot was last prepared/updated.
* @param frame Frame to mark the snapshot with.
*/
void MaterialVariant_SetSnapshotPrepareFrame(materialvariant_t* mat, int frame);
/// @return Translated 'next' (or target) MaterialVariant if set, else this.
materialvariant_t* MaterialVariant_TranslationNext(materialvariant_t* mat);
/// @return Translated 'current' MaterialVariant if set, else this.
materialvariant_t* MaterialVariant_TranslationCurrent(materialvariant_t* mat);
/// @return Translation position [0...1]
float MaterialVariant_TranslationPoint(materialvariant_t* mat);
/**
* Change the translation target for this variant.
*
* @param current Translated 'current' MaterialVariant.
* @param next Translated 'next' (or target) MaterialVariant.
*/
void MaterialVariant_SetTranslation(materialvariant_t* mat,
materialvariant_t* current, materialvariant_t* next);
/**
* Change the translation point for this variant.
* @param inter Translation point.
*/
void MaterialVariant_SetTranslationPoint(materialvariant_t* mat, float inter);
#endif /* LIBDENG_MATERIALVARIANT_H */