Skip to content

Commit

Permalink
xrEngine: fix full-screen rendering
Browse files Browse the repository at this point in the history
xrRenderGL: rewrite get list video modes on SDL
  • Loading branch information
eagleivg committed Jul 16, 2018
1 parent 715f1c0 commit fcb8a95
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
40 changes: 19 additions & 21 deletions src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,18 @@ void free_vid_mode_list();

CHW HW;

void CALLBACK OnDebugCallback(GLenum /*source*/, GLenum /*type*/, GLuint id, GLenum severity,
GLsizei /*length*/, const GLchar* message, const void* /*userParam*/)
void CALLBACK OnDebugCallback(GLenum /*source*/, GLenum /*type*/, GLuint id, GLenum severity, GLsizei /*length*/,
const GLchar* message, const void* /*userParam*/)
{
if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
Log(message, id);
}

CHW::CHW() :
pDevice(this),
pContext(this),
m_pSwapChain(this),
pBaseRT(0),
pBaseZB(0),
pPP(0),
pFB(0),
m_hWnd(nullptr),
m_hDC(nullptr),
m_hRC(nullptr) {}
CHW::CHW()
: pDevice(this), pContext(this), m_pSwapChain(this), pBaseRT(0), pBaseZB(0), pPP(0), pFB(0), m_hWnd(nullptr),
m_hDC(nullptr), m_hRC(nullptr)
{
}

CHW::~CHW() {}
//////////////////////////////////////////////////////////////////////
Expand All @@ -46,7 +40,7 @@ void CHW::CreateDevice(SDL_Window* hWnd)

R_ASSERT(m_hWnd);

//Choose the closest pixel format
// Choose the closest pixel format
SDL_DisplayMode mode;
SDL_GetWindowDisplayMode(m_hWnd, &mode);
mode.format = SDL_PIXELFORMAT_RGBA8888;
Expand Down Expand Up @@ -82,8 +76,8 @@ void CHW::CreateDevice(SDL_Window* hWnd)
}

#ifdef DEBUG
CHK_GL(glEnable(GL_DEBUG_OUTPUT));
CHK_GL(glDebugMessageCallback((GLDEBUGPROC)OnDebugCallback, nullptr));
CHK_GL(glEnable(GL_DEBUG_OUTPUT));
CHK_GL(glDebugMessageCallback((GLDEBUGPROC)OnDebugCallback, nullptr));
#endif // DEBUG

// Clip control ensures compatibility with D3D device coordinates.
Expand Down Expand Up @@ -151,17 +145,23 @@ void fill_vid_mode_list(CHW* /*_hw*/)

int i = 0;
auto& AVM = AvailableVideoModes;
while (EnumDisplaySettings(nullptr, iModeNum++, &dmi) != 0)

int num_modes = SDL_GetNumDisplayModes(0);
Log("found video modes:", num_modes);

for (i = 0; i < num_modes; i++)
{
SDL_DisplayMode mode;
SDL_GetDisplayMode(0, i, &mode);

string32 str;

xr_sprintf(str, sizeof(str), "%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight);
xr_sprintf(str, sizeof(str), "%dx%d", mode.w, mode.h);

if (AVM.cend() != find_if(AVM.cbegin(), AVM.cend(), uniqueRenderingMode(str)))
continue;

AVM.emplace_back(xr_token(xr_strdup(str), i));
++i;
}
AVM.emplace_back(xr_token(nullptr, -1));

Expand Down Expand Up @@ -191,7 +191,6 @@ void CHW::UpdateViews()
CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH24_STENCIL8, psCurrentVidMode[0], psCurrentVidMode[1]));
}


void CHW::ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[4])
{
if (pRenderTargetView == 0)
Expand Down Expand Up @@ -222,7 +221,6 @@ void CHW::ClearDepthStencilView(GLuint pDepthStencilView, UINT ClearFlags, FLOAT
if (ClearFlags & D3D_CLEAR_STENCIL)
mask |= (u32)GL_STENCIL_BUFFER_BIT;


glPushAttrib(mask);
if (ClearFlags & D3D_CLEAR_DEPTH)
{
Expand Down
31 changes: 24 additions & 7 deletions src/xrEngine/Device_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <SDL.h>
#include <SDL_syswm.h>


extern XRCDB_API BOOL* cdb_bDebug;

void CRenderDevice::_SetupStates()
Expand Down Expand Up @@ -39,11 +38,6 @@ void CRenderDevice::Create()
fASPECT = 1.f;
GEnv.Render->Create(m_sdlWnd, dwWidth, dwHeight, fWidth_2, fHeight_2);
UpdateWindowProps();
SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowClient.x, &m_rcWindowClient.y);
int w = 0, h = 0;
SDL_GetWindowSize(m_sdlWnd, &w, &h);
m_rcWindowClient.w = m_rcWindowClient.x + w;
m_rcWindowClient.h = m_rcWindowClient.y + h;
Memory.mem_compact();
b_is_Ready = TRUE;
_SetupStates();
Expand Down Expand Up @@ -73,7 +67,7 @@ void CRenderDevice::UpdateWindowProps()
else
{
int top = 0, left = 0, right = 0, bottom = 0;
//SDL_GetWindowBordersSize(m_sdlWnd, &top, &left, &bottom, &right);
// SDL_GetWindowBordersSize(m_sdlWnd, &top, &left, &bottom, &right);
#ifdef WINDOWS
// XXX: Currently SDL_GetWindowBordersSize is supported only on X11
// For now we must use method below.
Expand All @@ -84,6 +78,29 @@ void CRenderDevice::UpdateWindowProps()
#endif
SDL_SetWindowPosition(m_sdlWnd, left, top);
}

SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowClient.x, &m_rcWindowClient.y);
int w = 0, h = 0;
SDL_GetWindowSize(m_sdlWnd, &w, &h);
m_rcWindowClient.w = m_rcWindowClient.x + w;
m_rcWindowClient.h = m_rcWindowClient.y + h;
}
else
{
SDL_SetWindowFullscreen(m_sdlWnd, SDL_WINDOW_FULLSCREEN);
SDL_DisplayMode mode;
SDL_GetWindowDisplayMode(m_sdlWnd, &mode);
mode.w = dwWidth;
mode.h = dwHeight;

if(SDL_SetWindowDisplayMode(m_sdlWnd, &mode) != 0)
Log("Cannot setup video mode:", SDL_GetError());
else
{
SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowClient.x, &m_rcWindowClient.y);
m_rcWindowClient.w = mode.w;
m_rcWindowClient.h = mode.h;
}
}

if (!GEnv.isDedicatedServer)
Expand Down
3 changes: 2 additions & 1 deletion src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,11 @@ void CRenderDevice::message_loop()
case SDL_WINDOWEVENT_MOVED:
SDL_Log("Window %d moved to %d,%d", event.window.windowID, event.window.data1, event.window.data2);
break;
case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
SDL_Log(
"Window %d resized to %d,%d", event.window.windowID, event.window.data1, event.window.data2);
OnWM_Activate(1, event.window.data2);
break;
case SDL_WINDOWEVENT_CLOSE: event.type = SDL_QUIT; break;
case SDL_WINDOWEVENT_SHOWN:
Expand Down Expand Up @@ -399,7 +401,6 @@ void CRenderDevice::Run()
seqAppStart.Process();
GEnv.Render->ClearTarget();
splash::hide();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_SYSWMEVENT);
SDL_ShowWindow(m_sdlWnd);
SDL_RaiseWindow(m_sdlWnd);
pInput->ClipCursor(true);
Expand Down

0 comments on commit fcb8a95

Please sign in to comment.