Skip to content

Commit

Permalink
xrCore, xrRender, xrEngine, xrGame: initial SDL2 porting
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg authored and Xottab-DUTY committed Jul 24, 2018
1 parent 9b1aedc commit 264f30a
Show file tree
Hide file tree
Showing 57 changed files with 587 additions and 389 deletions.
16 changes: 1 addition & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
# exclude all dot files except .git, appveyor and travis files
.*
!.git*
!.appveyor*
!.travis.yml

# exclude binaries and temporary files
bin/
bin_plugs/
intermediate/
intermediate_plugs/
lib/
*.aps
*.user
*.PVS-Studio.*
src/packages
4 changes: 2 additions & 2 deletions src/Layers/xrRender/D3DXRenderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ class D3DXRenderBase : public IRender, public pureFrame
virtual void OnDeviceDestroy(bool bKeepTextures) override;
virtual void ValidateHW() override;
virtual void DestroyHW() override;
virtual void Reset(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) override;
virtual void Reset(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2) override;
// Init
virtual void SetupStates() override;
virtual void OnDeviceCreate(const char* shName) override;
virtual void Create(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool) override;
virtual void Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool) override;
virtual void SetupGPU(bool bForceGPU_SW, bool bForceGPU_NonPure, bool bForceGPU_REF) override;
// Overdraw
virtual void overdrawBegin() override;
Expand Down
72 changes: 33 additions & 39 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void CHW::DestroyD3D()
_RELEASE(pD3D);
}

void CHW::CreateDevice(HWND m_hWnd, bool move_window)
void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
{
m_move_window = move_window;
CreateD3D();
Expand Down Expand Up @@ -136,7 +136,22 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)

// Windoze
P.SwapEffect = bWindowed ? D3DSWAPEFFECT_COPY : D3DSWAPEFFECT_DISCARD;
P.hDeviceWindow = m_hWnd;

SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(m_sdlWnd, &info))
{
switch (info.subsystem)
{
case SDL_SYSWM_WINDOWS:
P.hDeviceWindow = info.info.win.window;
break;
default: break;
}
}
else
Log("Couldn't get window information: %s", SDL_GetError());

P.Windowed = bWindowed;

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

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

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

updateWindowProps(m_hWnd);
updateWindowProps(m_sdlWnd);
fill_vid_mode_list(this);
}

Expand All @@ -225,7 +240,7 @@ void CHW::DestroyDevice()
//////////////////////////////////////////////////////////////////////
// Resetting device
//////////////////////////////////////////////////////////////////////
void CHW::Reset(HWND hwnd)
void CHW::Reset(SDL_Window* m_sdlWnd)
{
#ifdef DEBUG
_RELEASE(dwDebugSB);
Expand Down Expand Up @@ -270,8 +285,8 @@ void CHW::Reset(HWND hwnd)
R_CHK(pDevice->CreateStateBlock(D3DSBT_ALL, &dwDebugSB));
#endif

updateWindowProps(hwnd);
ShowWindow(hwnd, SW_SHOWNORMAL);
updateWindowProps(m_sdlWnd);
SDL_ShowWindow(m_sdlWnd);
}

D3DFORMAT CHW::selectDepthStencil(D3DFORMAT fTarget)
Expand Down Expand Up @@ -451,7 +466,7 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
return TRUE;
}

void CHW::updateWindowProps(HWND m_hWnd)
void CHW::updateWindowProps(SDL_Window *m_sdlWnd)
{
bool bWindowed = !psDeviceFlags.is(rsFullscreen);

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

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

SDL_SetWindowSize(m_sdlWnd, DevPP.BackBufferWidth, DevPP.BackBufferHeight);

if (centerScreen)
{
RECT DesktopRect;

GetClientRect(GetDesktopWindow(), &DesktopRect);

SetRect(&m_rcWindowBounds,
(DesktopRect.right - DevPP.BackBufferWidth) / 2,
(DesktopRect.bottom - DevPP.BackBufferHeight) / 2,
(DesktopRect.right + DevPP.BackBufferWidth) / 2,
(DesktopRect.bottom + DevPP.BackBufferHeight) / 2);
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
else
{
if (drawBorders)
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
SetRect(&m_rcWindowBounds, 0, 0, DevPP.BackBufferWidth, DevPP.BackBufferHeight);
};

AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);

SetWindowPos(m_hWnd, HWND_NOTOPMOST,
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
m_rcWindowBounds.right - m_rcWindowBounds.left,
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
}
}
}
else
{
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
SDL_ShowWindow(m_sdlWnd);
}

if (!GEnv.isDedicatedServer)
SetForegroundWindow(m_hWnd);
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
}

struct uniqueRenderingMode
Expand Down
40 changes: 21 additions & 19 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "HWCaps.h"
#include "xrCore/ModuleLookup.hpp"
#include "SDL.h"
#include "SDL_syswm.h"

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

void CreateDevice(HWND hw, bool move_window);
void CreateDevice(SDL_Window* m_sdlWnd, bool move_window);

void DestroyDevice();

void Reset(HWND hw);
void Reset(SDL_Window* m_sdlWnd);

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

