Skip to content

Commit 264f30a

Browse files
eagleivgXottab-DUTY
authored andcommitted
xrCore, xrRender, xrEngine, xrGame: initial SDL2 porting
1 parent 9b1aedc commit 264f30a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+587
-389
lines changed

.gitignore

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
# exclude all dot files except .git, appveyor and travis files
2-
.*
3-
!.git*
4-
!.appveyor*
5-
!.travis.yml
6-
7-
# exclude binaries and temporary files
8-
bin/
9-
bin_plugs/
10-
intermediate/
11-
intermediate_plugs/
12-
lib/
13-
*.aps
14-
*.user
15-
*.PVS-Studio.*
1+
src/packages

src/Layers/xrRender/D3DXRenderBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ class D3DXRenderBase : public IRender, public pureFrame
186186
virtual void OnDeviceDestroy(bool bKeepTextures) override;
187187
virtual void ValidateHW() override;
188188
virtual void DestroyHW() override;
189-
virtual void Reset(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) override;
189+
virtual void Reset(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) override;
190190
// Init
191191
virtual void SetupStates() override;
192192
virtual void OnDeviceCreate(const char* shName) override;
193-
virtual void Create(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool) override;
193+
virtual void Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool) override;
194194
virtual void SetupGPU(bool bForceGPU_SW, bool bForceGPU_NonPure, bool bForceGPU_REF) override;
195195
// Overdraw
196196
virtual void overdrawBegin() override;

src/Layers/xrRender/HW.cpp

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void CHW::DestroyD3D()
3636
_RELEASE(pD3D);
3737
}
3838

39-
void CHW::CreateDevice(HWND m_hWnd, bool move_window)
39+
void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
4040
{
4141
m_move_window = move_window;
4242
CreateD3D();
@@ -136,7 +136,22 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)
136136

137137
// Windoze
138138
P.SwapEffect = bWindowed ? D3DSWAPEFFECT_COPY : D3DSWAPEFFECT_DISCARD;
139-
P.hDeviceWindow = m_hWnd;
139+
140+
SDL_SysWMinfo info;
141+
SDL_VERSION(&info.version);
142+
if (SDL_GetWindowWMInfo(m_sdlWnd, &info))
143+
{
144+
switch (info.subsystem)
145+
{
146+
case SDL_SYSWM_WINDOWS:
147+
P.hDeviceWindow = info.info.win.window;
148+
break;
149+
default: break;
150+
}
151+
}
152+
else
153+
Log("Couldn't get window information: %s", SDL_GetError());
154+
140155
P.Windowed = bWindowed;
141156

142157
// Depth/stencil
@@ -158,13 +173,13 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)
158173

159174
// Create the device
160175
const auto GPU = selectGPU();
161-
auto result = HW.pD3D->CreateDevice(DevAdapter, m_DriverType, m_hWnd,
176+
auto result = HW.pD3D->CreateDevice(DevAdapter, m_DriverType, P.hDeviceWindow,
162177
GPU | D3DCREATE_MULTITHREADED, //. ? locks at present
163178
&P, &pDevice);
164179

165180
if (FAILED(result))
166181
{
167-
result = HW.pD3D->CreateDevice(DevAdapter, m_DriverType, m_hWnd,
182+
result = HW.pD3D->CreateDevice(DevAdapter, m_DriverType, P.hDeviceWindow,
168183
GPU | D3DCREATE_MULTITHREADED, //. ? locks at present
169184
&P, &pDevice);
170185
}
@@ -199,7 +214,7 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)
199214
Msg("* Texture memory: %d M", memory / (1024 * 1024));
200215
Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
201216

202-
updateWindowProps(m_hWnd);
217+
updateWindowProps(m_sdlWnd);
203218
fill_vid_mode_list(this);
204219
}
205220

