Skip to content

Commit

Permalink
xrEngine: fix build with SDL2
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 264f30a commit d341b9b
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 587 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_subdirectory(Layers)
add_subdirectory(xrAICore)
add_subdirectory(xrCDB)
add_subdirectory(xrCore)
#add_subdirectory(xrEngine)
add_subdirectory(xrEngine)
#add_subdirectory(xrGame)
#add_subdirectory(xrNetServer)
add_subdirectory(xrParticles)
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class CHW

CHWCaps Caps;

HWND m_hWnd;
SDL_Window* m_hWnd;
HDC m_hDC;
HGLRC m_hRC;
SDL_GLContext m_hRC;
#elif defined(USE_DX11)
public:
IDXGIFactory1* m_pFactory = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/r__dsgraph_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void D3DXRenderBase::DestroyHW()
HW.DestroyDevice();
}

void D3DXRenderBase::Reset(HWND 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);
Expand Down Expand Up @@ -901,7 +901,7 @@ void D3DXRenderBase::OnDeviceCreate(const char* shName)
}
}

void D3DXRenderBase::Create(HWND 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, bool move_window)
{
HW.CreateDevice(hWnd, move_window);
#if defined(USE_OGL)
Expand Down
53 changes: 17 additions & 36 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(SDL_Window* hWnd, bool move_window)
void CHW::CreateDevice(SDL_Window* m_sdlWnd, bool move_window)
{
m_move_window = move_window;
CreateD3D();
Expand Down Expand Up @@ -196,7 +196,7 @@ void CHW::CreateDevice(SDL_Window* hWnd, bool move_window)
Msg("* Texture memory: %d M", memory / (1024 * 1024));
//Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
#ifndef _EDITOR
updateWindowProps(m_hWnd);
updateWindowProps(m_sdlWnd);
fill_vid_mode_list(this);
#endif
}
Expand Down Expand Up @@ -240,7 +240,7 @@ void CHW::DestroyDevice()
//////////////////////////////////////////////////////////////////////
// Resetting device
//////////////////////////////////////////////////////////////////////
void CHW::Reset(HWND hwnd)
void CHW::Reset(SDL_Window* m_sdlWnd)
{
DXGI_SWAP_CHAIN_DESC& cd = m_ChainDesc;
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);
Expand All @@ -265,8 +265,8 @@ void CHW::Reset(HWND hwnd)
cd.BufferCount, desc.Width, desc.Height, desc.Format, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH));
UpdateViews();

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

D3DFORMAT CHW::selectDepthStencil(D3DFORMAT /*fTarget*/)
Expand Down Expand Up @@ -352,7 +352,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 @@ -362,11 +362,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 @@ -376,45 +373,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, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);

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

SetRect(&m_rcWindowBounds,
(DesktopRect.right - m_ChainDesc.BufferDesc.Width) / 2,
(DesktopRect.bottom - m_ChainDesc.BufferDesc.Height) / 2,
(DesktopRect.right + m_ChainDesc.BufferDesc.Width) / 2,
(DesktopRect.bottom + m_ChainDesc.BufferDesc.Height) / 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, m_ChainDesc.BufferDesc.Width, m_ChainDesc.BufferDesc.Height);
};

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);
}

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

