/
tr_local.h
3988 lines (3119 loc) · 111 KB
/
tr_local.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
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2006-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
This file is part of Daemon source code.
Daemon source code 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.
Daemon source code 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 Daemon source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#ifndef TR_LOCAL_H
#define TR_LOCAL_H
#include "../qcommon/q_shared.h"
#include "../qcommon/qfiles.h"
#include "../qcommon/qcommon.h"
#include "tr_public.h"
#include "iqm.h"
#include <GL/glew.h>
#define BUFFER_OFFSET(i) ((char *)NULL + ( i ))
// GL conversion helpers
static inline float unorm8ToFloat(byte unorm8) {
return unorm8 * (1.0f / 255.0f);
}
static inline byte floatToUnorm8(float f) {
// don't use Q_ftol here, as the semantics of Q_ftol
// has been changed from round to nearest to round to 0 !
return lrintf(f * 255.0f);
}
static inline float snorm8ToFloat(byte snorm8) {
return MAX( (snorm8 - 128) * (1.0f / 127.0f), -1.0f);
}
static inline byte floatToSnorm8(float f) {
// don't use Q_ftol here, as the semantics of Q_ftol
// has been changed from round to nearest to round to 0 !
return lrintf(f * 127.0f) + 128;
}
// everything that is needed by the backend needs
// to be double buffered to allow it to run in
// parallel on a dual cpu machine
#define SMP_FRAMES 2
#define MAX_SHADERS ( 1 << 12 )
#define SHADERS_MASK ( MAX_SHADERS - 1 )
#define MAX_SHADER_TABLES 1024
#define MAX_SHADER_STAGES 16
#define MAX_OCCLUSION_QUERIES 4096
#define MAX_FBOS 64
#define MAX_VISCOUNTS 5
#define MAX_VIEWS 10
#define MAX_SHADOWMAPS 5
#define GLSL_COMPILE_STARTUP_ONLY 1
#define MAX_TEXTURE_MIPS 16
#define MAX_TEXTURE_LAYERS 256
// visibility tests: check if a 3D-point is visible
// results may be delayed, but for visual effect like flares this
// shouldn't matter
#define MAX_VISTESTS 256
typedef enum
{
RSPEEDS_GENERAL = 1,
RSPEEDS_CULLING,
RSPEEDS_VIEWCLUSTER,
RSPEEDS_LIGHTS,
RSPEEDS_SHADOWCUBE_CULLING,
RSPEEDS_FOG,
RSPEEDS_FLARES,
RSPEEDS_OCCLUSION_QUERIES,
RSPEEDS_SHADING_TIMES,
RSPEEDS_CHC,
RSPEEDS_NEAR_FAR,
RSPEEDS_DECALS
} renderSpeeds_t;
typedef enum
{
GLDEBUG_NONE,
GLDEBUG_ERROR,
GLDEBUG_DEPRECIATED,
GLDEBUG_UNDEFINED,
GLDEBUG_PORTABILITY,
GLDEBUG_PERFORMANCE,
GLDEBUG_OTHER,
GLDEBUG_ALL
} glDebugModes_t;
#define REF_CUBEMAP_SIZE 32
#define REF_CUBEMAP_STORE_SIZE 1024
#define REF_CUBEMAP_STORE_SIDE ( REF_CUBEMAP_STORE_SIZE / REF_CUBEMAP_SIZE )
#define REF_COLORGRADEMAP_SIZE 16
#define REF_COLORGRADEMAP_STORE_SIZE ( REF_COLORGRADEMAP_SIZE * REF_COLORGRADEMAP_SIZE * REF_COLORGRADEMAP_SIZE )
typedef enum
{
CULL_IN, // completely unclipped
CULL_CLIP, // clipped by one or more planes
CULL_OUT, // completely outside the clipping planes
} cullResult_t;
typedef struct screenRect_s
{
int coords[ 4 ];
struct screenRect_s *next;
} screenRect_t;
typedef enum
{
FRUSTUM_LEFT,
FRUSTUM_RIGHT,
FRUSTUM_BOTTOM,
FRUSTUM_TOP,
FRUSTUM_NEAR,
FRUSTUM_FAR,
FRUSTUM_PLANES = 5,
FRUSTUM_CLIPALL = 1 | 2 | 4 | 8 | 16 //| 32
} frustumBits_t;
typedef cplane_t frustum_t[ 6 ];
enum
{
CUBESIDE_PX = ( 1 << 0 ),
CUBESIDE_PY = ( 1 << 1 ),
CUBESIDE_PZ = ( 1 << 2 ),
CUBESIDE_NX = ( 1 << 3 ),
CUBESIDE_NY = ( 1 << 4 ),
CUBESIDE_NZ = ( 1 << 5 ),
CUBESIDE_CLIPALL = 1 | 2 | 4 | 8 | 16 | 32
};
typedef struct link_s
{
void *data;
int numElements; // only used by sentinels
struct link_s *prev, *next;
} link_t;
static INLINE void InitLink( link_t *l, void *data )
{
l->data = data;
l->prev = l->next = l;
}
static INLINE void ClearLink( link_t *l )
{
l->data = NULL;
l->prev = l->next = l;
}
static INLINE void RemoveLink( link_t *l )
{
l->next->prev = l->prev;
l->prev->next = l->next;
l->prev = l->next = NULL;
}
static INLINE void InsertLink( link_t *l, link_t *sentinel )
{
l->next = sentinel->next;
l->prev = sentinel;
l->next->prev = l;
l->prev->next = l;
}
static INLINE qboolean StackEmpty( link_t *l )
{
// GCC shit: cannot convert 'bool' to 'qboolean' in return
return l->next == l ? qtrue : qfalse;
}
static INLINE link_t *StackTop( link_t *l )
{
return l->next;
}
static INLINE void StackPush( link_t *sentinel, void *data )
{
link_t *l;
l = ( link_t * ) Com_Allocate( sizeof( *l ) );
InitLink( l, data );
InsertLink( l, sentinel );
}
static INLINE void *StackPop( link_t *l )
{
link_t *top;
void *data;
if ( l->next == l )
{
return NULL;
}
top = l->next;
RemoveLink( top );
data = top->data;
Com_Dealloc( top );
return data;
}
static INLINE void QueueInit( link_t *l )
{
l->data = NULL;
l->numElements = 0;
l->prev = l->next = l;
}
static INLINE int QueueSize( link_t *l )
{
return l->numElements;
}
static INLINE qboolean QueueEmpty( link_t *l )
{
return l->prev == l ? qtrue : qfalse;
}
static INLINE void EnQueue( link_t *sentinel, void *data )
{
link_t *l;
l = ( link_t * ) Com_Allocate( sizeof( *l ) );
InitLink( l, data );
InsertLink( l, sentinel );
sentinel->numElements++;
}
static INLINE void *DeQueue( link_t *l )
{
link_t *tail;
void *data;
tail = l->prev;
RemoveLink( tail );
data = tail->data;
Com_Dealloc( tail );
l->numElements--;
return data;
}
static INLINE link_t *QueueFront( link_t *l )
{
return l->prev;
}
// a trRefLight_t has all the information passed in by
// the client game, as well as some locally derived info
typedef struct trRefLight_s
{
// public from client game
refLight_t l;
// local
qboolean isStatic; // loaded from the BSP entities lump
qboolean noRadiosity; // this is a pure realtime light that was not considered by XMap2
qboolean additive; // texture detail is lost tho when the lightmap is dark
vec3_t origin; // l.origin + rotated l.center
vec3_t transformed; // origin in local coordinate system
vec3_t direction; // for directional lights (sun)
matrix_t transformMatrix; // light to world
matrix_t viewMatrix; // object to light
matrix_t projectionMatrix; // light frustum
float falloffLength;
matrix_t shadowMatrices[ MAX_SHADOWMAPS ];
matrix_t shadowMatricesBiased[ MAX_SHADOWMAPS ];
matrix_t attenuationMatrix; // attenuation * (light view * entity transform)
matrix_t attenuationMatrix2; // attenuation * tcMod matrices
cullResult_t cull;
vec3_t localBounds[ 2 ];
vec3_t worldBounds[ 2 ];
float sphereRadius; // calculated from localBounds
int8_t shadowLOD; // Level of Detail for shadow mapping
qboolean clipsNearPlane;
qboolean noOcclusionQueries;
uint32_t occlusionQueryObject;
uint32_t occlusionQuerySamples;
link_t multiQuery; // CHC++: list of all nodes that are used by the same occlusion query
int restrictInteractionFirst;
int restrictInteractionLast;
frustum_t frustum;
vec4_t localFrustum[ 6 ];
struct VBO_s *frustumVBO;
struct IBO_s *frustumIBO;
uint16_t frustumIndexes;
uint16_t frustumVerts;
screenRect_t scissor;
struct shader_s *shader;
struct interactionCache_s *firstInteractionCache; // only used by static lights
struct interactionCache_s *lastInteractionCache; // only used by static lights
struct interactionVBO_s *firstInteractionVBO; // only used by static lights
struct interactionVBO_s *lastInteractionVBO; // only used by static lights
struct interaction_s *firstInteraction;
struct interaction_s *lastInteraction;
uint16_t numInteractions; // total interactions
uint16_t numShadowOnlyInteractions;
uint16_t numLightOnlyInteractions;
qboolean noSort; // don't sort interactions by material
link_t leafs;
int visCounts[ MAX_VISCOUNTS ]; // node needs to be traversed if current
} trRefLight_t;
// a trRefEntity_t has all the information passed in by
// the client game, as well as some locally derived info
typedef struct
{
// public from client game
refEntity_t e;
// local
float axisLength; // compensate for non-normalized axis
qboolean lightingCalculated;
vec3_t lightDir; // normalized direction towards light
vec3_t ambientLight; // color normalized to 0-1
vec3_t directedLight;
cullResult_t cull;
vec3_t localBounds[ 2 ];
vec3_t worldBounds[ 2 ]; // only set when not completely culled. use them for light interactions
vec3_t worldCorners[ 8 ];
// GPU occlusion culling
qboolean noOcclusionQueries;
uint32_t occlusionQueryObject;
uint32_t occlusionQuerySamples;
link_t multiQuery; // CHC++: list of all nodes that are used by the same occlusion query
} trRefEntity_t;
typedef struct
{
vec3_t origin; // in world coordinates
vec3_t axis[ 3 ]; // orientation in world
vec3_t viewOrigin; // viewParms->or.origin in local coordinates
matrix_t transformMatrix; // transforms object to world: either used by camera, model or light
matrix_t viewMatrix; // affine inverse of transform matrix to transform other objects into this space
matrix_t viewMatrix2; // without quake2opengl conversion
matrix_t modelViewMatrix; // only used by models, camera viewMatrix * transformMatrix
} orientationr_t;
// useful helper struct
typedef struct vertexHash_s
{
vec3_t xyz;
void *data;
struct vertexHash_s *next;
} vertexHash_t;
enum
{
IF_NONE,
IF_NOPICMIP = BIT( 0 ),
IF_NOCOMPRESSION = BIT( 1 ),
IF_ALPHA = BIT( 2 ),
IF_NORMALMAP = BIT( 3 ),
IF_RGBA16F = BIT( 4 ),
IF_RGBA32F = BIT( 5 ),
IF_TWOCOMP16F = BIT( 6 ),
IF_TWOCOMP32F = BIT( 7 ),
IF_ONECOMP16F = BIT( 8 ),
IF_ONECOMP32F = BIT( 9 ),
IF_DEPTH16 = BIT( 10 ),
IF_DEPTH24 = BIT( 11 ),
IF_DEPTH32 = BIT( 12 ),
IF_PACKED_DEPTH24_STENCIL8 = BIT( 13 ),
IF_LIGHTMAP = BIT( 14 ),
IF_RGBA16 = BIT( 15 ),
IF_RGBE = BIT( 16 ),
IF_ALPHATEST = BIT( 17 ),
IF_DISPLACEMAP = BIT( 18 ),
IF_NOLIGHTSCALE = BIT( 19 ),
IF_BC1 = BIT( 20 ),
IF_BC3 = BIT( 21 ),
IF_BC4 = BIT( 22 ),
IF_BC5 = BIT( 23 )
};
typedef enum
{
FT_DEFAULT,
FT_LINEAR,
FT_NEAREST
} filterType_t;
typedef enum
{
WT_REPEAT,
WT_CLAMP, // don't repeat the texture for texture coords outside [0, 1]
WT_EDGE_CLAMP,
WT_ONE_CLAMP,
WT_ZERO_CLAMP, // guarantee 0,0,0,255 edge for projected textures
WT_ALPHA_ZERO_CLAMP // guarante 0 alpha edge for projected textures
} wrapTypeEnum_t;
typedef struct wrapType_s
{
wrapTypeEnum_t s, t;
wrapType_s() : s(WT_CLAMP), t(WT_CLAMP) {}
wrapType_s( wrapTypeEnum_t w ) : s(w), t(w) {}
wrapType_s( wrapTypeEnum_t s, wrapTypeEnum_t t ) : s(s), t(t) {}
inline struct wrapType_s &operator =( wrapTypeEnum_t w ) { this->s = this->t = w; return *this; }
} wrapType_t;
static inline bool operator ==( const wrapType_t &a, const wrapType_t &b ) { return a.s == b.s && a.t == b.t; }
static inline bool operator !=( const wrapType_t &a, const wrapType_t &b ) { return a.s != b.s || a.t != b.t; }
typedef struct image_s
{
char name[ 1024 ]; // formerly MAX_QPATH, game path, including extension
// can contain stuff like this now:
// addnormals ( textures/base_floor/stetile4_local.tga ,
// heightmap ( textures/base_floor/stetile4_bmp.tga , 4 ) )
GLenum type;
GLuint texnum; // gl texture binding
uint16_t width, height; // source image
uint16_t uploadWidth, uploadHeight; // after power of two and picmip but not including clamp to MAX_TEXTURE_SIZE
int frameUsed; // for texture usage in frame statistics
uint32_t internalFormat;
uint32_t bits;
filterType_t filterType;
wrapType_t wrapType;
struct image_s *next;
} image_t;
inline bool IsImageCompressed(int bits) { return bits & (IF_BC1 | IF_BC3 | IF_BC4 | IF_BC5); }
typedef struct FBO_s
{
char name[ MAX_QPATH ];
int index;
uint32_t frameBuffer;
uint32_t colorBuffers[ 16 ];
int colorFormat;
uint32_t depthBuffer;
int depthFormat;
uint32_t stencilBuffer;
int stencilFormat;
uint32_t packedDepthStencilBuffer;
int packedDepthStencilFormat;
int width;
int height;
} FBO_t;
enum
{
ATTR_INDEX_POSITION = 0,
ATTR_INDEX_TEXCOORD,
ATTR_INDEX_LIGHTCOORD,
ATTR_INDEX_TANGENT,
ATTR_INDEX_BINORMAL,
ATTR_INDEX_NORMAL,
ATTR_INDEX_COLOR,
// GPU vertex skinning
ATTR_INDEX_BONE_INDEXES,
ATTR_INDEX_BONE_WEIGHTS,
// GPU vertex animations
ATTR_INDEX_POSITION2,
ATTR_INDEX_TANGENT2,
ATTR_INDEX_BINORMAL2,
ATTR_INDEX_NORMAL2,
ATTR_INDEX_MAX
};
// must match order of ATTR_INDEX enums
static const char *const attributeNames[] =
{
"attr_Position",
"attr_TexCoord0",
"attr_TexCoord1",
"attr_Tangent",
"attr_Binormal",
"attr_Normal",
"attr_Color",
"attr_BoneIndexes",
"attr_BoneWeights",
"attr_Position2",
"attr_Tangent2",
"attr_Binormal2",
"attr_Normal2"
};
enum
{
ATTR_POSITION = BIT( ATTR_INDEX_POSITION ),
ATTR_TEXCOORD = BIT( ATTR_INDEX_TEXCOORD ),
ATTR_LIGHTCOORD = BIT( ATTR_INDEX_LIGHTCOORD ),
ATTR_TANGENT = BIT( ATTR_INDEX_TANGENT ),
ATTR_BINORMAL = BIT( ATTR_INDEX_BINORMAL ),
ATTR_NORMAL = BIT( ATTR_INDEX_NORMAL ),
ATTR_COLOR = BIT( ATTR_INDEX_COLOR ),
ATTR_BONE_INDEXES = BIT( ATTR_INDEX_BONE_INDEXES ),
ATTR_BONE_WEIGHTS = BIT( ATTR_INDEX_BONE_WEIGHTS ),
// for .md3 interpolation
ATTR_POSITION2 = BIT( ATTR_INDEX_POSITION2 ),
ATTR_TANGENT2 = BIT( ATTR_INDEX_TANGENT2 ),
ATTR_BINORMAL2 = BIT( ATTR_INDEX_BINORMAL2 ),
ATTR_NORMAL2 = BIT( ATTR_INDEX_NORMAL2 ),
ATTR_INTERP_BITS = ATTR_POSITION2 | ATTR_TANGENT2 | ATTR_BINORMAL2 | ATTR_NORMAL2,
// FIXME XBSP format with ATTR_LIGHTDIRECTION
//ATTR_DEFAULT = ATTR_POSITION | ATTR_TEXCOORD | ATTR_TANGENT | ATTR_BINORMAL | ATTR_COLOR,
ATTR_BITS = ATTR_POSITION |
ATTR_TEXCOORD |
ATTR_LIGHTCOORD |
ATTR_TANGENT |
ATTR_BINORMAL |
ATTR_NORMAL |
ATTR_COLOR // |
//ATTR_BONE_INDEXES |
//ATTR_BONE_WEIGHTS
};
typedef struct
{
GLint numComponents; // how many components in a single attribute for a single vertex
GLenum componentType; // the input type for a single component
GLboolean normalize; // convert signed integers to the floating point range [-1, 1], and unsigned integers to the range [0, 1]
GLsizei stride;
GLsizei realStride;
GLsizei ofs;
GLsizei frameOffset; // for vertex animation, real offset computed as ofs + frame * frameOffset
} vboAttributeLayout_t;
typedef enum
{
VBO_LAYOUT_VERTEX_ANIMATION,
VBO_LAYOUT_INTERLEAVED,
VBO_LAYOUT_SEPERATE
} vboLayout_t;
typedef struct
{
vec3_t *xyz;
vec3_t *tangent;
vec3_t *binormal;
vec3_t *normal;
int numFrames;
vec4_t *color;
vec2_t *st;
vec2_t *lightCoord;
vec3_t *ambientLight;
vec3_t *directedLight;
vec3_t *lightDir;
int (*boneIndexes)[ 4 ];
vec4_t *boneWeights;
int numVerts;
} vboData_t;
typedef struct VBO_s
{
char name[ MAX_QPATH ];
uint32_t vertexesVBO;
uint32_t vertexesSize; // total amount of memory data allocated for this vbo
uint32_t vertexesNum;
uint32_t framesNum; // number of frames for vertex animation
vboAttributeLayout_t attribs[ ATTR_INDEX_MAX ]; // info for buffer manipulation
vboLayout_t layout;
uint32_t attribBits;
GLenum usage;
} VBO_t;
typedef struct IBO_s
{
char name[ MAX_QPATH ];
uint32_t indexesVBO;
uint32_t indexesSize; // amount of memory data allocated for all triangles in bytes
uint32_t indexesNum;
} IBO_t;
//===============================================================================
typedef enum
{
SS_BAD,
SS_PORTAL, // mirrors, portals, viewscreens
SS_ENVIRONMENT_FOG, // sky
SS_OPAQUE, // opaque
SS_ENVIRONMENT_NOFOG, // Tr3B: moved skybox here so we can fog post process all SS_OPAQUE materials
SS_DECAL, // scorch marks, etc.
SS_SEE_THROUGH, // ladders, grates, grills that may have small blended edges
// in addition to alpha test
SS_BANNER,
SS_FOG,
SS_UNDERWATER, // for items that should be drawn in front of the water plane
SS_WATER,
SS_FAR,
SS_MEDIUM,
SS_CLOSE,
SS_BLEND0, // regular transparency and filters
SS_BLEND1, // generally only used for additive type effects
SS_BLEND2,
SS_BLEND3,
SS_BLEND6,
SS_ALMOST_NEAREST, // gun smoke puffs
SS_NEAREST, // blood blobs
SS_POST_PROCESS
} shaderSort_t;
typedef struct shaderTable_s
{
char name[ MAX_QPATH ];
uint16_t index;
qboolean clamp;
qboolean snap;
float *values;
uint16_t numValues;
struct shaderTable_s *next;
} shaderTable_t;
typedef enum
{
GF_NONE,
GF_SIN,
GF_SQUARE,
GF_TRIANGLE,
GF_SAWTOOTH,
GF_INVERSE_SAWTOOTH,
GF_NOISE
} genFunc_t;
typedef enum
{
DEFORM_NONE,
DEFORM_WAVE,
DEFORM_NORMALS,
DEFORM_BULGE,
DEFORM_MOVE,
DEFORM_PROJECTION_SHADOW,
DEFORM_AUTOSPRITE,
DEFORM_AUTOSPRITE2,
DEFORM_TEXT0,
DEFORM_TEXT1,
DEFORM_TEXT2,
DEFORM_TEXT3,
DEFORM_TEXT4,
DEFORM_TEXT5,
DEFORM_TEXT6,
DEFORM_TEXT7,
DEFORM_SPRITE,
DEFORM_FLARE
} deform_t;
// deformVertexes types that can be handled by the GPU
typedef enum
{
// do not edit: same as genFunc_t
DGEN_NONE,
DGEN_WAVE_SIN,
DGEN_WAVE_SQUARE,
DGEN_WAVE_TRIANGLE,
DGEN_WAVE_SAWTOOTH,
DGEN_WAVE_INVERSE_SAWTOOTH,
DGEN_WAVE_NOISE,
// do not edit until this line
DGEN_BULGE,
DGEN_MOVE
} deformGen_t;
typedef enum
{
DEFORM_TYPE_NONE,
DEFORM_TYPE_CPU,
DEFORM_TYPE_GPU,
} deformType_t;
typedef enum
{
AGEN_IDENTITY,
AGEN_ENTITY,
AGEN_ONE_MINUS_ENTITY,
AGEN_VERTEX,
AGEN_ONE_MINUS_VERTEX,
AGEN_WAVEFORM,
AGEN_CONST,
AGEN_CUSTOM
} alphaGen_t;
typedef enum
{
CGEN_BAD,
CGEN_IDENTITY_LIGHTING, // tr.identityLight
CGEN_IDENTITY, // always (1,1,1,1)
CGEN_ENTITY, // grabbed from entity's modulate field
CGEN_ONE_MINUS_ENTITY, // grabbed from 1 - entity.modulate
CGEN_VERTEX, // tess.colors
CGEN_ONE_MINUS_VERTEX,
CGEN_WAVEFORM, // programmatically generated
CGEN_CONST, // fixed color
CGEN_CUSTOM_RGB, // like fixed color but generated dynamically, single arithmetic expression
CGEN_CUSTOM_RGBs, // multiple expressions
} colorGen_t;
typedef enum
{
ACFF_NONE,
ACFF_MODULATE_RGB,
ACFF_MODULATE_RGBA,
ACFF_MODULATE_ALPHA
} acff_t;
typedef enum
{
OP_BAD,
// logic operators
OP_LAND,
OP_LOR,
OP_GE,
OP_LE,
OP_LEQ,
OP_LNE,
// arithmetic operators
OP_ADD,
OP_SUB,
OP_DIV,
OP_MOD,
OP_MUL,
OP_NEG,
// logic operators
OP_LT,
OP_GT,
// embracements
OP_LPAREN,
OP_RPAREN,
OP_LBRACKET,
OP_RBRACKET,
// constants or variables
OP_NUM,
OP_TIME,
OP_PARM0,
OP_PARM1,
OP_PARM2,
OP_PARM3,
OP_PARM4,
OP_PARM5,
OP_PARM6,
OP_PARM7,
OP_PARM8,
OP_PARM9,
OP_PARM10,
OP_PARM11,
OP_GLOBAL0,
OP_GLOBAL1,
OP_GLOBAL2,
OP_GLOBAL3,
OP_GLOBAL4,
OP_GLOBAL5,
OP_GLOBAL6,
OP_GLOBAL7,
OP_FRAGMENTSHADERS,
OP_FRAMEBUFFEROBJECTS,
OP_SOUND,
OP_DISTANCE,
// table access
OP_TABLE
} opcode_t;
typedef struct
{
const char *s;
opcode_t type;
} opstring_t;
typedef struct
{
opcode_t type;
float value;
} expOperation_t;
#define MAX_EXPRESSION_OPS 32
typedef struct
{
expOperation_t ops[ MAX_EXPRESSION_OPS ];
uint8_t numOps;
qboolean active; // no parsing problems
} expression_t;
typedef struct
{
genFunc_t func;
float base;
float amplitude;
float phase;
float frequency;
} waveForm_t;
#define TR_MAX_TEXMODS 4
typedef enum
{
TMOD_NONE,
TMOD_TRANSFORM,
TMOD_TURBULENT,
TMOD_SCROLL,
TMOD_SCALE,
TMOD_STRETCH,
TMOD_ROTATE,
TMOD_ENTITY_TRANSLATE,
TMOD_SCROLL2,
TMOD_SCALE2,
TMOD_CENTERSCALE,
TMOD_SHEAR,
TMOD_ROTATE2
} texMod_t;
#define MAX_SHADER_DEFORMS 3
#define MAX_SHADER_DEFORM_PARMS ( 1 + MAX_SHADER_DEFORMS + MAX_SHADER_DEFORMS * 8 )
typedef struct
{
deform_t deformation; // vertex coordinate modification type
vec3_t moveVector;
waveForm_t deformationWave;
float deformationSpread;
float bulgeWidth;
float bulgeHeight;
float bulgeSpeed;
float flareSize;
} deformStage_t;
typedef struct
{
texMod_t type;
// used for TMOD_TURBULENT and TMOD_STRETCH
waveForm_t wave;
// used for TMOD_TRANSFORM
matrix_t matrix; // s' = s * m[0][0] + t * m[1][0] + trans[0]
// t' = s * m[0][1] + t * m[0][1] + trans[1]
// used for TMOD_SCALE
float scale[ 2 ]; // s *= scale[0]
// t *= scale[1]
// used for TMOD_SCROLL
float scroll[ 2 ]; // s' = s + scroll[0] * time
// t' = t + scroll[1] * time
// + = clockwise
// - = counterclockwise
float rotateSpeed;
// used by everything else
expression_t sExp;
expression_t tExp;
expression_t rExp;
} texModInfo_t;
#define MAX_IMAGE_ANIMATIONS 24
enum
{
TB_COLORMAP = 0,
TB_DIFFUSEMAP = 0,
TB_NORMALMAP,
TB_SPECULARMAP,
TB_GLOWMAP,
MAX_TEXTURE_BUNDLES = 4
};
typedef struct
{
uint8_t numImages;
float imageAnimationSpeed;
image_t *image[ MAX_IMAGE_ANIMATIONS ];
uint8_t numTexMods;
texModInfo_t *texMods;
int videoMapHandle;
qboolean isVideoMap;
} textureBundle_t;
typedef enum
{
// material shader stage types
ST_COLORMAP, // vanilla Q3A style shader treatening
ST_GLOWMAP,
ST_DIFFUSEMAP,
ST_NORMALMAP,
ST_SPECULARMAP,
ST_REFLECTIONMAP, // cubeMap based reflection
ST_REFRACTIONMAP,
ST_DISPERSIONMAP,
ST_SKYBOXMAP,