@@ -225,7 +240,7 @@ void CHW::DestroyDevice()
225240
//////////////////////////////////////////////////////////////////////
226241
// Resetting device
227242
//////////////////////////////////////////////////////////////////////
228-
void CHW::Reset(HWND hwnd)
243+
void CHW::Reset(SDL_Window* m_sdlWnd)
229244
{
230245
#ifdef DEBUG
231246
_RELEASE(dwDebugSB);
@@ -270,8 +285,8 @@ void CHW::Reset(HWND hwnd)
270285
R_CHK(pDevice->CreateStateBlock(D3DSBT_ALL, &dwDebugSB));
271286
#endif
272287

273-
updateWindowProps(hwnd);
274-
ShowWindow(hwnd, SW_SHOWNORMAL);
288+
updateWindowProps(m_sdlWnd);
289+
SDL_ShowWindow(m_sdlWnd);
275290
}
276291

277292
D3DFORMAT CHW::selectDepthStencil(D3DFORMAT fTarget)
@@ -451,7 +466,7 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
451466
return TRUE;
452467
}
453468

454-
void CHW::updateWindowProps(HWND m_hWnd)
469+
void CHW::updateWindowProps(SDL_Window *m_sdlWnd)
455470
{
456471
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
457472

@@ -464,11 +479,8 @@ void CHW::updateWindowProps(HWND m_hWnd)
464479
{
465480
if (m_move_window)
466481
{
467-
const bool drawBorders = strstr(Core.Params, "-draw_borders");
468-
dwWindowStyle = WS_VISIBLE;
469-
if (drawBorders)
470-
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
471-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
482+
if(NULL != strstr(Core.Params, "-draw_borders"))
483+
SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE);
472484
// When moving from fullscreen to windowed mode, it is important to
473485
// adjust the window size after recreating the device rather than
474486
// beforehand to ensure that you get the window size you want. For
@@ -478,47 +490,29 @@ void CHW::updateWindowProps(HWND m_hWnd)
478490
// changed to 1024x768, because windows cannot be larger than the
479491
// desktop.
480492

481-
RECT m_rcWindowBounds;
482-
float fYOffset = 0.f;
483493
bool centerScreen = false;
484494
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
485495
centerScreen = true;
486496

497+
SDL_SetWindowSize(m_sdlWnd, DevPP.BackBufferWidth, DevPP.BackBufferHeight);
498+
487499
if (centerScreen)
488500
{
489-
RECT DesktopRect;
490-
491-
GetClientRect(GetDesktopWindow(), &DesktopRect);
492-
493-
SetRect(&m_rcWindowBounds,
494-
(DesktopRect.right - DevPP.BackBufferWidth) / 2,
495-
(DesktopRect.bottom - DevPP.BackBufferHeight) / 2,
496-
(DesktopRect.right + DevPP.BackBufferWidth) / 2,
497-
(DesktopRect.bottom + DevPP.BackBufferHeight) / 2);
501+
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
498502
}
499503
else
500504
{
501-
if (drawBorders)
502-
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
503-
SetRect(&m_rcWindowBounds, 0, 0, DevPP.BackBufferWidth, DevPP.BackBufferHeight);
504-
};
505-
506-
AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);
507-
508-
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
509-
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
510-
m_rcWindowBounds.right - m_rcWindowBounds.left,
511-
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
512-
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
505+
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
506+
}
513507
}
514508
}
515509
else
516510
{
517-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
511+
SDL_ShowWindow(m_sdlWnd);
518512
}
519513

520514
if (!GEnv.isDedicatedServer)
521-
SetForegroundWindow(m_hWnd);
515+
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
522516
}
523517

524518
struct uniqueRenderingMode

src/Layers/xrRender/HW.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "HWCaps.h"
44
#include "xrCore/ModuleLookup.hpp"
5+
#include "SDL.h"
6+
#include "SDL_syswm.h"
57

68
#if !defined(_MAYA_EXPORT) && !defined(USE_OGL)
79
#include "stats_manager.h"
@@ -23,11 +25,11 @@ class CHW
2325
void DestroyD3D();
2426
#endif // !USE_OGL
2527

26-
void CreateDevice(HWND hw, bool move_window);
28+
void CreateDevice(SDL_Window* m_sdlWnd, bool move_window);
2729

2830
void DestroyDevice();
2931

30-
void Reset(HWND hw);
32+
void Reset(SDL_Window* m_sdlWnd);
3133

