/
tr_init.c
883 lines (718 loc) · 24 KB
/
tr_init.c
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
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena 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.
Quake III Arena 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 Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
$Id: tr_init.c,v 1.24 2007-10-14 17:54:12 himan Exp $
*/
// tr_init.c -- functions that are not called every frame
#include "quakedef.h"
#include "gl_model.h"
#include "gl_local.h"
#ifdef GLSL
#include "gl_shader.h"
#endif // GLSL
#if defined(_WIN32) || defined(__linux__) || defined(__FreeBSD__)
#include "tr_types.h"
#endif // _WIN32 || __linux__ || __FreeBSD__
glconfig_t glConfig;
//glstate_t glState;
//
// latched variables that can only change over a restart
//
cvar_t r_glDriver = { "vid_glDriver", OPENGL_DRIVER_NAME, CVAR_LATCH };
cvar_t r_allowExtensions = { "vid_allowExtensions", "1", CVAR_LATCH };
//cvar_t r_texturebits = { "vid_texturebits", "0", CVAR_LATCH };
cvar_t r_colorbits = { "vid_colorbits", "0", CVAR_LATCH };
cvar_t r_stereo = { "vid_stereo", "0", CVAR_LATCH };
#ifdef __linux__
cvar_t r_stencilbits = { "vid_stencilbits", "0", CVAR_LATCH };
#else
cvar_t r_stencilbits = { "vid_stencilbits", "8", CVAR_LATCH };
#endif
cvar_t r_depthbits = { "vid_depthbits", "0", CVAR_LATCH };
//cvar_t r_overBrightBits= { "vid_overBrightBits", "1", CVAR_LATCH };
cvar_t r_mode = { "vid_mode", "3", CVAR_LATCH };
cvar_t r_fullscreen = { "vid_fullscreen", "1", CVAR_LATCH };
cvar_t r_customwidth = { "vid_customwidth", "1600", CVAR_LATCH };
cvar_t r_customheight = { "vid_customheight", "1024", CVAR_LATCH };
cvar_t r_customaspect = { "vid_customaspect", "1", CVAR_LATCH }; // qqshka: unused even in q3, but I keep cvar, just do not register it
cvar_t r_displayRefresh = { "vid_displayfrequency", "0", CVAR_LATCH };
cvar_t vid_borderless = { "vid_borderless", "0", CVAR_LATCH };
//cvar_t r_intensity = { "vid_intensity", "1", CVAR_LATCH };
//
// archived variables that can change at any time
//
cvar_t r_ignoreGLErrors = { "vid_ignoreGLErrors", "1", CVAR_SILENT };
//cvar_t r_textureMode = { "vid_textureMode", "GL_LINEAR_MIPMAP_NEAREST"};
cvar_t r_swapInterval = { "vid_vsync", "0", CVAR_SILENT };
#ifdef __MACOS__
//cvar_t r_gamma = { "vid_gamma", "1.2", CVAR_SILENT };
#else
//cvar_t r_gamma = { "vid_gamma", "1", CVAR_SILENT };
#endif
void OnChange_vid_pos(cvar_t *var, char *string, qbool *cancel);
cvar_t vid_xpos = { "vid_xpos", "3", CVAR_SILENT, OnChange_vid_pos};
cvar_t vid_ypos = { "vid_ypos", "22", CVAR_SILENT, OnChange_vid_pos};
cvar_t vid_minpos = { "vid_minpos", "0", CVAR_SILENT};
void OnChange_r_con_xxx (cvar_t *var, char *string, qbool *cancel);
void OnChange_r_conaspect (cvar_t *var, char *string, qbool *cancel);
cvar_t r_conwidth = { "vid_conwidth", "640", CVAR_NO_RESET | CVAR_SILENT, OnChange_r_con_xxx };
cvar_t r_conheight = { "vid_conheight", "0", CVAR_NO_RESET | CVAR_SILENT, OnChange_r_con_xxx }; // default is 0, so i can sort out is user specify conheight on cmd line or something
cvar_t r_conaspect = { "vid_conaspect", "", CVAR_SILENT, OnChange_r_conaspect }; // auto-adjusts vid_conheight
cvar_t vid_ref = { "vid_ref", "gl", CVAR_ROM | CVAR_SILENT };
cvar_t vid_hwgammacontrol = { "vid_hwgammacontrol", "2", CVAR_SILENT };
#ifdef _WIN32
cvar_t vid_flashonactivity = { "vid_flashonactivity", "1", CVAR_SILENT };
cvar_t _windowed_mouse = { "_windowed_mouse", "1", CVAR_SILENT }; // actually that more like input, but input registered after video in windows
#endif
cvar_t r_verbose = { "vid_verbose", "0", CVAR_SILENT };
//cvar_t r_logFile = { "vid_logFile", "0", CVAR_CHEAT | CVAR_SILENT};
// print gl extension in /gfxinfo
cvar_t r_showextensions = { "vid_showextensions", "0", CVAR_SILENT };
// aspect ratio for widescreens
void OnChange_vid_wideaspect (cvar_t *var, char *string, qbool *cancel);
cvar_t vid_wideaspect = {"vid_wideaspect", "0", CVAR_NO_RESET | CVAR_SILENT, OnChange_vid_wideaspect};
cvar_t vid_wideaspect_verbose = {"vid_wideaspect_verbose", "1", CVAR_SILENT };
void ( APIENTRY * qglMultiTexCoord2fARB )( GLenum texture, GLfloat s, GLfloat t );
void ( APIENTRY * qglActiveTextureARB )( GLenum texture );
void ( APIENTRY * qglClientActiveTextureARB )( GLenum texture );
static void GfxInfo_f( void );
static void AssertCvarRange( cvar_t *cv, float minVal, float maxVal, qbool shouldBeIntegral )
{
if ( shouldBeIntegral )
{
if ( ( int ) cv->value != cv->integer )
{
ST_Printf( PRINT_WARNING, "WARNING: cvar '%s' must be integral (%f)\n", cv->name, cv->value );
Cvar_SetValue( cv, cv->integer );
}
}
if ( cv->value < minVal )
{
ST_Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f < %f)\n", cv->name, cv->value, minVal );
Cvar_SetValue( cv, minVal );
}
else if ( cv->value > maxVal )
{
ST_Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f > %f)\n", cv->name, cv->value, maxVal );
Cvar_SetValue( cv, maxVal );
}
}
/*
** 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 )
{
char renderer_buffer[1024];
//
// initialize OS specific portions of the renderer
//
// GLimp_Init directly or indirectly references the following cvars:
// - r_fullscreen
// - r_glDriver
// - r_mode
// - r_(color|depth|stencil)bits
// - r_ignorehwgamma
// - r_gamma
//
if ( glConfig.vidWidth == 0 )
{
GLint temp;
GLimp_Init();
strlcpy( renderer_buffer, (const char*)glConfig.renderer_string , sizeof (renderer_buffer) );
Q_strlwr( renderer_buffer );
// OpenGL driver constants
glGetIntegerv( GL_MAX_TEXTURE_SIZE, &temp );
glConfig.maxTextureSize = temp;
// stubbed or broken drivers may have reported 0...
if ( glConfig.maxTextureSize <= 0 )
{
glConfig.maxTextureSize = 0;
}
}
// print info
if ( !host_initialized || r_verbose.integer )
GfxInfo_f();
// set default state
GL_SetDefaultState();
}
/*
==================
GL_CheckErrors
==================
*/
void GL_CheckErrors( void ) {
int err;
char s[64];
err = glGetError();
if ( err == GL_NO_ERROR ) {
return;
}
if ( r_ignoreGLErrors.integer ) {
return;
}
switch( err ) {
case GL_INVALID_ENUM:
strlcpy( s, "GL_INVALID_ENUM", sizeof( s ) );
break;
case GL_INVALID_VALUE:
strlcpy( s, "GL_INVALID_VALUE", sizeof( s ) );
break;
case GL_INVALID_OPERATION:
strlcpy( s, "GL_INVALID_OPERATION", sizeof( s ) );
break;
case GL_STACK_OVERFLOW:
strlcpy( s, "GL_STACK_OVERFLOW", sizeof( s ) );
break;
case GL_STACK_UNDERFLOW:
strlcpy( s, "GL_STACK_UNDERFLOW", sizeof( s ) );
break;
case GL_OUT_OF_MEMORY:
strlcpy( s, "GL_OUT_OF_MEMORY", sizeof( s ) );
break;
default:
snprintf( s, sizeof(s), "%i", err);
break;
}
ST_Printf( PRINT_ERR_FATAL, "GL_CheckErrors: %s", s );
}
/*
** R_GetModeInfo
*/
typedef struct vidmode_s
{
const char *description;
int width, height;
float pixelAspect; // pixel width / height
} vidmode_t;
vidmode_t r_vidModes[] =
{
{ "Mode 0: 320x240", 320, 240, 1 },
{ "Mode 1: 400x300", 400, 300, 1 },
{ "Mode 2: 512x384", 512, 384, 1 },
{ "Mode 3: 640x480", 640, 480, 1 },
{ "Mode 4: 800x600", 800, 600, 1 },
{ "Mode 5: 960x720", 960, 720, 1 },
{ "Mode 6: 1024x768", 1024, 768, 1 },
{ "Mode 7: 1152x864", 1152, 864, 1 },
{ "Mode 8: 1280x1024", 1280, 1024, 1 },
{ "Mode 9: 1600x1200", 1600, 1200, 1 },
{ "Mode 10: 2048x1536", 2048, 1536, 1 },
{ "Mode 11: 1920x1200", 1920, 1200, 1 },
{ "Mode 12: 1920x1080", 1920, 1080, 1 },
{ "Mode 13: 1680x1050", 1680, 1050, 1 },
{ "Mode 14: 1440x900", 1440, 900, 1 },
{ "Mode 15: 1280x800", 1280, 800, 1 }
// { "Mode 11: 856x480 (wide)",856, 480, 1 }
};
static int s_numVidModes = ( sizeof( r_vidModes ) / sizeof( r_vidModes[0] ) );
qbool R_GetModeInfo( int *width, int *height, float *windowAspect, int mode ) {
vidmode_t *vm;
if ( mode < -1 ) {
return false;
}
if ( mode >= s_numVidModes ) {
return false;
}
if ( mode == -1 ) {
*width = r_customwidth.integer;
*height = r_customheight.integer;
*windowAspect = r_customaspect.value;
return true;
}
vm = &r_vidModes[mode];
*width = vm->width;
*height = vm->height;
*windowAspect = (float)vm->width / ( vm->height * vm->pixelAspect );
return true;
}
// search mode which match params, in r_vidModes[]
// return -1 if not found and from 0 to s_numVidModes if found
int R_MatchMode( int width, int height )
{
int i;
for ( i = 0; i < s_numVidModes && (width || height); i++ )
if ( (!width || width == r_vidModes[i].width) && (!height || height == r_vidModes[i].height) )
return i; // found
return -1; // not found
}
/*
** R_ModeList_f
*/
static void R_ModeList_f( void )
{
int i;
ST_Printf( PRINT_ALL, "\n" );
for ( i = 0; i < s_numVidModes; i++ )
{
ST_Printf( PRINT_ALL, "%s\n", r_vidModes[i].description );
}
ST_Printf( PRINT_ALL, "\n" );
}
//============================================================================
int nonwideconheight = 0; // Store original conheight if vid_wideaspect is used
/// Parses the value vid_conaspect cvar.
///
/// \return true if vid_conaspect contained some valid ratio
qbool VID_r_con_aspect_get(int *x, int *y)
{
char *var = r_conaspect.string;
char buf[16];
int x_, y_;
char *colon;
strlcpy(buf, var, sizeof(buf));
colon = strchr(buf, ':');
if (colon) {
*colon = '\0';
x_ = Q_atoi(var);
y_ = Q_atoi(colon+1);
if (x_ > 0 && y_ > 0) {
*x = x_;
*y = y_;
return true;
}
}
return false;
}
/// Recalculates height if vid_conaspect is set.
///
/// \return true if recalculation was done
qbool VID_r_con_height_adjust(int width, int *height)
{
int x, y;
if (VID_r_con_aspect_get(&x, &y)) {
*height = width * y / x;
return true;
}
else {
return false;
}
}
void VID_r_con_height_apply(int height)
{
if (glConfig.vidHeight)
vid.height = vid.conheight = height = min(glConfig.vidHeight, height);
else
vid.conheight = height; // issued from cmd line ? then do not set vid.height because code may relay what it 0
Cvar_SetValue(&r_conheight, (float)height);
}
void OnChange_r_conaspect(cvar_t *var, char *string, qbool *cancel) {
int height;
Cvar_Set(var, string); // just accept the new value
if (VID_r_con_height_adjust(r_conwidth.integer, &height)) {
VID_r_con_height_apply(height);
}
}
void OnChange_r_con_xxx (cvar_t *var, char *string, qbool *cancel) {
float scale = 1;
if (var == &r_conwidth) {
int width = Q_atoi(string);
int height;
width = max(320, width);
//width &= 0xfff8; // make it a multiple of eight
if (glConfig.vidWidth)
vid.width = vid.conwidth = width = min(glConfig.vidWidth, width);
else
vid.conwidth = width; // issued from cmd line ? then do not set vid.width because code may relay what it 0
Cvar_SetValue(var, (float)width);
if (VID_r_con_height_adjust(width, &height)) {
VID_r_con_height_apply(height);
}
}
else if (var == &r_conheight)
{
int height = Q_atoi(string);
if (nonwideconheight==0)
nonwideconheight=height; // save original conheight
if (host_everything_loaded)
{
if (vid_wideaspect.integer)
{
nonwideconheight=height;
scale = (4.0/3) / (16.0/10); //widescreen
}
else
{
scale = 1;
}
height = floor(height * scale + 0.5);
//height &= 0xfff8; // make it a multiple of eight
if (vid_wideaspect.value != 0 && vid_wideaspect_verbose.integer > 0)
Com_Printf("vid_wideaspect enabled - conheight recalculated to %i\n", height);
}
else if (host_initialized && vid_wideaspect.integer)
{
scale = (16.0/10) / (4.0/3); // standard
nonwideconheight = floor( height * scale + 0.5);
}
height = max(200, height);
VID_r_con_height_apply(height);
}
else
{
*cancel = true; // hrm?
return;
}
Draw_AdjustConback ();
vid.recalc_refdef = 1;
*cancel = true;
}
//============================================================================
/*
** GL_SetDefaultState
*/
void GL_SetDefaultState( void )
{
}
/*
================
GfxInfo_f
================
*/
void GfxInfo_f( void )
{
// cvar_t *sys_cpustring = Cvar_Get( "sys_cpustring", "", 0 );
#if 0
const char *enablestrings[] =
{
"disabled",
"enabled"
};
#endif
const char *fsstrings[] =
{
"windowed",
"fullscreen"
};
ST_Printf( PRINT_ALL, "\nGL_VENDOR: %s\n", glConfig.vendor_string );
ST_Printf( PRINT_ALL, "GL_RENDERER: %s\n", glConfig.renderer_string );
ST_Printf( PRINT_ALL, "GL_VERSION: %s\n", glConfig.version_string );
if ( r_showextensions.value )
ST_Printf( PRINT_ALL, "GL_EXTENSIONS: %s\n", glConfig.extensions_string );
// ST_Printf( PRINT_ALL, "GL_MAX_TEXTURE_SIZE: %d\n", glConfig.maxTextureSize );
// ST_Printf( PRINT_ALL, "GL_MAX_ACTIVE_TEXTURES_ARB: %d\n", glConfig.maxActiveTextures );
ST_Printf( PRINT_ALL, "PIXELFORMAT: color(%d-bits) Z(%d-bit)\n stencil(%d-bits)\n", glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );
ST_Printf( PRINT_ALL, "MODE: %d, %d x %d ", r_mode.integer, glConfig.vidWidth, glConfig.vidHeight);
if ( glConfig.displayFrequency )
{
ST_Printf( PRINT_ALL, "%d", glConfig.displayFrequency );
}
else
{
ST_Printf( PRINT_ALL, "N/A" );
}
Com_Printf ("hz %s\n", fsstrings[r_fullscreen.integer == 1]);
ST_Printf( PRINT_ALL, "CONRES: %d x %d\n", r_conwidth.integer, r_conheight.integer );
#if 0
if ( glConfig.deviceSupportsGamma )
{
ST_Printf( PRINT_ALL, "GAMMA: hardware w/ %d overbright bits\n", tr.overbrightBits );
}
else
{
ST_Printf( PRINT_ALL, "GAMMA: software w/ %d overbright bits\n", tr.overbrightBits );
}
ST_Printf( PRINT_ALL, "CPU: %s\n", sys_cpustring.string );
ST_Printf( PRINT_ALL, "texturemode: %s\n", r_textureMode.string );
ST_Printf( PRINT_ALL, "picmip: %d\n", r_picmip.integer );
ST_Printf( PRINT_ALL, "texture bits: %d\n", r_texturebits.integer );
ST_Printf( PRINT_ALL, "multitexture: %s\n", enablestrings[qglActiveTextureARB != 0] );
if ( r_vertexLight.integer || glConfig.hardwareType == GLHW_PERMEDIA2 )
{
ST_Printf( PRINT_ALL, "HACK: using vertex lightmap approximation\n" );
}
if ( glConfig.hardwareType == GLHW_RAGEPRO )
{
ST_Printf( PRINT_ALL, "HACK: ragePro approximations\n" );
}
if ( glConfig.hardwareType == GLHW_RIVA128 )
{
ST_Printf( PRINT_ALL, "HACK: riva128 approximations\n" );
}
if ( r_finish.integer ) {
ST_Printf( PRINT_ALL, "Forcing glFinish\n" );
}
#endif
}
/*
===============
R_Register
===============
*/
void R_Register( void )
{
int i;
extern void VID_Restart_f (void);
Cvar_SetCurrentGroup(CVAR_GROUP_VIDEO);
//
// latched and archived variables
//
Cvar_Register (&r_glDriver);
Cvar_Register (&r_allowExtensions);
// Cvar_Register (&r_texturebits);
Cvar_Register (&r_colorbits);
// Cvar_Register (&r_stereo); // qqshka: unused but saved
Cvar_Register (&r_stencilbits);
Cvar_Register (&r_depthbits);
// Cvar_Register (&r_overBrightBits);
Cvar_Register (&r_mode);
Cvar_Register (&r_fullscreen);
Cvar_Register (&r_customwidth);
Cvar_Register (&r_customheight);
// Cvar_Register (&r_customaspect); // qqshka: unused even in q3, but I keep cvar, just do not register it
//
// temporary latched variables that can only change over a restart
//
Cvar_Register (&r_displayRefresh);
AssertCvarRange( &r_displayRefresh, 0, 300, true ); // useless in most cases thought
Cvar_Register (&vid_borderless);
// Cvar_Register (&r_intensity);
//
// archived variables that can change at any time
//
Cvar_Register (&r_ignoreGLErrors);
// Cvar_Register (&r_textureMode);
Cvar_Register (&r_swapInterval);
// Cvar_Register (&r_gamma);
Cvar_Register (&vid_hwgammacontrol);
Cvar_Register (&r_verbose);
// Cvar_Register (&r_logFile);
Cvar_Register (&vid_xpos);
Cvar_Register (&vid_ypos);
Cvar_Register (&vid_minpos);
Cvar_Register (&r_conwidth);
Cvar_Register (&r_conheight);
Cvar_Register (&vid_wideaspect);
Cvar_Register (&vid_wideaspect_verbose);
Cvar_Register (&r_conaspect);
if ( !host_initialized ) // compatibility with retarded cmd line, and actually this still needed for some other reasons
{
int w = 0, h = 0;
if (COM_CheckParm("-window") || COM_CheckParm("-startwindowed"))
Cvar_LatchedSetValue(&r_fullscreen, 0);
if ((i = COM_CheckParm("-freq")) && i + 1 < COM_Argc())
Cvar_LatchedSetValue(&r_displayRefresh, Q_atoi(COM_Argv(i + 1)));
if ((i = COM_CheckParm("-bpp")) && i + 1 < COM_Argc())
Cvar_LatchedSetValue(&r_colorbits, Q_atoi(COM_Argv(i + 1)));
w = ((i = COM_CheckParm("-width")) && i + 1 < COM_Argc()) ? Q_atoi(COM_Argv(i + 1)) : 0;
h = ((i = COM_CheckParm("-height")) && i + 1 < COM_Argc()) ? Q_atoi(COM_Argv(i + 1)) : 0;
#ifdef _WIN32
if (!( // no!
strcmp (r_displayRefresh.defaultvalue, r_displayRefresh.string) || // refresh rate wasnt changed
strcmp (r_colorbits.defaultvalue, r_colorbits.string ) || // bpp wasnt changed
strcmp (r_mode.defaultvalue, r_mode.string ) || // bpp wasnt changed
w || h) // width and height wasnt changed
)
{
// ok, pseudo current
int freq = 0;
DEVMODE dm;
memset( &dm, 0, sizeof( dm ) );
dm.dmSize = sizeof( dm );
if ( EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &dm ) ) // FIXME: Do we need to care about which device we get this? With several monitors we might...
freq = dm.dmDisplayFrequency; // get actual frequency
w = GetSystemMetrics (SM_CXSCREEN);
h = GetSystemMetrics (SM_CYSCREEN);
Cvar_LatchedSetValue(&r_displayRefresh, freq); // current mean current
Cvar_LatchedSetValue(&r_colorbits, 0); // use desktop bpp
}
#endif // _WIN32
if ( w || h )
{
int m = R_MatchMode( w, h );
if (m == -1) { // ok, mode not found, trying custom
w = w ? w : h * 4 / 3; // guessing width from height may cause some problems thought, because 4/3 uneven
h = h ? h : w * 3 / 4;
Cvar_LatchedSetValue(&r_customwidth, w);
Cvar_LatchedSetValue(&r_customheight, h);
}
Cvar_LatchedSetValue(&r_mode, m);
}
if ((i = COM_CheckParm("-conwidth")) && i + 1 < COM_Argc())
Cvar_SetValue(&r_conwidth, (float)Q_atoi(COM_Argv(i + 1)));
else // this is ether +set vid_con... or just default value which we select in cvar initialization
Cvar_SetValue(&r_conwidth, r_conwidth.value); // must trigger callback which validate value
if ((i = COM_CheckParm("-conheight")) && i + 1 < COM_Argc())
Cvar_SetValue(&r_conheight, (float)Q_atoi(COM_Argv(i + 1)));
else // this is ether +set vid_con... or just default value which we select in cvar initialization
// also select r_conheight with proper aspect ratio if user omit it
Cvar_SetValue(&r_conheight, r_conheight.value ? r_conheight.value : r_conwidth.value * 3 / 4); // must trigger callback which validate value
}
Cvar_Register (&vid_ref);
#ifdef _WIN32
Cvar_Register (&vid_flashonactivity);
Cvar_Register (&_windowed_mouse); //that more like an input, but i have serious reason to register it here
#endif
Cvar_Register (&r_showextensions);
Cvar_ResetCurrentGroup();
if ( !host_initialized )
{
#ifdef _WIN32
void VID_ShowFreq_f(void);
Cmd_AddCommand( "vid_showfreq", VID_ShowFreq_f );
#endif
Cmd_AddCommand( "vid_modelist", R_ModeList_f );
Cmd_AddCommand( "vid_gfxinfo", GfxInfo_f );
Cmd_AddCommand( "vid_restart", VID_Restart_f );
}
}
/*
===============
RE_Init
===============
*/
void RE_Init( void ) {
int err;
ST_Printf( PRINT_R_VERBOSE, "----- R_Init -----\n" );
R_Register();
InitOpenGL();
err = glGetError();
if ( err != GL_NO_ERROR )
ST_Printf ( PRINT_R_VERBOSE, "glGetError() = 0x%x\n", err );
ST_Printf( PRINT_R_VERBOSE, "----- finished R_Init -----\n" );
}
/*
===============
RE_Shutdown
===============
*/
void RE_Shutdown( qbool destroyWindow ) {
ST_Printf( PRINT_R_VERBOSE, "R_Shutdown( %i )\n", destroyWindow );
// shut down platform specific OpenGL stuff
if ( destroyWindow ) {
GLimp_Shutdown();
}
}
/******************************************************************************/
//
// OK, BELOW STUFF FROM Q1
//
/******************************************************************************/
/******************************** VID SHUTDOWN ********************************/
void VID_Shutdown (void) {
#ifdef _WIN32
extern void AppActivate(BOOL fActive, BOOL minimize);
AppActivate(false, false);
#endif
#ifdef GLSL
SHD_Shutdown();
#endif
RE_Shutdown( true );
}
/********************************** VID INIT **********************************/
#ifdef _WIN32
extern void ClearAllStates (void);
#endif
void VID_zzz (void) {
extern int nonwideconheight;
vid.width = vid.conwidth = min(vid.conwidth, glConfig.vidWidth);
vid.height = vid.conheight = min(vid.conheight, glConfig.vidHeight);
// we need cap cvars, after resolution changed, here may be conwidth > width, so set cvars right
Cvar_SetValue(&r_conwidth, r_conwidth.value); // must trigger callback which validate value
Cvar_SetValue(&r_conheight, nonwideconheight); // must trigger callback which validate value
vid.numpages = 2;
Draw_AdjustConback ();
#ifdef _WIN32
//fix the leftover Alt from any Alt-Tab or the like that switched us away
ClearAllStates ();
#endif
vid.recalc_refdef = 1;
}
void VID_Init (unsigned char *palette) {
vid.colormap = host_colormap;
Check_Gamma(palette);
VID_SetPalette(palette);
RE_Init();
#ifdef GLSL
SHD_Init();
#endif
VID_zzz();
GL_Init();
}
void VID_Restart_f (void)
{
extern void GFX_Init(void);
extern void ReloadPaletteAndColormap(void);
extern int nonwideconheight;
qbool old_con_suppress;
if (!host_initialized) { // sanity
Com_Printf("Can't do %s yet\n", Cmd_Argv(0));
return;
}
VID_Shutdown ();
ReloadPaletteAndColormap();
VID_Init (host_basepal);
// force models to reload (just flush, no actual loading code here)
Cache_Flush();
// shut up warnings during GFX_Init();
old_con_suppress = con_suppress;
con_suppress = (developer.value ? false : true);
// reload 2D textures, particles textures, some other textures and gfx.wad
GFX_Init();
// reload skins
Skin_Skins_f();
con_suppress = old_con_suppress;
// we need done something like for map reloading, for example reload textures for brush models
R_NewMap(true);
// force all cached models to be loaded, so no short HDD lag then u walk over level and discover new model
Mod_TouchModels();
// window may be re-created, so caption need to be forced to update
CL_UpdateCaption(true);
}
void OnChange_vid_wideaspect (cvar_t *var, char *string, qbool *cancel)
{
// FIXME conheight
extern int nonwideconheight;
extern cvar_t r_conheight;
if ( (Q_atoi(string) == vid_wideaspect.value) || (Q_atoi(string) > 1) || (Q_atoi(string) < 0))
{
*cancel = true;
return;
}
Cvar_Set (&vid_wideaspect, string);
if(!host_everything_loaded)
return;
if (nonwideconheight != 0)
{
if (vid_wideaspect.integer == 0)
r_conheight.OnChange(&r_conheight, Q_ftos(nonwideconheight), cancel);
else
r_conheight.OnChange(&r_conheight, Q_ftos(r_conheight.value), cancel);
}
}
void OnChange_vid_pos(cvar_t *var, char *string, qbool *cancel)
{
#ifdef WIN32
if (!r_fullscreen.integer)
{
extern HWND mainwindow;
if (mainwindow)
{
SetWindowPos( mainwindow,
NULL,
var == &vid_xpos ? atof(string) : vid_xpos.value,
var == &vid_ypos ? atof(string) : vid_ypos.value,
0,
0,
SWP_NOSIZE | SWP_NOZORDER);
}
}
#endif
}