Skip to content

Commit

Permalink
Moved part of the window management code from renderers to xrEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jul 16, 2018
1 parent 92be298 commit 5529556
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 197 deletions.
2 changes: 1 addition & 1 deletion src/Layers/xrRender/D3DXRenderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class D3DXRenderBase : public IRender, public pureFrame
// Init
virtual void SetupStates() override;
virtual void OnDeviceCreate(const char* shName) override;
virtual void Create(SDL_Window* 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) override;
virtual void SetupGPU(bool bForceGPU_SW, bool bForceGPU_NonPure, bool bForceGPU_REF) override;
// Overdraw
virtual void overdrawBegin() override;
Expand Down
60 changes: 3 additions & 57 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ void CHW::DestroyD3D()
_RELEASE(pD3D);
}

void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
void CHW::CreateDevice(SDL_Window* m_sdlWnd)
{
m_move_window = move_window;
CreateD3D();

bool bWindowed = !psDeviceFlags.is(rsFullscreen);
if (GEnv.isDedicatedServer)
if (GEnv.isDedicatedServer || Device.editor())
bWindowed = true;

m_DriverType = Caps.bForceGPU_REF ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL;
Expand Down Expand Up @@ -214,7 +213,6 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
Msg("* Texture memory: %d M", memory / (1024 * 1024));
Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);

updateWindowProps(m_sdlWnd);
fill_vid_mode_list(this);
}

Expand All @@ -240,7 +238,7 @@ void CHW::DestroyDevice()
//////////////////////////////////////////////////////////////////////
// Resetting device
//////////////////////////////////////////////////////////////////////
void CHW::Reset(SDL_Window* m_sdlWnd)
void CHW::Reset()
{
#ifdef DEBUG
_RELEASE(dwDebugSB);
Expand Down Expand Up @@ -284,9 +282,6 @@ void CHW::Reset(SDL_Window* m_sdlWnd)
#ifdef DEBUG
R_CHK(pDevice->CreateStateBlock(D3DSBT_ALL, &dwDebugSB));
#endif

updateWindowProps(m_sdlWnd);
SDL_ShowWindow(m_sdlWnd);
}

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

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

if (GEnv.isDedicatedServer)
bWindowed = true;

u32 dwWindowStyle = 0;
// Set window properties depending on what mode were in.
if (bWindowed)
{
if (m_move_window)
{
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
// example, when switching from 640x480 fullscreen to windowed with
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
// the window size to 1000x600 until after the display mode has
// changed to 1024x768, because windows cannot be larger than the
// desktop.

bool centerScreen = false;
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
centerScreen = true;

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

if (centerScreen)
{
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
else
{
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
}
}
}
else
{
SDL_ShowWindow(m_sdlWnd);
}

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

struct uniqueRenderingMode
{
uniqueRenderingMode(pcstr v) : value(v) {}
Expand Down
8 changes: 2 additions & 6 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class CHW
void DestroyD3D();
#endif // !USE_OGL

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

void DestroyDevice();

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

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

void updateWindowProps(SDL_Window* m_sdlWnd);
#ifdef DEBUG
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
void Validate(void){};
Expand Down Expand Up @@ -145,9 +144,6 @@ class CHW
#endif // USE_OGL

int maxRefreshRate = 200; // ECO_RENDER add

private:
bool m_move_window = true;
};

extern ECORE_API CHW HW;
8 changes: 4 additions & 4 deletions src/Layers/xrRender/r__dsgraph_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,15 +804,15 @@ void D3DXRenderBase::DestroyHW()
HW.DestroyDevice();
}

void D3DXRenderBase::Reset(SDL_Window *hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2)
void D3DXRenderBase::Reset(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2)
{
#if defined(DEBUG) && !defined(USE_OGL)
_SHOW_REF("*ref -CRenderDevice::ResetTotal: DeviceREF:", HW.pDevice);
#endif // DEBUG

Resources->reset_begin();
Memory.mem_compact();
HW.Reset(hWnd);
HW.Reset();

#if defined(USE_OGL)
dwWidth = psCurrentVidMode[0];
Expand Down Expand Up @@ -900,9 +900,9 @@ void D3DXRenderBase::OnDeviceCreate(const char* shName)
}
}

void D3DXRenderBase::Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2, bool move_window)
void D3DXRenderBase::Create(SDL_Window* hWnd, u32& dwWidth, u32& dwHeight, float& fWidth_2, float& fHeight_2)
{
HW.CreateDevice(hWnd, move_window);
HW.CreateDevice(hWnd);
#if defined(USE_OGL)
dwWidth = psCurrentVidMode[0];
dwHeight = psCurrentVidMode[1];
Expand Down
59 changes: 3 additions & 56 deletions src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ void CHW::DestroyD3D()
_RELEASE(m_pFactory);
}

void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
void CHW::CreateDevice(SDL_Window* m_sdlWnd)
{
m_move_window = move_window;
CreateD3D();

bool bWindowed = !psDeviceFlags.is(rsFullscreen);
bool bWindowed = !psDeviceFlags.is(rsFullscreen) || Device.editor();

m_DriverType = Caps.bForceGPU_REF ? D3D_DRIVER_TYPE_REFERENCE : D3D_DRIVER_TYPE_HARDWARE;

Expand Down Expand Up @@ -196,10 +195,7 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
const auto memory = Desc.DedicatedVideoMemory;
Msg("* Texture memory: %d M", memory / (1024 * 1024));
//Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
#ifndef _EDITOR
updateWindowProps(m_sdlWnd);
fill_vid_mode_list(this);
#endif
}

