/
material.h
1018 lines (855 loc) · 31 KB
/
material.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file material.h Logical material resource.
*
* @authors Copyright © 2009-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @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 DENG_RESOURCE_MATERIAL_H
#define DENG_RESOURCE_MATERIAL_H
#include "MapElement"
#include "def_data.h"
#include "audio/s_environ.h"
#include "world/dmuargs.h"
#ifdef __CLIENT__
# include "MaterialContext"
#endif
#include "Texture"
#include "uri.hh"
#include <de/Error>
#include <de/Observers>
#include <de/Vector>
#include <QFlag>
#include <QList>
#include <QMap>
// Forward declarations:
namespace de {
class MaterialManifest;
#ifdef __CLIENT__
class MaterialSnapshot;
struct MaterialVariantSpec;
#endif
}
/**
* Logical material resource.
*
* @ingroup resource
*/
class Material : public de::MapElement
{
public:
/// Maximum number of layers a material supports.
static int const max_layers = 1;
#ifdef __CLIENT__
/// Maximum number of (light) decorations a material supports.
static int const max_decorations = 16;
#endif
/// Required animation is missing. @ingroup errors
DENG2_ERROR(MissingAnimationError);
/// The referenced layer does not exist. @ingroup errors
DENG2_ERROR(UnknownLayerError);
#ifdef __CLIENT__
/// The referenced decoration does not exist. @ingroup errors
DENG2_ERROR(UnknownDecorationError);
#endif
/**
* Notified when the material is about to be deleted.
*/
DENG2_DEFINE_AUDIENCE(Deletion, void materialBeingDeleted(Material const &material))
/**
* Notified when the logical dimensions change.
*/
DENG2_DEFINE_AUDIENCE(DimensionsChange, void materialDimensionsChanged(Material &material))
/// @todo Define these values here instead of at API level
enum Flag
{
//Unused1 = MATF_UNUSED1,
/// Map surfaces using the material should never be drawn.
NoDraw = MATF_NO_DRAW,
/// Apply sky masking for map surfaces using the material.
SkyMask = MATF_SKYMASK
};
Q_DECLARE_FLAGS(Flags, Flag)
/**
* Each material consitutes at least one layer. Layers are arranged in a
* stack according to the order in which they should be drawn, from the
* bottom-most to the top-most layer.
*/
class Layer
{
public:
struct Stage
{
de::Texture *texture;
int tics;
float variance; // Stage variance (time).
float glowStrength;
float glowStrengthVariance;
de::Vector2f texOrigin;
Stage(de::Texture *_texture, int _tics,
float _variance = 0,
float _glowStrength = 0,
float _glowStrengthVariance = 0,
de::Vector2f const _texOrigin = de::Vector2f())
: texture(_texture), tics(_tics), variance(_variance),
glowStrength(_glowStrength),
glowStrengthVariance(_glowStrengthVariance),
texOrigin(_texOrigin)
{}
Stage(Stage const &other)
: texture(other.texture),
tics(other.tics),
variance(other.variance),
glowStrength(other.glowStrength),
glowStrengthVariance(other.glowStrengthVariance),
texOrigin(other.texOrigin)
{}
static Stage *fromDef(ded_material_layer_stage_t const &def);
};
/// A list of stages.
typedef QList<Stage *> Stages;
public:
/**
* Construct a new default layer.
*/
Layer();
~Layer();
/**
* Construct a new layer from the specified definition.
*/
static Layer *fromDef(ded_material_layer_t const &def);
/// @return @c true if the layer is animated; otherwise @c false.
inline bool isAnimated() const { return stageCount() > 1; }
/**
* Returns the total number of animation stages for the layer.
*/
int stageCount() const;
/**
* Add a new animation stage to the layer.
*
* @param stage New stage to add (a copy is made).
* @return Index of the newly added stage (0-based).
*/
int addStage(Stage const &stage);
/**
* Provides access to the animation stages for efficient traversal.
*/
Stages const &stages() const;
private:
/// Animation stages.
Stages _stages;
};
/// A list of layers.
typedef QList<Material::Layer *> Layers;
/// @todo $revise-texture-animation Merge with Material::Layer
class DetailLayer
{
public:
struct Stage
{
de::Texture *texture; // The file/lump with the detail texture.
int tics;
float variance;
float scale;
float strength;
float maxDistance;
Stage(de::Texture *_texture, int _tics,
float _variance = 0,
float _scale = 1,
float _strength = 1,
float _maxDistance = 0)
: texture(_texture), tics(_tics), variance(_variance),
scale(_scale), strength(_strength), maxDistance(_maxDistance)
{}
Stage(Stage const &other)
: texture(other.texture),
tics(other.tics),
variance(other.variance),
scale(other.scale),
strength(other.strength),
maxDistance(other.maxDistance)
{}
static Stage *fromDef(ded_detail_stage_t const &def);
};
/// A list of stages.
typedef QList<Stage *> Stages;
public:
/**
* Construct a new default layer.
*/
DetailLayer();
~DetailLayer();
/**
* Construct a new layer from the specified definition.
*/
static DetailLayer *fromDef(ded_detailtexture_t const &def);
/// @return @c true if the layer is animated; otherwise @c false.
inline bool isAnimated() const { return stageCount() > 1; }
/**
* Returns the total number of animation stages for the layer.
*/
int stageCount() const;
/**
* Add a new animation stage to the layer.
*
* @param stage New stage to add (a copy is made).
* @return Index of the newly added stage (0-based).
*/
int addStage(Stage const &stage);
/**
* Provides access to the animation stages for efficient traversal.
*/
Stages const &stages() const;
private:
/// Animation stages.
Stages _stages;
};
/// @todo $revise-texture-animation Merge with Material::Layer
class ShineLayer
{
public:
struct Stage
{
de::Texture *texture;
int tics;
float variance;
de::Texture *maskTexture;
blendmode_t blendMode; // Blend mode flags (bm_*).
float shininess;
de::Vector3f minColor;
de::Vector2f maskDimensions;
Stage(de::Texture *_texture, int _tics, float _variance,
de::Texture *_maskTexture = 0,
blendmode_t _blendMode = BM_ADD,
float _shininess = 1,
de::Vector3f const &_minColor = de::Vector3f(0, 0, 0),
de::Vector2f const &_maskDimensions = de::Vector2f(1, 1))
: texture(_texture), tics(_tics), variance(_variance),
maskTexture(_maskTexture), blendMode(_blendMode),
shininess(_shininess), minColor(_minColor),
maskDimensions(_maskDimensions)
{}
Stage(Stage const &other)
: texture(other.texture),
tics(other.tics),
variance(other.variance),
maskTexture(other.maskTexture),
blendMode(other.blendMode),
shininess(other.shininess),
minColor(other.minColor),
maskDimensions(other.maskDimensions)
{}
static Stage *fromDef(ded_shine_stage_t const &def);
};
/// A list of stages.
typedef QList<Stage *> Stages;
public:
/**
* Construct a new default layer.
*/
ShineLayer();
~ShineLayer();
/**
* Construct a new layer from the specified definition.
*/
static ShineLayer *fromDef(ded_reflection_t const &def);
/// @return @c true if the layer is animated; otherwise @c false.
inline bool isAnimated() const { return stageCount() > 1; }
/**
* Returns the total number of animation stages for the layer.
*/
int stageCount() const;
/**
* Add a new animation stage to the layer.
*
* @param stage New stage to add (a copy is made).
* @return Index of the newly added stage (0-based).
*/
int addStage(Stage const &stage);
/**
* Provides access to the animation stages for efficient traversal.
*/
Stages const &stages() const;
private:
/// Animation stages.
Stages _stages;
};
#ifdef __CLIENT__
#undef min
#undef max
/**
* (Light) decoration.
*/
class Decoration
{
public:
struct Stage
{
struct LightLevels
{
float min;
float max;
LightLevels(float _min = 0, float _max = 0)
: min(_min), max(_max)
{}
LightLevels(float const minMax[2])
: min(minMax[0]), max(minMax[1])
{}
LightLevels(LightLevels const &other)
: min(other.min), max(other.max)
{}
/// Returns a textual representation of the lightlevels.
de::String asText() const;
};
int tics;
float variance; // Stage variance (time).
de::Vector2f pos; // Coordinates on the surface.
float elevation; // Distance from the surface.
de::Vector3f color; // Light color.
float radius; // Dynamic light radius (-1 = no light).
float haloRadius; // Halo radius (zero = no halo).
LightLevels lightLevels; // Fade by sector lightlevel.
de::Texture *up, *down, *sides;
de::Texture *flare;
int sysFlareIdx; /// @todo Remove me
Stage(int _tics, float _variance, de::Vector2f const &_pos, float _elevation,
de::Vector3f const &_color, float _radius, float _haloRadius,
LightLevels const &_lightLevels,
de::Texture *upTexture, de::Texture *downTexture, de::Texture *sidesTexture,
de::Texture *flareTexture,
int _sysFlareIdx = -1 /** @todo Remove me */)
: tics(_tics), variance(_variance), pos(_pos), elevation(_elevation), color(_color),
radius(_radius), haloRadius(_haloRadius), lightLevels(_lightLevels),
up(upTexture), down(downTexture), sides(sidesTexture), flare(flareTexture),
sysFlareIdx(_sysFlareIdx)
{}
static Stage *fromDef(ded_decorlight_stage_t const &def);
};
/// A list of stages.
typedef QList<Stage *> Stages;
public:
/**
* Construct a new default decoration.
*/
Decoration(de::Vector2i const &_patternSkip = de::Vector2i(),
de::Vector2i const &_patternOffset = de::Vector2i());
~Decoration();
/**
* Construct a new decoration from the specified definition.
*/
static Decoration *fromDef(ded_material_decoration_t const &def);
/**
* Construct a new decoration from the specified definition.
*/
static Decoration *fromDef(ded_decoration_t const &def);
/**
* Returns the attributed owner material for the decoration.
*/
Material &material();
/// @copydoc material()
Material const &material() const;
/**
* Change the attributed 'owner' material for the decoration. Usually
* it is unnecessary to call this manually as adding the decoration to
* a material will setup the attribution automatically.
*
* @param newOwner New material to attribute as 'owner'. Use @c 0 to
* clear the attribution.
*/
void setMaterial(Material *newOwner);
/// @return @c true if the decoration is animated; otherwise @c false.
inline bool isAnimated() const { return stageCount() > 1; }
/**
* Retrieve the pattern skip for the decoration. Normally a decoration
* is repeated on a surface as many times as the material does. A skip
* pattern allows sparser repeats on the horizontal and vertical axes
* respectively.
*
* @see patternOffset()
*/
de::Vector2i const &patternSkip() const;
/**
* Retrieve the pattern offset for the decoration. Used with pattern
* skip to offset the origin of the pattern.
*
* @see patternSkip()
*/
de::Vector2i const &patternOffset() const;
/**
* Returns the total number of animation stages for the decoration.
*/
int stageCount() const;
/**
* Provides access to the animation stages for efficient traversal.
*/
Stages const &stages() const;
private:
Material *_material; ///< Owning Material.
de::Vector2i _patternSkip; ///< Pattern skip intervals.
de::Vector2i _patternOffset; ///< Pattern skip interval offsets.
Stages _stages; ///< Animation stages.
};
/// A list of decorations.
typedef QList<Decoration *> Decorations;
/**
* Animation (state).
*/
class Animation
{
Animation(Material &material, MaterialContextId context);
public:
/**
* Notified when a decoration stage change occurs.
*/
DENG2_DEFINE_AUDIENCE(DecorationStageChange,
void materialAnimationDecorationStageChanged(Animation &anim, Decoration &decor))
/// Current state of a layer animation.
struct LayerState
{
/// Animation stage else @c -1 => layer not in use.
int stage;
/// Remaining (sharp) tics in the current stage.
short tics;
/// Intermark from the current stage to the next [0..1].
float inter;
};
/// Current state of a (light) decoration animation.
struct DecorationState
{
/// Animation stage else @c -1 => decoration not in use.
int stage;
/// Remaining (sharp) tics in the current stage.
short tics;
/// Intermark from the current stage to the next [0..1].
float inter;
};
/**
* Returns the logical usage context identifier for the animation.
*/
MaterialContextId context() const;
/**
* Process a system tick event. If not currently paused and still valid;
* the material's layers and decorations are animated.
*
* @param ticLength Length of the tick in seconds.
*
* @see isPaused()
*/
void animate(timespan_t ticLength);
/**
* Returns @c true if animation is currently paused (e.g., this state
* is for use with a context driven by the game timer (and the client
* has paused the game)).
*/
bool isPaused() const;
/**
* Restart the animation, resetting the staged animation point. The
* state of all layers and decorations will be rewound to the beginning.
*/
void restart();
/**
* Returns the current state of layer @a layerNum for the animation.
*/
LayerState const &layer(int layerNum) const;
/**
* Returns the current state of the detail layer for the animation.
*
* @see Material::isDetailed()
*/
LayerState const &detailLayer() const;
/**
* Returns the current state of the shine layer for the animation.
*
* @see Material::isShiny()
*/
LayerState const &shineLayer() const;
/**
* Returns the current state of (light) decoration @a decorNum for
* the animation.
*/
DecorationState const &decoration(int decorNum) const;
friend class Material;
private:
DENG2_PRIVATE(d)
};
/// An animation state for each usage context.
typedef QMap<MaterialContextId, Animation *> Animations;
/**
* Context-specialized variant. Encapsulates all context variant values
* and logics pertaining to a specialized version of the @em superior
* material instance.
*
* Variant instances are only created by the superior material when asked
* to @ref Material::prepare() for render using a context specialization
* specification which it cannot fulfill/match.
*
* @see MaterialVariantSpec
*/
class Variant
{
/**
* @param generalCase Material from which the variant is to be derived.
* @param spec Specification used to derive the variant.
*/
Variant(Material &generalCase, de::MaterialVariantSpec const &spec);
public:
/**
* Retrieve the general case for this variant. Allows for a variant
* reference to be used in place of a material (implicit indirection).
*
* @see generalCase()
*/
inline operator Material &() const {
return generalCase();
}
/// @return Superior material from which the variant was derived.
Material &generalCase() const;
/// @return Material variant specification for the variant.
de::MaterialVariantSpec const &spec() const;
/**
* Returns the usage context for this variant (from the spec).
*
* Same as @c spec().context
*
* @see spec()
*/
MaterialContextId context() const;
/**
* Prepare the context variant for render (if necessary, uploading
* GL textures and updating the state snapshot).
*
* @param forceSnapshotUpdate @c true= Force an update of the state
* snapshot. The snapshot is automatically updated when first
* prepared for a new render frame. Typically the only time force
* is needed is when the material variant has changed since.
*
* @return Snapshot for the variant.
*
* @see Material::chooseVariant(), Material::prepare()
*/
de::MaterialSnapshot const &prepare(bool forceSnapshotUpdate = false);
friend class Material;
private:
DENG2_PRIVATE(d)
};
/// A list of variant instances.
typedef QList<Variant *> Variants;
#endif // __CLIENT__
public:
/**
* @param manifest Manifest derived to yield the material.
*/
Material(de::MaterialManifest &manifest);
~Material();
/**
* Returns the MaterialManifest derived to yield the material.
*/
de::MaterialManifest &manifest() const;
/**
* Returns a brief textual description/overview of the material.
*
* @return Human-friendly description/overview of the material.
*/
de::String description() const;
/**
* Returns a textual synopsis of the full material configuration.
*
* @return Human-friendly synopsis of the material's configuration.
*/
de::String synopsis() const;
/**
* Returns @c true if the material is considered @em valid. A material is
* only invalidated when resources it depends on (such as the definition
* from which it was produced) are destroyed as result of runtime file
* unloading.
*
* These 'orphaned' materials cannot be immediately destroyed as the game
* may be holding on to pointers (which are considered eternal). Invalid
* materials are instead disabled and then ignored until such time as the
* current game is reset or changed.
*/
bool isValid() const;
/**
* Mark the material as invalid.
*
* @see isValid();
*/
void markValid(bool yes);
/// Returns @c true if the material has at least one animated layer.
bool isAnimated() const;
#ifdef __CLIENT__
/**
* Returns @c true if the material has one or more (light) decorations.
*
* Equivalent to:
* @code
* decorationCount() != 0;
* @endcode
*
* @see decorationCount()
*/
inline bool isDecorated() const { return decorationCount() != 0; }
#endif
/// Returns @c true if the material has a detail texturing layer.
bool isDetailed() const;
/// Returns @c true if the material is considered drawable.
bool isDrawable() const { return !isFlagged(NoDraw); }
/// Returns @c true if the material has a shine texturing layer.
bool isShiny() const;
/// Returns @c true if the material is considered @em skymasked.
inline bool isSkyMasked() const { return isFlagged(SkyMask); }
/// Returns @c true if one or more of the material's layers are glowing.
bool hasGlow() const;
#ifdef __CLIENT__
inline bool hasAnimatedLayers() const
{
foreach(Layer *layer, layers())
{
if(layer->isAnimated()) return true;
}
if(isDetailed() && detailLayer().isAnimated()) return true;
if(isShiny() && shineLayer().isAnimated()) return true;
return false;
}
inline bool hasAnimatedDecorations() const
{
foreach(Decoration *decor, decorations())
{
if(decor->isAnimated()) return true;
}
return false;
}
#endif // __CLIENT__
/**
* Returns the dimensions of the material in map coordinate space units.
*/
de::Vector2i const &dimensions() const;
/// Returns the width of the material in map coordinate space units.
inline int width() const { return dimensions().x; }
/// Returns the height of the material in map coordinate space units.
inline int height() const { return dimensions().y; }
/**
* Change the world dimensions of the material.
* @param newDimensions New dimensions in map coordinate space units.
*/
void setDimensions(de::Vector2i const &newDimensions);
/**
* Change the world width of the material.
* @param newWidth New width in map coordinate space units.
*/
void setWidth(int newWidth);
/**
* Change the world height of the material.
* @param newHeight New height in map coordinate space units.
*/
void setHeight(int newHeight);
/**
* Returns @c true if the material is flagged @a flagsToTest.
*/
inline bool isFlagged(Flags flagsToTest) const { return !!(flags() & flagsToTest); }
/**
* Returns the flags for the material.
*/
Flags flags() const;
/**
* Change the material's flags.
*
* @param flagsToChange Flags to change the value of.
* @param operation Logical operation to perform on the flags.
*/
void setFlags(Flags flagsToChange, de::FlagOp operation = de::SetFlags);
/**
* Add a new layer to the end of the material's layer stack. Ownership of the
* layer is @em not transferred to the caller.
*
* @note As this invalidates the existing logical state, any previously derived
* context variants are cleared in the process (they will be automatically
* rebuilt later if/when needed).
*
* @param def Definition for the new layer. Can be @c NULL in which case a
* default-initialized layer will be constructed.
*/
Layer *newLayer(ded_material_layer_t const *def);
/**
* Add a new detail layer to the material. Note that only one detail layer is
* supported (any existing layer will be replaced). Ownership of the layer is
* @em not transferred to the caller.
*
* @note As this invalidates the existing logical state, any previously derived
* context variants are cleared in the process (they will be automatically
* rebuilt later if/when needed).
*
* @param def Definition for the new layer. Can be @c NULL in which case a
* default-initialized layer will be constructed.
*/
DetailLayer *newDetailLayer(ded_detailtexture_t const *def);
/**
* Add a new shine layer to the material. Note that only one shine layer is
* supported (any existing layer will be replaced). Ownership of the layer is
* @em not transferred to the caller.
*
* @note As this invalidates the existing logical state, any previously derived
* context variants are cleared in the process (they will be automatically
* rebuilt later if/when needed).
*
* @param def Definition for the new layer. Can be @c NULL in which case a
* default-initialized layer will be constructed.
*/
ShineLayer *newShineLayer(ded_reflection_t const *def);
/**
* Returns the number of material layers.
*/
inline int layerCount() const { return layers().count(); }
/**
* Destroys all the material's layers.
*
* @note As this invalidates the existing logical state, any previously derived
* context variants are cleared in the process (they will be automatically
* rebuilt later if/when needed).
*/
void clearLayers();
/**
* Provides access to the list of layers for efficient traversal.
*/
Layers const &layers() const;
/**
* Provides access to the detail layer.
*
* @see isDetailed()
*/
DetailLayer const &detailLayer() const;
/**
* Provides access to the shine layer.
*
* @see isShiny()
*/
ShineLayer const &shineLayer() const;
#ifdef __CLIENT__
/**
* Returns the identifier of the audio environment for the material.
*/
AudioEnvironmentId audioEnvironment() const;
/**
* Change the audio environment for the material.
*
* @param newEnvironment New audio environment to apply.
*/
void setAudioEnvironment(AudioEnvironmentId newEnvironment);
/**
* Returns the number of material (light) decorations.
*/
int decorationCount() const { return decorations().count(); }
/**
* Destroys all the material's decorations.
*/
void clearDecorations();
/**
* Add a new (light) decoration to the material.
*
* @param decor Decoration to add.
*
* @todo Mark existing variant snapshots as 'dirty'.
*/
void addDecoration(Decoration &decor);
/**
* Provides access to the list of decorations for efficient traversal.
*/
Decorations const &decorations() const;
/**
* Retrieve the animation state for the specified render @a context.
*/
Animation &animation(MaterialContextId context) const;
/**
* Provides access to the set of usage context animation states,
* for efficient traversal.
*/
Animations const &animations() const;
/**
* Returns the number of context variants for the material.
*/
inline int variantCount() const { return variants().count(); }
/**
* Destroys all derived context variants for the material.
*/
void clearVariants();
/**
* Provides access to the list of context variants for efficient traversal.
*/
Variants const &variants() const;
/**
* Choose/create a context variant of the material which fulfills @a spec.
*
* @param spec Material specialization specification.
* @param canCreate @c true= Create a new variant if no suitable one exists.
*
* @return The chosen variant; otherwise @c 0 (if none suitable, when not creating).
*/
Variant *chooseVariant(de::MaterialVariantSpec const &spec, bool canCreate = false);
/**
* Shorthand alternative to @c chooseVariant(@a spec, true).
*
* @param spec Material specialization specification.
* @return The (perhaps newly created) variant.
*
* @see chooseVariant()
*/
inline Variant &createVariant(de::MaterialVariantSpec const &spec)
{
return *chooseVariant(spec, true/*create*/);
}
/**
* Choose/create a variant of the material which fulfills @a spec and then
* immediately prepare it for render (e.g., upload textures if necessary).
*
* Intended as a convenient shorthand of the call tree:
* @code
* chooseVariant(@a spec, true)->prepare(@a forceSnapshotUpdate)
* @endcode
*
* @param spec Specification with which to derive the variant.
* @param forceSnapshotUpdate @c true= Force an update of the variant's
* state snapshot. The snapshot is automatically updated when first
* prepared for a new render frame. Typically the only time force is
* needed is when the material variant has changed since.
*
* @return Snapshot for the chosen and prepared variant of Material.
*
* @see ResourceSystem::materialSpec(), chooseVariant(), Variant::prepare()
*/
inline de::MaterialSnapshot const &prepare(de::MaterialVariantSpec const &spec,
bool forceSnapshotUpdate = false)
{
return createVariant(spec).prepare(forceSnapshotUpdate);
}
#endif // __CLIENT__
protected:
int property(DmuArgs &args) const;
public:
/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();