Libprimis
Imprimis' 3D destroyable world engine
Toggle main menu visibility
Loading...
Searching...
No Matches
slot.h
Go to the documentation of this file.
1
15
16
#ifndef SLOT_H_
17
#define SLOT_H_
18
28
enum
29
{
30
VSlot_ShParam = 0,
31
VSlot_Scale,
32
VSlot_Rotation,
33
VSlot_Offset,
34
VSlot_Scroll,
35
VSlot_Layer,
36
VSlot_Alpha,
37
VSlot_Color,
38
VSlot_Reserved,
// used by RE
39
VSlot_Refract,
40
VSlot_Detail,
41
VSlot_Angle,
42
VSlot_Num
43
};
44
45
struct
SlotShaderParam
46
{
47
enum
48
{
49
REUSE = 1<<0
50
};
51
52
const
char
*name;
53
size_t
loc;
54
int
flags;
55
float
val[4];
56
};
57
58
struct
Texture;
59
class
Shader;
60
struct
VSlot
;
//both slot and vslot depend on each other
61
70
struct
Slot
71
{
72
enum
73
{
74
SlotType_Octa,
75
SlotType_Material,
76
SlotType_Decal
77
};
78
79
struct
Tex
80
{
81
int
type;
82
Texture *t;
83
string
name;
84
int
combined;
85
86
Tex() : t(
nullptr
), combined(-1) {}
87
};
88
89
int
index, smooth;
90
std::vector<Tex> sts;
91
Shader *shader;
92
std::vector<SlotShaderParam> params;
93
VSlot
*variants;
94
bool
loaded;
95
uint texmask;
96
char
*grass;
97
Texture *grasstex, *thumbnail;
98
99
Slot(
int
newindex = -1) : index(newindex), variants(nullptr), grass(nullptr) { reset(); }
100
virtual
~Slot
() {}
101
102
virtual
int
type()
const
103
{
104
return
SlotType_Octa;
105
}
106
107
virtual
const
char
*name()
const
;
108
virtual
const
char
*texturedir()
const
109
{
110
return
"media/texture"
;
111
}
112
113
virtual
VSlot &emptyvslot();
114
115
virtual
int
cancombine(
int
type)
const
;
116
virtual
bool
shouldpremul(
int
)
const
117
{
118
return
false
;
119
}
120
132
int
findtextype
(
int
type,
int
last = -1)
const
;
133
134
void
load(
int
index,
Slot::Tex
&t);
135
void
load();
136
145
Texture *
loadthumbnail
();
146
147
void
reset()
148
{
149
smooth = -1;
150
sts.clear();
151
shader =
nullptr
;
152
params.clear();
153
loaded =
false
;
154
texmask = 0;
155
delete
[] grass;
156
grass =
nullptr
;
157
grasstex =
nullptr
;
158
thumbnail =
nullptr
;
159
}
160
161
void
cleanup()
162
{
163
loaded =
false
;
164
grasstex =
nullptr
;
165
thumbnail =
nullptr
;
166
for
(uint i = 0; i < sts.size(); i++)
167
{
168
Tex &t = sts[i];
169
t.t =
nullptr
;
170
t.combined = -1;
171
}
172
}
173
};
174
187
struct
VSlot
188
{
189
Slot
*slot;
190
VSlot *next;
191
int
index;
192
int
changed;
193
std::vector<SlotShaderParam>
params
;
194
bool
linked;
195
float
scale;
196
int
rotation;
197
vec
angle;
198
ivec2
offset;
199
vec2
scroll;
200
int
layer;
201
float
alphafront, alphaback;
202
vec
colorscale;
203
vec
glowcolor;
204
float
refractscale;
205
vec
refractcolor;
206
207
VSlot(
Slot
*newslot =
nullptr
,
int
newindex = -1) : slot(newslot), next(nullptr), index(newindex), changed(0)
208
{
209
reset();
210
if
(slot)
211
{
212
addvariant(slot);
213
}
214
}
215
216
void
addvariant(
Slot
*slot);
217
218
void
reset()
219
{
220
params
.clear();
221
linked =
false
;
222
scale = 1;
223
rotation = 0;
224
angle =
vec
(0, sinf(0), cosf(0));
225
offset =
ivec2
(0, 0);
226
scroll =
vec2
(0, 0);
227
layer = 0;
228
alphafront = 0.5f;
229
alphaback = 0;
230
colorscale =
vec
(1, 1, 1);
231
glowcolor =
vec
(1, 1, 1);
232
refractscale = 0;
233
refractcolor =
vec
(1, 1, 1);
234
}
235
236
void
cleanup()
237
{
238
linked =
false
;
239
}
240
241
bool
isdynamic()
const
;
242
};
243
247
struct
DecalSlot final : Slot, VSlot
248
{
249
float
depth, fade;
250
251
DecalSlot(
int
index = -1) : Slot(index), VSlot(
this
), depth(1), fade(0.5f) {}
252
253
int
type()
const
override
final
254
{
255
return
SlotType_Decal;
256
}
257
258
const
char
*name()
const
override
final
;
259
const
char
*texturedir()
const
override
final
260
{
261
return
"media/decal"
;
262
}
263
264
VSlot &emptyvslot()
override
final
265
{
266
return
*
this
;
267
}
268
269
int
cancombine(
int
type)
const
override
final
;
270
bool
shouldpremul(
int
type)
const
override
final
;
271
272
void
reset()
273
{
274
Slot::reset();
275
VSlot::reset();
276
depth = 1;
277
fade = 0.5f;
278
}
279
280
void
cleanup()
281
{
282
Slot::cleanup();
283
VSlot::cleanup();
284
}
285
};
286
287
extern
std::vector<Slot *> slots;
288
extern
std::vector<VSlot *> vslots;
289
extern
std::vector<int *> editingvslots;
290
291
extern
const
char
*getshaderparamname(
const
char
*name,
bool
insert =
true
);
292
extern
void
setldrnotexture();
293
294
extern
VSlot
*findvslot(
const
Slot
&slot,
const
VSlot
&src,
const
VSlot
&delta);
295
extern
VSlot
*editvslot(
const
VSlot
&src,
const
VSlot
&delta);
296
extern
Slot
&lookupslot(
int
slot,
bool
load =
true
);
297
extern
VSlot
&lookupvslot(
int
slot,
bool
load =
true
);
298
extern
bool
unpackvslot(ucharbuf &buf,
VSlot
&dst,
bool
delta);
299
extern
DecalSlot
&lookupdecalslot(
int
slot,
bool
load =
true
);
300
301
#endif
/* SLOT_H_ */
DecalSlot
Definition
slot.h:248
SlotShaderParam
Definition
slot.h:46
Slot::Tex
Definition
slot.h:80
Slot
A representation of a texture inside the engine.
Definition
slot.h:71
Slot::loadthumbnail
Texture * loadthumbnail()
Returns a new texture that is a thumbnail of the slot's texture.
Slot::findtextype
int findtextype(int type, int last=-1) const
Attempts to find a tex with index type.
VSlot
A virtual texture slot.
Definition
slot.h:188
VSlot::params
std::vector< SlotShaderParam > params
bitmask containing zero or more bits defined above in the VSlot enum values.
Definition
slot.h:193
ivec2
integer vector2
Definition
geom.h:2646
vec2
two dimensional Cartesian vector object
Definition
geom.h:34
vec
three dimensional Cartesian vector object
Definition
geom.h:207
src
libprimis-headers
slot.h
Generated by
1.17.0