void CHW::DestroyDevice()
Expand Down Expand Up @@ -241,7 +237,7 @@ void CHW::DestroyDevice()
//////////////////////////////////////////////////////////////////////
// Resetting device
//////////////////////////////////////////////////////////////////////
void CHW::Reset(SDL_Window* m_sdlWnd)
void CHW::Reset()
{
DXGI_SWAP_CHAIN_DESC& cd = m_ChainDesc;
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
Expand All @@ -265,9 +261,6 @@ void CHW::Reset(SDL_Window* m_sdlWnd)
CHK_DX(m_pSwapChain->ResizeBuffers(
cd.BufferCount, desc.Width, desc.Height, desc.Format, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH));
UpdateViews();

updateWindowProps(m_sdlWnd);
SDL_ShowWindow(m_sdlWnd);
}

D3DFORMAT CHW::selectDepthStencil(D3DFORMAT /*fTarget*/)
Expand Down Expand Up @@ -353,52 +346,6 @@ BOOL CHW::support(D3DFORMAT fmt, DWORD type, DWORD usage)
return TRUE;
}

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

u32 dwWindowStyle = 0;
// Set window properties depending on what mode were in.
if (bWindowed)
{
if (m_move_window)
{
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
// example, when switching from 640x480 fullscreen to windowed with
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
// the window size to 1000x600 until after the display mode has
// changed to 1024x768, because windows cannot be larger than the
// desktop.

bool centerScreen = false;
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
centerScreen = true;

SDL_SetWindowSize(m_sdlWnd, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);

if (centerScreen)
{
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
else
{
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
}
}
}
else
{
SDL_ShowWindow(m_sdlWnd);
}

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

struct uniqueRenderingMode
{
uniqueRenderingMode(pcstr v) : value(v) {}
Expand Down
65 changes: 3 additions & 62 deletions src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ CHW::CHW() :
pFB(0),
m_hWnd(nullptr),
m_hDC(nullptr),
m_hRC(nullptr),
m_move_window(true) {}
m_hRC(nullptr) {}

CHW::~CHW() {}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void CHW::CreateDevice(SDL_Window *hWnd, bool move_window)
void CHW::CreateDevice(SDL_Window* hWnd)
{
m_hWnd = hWnd;
m_move_window = move_window;

R_ASSERT(m_hWnd);

Expand Down Expand Up @@ -94,11 +92,7 @@ void CHW::CreateDevice(SDL_Window *hWnd, bool move_window)

// Create render target and depth-stencil views here
UpdateViews();

#ifndef _EDITOR
updateWindowProps(m_hWnd);
fill_vid_mode_list(this);
#endif
}

void CHW::DestroyDevice()
Expand All @@ -119,10 +113,8 @@ void CHW::DestroyDevice()
//////////////////////////////////////////////////////////////////////
// Resetting device
//////////////////////////////////////////////////////////////////////
void CHW::Reset(SDL_Window* hwnd)
void CHW::Reset()
{
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);

CHK_GL(glDeleteProgramPipelines(1, &pPP));
CHK_GL(glDeleteFramebuffers(1, &pFB));
CHK_GL(glDeleteFramebuffers(1, &pCFB));
Expand All @@ -131,57 +123,6 @@ void CHW::Reset(SDL_Window* hwnd)
CHK_GL(glDeleteTextures(1, &pBaseZB));

UpdateViews();

updateWindowProps(hwnd);
SDL_ShowWindow(hwnd);
}

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

u32 dwWindowStyle = 0;
// Set window properties depending on what mode were in.
if (bWindowed)
{
if (m_move_window)
{
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
// example, when switching from 640x480 fullscreen to windowed with
// a 1000x600 window on a 1024x768 desktop, it is impossible to set
// the window size to 1000x600 until after the display mode has
// changed to 1024x768, because windows cannot be larger than the
// desktop.

bool centerScreen = false;
if (GEnv.isDedicatedServer || strstr(Core.Params, "-center_screen"))
centerScreen = true;

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

if (centerScreen)
{
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
else
{
SDL_SetWindowPosition(m_sdlWnd, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
}
}
}
else
{
SDL_SetWindowPosition(m_sdlWnd, 0, 0);
SDL_SetWindowSize(m_sdlWnd, psCurrentVidMode[0], psCurrentVidMode[1]);
SDL_ShowWindow(m_sdlWnd);
}

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

struct uniqueRenderingMode
Expand Down
4 changes: 2 additions & 2 deletions src/xrEngine/Device_Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ void CRenderDevice::Initialize()

if (!m_sdlWnd)
{
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL;
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
#if SDL_VERSION_ATLEAST(2, 0, 5)
flags |= SDL_WINDOW_ALWAYS_ON_TOP;
#endif

m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, flags);
m_sdlWnd = SDL_CreateWindow("S.T.A.L.K.E.R.: Call of Pripyat", 0, 0, 640, 480, flags);

R_ASSERT3(m_sdlWnd, "Unable to create SDL window", SDL_GetError());
}
Expand Down
Loading

0 comments on commit 5529556

Please sign in to comment.