forked from DaemonEngine/Daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtr_local.h
More file actions
3675 lines (2904 loc) · 105 KB
/
tr_local.h
File metadata and controls
3675 lines (2904 loc) · 105 KB
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 <GL/glew.h>
#include "common/FileSystem.h"
#include "qcommon/q_shared.h"
#include "qcommon/qfiles.h"
#include "qcommon/qcommon.h"
#include "botlib/bot_debug.h"
#include "engine/RefAPI.h"
#include "GLUtils.h"
#include "iqm.h"
#include "DetectGLVendors.h"
#include "TextureManager.h"
#include "VBO.h"
#define DYN_BUFFER_SIZE ( 4 * 1024 * 1024 )
#define DYN_BUFFER_SEGMENTS 4
#define BUFFER_OFFSET(i) (reinterpret_cast<const void*>( i ))
using i8vec4_t = int8_t[4];
using u8vec4_t = uint8_t[4];
using i16vec4_t = int16_t[4];
using u16vec4_t = uint16_t[4];
using i16vec2_t = int16_t[2];
using u16vec2_t = uint16_t[2];
// The struct has the same memory layout as a half-float
struct f16_t
{
uint16_t bits;
};
using f16vec2_t = f16_t[2]; // half float vector
using f16vec4_t = f16_t[4]; // half float vector
// 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(int8_t snorm8) {
return std::max( snorm8 * (1.0f / 127.0f), -1.0f);
}
static inline int8_t 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);
}
static inline float unorm16ToFloat(uint16_t unorm16) {
return unorm16 * (1.0f / 65535.0f);
}
static inline uint16_t floatToUnorm16(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 * 65535.0f);
}
static inline float snorm16ToFloat(int16_t snorm16) {
return std::max( snorm16 * (1.0f / 32767.0f), -1.0f);
}
static inline int16_t floatToSnorm16(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 * 32767.0f);
}
static inline void floatToUnorm8( const vec4_t in, u8vec4_t out )
{
out[ 0 ] = floatToUnorm8( in[ 0 ] );
out[ 1 ] = floatToUnorm8( in[ 1 ] );
out[ 2 ] = floatToUnorm8( in[ 2 ] );
out[ 3 ] = floatToUnorm8( in[ 3 ] );
}
static inline void unorm8ToFloat( const u8vec4_t in, vec4_t out )
{
out[ 0 ] = unorm8ToFloat( in[ 0 ] );
out[ 1 ] = unorm8ToFloat( in[ 1 ] );
out[ 2 ] = unorm8ToFloat( in[ 2 ] );
out[ 3 ] = unorm8ToFloat( in[ 3 ] );
}
static inline void floatToSnorm16( const vec4_t in, i16vec4_t out )
{
out[ 0 ] = floatToSnorm16( in[ 0 ] );
out[ 1 ] = floatToSnorm16( in[ 1 ] );
out[ 2 ] = floatToSnorm16( in[ 2 ] );
out[ 3 ] = floatToSnorm16( in[ 3 ] );
}
static inline void floatToSnorm16_fast( const vec4_t in, i16vec4_t out )
{
// Just truncate them all.
out[ 0 ] = in[ 0 ] * 32767.0f;
out[ 1 ] = in[ 1 ] * 32767.0f;
out[ 2 ] = in[ 2 ] * 32767.0f;
out[ 3 ] = in[ 3 ] * 32767.0f;
}
static inline void snorm16ToFloat( const i16vec4_t in, vec4_t out )
{
out[ 0 ] = snorm16ToFloat( in[ 0 ] );
out[ 1 ] = snorm16ToFloat( in[ 1 ] );
out[ 2 ] = snorm16ToFloat( in[ 2 ] );
out[ 3 ] = snorm16ToFloat( in[ 3 ] );
}
static inline uint32_t packUnorm4x8( const vec4_t in ) {
return uint32_t( floatToUnorm8( in[0] ) )
| ( uint32_t( floatToUnorm8( in[1] ) ) << 8 )
| ( uint32_t( floatToUnorm8( in[2] ) ) << 16 )
| ( uint32_t( floatToUnorm8( in[3] ) ) << 24 );
}
static inline f16_t floatToHalf( float in ) {
static float scale = powf(2.0f, 15 - 127);
uint32_t ui = Util::bit_cast<uint32_t>( in * scale );
return { uint16_t(((ui & 0x80000000) >> 16) | ((ui & 0x0fffe000) >> 13)) };
}
static inline void floatToHalf( const vec4_t in, f16vec4_t out )
{
out[ 0 ] = floatToHalf( in[ 0 ] );
out[ 1 ] = floatToHalf( in[ 1 ] );
out[ 2 ] = floatToHalf( in[ 2 ] );
out[ 3 ] = floatToHalf( in[ 3 ] );
}
static inline float halfToFloat( f16_t in ) {
static float scale = powf(2.0f, 127 - 15);
uint32_t ui = (((unsigned int)in.bits & 0x8000) << 16) | (((unsigned int)in.bits & 0x7fff) << 13);
return Util::bit_cast<float>(ui) * scale;
}
static inline void halfToFloat( const f16vec4_t in, vec4_t out )
{
out[ 0 ] = halfToFloat( in[ 0 ] );
out[ 1 ] = halfToFloat( in[ 1 ] );
out[ 2 ] = halfToFloat( in[ 2 ] );
out[ 3 ] = halfToFloat( in[ 3 ] );
}
// 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 MAX_SHADER_TABLES 1024
#define MAX_SHADER_STAGES 16
#define MAX_FBOS 64
#define MAX_VISCOUNTS 5
#define MAX_VIEWS 10
#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
#define MAX_MOD_KNOWN 1024
#define MAX_ANIMATIONFILES 4096
#define MAX_LIGHTMAPS 256
#define MAX_SKINS 1024
#define MAX_IN_GAME_VIDEOS 32
#define MAX_DRAWSURFS 0x10000
#define DRAWSURF_MASK ( MAX_DRAWSURFS - 1 )
// 16x16 pixels per tile
#define TILE_SHIFT 4
#define TILE_SIZE (1 << TILE_SHIFT)
#define TILE_SHIFT_STEP1 2
#define TILE_SIZE_STEP1 (1 << TILE_SHIFT_STEP1)
struct glFboShim_t
{
/* Functions with same signature and similar purpose can be provided by:
- ARB_framebuffer_object
- EXT_framebuffer_object
- OES_framebuffer_object
They are not 100% equivalent, for example the ARB fbo provides more
features than the EXT fbo, but the EXT fbo subset of the ARB fbo looks
to be enough for us. */
// void (*glBindFramebuffer) (GLenum target, GLuint framebuffer);
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
// void (*glBindRenderbuffer) (GLenum target, GLuint renderbuffer);
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
// GLenum (*glCheckFramebufferStatus) (GLenum target);
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
// void (*glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers);
PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
// void (*glDeleteRenderbuffers) (GLsizei n, const GLuint *renderbuffers);
PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
// void (*glFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
// void (*glFramebufferTexture1D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
// void (*glFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
// void (*glFramebufferTexture3D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
// void (*glGenerateMipmap) (GLenum target);
PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
// void (*glGenFramebuffers) (GLsizei n, GLuint *framebuffers);
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
// void (*glGenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
// void (*glRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
// void (*glBlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
/* Unused for now, part of GL_EXT_framebuffer_multisample:
// void (*glRenderbufferStorageMultisample) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample; */
/* Those three values are the same:
- GL_FRAMEBUFFER_COMPLETE
- GL_FRAMEBUFFER_COMPLETE_EXT
- GL_FRAMEBUFFER_COMPLETE_OES
The same happens with other GL_FRAMEBUFFER_* defines, we can expect the
various names for various the extension variants to share the same values.
So there is no need to abstract them and GL_FRAMEBUFFER_COMPLETE can be
used in all cases. */
};
extern glFboShim_t GL_fboShim;
static inline void glFboSetArb()
{
GL_fboShim.glBindFramebuffer = glBindFramebuffer;
GL_fboShim.glBindRenderbuffer = glBindRenderbuffer;
GL_fboShim.glCheckFramebufferStatus = glCheckFramebufferStatus;
GL_fboShim.glDeleteFramebuffers = glDeleteFramebuffers;
GL_fboShim.glDeleteRenderbuffers = glDeleteRenderbuffers;
GL_fboShim.glFramebufferRenderbuffer = glFramebufferRenderbuffer;
GL_fboShim.glFramebufferTexture1D = glFramebufferTexture1D;
GL_fboShim.glFramebufferTexture2D = glFramebufferTexture2D;
GL_fboShim.glFramebufferTexture3D = glFramebufferTexture3D;
GL_fboShim.glGenerateMipmap = glGenerateMipmap;
GL_fboShim.glGenFramebuffers = glGenFramebuffers;
GL_fboShim.glGenRenderbuffers = glGenRenderbuffers;
GL_fboShim.glRenderbufferStorage = glRenderbufferStorage;
GL_fboShim.glBlitFramebuffer = glBlitFramebuffer;
/* Unused for now, part of GL_EXT_framebuffer_multisample:
GL_fboShim.glRenderbufferStorageMultisample = glRenderbufferStorageMultisample; */
}
static inline void glFboSetExt()
{
// EXT_framebuffer_object
GL_fboShim.glBindFramebuffer = glBindFramebufferEXT;
GL_fboShim.glBindRenderbuffer = glBindRenderbufferEXT;
GL_fboShim.glCheckFramebufferStatus = glCheckFramebufferStatusEXT;
GL_fboShim.glDeleteFramebuffers = glDeleteFramebuffersEXT;
GL_fboShim.glDeleteRenderbuffers = glDeleteRenderbuffersEXT;
GL_fboShim.glFramebufferRenderbuffer = glFramebufferRenderbufferEXT;
GL_fboShim.glFramebufferTexture1D = glFramebufferTexture1DEXT;
GL_fboShim.glFramebufferTexture2D = glFramebufferTexture2DEXT;
GL_fboShim.glFramebufferTexture3D = glFramebufferTexture3DEXT;
GL_fboShim.glGenerateMipmap = glGenerateMipmapEXT;
GL_fboShim.glGenFramebuffers = glGenFramebuffersEXT;
GL_fboShim.glGenRenderbuffers = glGenRenderbuffersEXT;
GL_fboShim.glRenderbufferStorage = glRenderbufferStorageEXT;
// EXT_framebuffer_blit
GL_fboShim.glBlitFramebuffer = glBlitFramebufferEXT;
/* Unused for now, part of GL_EXT_framebuffer_multisample:
GL_fboShim.glRenderbufferStorageMultisample = glRenderbufferStorageMultisampleEXT; */
}
enum class lightMode_t { FULLBRIGHT, VERTEX, GRID, MAP };
enum class deluxeMode_t { NONE, GRID, MAP };
enum class showCubeProbesMode {
DISABLED,
GRID,
UNIQUE
};
enum class cubeProbesAutoBuildMode {
DISABLED,
CACHED,
ALWAYS
};
enum class shaderProfilerRenderSubGroupsMode {
VS_OPAQUE,
VS_TRANSPARENT,
VS_ALL,
FS_OPAQUE,
FS_TRANSPARENT,
FS_ALL
};
enum class ssaoMode {
SHOW = -1,
DISABLED,
ENABLED,
};
enum class renderSpeeds_t
{
RSPEEDS_GENERAL = 1,
RSPEEDS_CULLING,
RSPEEDS_VIEWCLUSTER,
RSPEEDS_CHC,
RSPEEDS_NEAR_FAR,
};
enum class glDebugModes_t
{
GLDEBUG_NONE,
GLDEBUG_ERROR,
GLDEBUG_DEPRECIATED,
GLDEBUG_UNDEFINED,
GLDEBUG_PORTABILITY,
GLDEBUG_PERFORMANCE,
GLDEBUG_OTHER,
GLDEBUG_ALL
};
#define REF_CUBEMAP_SIZE 32
#define REF_COLORGRADE_SLOTS 4
#define REF_COLORGRADEMAP_SIZE 16
#define REF_COLORGRADEMAP_STORE_SIZE ( REF_COLORGRADEMAP_SIZE * REF_COLORGRADEMAP_SIZE * REF_COLORGRADEMAP_SIZE )
enum cullResult_t
{
CULL_IN, // completely unclipped
CULL_CLIP, // clipped by one or more planes
CULL_OUT, // completely outside the clipping planes
};
struct screenRect_t
{
int coords[ 4 ];
};
enum frustumBits_t : int
{
FRUSTUM_LEFT,
FRUSTUM_RIGHT,
FRUSTUM_BOTTOM,
FRUSTUM_TOP,
FRUSTUM_NEAR,
// seems intentionnal to have twice the value 5, except that, quote:
// There is at least one minor mistake in the usage of FRUSTUM_PLANES though.
// The signature of R_CalcFrustumFarCorners suggests that an array of length
// 5 is a good input, but it reads from the 6th element"
FRUSTUM_FAR = 5,
FRUSTUM_PLANES = 5,
FRUSTUM_CLIPALL = 1 | 2 | 4 | 8 | 16 //| 32
};
using frustum_t = cplane_t[6];
// FIXME: it is impossible for the game to create any type besides RL_OMNI
enum class refLightType_t
{
RL_OMNI, // point light
RL_PROJ, // spot light
RL_DIRECTIONAL, // sun light
RL_MAX_REF_LIGHT_TYPE
};
struct refLight_t
{
refLightType_t rlType;
vec3_t origin;
vec3_t color; // should be color normalized
// omni-directional light specific
float radius;
// projective light specific
vec3_t projTarget;
vec3_t projUp;
};
// a structure matching the GLSL struct shaderLight in std140 layout
struct shaderLight_t {
vec3_t center;
float radius;
vec3_t color;
float type;
vec3_t direction;
float angle;
};
// a trRefEntity_t has all the information passed in by
// the client game, as well as some locally derived info
struct trRefEntity_t
{
// public from client game
refEntity_t e;
// local
float axisLength; // compensate for non-normalized axis
vec3_t localBounds[ 2 ];
vec3_t worldBounds[ 2 ];
};
struct orientationr_t
{
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
};
enum
{
BIND_DIFFUSEMAP,
BIND_NORMALMAP,
BIND_HEIGHTMAP,
BIND_MATERIALMAP,
BIND_LIGHTMAP,
BIND_DELUXEMAP,
BIND_GLOWMAP,
BIND_LIGHTGRID1,
BIND_LIGHTGRID2,
BIND_ENVIRONMENTMAP0,
BIND_ENVIRONMENTMAP1,
BIND_LIGHTTILES,
BIND_LIGHTS,
};
enum
{
IF_NONE,
IF_NOPICMIP = BIT( 0 ),
IF_FITSCREEN = BIT( 1 ),
IF_NORMALMAP = BIT( 2 ),
IF_RGBA16F = BIT( 3 ),
IF_RGBA32F = BIT( 4 ),
IF_TWOCOMP16F = BIT( 5 ),
IF_TWOCOMP32F = BIT( 6 ),
IF_ONECOMP16F = BIT( 7 ),
IF_ONECOMP32F = BIT( 8 ),
IF_DEPTH16 = BIT( 9 ),
IF_DEPTH24 = BIT( 10 ),
IF_DEPTH32 = BIT( 11 ),
IF_PACKED_DEPTH24_STENCIL8 = BIT( 12 ),
IF_LIGHTMAP = BIT( 13 ),
IF_RGBE = BIT( 15 ),
IF_ALPHATEST = BIT( 16 ), // FIXME: this is unused
IF_ALPHA = BIT( 17 ),
IF_SRGB = BIT( 18 ),
IF_BC1 = BIT( 19 ),
IF_BC2 = BIT( 20 ),
IF_BC3 = BIT( 21 ),
IF_BC4 = BIT( 22 ),
IF_BC5 = BIT( 23 ),
IF_RGBA32UI = BIT( 24 ),
IF_HOMEPATH = BIT( 25 )
};
enum class filterType_t
{
FT_DEFAULT,
FT_LINEAR,
FT_NEAREST
};
enum class wrapTypeEnum_t
{
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 // guarantee 0 alpha edge for projected textures
};
struct wrapType_t
{
wrapTypeEnum_t s, t;
wrapType_t() = default;
wrapType_t( wrapTypeEnum_t w ) : s(w), t(w) {}
wrapType_t( wrapTypeEnum_t s, wrapTypeEnum_t t ) : s(s), t(t) {}
inline wrapType_t &operator =( wrapTypeEnum_t w ) { this->s = this->t = w; return *this; }
};
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; }
struct imageParams_t
{
int bits = 0;
filterType_t filterType;
wrapType_t wrapType;
int minDimension = 0;
int maxDimension = 0;
bool operator==(const imageParams_t &o) const
{
return o.bits == bits && o.filterType == filterType && o.wrapType == wrapType
&& o.minDimension == minDimension && o.maxDimension == maxDimension;
}
};
struct image_t
{
char name[ MAX_QPATH ];
imageParams_t initialParams; // may not match final values
GLenum type;
GLuint texnum; // gl texture binding
Texture *texture;
uint16_t width, height, numLayers; // 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;
image_t *next;
};
inline bool IsImageCompressed(int bits) { return bits & (IF_BC1 | IF_BC2 | IF_BC3 | IF_BC4 | IF_BC5); }
struct FBO_t
{
char name[ MAX_QPATH ];
uint32_t frameBuffer;
int width;
int height;
};
//===============================================================================
// Sorts commented "keyword only" will never be used unless the shader text has a `sort` keyword specifying it.
enum class shaderSort_t
{
SS_BAD,
SS_PORTAL, // mirrors, portals, viewscreens
SS_DEPTH, // depth pre-pass
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, // keyword only
SS_FOG,
SS_UNDERWATER, // keyword only
SS_FAR, // keyword only
SS_MEDIUM, // keyword only
SS_CLOSE, // keyword only
// Must have value 15 because binary.shader contains numerical sort values between 15 and 16
SS_BLEND0 = 15, // regular transparency and filters
SS_BLEND1, // Keyword only. Generally only used for additive type effects
SS_ALMOST_NEAREST, // keyword only
SS_NEAREST, // keyword only
SS_POST_PROCESS, // keyword only
SS_NUM_SORTS
};
struct shaderTable_t
{
char name[ MAX_QPATH ];
uint16_t index;
bool clamp;
bool snap;
float *values;
uint16_t numValues;
shaderTable_t *next;
};
enum class genFunc_t
{
GF_NONE,
GF_SIN,
GF_SQUARE,
GF_TRIANGLE,
GF_SAWTOOTH,
GF_INVERSE_SAWTOOTH,
GF_NOISE
};
enum class deform_t
{
DEFORM_NONE,
DEFORM_WAVE,
DEFORM_NORMALS,
DEFORM_BULGE,
DEFORM_MOVE,
DEFORM_ROTGROW
};
enum class alphaGen_t
{
AGEN_IDENTITY,
AGEN_ENTITY,
AGEN_ONE_MINUS_ENTITY,
AGEN_VERTEX,
AGEN_ONE_MINUS_VERTEX,
AGEN_WAVEFORM,
AGEN_PORTAL,
AGEN_CONST,
AGEN_CUSTOM
};
enum class colorGen_t
{
CGEN_BAD,
CGEN_IDENTITY_LIGHTING, // Always (1,1,1,1) in Dæmon engine, unless you set r_overbrightQ3.
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
};
enum class opcode_t
{
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_NAIVE_BLENDING,
OP_LINEAR_BLENDING,
OP_FRAGMENTSHADERS,
OP_FRAMEBUFFEROBJECTS,
OP_SOUND,
OP_DISTANCE,
// table access
OP_TABLE
};
struct opstring_t
{
const char *s;
opcode_t type;
};
struct expOperation_t
{
opcode_t type;
float value;
};
enum
{
EXP_NONE,
EXP_CLAMP = BIT( 0 ),
EXP_SRGB = BIT( 1 ),
};
#define MAX_EXPRESSION_OPS 32
struct expression_t
{
expOperation_t ops[ MAX_EXPRESSION_OPS ];
size_t numOps;
int bits;
bool operator==( const expression_t& other ) {
if ( numOps != other.numOps ) {
return false;
}
for ( size_t i = 0; i < numOps; i++ ) {
if ( ops[i].type != other.ops[i].type || ops[i].value != other.ops[i].value ) {
return false;
}
}
return true;
}
bool operator!=( const expression_t& other ) {
return !( *this == other );
}
};
struct waveForm_t
{
genFunc_t func;
float base;
float amplitude;
float phase;
float frequency;
bool operator==( const waveForm_t& other ) {
return func == other.func && base == other.base && amplitude == other.amplitude && phase == other.phase
&& frequency == other.frequency;
}
bool operator!=( const waveForm_t& other ) {
return !( *this == other );
}
};
#define TR_MAX_TEXMODS 4
enum class texMod_t
{
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
};
#define MAX_SHADER_DEFORMS 3
struct deformStage_t
{
deform_t deformation; // vertex coordinate modification type
vec3_t moveVector;
waveForm_t deformationWave;
float deformationSpread;
float bulgeWidth;
float bulgeHeight;
float bulgeSpeed;
float flareSize;
};
struct texModInfo_t
{
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;
bool operator==( const texModInfo_t& other ) {
return type == other.type && wave == other.wave && MatrixCompare( matrix, other.matrix )
&& scale[0] == other.scale[0] && scale[1] == other.scale[1] && scroll[0] == other.scroll[0] && scroll[1] == other.scroll[1]
&& rotateSpeed == other.rotateSpeed
&& sExp == other.sExp && tExp == other.tExp && rExp == other.rExp;
}
bool operator!=( const texModInfo_t& other ) {
return !( *this == other );
}
};
#define MAX_IMAGE_ANIMATIONS 32
enum
{
TB_COLORMAP,
TB_DIFFUSEMAP = TB_COLORMAP,
TB_REFLECTIONMAP = TB_COLORMAP,
TB_NORMALMAP,
TB_HEIGHTMAP,
TB_MATERIALMAP,
TB_PHYSICALMAP = TB_MATERIALMAP,
TB_SPECULARMAP = TB_MATERIALMAP,
TB_GLOWMAP,
MAX_TEXTURE_BUNDLES
};
struct textureBundle_t
{
uint8_t numImages;
float imageAnimationSpeed;
image_t *image[ MAX_IMAGE_ANIMATIONS ];
size_t numTexMods;
texModInfo_t *texMods;
int videoMapHandle;
bool isVideoMap;
};
enum class stageType_t
{
// material shader stage types
ST_COLORMAP, // vanilla Q3A style shader treatening
ST_GLOWMAP,
ST_DIFFUSEMAP,
ST_NORMALMAP,
ST_HEIGHTMAP,
ST_PHYSICALMAP,
ST_SPECULARMAP,
ST_REFLECTIONMAP, // cubeMap based reflection
ST_SKYBOXMAP,
ST_SCREENMAP, // 2d offscreen or portal rendering
ST_PORTALMAP,
ST_HEATHAZEMAP, // heatHaze post process effect
ST_LIQUIDMAP,
ST_FOGMAP_INNER, // a fog seen from inside
ST_FOGMAP_OUTER, // a fog seen from outside
ST_LIGHTMAP,
ST_STYLELIGHTMAP,
ST_STYLECOLORMAP,
ST_COLLAPSE_COLORMAP,
ST_COLLAPSE_DIFFUSEMAP,
ST_COLLAPSE_REFLECTIONMAP, // color cubemap + normalmap
};
enum class collapseType_t
{
COLLAPSE_none,
COLLAPSE_generic, // used before we know it's another one
COLLAPSE_PHONG,
COLLAPSE_PBR,
COLLAPSE_REFLECTIONMAP,
};
struct shader_t;
struct shaderStage_t;
struct Material;
struct MaterialSurface;
using stageRenderer_t = void(*)(shaderStage_t *);
using stageShaderBuildMarker_t = void(*)(const shaderStage_t*);
using surfaceDataUpdater_t = void(*)(uint32_t*, shaderStage_t*, bool, bool);
using stageShaderBinder_t = void(*)(Material*);
using stageMaterialProcessor_t = void(*)(Material*, shaderStage_t*, MaterialSurface*);
enum ShaderStageVariant {
VERTEX_LIT = BIT( 0 ),
FULLBRIGHT = BIT( 1 ),
ALL = BIT( 2 )
};
using floatProcessor_t = float(*)(float);
using colorProcessor_t = Color::Color(*)(Color::Color);
Color::Color convertColorFromSRGB_NOP( Color::Color c );
struct shaderStage_t
{
stageType_t type;
collapseType_t collapseType;
bool active;
bool dpMaterial;
// Core renderer (code path for when only OpenGL Core is available, or compatible OpenGL 2).
stageRenderer_t colorRenderer;
stageShaderBuildMarker_t shaderBuildMarker;
// Material renderer (code path for advanced OpenGL techniques like bindless textures).
surfaceDataUpdater_t surfaceDataUpdater;
stageShaderBinder_t shaderBinder;
stageMaterialProcessor_t materialProcessor;