void updateWindowProps(HWND hw);
void updateWindowProps(SDL_Window* m_sdlWnd);
#ifdef DEBUG
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
void Validate(void) {};
void Validate(void){};
#else // USE_DX10
void Validate(void)
{
Expand Down Expand Up @@ -71,11 +73,11 @@ class CHW
HGLRC m_hRC;
#elif defined(USE_DX11)
public:
IDXGIFactory1* m_pFactory = nullptr;
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3D11Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
ID3D11DeviceContext* pContext = nullptr; // combine with DX9 pDevice via typedef
IDXGISwapChain* m_pSwapChain = nullptr;
IDXGIFactory1* m_pFactory = nullptr;
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3D11Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
ID3D11DeviceContext* pContext = nullptr; // combine with DX9 pDevice via typedef
IDXGISwapChain* m_pSwapChain = nullptr;
ID3D11RenderTargetView* pBaseRT = nullptr; // combine with DX9 pBaseRT via typedef
ID3D11DepthStencilView* pBaseZB = nullptr;

Expand All @@ -86,13 +88,13 @@ class CHW
D3D_FEATURE_LEVEL FeatureLevel;
#elif defined(USE_DX10)
public:
IDXGIFactory1* m_pFactory = nullptr;
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3D10Device1* pDevice1 = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device1* pContext1 = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device* pContext = nullptr; // combine with DX9 pDevice via typedef
IDXGISwapChain* m_pSwapChain = nullptr;
IDXGIFactory1* m_pFactory = nullptr;
IDXGIAdapter1* m_pAdapter = nullptr; // pD3D equivalent
ID3D10Device1* pDevice1 = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device* pDevice = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device1* pContext1 = nullptr; // combine with DX9 pDevice via typedef
ID3D10Device* pContext = nullptr; // combine with DX9 pDevice via typedef
IDXGISwapChain* m_pSwapChain = nullptr;
ID3D10RenderTargetView* pBaseRT = nullptr; // combine with DX9 pBaseRT via typedef
ID3D10DepthStencilView* pBaseZB = nullptr;

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

public:
IDirect3D9* pD3D = nullptr; // D3D
IDirect3DDevice9* pDevice = nullptr; // render device
IDirect3D9* pD3D = nullptr; // D3D
IDirect3DDevice9* pDevice = nullptr; // render device
IDirect3DSurface9* pBaseRT = nullptr;
IDirect3DSurface9* pBaseZB = nullptr;

Expand Down Expand Up @@ -142,7 +144,7 @@ class CHW
HRESULT Present(UINT SyncInterval, UINT Flags);
#endif // USE_OGL

int maxRefreshRate = 200; //ECO_RENDER add
int maxRefreshRate = 200; // ECO_RENDER add

private:
bool m_move_window = true;
Expand Down
17 changes: 15 additions & 2 deletions src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void CHW::DestroyD3D()
_RELEASE(m_pFactory);
}

void CHW::CreateDevice(HWND m_hWnd, bool move_window)
void CHW::CreateDevice(SDL_Window* hWnd, bool move_window)
{
m_move_window = move_window;
CreateD3D();
Expand Down Expand Up @@ -110,7 +110,20 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)

// Windoze
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.OutputWindow = m_hWnd;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(m_sdlWnd, &info))
{
switch (info.subsystem)
{
case SDL_SYSWM_WINDOWS:
sd.OutputWindow = info.info.win.window;
break;
default: break;
}
}
else
Log("Couldn't get window information: %s", SDL_GetError());
sd.Windowed = bWindowed;

// Depth/stencil (DX10 don't need this?)
Expand Down
43 changes: 12 additions & 31 deletions src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,18 @@ void CHW::Reset(HWND hwnd)
ShowWindow(hwnd, SW_SHOWNORMAL);
}

void CHW::updateWindowProps(HWND m_hWnd)
void CHW::updateWindowProps(SDL_Window* m_sdlWnd)
{
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);
bool bWindowed = !psDeviceFlags.is(rsFullscreen);

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

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

SDL_SetWindowSize(m_sdlWnd, psCurrentVidMode[0], psCurrentVidMode[1]);

if (centerScreen)
{
RECT DesktopRect;
GetClientRect(GetDesktopWindow(), &DesktopRect);

SetRect(&m_rcWindowBounds,
(DesktopRect.right - psCurrentVidMode[0]) / 2,
(DesktopRect.bottom - psCurrentVidMode[1]) / 2,
(DesktopRect.right + psCurrentVidMode[0]) / 2,
(DesktopRect.bottom + psCurrentVidMode[1]) / 2);
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
else
{
if (drawBorders)
fYOffset = GetSystemMetrics(SM_CYCAPTION); // size of the window title bar
SetRect(&m_rcWindowBounds, 0, 0, psCurrentVidMode[0], psCurrentVidMode[1]);
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
}

AdjustWindowRect(&m_rcWindowBounds, dwWindowStyle, FALSE);

SetWindowPos(m_hWnd, HWND_NOTOPMOST,
m_rcWindowBounds.left, m_rcWindowBounds.top + fYOffset,
m_rcWindowBounds.right - m_rcWindowBounds.left,
m_rcWindowBounds.bottom - m_rcWindowBounds.top,
SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_DRAWFRAME);
}
}
else
{
SetWindowLong(m_hWnd, GWL_STYLE, dwWindowStyle = WS_POPUP | WS_VISIBLE);
SDL_ShowWindow(m_sdlWnd);
}

SetForegroundWindow(m_hWnd);
if (!GEnv.isDedicatedServer)
SDL_SetWindowGrab(m_sdlWnd, SDL_TRUE);
}

struct uniqueRenderingMode
Expand Down
5 changes: 5 additions & 0 deletions src/Layers/xrRenderPC_GL/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="sdl2" version="2.0.5" targetFramework="native" />
<package id="sdl2.redist" version="2.0.5" targetFramework="native" />
</packages>
Loading

0 comments on commit 264f30a

Please sign in to comment.