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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#define DISABLE_PROTECTED_THINGS
#include "togl/rendermechanism.h"
#include "shaderdevicebase.h"
#include "tier1/KeyValues.h"
#include "tier1/convar.h"
#include "tier1/utlbuffer.h"
#include "tier0/icommandline.h"
#include "tier2/tier2.h"
#include "filesystem.h"
#include "datacache/idatacache.h"
#include "shaderapi/ishaderutil.h"
#include "shaderapibase.h"
#include "shaderapi/ishadershadow.h"
#include "shaderapi_global.h"
#include "winutils.h"
#ifdef _X360
#include "xbox/xbox_win32stubs.h"
#endif
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
IShaderUtil* g_pShaderUtil; // The main shader utility interface
CShaderDeviceBase *g_pShaderDevice;
CShaderDeviceMgrBase *g_pShaderDeviceMgr;
CShaderAPIBase *g_pShaderAPI;
IShaderShadow *g_pShaderShadow;
bool g_bUseShaderMutex = false; // Shader mutex globals
bool g_bShaderAccessDisallowed;
CShaderMutex g_ShaderMutex;
//-----------------------------------------------------------------------------
// FIXME: Hack related to setting command-line values for convars. Remove!!!
//-----------------------------------------------------------------------------
class CShaderAPIConVarAccessor : public IConCommandBaseAccessor
{
public:
virtual bool RegisterConCommandBase( ConCommandBase *pCommand )
{
// Link to engine's list instead
g_pCVar->RegisterConCommand( pCommand );
char const *pValue = g_pCVar->GetCommandLineValue( pCommand->GetName() );
if( pValue && !pCommand->IsCommand() )
{
( ( ConVar * )pCommand )->SetValue( pValue );
}
return true;
}
};
static void InitShaderAPICVars( )
{
static CShaderAPIConVarAccessor g_ConVarAccessor;
if ( g_pCVar )
{
ConVar_Register( FCVAR_MATERIAL_SYSTEM_THREAD, &g_ConVarAccessor );
}
}
//-----------------------------------------------------------------------------
// Read dx support levels
//-----------------------------------------------------------------------------
#if defined( DX_TO_GL_ABSTRACTION )
#if defined( OSX )
// OSX
#define SUPPORT_CFG_FILE "dxsupport_mac.cfg"
// TODO: make this different for Mac?
#define SUPPORT_CFG_OVERRIDE_FILE "dxsupport_override.cfg"
#else
// Linux/Win GL
#define SUPPORT_CFG_FILE "dxsupport_linux.cfg"
// TODO: make this different for Linux?
#define SUPPORT_CFG_OVERRIDE_FILE "dxsupport_override.cfg"
#endif
#else
// D3D
#define SUPPORT_CFG_FILE "dxsupport.cfg"
#define SUPPORT_CFG_OVERRIDE_FILE "dxsupport_override.cfg"
#endif
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CShaderDeviceMgrBase::CShaderDeviceMgrBase()
{
m_pDXSupport = NULL;
}
CShaderDeviceMgrBase::~CShaderDeviceMgrBase()
{
}
//-----------------------------------------------------------------------------
// Factory used to get at internal interfaces (used by shaderapi + shader dlls)
//-----------------------------------------------------------------------------
static CreateInterfaceFn s_TempFactory;
void *ShaderDeviceFactory( const char *pName, int *pReturnCode )
{
if (pReturnCode)
{
*pReturnCode = IFACE_OK;
}
void *pInterface = s_TempFactory( pName, pReturnCode );
if ( pInterface )
return pInterface;
pInterface = Sys_GetFactoryThis()( pName, pReturnCode );
if ( pInterface )
return pInterface;
if ( pReturnCode )
{
*pReturnCode = IFACE_FAILED;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Connect, disconnect
//-----------------------------------------------------------------------------
bool CShaderDeviceMgrBase::Connect( CreateInterfaceFn factory )
{
LOCK_SHADERAPI();
Assert( !g_pShaderDeviceMgr );
s_TempFactory = factory;
// Connection/convar registration
CreateInterfaceFn actualFactory = ShaderDeviceFactory;
ConnectTier1Libraries( &actualFactory, 1 );
InitShaderAPICVars();
ConnectTier2Libraries( &actualFactory, 1 );
g_pShaderUtil = (IShaderUtil*)ShaderDeviceFactory( SHADER_UTIL_INTERFACE_VERSION, NULL );
g_pShaderDeviceMgr = this;
s_TempFactory = NULL;
if ( !g_pShaderUtil || !g_pFullFileSystem || !g_pShaderDeviceMgr )
{
Warning( "ShaderAPIDx10 was unable to access the required interfaces!\n" );
return false;
}
// NOTE! : Overbright is 1.0 so that Hammer will work properly with the white bumped and unbumped lightmaps.
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
return true;
}
void CShaderDeviceMgrBase::Disconnect()
{
LOCK_SHADERAPI();
g_pShaderDeviceMgr = NULL;
g_pShaderUtil = NULL;
DisconnectTier2Libraries();
ConVar_Unregister();
DisconnectTier1Libraries();
if ( m_pDXSupport )
{
m_pDXSupport->deleteThis();
m_pDXSupport = NULL;
}
}
//-----------------------------------------------------------------------------
// Query interface
//-----------------------------------------------------------------------------
void *CShaderDeviceMgrBase::QueryInterface( const char *pInterfaceName )
{
if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_MGR_INTERFACE_VERSION ) )
return ( IShaderDeviceMgr* )this;
if ( !Q_stricmp( pInterfaceName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) )
return ( IMaterialSystemHardwareConfig* )g_pHardwareConfig;
return NULL;
}
//-----------------------------------------------------------------------------
// Returns the hardware caps for a particular adapter
//-----------------------------------------------------------------------------
const HardwareCaps_t& CShaderDeviceMgrBase::GetHardwareCaps( int nAdapter ) const
{
Assert( ( nAdapter >= 0 ) && ( nAdapter < GetAdapterCount() ) );
return m_Adapters[nAdapter].m_ActualCaps;
}
//-----------------------------------------------------------------------------
// Utility methods for reading config scripts
//-----------------------------------------------------------------------------
static inline int ReadHexValue( KeyValues *pVal, const char *pName )
{
const char *pString = pVal->GetString( pName, NULL );
if (!pString)
{
return -1;
}
char *pTemp;
int nVal = strtol( pString, &pTemp, 16 );
return (pTemp != pString) ? nVal : -1;
}
static bool ReadBool( KeyValues *pGroup, const char *pKeyName, bool bDefault )
{
int nVal = pGroup->GetInt( pKeyName, -1 );
if ( nVal != -1 )
{
// Warning( "\t%s = %s\n", pKeyName, (nVal != false) ? "true" : "false" );
return (nVal != false);
}
return bDefault;
}
static void ReadInt( KeyValues *pGroup, const char *pKeyName, int nInvalidValue, int *pResult )
{
int nVal = pGroup->GetInt( pKeyName, nInvalidValue );
if ( nVal != nInvalidValue )
{
*pResult = nVal;
// Warning( "\t%s = %d\n", pKeyName, *pResult );
}
}
//-----------------------------------------------------------------------------
// Utility method to copy over a keyvalue
//-----------------------------------------------------------------------------
static void AddKey( KeyValues *pDest, KeyValues *pSrc )
{
// Note this will replace already-existing values
switch( pSrc->GetDataType() )
{
case KeyValues::TYPE_NONE:
break;
case KeyValues::TYPE_STRING:
pDest->SetString( pSrc->GetName(), pSrc->GetString() );
break;
case KeyValues::TYPE_INT:
pDest->SetInt( pSrc->GetName(), pSrc->GetInt() );
break;
case KeyValues::TYPE_FLOAT:
pDest->SetFloat( pSrc->GetName(), pSrc->GetFloat() );
break;
case KeyValues::TYPE_PTR:
pDest->SetPtr( pSrc->GetName(), pSrc->GetPtr() );
break;
case KeyValues::TYPE_WSTRING:
pDest->SetWString( pSrc->GetName(), pSrc->GetWString() );
break;
case KeyValues::TYPE_COLOR:
pDest->SetColor( pSrc->GetName(), pSrc->GetColor() );
break;
default:
Assert( 0 );
break;
}
}
//-----------------------------------------------------------------------------
// Finds if we have a dxlevel-specific config in the support keyvalues
//-----------------------------------------------------------------------------
KeyValues *CShaderDeviceMgrBase::FindDXLevelSpecificConfig( KeyValues *pKeyValues, int nDxLevel )
{
KeyValues *pGroup = pKeyValues->GetFirstSubKey();
for( pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
int nFoundDxLevel = pGroup->GetInt( "name", 0 );
if( nFoundDxLevel == nDxLevel )
return pGroup;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Finds if we have a dxlevel and vendor-specific config in the support keyvalues
//-----------------------------------------------------------------------------
KeyValues *CShaderDeviceMgrBase::FindDXLevelAndVendorSpecificConfig( KeyValues *pKeyValues, int nDxLevel, int nVendorID )
{
if ( IsX360() )
{
// 360 unique dxlevel implies hw config, vendor variance not applicable
return NULL;
}
KeyValues *pGroup = pKeyValues->GetFirstSubKey();
for( pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
int nFoundDxLevel = pGroup->GetInt( "name", 0 );
int nFoundVendorID = ReadHexValue( pGroup, "VendorID" );
if( nFoundDxLevel == nDxLevel && nFoundVendorID == nVendorID )
return pGroup;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Finds if we have a vendor-specific config in the support keyvalues
//-----------------------------------------------------------------------------
KeyValues *CShaderDeviceMgrBase::FindCPUSpecificConfig( KeyValues *pKeyValues, int nCPUMhz, bool bAMD )
{
if ( IsX360() )
{
// 360 unique dxlevel implies hw config, cpu variance not applicable
return NULL;
}
for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
const char *pName = pGroup->GetString( "name", NULL );
if ( !pName )
continue;
if ( ( bAMD && Q_stristr( pName, "AMD" ) ) ||
( !bAMD && Q_stristr( pName, "Intel" ) ) )
{
int nMinMegahertz = pGroup->GetInt( "min megahertz", -1 );
int nMaxMegahertz = pGroup->GetInt( "max megahertz", -1 );
if( nMinMegahertz == -1 || nMaxMegahertz == -1 )
continue;
if( nMinMegahertz <= nCPUMhz && nCPUMhz < nMaxMegahertz )
return pGroup;
}
}
return NULL;
}
//-----------------------------------------------------------------------------
// Finds if we have a vendor-specific config in the support keyvalues
//-----------------------------------------------------------------------------
KeyValues *CShaderDeviceMgrBase::FindCardSpecificConfig( KeyValues *pKeyValues, int nVendorId, int nDeviceId )
{
if ( IsX360() )
{
// 360 unique dxlevel implies hw config, vendor variance not applicable
return NULL;
}
KeyValues *pGroup = pKeyValues->GetFirstSubKey();
for( pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
int nFoundVendorId = ReadHexValue( pGroup, "VendorID" );
int nFoundDeviceIdMin = ReadHexValue( pGroup, "MinDeviceID" );
int nFoundDeviceIdMax = ReadHexValue( pGroup, "MaxDeviceID" );
if ( nFoundVendorId == nVendorId && nDeviceId >= nFoundDeviceIdMin && nDeviceId <= nFoundDeviceIdMax )
return pGroup;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Finds if we have a vendor-specific config in the support keyvalues
//-----------------------------------------------------------------------------
KeyValues *CShaderDeviceMgrBase::FindMemorySpecificConfig( KeyValues *pKeyValues, int nSystemRamMB )
{
if ( IsX360() )
{
// 360 unique dxlevel implies hw config, memory variance not applicable
return NULL;
}
for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
// Used to help us debug this code
// const char *pDebugName = pGroup->GetString( "name", "blah" );
int nMinMB = pGroup->GetInt( "min megabytes", -1 );
int nMaxMB = pGroup->GetInt( "max megabytes", -1 );
if ( nMinMB == -1 || nMaxMB == -1 )
continue;
if ( nMinMB <= nSystemRamMB && nSystemRamMB < nMaxMB )
return pGroup;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Finds if we have a texture mem size specific config
//-----------------------------------------------------------------------------
KeyValues *CShaderDeviceMgrBase::FindVidMemSpecificConfig( KeyValues *pKeyValues, int nVideoRamMB )
{
if ( IsX360() )
{
// 360 unique dxlevel implies hw config, vidmem variance not applicable
return NULL;
}
for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
int nMinMB = pGroup->GetInt( "min megatexels", -1 );
int nMaxMB = pGroup->GetInt( "max megatexels", -1 );
if ( nMinMB == -1 || nMaxMB == -1 )
continue;
if ( nMinMB <= nVideoRamMB && nVideoRamMB < nMaxMB )
return pGroup;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Methods related to reading DX support levels given particular devices
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Reads in the dxsupport.cfg keyvalues
//-----------------------------------------------------------------------------
static void OverrideValues_R( KeyValues *pDest, KeyValues *pSrc )
{
// Any same-named values get overridden in pDest.
for ( KeyValues *pSrcValue=pSrc->GetFirstValue(); pSrcValue; pSrcValue=pSrcValue->GetNextValue() )
{
// Shouldn't be a container for more keys.
Assert( pSrcValue->GetDataType() != KeyValues::TYPE_NONE );
AddKey( pDest, pSrcValue );
}
// Recurse.
for ( KeyValues *pSrcDir=pSrc->GetFirstTrueSubKey(); pSrcDir; pSrcDir=pSrcDir->GetNextTrueSubKey() )
{
Assert( pSrcDir->GetDataType() == KeyValues::TYPE_NONE );
KeyValues *pDestDir = pDest->FindKey( pSrcDir->GetName() );
if ( pDestDir && pDestDir->GetDataType() == KeyValues::TYPE_NONE )
{
OverrideValues_R( pDestDir, pSrcDir );
}
}
}
static KeyValues * FindMatchingGroup( KeyValues *pSrc, KeyValues *pMatch )
{
KeyValues *pMatchSubKey = pMatch->FindKey( "name" );
bool bHasSubKey = ( pMatchSubKey && ( pMatchSubKey->GetDataType() != KeyValues::TYPE_NONE ) );
const char *name = bHasSubKey ? pMatchSubKey->GetString() : NULL;
int nMatchVendorID = ReadHexValue( pMatch, "VendorID" );
int nMatchMinDeviceID = ReadHexValue( pMatch, "MinDeviceID" );
int nMatchMaxDeviceID = ReadHexValue( pMatch, "MaxDeviceID" );
KeyValues *pSrcGroup = NULL;
for ( pSrcGroup = pSrc->GetFirstTrueSubKey(); pSrcGroup; pSrcGroup = pSrcGroup->GetNextTrueSubKey() )
{
if ( name )
{
KeyValues *pSrcGroupName = pSrcGroup->FindKey( "name" );
Assert( pSrcGroupName );
Assert( pSrcGroupName->GetDataType() != KeyValues::TYPE_NONE );
if ( Q_stricmp( pSrcGroupName->GetString(), name ) )
continue;
}
if ( nMatchVendorID >= 0 )
{
int nVendorID = ReadHexValue( pSrcGroup, "VendorID" );
if ( nMatchVendorID != nVendorID )
continue;
}
if ( nMatchMinDeviceID >= 0 && nMatchMaxDeviceID >= 0 )
{
int nMinDeviceID = ReadHexValue( pSrcGroup, "MinDeviceID" );
int nMaxDeviceID = ReadHexValue( pSrcGroup, "MaxDeviceID" );
if ( nMinDeviceID < 0 || nMaxDeviceID < 0 )
continue;
if ( nMatchMinDeviceID > nMinDeviceID || nMatchMaxDeviceID < nMaxDeviceID )
continue;
}
return pSrcGroup;
}
return NULL;
}
static void OverrideKeyValues( KeyValues *pDst, KeyValues *pSrc )
{
KeyValues *pSrcGroup = NULL;
for ( pSrcGroup = pSrc->GetFirstTrueSubKey(); pSrcGroup; pSrcGroup = pSrcGroup->GetNextTrueSubKey() )
{
// Match each group in pSrc to one in pDst containing the same "name" value:
KeyValues * pDstGroup = FindMatchingGroup( pDst, pSrcGroup );
//Assert( pDstGroup );
if ( pDstGroup )
{
OverrideValues_R( pDstGroup, pSrcGroup );
}
}
// if( CommandLine()->FindParm( "-debugdxsupport" ) )
// {
// CUtlBuffer tmpBuf;
// pDst->RecursiveSaveToFile( tmpBuf, 0 );
// g_pFullFileSystem->WriteFile( "gary.txt", NULL, tmpBuf );
// }
}
KeyValues *CShaderDeviceMgrBase::ReadDXSupportKeyValues()
{
if ( CommandLine()->CheckParm( "-ignoredxsupportcfg" ) )
return NULL;
if ( m_pDXSupport )
return m_pDXSupport;
KeyValues *pCfg = new KeyValues( "dxsupport" );
const char *pPathID = "EXECUTABLE_PATH";
if ( IsX360() && g_pFullFileSystem->GetDVDMode() == DVDMODE_STRICT )
{
// 360 dvd optimzation, expect it inside the platform zip
pPathID = "PLATFORM";
}
// First try to read a game-specific config, if it exists
if ( !pCfg->LoadFromFile( g_pFullFileSystem, SUPPORT_CFG_FILE, pPathID ) )
{
pCfg->deleteThis();
return NULL;
}
char pTempPath[1024];
if ( g_pFullFileSystem->GetSearchPath( "GAME", false, pTempPath, sizeof(pTempPath) ) > 1 )
{
// Is there a mod-specific override file?
KeyValues *pOverride = new KeyValues( "dxsupport_override" );
if ( pOverride->LoadFromFile( g_pFullFileSystem, SUPPORT_CFG_OVERRIDE_FILE, "GAME" ) )
{
OverrideKeyValues( pCfg, pOverride );
}
pOverride->deleteThis();
}
m_pDXSupport = pCfg;
return pCfg;
}
//-----------------------------------------------------------------------------
// Returns the max dx support level achievable with this board
//-----------------------------------------------------------------------------
void CShaderDeviceMgrBase::ReadDXSupportLevels( HardwareCaps_t &caps )
{
// See if the file tells us otherwise
KeyValues *pCfg = ReadDXSupportKeyValues();
if ( !pCfg )
return;
KeyValues *pDeviceKeyValues = FindCardSpecificConfig( pCfg, caps.m_VendorID, caps.m_DeviceID );
if ( pDeviceKeyValues )
{
// First, set the max dx level
int nMaxDXSupportLevel = 0;
ReadInt( pDeviceKeyValues, "MaxDXLevel", 0, &nMaxDXSupportLevel );
if ( nMaxDXSupportLevel != 0 )
{
caps.m_nMaxDXSupportLevel = nMaxDXSupportLevel;
}
// Next, set the preferred dx level
int nDXSupportLevel = 0;
ReadInt( pDeviceKeyValues, "DXLevel", 0, &nDXSupportLevel );
if ( nDXSupportLevel != 0 )
{
caps.m_nDXSupportLevel = nDXSupportLevel;
// Don't slam up the dxlevel level to 92 on DX10 cards in OpenGL Linux/Win mode (otherwise Intel will get dxlevel 92 when we want 90)
if ( !( IsOpenGL() && ( IsLinux() || IsWindows() ) ) )
{
if ( caps.m_bDX10Card )
{
caps.m_nDXSupportLevel = 92;
}
}
}
else
{
caps.m_nDXSupportLevel = caps.m_nMaxDXSupportLevel;
}
}
}
//-----------------------------------------------------------------------------
// Loads the hardware caps, for cases in which the D3D caps lie or where we need to augment the caps
//-----------------------------------------------------------------------------
void CShaderDeviceMgrBase::LoadHardwareCaps( KeyValues *pGroup, HardwareCaps_t &caps )
{
if( !pGroup )
return;
// don't just blanket kill clip planes on POSIX, only shoot them down if we're running ARB, or asked for nouserclipplanes.
//FIXME need to take into account the caps bit that GLM can now provide, so NV can use normal clipping and ATI can fall back to fastclip.
if ( CommandLine()->FindParm("-arbmode") || CommandLine()->CheckParm( "-nouserclip" ) )
{
caps.m_UseFastClipping = true;
}
else
{
caps.m_UseFastClipping = ReadBool( pGroup, "NoUserClipPlanes", caps.m_UseFastClipping );
}
caps.m_bNeedsATICentroidHack = ReadBool( pGroup, "CentroidHack", caps.m_bNeedsATICentroidHack );
caps.m_bDisableShaderOptimizations = ReadBool( pGroup, "DisableShaderOptimizations", caps.m_bDisableShaderOptimizations );
}
//-----------------------------------------------------------------------------
// Reads in the hardware caps from the dxsupport.cfg file
//-----------------------------------------------------------------------------
void CShaderDeviceMgrBase::ReadHardwareCaps( HardwareCaps_t &caps, int nDxLevel )
{
KeyValues *pCfg = ReadDXSupportKeyValues();
if ( !pCfg )
return;
// Next, read the hardware caps for that dx support level.
KeyValues *pDxLevelKeyValues = FindDXLevelSpecificConfig( pCfg, nDxLevel );
// Look for a vendor specific line for a given dxlevel.
KeyValues *pDXLevelAndVendorKeyValue = FindDXLevelAndVendorSpecificConfig( pCfg, nDxLevel, caps.m_VendorID );
// Finally, override the hardware caps based on the specific card
KeyValues *pCardKeyValues = FindCardSpecificConfig( pCfg, caps.m_VendorID, caps.m_DeviceID );
// Apply
if( pCardKeyValues && ReadHexValue( pCardKeyValues, "MinDeviceID" ) == 0 && ReadHexValue( pCardKeyValues, "MaxDeviceID" ) == 0xffff )
{
// The card specific case is a catch all for device ids, so run it before running the dxlevel and card specific stuff.
LoadHardwareCaps( pDxLevelKeyValues, caps );
LoadHardwareCaps( pCardKeyValues, caps );
LoadHardwareCaps( pDXLevelAndVendorKeyValue, caps );
}
else
{
// The card specific case is a small range of cards, so run it last to override all other configs.
LoadHardwareCaps( pDxLevelKeyValues, caps );
// don't run this one since we have a specific config for this card.
// LoadHardwareCaps( pDXLevelAndVendorKeyValue, caps );
LoadHardwareCaps( pCardKeyValues, caps );
}
}
//-----------------------------------------------------------------------------
// Reads in ConVars + config variables
//-----------------------------------------------------------------------------
void CShaderDeviceMgrBase::LoadConfig( KeyValues *pKeyValues, KeyValues *pConfiguration )
{
if( !pKeyValues )
return;
if( CommandLine()->FindParm( "-debugdxsupport" ) )
{
CUtlBuffer tmpBuf;
pKeyValues->RecursiveSaveToFile( tmpBuf, 0 );
Warning( "%s\n", ( const char * )tmpBuf.Base() );
}
for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() )
{
AddKey( pConfiguration, pGroup );
}
}
//-----------------------------------------------------------------------------
// Computes amount of ram
//-----------------------------------------------------------------------------
static unsigned long GetRam()
{
MEMORYSTATUS stat;
GlobalMemoryStatus( &stat );
char buf[256];
V_snprintf( buf, sizeof( buf ), "GlobalMemoryStatus: %llu\n", (uint64)(stat.dwTotalPhys) );
Plat_DebugString( buf );
return (stat.dwTotalPhys / (1024 * 1024));
}
//-----------------------------------------------------------------------------
// Gets the recommended configuration associated with a particular dx level
//-----------------------------------------------------------------------------
bool CShaderDeviceMgrBase::GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, int nVendorID, int nDeviceID, KeyValues *pConfiguration )
{
LOCK_SHADERAPI();
const HardwareCaps_t& caps = GetHardwareCaps( nAdapter );
if ( nDXLevel == 0 )
{
nDXLevel = caps.m_nDXSupportLevel;
}
nDXLevel = GetClosestActualDXLevel( nDXLevel );
if ( nDXLevel > caps.m_nMaxDXSupportLevel )
return false;
KeyValues *pCfg = ReadDXSupportKeyValues();
if ( !pCfg )
return true;
// Look for a dxlevel specific line
KeyValues *pDxLevelKeyValues = FindDXLevelSpecificConfig( pCfg, nDXLevel );
// Look for a vendor specific line for a given dxlevel.
KeyValues *pDXLevelAndVendorKeyValue = FindDXLevelAndVendorSpecificConfig( pCfg, nDXLevel, nVendorID );
// Next, override with device-specific overrides
KeyValues *pCardKeyValues = FindCardSpecificConfig( pCfg, nVendorID, nDeviceID );
// Apply
if ( pCardKeyValues && ReadHexValue( pCardKeyValues, "MinDeviceID" ) == 0 && ReadHexValue( pCardKeyValues, "MaxDeviceID" ) == 0xffff )
{
// The card specific case is a catch all for device ids, so run it before running the dxlevel and card specific stuff.
LoadConfig( pDxLevelKeyValues, pConfiguration );
LoadConfig( pCardKeyValues, pConfiguration );
LoadConfig( pDXLevelAndVendorKeyValue, pConfiguration );
}
else
{
// The card specific case is a small range of cards, so run it last to override all other configs.
LoadConfig( pDxLevelKeyValues, pConfiguration );
// don't run this one since we have a specific config for this card.
// LoadConfig( pDXLevelAndVendorKeyValue, pConfiguration );
LoadConfig( pCardKeyValues, pConfiguration );
}
// Next, override with cpu-speed based overrides
const CPUInformation& pi = *GetCPUInformation();
int nCPUSpeedMhz = (int)(pi.m_Speed / 1000000.0f);
bool bAMD = Q_stristr( pi.m_szProcessorID, "amd" ) != NULL;
char buf[256];
V_snprintf( buf, sizeof( buf ), "CShaderDeviceMgrBase::GetRecommendedConfigurationInfo: CPU speed: %d MHz, Processor: %s\n", nCPUSpeedMhz, pi.m_szProcessorID );
Plat_DebugString( buf );
KeyValues *pCPUKeyValues = FindCPUSpecificConfig( pCfg, nCPUSpeedMhz, bAMD );
LoadConfig( pCPUKeyValues, pConfiguration );
// override with system memory-size based overrides
int nSystemMB = GetRam();
DevMsg( "%d MB of system RAM\n", nSystemMB );
KeyValues *pMemoryKeyValues = FindMemorySpecificConfig( pCfg, nSystemMB );
LoadConfig( pMemoryKeyValues, pConfiguration );
// override with texture memory-size based overrides
int nTextureMemorySize = GetVidMemBytes( nAdapter );
int vidMemMB = nTextureMemorySize / ( 1024 * 1024 );
KeyValues *pVidMemKeyValues = FindVidMemSpecificConfig( pCfg, vidMemMB );
if ( pVidMemKeyValues && nTextureMemorySize > 0 )
{
if ( CommandLine()->FindParm( "-debugdxsupport" ) )
{
CUtlBuffer tmpBuf;
pVidMemKeyValues->RecursiveSaveToFile( tmpBuf, 0 );
Warning( "pVidMemKeyValues\n%s\n", ( const char * )tmpBuf.Base() );
}
KeyValues *pMatPicmipKeyValue = pVidMemKeyValues->FindKey( "ConVar.mat_picmip", false );
// FIXME: Man, is this brutal. If it wasn't 1 day till orange box ship, I'd do something in dxsupport maybe
if ( pMatPicmipKeyValue && ( ( nDXLevel == caps.m_nMaxDXSupportLevel ) || ( vidMemMB < 100 ) ) )
{
KeyValues *pConfigMatPicMip = pConfiguration->FindKey( "ConVar.mat_picmip", false );
int newPicMip = pMatPicmipKeyValue->GetInt();
int oldPicMip = pConfigMatPicMip ? pConfigMatPicMip->GetInt() : 0;
pConfiguration->SetInt( "ConVar.mat_picmip", max( newPicMip, oldPicMip ) );
}
}
// Hack to slam the mat_dxlevel ConVar to match the requested dxlevel
pConfiguration->SetInt( "ConVar.mat_dxlevel", nDXLevel );
if ( CommandLine()->FindParm( "-debugdxsupport" ) )
{
CUtlBuffer tmpBuf;
pConfiguration->RecursiveSaveToFile( tmpBuf, 0 );
Warning( "final config:\n%s\n", ( const char * )tmpBuf.Base() );
}
return true;
}
//-----------------------------------------------------------------------------
// Gets recommended congifuration for a particular adapter at a particular dx level
//-----------------------------------------------------------------------------
bool CShaderDeviceMgrBase::GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pCongifuration )
{
Assert( nAdapter >= 0 && nAdapter <= GetAdapterCount() );
MaterialAdapterInfo_t info;
GetAdapterInfo( nAdapter, info );
return GetRecommendedConfigurationInfo( nAdapter, nDXLevel, info.m_VendorID, info.m_DeviceID, pCongifuration );
}
//-----------------------------------------------------------------------------
// Returns only valid dx levels
//-----------------------------------------------------------------------------
int CShaderDeviceMgrBase::GetClosestActualDXLevel( int nDxLevel ) const
{
if ( nDxLevel < ABSOLUTE_MINIMUM_DXLEVEL )
return ABSOLUTE_MINIMUM_DXLEVEL;
if ( nDxLevel == 80 )
return 80;
if ( nDxLevel <= 89 )
return 81;
if ( IsOpenGL() )
{
return ( nDxLevel <= 90 ) ? 90 : 92;
}
if ( nDxLevel <= 94 )
return 90;
if ( IsX360() && nDxLevel <= 98 )
return 98;
if ( nDxLevel <= 99 )
return 95;
return 100;
}
//-----------------------------------------------------------------------------
// Mode change callback
//-----------------------------------------------------------------------------
void CShaderDeviceMgrBase::AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func )
{
LOCK_SHADERAPI();
Assert( func && m_ModeChangeCallbacks.Find( func ) < 0 );
m_ModeChangeCallbacks.AddToTail( func );
}
void CShaderDeviceMgrBase::RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func )
{
LOCK_SHADERAPI();
m_ModeChangeCallbacks.FindAndRemove( func );
}
void CShaderDeviceMgrBase::InvokeModeChangeCallbacks()
{
int nCount = m_ModeChangeCallbacks.Count();
for ( int i = 0; i < nCount; ++i )
{
m_ModeChangeCallbacks[i]();
}
}
//-----------------------------------------------------------------------------
// Factory to return from SetMode
//-----------------------------------------------------------------------------
void* CShaderDeviceMgrBase::ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode )
{
if ( pReturnCode )
{
*pReturnCode = IFACE_OK;
}
if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_INTERFACE_VERSION ) )
return static_cast< IShaderDevice* >( g_pShaderDevice );
if ( !Q_stricmp( pInterfaceName, SHADERAPI_INTERFACE_VERSION ) )
return static_cast< IShaderAPI* >( g_pShaderAPI );
if ( !Q_stricmp( pInterfaceName, SHADERSHADOW_INTERFACE_VERSION ) )
return static_cast< IShaderShadow* >( g_pShaderShadow );
if ( pReturnCode )
{
*pReturnCode = IFACE_FAILED;
}
return NULL;
}
//-----------------------------------------------------------------------------
//
// The Base implementation of the shader device
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CShaderDeviceBase::CShaderDeviceBase()
{
m_bInitialized = false;
m_nAdapter = -1;
m_hWnd = NULL;
m_hWndCookie = NULL;
m_dwThreadId = ThreadGetCurrentId();
}
CShaderDeviceBase::~CShaderDeviceBase()
{
}
void CShaderDeviceBase::SetCurrentThreadAsOwner()
{
m_dwThreadId = ThreadGetCurrentId();
}
void CShaderDeviceBase::RemoveThreadOwner()
{
m_dwThreadId = 0xFFFFFFFF;
}
bool CShaderDeviceBase::ThreadOwnsDevice()
{
if ( ThreadGetCurrentId() == m_dwThreadId )
return true;
return false;
}
// Methods of IShaderDevice
ImageFormat CShaderDeviceBase::GetBackBufferFormat() const
{
return IMAGE_FORMAT_UNKNOWN;
}
int CShaderDeviceBase::StencilBufferBits() const
{
return 0;
}
bool CShaderDeviceBase::IsAAEnabled() const
{
return false;
}
//-----------------------------------------------------------------------------
// Methods for interprocess communication to release resources
//-----------------------------------------------------------------------------
#define MATERIAL_SYSTEM_WINDOW_ID 0xFEEDDEAD
#ifdef USE_ACTUAL_DX
static VD3DHWND GetTopmostParentWindow( VD3DHWND hWnd )
{
// Find the parent window...
VD3DHWND hParent = GetParent( hWnd );
while ( hParent )
{
hWnd = hParent;
hParent = GetParent( hWnd );
}
return hWnd;
}
static BOOL CALLBACK EnumChildWindowsProc( VD3DHWND hWnd, LPARAM lParam )
{
int windowId = GetWindowLongPtr( hWnd, GWLP_USERDATA );
if (windowId == MATERIAL_SYSTEM_WINDOW_ID)
{
COPYDATASTRUCT copyData;
copyData.dwData = lParam;
copyData.cbData = 0;
copyData.lpData = 0;
SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)©Data);
}
return TRUE;
}
static BOOL CALLBACK EnumWindowsProc( VD3DHWND hWnd, LPARAM lParam )
{
EnumChildWindows( hWnd, EnumChildWindowsProc, lParam );
return TRUE;
}
static BOOL CALLBACK EnumWindowsProcNotThis( VD3DHWND hWnd, LPARAM lParam )
{
if ( g_pShaderDevice && ( GetTopmostParentWindow( (VD3DHWND)g_pShaderDevice->GetIPCHWnd() ) == hWnd ) )
return TRUE;
EnumChildWindows( hWnd, EnumChildWindowsProc, lParam );
return TRUE;
}
#endif
//-----------------------------------------------------------------------------
// Adds a hook to let us know when other instances are setting the mode
//-----------------------------------------------------------------------------
#ifdef STRICT
#define WINDOW_PROC WNDPROC
#else
#define WINDOW_PROC FARPROC
#endif
#ifdef USE_ACTUAL_DX
static LRESULT CALLBACK ShaderDX8WndProc(VD3DHWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
#if !defined( _X360 )
// FIXME: Should these IPC messages tell when an app has focus or not?
// If so, we'd want to totally disable the shader api layer when an app
// doesn't have focus.
// Look for the special IPC message that tells us we're trying to set
// the mode....
switch(msg)
{
case WM_COPYDATA:
{
if ( !g_pShaderDevice )
break;
COPYDATASTRUCT* pData = (COPYDATASTRUCT*)lParam;
// that number is our magic cookie number
if ( pData->dwData == CShaderDeviceBase::RELEASE_MESSAGE )
{
g_pShaderDevice->OtherAppInitializing(true);
}
else if ( pData->dwData == CShaderDeviceBase::REACQUIRE_MESSAGE )
{
g_pShaderDevice->OtherAppInitializing(false);
}
else if ( pData->dwData == CShaderDeviceBase::EVICT_MESSAGE )
{
g_pShaderDevice->EvictManagedResourcesInternal( );
}
}
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
#endif
}
#endif
//-----------------------------------------------------------------------------
// Install, remove ability to talk to other shaderapi apps
//-----------------------------------------------------------------------------
void CShaderDeviceBase::InstallWindowHook( void* hWnd )
{
Assert( m_hWndCookie == NULL );
#ifdef USE_ACTUAL_DX
#if !defined( _X360 )
VD3DHWND hParent = GetTopmostParentWindow( (VD3DHWND)hWnd );
// Attach a child window to the parent; we're gonna store special info there
// We can't use the USERDATA, cause other apps may want to use this.
HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr( hParent, GWLP_HINSTANCE );
WNDCLASS wc;
memset( &wc, 0, sizeof( wc ) );
wc.style = CS_NOCLOSE | CS_PARENTDC;
wc.lpfnWndProc = ShaderDX8WndProc;
wc.hInstance = hInst;
wc.lpszClassName = "shaderdx8";
// In case an old one is sitting around still...
UnregisterClass( "shaderdx8", hInst );
RegisterClass( &wc );
// Create the window
m_hWndCookie = CreateWindow( "shaderdx8", "shaderdx8", WS_CHILD,
0, 0, 0, 0, hParent, NULL, hInst, NULL );
// Marks it as a material system window
SetWindowLongPtr( (VD3DHWND)m_hWndCookie, GWLP_USERDATA, MATERIAL_SYSTEM_WINDOW_ID );
#endif
#endif
}
void CShaderDeviceBase::RemoveWindowHook( void* hWnd )
{
#ifdef USE_ACTUAL_DX
#if !defined( _X360 )
if ( m_hWndCookie )
{
DestroyWindow( (VD3DHWND)m_hWndCookie );
m_hWndCookie = 0;
}
VD3DHWND hParent = GetTopmostParentWindow( (VD3DHWND)hWnd );
HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr( hParent, GWLP_HINSTANCE );
UnregisterClass( "shaderdx8", hInst );
#endif
#endif
}
//-----------------------------------------------------------------------------
// Sends a message to other shaderapi applications
//-----------------------------------------------------------------------------
void CShaderDeviceBase::SendIPCMessage( IPCMessage_t msg )
{
#ifdef USE_ACTUAL_DX
#if !defined( _X360 )
// Gotta send this to all windows, since we don't know which ones
// are material system apps...
if ( msg != EVICT_MESSAGE )
{
EnumWindows( EnumWindowsProc, (DWORD)msg );
}
else
{
EnumWindows( EnumWindowsProcNotThis, (DWORD)msg );
}
#endif
#endif
}
//-----------------------------------------------------------------------------
// Find view
//-----------------------------------------------------------------------------
int CShaderDeviceBase::FindView( void* hWnd ) const
{
/* FIXME: Is this necessary?
// Look for the view in the list of views
for (int i = m_Views.Count(); --i >= 0; )
{
if (m_Views[i].m_HWnd == (VD3DHWND)hwnd)
return i;
}
*/
return -1;
}
//-----------------------------------------------------------------------------
// Creates a child window
//-----------------------------------------------------------------------------
bool CShaderDeviceBase::AddView( void* hWnd )
{
LOCK_SHADERAPI();
/*
// If we haven't created a device yet
if (!Dx9Device())
return false;
// Make sure no duplicate hwnds...
if (FindView(hwnd) >= 0)
return false;
// In this case, we need to create the device; this is our
// default swap chain. This here says we're gonna use a part of the
// existing buffer and just grab that.
int view = m_Views.AddToTail();
m_Views[view].m_HWnd = (VD3DHWND)hwnd;
// memcpy( &m_Views[view].m_PresentParamters, m_PresentParameters, sizeof(m_PresentParamters) );
HRESULT hr;
hr = Dx9Device()->CreateAdditionalSwapChain( &m_PresentParameters,
&m_Views[view].m_pSwapChain );
return !FAILED(hr);
*/
return true;
}
void CShaderDeviceBase::RemoveView( void* hWnd )
{
LOCK_SHADERAPI();
/*
// Look for the view in the list of views
int i = FindView(hwnd);
if (i >= 0)
{
// FIXME m_Views[i].m_pSwapChain->Release();
m_Views.FastRemove(i);
}
*/
}
//-----------------------------------------------------------------------------
// Activates a child window
//-----------------------------------------------------------------------------
void CShaderDeviceBase::SetView( void* hWnd )
{
LOCK_SHADERAPI();
ShaderViewport_t viewport;
g_pShaderAPI->GetViewports( &viewport, 1 );
// Get the window (*not* client) rect of the view window
m_ViewHWnd = (VD3DHWND)hWnd;
GetWindowSize( m_nWindowWidth, m_nWindowHeight );
// Reset the viewport (takes into account the view rect)
// Don't need to set the viewport if it's not ready
g_pShaderAPI->SetViewports( 1, &viewport );
}
//-----------------------------------------------------------------------------
// Gets the window size
//-----------------------------------------------------------------------------
void CShaderDeviceBase::GetWindowSize( int& nWidth, int& nHeight ) const
{
#if defined( USE_SDL )
// this matches up to what the threaded material system does
g_pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
#else
// If the window was minimized last time swap buffers happened, or if it's iconic now,
// return 0 size
#ifdef _WIN32
if ( !m_bIsMinimized && !IsIconic( ( HWND )m_hWnd ) )
#else
if ( !m_bIsMinimized && !IsIconic( (VD3DHWND)m_hWnd ) )
#endif
{
// NOTE: Use the 'current view' (which may be the same as the main window)
RECT rect;
#ifdef _WIN32
GetClientRect( ( HWND )m_ViewHWnd, &rect );
#else
toglGetClientRect( (VD3DHWND)m_ViewHWnd, &rect );
#endif
nWidth = rect.right - rect.left;
nHeight = rect.bottom - rect.top;
}
else
{
nWidth = nHeight = 0;
}
#endif
}
|