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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "OptionsSubVideo.h"
#include "cvarslider.h"
#include "EngineInterface.h"
#include "BasePanel.h"
#include "IGameUIFuncs.h"
#include "modes.h"
#include "materialsystem/materialsystem_config.h"
#include "filesystem.h"
#include "GameUI_Interface.h"
#include "vgui_controls/CheckButton.h"
#include "vgui_controls/ComboBox.h"
#include "vgui_controls/Frame.h"
#include "vgui_controls/QueryBox.h"
#include "CvarToggleCheckButton.h"
#include "tier1/KeyValues.h"
#include "vgui/IInput.h"
#include "vgui/ILocalize.h"
#include "vgui/ISystem.h"
#include "tier0/icommandline.h"
#include "tier1/convar.h"
#include "ModInfo.h"
#include "vgui_controls/Tooltip.h"
#include "sourcevr/isourcevirtualreality.h"
#if defined( USE_SDL )
#include "SDL.h"
#endif
#include "inetchannelinfo.h"
extern IMaterialSystem *materials;
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: aspect ratio mappings (for normal/widescreen combo)
//-----------------------------------------------------------------------------
struct RatioToAspectMode_t
{
int anamorphic;
float aspectRatio;
};
RatioToAspectMode_t g_RatioToAspectModes[] =
{
{ 0, 4.0f / 3.0f },
{ 1, 16.0f / 9.0f },
{ 2, 16.0f / 10.0f },
{ 2, 1.0f },
};
struct AAMode_t
{
int m_nNumSamples;
int m_nQualityLevel;
};
//-----------------------------------------------------------------------------
// Purpose: list of valid dx levels
//-----------------------------------------------------------------------------
int g_DirectXLevels[] =
{
70,
80,
81,
90,
#if DX_TO_GL_ABSTRACTION
92,
#endif
95,
};
//-----------------------------------------------------------------------------
// Purpose: returns the string name of a given dxlevel
//-----------------------------------------------------------------------------
void GetNameForDXLevel( int dxlevel, char *name, int bufferSize)
{
if ( ( dxlevel >= 92 ) && ( dxlevel <= 95 ) )
{
Q_snprintf( name, bufferSize, "DirectX v9.0+" );
}
else
{
Q_snprintf( name, bufferSize, "DirectX v%.1f", dxlevel / 10.0f );
}
}
//-----------------------------------------------------------------------------
// Purpose: returns the aspect ratio mode number for the given resolution
//-----------------------------------------------------------------------------
int GetScreenAspectMode( int width, int height )
{
float aspectRatio = (float)width / (float)height;
// just find the closest ratio
float closestAspectRatioDist = 99999.0f;
int closestAnamorphic = 0;
for (int i = 0; i < ARRAYSIZE(g_RatioToAspectModes); i++)
{
float dist = fabs( g_RatioToAspectModes[i].aspectRatio - aspectRatio );
if (dist < closestAspectRatioDist)
{
closestAspectRatioDist = dist;
closestAnamorphic = g_RatioToAspectModes[i].anamorphic;
}
}
return closestAnamorphic;
}
//-----------------------------------------------------------------------------
// Purpose: returns the string name of the specified resolution mode
//-----------------------------------------------------------------------------
static void GetResolutionName( vmode_t *mode, char *sz, int sizeofsz, int desktopWidth, int desktopHeight )
{
Q_snprintf( sz, sizeofsz, "%i x %i%s", mode->width, mode->height,
( mode->width == desktopWidth ) && ( mode->height == desktopHeight ) ? " (native)": "" );
}
//-----------------------------------------------------------------------------
// Purpose: Gamma-adjust dialog
//-----------------------------------------------------------------------------
class CGammaDialog : public vgui::Frame
{
DECLARE_CLASS_SIMPLE( CGammaDialog, vgui::Frame );
public:
CGammaDialog( vgui::VPANEL hParent ) : BaseClass( NULL, "OptionsSubVideoGammaDlg" )
{
// parent is ignored, since we want look like we're steal focus from the parent (we'll become modal below)
SetTitle("#GameUI_AdjustGamma_Title", true);
SetSize( 400, 260 );
SetDeleteSelfOnClose( true );
m_pGammaSlider = new CCvarSlider( this, "Gamma", "#GameUI_Gamma", 1.6f, 2.6f, "mat_monitorgamma" );
m_pGammaLabel = new Label( this, "Gamma label", "#GameUI_Gamma" );
m_pGammaEntry = new TextEntry( this, "GammaEntry" );
Button *ok = new Button( this, "OKButton", "#vgui_ok" );
ok->SetCommand( new KeyValues("OK") );
LoadControlSettings( "resource/OptionsSubVideoGammaDlg.res" );
MoveToCenterOfScreen();
SetSizeable( false );
m_pGammaSlider->SetTickCaptions( "#GameUI_Light", "#GameUI_Dark" );
}
MESSAGE_FUNC_PTR( OnGammaChanged, "SliderMoved", panel )
{
if (panel == m_pGammaSlider)
{
m_pGammaSlider->ApplyChanges();
}
}
virtual void Activate()
{
BaseClass::Activate();
m_flOriginalGamma = m_pGammaSlider->GetValue();
UpdateGammaLabel();
}
MESSAGE_FUNC( OnOK, "OK" )
{
// make the gamma stick
m_flOriginalGamma = m_pGammaSlider->GetValue();
Close();
}
virtual void OnClose()
{
// reset to the original gamma
m_pGammaSlider->SetValue( m_flOriginalGamma );
m_pGammaSlider->ApplyChanges();
BaseClass::OnClose();
}
void OnKeyCodeTyped(KeyCode code)
{
// force ourselves to be closed if the escape key it pressed
if (code == KEY_ESCAPE)
{
Close();
}
else
{
BaseClass::OnKeyCodeTyped(code);
}
}
MESSAGE_FUNC_PTR( OnControlModified, "ControlModified", panel )
{
// the HasBeenModified() check is so that if the value is outside of the range of the
// slider, it won't use the slider to determine the display value but leave the
// real value that we determined in the constructor
if (panel == m_pGammaSlider && m_pGammaSlider->HasBeenModified())
{
UpdateGammaLabel();
}
}
MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel )
{
if (panel == m_pGammaEntry)
{
char buf[64];
m_pGammaEntry->GetText(buf, 64);
float fValue = (float) atof(buf);
if (fValue >= 1.0)
{
m_pGammaSlider->SetSliderValue(fValue);
PostActionSignal(new KeyValues("ApplyButtonEnable"));
}
}
}
void UpdateGammaLabel()
{
char buf[64];
Q_snprintf(buf, sizeof( buf ), " %.1f", m_pGammaSlider->GetSliderValue());
m_pGammaEntry->SetText(buf);
}
private:
CCvarSlider *m_pGammaSlider;
vgui::Label *m_pGammaLabel;
vgui::TextEntry *m_pGammaEntry;
float m_flOriginalGamma;
};
//-----------------------------------------------------------------------------
// Purpose: advanced keyboard settings dialog
//-----------------------------------------------------------------------------
class COptionsSubVideoAdvancedDlg : public vgui::Frame
{
DECLARE_CLASS_SIMPLE( COptionsSubVideoAdvancedDlg, vgui::Frame );
public:
COptionsSubVideoAdvancedDlg( vgui::Panel *parent ) : BaseClass( parent , "OptionsSubVideoAdvancedDlg" )
{
SetTitle("#GameUI_VideoAdvanced_Title", true);
SetSize( 260, 400 );
m_pDXLevel = new ComboBox(this, "dxlabel", 6, false );
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
KeyValues *pKeyValues = new KeyValues( "config" );
materials->GetRecommendedConfigurationInfo( 0, pKeyValues );
m_pDXLevel->DeleteAllItems();
for (int i = 0; i < ARRAYSIZE(g_DirectXLevels); i++)
{
// don't allow choice of lower dxlevels than the default,
// unless we're already at that lower level or have it forced
if (!CommandLine()->CheckParm("-dxlevel") &&
g_DirectXLevels[i] != config.dxSupportLevel &&
g_DirectXLevels[i] < pKeyValues->GetInt("ConVar.mat_dxlevel"))
continue;
KeyValues *pTempKV = new KeyValues("config");
if (g_DirectXLevels[i] == pKeyValues->GetInt("ConVar.mat_dxlevel")
|| materials->GetRecommendedConfigurationInfo( g_DirectXLevels[i], pTempKV ))
{
// add the configuration in the combo
char szDXLevelName[64];
GetNameForDXLevel( g_DirectXLevels[i], szDXLevelName, sizeof(szDXLevelName) );
m_pDXLevel->AddItem( szDXLevelName, new KeyValues("dxlevel", "dxlevel", g_DirectXLevels[i]) );
}
pTempKV->deleteThis();
}
pKeyValues->deleteThis();
m_pModelDetail = new ComboBox( this, "ModelDetail", 6, false );
m_pModelDetail->AddItem("#gameui_low", NULL);
m_pModelDetail->AddItem("#gameui_medium", NULL);
m_pModelDetail->AddItem("#gameui_high", NULL);
m_pTextureDetail = new ComboBox( this, "TextureDetail", 6, false );
m_pTextureDetail->AddItem("#gameui_low", NULL);
m_pTextureDetail->AddItem("#gameui_medium", NULL);
m_pTextureDetail->AddItem("#gameui_high", NULL);
m_pTextureDetail->AddItem("#gameui_ultra", NULL);
// Build list of MSAA and CSAA modes, based upon those which are supported by the device
//
// The modes that we've seen in the wild to date are as follows (in perf order, fastest to slowest)
//
// 2x 4x 6x 8x 16x 8x 16xQ
// Texture/Shader Samples 1 1 1 1 1 1 1
// Stored Color/Z Samples 2 4 6 4 4 8 8
// Coverage Samples 2 4 6 8 16 8 16
// MSAA or CSAA M M M C C M C
//
// The CSAA modes are nVidia only (added in the G80 generation of GPUs)
//
m_nNumAAModes = 0;
m_pAntialiasingMode = new ComboBox( this, "AntialiasingMode", 10, false );
m_pAntialiasingMode->AddItem("#GameUI_None", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 1;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
m_nNumAAModes++;
if ( materials->SupportsMSAAMode(2) )
{
m_pAntialiasingMode->AddItem("#GameUI_2X", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 2;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
m_nNumAAModes++;
}
if ( materials->SupportsMSAAMode(4) )
{
m_pAntialiasingMode->AddItem("#GameUI_4X", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 4;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
m_nNumAAModes++;
}
if ( materials->SupportsMSAAMode(6) )
{
m_pAntialiasingMode->AddItem("#GameUI_6X", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 6;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
m_nNumAAModes++;
}
if ( materials->SupportsCSAAMode(4, 2) ) // nVidia CSAA "8x"
{
m_pAntialiasingMode->AddItem("#GameUI_8X_CSAA", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 4;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 2;
m_nNumAAModes++;
}
if ( materials->SupportsCSAAMode(4, 4) ) // nVidia CSAA "16x"
{
m_pAntialiasingMode->AddItem("#GameUI_16X_CSAA", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 4;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 4;
m_nNumAAModes++;
}
if ( materials->SupportsMSAAMode(8) )
{
m_pAntialiasingMode->AddItem("#GameUI_8X", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 8;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 0;
m_nNumAAModes++;
}
if ( materials->SupportsCSAAMode(8, 2) ) // nVidia CSAA "16xQ"
{
m_pAntialiasingMode->AddItem("#GameUI_16XQ_CSAA", NULL);
m_nAAModes[m_nNumAAModes].m_nNumSamples = 8;
m_nAAModes[m_nNumAAModes].m_nQualityLevel = 2;
m_nNumAAModes++;
}
m_pFilteringMode = new ComboBox( this, "FilteringMode", 6, false );
m_pFilteringMode->AddItem("#GameUI_Bilinear", NULL);
m_pFilteringMode->AddItem("#GameUI_Trilinear", NULL);
m_pFilteringMode->AddItem("#GameUI_Anisotropic2X", NULL);
m_pFilteringMode->AddItem("#GameUI_Anisotropic4X", NULL);
m_pFilteringMode->AddItem("#GameUI_Anisotropic8X", NULL);
m_pFilteringMode->AddItem("#GameUI_Anisotropic16X", NULL);
m_pShadowDetail = new ComboBox( this, "ShadowDetail", 6, false );
m_pShadowDetail->AddItem("#gameui_low", NULL);
m_pShadowDetail->AddItem("#gameui_medium", NULL);
if ( materials->SupportsShadowDepthTextures() )
{
m_pShadowDetail->AddItem("#gameui_high", NULL);
}
ConVarRef mat_dxlevel( "mat_dxlevel" );
m_pHDR = new ComboBox( this, "HDR", 6, false );
m_pHDR->AddItem("#GameUI_hdr_level0", NULL);
m_pHDR->AddItem("#GameUI_hdr_level1", NULL);
if ( materials->SupportsHDRMode( HDR_TYPE_INTEGER ) )
{
m_pHDR->AddItem("#GameUI_hdr_level2", NULL);
}
#if 0
if ( materials->SupportsHDRMode( HDR_TYPE_FLOAT ) )
{
m_pHDR->AddItem("#GameUI_hdr_level3", NULL);
}
#endif
m_pHDR->SetEnabled( mat_dxlevel.GetInt() >= 80 );
m_pWaterDetail = new ComboBox( this, "WaterDetail", 6, false );
m_pWaterDetail->AddItem("#gameui_noreflections", NULL);
m_pWaterDetail->AddItem("#gameui_reflectonlyworld", NULL);
m_pWaterDetail->AddItem("#gameui_reflectall", NULL);
m_pVSync = new ComboBox( this, "VSync", 2, false );
m_pVSync->AddItem("#gameui_disabled", NULL);
m_pVSync->AddItem("#gameui_enabled", NULL);
m_pMulticore = new ComboBox( this, "Multicore", 2, false );
m_pMulticore->AddItem("#gameui_disabled", NULL);
m_pMulticore->AddItem("#gameui_enabled", NULL);
m_pShaderDetail = new ComboBox( this, "ShaderDetail", 6, false );
m_pShaderDetail->AddItem("#gameui_low", NULL);
m_pShaderDetail->AddItem("#gameui_high", NULL);
m_pColorCorrection = new ComboBox( this, "ColorCorrection", 2, false );
m_pColorCorrection->AddItem("#gameui_disabled", NULL);
m_pColorCorrection->AddItem("#gameui_enabled", NULL);
m_pMotionBlur = new ComboBox( this, "MotionBlur", 2, false );
m_pMotionBlur->AddItem("#gameui_disabled", NULL);
m_pMotionBlur->AddItem("#gameui_enabled", NULL);
LoadControlSettings( "resource/OptionsSubVideoAdvancedDlg.res" );
MoveToCenterOfScreen();
SetSizeable( false );
m_pDXLevel->SetEnabled(false);
m_pColorCorrection->SetEnabled( mat_dxlevel.GetInt() >= 90 );
m_pMotionBlur->SetEnabled( mat_dxlevel.GetInt() >= 90 );
if ( g_pCVar->FindVar( "fov_desired" ) == NULL )
{
Panel *pFOV = FindChildByName( "FovSlider" );
if ( pFOV )
{
pFOV->SetVisible( false );
}
pFOV = FindChildByName( "FovLabel" );
if ( pFOV )
{
pFOV->SetVisible( false );
}
}
MarkDefaultSettingsAsRecommended();
m_bUseChanges = false;
}
virtual void Activate()
{
BaseClass::Activate();
input()->SetAppModalSurface(GetVPanel());
if (!m_bUseChanges)
{
// reset the data
OnResetData();
}
}
void SetComboItemAsRecommended( vgui::ComboBox *combo, int iItem )
{
// get the item text
wchar_t text[512];
combo->GetItemText(iItem, text, sizeof(text));
// append the recommended flag
wchar_t newText[512];
_snwprintf( newText, sizeof(newText) / sizeof(wchar_t), L"%ls *", text );
// reset
combo->UpdateItem(iItem, newText, NULL);
}
int FindMSAAMode( int nAASamples, int nAAQuality )
{
// Run through the AA Modes supported by the device
for ( int nAAMode = 0; nAAMode < m_nNumAAModes; nAAMode++ )
{
// If we found the mode that matches what we're looking for, return the index
if ( ( m_nAAModes[nAAMode].m_nNumSamples == nAASamples) && ( m_nAAModes[nAAMode].m_nQualityLevel == nAAQuality) )
{
return nAAMode;
}
}
return 0; // Didn't find what we're looking for, so no AA
}
MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel )
{
if ( panel == m_pDXLevel && RequiresRestart() )
{
// notify the user that this will require a disconnect
QueryBox *box = new QueryBox("#GameUI_SettingRequiresDisconnect_Title", "#GameUI_SettingRequiresDisconnect_Info");
box->AddActionSignalTarget( this );
box->SetCancelCommand(new KeyValues("ResetDXLevelCombo"));
box->DoModal();
}
}
MESSAGE_FUNC( OnGameUIHidden, "GameUIHidden" ) // called when the GameUI is hidden
{
Close();
}
MESSAGE_FUNC( ResetDXLevelCombo, "ResetDXLevelCombo" )
{
ConVarRef mat_dxlevel( "mat_dxlevel" );
for (int i = 0; i < m_pDXLevel->GetItemCount(); i++)
{
KeyValues *kv = m_pDXLevel->GetItemUserData(i);
if ( kv->GetInt("dxlevel") == mat_dxlevel.GetInt( ) )
{
m_pDXLevel->ActivateItem( i );
break;
}
}
// Reset HDR too
if ( m_pHDR->IsEnabled() )
{
ConVarRef mat_hdr_level("mat_hdr_level");
Assert( mat_hdr_level.IsValid() );
m_pHDR->ActivateItem( clamp( mat_hdr_level.GetInt(), 0, 2 ) );
}
}
MESSAGE_FUNC( OK_Confirmed, "OK_Confirmed" )
{
m_bUseChanges = true;
Close();
}
void MarkDefaultSettingsAsRecommended()
{
// Pull in data from dxsupport.cfg database (includes fine-grained per-vendor/per-device config data)
KeyValues *pKeyValues = new KeyValues( "config" );
materials->GetRecommendedConfigurationInfo( 0, pKeyValues );
// Read individual values from keyvalues which came from dxsupport.cfg database
int nSkipLevels = pKeyValues->GetInt( "ConVar.mat_picmip", 0 );
int nAnisotropicLevel = pKeyValues->GetInt( "ConVar.mat_forceaniso", 1 );
int nForceTrilinear = pKeyValues->GetInt( "ConVar.mat_trilinear", 0 );
int nAASamples = pKeyValues->GetInt( "ConVar.mat_antialias", 0 );
int nAAQuality = pKeyValues->GetInt( "ConVar.mat_aaquality", 0 );
int nRenderToTextureShadows = pKeyValues->GetInt( "ConVar.r_shadowrendertotexture", 0 );
int nShadowDepthTextureShadows = pKeyValues->GetInt( "ConVar.r_flashlightdepthtexture", 0 );
#ifndef _X360
int nWaterUseRealtimeReflection = pKeyValues->GetInt( "ConVar.r_waterforceexpensive", 0 );
#endif
int nWaterUseEntityReflection = pKeyValues->GetInt( "ConVar.r_waterforcereflectentities", 0 );
int nMatVSync = pKeyValues->GetInt( "ConVar.mat_vsync", 1 );
int nRootLOD = pKeyValues->GetInt( "ConVar.r_rootlod", 0 );
int nReduceFillRate = pKeyValues->GetInt( "ConVar.mat_reducefillrate", 0 );
int nDXLevel = pKeyValues->GetInt( "ConVar.mat_dxlevel", 0 );
int nColorCorrection = pKeyValues->GetInt( "ConVar.mat_colorcorrection", 0 );
int nMotionBlur = pKeyValues->GetInt( "ConVar.mat_motion_blur_enabled", 0 );
// It doesn't make sense to retrieve this convar from dxsupport, because we'll then have materialsystem setting this config at loadtime. (Also, it only has very minimal support for CPU related configuration.)
//int nMulticore = pKeyValues->GetInt( "ConVar.mat_queue_mode", 0 );
int nMulticore = GetCPUInformation()->m_nPhysicalProcessors >= 2;
// Only recommend a dxlevel if there is more than one available
if ( m_pDXLevel->GetItemCount() > 1 )
{
for (int i = 0; i < m_pDXLevel->GetItemCount(); i++)
{
KeyValues *kv = m_pDXLevel->GetItemUserData(i);
if (kv->GetInt("dxlevel") == pKeyValues->GetInt("ConVar.mat_dxlevel"))
{
SetComboItemAsRecommended( m_pDXLevel, i );
break;
}
}
}
SetComboItemAsRecommended( m_pModelDetail, 2 - nRootLOD );
SetComboItemAsRecommended( m_pTextureDetail, 2 - nSkipLevels );
switch ( nAnisotropicLevel )
{
case 2:
SetComboItemAsRecommended( m_pFilteringMode, 2 );
break;
case 4:
SetComboItemAsRecommended( m_pFilteringMode, 3 );
break;
case 8:
SetComboItemAsRecommended( m_pFilteringMode, 4 );
break;
case 16:
SetComboItemAsRecommended( m_pFilteringMode, 5 );
break;
case 0:
default:
if ( nForceTrilinear != 0 )
{
SetComboItemAsRecommended( m_pFilteringMode, 1 );
}
else
{
SetComboItemAsRecommended( m_pFilteringMode, 0 );
}
break;
}
// Map desired mode to list item number
int nMSAAMode = FindMSAAMode( nAASamples, nAAQuality );
SetComboItemAsRecommended( m_pAntialiasingMode, nMSAAMode );
if ( nShadowDepthTextureShadows )
SetComboItemAsRecommended( m_pShadowDetail, 2 ); // Shadow depth mapping (in addition to RTT shadows)
else if ( nRenderToTextureShadows )
SetComboItemAsRecommended( m_pShadowDetail, 1 ); // RTT shadows
else
SetComboItemAsRecommended( m_pShadowDetail, 0 ); // Blobbies
SetComboItemAsRecommended( m_pShaderDetail, nReduceFillRate ? 0 : 1 );
#ifndef _X360
if ( nWaterUseRealtimeReflection )
#endif
{
if ( nWaterUseEntityReflection )
{
SetComboItemAsRecommended( m_pWaterDetail, 2 );
}
else
{
SetComboItemAsRecommended( m_pWaterDetail, 1 );
}
}
#ifndef _X360
else
{
SetComboItemAsRecommended( m_pWaterDetail, 0 );
}
#endif
SetComboItemAsRecommended( m_pVSync, nMatVSync != 0 );
SetComboItemAsRecommended( m_pMulticore, nMulticore != 0 );
SetComboItemAsRecommended( m_pHDR, nDXLevel >= 90 ? 2 : 0 );
SetComboItemAsRecommended( m_pColorCorrection, nColorCorrection );
SetComboItemAsRecommended( m_pMotionBlur, nMotionBlur );
pKeyValues->deleteThis();
}
void ApplyChangesToConVar( const char *pConVarName, int value )
{
Assert( cvar->FindVar( pConVarName ) );
char szCmd[256];
Q_snprintf( szCmd, sizeof(szCmd), "%s %d\n", pConVarName, value );
engine->ClientCmd_Unrestricted( szCmd );
}
virtual void ApplyChanges()
{
if ( !m_bUseChanges )
return;
KeyValues *pActiveItem = m_pDXLevel->GetActiveItemUserData();
if ( pActiveItem )
{
ApplyChangesToConVar( "mat_dxlevel", pActiveItem->GetInt( "dxlevel" ) );
}
ApplyChangesToConVar( "r_rootlod", 2 - m_pModelDetail->GetActiveItem());
ApplyChangesToConVar( "mat_picmip", 2 - m_pTextureDetail->GetActiveItem());
// reset everything tied to the filtering mode, then the switch sets the appropriate one
ApplyChangesToConVar( "mat_trilinear", false );
ApplyChangesToConVar( "mat_forceaniso", 1 );
switch ( m_pFilteringMode->GetActiveItem() )
{
case 0:
break;
case 1:
ApplyChangesToConVar( "mat_trilinear", true );
break;
case 2:
ApplyChangesToConVar( "mat_forceaniso", 2 );
break;
case 3:
ApplyChangesToConVar( "mat_forceaniso", 4 );
break;
case 4:
ApplyChangesToConVar( "mat_forceaniso", 8 );
break;
case 5:
ApplyChangesToConVar( "mat_forceaniso", 16 );
break;
default:
// Trilinear.
ApplyChangesToConVar( "mat_forceaniso", 1 );
break;
}
// Set the AA convars according to the menu item chosen
int nActiveAAItem = m_pAntialiasingMode->GetActiveItem();
ApplyChangesToConVar( "mat_antialias", m_nAAModes[nActiveAAItem].m_nNumSamples );
ApplyChangesToConVar( "mat_aaquality", m_nAAModes[nActiveAAItem].m_nQualityLevel );
if( m_pHDR->IsEnabled() )
{
ConVarRef mat_hdr_level("mat_hdr_level");
Assert( mat_hdr_level.IsValid() );
mat_hdr_level.SetValue(m_pHDR->GetActiveItem());
}
if ( m_pShadowDetail->GetActiveItem() == 0 ) // Blobby shadows
{
ApplyChangesToConVar( "r_shadowrendertotexture", 0 ); // Turn off RTT shadows
ApplyChangesToConVar( "r_flashlightdepthtexture", 0 ); // Turn off shadow depth textures
}
else if ( m_pShadowDetail->GetActiveItem() == 1 ) // RTT shadows only
{
ApplyChangesToConVar( "r_shadowrendertotexture", 1 ); // Turn on RTT shadows
ApplyChangesToConVar( "r_flashlightdepthtexture", 0 ); // Turn off shadow depth textures
}
else if ( m_pShadowDetail->GetActiveItem() == 2 ) // Shadow depth textures
{
ApplyChangesToConVar( "r_shadowrendertotexture", 1 ); // Turn on RTT shadows
ApplyChangesToConVar( "r_flashlightdepthtexture", 1 ); // Turn on shadow depth textures
}
ApplyChangesToConVar( "mat_reducefillrate", ( m_pShaderDetail->GetActiveItem() > 0 ) ? 0 : 1 );
switch ( m_pWaterDetail->GetActiveItem() )
{
default:
case 0:
#ifndef _X360
ApplyChangesToConVar( "r_waterforceexpensive", false );
#endif
ApplyChangesToConVar( "r_waterforcereflectentities", false );
break;
case 1:
#ifndef _X360
ApplyChangesToConVar( "r_waterforceexpensive", true );
#endif
ApplyChangesToConVar( "r_waterforcereflectentities", false );
break;
case 2:
#ifndef _X360
ApplyChangesToConVar( "r_waterforceexpensive", true );
#endif
ApplyChangesToConVar( "r_waterforcereflectentities", true );
break;
}
ApplyChangesToConVar( "mat_vsync", m_pVSync->GetActiveItem() );
int iMC = m_pMulticore->GetActiveItem();
ApplyChangesToConVar( "mat_queue_mode", (iMC == 0) ? 0 : -1 );
ApplyChangesToConVar( "mat_colorcorrection", m_pColorCorrection->GetActiveItem() );
ApplyChangesToConVar( "mat_motion_blur_enabled", m_pMotionBlur->GetActiveItem() );
CCvarSlider *pFOV = (CCvarSlider *)FindChildByName( "FOVSlider" );
if ( pFOV )
{
pFOV->ApplyChanges();
}
}
virtual void OnResetData()
{
ConVarRef mat_dxlevel( "mat_dxlevel" );
ConVarRef r_rootlod( "r_rootlod" );
ConVarRef mat_picmip( "mat_picmip" );
ConVarRef mat_trilinear( "mat_trilinear" );
ConVarRef mat_forceaniso( "mat_forceaniso" );
ConVarRef mat_antialias( "mat_antialias" );
ConVarRef mat_aaquality( "mat_aaquality" );
ConVarRef mat_vsync( "mat_vsync" );
ConVarRef mat_queue_mode( "mat_queue_mode" );
ConVarRef r_flashlightdepthtexture( "r_flashlightdepthtexture" );
#ifndef _X360
ConVarRef r_waterforceexpensive( "r_waterforceexpensive" );
#endif
ConVarRef r_waterforcereflectentities( "r_waterforcereflectentities" );
ConVarRef mat_reducefillrate("mat_reducefillrate" );
ConVarRef mat_hdr_level( "mat_hdr_level" );
ConVarRef mat_colorcorrection( "mat_colorcorrection" );
ConVarRef mat_motion_blur_enabled( "mat_motion_blur_enabled" );
ConVarRef r_shadowrendertotexture( "r_shadowrendertotexture" );
ResetDXLevelCombo();
m_pModelDetail->ActivateItem( 2 - clamp(r_rootlod.GetInt(), 0, 2) );
m_pTextureDetail->ActivateItem( 2 - clamp(mat_picmip.GetInt(), -1, 2) );
if ( r_flashlightdepthtexture.GetBool() ) // If we're doing flashlight shadow depth texturing...
{
r_shadowrendertotexture.SetValue( 1 ); // ...be sure render to texture shadows are also on
m_pShadowDetail->ActivateItem( 2 );
}
else if ( r_shadowrendertotexture.GetBool() ) // RTT shadows, but not shadow depth texturing
{
m_pShadowDetail->ActivateItem( 1 );
}
else // Lowest shadow quality
{
m_pShadowDetail->ActivateItem( 0 );
}
m_pShaderDetail->ActivateItem( mat_reducefillrate.GetBool() ? 0 : 1 );
m_pHDR->ActivateItem(clamp(mat_hdr_level.GetInt(), 0, 2));
switch (mat_forceaniso.GetInt())
{
case 2:
m_pFilteringMode->ActivateItem( 2 );
break;
case 4:
m_pFilteringMode->ActivateItem( 3 );
break;
case 8:
m_pFilteringMode->ActivateItem( 4 );
break;
case 16:
m_pFilteringMode->ActivateItem( 5 );
break;
case 0:
default:
if (mat_trilinear.GetBool())
{
m_pFilteringMode->ActivateItem( 1 );
}
else
{
m_pFilteringMode->ActivateItem( 0 );
}
break;
}
// Map convar to item on AA drop-down
int nAASamples = mat_antialias.GetInt();
int nAAQuality = mat_aaquality.GetInt();
int nMSAAMode = FindMSAAMode( nAASamples, nAAQuality );
m_pAntialiasingMode->ActivateItem( nMSAAMode );
m_pAntialiasingMode->SetEnabled( m_nNumAAModes > 1 );
#ifndef _X360
if ( r_waterforceexpensive.GetBool() )
#endif
{
if ( r_waterforcereflectentities.GetBool() )
{
m_pWaterDetail->ActivateItem( 2 );
}
else
{
m_pWaterDetail->ActivateItem( 1 );
}
}
#ifndef _X360
else
{
m_pWaterDetail->ActivateItem( 0 );
}
#endif
m_pVSync->ActivateItem( mat_vsync.GetInt() );
int iMC = mat_queue_mode.GetInt();
// We (Rick!) have now switched -2 to mean enabled. So this comment has been rendered obsolete:
// -- For testing, we have -2, the legacy default setting as meaning multicore is disabled.
// -- After that, we'll switch -2 to mean it's enabled.
m_pMulticore->ActivateItem( (iMC == 0) ? 0 : 1 );
m_pColorCorrection->ActivateItem( mat_colorcorrection.GetInt() );
m_pMotionBlur->ActivateItem( mat_motion_blur_enabled.GetInt() );
// get current hardware dx support level
char dxVer[64];
GetNameForDXLevel( mat_dxlevel.GetInt(), dxVer, sizeof( dxVer ) );
SetControlString("dxlabel", dxVer);
// get installed version
char szVersion[64];
szVersion[0] = 0;
system()->GetRegistryString( "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\DirectX\\Version", szVersion, sizeof(szVersion) );
int os = 0, majorVersion = 0, minorVersion = 0, subVersion = 0;
sscanf(szVersion, "%d.%d.%d.%d", &os, &majorVersion, &minorVersion, &subVersion);
Q_snprintf(dxVer, sizeof(dxVer), "DirectX v%d.%d", majorVersion, minorVersion);
SetControlString("dxinstalledlabel", dxVer);
}
virtual void OnCommand( const char *command )
{
if ( !stricmp(command, "OK") )
{
if ( RequiresRestart() )
{
// Bring up the confirmation dialog
QueryBox *box = new QueryBox("#GameUI_SettingRequiresDisconnect_Title", "#GameUI_SettingRequiresDisconnect_Info");
box->AddActionSignalTarget( this );
box->SetOKCommand(new KeyValues("OK_Confirmed"));
box->SetCancelCommand(new KeyValues("ResetDXLevelCombo"));
box->DoModal();
box->MoveToFront();
return;
}
m_bUseChanges = true;
Close();
}
else
{
BaseClass::OnCommand( command );
}
}
void OnKeyCodeTyped(KeyCode code)
{
// force ourselves to be closed if the escape key it pressed
if (code == KEY_ESCAPE)
{
Close();
}
else
{
BaseClass::OnKeyCodeTyped(code);
}
}
bool RequiresRestart()
{
if ( GameUI().IsInLevel() )
{
if ( GameUI().IsInBackgroundLevel() )
return false;
if ( !GameUI().IsInMultiplayer() )
return false;
ConVarRef mat_dxlevel( "mat_dxlevel" );
KeyValues *pUserData = m_pDXLevel->GetActiveItemUserData();
Assert( pUserData );
if ( pUserData && mat_dxlevel.GetInt() != pUserData->GetInt("dxlevel") )
{
return true;
}
// HDR changed?
if ( m_pHDR->IsEnabled() )
{
ConVarRef mat_hdr_level("mat_hdr_level");
Assert( mat_hdr_level.IsValid() );
if ( mat_hdr_level.GetInt() != m_pHDR->GetActiveItem() )
return true;
}
}
return false;
}
private:
bool m_bUseChanges;
vgui::ComboBox *m_pModelDetail, *m_pTextureDetail, *m_pAntialiasingMode, *m_pFilteringMode;
vgui::ComboBox *m_pShadowDetail, *m_pHDR, *m_pWaterDetail, *m_pVSync, *m_pMulticore, *m_pShaderDetail;
vgui::ComboBox *m_pColorCorrection;
vgui::ComboBox *m_pMotionBlur;
vgui::ComboBox *m_pDXLevel;
int m_nNumAAModes;
AAMode_t m_nAAModes[16];
};
#if defined( USE_SDL )
//-----------------------------------------------------------------------------
// Purpose: Get display index we will go fullscreen on.
//-----------------------------------------------------------------------------
static int getSDLDisplayIndex()
{
static ConVarRef sdl_displayindex( "sdl_displayindex" );
Assert( sdl_displayindex.IsValid() );
return sdl_displayindex.IsValid() ? sdl_displayindex.GetInt() : 0;
}
//-----------------------------------------------------------------------------
// Purpose: Get display index we are currently fullscreen on. (or -1 if none).
//-----------------------------------------------------------------------------
static int getSDLDisplayIndexFullscreen()
{
static ConVarRef sdl_displayindex_fullscreen( "sdl_displayindex_fullscreen" );
Assert( sdl_displayindex_fullscreen.IsValid() );
return sdl_displayindex_fullscreen.IsValid() ? sdl_displayindex_fullscreen.GetInt() : -1;
}
#endif // USE_SDL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
COptionsSubVideo::COptionsSubVideo(vgui::Panel *parent) : PropertyPage(parent, NULL)
{
m_bRequireRestart = false;
m_bDisplayedVRModeMessage = false;
m_pGammaButton = new Button( this, "GammaButton", "#GameUI_AdjustGamma" );
m_pGammaButton->SetCommand(new KeyValues("OpenGammaDialog"));
m_pMode = new ComboBox(this, "Resolution", 8, false);
m_pAspectRatio = new ComboBox( this, "AspectRatio", 6, false );
m_pVRMode = new ComboBox( this, "VRMode", 2, false );
m_pAdvanced = new Button( this, "AdvancedButton", "#GameUI_AdvancedEllipsis" );
m_pAdvanced->SetCommand(new KeyValues("OpenAdvanced"));
m_pBenchmark = new Button( this, "BenchmarkButton", "#GameUI_LaunchBenchmark" );
m_pBenchmark->SetCommand(new KeyValues("LaunchBenchmark"));
m_pThirdPartyCredits = new URLButton(this, "ThirdPartyVideoCredits", "#GameUI_ThirdPartyTechCredits");
m_pThirdPartyCredits->SetCommand(new KeyValues("OpenThirdPartyVideoCreditsDialog"));
m_pHDContent = new CheckButton( this, "HDContentButton", "#GameUI_HDContent" );
char pszAspectName[3][64];
const wchar_t *unicodeText = g_pVGuiLocalize->Find("#GameUI_AspectNormal");
g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszAspectName[0], 32);
unicodeText = g_pVGuiLocalize->Find("#GameUI_AspectWide16x9");
g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszAspectName[1], 32);
unicodeText = g_pVGuiLocalize->Find("#GameUI_AspectWide16x10");
g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszAspectName[2], 32);
int iNormalItemID = m_pAspectRatio->AddItem( pszAspectName[0], NULL );
int i16x9ItemID = m_pAspectRatio->AddItem( pszAspectName[1], NULL );
int i16x10ItemID = m_pAspectRatio->AddItem( pszAspectName[2], NULL );
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
int iAspectMode = GetScreenAspectMode( config.m_VideoMode.m_Width, config.m_VideoMode.m_Height );
switch ( iAspectMode )
{
default:
case 0:
m_pAspectRatio->ActivateItem( iNormalItemID );
break;
case 1:
m_pAspectRatio->ActivateItem( i16x9ItemID );
break;
case 2:
m_pAspectRatio->ActivateItem( i16x10ItemID );
break;
}
char pszVRModeName[2][64];
unicodeText = g_pVGuiLocalize->Find("#GameUI_Disabled");
g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszVRModeName[0], 32);
unicodeText = g_pVGuiLocalize->Find("#GameUI_Enabled");
g_pVGuiLocalize->ConvertUnicodeToANSI(unicodeText, pszVRModeName[1], 32);
m_pVRMode->AddItem( pszVRModeName[0], NULL );
m_pVRMode->AddItem( pszVRModeName[1], NULL );
// Multimonitor under Direct3D requires you to destroy and recreate the device,
// which is an operation we don't support as it currently stands. The user can
// pass -adapter N to use a different device.
#if defined( USE_SDL ) && defined( DX_TO_GL_ABSTRACTION )
int numVideoDisplays = SDL_GetNumVideoDisplays();
m_pWindowed = new vgui::ComboBox( this, "DisplayModeCombo", 5 + numVideoDisplays, false );
if ( numVideoDisplays <= 1 )
{
m_pWindowed->AddItem( "#GameUI_Fullscreen", NULL );
m_pWindowed->AddItem( "#GameUI_Windowed", NULL );
}
else
{
// Add something like this:
// Full Screen (0)
// Full Screen (1)
// Windowed
wchar_t *fullscreenText = g_pVGuiLocalize->Find( "#GameUI_Fullscreen" );
for ( int i = 0; i < numVideoDisplays; i++ )
{
wchar_t ItemText[ 256 ];
V_swprintf_safe( ItemText, L"%ls (%d)", fullscreenText, i );
m_pWindowed->AddItem( ItemText, NULL );
}
m_pWindowed->AddItem( "#GameUI_Windowed", NULL );
}
#else
m_pWindowed = new vgui::ComboBox( this, "DisplayModeCombo", 6, false );
m_pWindowed->AddItem( "#GameUI_Fullscreen", NULL );
m_pWindowed->AddItem( "#GameUI_Windowed", NULL );
#endif
LoadControlSettings("Resource\\OptionsSubVideo.res");
// Moved down here so we can set the Drop down's
// menu state after the default (disabled) value is loaded
PrepareResolutionList();
// only show the benchmark button if they have the benchmark map
if ( !g_pFullFileSystem->FileExists("maps/test_hardware.bsp") )
{
m_pBenchmark->SetVisible( false );
}
if ( ModInfo().HasHDContent() )
{
m_pHDContent->SetVisible( true );
}
// if VR mode isn't available, disable the dropdown
if( !g_pSourceVR )
{
// if sourcevr.dll is missing entirely that means VR mode is not
// supported in this game. Hide the mode dropdown and its label
m_pVRMode->SetVisible( false );
Panel *label = FindChildByName( "VRModeLabel" );
if( label )
label->SetVisible( false );
}
else if( !g_pSourceVR->IsHmdConnected() )
{
m_pVRMode->ActivateItem( 0 );
m_pVRMode->SetEnabled( false );
m_pVRMode->GetTooltip()->SetText( "#GameUI_NoVRTooltip" );
EnableOrDisableWindowedForVR();
}
}
//-----------------------------------------------------------------------------
// Purpose: Generates resolution list
//-----------------------------------------------------------------------------
void COptionsSubVideo::PrepareResolutionList()
{
// get the currently selected resolution
char sz[256];
m_pMode->GetText(sz, 256);
int currentWidth = 0, currentHeight = 0;
sscanf( sz, "%i x %i", ¤tWidth, ¤tHeight );
// Clean up before filling the info again.
m_pMode->DeleteAllItems();
m_pAspectRatio->SetItemEnabled(1, false);
m_pAspectRatio->SetItemEnabled(2, false);
// get full video mode list
vmode_t *plist = NULL;
int count = 0;
gameuifuncs->GetVideoModes( &plist, &count );
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
// Windowed is the last item in the combobox.
bool bWindowed = ( m_pWindowed->GetActiveItem() >= ( m_pWindowed->GetItemCount() - 1 ) );
int desktopWidth, desktopHeight;
gameuifuncs->GetDesktopResolution( desktopWidth, desktopHeight );
#if defined( USE_SDL )
bool bFullScreenWithMultipleDisplays = ( !bWindowed && ( SDL_GetNumVideoDisplays() > 1 ) );
if ( bFullScreenWithMultipleDisplays )
{
SDL_Rect rect;
#if defined( DX_TO_GL_ABSTRACTION )
int displayIndex = m_pWindowed->GetActiveItem();
#else
int displayIndex = materials->GetCurrentAdapter();
#endif
if ( !SDL_GetDisplayBounds( displayIndex, &rect ) )
{
desktopWidth = rect.w;
desktopHeight = rect.h;
}
}
// If we are switching to fullscreen, and this isn't the mode we're currently in, then
// fake things out so the native fullscreen resolution is selected. Stuck this in
// because I assume most people will go fullscreen at native resolution, and it's sometimes
// difficult to find the native resolution with all the aspect ratio options.
bool bNewFullscreenDisplay = ( !bWindowed && ( getSDLDisplayIndexFullscreen() != m_pWindowed->GetActiveItem() ) );
if ( bNewFullscreenDisplay )
{
currentWidth = desktopWidth;
currentHeight = desktopHeight;
}
#endif
// iterate all the video modes adding them to the dropdown
bool bFoundWidescreen = false;
int selectedItemID = -1;
for (int i = 0; i < count; i++, plist++)
{
#if !defined( USE_SDL )
// don't show modes bigger than the desktop for windowed mode
if ( bWindowed )
#endif
{
if ( plist->width > desktopWidth || plist->height > desktopHeight )
{
// Filter out sizes larger than our desktop.
continue;
}
}
GetResolutionName( plist, sz, sizeof( sz ), desktopWidth, desktopHeight );
int itemID = -1;
int iAspectMode = GetScreenAspectMode( plist->width, plist->height );
if ( iAspectMode > 0 )
{
m_pAspectRatio->SetItemEnabled( iAspectMode, true );
bFoundWidescreen = true;
}
// filter the list for those matching the current aspect
if ( iAspectMode == m_pAspectRatio->GetActiveItem() )
{
itemID = m_pMode->AddItem( sz, NULL);
}
// try and find the best match for the resolution to be selected
if ( plist->width == currentWidth && plist->height == currentHeight )
{
selectedItemID = itemID;
}
else if ( selectedItemID == -1 && plist->width == config.m_VideoMode.m_Width && plist->height == config.m_VideoMode.m_Height )
{
selectedItemID = itemID;
}
}
// disable ratio selection if we can't display widescreen.
m_pAspectRatio->SetEnabled( bFoundWidescreen );
m_nSelectedMode = selectedItemID;
if ( selectedItemID != -1 )
{
m_pMode->ActivateItem( selectedItemID );
}
else
{
int Width = config.m_VideoMode.m_Width;
int Height = config.m_VideoMode.m_Height;
#if defined( USE_SDL )
// If we are switching to a new display, or the size is greater than the desktop, then
// display the desktop width and height.
if ( bNewFullscreenDisplay || ( Width > desktopWidth ) || ( Height > desktopHeight ) )
{
Width = desktopWidth;
Height = desktopHeight;
}
#endif
Q_snprintf( sz, ARRAYSIZE( sz ), "%d x %d", Width, Height );
m_pMode->SetText( sz );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
COptionsSubVideo::~COptionsSubVideo()
{
if (m_hOptionsSubVideoAdvancedDlg.Get())
{
m_hOptionsSubVideoAdvancedDlg->MarkForDeletion();
}
}
FILE *FOpenGameHDFile( const char *pchMode )
{
const char *pGameDir = engine->GetGameDirectory();
char szModSteamInfPath[ 1024 ];
V_ComposeFileName( pGameDir, "game_hd.txt", szModSteamInfPath, sizeof( szModSteamInfPath ) );
FILE *fp = fopen( szModSteamInfPath, pchMode );
return fp;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool COptionsSubVideo::BUseHDContent()
{
FILE *fp = FOpenGameHDFile( "rb" );
if ( fp )
{
fclose(fp);
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: hint the engine to load HD content if possible, logic must match with engine/common.cpp BLoadHDContent
//-----------------------------------------------------------------------------
void COptionsSubVideo::SetUseHDContent( bool bUse )
{
if ( bUse )
{
FILE *fp = FOpenGameHDFile( "wb+" );
if ( fp )
{
fprintf( fp, "If this file exists on disk HD content will be loaded.\n" );
fclose( fp );
}
}
else
{
const char *pGameDir = engine->GetGameDirectory();
char szModSteamInfPath[ 1024 ];
V_ComposeFileName( pGameDir, "game_hd.txt", szModSteamInfPath, sizeof( szModSteamInfPath ) );
_unlink( szModSteamInfPath );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void COptionsSubVideo::OnResetData()
{
m_bRequireRestart = false;
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
// reset UI elements
#if defined( USE_SDL ) && defined( DX_TO_GL_ABSTRACTION )
int ItemIndex;
if ( config.Windowed() )
{
// Last item in the combobox is Windowed.
ItemIndex = ( m_pWindowed->GetItemCount() - 1 );
}
else
{
// Check which fullscreen displayindex is currently selected, and pick it.
ItemIndex = getSDLDisplayIndex();
if ( ( ItemIndex < 0 ) || ItemIndex >= ( m_pWindowed->GetItemCount() - 1 ) )
{
Assert( 0 );
ItemIndex = 0;
}
}
m_pWindowed->ActivateItem( ItemIndex );
#else
m_pWindowed->ActivateItem( config.Windowed() ? 1 : 0 );
#endif
// reset gamma control
m_pGammaButton->SetEnabled( !config.Windowed() );
m_pHDContent->SetSelected( BUseHDContent() );
SetCurrentResolutionComboItem();
bool bVREnabled = config.m_nVRModeAdapter != -1;
m_pVRMode->ActivateItem( bVREnabled ? 1 : 0 );
EnableOrDisableWindowedForVR();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void COptionsSubVideo::SetCurrentResolutionComboItem()
{
vmode_t *plist = NULL;
int count = 0;
gameuifuncs->GetVideoModes( &plist, &count );
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
int resolution = -1;
for ( int i = 0; i < count; i++, plist++ )
{
if ( plist->width == config.m_VideoMode.m_Width &&
plist->height == config.m_VideoMode.m_Height )
{
resolution = i;
break;
}
}
if (resolution != -1)
{
char sz[256];
int desktopWidth, desktopHeight;
gameuifuncs->GetDesktopResolution( desktopWidth, desktopHeight );
#if defined( USE_SDL )
SDL_Rect rect;
#if defined( DX_TO_GL_ABSTRACTION )
int displayIndex = getSDLDisplayIndex();
#else
int displayIndex = materials->GetCurrentAdapter();
#endif
if ( !SDL_GetDisplayBounds( displayIndex, &rect ) )
{
desktopWidth = rect.w;
desktopHeight = rect.h;
}
#endif
GetResolutionName( plist, sz, sizeof(sz), desktopWidth, desktopHeight );
m_pMode->SetText(sz);
}
}
//-----------------------------------------------------------------------------
// Purpose: restarts the game
//-----------------------------------------------------------------------------
void COptionsSubVideo::OnApplyChanges()
{
if ( RequiresRestart() )
{
INetChannelInfo *nci = engine->GetNetChannelInfo();
if ( nci )
{
// Only retry if we're not running the server
const char *pAddr = nci->GetAddress();
if ( pAddr )
{
if ( Q_strncmp(pAddr,"127.0.0.1",9) && Q_strncmp(pAddr,"localhost",9) )
{
engine->ClientCmd_Unrestricted( "retry\n" );
}
else
{
engine->ClientCmd_Unrestricted( "disconnect\n" );
}
}
}
}
// apply advanced options
if (m_hOptionsSubVideoAdvancedDlg.Get())
{
m_hOptionsSubVideoAdvancedDlg->ApplyChanges();
}
// resolution
char sz[256];
if ( m_nSelectedMode == -1 )
{
m_pMode->GetText( sz, 256 );
}
else
{
m_pMode->GetItemText( m_nSelectedMode, sz, 256 );
}
int width = 0, height = 0;
sscanf( sz, "%i x %i", &width, &height );
// windowed
bool bConfigChanged = false;
bool windowed = ( m_pWindowed->GetActiveItem() == ( m_pWindowed->GetItemCount() - 1 ) ) ? true : false;
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
bool bVRMode = m_pVRMode->GetActiveItem() != 0;
if( ( -1 != config.m_nVRModeAdapter ) != bVRMode )
{
// let engine fill in mat_vrmode_adapter
char szCmd[256];
Q_snprintf( szCmd, sizeof(szCmd), "mat_enable_vrmode %d\n", bVRMode ? 1 : 0 );
engine->ClientCmd_Unrestricted( szCmd );
// force windowed. VR mode ignores this flag and desktop mode needs to be in a window always
windowed = bVRMode;
}
// make sure there is a change
if ( config.m_VideoMode.m_Width != width
|| config.m_VideoMode.m_Height != height
|| config.Windowed() != windowed )
{
bConfigChanged = true;
}
#if defined( USE_SDL )
if ( !windowed )
{
SDL_Rect rect;
int displayIndexTarget = m_pWindowed->GetActiveItem();
int displayIndexCurrent = getSDLDisplayIndexFullscreen();
// Handle going fullscreen from display X to display Y.
if ( displayIndexCurrent != displayIndexTarget )
{
static ConVarRef sdl_displayindex( "sdl_displayindex" );
if ( sdl_displayindex.IsValid() )
{
// Set the displayindex we want to go fullscreen on now.
sdl_displayindex.SetValue( displayIndexTarget );
bConfigChanged = true;
}
}
if ( !SDL_GetDisplayBounds( displayIndexTarget, &rect ) )
{
// If we are going non-native fullscreen, tweak the resolution to have the same aspect ratio as the display.
if ( ( width != rect.w ) || ( height != rect.h ) )
{
// TODO: We may want a convar to allow folks to mess with their aspect ratio?
height = ( width * rect.h ) / rect.w;
bConfigChanged = true;
}
}
}
#endif // USE_SDL
if ( bConfigChanged )
{
// set mode
char szCmd[ 256 ];
Q_snprintf( szCmd, sizeof( szCmd ), "mat_setvideomode %i %i %i\n", width, height, windowed ? 1 : 0 );
engine->ClientCmd_Unrestricted( szCmd );
}
if ( ModInfo().HasHDContent() )
{
if ( BUseHDContent() != m_pHDContent->IsSelected() )
{
SetUseHDContent( m_pHDContent->IsSelected() );
// Bring up the confirmation dialog
MessageBox *box = new MessageBox("#GameUI_OptionsRestartRequired_Title", "#GameUI_HDRestartRequired_Info");
box->DoModal();
box->MoveToFront();
}
}
// apply changes
engine->ClientCmd_Unrestricted( "mat_savechanges\n" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void COptionsSubVideo::PerformLayout()
{
BaseClass::PerformLayout();
if ( m_pGammaButton )
{
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
m_pGammaButton->SetEnabled( !config.Windowed() );
}
}
//-----------------------------------------------------------------------------
// Purpose: enables apply button on data changing
//-----------------------------------------------------------------------------
void COptionsSubVideo::OnTextChanged(Panel *pPanel, const char *pszText)
{
if (pPanel == m_pMode)
{
const MaterialSystem_Config_t &config = materials->GetCurrentConfigForVideoCard();
m_nSelectedMode = m_pMode->GetActiveItem();
int w = 0, h = 0;
sscanf(pszText, "%i x %i", &w, &h);
if ( config.m_VideoMode.m_Width != w || config.m_VideoMode.m_Height != h )
{
OnDataChanged();
}
}
else if (pPanel == m_pAspectRatio)
{
PrepareResolutionList();
}
else if (pPanel == m_pWindowed)
{
PrepareResolutionList();
OnDataChanged();
}
else if ( pPanel == m_pVRMode )
{
if ( !m_bDisplayedVRModeMessage )
{
bool bVRNowEnabled = m_pVRMode->GetActiveItem() == 1;
bool bVRWasEnabled = materials->GetCurrentConfigForVideoCard().m_nVRModeAdapter != -1;
if( bVRWasEnabled != bVRNowEnabled )
{
m_bDisplayedVRModeMessage = true;
MessageBox *box = new MessageBox( "#GameUI_VRMode", "#GameUI_VRModeRelaunchMsg", this );
box->MoveToFront();
box->DoModal();
}
}
EnableOrDisableWindowedForVR();
}
}
//-----------------------------------------------------------------------------
// Purpose: enables windowed combo box
//-----------------------------------------------------------------------------
void COptionsSubVideo::EnableOrDisableWindowedForVR()
{
bool bCanBeEnabled = g_pSourceVR && g_pSourceVR->IsHmdConnected();
bool bVRNowEnabled = m_pVRMode->GetActiveItem() == 1;
bool bVRWasEnabled = materials->GetCurrentConfigForVideoCard().m_nVRModeAdapter != -1;
if( bCanBeEnabled && ( bVRNowEnabled || bVRWasEnabled ) )
{
m_pWindowed->SetEnabled( false );
m_pWindowed->ActivateItem( m_pWindowed->GetItemCount() - 1 );
m_pWindowed->GetTooltip()->SetText( "#GameUI_WindowedTooltip" );
}
else
{
m_pWindowed->SetEnabled( true );
}
}
//-----------------------------------------------------------------------------
// Purpose: enables apply button
//-----------------------------------------------------------------------------
void COptionsSubVideo::OnDataChanged()
{
PostActionSignal(new KeyValues("ApplyButtonEnable"));
}
//-----------------------------------------------------------------------------
// Purpose: Checks to see if the changes requires a restart to take effect
//-----------------------------------------------------------------------------
bool COptionsSubVideo::RequiresRestart()
{
if ( m_hOptionsSubVideoAdvancedDlg.Get()
&& m_hOptionsSubVideoAdvancedDlg->RequiresRestart() )
{
return true;
}
// make sure there is a change
return m_bRequireRestart;
}
//-----------------------------------------------------------------------------
// Purpose: Opens advanced video mode options dialog
//-----------------------------------------------------------------------------
void COptionsSubVideo::OpenAdvanced()
{
if ( !m_hOptionsSubVideoAdvancedDlg.Get() )
{
m_hOptionsSubVideoAdvancedDlg = new COptionsSubVideoAdvancedDlg( BasePanel()->FindChildByName( "OptionsDialog" ) ); // we'll parent this to the OptionsDialog directly
}
m_hOptionsSubVideoAdvancedDlg->Activate();
}
//-----------------------------------------------------------------------------
// Purpose: Opens gamma-adjusting dialog
//-----------------------------------------------------------------------------
void COptionsSubVideo::OpenGammaDialog()
{
if ( !m_hGammaDialog.Get() )
{
m_hGammaDialog = new CGammaDialog( GetVParent() );
}
m_hGammaDialog->Activate();
}
//-----------------------------------------------------------------------------
// Purpose: Opens benchmark dialog
//-----------------------------------------------------------------------------
void COptionsSubVideo::LaunchBenchmark()
{
BasePanel()->OnOpenBenchmarkDialog();
}
//-----------------------------------------------------------------------------
// Purpose: third-party audio credits dialog
//-----------------------------------------------------------------------------
class COptionsSubVideoThirdPartyCreditsDlg : public vgui::Frame
{
DECLARE_CLASS_SIMPLE( COptionsSubVideoThirdPartyCreditsDlg, vgui::Frame );
public:
COptionsSubVideoThirdPartyCreditsDlg( vgui::VPANEL hParent ) : BaseClass( NULL, NULL )
{
// parent is ignored, since we want look like we're steal focus from the parent (we'll become modal below)
SetTitle("#GameUI_ThirdPartyVideo_Title", true);
SetSize( 500, 200 );
LoadControlSettings( "resource/OptionsSubVideoThirdPartyDlg.res" );
MoveToCenterOfScreen();
SetSizeable( false );
SetDeleteSelfOnClose( true );
}
virtual void Activate()
{
BaseClass::Activate();
input()->SetAppModalSurface(GetVPanel());
}
void OnKeyCodeTyped(KeyCode code)
{
// force ourselves to be closed if the escape key it pressed
if (code == KEY_ESCAPE)
{
Close();
}
else
{
BaseClass::OnKeyCodeTyped(code);
}
}
};
//-----------------------------------------------------------------------------
// Purpose: Open third party audio credits dialog
//-----------------------------------------------------------------------------
void COptionsSubVideo::OpenThirdPartyVideoCreditsDialog()
{
if (!m_OptionsSubVideoThirdPartyCreditsDlg.Get())
{
m_OptionsSubVideoThirdPartyCreditsDlg = new COptionsSubVideoThirdPartyCreditsDlg(GetVParent());
}
m_OptionsSubVideoThirdPartyCreditsDlg->Activate();
}
|