forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtr_init.cpp
2163 lines (1856 loc) · 65.6 KB
/
tr_init.cpp
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) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2005 - 2015, ioquake3 contributors
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
// tr_init.c -- functions that are not called every frame
#include "../server/exe_headers.h"
#include "tr_local.h"
#include "../rd-common/tr_common.h"
#include "tr_stl.h"
#include "../rd-common/tr_font.h"
#include "tr_WorldEffects.h"
glconfig_t glConfig;
glstate_t glState;
window_t window;
static void GfxInfo_f( void );
cvar_t *r_verbose;
cvar_t *r_ignore;
cvar_t *r_detailTextures;
cvar_t *r_znear;
cvar_t *r_skipBackEnd;
cvar_t *r_measureOverdraw;
cvar_t *r_fastsky;
cvar_t *r_drawSun;
cvar_t *r_dynamiclight;
// rjr - removed for hacking cvar_t *r_dlightBacks;
cvar_t *r_lodbias;
cvar_t *r_lodscale;
cvar_t *r_norefresh;
cvar_t *r_drawentities;
cvar_t *r_drawworld;
cvar_t *r_drawfog;
cvar_t *r_speeds;
cvar_t *r_fullbright;
cvar_t *r_novis;
cvar_t *r_nocull;
cvar_t *r_facePlaneCull;
cvar_t *r_showcluster;
cvar_t *r_nocurves;
cvar_t *r_dlightStyle;
cvar_t *r_surfaceSprites;
cvar_t *r_surfaceWeather;
cvar_t *r_windSpeed;
cvar_t *r_windAngle;
cvar_t *r_windGust;
cvar_t *r_windDampFactor;
cvar_t *r_windPointForce;
cvar_t *r_windPointX;
cvar_t *r_windPointY;
cvar_t *r_allowExtensions;
cvar_t *r_ext_compressed_textures;
cvar_t *r_ext_compressed_lightmaps;
cvar_t *r_ext_preferred_tc_method;
cvar_t *r_ext_gamma_control;
cvar_t *r_ext_multitexture;
cvar_t *r_ext_compiled_vertex_array;
cvar_t *r_ext_texture_env_add;
cvar_t *r_ext_texture_filter_anisotropic;
cvar_t *r_DynamicGlow;
cvar_t *r_DynamicGlowPasses;
cvar_t *r_DynamicGlowDelta;
cvar_t *r_DynamicGlowIntensity;
cvar_t *r_DynamicGlowSoft;
cvar_t *r_DynamicGlowWidth;
cvar_t *r_DynamicGlowHeight;
cvar_t *r_ignoreGLErrors;
cvar_t *r_logFile;
cvar_t *r_primitives;
cvar_t *r_texturebits;
cvar_t *r_texturebitslm;
cvar_t *r_lightmap;
cvar_t *r_vertexLight;
cvar_t *r_shadows;
cvar_t *r_shadowRange;
cvar_t *r_flares;
cvar_t *r_nobind;
cvar_t *r_singleShader;
cvar_t *r_colorMipLevels;
cvar_t *r_picmip;
cvar_t *r_showtris;
cvar_t *r_showtriscolor;
cvar_t *r_showsky;
cvar_t *r_shownormals;
cvar_t *r_finish;
cvar_t *r_clear;
cvar_t *r_textureMode;
cvar_t *r_offsetFactor;
cvar_t *r_offsetUnits;
cvar_t *r_gamma;
cvar_t *r_intensity;
cvar_t *r_lockpvs;
cvar_t *r_noportals;
cvar_t *r_portalOnly;
cvar_t *r_subdivisions;
cvar_t *r_lodCurveError;
cvar_t *r_overBrightBits;
cvar_t *r_mapOverBrightBits;
cvar_t *r_debugSurface;
cvar_t *r_simpleMipMaps;
cvar_t *r_showImages;
cvar_t *r_ambientScale;
cvar_t *r_directedScale;
cvar_t *r_debugLight;
cvar_t *r_debugSort;
cvar_t *r_debugStyle;
cvar_t *r_modelpoolmegs;
cvar_t *r_noGhoul2;
cvar_t *r_Ghoul2AnimSmooth;
cvar_t *r_Ghoul2UnSqash;
cvar_t *r_Ghoul2TimeBase=0;
cvar_t *r_Ghoul2NoLerp;
cvar_t *r_Ghoul2NoBlend;
cvar_t *r_Ghoul2BlendMultiplier=0;
cvar_t *r_Ghoul2UnSqashAfterSmooth;
cvar_t *broadsword;
cvar_t *broadsword_kickbones;
cvar_t *broadsword_kickorigin;
cvar_t *broadsword_playflop;
cvar_t *broadsword_dontstopanim;
cvar_t *broadsword_waitforshot;
cvar_t *broadsword_smallbbox;
cvar_t *broadsword_extra1;
cvar_t *broadsword_extra2;
cvar_t *broadsword_effcorr;
cvar_t *broadsword_ragtobase;
cvar_t *broadsword_dircap;
// More bullshit needed for the proper modular renderer --eez
cvar_t *sv_mapname;
cvar_t *sv_mapChecksum;
cvar_t *se_language; // JKA
#ifdef JK2_MODE
cvar_t *sp_language; // JK2
#endif
cvar_t *com_buildScript;
cvar_t *r_environmentMapping;
cvar_t *r_screenshotJpegQuality;
PFNGLACTIVETEXTUREARBPROC qglActiveTextureARB;
PFNGLCLIENTACTIVETEXTUREARBPROC qglClientActiveTextureARB;
PFNGLMULTITEXCOORD2FARBPROC qglMultiTexCoord2fARB;
PFNGLCOMBINERPARAMETERFVNVPROC qglCombinerParameterfvNV;
PFNGLCOMBINERPARAMETERIVNVPROC qglCombinerParameterivNV;
PFNGLCOMBINERPARAMETERFNVPROC qglCombinerParameterfNV;
PFNGLCOMBINERPARAMETERINVPROC qglCombinerParameteriNV;
PFNGLCOMBINERINPUTNVPROC qglCombinerInputNV;
PFNGLCOMBINEROUTPUTNVPROC qglCombinerOutputNV;
PFNGLFINALCOMBINERINPUTNVPROC qglFinalCombinerInputNV;
PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC qglGetCombinerInputParameterfvNV;
PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC qglGetCombinerInputParameterivNV;
PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC qglGetCombinerOutputParameterfvNV;
PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC qglGetCombinerOutputParameterivNV;
PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC qglGetFinalCombinerInputParameterfvNV;
PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC qglGetFinalCombinerInputParameterivNV;
PFNGLPROGRAMSTRINGARBPROC qglProgramStringARB;
PFNGLBINDPROGRAMARBPROC qglBindProgramARB;
PFNGLDELETEPROGRAMSARBPROC qglDeleteProgramsARB;
PFNGLGENPROGRAMSARBPROC qglGenProgramsARB;
PFNGLPROGRAMENVPARAMETER4DARBPROC qglProgramEnvParameter4dARB;
PFNGLPROGRAMENVPARAMETER4DVARBPROC qglProgramEnvParameter4dvARB;
PFNGLPROGRAMENVPARAMETER4FARBPROC qglProgramEnvParameter4fARB;
PFNGLPROGRAMENVPARAMETER4FVARBPROC qglProgramEnvParameter4fvARB;
PFNGLPROGRAMLOCALPARAMETER4DARBPROC qglProgramLocalParameter4dARB;
PFNGLPROGRAMLOCALPARAMETER4DVARBPROC qglProgramLocalParameter4dvARB;
PFNGLPROGRAMLOCALPARAMETER4FARBPROC qglProgramLocalParameter4fARB;
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC qglProgramLocalParameter4fvARB;
PFNGLGETPROGRAMENVPARAMETERDVARBPROC qglGetProgramEnvParameterdvARB;
PFNGLGETPROGRAMENVPARAMETERFVARBPROC qglGetProgramEnvParameterfvARB;
PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC qglGetProgramLocalParameterdvARB;
PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC qglGetProgramLocalParameterfvARB;
PFNGLGETPROGRAMIVARBPROC qglGetProgramivARB;
PFNGLGETPROGRAMSTRINGARBPROC qglGetProgramStringARB;
PFNGLISPROGRAMARBPROC qglIsProgramARB;
PFNGLLOCKARRAYSEXTPROC qglLockArraysEXT;
PFNGLUNLOCKARRAYSEXTPROC qglUnlockArraysEXT;
bool g_bTextureRectangleHack = false;
void RE_SetLightStyle(int style, int color);
void R_Splash()
{
image_t *pImage = R_FindImageFile( "menu/splash", qfalse, qfalse, qfalse, GL_CLAMP);
if ( !pImage )
{
// Can't find the splash image so just clear to black
qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
qglClear( GL_COLOR_BUFFER_BIT );
}
else
{
extern void RB_SetGL2D (void);
RB_SetGL2D();
GL_Bind( pImage );
GL_State(GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO);
const int width = 640;
const int height = 480;
const float x1 = 320 - width / 2;
const float x2 = 320 + width / 2;
const float y1 = 240 - height / 2;
const float y2 = 240 + height / 2;
qglBegin (GL_TRIANGLE_STRIP);
qglTexCoord2f( 0, 0 );
qglVertex2f(x1, y1);
qglTexCoord2f( 1 , 0 );
qglVertex2f(x2, y1);
qglTexCoord2f( 0, 1 );
qglVertex2f(x1, y2);
qglTexCoord2f( 1, 1 );
qglVertex2f(x2, y2);
qglEnd();
}
ri.WIN_Present( &window );
}
/*
** GLW_CheckForExtension
Cannot use strstr directly to differentiate between (for eg) reg_combiners and reg_combiners2
*/
bool GL_CheckForExtension(const char *ext)
{
const char *ptr = Q_stristr( glConfig.extensions_string, ext );
if (ptr == NULL)
return false;
ptr += strlen(ext);
return ((*ptr == ' ') || (*ptr == '\0')); // verify it's complete string.
}
static void GLW_InitTextureCompression( void )
{
bool newer_tc, old_tc;
// Check for available tc methods.
newer_tc = GL_CheckForExtension("ARB_texture_compression") && GL_CheckForExtension("EXT_texture_compression_s3tc");
old_tc = GL_CheckForExtension("GL_S3_s3tc");
if ( old_tc )
{
Com_Printf ("...GL_S3_s3tc available\n" );
}
if ( newer_tc )
{
Com_Printf ("...GL_EXT_texture_compression_s3tc available\n" );
}
if ( !r_ext_compressed_textures->value )
{
// Compressed textures are off
glConfig.textureCompression = TC_NONE;
Com_Printf ("...ignoring texture compression\n" );
}
else if ( !old_tc && !newer_tc )
{
// Requesting texture compression, but no method found
glConfig.textureCompression = TC_NONE;
Com_Printf ("...no supported texture compression method found\n" );
Com_Printf (".....ignoring texture compression\n" );
}
else
{
// some form of supported texture compression is avaiable, so see if the user has a preference
if ( r_ext_preferred_tc_method->integer == TC_NONE )
{
// No preference, so pick the best
if ( newer_tc )
{
Com_Printf ("...no tc preference specified\n" );
Com_Printf (".....using GL_EXT_texture_compression_s3tc\n" );
glConfig.textureCompression = TC_S3TC_DXT;
}
else
{
Com_Printf ("...no tc preference specified\n" );
Com_Printf (".....using GL_S3_s3tc\n" );
glConfig.textureCompression = TC_S3TC;
}
}
else
{
// User has specified a preference, now see if this request can be honored
if ( old_tc && newer_tc )
{
// both are avaiable, so we can use the desired tc method
if ( r_ext_preferred_tc_method->integer == TC_S3TC )
{
Com_Printf ("...using preferred tc method, GL_S3_s3tc\n" );
glConfig.textureCompression = TC_S3TC;
}
else
{
Com_Printf ("...using preferred tc method, GL_EXT_texture_compression_s3tc\n" );
glConfig.textureCompression = TC_S3TC_DXT;
}
}
else
{
// Both methods are not available, so this gets trickier
if ( r_ext_preferred_tc_method->integer == TC_S3TC )
{
// Preferring to user older compression
if ( old_tc )
{
Com_Printf ("...using GL_S3_s3tc\n" );
glConfig.textureCompression = TC_S3TC;
}
else
{
// Drat, preference can't be honored
Com_Printf ("...preferred tc method, GL_S3_s3tc not available\n" );
Com_Printf (".....falling back to GL_EXT_texture_compression_s3tc\n" );
glConfig.textureCompression = TC_S3TC_DXT;
}
}
else
{
// Preferring to user newer compression
if ( newer_tc )
{
Com_Printf ("...using GL_EXT_texture_compression_s3tc\n" );
glConfig.textureCompression = TC_S3TC_DXT;
}
else
{
// Drat, preference can't be honored
Com_Printf ("...preferred tc method, GL_EXT_texture_compression_s3tc not available\n" );
Com_Printf (".....falling back to GL_S3_s3tc\n" );
glConfig.textureCompression = TC_S3TC;
}
}
}
}
}
}
/*
===============
GLimp_InitExtensions
===============
*/
extern bool g_bDynamicGlowSupported;
static void GLimp_InitExtensions( void )
{
if ( !r_allowExtensions->integer )
{
Com_Printf ("*** IGNORING OPENGL EXTENSIONS ***\n" );
g_bDynamicGlowSupported = false;
ri.Cvar_Set( "r_DynamicGlow","0" );
return;
}
Com_Printf ("Initializing OpenGL extensions\n" );
// Select our tc scheme
GLW_InitTextureCompression();
// GL_EXT_texture_env_add
glConfig.textureEnvAddAvailable = qfalse;
if ( GL_CheckForExtension( "EXT_texture_env_add" ) )
{
if ( r_ext_texture_env_add->integer )
{
glConfig.textureEnvAddAvailable = qtrue;
Com_Printf ("...using GL_EXT_texture_env_add\n" );
}
else
{
glConfig.textureEnvAddAvailable = qfalse;
Com_Printf ("...ignoring GL_EXT_texture_env_add\n" );
}
}
else
{
Com_Printf ("...GL_EXT_texture_env_add not found\n" );
}
// GL_EXT_texture_filter_anisotropic
glConfig.maxTextureFilterAnisotropy = 0;
if ( GL_CheckForExtension( "EXT_texture_filter_anisotropic" ) )
{
qglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.maxTextureFilterAnisotropy );
Com_Printf ("...GL_EXT_texture_filter_anisotropic available\n" );
if ( r_ext_texture_filter_anisotropic->integer > 1 )
{
Com_Printf ("...using GL_EXT_texture_filter_anisotropic\n" );
}
else
{
Com_Printf ("...ignoring GL_EXT_texture_filter_anisotropic\n" );
}
ri.Cvar_SetValue( "r_ext_texture_filter_anisotropic_avail", glConfig.maxTextureFilterAnisotropy );
if ( r_ext_texture_filter_anisotropic->value > glConfig.maxTextureFilterAnisotropy )
{
ri.Cvar_SetValue( "r_ext_texture_filter_anisotropic_avail", glConfig.maxTextureFilterAnisotropy );
}
}
else
{
Com_Printf ("...GL_EXT_texture_filter_anisotropic not found\n" );
ri.Cvar_Set( "r_ext_texture_filter_anisotropic_avail", "0" );
}
// GL_EXT_clamp_to_edge
glConfig.clampToEdgeAvailable = qtrue;
Com_Printf ("...using GL_EXT_texture_edge_clamp\n" );
// GL_ARB_multitexture
qglMultiTexCoord2fARB = NULL;
qglActiveTextureARB = NULL;
qglClientActiveTextureARB = NULL;
if ( GL_CheckForExtension( "GL_ARB_multitexture" ) )
{
if ( r_ext_multitexture->integer )
{
qglMultiTexCoord2fARB = ( PFNGLMULTITEXCOORD2FARBPROC ) ri.GL_GetProcAddress( "glMultiTexCoord2fARB" );
qglActiveTextureARB = ( PFNGLACTIVETEXTUREARBPROC ) ri.GL_GetProcAddress( "glActiveTextureARB" );
qglClientActiveTextureARB = ( PFNGLCLIENTACTIVETEXTUREARBPROC ) ri.GL_GetProcAddress( "glClientActiveTextureARB" );
if ( qglActiveTextureARB )
{
qglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.maxActiveTextures );
if ( glConfig.maxActiveTextures > 1 )
{
Com_Printf ("...using GL_ARB_multitexture\n" );
}
else
{
qglMultiTexCoord2fARB = NULL;
qglActiveTextureARB = NULL;
qglClientActiveTextureARB = NULL;
Com_Printf ("...not using GL_ARB_multitexture, < 2 texture units\n" );
}
}
}
else
{
Com_Printf ("...ignoring GL_ARB_multitexture\n" );
}
}
else
{
Com_Printf ("...GL_ARB_multitexture not found\n" );
}
// GL_EXT_compiled_vertex_array
qglLockArraysEXT = NULL;
qglUnlockArraysEXT = NULL;
if ( GL_CheckForExtension( "GL_EXT_compiled_vertex_array" ) )
{
if ( r_ext_compiled_vertex_array->integer )
{
Com_Printf ("...using GL_EXT_compiled_vertex_array\n" );
qglLockArraysEXT = ( PFNGLLOCKARRAYSEXTPROC ) ri.GL_GetProcAddress( "glLockArraysEXT" );
qglUnlockArraysEXT = ( PFNGLUNLOCKARRAYSEXTPROC ) ri.GL_GetProcAddress( "glUnlockArraysEXT" );
if (!qglLockArraysEXT || !qglUnlockArraysEXT) {
Com_Error (ERR_FATAL, "bad getprocaddress");
}
}
else
{
Com_Printf ("...ignoring GL_EXT_compiled_vertex_array\n" );
}
}
else
{
Com_Printf ("...GL_EXT_compiled_vertex_array not found\n" );
}
bool bNVRegisterCombiners = false;
// Register Combiners.
if ( GL_CheckForExtension( "GL_NV_register_combiners" ) )
{
// NOTE: This extension requires multitexture support (over 2 units).
if ( glConfig.maxActiveTextures >= 2 )
{
bNVRegisterCombiners = true;
// Register Combiners function pointer address load. - AReis
// NOTE: VV guys will _definetly_ not be able to use regcoms. Pixel Shaders are just as good though :-)
// NOTE: Also, this is an nVidia specific extension (of course), so fragment shaders would serve the same purpose
// if we needed some kind of fragment/pixel manipulation support.
qglCombinerParameterfvNV = (PFNGLCOMBINERPARAMETERFVNVPROC)ri.GL_GetProcAddress( "glCombinerParameterfvNV" );
qglCombinerParameterivNV = (PFNGLCOMBINERPARAMETERIVNVPROC)ri.GL_GetProcAddress( "glCombinerParameterivNV" );
qglCombinerParameterfNV = (PFNGLCOMBINERPARAMETERFNVPROC)ri.GL_GetProcAddress( "glCombinerParameterfNV" );
qglCombinerParameteriNV = (PFNGLCOMBINERPARAMETERINVPROC)ri.GL_GetProcAddress( "glCombinerParameteriNV" );
qglCombinerInputNV = (PFNGLCOMBINERINPUTNVPROC)ri.GL_GetProcAddress( "glCombinerInputNV" );
qglCombinerOutputNV = (PFNGLCOMBINEROUTPUTNVPROC)ri.GL_GetProcAddress( "glCombinerOutputNV" );
qglFinalCombinerInputNV = (PFNGLFINALCOMBINERINPUTNVPROC)ri.GL_GetProcAddress( "glFinalCombinerInputNV" );
qglGetCombinerInputParameterfvNV = (PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC)ri.GL_GetProcAddress( "glGetCombinerInputParameterfvNV" );
qglGetCombinerInputParameterivNV = (PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC)ri.GL_GetProcAddress( "glGetCombinerInputParameterivNV" );
qglGetCombinerOutputParameterfvNV = (PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC)ri.GL_GetProcAddress( "glGetCombinerOutputParameterfvNV" );
qglGetCombinerOutputParameterivNV = (PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC)ri.GL_GetProcAddress( "glGetCombinerOutputParameterivNV" );
qglGetFinalCombinerInputParameterfvNV = (PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC)ri.GL_GetProcAddress( "glGetFinalCombinerInputParameterfvNV" );
qglGetFinalCombinerInputParameterivNV = (PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC)ri.GL_GetProcAddress( "glGetFinalCombinerInputParameterivNV" );
// Validate the functions we need.
if ( !qglCombinerParameterfvNV || !qglCombinerParameterivNV || !qglCombinerParameterfNV || !qglCombinerParameteriNV || !qglCombinerInputNV ||
!qglCombinerOutputNV || !qglFinalCombinerInputNV || !qglGetCombinerInputParameterfvNV || !qglGetCombinerInputParameterivNV ||
!qglGetCombinerOutputParameterfvNV || !qglGetCombinerOutputParameterivNV || !qglGetFinalCombinerInputParameterfvNV || !qglGetFinalCombinerInputParameterivNV )
{
bNVRegisterCombiners = false;
qglCombinerParameterfvNV = NULL;
qglCombinerParameteriNV = NULL;
Com_Printf ("...GL_NV_register_combiners failed\n" );
}
}
else
{
bNVRegisterCombiners = false;
Com_Printf ("...ignoring GL_NV_register_combiners\n" );
}
}
else
{
bNVRegisterCombiners = false;
Com_Printf ("...GL_NV_register_combiners not found\n" );
}
// NOTE: Vertex and Fragment Programs are very dependant on each other - this is actually a
// good thing! So, just check to see which we support (one or the other) and load the shared
// function pointers. ARB rocks!
// Vertex Programs.
bool bARBVertexProgram = false;
if ( GL_CheckForExtension( "GL_ARB_vertex_program" ) )
{
bARBVertexProgram = true;
}
else
{
bARBVertexProgram = false;
Com_Printf ("...GL_ARB_vertex_program not found\n" );
}
// Fragment Programs.
bool bARBFragmentProgram = false;
if ( GL_CheckForExtension( "GL_ARB_fragment_program" ) )
{
bARBFragmentProgram = true;
}
else
{
bARBFragmentProgram = false;
Com_Printf ("...GL_ARB_fragment_program not found\n" );
}
// If we support one or the other, load the shared function pointers.
if ( bARBVertexProgram || bARBFragmentProgram )
{
qglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) ri.GL_GetProcAddress("glProgramStringARB");
qglBindProgramARB = (PFNGLBINDPROGRAMARBPROC) ri.GL_GetProcAddress("glBindProgramARB");
qglDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) ri.GL_GetProcAddress("glDeleteProgramsARB");
qglGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) ri.GL_GetProcAddress("glGenProgramsARB");
qglProgramEnvParameter4dARB = (PFNGLPROGRAMENVPARAMETER4DARBPROC) ri.GL_GetProcAddress("glProgramEnvParameter4dARB");
qglProgramEnvParameter4dvARB = (PFNGLPROGRAMENVPARAMETER4DVARBPROC) ri.GL_GetProcAddress("glProgramEnvParameter4dvARB");
qglProgramEnvParameter4fARB = (PFNGLPROGRAMENVPARAMETER4FARBPROC) ri.GL_GetProcAddress("glProgramEnvParameter4fARB");
qglProgramEnvParameter4fvARB = (PFNGLPROGRAMENVPARAMETER4FVARBPROC) ri.GL_GetProcAddress("glProgramEnvParameter4fvARB");
qglProgramLocalParameter4dARB = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) ri.GL_GetProcAddress("glProgramLocalParameter4dARB");
qglProgramLocalParameter4dvARB = (PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) ri.GL_GetProcAddress("glProgramLocalParameter4dvARB");
qglProgramLocalParameter4fARB = (PFNGLPROGRAMLOCALPARAMETER4FARBPROC) ri.GL_GetProcAddress("glProgramLocalParameter4fARB");
qglProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) ri.GL_GetProcAddress("glProgramLocalParameter4fvARB");
qglGetProgramEnvParameterdvARB = (PFNGLGETPROGRAMENVPARAMETERDVARBPROC) ri.GL_GetProcAddress("glGetProgramEnvParameterdvARB");
qglGetProgramEnvParameterfvARB = (PFNGLGETPROGRAMENVPARAMETERFVARBPROC) ri.GL_GetProcAddress("glGetProgramEnvParameterfvARB");
qglGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) ri.GL_GetProcAddress("glGetProgramLocalParameterdvARB");
qglGetProgramLocalParameterfvARB = (PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) ri.GL_GetProcAddress("glGetProgramLocalParameterfvARB");
qglGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) ri.GL_GetProcAddress("glGetProgramivARB");
qglGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC) ri.GL_GetProcAddress("glGetProgramStringARB");
qglIsProgramARB = (PFNGLISPROGRAMARBPROC) ri.GL_GetProcAddress("glIsProgramARB");
// Validate the functions we need.
if ( !qglProgramStringARB || !qglBindProgramARB || !qglDeleteProgramsARB || !qglGenProgramsARB ||
!qglProgramEnvParameter4dARB || !qglProgramEnvParameter4dvARB || !qglProgramEnvParameter4fARB ||
!qglProgramEnvParameter4fvARB || !qglProgramLocalParameter4dARB || !qglProgramLocalParameter4dvARB ||
!qglProgramLocalParameter4fARB || !qglProgramLocalParameter4fvARB || !qglGetProgramEnvParameterdvARB ||
!qglGetProgramEnvParameterfvARB || !qglGetProgramLocalParameterdvARB || !qglGetProgramLocalParameterfvARB ||
!qglGetProgramivARB || !qglGetProgramStringARB || !qglIsProgramARB )
{
bARBVertexProgram = false;
bARBFragmentProgram = false;
qglGenProgramsARB = NULL; //clear ptrs that get checked
qglProgramEnvParameter4fARB = NULL;
Com_Printf ("...ignoring GL_ARB_vertex_program\n" );
Com_Printf ("...ignoring GL_ARB_fragment_program\n" );
}
}
// Figure out which texture rectangle extension to use.
bool bTexRectSupported = false;
if ( Q_stricmpn( glConfig.vendor_string, "ATI Technologies",16 )==0
&& Q_stricmpn( glConfig.version_string, "1.3.3",5 )==0
&& glConfig.version_string[5] < '9' ) //1.3.34 and 1.3.37 and 1.3.38 are broken for sure, 1.3.39 is not
{
g_bTextureRectangleHack = true;
}
if ( GL_CheckForExtension( "GL_NV_texture_rectangle" ) || GL_CheckForExtension( "GL_EXT_texture_rectangle" ) )
{
bTexRectSupported = true;
}
// Find out how many general combiners they have.
#define GL_MAX_GENERAL_COMBINERS_NV 0x854D
GLint iNumGeneralCombiners = 0;
if(bNVRegisterCombiners)
qglGetIntegerv( GL_MAX_GENERAL_COMBINERS_NV, &iNumGeneralCombiners );
// Only allow dynamic glows/flares if they have the hardware
if ( bTexRectSupported && bARBVertexProgram && qglActiveTextureARB && glConfig.maxActiveTextures >= 4 &&
( ( bNVRegisterCombiners && iNumGeneralCombiners >= 2 ) || bARBFragmentProgram ) )
{
g_bDynamicGlowSupported = true;
// this would overwrite any achived setting gwg
// ri.Cvar_Set( "r_DynamicGlow", "1" );
}
else
{
g_bDynamicGlowSupported = false;
ri.Cvar_Set( "r_DynamicGlow","0" );
}
}
/*
** InitOpenGL
**
** This function is responsible for initializing a valid OpenGL subsystem. This
** is done by calling GLimp_Init (which gives us a working OGL subsystem) then
** setting variables, checking GL constants, and reporting the gfx system config
** to the user.
*/
static void InitOpenGL( void )
{
//
// initialize OS specific portions of the renderer
//
// GLimp_Init directly or indirectly references the following cvars:
// - r_fullscreen
// - r_mode
// - r_(color|depth|stencil)bits
// - r_ignorehwgamma
// - r_gamma
//
if ( glConfig.vidWidth == 0 )
{
windowDesc_t windowDesc = { GRAPHICS_API_OPENGL };
memset(&glConfig, 0, sizeof(glConfig));
window = ri.WIN_Init(&windowDesc, &glConfig);
// get our config strings
glConfig.vendor_string = (const char *)qglGetString (GL_VENDOR);
glConfig.renderer_string = (const char *)qglGetString (GL_RENDERER);
glConfig.version_string = (const char *)qglGetString (GL_VERSION);
glConfig.extensions_string = (const char *)qglGetString (GL_EXTENSIONS);
// OpenGL driver constants
qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glConfig.maxTextureSize );
// stubbed or broken drivers may have reported 0...
glConfig.maxTextureSize = Q_max(0, glConfig.maxTextureSize);
// initialize extensions
GLimp_InitExtensions( );
// set default state
GL_SetDefaultState();
R_Splash(); //get something on screen asap
}
else
{
// set default state
GL_SetDefaultState();
}
}
/*
==================
GL_CheckErrors
==================
*/
void GL_CheckErrors( void ) {
int err;
char s[64];
err = qglGetError();
if ( err == GL_NO_ERROR ) {
return;
}
if ( r_ignoreGLErrors->integer ) {
return;
}
switch( err ) {
case GL_INVALID_ENUM:
strcpy( s, "GL_INVALID_ENUM" );
break;
case GL_INVALID_VALUE:
strcpy( s, "GL_INVALID_VALUE" );
break;
case GL_INVALID_OPERATION:
strcpy( s, "GL_INVALID_OPERATION" );
break;
case GL_STACK_OVERFLOW:
strcpy( s, "GL_STACK_OVERFLOW" );
break;
case GL_STACK_UNDERFLOW:
strcpy( s, "GL_STACK_UNDERFLOW" );
break;
case GL_OUT_OF_MEMORY:
strcpy( s, "GL_OUT_OF_MEMORY" );
break;
default:
Com_sprintf( s, sizeof(s), "%i", err);
break;
}
Com_Error( ERR_FATAL, "GL_CheckErrors: %s", s );
}
/*
==============================================================================
SCREEN SHOTS
==============================================================================
*/
/*
==================
RB_ReadPixels
Reads an image but takes care of alignment issues for reading RGB images.
Reads a minimum offset for where the RGB data starts in the image from
integer stored at pointer offset. When the function has returned the actual
offset was written back to address offset. This address will always have an
alignment of packAlign to ensure efficient copying.
Stores the length of padding after a line of pixels to address padlen
Return value must be freed with Hunk_FreeTempMemory()
==================
*/
byte *RB_ReadPixels(int x, int y, int width, int height, size_t *offset, int *padlen)
{
byte *buffer, *bufstart;
int padwidth, linelen;
GLint packAlign;
qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);
linelen = width * 3;
padwidth = PAD(linelen, packAlign);
// Allocate a few more bytes so that we can choose an alignment we like
buffer = (byte *)ri.Z_Malloc(padwidth * height + *offset + packAlign - 1, TAG_TEMP_WORKSPACE, qfalse, 4);
bufstart = (byte *)PADP((intptr_t) buffer + *offset, packAlign);
qglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, bufstart);
*offset = bufstart - buffer;
*padlen = padwidth - linelen;
return buffer;
}
/*
==================
R_TakeScreenshot
==================
*/
void R_TakeScreenshot( int x, int y, int width, int height, char *fileName ) {
byte *allbuf, *buffer;
byte *srcptr, *destptr;
byte *endline, *endmem;
byte temp;
int linelen, padlen;
size_t offset = 18, memcount;
allbuf = RB_ReadPixels(x, y, width, height, &offset, &padlen);
buffer = allbuf + offset - 18;
Com_Memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = width & 255;
buffer[13] = width >> 8;
buffer[14] = height & 255;
buffer[15] = height >> 8;
buffer[16] = 24; // pixel size
// swap rgb to bgr and remove padding from line endings
linelen = width * 3;
srcptr = destptr = allbuf + offset;
endmem = srcptr + (linelen + padlen) * height;
while(srcptr < endmem)
{
endline = srcptr + linelen;
while(srcptr < endline)
{
temp = srcptr[0];
*destptr++ = srcptr[2];
*destptr++ = srcptr[1];
*destptr++ = temp;
srcptr += 3;
}
// Skip the pad
srcptr += padlen;
}
memcount = linelen * height;
// gamma correct
if(glConfig.deviceSupportsGamma)
R_GammaCorrect(allbuf + offset, memcount);
ri.FS_WriteFile(fileName, buffer, memcount + 18);
ri.Z_Free(allbuf);
}
/*
==================
R_TakeScreenshotPNG
==================
*/
void R_TakeScreenshotPNG( int x, int y, int width, int height, char *fileName ) {
byte *buffer=NULL;
size_t offset=0;
int padlen=0;
buffer = RB_ReadPixels( x, y, width, height, &offset, &padlen );
RE_SavePNG( fileName, buffer, width, height, 3 );
ri.Z_Free( buffer );
}
/*
==================
R_TakeScreenshotJPEG
==================
*/
void R_TakeScreenshotJPEG( int x, int y, int width, int height, char *fileName ) {
byte *buffer;
size_t offset = 0, memcount;
int padlen;
buffer = RB_ReadPixels(x, y, width, height, &offset, &padlen);
memcount = (width * 3 + padlen) * height;
// gamma correct
if(glConfig.deviceSupportsGamma)
R_GammaCorrect(buffer + offset, memcount);
RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, buffer + offset, padlen);
ri.Z_Free(buffer);
}
/*
==================
R_ScreenshotFilename
==================
*/
void R_ScreenshotFilename( char *buf, int bufSize, const char *ext ) {
time_t rawtime;
char timeStr[32] = {0}; // should really only reach ~19 chars
time( &rawtime );
strftime( timeStr, sizeof( timeStr ), "%Y-%m-%d_%H-%M-%S", localtime( &rawtime ) ); // or gmtime
Com_sprintf( buf, bufSize, "screenshots/shot%s%s", timeStr, ext );
}
/*
====================
R_LevelShot
levelshots are specialized 256*256 thumbnails for
the menu system, sampled down from full screen distorted images
====================
*/
#define LEVELSHOTSIZE 256
static void R_LevelShot( void ) {
char checkname[MAX_OSPATH];
byte *buffer;
byte *source, *allsource;
byte *src, *dst;
size_t offset = 0;
int padlen;
int x, y;
int r, g, b;
float xScale, yScale;
int xx, yy;
Com_sprintf( checkname, sizeof(checkname), "levelshots/%s.tga", tr.world->baseName );
allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &padlen);
source = allsource + offset;
buffer = (byte *)ri.Z_Malloc(LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18, TAG_TEMP_WORKSPACE, qfalse, 4);
Com_Memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = LEVELSHOTSIZE & 255;
buffer[13] = LEVELSHOTSIZE >> 8;
buffer[14] = LEVELSHOTSIZE & 255;
buffer[15] = LEVELSHOTSIZE >> 8;
buffer[16] = 24; // pixel size
// resample from source
xScale = glConfig.vidWidth / (4.0*LEVELSHOTSIZE);
yScale = glConfig.vidHeight / (3.0*LEVELSHOTSIZE);
for ( y = 0 ; y < LEVELSHOTSIZE ; y++ ) {
for ( x = 0 ; x < LEVELSHOTSIZE ; x++ ) {
r = g = b = 0;
for ( yy = 0 ; yy < 3 ; yy++ ) {
for ( xx = 0 ; xx < 4 ; xx++ ) {
src = source + 3 * ( glConfig.vidWidth * (int)( (y*3+yy)*yScale ) + (int)( (x*4+xx)*xScale ) );
r += src[0];
g += src[1];
b += src[2];
}
}
dst = buffer + 18 + 3 * ( y * LEVELSHOTSIZE + x );
dst[0] = b / 12;
dst[1] = g / 12;
dst[2] = r / 12;
}
}
// gamma correct
if ( ( tr.overbrightBits > 0 ) && glConfig.deviceSupportsGamma ) {
R_GammaCorrect( buffer + 18, LEVELSHOTSIZE * LEVELSHOTSIZE * 3 );
}