struct uniqueRenderingMode
Expand Down
72 changes: 15 additions & 57 deletions src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,39 @@ CHW::~CHW() {}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void CHW::CreateDevice(HWND hWnd, bool move_window)
void CHW::CreateDevice(SDL_Window *hWnd, bool move_window)
{
m_hWnd = hWnd;
m_move_window = move_window;

R_ASSERT(m_hWnd);

PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER, // Flags
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
32, // Color depth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24, // Number of bits for the depthbuffer
8, // Number of bits for the stencilbuffer
0, // Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};

// Get the device context
m_hDC = GetDC(m_hWnd);
if (m_hDC == nullptr)
Uint32 pixelFormat = SDL_GetWindowPixelFormat(m_hWnd);
if (SDL_PIXELFORMAT_UNKNOWN == pixelFormat)
{
Msg("Could not get device context.");
Msg("Could not get pixel format: %s", SDL_GetError());
return;
}

// Choose the closest pixel format
int iPixelFormat = ChoosePixelFormat(m_hDC, &pfd);
if (iPixelFormat == 0)
{
Msg("No pixel format found.");
return;
}
//TODO Choose the closest pixel format

// Apply the pixel format to the device context
if (!SetPixelFormat(m_hDC, iPixelFormat, &pfd))
{
Msg("Could not set pixel format.");
return;
}
//TODO Apply the pixel format to the device context

// Create the context
m_hRC = wglCreateContext(m_hDC);
m_hRC = SDL_GL_CreateContext(m_hWnd);
if (m_hRC == nullptr)
{
Msg("Could not create drawing context.");
Msg("Could not create drawing context: %s", SDL_GetError());
return;
}

// Make the new context the current context for this thread
// NOTE: This assumes the thread calling Create() is the only
// thread that will use the context.
if (!wglMakeCurrent(m_hDC, m_hRC))
if (SDL_GL_MakeCurrent(m_hWnd, m_hRC) != 0)
{
Msg("Could not make context current.");
Msg("Could not make context current. %s", SDL_GetError());
return;
}

Expand Down Expand Up @@ -139,30 +106,21 @@ void CHW::DestroyDevice()
{
if (m_hRC)
{
if (!wglMakeCurrent(nullptr, nullptr))
Msg("Could not release drawing context.");
if (SDL_GL_MakeCurrent(nullptr, nullptr) != 0)
Msg("Could not release drawing context: %s", SDL_GetError());

if (!wglDeleteContext(m_hRC))
Msg("Could not delete context.");
SDL_GL_DeleteContext(m_hRC);

m_hRC = nullptr;
}

if (m_hDC)
{
if (!ReleaseDC(m_hWnd, m_hDC))
Msg("Could not release device context.");

m_hDC = nullptr;
}

free_vid_mode_list();
}

//////////////////////////////////////////////////////////////////////
// Resetting device
//////////////////////////////////////////////////////////////////////
void CHW::Reset(HWND hwnd)
void CHW::Reset(SDL_Window* hwnd)
{
BOOL bWindowed = !psDeviceFlags.is(rsFullscreen);

Expand All @@ -176,7 +134,7 @@ void CHW::Reset(HWND hwnd)
UpdateViews();

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

void CHW::updateWindowProps(SDL_Window* m_sdlWnd)
Expand Down
23 changes: 23 additions & 0 deletions src/utils/xrLC_Light/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
project(xrLC_Light)

list(APPEND DIRS
"."
)

add_dir("${DIRS}")

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_SOURCE_DIR}/../../../sdk/include
)

list(APPEND ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../Shader_xrLC.h")
list(APPEND ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../xrEngine/xrLoadSurface.cpp")
#list(REMOVE_ITEM ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/./LevelCompilerLoggerWindow.cpp")
#list(REMOVE_ITEM ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/./LevelCompilerLoggerWindow.hpp")

add_definitions(-D_USRDLL -DLEVEL_COMPILER -D_USE_MATH_DEFINES -DXRLC_LIGHT_EXPORTS -DFORCE_NO_EXCEPTIONS -DNO_XR_VDECLARATOR)
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
target_link_libraries(${PROJECT_NAME} xrCore xrCDB zlib xrLCUtil)
2 changes: 1 addition & 1 deletion src/xrCDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ list(APPEND DIRS

add_dir("${DIRS}")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include /usr/include/SDL2)

add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})

Expand Down
7 changes: 6 additions & 1 deletion src/xrCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ list(APPEND DIRS

add_dir("${DIRS}")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/pugixml/src ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/pugixml/src
${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include
/usr/include/SDL2
)

add_definitions(-DXRCORE_EXPORTS)
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})
Expand Down
14 changes: 9 additions & 5 deletions src/xrEngine/Device_Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ void CRenderDevice::Initialize()

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

if (strstr(Core.Params, "-gl"))
flags |= SDL_WINDOW_OPENGL;

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

if (!m_sdlWnd)
Log("Unable to create window: %s", SDL_GetError());

m_sdlRndr = SDL_CreateRenderer(m_sdlWnd, -1, SDL_RENDERER_ACCELERATED);
//m_sdlRndr = SDL_CreateRenderer(m_sdlWnd, -1, SDL_RENDERER_ACCELERATED);

SDL_RenderClear(m_sdlRndr);
SDL_RenderPresent(m_sdlRndr);
//SDL_RenderClear(m_sdlRndr);
//SDL_RenderPresent(m_sdlRndr);
}
// Save window properties

Expand Down
Loading

0 comments on commit d341b9b

Please sign in to comment.