-
Notifications
You must be signed in to change notification settings - Fork 12
/
Adapter.cpp
597 lines (509 loc) · 19 KB
/
Adapter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/* Copyright (c) 2002-2012 Croteam Ltd.
Copyright (c) 2020 Sultim Tsyrendashiev
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "Engine/StdH.h"
#include <Engine/Graphics/Adapter.h>
#include <Engine/Graphics/GfxLibrary.h>
#include <Engine/Base/Translation.h>
#include <Engine/Base/Console.h>
#include <Engine/Base/Shell.h>
#include <Engine/Base/ErrorReporting.h>
#ifdef SE1_VULKAN
#include <Engine/Graphics/Vulkan/VulkanInclude.h>
#endif
// !!! FIXME : rcg11052001 move this somewhere.
#ifdef PLATFORM_UNIX
#include "SDL.h"
#endif
extern BOOL _bDedicatedServer;
#ifdef SE1_D3D
extern const D3DDEVTYPE d3dDevType;
#endif // SE1_D3D
// list of all modes avaliable through CDS
static CListHead _lhCDSModes;
#ifdef PLATFORM_WIN32 // DG: all this code is (currently?) only used for windows.
class CResolution {
public:
PIX re_pixSizeI;
PIX re_pixSizeJ;
};
static CResolution _areResolutions[] =
{
{ 640, 480 },
{ 960, 720 },
{ 1024, 768 },
{ 1280, 960 },
{ 1280, 720 },
{ 1600, 900 },
{ 1920, 1080 },
{ 2048, 1152 },
{ 2560, 1440 },
{ 3200, 1800 },
{ 3840, 2160 },
//{ 320, 240 },
//{ 400, 300 },
//{ 480, 360 },
//{ 512, 384 },
//{ 640, 480 },
//{ 720, 540 },
//{ 720, 576 },
//{ 800, 600 },
//{ 960, 720 },
//{ 1024, 768 },
//{ 1152, 864 },
//{ 1280, 960 },
//{ 1280, 1024 },
//{ 1600, 1200 },
//{ 1792, 1344 },
//{ 1856, 1392 },
//{ 1920, 1440 },
//{ 2048, 1536 },
//// matrox dualhead modes
//{ 1280, 480 },
//{ 1600, 600 },
//{ 2048, 768 },
//// NTSC HDTV widescreen
//{ 848, 480 },
//{ 856, 480 },
};
// THIS NUMBER MUST NOT BE OVER 25! (otherwise change it in adapter.h)
static const INDEX MAX_RESOLUTIONS = sizeof(_areResolutions)/sizeof(_areResolutions[0]);
// initialize CDS support (enumerate modes at startup)
void CGfxLibrary::InitAPIs(void)
{
// no need for gfx when dedicated server is on
if( _bDedicatedServer) return;
CPrintF("Initialize CDS support (enumerate modes at startup).\n");
CDisplayAdapter *pda;
INDEX iResolution;
// detect current mode and print to console
DEVMODE devmode;
memset( &devmode, 0, sizeof(devmode));
devmode.dmSize = sizeof(devmode);
LONG lRes = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
CPrintF( TRANS("Current display: '%s' version %d - %dx%dx%d\n\n"),
devmode.dmDeviceName, devmode.dmDriverVersion,
devmode.dmPelsWidth, devmode.dmPelsHeight, devmode.dmBitsPerPel);
// fill OpenGL adapter info
gl_gaAPI[GAT_OGL].ga_ctAdapters = 1;
gl_gaAPI[GAT_OGL].ga_iCurrentAdapter = 0;
pda = &gl_gaAPI[GAT_OGL].ga_adaAdapter[0];
pda->da_ulFlags = DAF_USEGDIFUNCTIONS;
pda->da_strVendor = TRANS( "unknown");
pda->da_strRenderer = TRANS( "Default ICD");
pda->da_strVersion = "1.1+";
// detect modes for OpenGL ICD
pda->da_ctDisplayModes = 0;
pda->da_iCurrentDisplayMode = -1;
// enumerate modes thru resolution list
for( iResolution=0; iResolution<MAX_RESOLUTIONS; iResolution++)
{
DEVMODE devmode;
memset( &devmode, 0, sizeof(devmode));
CResolution &re = _areResolutions[iResolution];
// ask windows if they could set the mode
devmode.dmSize = sizeof(devmode);
devmode.dmPelsWidth = re.re_pixSizeI;
devmode.dmPelsHeight = re.re_pixSizeJ;
devmode.dmDisplayFlags = CDS_FULLSCREEN;
devmode.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFLAGS;
LONG lRes = ChangeDisplaySettings( &devmode, CDS_TEST|CDS_FULLSCREEN);
// skip if not successfull
if( lRes!=DISP_CHANGE_SUCCESSFUL) continue;
// make a new display mode
CDisplayMode &dm = pda->da_admDisplayModes[pda->da_ctDisplayModes];
dm.dm_pixSizeI = re.re_pixSizeI;
dm.dm_pixSizeJ = re.re_pixSizeJ;
dm.dm_ddDepth = DD_DEFAULT;
pda->da_ctDisplayModes++;
}
// detect presence of 3Dfx standalone OpenGL driver (for Voodoo1/2)
char *strDummy;
char strBuffer[_MAX_PATH+1];
int iRes = SearchPathA( NULL, "3DFXVGL.DLL", NULL, _MAX_PATH, strBuffer, &strDummy);
// if present
if(iRes) {
// set adapter and force some enumeration of voodoo1/2 display modes
gl_gaAPI[GAT_OGL].ga_ctAdapters++;
pda = &gl_gaAPI[GAT_OGL].ga_adaAdapter[1];
pda->da_ctDisplayModes = 4; // voodoos have only 4 display modes
pda->da_ulFlags = DAF_ONEWINDOW | DAF_FULLSCREENONLY | DAF_16BITONLY;
pda->da_strVendor = "3Dfx";
pda->da_strRenderer = "3Dfx Voodoo2";
pda->da_strVersion = "1.1+";
CDisplayMode *adm = &pda->da_admDisplayModes[0];
adm[0].dm_pixSizeI = 512; adm[0].dm_pixSizeJ = 384; adm[0].dm_ddDepth = DD_16BIT;
adm[1].dm_pixSizeI = 640; adm[1].dm_pixSizeJ = 480; adm[1].dm_ddDepth = DD_16BIT;
adm[2].dm_pixSizeI = 800; adm[2].dm_pixSizeJ = 600; adm[2].dm_ddDepth = DD_16BIT;
adm[3].dm_pixSizeI = 1024; adm[3].dm_pixSizeJ = 768; adm[3].dm_ddDepth = DD_16BIT;
}
#ifdef SE1_VULKAN
VkApplicationInfo tempAppInfo = {};
tempAppInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
tempAppInfo.pApplicationName = "Temp VK to get GPU list";
tempAppInfo.applicationVersion = 0;
tempAppInfo.pEngineName = "Serious Engine 1";
tempAppInfo.engineVersion = 0;
tempAppInfo.apiVersion = VK_API_VERSION_1_2;
VkInstance tempVkInstance;
VkInstanceCreateInfo instanceInfo = {};
instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instanceInfo.pApplicationInfo = &tempAppInfo;
VkResult r = vkCreateInstance(&instanceInfo, nullptr, &tempVkInstance);
if (r != VK_SUCCESS)
{
ASSERT(FALSE);
}
// get all physical devices
uint32_t ctMaxPhysDevices = 0;
vkEnumeratePhysicalDevices(tempVkInstance, &ctMaxPhysDevices, nullptr);
if (ctMaxPhysDevices == 0)
{
FatalError("GPU wasn't found");
}
VkPhysicalDevice physDevices[64];
vkEnumeratePhysicalDevices(tempVkInstance, &ctMaxPhysDevices, physDevices);
// TODO: Vulkan: add only suitable devices, i.e. with:
// * required formats
// * queue family indices
// * present modes
// * required extensions (VK_KHR_SWAPCHAIN_EXTENSION_NAME)
for (INDEX iAdapter = 0; iAdapter < ctMaxPhysDevices; iAdapter++)
{
pda = &gl_gaAPI[GAT_VK].ga_adaAdapter[iAdapter];
pda->da_ulFlags = NONE;
pda->da_ctDisplayModes = 0;
// pda->da_iCurrentDisplayMode = -1;
// Are they realy needed?
// * 32-bits rendering modes support
// * windowed rendering modes support
// enumerate modes thru resolution list
for (iResolution = 0; iResolution < MAX_RESOLUTIONS; iResolution++)
{
DEVMODE devmode;
memset(&devmode, 0, sizeof(devmode));
CResolution& re = _areResolutions[iResolution];
// ask windows if they could set the mode
devmode.dmSize = sizeof(devmode);
devmode.dmPelsWidth = re.re_pixSizeI;
devmode.dmPelsHeight = re.re_pixSizeJ;
devmode.dmDisplayFlags = CDS_FULLSCREEN;
devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS;
LONG lRes = ChangeDisplaySettings(&devmode, CDS_TEST | CDS_FULLSCREEN);
// skip if not successfull
if (lRes != DISP_CHANGE_SUCCESSFUL) continue;
// make a new display mode
CDisplayMode& dm = pda->da_admDisplayModes[pda->da_ctDisplayModes];
dm.dm_pixSizeI = re.re_pixSizeI;
dm.dm_pixSizeJ = re.re_pixSizeJ;
dm.dm_ddDepth = DD_DEFAULT;
pda->da_ctDisplayModes++;
}
VkPhysicalDeviceProperties properties;
vkGetPhysicalDeviceProperties(physDevices[iAdapter], &properties);
switch (properties.vendorID)
{
case 0x1002: pda->da_strVendor = "Advanced Micro Devices"; break;
case 0x1010: pda->da_strVendor = "Imagination Technologies"; break;
case 0x10DE: pda->da_strVendor = "NVIDIA"; break;
case 0x5143: pda->da_strVendor = "Qualcomm"; break;
case 0x8086: pda->da_strVendor = "Intel"; break;
default: pda->da_strVendor = TRANS("unknown"); break;
}
pda->da_strRenderer = properties.deviceName;
pda->da_strVersion.PrintF("%d.%d",
VK_VERSION_MAJOR(properties.apiVersion),
VK_VERSION_MINOR(properties.apiVersion));
}
gl_gaAPI[GAT_VK].ga_ctAdapters = ctMaxPhysDevices;
gl_gaAPI[GAT_VK].ga_iCurrentAdapter = 0;
// destroy temporary instance
vkDestroyInstance(tempVkInstance, nullptr);
#endif // SE1_VULKAN
// try to init Direct3D 8
#ifdef SE1_D3D
BOOL bRes = InitDriver_D3D();
if( !bRes) return; // didn't made it?
// determine DX8 adapters and display modes
const INDEX ctMaxAdapters = gl_pD3D->GetAdapterCount();
INDEX &ctAdapters = gl_gaAPI[GAT_D3D].ga_ctAdapters;
ctAdapters = 0;
for( INDEX iAdapter=0; iAdapter<ctMaxAdapters; iAdapter++)
{
pda = &gl_gaAPI[1].ga_adaAdapter[ctAdapters];
pda->da_ulFlags = NONE;
pda->da_ctDisplayModes = 0;
INDEX ctModes = gl_pD3D->GetAdapterModeCount(iAdapter);
INDEX iMode;
HRESULT hr;
// check whether 32-bits rendering modes are supported
hr = gl_pD3D->CheckDeviceType( iAdapter, d3dDevType, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE);
if( hr!=D3D_OK) {
hr = gl_pD3D->CheckDeviceType( iAdapter, d3dDevType, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE);
if( hr!=D3D_OK) pda->da_ulFlags |= DAF_16BITONLY;
}
// check whether windowed rendering modes are supported
D3DCAPS8 d3dCaps;
gl_pD3D->GetDeviceCaps( iAdapter, d3dDevType, &d3dCaps);
if( !(d3dCaps.Caps2 & D3DCAPS2_CANRENDERWINDOWED)) pda->da_ulFlags |= DAF_FULLSCREENONLY;
// enumerate modes thru resolution list
for( iResolution=0; iResolution<MAX_RESOLUTIONS; iResolution++)
{
CResolution &re = _areResolutions[iResolution];
for( iMode=0; iMode<ctModes; iMode++) {
// if resolution matches and display depth is 16 or 32 bit
D3DDISPLAYMODE d3dDisplayMode;
gl_pD3D->EnumAdapterModes( iAdapter, iMode, &d3dDisplayMode);
if( d3dDisplayMode.Width==re.re_pixSizeI && d3dDisplayMode.Height==re.re_pixSizeJ
&& (d3dDisplayMode.Format==D3DFMT_A8R8G8B8 || d3dDisplayMode.Format==D3DFMT_X8R8G8B8
|| d3dDisplayMode.Format==D3DFMT_A1R5G5B5 || d3dDisplayMode.Format==D3DFMT_X1R5G5B5
|| d3dDisplayMode.Format==D3DFMT_R5G6B5)) {
hr = gl_pD3D->CheckDeviceType( iAdapter, d3dDevType, d3dDisplayMode.Format, d3dDisplayMode.Format, FALSE);
if( hr!=D3D_OK) continue;
// make a new display mode
CDisplayMode &dm = pda->da_admDisplayModes[pda->da_ctDisplayModes];
dm.dm_pixSizeI = re.re_pixSizeI;
dm.dm_pixSizeJ = re.re_pixSizeJ;
dm.dm_ddDepth = DD_DEFAULT;
pda->da_ctDisplayModes++;
break;
}
}
}
// get adapter identifier
ctAdapters++;
D3DADAPTER_IDENTIFIER8 d3dAdapterIdentifier;
gl_pD3D->GetAdapterIdentifier( iAdapter, D3DENUM_NO_WHQL_LEVEL, &d3dAdapterIdentifier);
pda->da_strVendor = "MS DirectX 8";
pda->da_strRenderer = d3dAdapterIdentifier.Description;
pda->da_strVersion.PrintF("%d.%d.%d.%d", d3dAdapterIdentifier.DriverVersion.HighPart >>16,
d3dAdapterIdentifier.DriverVersion.HighPart & 0xFFFF,
d3dAdapterIdentifier.DriverVersion.LowPart >>16,
d3dAdapterIdentifier.DriverVersion.LowPart & 0xFFFF);
}
// shutdown DX8 (we'll start it again if needed)
D3DRELEASE( gl_pD3D, TRUE);
////#endif
if( gl_hiDriver!=NONE) FreeLibrary(gl_hiDriver);
gl_hiDriver = NONE;
#endif // SE1_D3D
}
#else
// initialize CDS support (enumerate modes at startup)
void CGfxLibrary::InitAPIs(void)
{
// no need for gfx when dedicated server is on
if( _bDedicatedServer) return;
// fill OpenGL adapter info
CDisplayAdapter *pda;
//INDEX iResolution;
CPrintF("GfxLibrary: InitAPI\n");
CPrintF("GfxLibrary: OpenGL InitAPIs.\n");
gl_gaAPI[GAT_OGL].ga_ctAdapters = 1;
gl_gaAPI[GAT_OGL].ga_iCurrentAdapter = 0;
pda = &gl_gaAPI[GAT_OGL].ga_adaAdapter[0];
pda->da_ulFlags = 0;
pda->da_strVendor = TRANS( "unknown");
pda->da_strRenderer = TRANS( "Default ICD");
pda->da_strVersion = "1.1+";
// detect modes for OpenGL ICD
pda->da_ctDisplayModes = 0;
pda->da_iCurrentDisplayMode = -1;
const int dpy = 0; // !!! FIXME: hook up a cvar?
const int total = SDL_GetNumDisplayModes(dpy);
for (int i = 0; i < total; i++)
{
if (pda->da_ctDisplayModes >= static_cast<INDEX>(ARRAYCOUNT(pda->da_admDisplayModes)))
break;
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(dpy, i, &mode) == 0)
{
const int bpp = (int) SDL_BITSPERPIXEL(mode.format);
if (bpp < 16) continue;
DisplayDepth bits = DD_DEFAULT;
switch (bpp)
{
case 16: bits = DD_16BIT; break;
case 32: bits = DD_32BIT; break;
case 24: bits = DD_24BIT; break;
default: break;
}
CDisplayMode &dm = pda->da_admDisplayModes[pda->da_ctDisplayModes];
dm.dm_pixSizeI = mode.w;
dm.dm_pixSizeJ = mode.h;
dm.dm_ddDepth = bits;
pda->da_ctDisplayModes++;
}
}
#ifdef SE1_VULKAN
CPrintF("GfxLibrary: Vulkan InitAPIs.\n");
VkInstance tempVkInstance;
VkInstanceCreateInfo instanceInfo = {};
instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
VkResult r = vkCreateInstance(&instanceInfo, nullptr, &tempVkInstance);
if (r != VK_SUCCESS)
{
CPrintF("Cannot create Vulkan instance.\n");
return;;
}
// get all physical devices
uint32_t ctMaxPhysDevices = 0;
vkEnumeratePhysicalDevices(tempVkInstance, &ctMaxPhysDevices, nullptr);
ASSERT(ctMaxPhysDevices < 8);
VkPhysicalDevice physDevices[8];
vkEnumeratePhysicalDevices(tempVkInstance, &ctMaxPhysDevices, physDevices);
// TODO: Vulkan: add only suitable devices, i.e. with:
// * required formats
// * queue family indices
// * present modes
// * required extensions (VK_KHR_SWAPCHAIN_EXTENSION_NAME)
for (uint32_t iAdapter = 0; iAdapter < ctMaxPhysDevices; iAdapter++)
{
pda = &gl_gaAPI[GAT_VK].ga_adaAdapter[iAdapter];
pda->da_ulFlags = NONE;
pda->da_ctDisplayModes = 0;
// pda->da_iCurrentDisplayMode = -1;
const int dpy = 0; // !!! FIXME: hook up a cvar?
const int total = SDL_GetNumDisplayModes(dpy);
for (int i = 0; i < total; i++)
{
if ((uint32_t)(pda->da_ctDisplayModes) >= ARRAYCOUNT(pda->da_admDisplayModes))
break;
SDL_DisplayMode mode;
if (SDL_GetDisplayMode(dpy, i, &mode) == 0)
{
const int bpp = (int) SDL_BITSPERPIXEL(mode.format);
if (bpp < 16) continue;
DisplayDepth bits = DD_DEFAULT;
switch (bpp)
{
case 16: bits = DD_16BIT; break;
case 32: bits = DD_32BIT; break;
case 24: bits = DD_24BIT; break;
default: break;
}
CDisplayMode &dm = pda->da_admDisplayModes[pda->da_ctDisplayModes];
dm.dm_pixSizeI = mode.w;
dm.dm_pixSizeJ = mode.h;
dm.dm_ddDepth = bits;
pda->da_ctDisplayModes++;
}
}
VkPhysicalDeviceProperties properties;
vkGetPhysicalDeviceProperties(physDevices[iAdapter], &properties);
switch (properties.vendorID)
{
case 0x1002: pda->da_strVendor = "Advanced Micro Devices, Inc."; break;
case 0x10DE: pda->da_strVendor = "NVIDIA Corporation"; break;
case 0x13B5: pda->da_strVendor = "ARM Ltd"; break;
case 0x5143: pda->da_strVendor = "Qualcomm Technologies, Inc."; break;
case 0x8086: pda->da_strVendor = "Intel Corporation"; break;
default: pda->da_strVendor = TRANS("unknown");; break;
}
CPrintF("Vendor: %s\n", (const char*)pda->da_strVendor);
pda->da_strRenderer = properties.deviceName;
pda->da_strVersion.PrintF("%d.%d",
VK_VERSION_MAJOR(properties.apiVersion),
VK_VERSION_MINOR(properties.apiVersion));
}
gl_gaAPI[GAT_VK].ga_ctAdapters = ctMaxPhysDevices;
gl_gaAPI[GAT_VK].ga_iCurrentAdapter = 0;
// destroy temporary instance
vkDestroyInstance(tempVkInstance, nullptr);
#endif // SE1_VULKAN
}
#endif
// get list of all modes avaliable through CDS -- do not modify/free the returned list
CListHead &CDS_GetModes(void)
{
return _lhCDSModes;
}
// set given display mode
BOOL CDS_SetMode( PIX pixSizeI, PIX pixSizeJ, enum DisplayDepth dd)
{
// no need for gfx when dedicated server is on
if( _bDedicatedServer) return FALSE;
// !!! FIXME : rcg11052001 better abstraction!
#ifdef PLATFORM_WIN32
// prepare general mode parameters
DEVMODE devmode;
memset(&devmode, 0, sizeof(devmode));
devmode.dmSize = sizeof(devmode);
devmode.dmPelsWidth = pixSizeI;
devmode.dmPelsHeight = pixSizeJ;
devmode.dmDisplayFlags = CDS_FULLSCREEN;
devmode.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFLAGS;
extern INDEX gap_iRefreshRate;
if( gap_iRefreshRate>0) {
devmode.dmFields |= DM_DISPLAYFREQUENCY;
devmode.dmDisplayFrequency = gap_iRefreshRate;
}
// determine bits per pixel to try to set
SLONG slBPP2 = 0;
switch(dd) {
case DD_16BIT:
devmode.dmBitsPerPel = 16;
slBPP2 = 15;
devmode.dmFields |= DM_BITSPERPEL;
break;
case DD_32BIT:
devmode.dmBitsPerPel = 32;
slBPP2 = 24;
devmode.dmFields |= DM_BITSPERPEL;
break;
case DD_DEFAULT:
NOTHING;
break;
default:
ASSERT(FALSE);
NOTHING;
}
// try to set primary depth
LONG lRes = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
// if failed
if( lRes!=DISP_CHANGE_SUCCESSFUL) {
// try to set secondary depth
devmode.dmBitsPerPel = slBPP2;
LONG lRes2 = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
// if failed
if( lRes2!=DISP_CHANGE_SUCCESSFUL) {
CTString strError;
switch(lRes) {
case DISP_CHANGE_SUCCESSFUL: strError = "DISP_CHANGE_SUCCESSFUL"; break;
case DISP_CHANGE_RESTART: strError = "DISP_CHANGE_RESTART"; break;
case DISP_CHANGE_BADFLAGS: strError = "DISP_CHANGE_BADFLAGS"; break;
case DISP_CHANGE_BADPARAM: strError = "DISP_CHANGE_BADPARAM"; break;
case DISP_CHANGE_FAILED: strError = "DISP_CHANGE_FAILED"; break;
case DISP_CHANGE_BADMODE: strError = "DISP_CHANGE_BADMODE"; break;
case DISP_CHANGE_NOTUPDATED: strError = "DISP_CHANGE_NOTUPDATED"; break;
default: strError.PrintF("%d", lRes); break;
}
CPrintF(TRANSV("CDS error: %s\n"), strError);
return FALSE;
}
}
// report
CPrintF(TRANSV(" CDS: mode set to %dx%dx%d\n"), pixSizeI, pixSizeJ, devmode.dmBitsPerPel);
#endif
return TRUE;
}
// reset windows to mode chosen by user within windows diplay properties
void CDS_ResetMode(void)
{
// no need for gfx when dedicated server is on
if( _bDedicatedServer) return;
#ifdef PLATFORM_WIN32
LONG lRes = ChangeDisplaySettings( NULL, 0);
ASSERT(lRes==DISP_CHANGE_SUCCESSFUL);
CPrintF(TRANSV(" CDS: mode reset to original desktop settings\n"));
#endif
}