3234
#ifndef USE_OGL
3335
void selectResolution(u32& dwWidth, u32& dwHeight, BOOL bWindowed);
@@ -38,10 +40,10 @@ class CHW
3840
BOOL support(D3DFORMAT fmt, DWORD type, DWORD usage);
3941
#endif // !USE_OGL
4042

41-
void updateWindowProps(HWND hw);
43+
void updateWindowProps(SDL_Window* m_sdlWnd);
4244
#ifdef DEBUG
4345
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
44-
void Validate(void) {};
46+
void Validate(void){};
4547
#else // USE_DX10
4648
void Validate(void)
4749
{
@@ -71,11 +73,11 @@ class CHW
7173
HGLRC m_hRC;
7274
#elif defined(USE_DX11)
7375
public:
74-
IDXGIFactory1* m_pFactory = nullptr;
75-
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
76-
ID3D11Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
77-
ID3D11DeviceContext* pContext = nullptr; // combine with DX9 pDevice via typedef
78-
IDXGISwapChain* m_pSwapChain = nullptr;
76+
IDXGIFactory1* m_pFactory = nullptr;
77+
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
78+
ID3D11Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
79+
ID3D11DeviceContext* pContext = nullptr; // combine with DX9 pDevice via typedef
80+
IDXGISwapChain* m_pSwapChain = nullptr;
7981
ID3D11RenderTargetView* pBaseRT = nullptr; // combine with DX9 pBaseRT via typedef
8082
ID3D11DepthStencilView* pBaseZB = nullptr;
8183

@@ -86,13 +88,13 @@ class CHW
8688
D3D_FEATURE_LEVEL FeatureLevel;
8789
#elif defined(USE_DX10)
8890
public:
89-
IDXGIFactory1* m_pFactory = nullptr;
90-
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
91-
ID3D10Device1* pDevice1 = nullptr; // combine with DX9 pDevice via typedef
92-
ID3D10Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
93-
ID3D10Device1* pContext1 = nullptr; // combine with DX9 pDevice via typedef
94-
ID3D10Device* pContext = nullptr; // combine with DX9 pDevice via typedef
95-
IDXGISwapChain* m_pSwapChain = nullptr;
91+
IDXGIFactory1* m_pFactory = nullptr;
92+
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
93+
ID3D10Device1* pDevice1 = nullptr; // combine with DX9 pDevice via typedef
94+
ID3D10Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
95+
ID3D10Device1* pContext1 = nullptr; // combine with DX9 pDevice via typedef
96+
ID3D10Device* pContext = nullptr; // combine with DX9 pDevice via typedef
97+
IDXGISwapChain* m_pSwapChain = nullptr;
9698
ID3D10RenderTargetView* pBaseRT = nullptr; // combine with DX9 pBaseRT via typedef
9799
ID3D10DepthStencilView* pBaseZB = nullptr;
98100

@@ -109,8 +111,8 @@ class CHW
109111
XRay::Module hD3D = nullptr;
110112

111113
public:
112-
IDirect3D9* pD3D = nullptr; // D3D
113-
IDirect3DDevice9* pDevice = nullptr; // render device
114+
IDirect3D9* pD3D = nullptr; // D3D
115+
IDirect3DDevice9* pDevice = nullptr; // render device
114116
IDirect3DSurface9* pBaseRT = nullptr;
115117
IDirect3DSurface9* pBaseZB = nullptr;
116118

@@ -142,7 +144,7 @@ class CHW
142144
HRESULT Present(UINT SyncInterval, UINT Flags);
143145
#endif // USE_OGL
144146

145-
int maxRefreshRate = 200; //ECO_RENDER add
147+
int maxRefreshRate = 200; // ECO_RENDER add
146148

147149
private:
148150
bool m_move_window = true;

src/Layers/xrRenderDX10/dx10HW.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void CHW::DestroyD3D()
6464
_RELEASE(m_pFactory);
6565
}
6666

