-
Notifications
You must be signed in to change notification settings - Fork 1
/
RenderDevice.cpp
2953 lines (2604 loc) · 110 KB
/
RenderDevice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include <DxErr.h>
//#include "Dwmapi.h" // use when we get rid of XP at some point, get rid of the manual dll loads in here then
#ifndef DISABLE_FORCE_NVIDIA_OPTIMUS
#include "nvapi.h"
#endif
#include "typeDefs3D.h"
#ifdef ENABLE_SDL
#include "sdl2/SDL_syswm.h"
#endif
#include "RenderDevice.h"
#include "TextureManager.h"
#include "Shader.h"
#ifndef ENABLE_SDL
#include "Material.h"
#include "BasicShader.h"
#include "BallShader.h"
#include "DMDShader.h"
#include "FBShader.h"
#include "FlasherShader.h"
#include "LightShader.h"
#include "StereoShader.h"
#ifdef SEPARATE_CLASSICLIGHTSHADER
#include "ClassicLightShader.h"
#endif
#endif
#include "shader/AreaTex.h"
#include "shader/SearchTex.h"
#ifndef ENABLE_SDL
#pragma comment(lib, "d3d9.lib") // TODO: put into build system
#pragma comment(lib, "d3dx9.lib") // TODO: put into build system
#if _MSC_VER >= 1900
#pragma comment(lib, "legacy_stdio_definitions.lib") //dxerr.lib needs this
#endif
#pragma comment(lib, "dxerr.lib") // TODO: put into build system
#endif
static RenderTarget *srcr_cache = NULL; //!! meh, for nvidia depth read only
static D3DTexture *srct_cache = NULL;
static D3DTexture* dest_cache = NULL;
static bool IsWindowsVistaOr7()
{
OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };
const DWORDLONG dwlConditionMask = //VerSetConditionMask(
VerSetConditionMask(
VerSetConditionMask(
0, VER_MAJORVERSION, VER_EQUAL),
VER_MINORVERSION, VER_EQUAL)/*,
VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL)*/;
osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_VISTA);
osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_VISTA);
//osvi.wServicePackMajor = 0;
const bool vista = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION /*| VER_SERVICEPACKMAJOR*/, dwlConditionMask) != FALSE;
OSVERSIONINFOEXW osvi2 = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };
osvi2.dwMajorVersion = HIBYTE(_WIN32_WINNT_WIN7);
osvi2.dwMinorVersion = LOBYTE(_WIN32_WINNT_WIN7);
//osvi2.wServicePackMajor = 0;
const bool win7 = VerifyVersionInfoW(&osvi2, VER_MAJORVERSION | VER_MINORVERSION /*| VER_SERVICEPACKMAJOR*/, dwlConditionMask) != FALSE;
return vista || win7;
}
typedef HRESULT(STDAPICALLTYPE *pRGV)(LPOSVERSIONINFOEXW osi);
static pRGV mRtlGetVersion = NULL;
bool IsWindows10_1803orAbove()
{
if (mRtlGetVersion == NULL)
mRtlGetVersion = (pRGV)GetProcAddress(GetModuleHandle(TEXT("ntdll")), "RtlGetVersion"); // apparently the only really reliable solution to get the OS version (as of Win10 1803)
if (mRtlGetVersion != NULL)
{
OSVERSIONINFOEXW osInfo;
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
mRtlGetVersion(&osInfo);
if (osInfo.dwMajorVersion > 10)
return true;
if (osInfo.dwMajorVersion == 10 && osInfo.dwMinorVersion > 0)
return true;
if (osInfo.dwMajorVersion == 10 && osInfo.dwMinorVersion == 0 && osInfo.dwBuildNumber >= 17134) // which is the more 'common' 1803
return true;
}
return false;
}
#ifdef ENABLE_SDL
//my definition for SDL GLint size; GLenum type; GLboolean normalized; GLsizei stride;
//D3D definition WORD Stream; WORD Offset; BYTE Type; BYTE Method; BYTE Usage; BYTE UsageIndex;
const VertexElement VertexTexelElement[] =
{
{ 3, GL_FLOAT, GL_FALSE, 0, "POSITION0" },
{ 2, GL_FLOAT, GL_FALSE, 0, "TEXCOORD0" },
{ 0, 0, 0, 0, NULL}
/* { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // pos
{ 0, 3 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
D3DDECL_END()*/
};
VertexDeclaration* RenderDevice::m_pVertexTexelDeclaration = (VertexDeclaration*)&VertexTexelElement;
const VertexElement VertexNormalTexelElement[] =
{
{ 3, GL_FLOAT, GL_FALSE, 0, "POSITION0" },
{ 3, GL_FLOAT, GL_FALSE, 0, "NORMAL0" },
{ 2, GL_FLOAT, GL_FALSE, 0, "TEXCOORD0" },
{ 0, 0, 0, 0, NULL}
/*
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // pos
{ 0, 3 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, // normal
{ 0, 6 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
D3DDECL_END()*/
};
VertexDeclaration* RenderDevice::m_pVertexNormalTexelDeclaration = (VertexDeclaration*)&VertexNormalTexelElement;
/*const VertexElement VertexNormalTexelTexelElement[] =
{
{ 0, 0 * sizeof(float),D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // pos
{ 0, 3 * sizeof(float),D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, // normal
{ 0, 6 * sizeof(float),D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
{ 0, 8 * sizeof(float),D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, // tex1
D3DDECL_END()
};
VertexDeclaration* RenderDevice::m_pVertexNormalTexelTexelDeclaration = NULL;*/
const VertexElement VertexTrafoTexelElement[] =
{
{ 4, GL_FLOAT, GL_FALSE, 0, "POSITION0" },
{ 2, GL_FLOAT, GL_FALSE, 0, NULL },//legacy?
{ 2, GL_FLOAT, GL_FALSE, 0, "TEXCOORD0" },
{ 0, 0, 0, 0, NULL }
/* { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 }, // transformed pos
{ 0, 4 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, // (mostly, except for classic lights) unused, there to be able to share same code as VertexNormalTexelElement
{ 0, 6 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
D3DDECL_END()*/
};
VertexDeclaration* RenderDevice::m_pVertexTrafoTexelDeclaration = (VertexDeclaration*)&VertexTrafoTexelElement;
#else
const VertexElement VertexTexelElement[] =
{
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // pos
{ 0, 3 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
D3DDECL_END()
};
VertexDeclaration* RenderDevice::m_pVertexTexelDeclaration = NULL;
const VertexElement VertexNormalTexelElement[] =
{
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // pos
{ 0, 3 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, // normal
{ 0, 6 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
D3DDECL_END()
};
VertexDeclaration* RenderDevice::m_pVertexNormalTexelDeclaration = NULL;
/*const VertexElement VertexNormalTexelTexelElement[] =
{
{ 0, 0 * sizeof(float),D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // pos
{ 0, 3 * sizeof(float),D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, // normal
{ 0, 6 * sizeof(float),D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
{ 0, 8 * sizeof(float),D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, // tex1
D3DDECL_END()
};
VertexDeclaration* RenderDevice::m_pVertexNormalTexelTexelDeclaration = NULL;*/
// pre-transformed, take care that this is a float4 and needs proper w component setup (also see https://docs.microsoft.com/en-us/windows/desktop/direct3d9/mapping-fvf-codes-to-a-directx-9-declaration)
const VertexElement VertexTrafoTexelElement[] =
{
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 }, // transformed pos
{ 0, 4 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, // (mostly, except for classic lights) unused, there to be able to share same code as VertexNormalTexelElement
{ 0, 6 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // tex0
D3DDECL_END()
};
VertexDeclaration* RenderDevice::m_pVertexTrafoTexelDeclaration = NULL;
#endif
static unsigned int fvfToSize(const DWORD fvf)
{
switch (fvf)
{
case MY_D3DFVF_NOTEX2_VERTEX:
case MY_D3DTRANSFORMED_NOTEX2_VERTEX:
return sizeof(Vertex3D_NoTex2);
case MY_D3DFVF_TEX:
return sizeof(Vertex3D_TexelOnly);
default:
assert(0 && "Unknown FVF type in fvfToSize");
return 0;
}
}
static VertexDeclaration* fvfToDecl(const DWORD fvf)
{
switch (fvf)
{
case MY_D3DFVF_NOTEX2_VERTEX:
return RenderDevice::m_pVertexNormalTexelDeclaration;
case MY_D3DTRANSFORMED_NOTEX2_VERTEX:
return RenderDevice::m_pVertexTrafoTexelDeclaration;
case MY_D3DFVF_TEX:
return RenderDevice::m_pVertexTexelDeclaration;
default:
assert(0 && "Unknown FVF type in fvfToDecl");
return NULL;
}
}
static UINT ComputePrimitiveCount(const RenderDevice::PrimitveTypes type, const int vertexCount)
{
switch (type)
{
case RenderDevice::POINTLIST:
return vertexCount;
case RenderDevice::LINELIST:
return vertexCount / 2;
case RenderDevice::LINESTRIP:
return std::max(0, vertexCount - 1);
case RenderDevice::TRIANGLELIST:
return vertexCount / 3;
case RenderDevice::TRIANGLESTRIP:
case RenderDevice::TRIANGLEFAN:
return std::max(0, vertexCount - 2);
default:
return 0;
}
}
#ifdef ENABLE_SDL
const char* glErrorToString(int error) {
switch (error) {
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
default: return "unknown";
}
}
#endif
void ReportFatalError(const HRESULT hr, const char *file, const int line)
{
#ifdef ENABLE_SDL
char msg[128];
sprintf_s(msg, 128, "GL Error 0x%0002X %s in %s:%d", hr, glErrorToString(hr), file, line);
ShowError(msg);
#else
char msg[128];
sprintf_s(msg, 128, "Fatal error %s (0x%x: %s) at %s:%d", DXGetErrorString(hr), hr, DXGetErrorDescription(hr), file, line);
ShowError(msg);
exit(-1);
#endif
}
void ReportError(const char *errorText, const HRESULT hr, const char *file, const int line)
{
#ifdef ENABLE_SDL
char msg[128];
sprintf_s(msg, 128, "GL Error 0x%0002X %s in %s:%d", hr, glErrorToString(hr), file, line);
ShowError(msg);
#else
char msg[128];
sprintf_s(msg, 128, "%s %s (0x%x: %s) at %s:%d", errorText, DXGetErrorString(hr), hr, DXGetErrorDescription(hr), file, line);
ShowError(msg);
exit(-1);
#endif
}
#ifdef ENABLE_SDL
void checkGLErrors(const char *file, const int line) {
GLenum err;
unsigned int count = 0;
while ((err = glGetError()) != GL_NO_ERROR) {
count++;
ReportFatalError(err, file, line);
}
if (count>0) {
/*exit(-1);*/
}
}
#endif
////////////////////////////////////////////////////////////////////
int getNumberOfDisplays()
{
#ifdef ENABLE_SDL
return SDL_GetNumVideoDisplays();
#else
return GetSystemMetrics(SM_CMONITORS);
#endif
}
void EnumerateDisplayModes(const int display, std::vector<VideoMode>& modes)
{
modes.clear();
#ifdef ENABLE_SDL
for (int mode = 0; mode < SDL_GetNumDisplayModes(display); ++mode) {
SDL_DisplayMode myMode;
SDL_GetDisplayMode(display, mode, &myMode);
VideoMode vmode;
vmode.width = myMode.w;
vmode.height = myMode.h;
switch (myMode.format) {
case SDL_PIXELFORMAT_RGB24:
case SDL_PIXELFORMAT_BGR24:
case SDL_PIXELFORMAT_RGB888:
case SDL_PIXELFORMAT_RGBX8888:
case SDL_PIXELFORMAT_BGR888:
case SDL_PIXELFORMAT_BGRX8888:
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_RGBA8888:
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGRA8888:
vmode.depth = 32;
break;
case SDL_PIXELFORMAT_RGB565:
case SDL_PIXELFORMAT_BGR565:
case SDL_PIXELFORMAT_ABGR1555:
case SDL_PIXELFORMAT_BGRA5551:
case SDL_PIXELFORMAT_ARGB1555:
case SDL_PIXELFORMAT_RGBA5551:
vmode.depth = 16;
break;
case SDL_PIXELFORMAT_ARGB2101010:
vmode.depth = 30;
break;
default:
vmode.depth = 0;
}
vmode.refreshrate = myMode.refresh_rate;
modes.push_back(vmode);
}
#else
std::vector<DisplayConfig> displays;
getDisplayList(displays);
if (display >= displays.size())
return;
int adapter = displays[display].adapter;
IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (d3d == NULL)
{
ShowError("Could not create D3D9 object.");
throw 0;
}
const unsigned numModes = d3d->GetAdapterModeCount(adapter, (D3DFORMAT)colorFormat::RGB);
for (unsigned i = 0; i < numModes; ++i)
{
D3DDISPLAYMODE d3dmode;
d3d->EnumAdapterModes(adapter, (D3DFORMAT)colorFormat::RGB, i, &d3dmode);
if (d3dmode.Width >= 640)
{
VideoMode mode;
mode.width = d3dmode.Width;
mode.height = d3dmode.Height;
mode.depth = 32;
mode.refreshrate = d3dmode.RefreshRate;
modes.push_back(mode);
}
}
SAFE_RELEASE(d3d);
#endif
}
//int getDisplayList(std::vector<DisplayConfig>& displays)
//{
// int maxAdapter = SDL_GetNumVideoDrivers();
// int display = 0;
// for (display = 0; display < getNumberOfDisplays(); display++)
// {
// SDL_Rect displayBounds;
// if (SDL_GetDisplayBounds(display, &displayBounds) == 0) {
// DisplayConfig displayConf;
// displayConf.display = display;
// displayConf.adapter = 0;
// displayConf.isPrimary = (displayBounds.x == 0) && (displayBounds.y == 0);
// displayConf.top = displayBounds.x;
// displayConf.left = displayBounds.x;
// displayConf.width = displayBounds.w;
// displayConf.height = displayBounds.h;
//
// strncpy_s(displayConf.DeviceName, SDL_GetDisplayName(displayConf.display), 32);
// strncpy_s(displayConf.GPU_Name, SDL_GetVideoDriver(displayConf.adapter), MAX_DEVICE_IDENTIFIER_STRING);
//
// displays.push_back(displayConf);
// }
// }
// return display;
//}
BOOL CALLBACK MonitorEnumList(__in HMONITOR hMonitor, __in HDC hdcMonitor, __in LPRECT lprcMonitor, __in LPARAM dwData)
{
std::map<std::string, DisplayConfig>* data = reinterpret_cast<std::map<std::string, DisplayConfig>*>(dwData);
DisplayConfig config;
MONITORINFOEX info;
info.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &info);
config.top = info.rcMonitor.top;
config.left = info.rcMonitor.left;
config.width = info.rcMonitor.right - info.rcMonitor.left;
config.height = info.rcMonitor.bottom - info.rcMonitor.top;
config.isPrimary = (config.top == 0) && (config.left == 0);
config.display = (int)data->size(); // This number does neither map to the number form display settings nor something else.
#ifdef ENABLE_SDL
config.adapter = config.display;
#else
config.adapter = -1;
#endif
memcpy(config.DeviceName, info.szDevice, 32); // Internal display name e.g. "\\\\.\\DISPLAY1"
data->insert(std::pair<std::string, DisplayConfig>(std::string(config.DeviceName), config));
return TRUE;
}
int getDisplayList(std::vector<DisplayConfig>& displays)
{
displays.clear();
std::map<std::string, DisplayConfig> displayMap;
// Get the resolution of all enabled displays.
EnumDisplayMonitors(NULL, NULL, MonitorEnumList, reinterpret_cast<LPARAM>(&displayMap));
DISPLAY_DEVICE DispDev;
ZeroMemory(&DispDev, sizeof(DispDev));
DispDev.cb = sizeof(DispDev);
#ifndef ENABLE_SDL
IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (pD3D == NULL)
{
ShowError("Could not create D3D9 object.");
throw 0;
}
// Map the displays to the DX9 adapter. Otherwise this leads to an performance impact on systems with multiple GPUs
int adapterCount = pD3D->GetAdapterCount();
for (int i = 0;i < adapterCount;++i) {
D3DADAPTER_IDENTIFIER9 adapter;
pD3D->GetAdapterIdentifier(i, 0, &adapter);
std::map<std::string, DisplayConfig>::iterator display = displayMap.find(adapter.DeviceName);
if (display != displayMap.end()) {
display->second.adapter = i;
strncpy_s(display->second.GPU_Name, adapter.Description, MAX_DEVICE_IDENTIFIER_STRING);
}
}
SAFE_RELEASE(pD3D);
#endif
// Apply the same numbering as windows
int i = 0;
for (std::map<std::string, DisplayConfig>::iterator display = displayMap.begin(); display != displayMap.end(); display++)
{
if (display->second.adapter >= 0) {
display->second.display = i;
#ifdef ENABLE_SDL
strncpy_s(display->second.GPU_Name, SDL_GetDisplayName(display->second.adapter), MAX_DEVICE_IDENTIFIER_STRING);
#endif
displays.push_back(display->second);
}
i++;
}
return i;
}
bool getDisplaySetupByID(const int display, int &x, int &y, int &width, int &height)
{
std::vector<DisplayConfig> displays;
getDisplayList(displays);
for (std::vector<DisplayConfig>::iterator displayConf = displays.begin(); displayConf != displays.end(); displayConf++) {
if ((display == -1 && displayConf->isPrimary) || display == displayConf->display) {
x = displayConf->left;
y = displayConf->top;
width = displayConf->width;
height = displayConf->height;
return true;
}
}
x = 0;
y = 0;
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
return false;
}
int getPrimaryDisplay()
{
std::vector<DisplayConfig> displays;
getDisplayList(displays);
for (std::vector<DisplayConfig>::iterator displayConf = displays.begin(); displayConf != displays.end(); displayConf++) {
if (displayConf->isPrimary) {
return displayConf->adapter;
}
}
return 0;
}
////////////////////////////////////////////////////////////////////
#define CHECKNVAPI(s) { NvAPI_Status hr = (s); if (hr != NVAPI_OK) { NvAPI_ShortString ss; NvAPI_GetErrorMessage(hr,ss); MessageBox(NULL, ss, "NVAPI", MB_OK | MB_ICONEXCLAMATION); } }
static bool NVAPIinit = false; //!! meh
bool RenderDevice::m_INTZ_support = false;
VertexBuffer *RenderDevice::m_quadVertexBuffer = NULL;
#ifdef USE_D3D9EX
typedef HRESULT(WINAPI *pD3DC9Ex)(UINT SDKVersion, IDirect3D9Ex**);
static pD3DC9Ex mDirect3DCreate9Ex = NULL;
#endif
#define DWM_EC_DISABLECOMPOSITION 0
#define DWM_EC_ENABLECOMPOSITION 1
typedef HRESULT(STDAPICALLTYPE *pDICE)(BOOL* pfEnabled);
static pDICE mDwmIsCompositionEnabled = NULL;
typedef HRESULT(STDAPICALLTYPE *pDF)();
static pDF mDwmFlush = NULL;
typedef HRESULT(STDAPICALLTYPE *pDEC)(UINT uCompositionAction);
static pDEC mDwmEnableComposition = NULL;
#ifdef _DEBUG
#ifdef ENABLE_SDL
static void CheckForGLLeak()
{
//TODO
}
#else
static void CheckForD3DLeak(IDirect3DDevice9* d3d)
{
IDirect3DSwapChain9 *swapChain;
CHECKD3D(d3d->GetSwapChain(0, &swapChain));
D3DPRESENT_PARAMETERS pp;
CHECKD3D(swapChain->GetPresentParameters(&pp));
SAFE_RELEASE(swapChain);
// idea: device can't be reset if there are still allocated resources
HRESULT hr = d3d->Reset(&pp);
if (FAILED(hr))
{
MessageBox(0, "WARNING! Direct3D resource leak detected!", "Visual Pinball", MB_ICONWARNING);
}
}
#endif
#endif
bool RenderDevice::isVRinstalled()
{
#ifdef ENABLE_VR
return vr::VR_IsRuntimeInstalled();
#else
return false;
#endif
}
vr::IVRSystem* RenderDevice::m_pHMD = nullptr;
bool RenderDevice::isVRturnedOn()
{
#ifdef ENABLE_VR
if (vr::VR_IsHmdPresent()) {
vr::EVRInitError VRError = vr::VRInitError_None;
if (!m_pHMD)
m_pHMD = vr::VR_Init(&VRError, vr::VRApplication_Background);
if (VRError == vr::VRInitError_None && vr::VRCompositor()) {
for (int device = 0; device < vr::k_unMaxTrackedDeviceCount; device++) {
if ((m_pHMD->GetTrackedDeviceClass(device) == vr::TrackedDeviceClass_HMD)) {
return true;
}
}
} else {
m_pHMD = nullptr;
}
}
#endif
return false;
}
void RenderDevice::turnVROff()
{
if (m_pHMD)
{
vr::VR_Shutdown();
m_pHMD = nullptr;
}
}
void RenderDevice::InitVR() {
#ifdef ENABLE_VR
vr::EVRInitError VRError = vr::VRInitError_None;
if (!m_pHMD) {
m_pHMD = vr::VR_Init(&VRError, vr::VRApplication_Scene);
if (VRError != vr::VRInitError_None) {
m_pHMD = nullptr;
char buf[1024];
sprintf_s(buf, sizeof(buf), "Unable to init VR runtime: %s", vr::VR_GetVRInitErrorAsEnglishDescription(VRError));
std::runtime_error vrInitFailed(buf);
throw(vrInitFailed);
}
if (!vr::VRCompositor())
if (VRError != vr::VRInitError_None) {
m_pHMD = NULL;
char buf[1024];
sprintf_s(buf, sizeof(buf), "Unable to init VR compositor: %s", vr::VR_GetVRInitErrorAsEnglishDescription(VRError));
std::runtime_error vrInitFailed(buf);
throw(vrInitFailed);
}
}
m_pHMD->GetRecommendedRenderTargetSize(&m_Buf_width, &m_Buf_height);
vr::HmdMatrix34_t mat34;
vr::HmdMatrix44_t mat44;
Matrix3D matEye2Head, matProjection;
//Calculate left EyeProjection Matrix relative to HMD position
mat34 = m_pHMD->GetEyeToHeadTransform(vr::Eye_Left);
for (int i = 0;i < 3;i++)
for (int j = 0;j < 4;j++)
matEye2Head.m[j][i] = mat34.m[i][j];
for (int j = 0;j < 4;j++)
matEye2Head.m[j][3] = (j == 3) ? 1.0f : 0.0f;
matEye2Head.Invert();
float nearPlane = LoadValueFloatWithDefault("PlayerVR", "nearPlane", 5.0f) / 100.0f;
float farPlane = LoadValueFloatWithDefault("PlayerVR", "farPlane", 500.0f) / 100.0f;
mat44 = m_pHMD->GetProjectionMatrix(vr::Eye_Left, nearPlane, farPlane);//5cm to 5m should be a reasonable range
for (int i = 0;i < 4;i++)
for (int j = 0;j < 4;j++)
matProjection.m[j][i] = mat44.m[i][j];
m_matProj[0] = matEye2Head * matProjection;
//Calculate right EyeProjection Matrix relative to HMD position
mat34 = m_pHMD->GetEyeToHeadTransform(vr::Eye_Right);
for (int i = 0;i < 3;i++)
for (int j = 0;j < 4;j++)
matEye2Head.m[j][i] = mat34.m[i][j];
for (int j = 0;j < 4;j++)
matEye2Head.m[j][3] = (j == 3) ? 1.0f : 0.0f;
matEye2Head.Invert();
mat44 = m_pHMD->GetProjectionMatrix(vr::Eye_Right, nearPlane, farPlane);//5cm to 5m should be a reasonable range
for (int i = 0;i < 4;i++)
for (int j = 0;j < 4;j++)
matProjection.m[j][i] = mat44.m[i][j];
m_matProj[1] = matEye2Head * matProjection;
if (vr::k_unMaxTrackedDeviceCount > 0) {
m_rTrackedDevicePose = new vr::TrackedDevicePose_t[vr::k_unMaxTrackedDeviceCount];
}
else {
std::runtime_error noDevicesFound("No Tracking devices found");
throw(noDevicesFound);
}
slope = LoadValueFloatWithDefault("Player", "VRSlope", 6.5f);
orientation = LoadValueFloatWithDefault("Player", "VROrientation", 0.0f);
tablex = LoadValueFloatWithDefault("Player", "VRTableX", 0.0f);
tabley = LoadValueFloatWithDefault("Player", "VRTableY", 0.0f);
tablez = LoadValueFloatWithDefault("Player", "VRTableZ", 80.0f);
roomOrientation = LoadValueFloatWithDefault("Player", "VRRoomOrientation", 0.0f);
roomx = LoadValueFloatWithDefault("Player", "VRRoomX", 0.0f);
roomy = LoadValueFloatWithDefault("Player", "VRRoomY", 0.0f);
updateTableMatrix();
#else
std::runtime_error unknownStereoMode("This version of Visual Pinball was compiled without VR support");
throw(unknownStereoMode);
#endif
}
#ifdef ENABLE_SDL
RenderDevice::RenderDevice(HWND* const hwnd, const int width, const int height, const bool fullscreen, const int colordepth, int VSync, const float AAfactor, const int stereo3D, const unsigned int FXAA, const bool ss_refl, const bool useNvidiaApi, const bool disable_dwm, const int BWrendering, const RenderDevice* primaryDevice)
: m_texMan(*this), m_width(width), m_height(height), m_fullscreen(fullscreen),
m_colorDepth(colordepth), m_vsync(VSync), m_AAfactor(AAfactor), m_stereo3D(stereo3D), m_FXAA(FXAA),
m_ssRefl(ss_refl), m_useNvidiaApi(useNvidiaApi), m_disableDwm(disable_dwm), m_BWrendering(BWrendering)
{
#ifdef ENABLE_VR
m_pHMD = NULL;
m_rTrackedDevicePose = NULL;
#endif
}
void RenderDevice::CreateDevice(int &refreshrate, UINT adapterIndex)
{
m_stats_drawn_triangles = 0;
m_useNvidiaApi = false;
int displays = getNumberOfDisplays();
if (adapterIndex >= displays) {
m_adapter = 0;
}
else {
m_adapter = adapterIndex;
}
bool video10bit = (m_colorDepth == SDL_PIXELFORMAT_ARGB2101010);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GL_VERSION_NUMBER / 100);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, GL_VERSION_NUMBER % 100);
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
/* SDL_GL_SetAttribute(SDL_GL_RED_SIZE, video10bit ? 10 : 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, video10bit ? 10 : 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, video10bit ? 10 : 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, video10bit ? 2 : 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);*/
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
// ATM Supersampling is used. MSAA can be enabled here with useAA ? 0 : 4
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
//SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
int disp_x, disp_y, disp_w, disp_h;
getDisplaySetupByID(m_adapter, disp_x, disp_y, disp_w, disp_h);
bool disableVRPreview = (m_stereo3D == STEREO_VR) && (LoadValueIntWithDefault("PlayerVR", "VRPreviewDisabled", 0) > 0);
if (disableVRPreview == 0)
m_sdl_playfieldHwnd = SDL_CreateWindow(
"Visual Pinball Player SDL", disp_x + (disp_w - m_width) / 2, disp_y + (disp_h - m_height) / 2, m_width, m_height,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | (m_fullscreen ? SDL_WINDOW_FULLSCREEN : 0));
else
m_sdl_playfieldHwnd = SDL_CreateWindow(
"Visual Pinball Player SDL", disp_x + (disp_w - 640) / 2, disp_y + (disp_h - 480) / 2, 640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(m_sdl_playfieldHwnd, &wmInfo);
m_windowHwnd = wmInfo.info.win.window;
m_sdl_context = SDL_GL_CreateContext(m_sdl_playfieldHwnd);
SDL_GL_MakeCurrent(m_sdl_playfieldHwnd, m_sdl_context);
if (!gladLoadGLLoader(SDL_GL_GetProcAddress)) {
ShowError("Glad failed");
exit(-1);
}
GLint frameBuffer[4];
glGetIntegerv(GL_VIEWPORT, frameBuffer);
int fbWidth = frameBuffer[2];
int fbHeight = frameBuffer[3];
switch (m_stereo3D) {
case STEREO_OFF:
m_Buf_width = fbWidth;
m_Buf_height = fbHeight;
m_Buf_widthBlur = m_Buf_width / 3;
m_Buf_heightBlur = m_Buf_height / 3;
m_Buf_width = (int)(m_Buf_width * m_AAfactor);
m_Buf_height = (int)(m_Buf_height * m_AAfactor);
break;
case STEREO_TB:
case STEREO_INT:
m_Buf_width = fbWidth;
m_Buf_height = fbHeight * 2;
m_Buf_widthBlur = m_Buf_width / 3;
m_Buf_heightBlur = m_Buf_height / 3;
m_Buf_width = (int)(m_Buf_width * m_AAfactor);
m_Buf_height = (int)(m_Buf_height * m_AAfactor);
break;
case STEREO_SBS:
m_Buf_width = fbWidth * 2;
m_Buf_height = fbHeight;
m_Buf_widthBlur = m_Buf_width / 3;
m_Buf_heightBlur = m_Buf_height / 3;
m_Buf_width = (int)(m_Buf_width * m_AAfactor);
m_Buf_height = (int)(m_Buf_height * m_AAfactor);
break;
#ifdef ENABLE_VR
case STEREO_VR:
if (LoadValueBoolWithDefault("PlayerVR", "scaleToFixedWidth", false)) {
float width = 0.0f;
g_pplayer->m_ptable->get_Width(&width);
m_scale = LoadValueFloatWithDefault("PlayerVR", "scaleAbsolute", 55.0f) *0.01f / width;
}
else {
m_scale = 0.000540425f * LoadValueFloatWithDefault("PlayerVR", "scaleRelative", 1.0f);
}
if (m_scale <= 0)
m_scale = 0.000540425f;// Scale factor for VPUnits to Meters
InitVR();
m_Buf_width = m_Buf_width * 2;
m_Buf_widthBlur = m_Buf_width / 3;
m_Buf_heightBlur = m_Buf_height / 3;
m_Buf_width = (int)(m_Buf_width * m_AAfactor);
m_Buf_height = (int)(m_Buf_height * m_AAfactor);
break;
#endif
default:
char buf[1024];
sprintf_s(buf, sizeof(buf), "Unknown stereo Mode id: %d", m_stereo3D);
std::runtime_error unknownStereoMode(buf);
throw(unknownStereoMode);
}
CHECKD3D();
if (m_stereo3D == STEREO_VR || m_vsync > refreshrate)
m_vsync = 0;
SDL_GL_SetSwapInterval(m_vsync);
m_autogen_mipmap = true;
// Retrieve a reference to the back buffer.
m_pBackBuffer = new RenderTarget;
m_pBackBuffer->width = fbWidth;
m_pBackBuffer->height = fbHeight;
CHECKD3D(glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)(&m_pBackBuffer->framebuffer)));
colorFormat renderBufferFormat = RGBA16F;
// alloc float buffer for rendering (optionally 2x2 res for manual super sampling)
m_pOffscreenBackBufferTexture = CreateTexture(m_Buf_width, m_Buf_height, 0, RENDERTARGET_DEPTH, renderBufferFormat, NULL, m_stereo3D);
if ((g_pplayer != NULL) && (g_pplayer->m_ptable->m_fReflectElementsOnPlayfield || (g_pplayer->m_fReflectionForBalls && (g_pplayer->m_ptable->m_useReflectionForBalls == -1)) || (g_pplayer->m_ptable->m_useReflectionForBalls == 1)))
m_pMirrorTmpBufferTexture = CreateTexture(m_Buf_width, m_Buf_height, 0, RENDERTARGET_DEPTH, renderBufferFormat, NULL, m_stereo3D);
// alloc bloom tex at 1/3 x 1/3 res (allows for simple HQ downscale of clipped input while saving memory)
m_pBloomBufferTexture = CreateTexture(m_Buf_widthBlur, m_Buf_heightBlur, 0, RENDERTARGET, renderBufferFormat, NULL, m_stereo3D);
// temporary buffer for gaussian blur
m_pBloomTmpBufferTexture = CreateTexture(m_Buf_widthBlur, m_Buf_heightBlur, 0, RENDERTARGET, renderBufferFormat, NULL, m_stereo3D);
// alloc temporary buffer for postprocessing
if ((m_FXAA > 0) || (m_stereo3D > 0))
m_pOffscreenBackBufferStereoTexture = CreateTexture(m_Buf_width, m_Buf_height, 0, RENDERTARGET, RGBA, NULL, 0);
else
m_pOffscreenBackBufferStereoTexture = NULL;
if (m_stereo3D == STEREO_VR) {
//AMD Debugging
colorFormat renderBufferFormatVR;
int textureModeVR = LoadValueIntWithDefault("Player", "textureModeVR", 1);
switch (textureModeVR) {
case 0:
renderBufferFormatVR = RGB8;
break;
case 2:
renderBufferFormatVR = RGB16F;
break;
case 3:
renderBufferFormatVR = RGBA16F;
break;
case 1:
default:
renderBufferFormatVR = RGBA8;
break;
}
m_pOffscreenVRLeft = CreateTexture(m_Buf_width / 2, m_Buf_height, 0, RENDERTARGET, renderBufferFormatVR, NULL, 0);
m_pOffscreenVRRight = CreateTexture(m_Buf_width / 2, m_Buf_height, 0, RENDERTARGET, renderBufferFormatVR, NULL, 0);
}
// alloc one more temporary buffer for SMAA
if (m_FXAA == Quality_SMAA)
m_pOffscreenBackBufferSMAATexture = CreateTexture(m_Buf_width, m_Buf_height, 0, RENDERTARGET, renderBufferFormat, NULL, 0);
else
m_pOffscreenBackBufferSMAATexture = NULL;
if (m_ssRefl)
m_pReflectionBufferTexture = CreateTexture(m_Buf_width, m_Buf_height, 0, RENDERTARGET_DEPTH, renderBufferFormat, NULL, 0);
else
m_pReflectionBufferTexture = NULL;
if (video10bit && (m_FXAA == Quality_SMAA || m_FXAA == Standard_DLAA))
ShowError("SMAA or DLAA post-processing AA should not be combined with 10bit-output rendering (will result in visible artifacts)!");
currentDeclaration = NULL;
//m_curShader = NULL;
// fill state caches with dummy values
memset(textureStateCache, 0xCC, sizeof(DWORD) * 8 * TEXTURE_STATE_CACHE_SIZE);
memset(textureSamplerCache, 0xCC, sizeof(DWORD) * 8 * TEXTURE_SAMPLER_CACHE_SIZE);
// initialize performance counters
m_curDrawCalls = m_frameDrawCalls = 0;
m_curStateChanges = m_frameStateChanges = 0;
m_curTextureChanges = m_frameTextureChanges = 0;
m_curParameterChanges = m_frameParameterChanges = 0;
m_curTextureUpdates = m_frameTextureUpdates = 0;
// CHECKD3D(glGetIntegeri_v(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, 0, (GLint*)&m_maxaniso));
m_maxaniso = 0;
if (m_quadVertexBuffer == NULL) {
VertexBuffer::CreateVertexBuffer(4, USAGE_STATIC, MY_D3DFVF_TEX, &m_quadVertexBuffer);
Vertex3D_TexelOnly* bufvb;
m_quadVertexBuffer->lock(0, 0, (void**)&bufvb, USAGE_STATIC);
static const float verts[4 * 5] = //GL Texture coordinates
{
1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
memcpy(bufvb, verts, 4 * sizeof(Vertex3D_TexelOnly));
m_quadVertexBuffer->unlock();
}
SetRenderState(RenderDevice::ZFUNC, RenderDevice::Z_LESSEQUAL);
CHECKD3D();
}
bool RenderDevice::LoadShaders()
{
bool shaderCompilationOkay = true;
CHECKD3D();
char glShaderPath[256];
DWORD length = GetModuleFileName(NULL, glShaderPath, 256);
if (m_stereo3D == STEREO_OFF) {
Shader::Defines = "#define eyes 1\n#define enable_VR 0";
} else if (m_stereo3D == STEREO_VR) {
Shader::Defines = "#define eyes 2\n#define enable_VR 1";
} else {
Shader::Defines = "#define eyes 2\n#define enable_VR 0";
}
Shader::shaderPath = string(glShaderPath);
Shader::shaderPath = Shader::shaderPath.substr(0, Shader::shaderPath.find_last_of("\\/"));
Shader::shaderPath.append("\\glshader\\");
basicShader = new Shader(this);
shaderCompilationOkay = basicShader->Load("BasicShader.glfx", 0) && shaderCompilationOkay;
ballShader = new Shader(this);
shaderCompilationOkay = ballShader->Load("ballShader.glfx", 0) && shaderCompilationOkay;
DMDShader = new Shader(this);
if (m_stereo3D == STEREO_VR)
shaderCompilationOkay = DMDShader->Load("DMDShaderVR.glfx", 0) && shaderCompilationOkay;
else
shaderCompilationOkay = DMDShader->Load("DMDShader.glfx", 0) && shaderCompilationOkay;
DMDShader->SetVector("quadOffsetScale", 0.0f, 0.0f, 1.0f, 1.0f);
DMDShader->SetVector("quadOffsetScaleTex", 0.0f, 0.0f, 1.0f, 1.0f);
FBShader = new Shader(this);
shaderCompilationOkay = FBShader->Load("FBShader.glfx", 0) && shaderCompilationOkay;
shaderCompilationOkay = FBShader->Load("SMAA.glfx", 0) && shaderCompilationOkay;
FBShader->SetVector("quadOffsetScale", 0.0f, 0.0f, 1.0f, 1.0f);
FBShader->SetVector("quadOffsetScaleTex", 0.0f, 0.0f, 1.0f, 1.0f);
if (m_stereo3D) {
StereoShader = new Shader(this);
shaderCompilationOkay = StereoShader->Load("StereoShader.glfx", 0) && shaderCompilationOkay;
}
else {
StereoShader = NULL;
}
flasherShader = new Shader(this);
shaderCompilationOkay = flasherShader->Load("flasherShader.glfx", 0) && shaderCompilationOkay;
lightShader = new Shader(this);
shaderCompilationOkay = lightShader->Load("lightShader.glfx", 0) && shaderCompilationOkay;
#ifdef SEPARATE_CLASSICLIGHTSHADER
classicLightShader = new Shader(this);
shaderCompilationOkay = classicLightShader->Load("classicLightShader.glfx", 0) && shaderCompilationOkay;
#endif
if (!shaderCompilationOkay)
ReportError("Fatal Error: shader compilation failed!", -1, __FILE__, __LINE__);
CHECKD3D();
if (shaderCompilationOkay && m_FXAA == Quality_SMAA)
UploadAndSetSMAATextures();
else
{
m_SMAAareaTexture = 0;
m_SMAAsearchTexture = 0;
}
return shaderCompilationOkay;
}
RenderDevice::~RenderDevice()