67-
void CHW::CreateDevice(HWND m_hWnd, bool move_window)
67+
void CHW::CreateDevice(SDL_Window* hWnd, bool move_window)
6868
{
6969
m_move_window = move_window;
7070
CreateD3D();
@@ -110,7 +110,20 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)
110110

111111
// Windoze
112112
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
113-
sd.OutputWindow = m_hWnd;
113+
SDL_SysWMinfo info;
114+
SDL_VERSION(&info.version);
115+
if (SDL_GetWindowWMInfo(m_sdlWnd, &info))
116+
{
117+
switch (info.subsystem)
118+
{
119+
case SDL_SYSWM_WINDOWS:
120+
sd.OutputWindow = info.info.win.window;
121+
break;
122+
default: break;
123+
}
124+
}
125+
else
126+
Log("Couldn't get window information: %s", SDL_GetError());
114127
sd.Windowed = bWindowed;
115128

116129
// Depth/stencil (DX10 don't need this?)

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,18 @@ void CHW::Reset(HWND hwnd)
179179
ShowWindow(hwnd, SW_SHOWNORMAL);
180180
}
181181

182-
void CHW::updateWindowProps(HWND m_hWnd)
182+
void CHW::updateWindowProps(SDL_Window* m_sdlWnd)
183183
{
184-
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);
184+
bool bWindowed = !psDeviceFlags.is(rsFullscreen);
185185

186186
u32 dwWindowStyle = 0;
187187
// Set window properties depending on what mode were in.
188188
if (bWindowed)
189189
{
190190
if (m_move_window)
191191
{
192-
const bool drawBorders = strstr(Core.Params, "-draw_borders");
193-
dwWindowStyle = WS_VISIBLE;
194-
if (drawBorders)
195-
dwWindowStyle |= WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
196-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle);
192+
if (NULL != strstr(Core.Params, "-draw_borders"))
193+
SDL_SetWindowBordered(m_sdlWnd, SDL_TRUE);
197194
// When moving from fullscreen to windowed mode, it is important to
198195
// adjust the window size after recreating the device rather than
199196
// beforehand to ensure that you get the window size you want. For
@@ -203,45 +200,29 @@ void CHW::updateWindowProps(HWND m_hWnd)
203200
// changed to 1024x768, because windows cannot be larger than the
204201
// desktop.
205202

206-
RECT m_rcWindowBounds;
207-
float fYOffset = 0.f;
208203
bool centerScreen = false;
209-
if (strstr(Core.Params, "-center_screen"))
204+
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
210205
centerScreen = true;
211206

207+
SDL_SetWindowSize(m_sdlWnd, psCurrentVidMode[0], psCurrentVidMode[1]);
208+
212209
if (centerScreen)
213210
{
214-
RECT DesktopRect;
215-
GetClientRect(GetDesktopWindow(), &DesktopRect);
216-
217-
SetRect(&m_rcWindowBounds,
218-
(DesktopRect.right - psCurrentVidMode[0]) / 2,
219-
(DesktopRect.bottom - psCurrentVidMode[1]) / 2,
220-
(DesktopRect.right + psCurrentVidMode[0]) / 2,
221-
(DesktopRect.bottom + psCurrentVidMode[1]) / 2);
211+
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
222212
}
223213
else
224214
{
225-
if (drawBorders)
226-
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
227-
SetRect(&m_rcWindowBounds, 0, 0, psCurrentVidMode[0], psCurrentVidMode[1]);
215+
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
228216
}
229-
230-
AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);
231-
232-
SetWindowPos(m_hWnd, HWND_NOTOPMOST,
233-
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
234-
m_rcWindowBounds.right - m_rcWindowBounds.left,
235-
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
236-
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
237217
}
238218
}
239219
else
240220
{
241-
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
221+
SDL_ShowWindow(m_sdlWnd);
242222
}
243223

244-
SetForegroundWindow(m_hWnd);
224+
if (!GEnv.isDedicatedServer)
225+
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
245226
}
246227

247228
struct uniqueRenderingMode
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="sdl2" version="2.0.5" targetFramework="native" />
4+
<package id="sdl2.redist" version="2.0.5" targetFramework="native" />
5+
</packages>

0 commit comments

Comments
 (0)