Skip to content

Commit eaab565

Browse files
eagleivgXottab-DUTY
authored andcommitted
xrEngine: fix full-screen rendering
xrRenderGL: rewrite get list video modes on SDL
1 parent aa6dbbb commit eaab565

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,18 @@ void free_vid_mode_list();
1717

1818
CHW HW;
1919

20-
void CALLBACK OnDebugCallback(GLenum /*source*/, GLenum /*type*/, GLuint id, GLenum severity,
21-
GLsizei /*length*/, const GLchar* message, const void* /*userParam*/)
20+
void CALLBACK OnDebugCallback(GLenum /*source*/, GLenum /*type*/, GLuint id, GLenum severity, GLsizei /*length*/,
21+
const GLchar* message, const void* /*userParam*/)
2222
{
2323
if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
2424
Log(message, id);
2525
}
2626

27-
CHW::CHW() :
28-
pDevice(this),
29-
pContext(this),
30-
m_pSwapChain(this),
31-
pBaseRT(0),
32-
pBaseZB(0),
33-
pPP(0),
34-
pFB(0),
35-
m_hWnd(nullptr),
36-
m_hDC(nullptr),
37-
m_hRC(nullptr) {}
27+
CHW::CHW()
28+
: pDevice(this), pContext(this), m_pSwapChain(this), pBaseRT(0), pBaseZB(0), pPP(0), pFB(0), m_hWnd(nullptr),
29+
m_hDC(nullptr), m_hRC(nullptr)
30+
{
31+
}
3832

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

4741
R_ASSERT(m_hWnd);
4842

49-
//Choose the closest pixel format
43+
// Choose the closest pixel format
5044
SDL_DisplayMode mode;
5145
SDL_GetWindowDisplayMode(m_hWnd, &mode);
5246
mode.format = SDL_PIXELFORMAT_RGBA8888;
@@ -82,8 +76,8 @@ void CHW::CreateDevice(SDL_Window* hWnd)
8276
}
8377

8478
#ifdef DEBUG
85-
CHK_GL(glEnable(GL_DEBUG_OUTPUT));
86-
CHK_GL(glDebugMessageCallback((GLDEBUGPROC)OnDebugCallback, nullptr));
79+
CHK_GL(glEnable(GL_DEBUG_OUTPUT));
80+
CHK_GL(glDebugMessageCallback((GLDEBUGPROC)OnDebugCallback, nullptr));
8781
#endif // DEBUG
8882

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

152146
int i = 0;
153147
auto& AVM = AvailableVideoModes;
154-
while (EnumDisplaySettings(nullptr, iModeNum++, &dmi) != 0)
148+
149+
int num_modes = SDL_GetNumDisplayModes(0);
150+
Log("found video modes:", num_modes);
151+
152+
for (i = 0; i < num_modes; i++)
155153
{
154+
SDL_DisplayMode mode;
155+
SDL_GetDisplayMode(0, i, &mode);
156+
156157
string32 str;
157158

158-
xr_sprintf(str, sizeof(str), "%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight);
159+
xr_sprintf(str, sizeof(str), "%dx%d", mode.w, mode.h);
159160

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

163164
AVM.emplace_back(xr_token(xr_strdup(str), i));
164-
++i;
165165
}
166166
AVM.emplace_back(xr_token(nullptr, -1));
167167

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

194-
195194
void CHW::ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[4])
196195
{
197196
if (pRenderTargetView == 0)
@@ -222,7 +221,6 @@ void CHW::ClearDepthStencilView(GLuint pDepthStencilView, UINT ClearFlags, FLOAT
222221
if (ClearFlags & D3D_CLEAR_STENCIL)
223222
mask |= (u32)GL_STENCIL_BUFFER_BIT;
224223

225-
226224
glPushAttrib(mask);
227225
if (ClearFlags & D3D_CLEAR_DEPTH)
228226
{

src/xrEngine/Device_create.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <SDL.h>
66
#include <SDL_syswm.h>
77

8-
98
extern XRCDB_API BOOL* cdb_bDebug;
109

1110
void CRenderDevice::_SetupStates()
@@ -39,11 +38,6 @@ void CRenderDevice::Create()
3938
fASPECT = 1.f;
4039
GEnv.Render->Create(m_sdlWnd, dwWidth, dwHeight, fWidth_2, fHeight_2);
4140
UpdateWindowProps();
42-
SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowClient.x, &m_rcWindowClient.y);
43-
int w = 0, h = 0;
44-
SDL_GetWindowSize(m_sdlWnd, &w, &h);
45-
m_rcWindowClient.w = m_rcWindowClient.x + w;
46-
m_rcWindowClient.h = m_rcWindowClient.y + h;
4741
Memory.mem_compact();
4842
b_is_Ready = TRUE;
4943
_SetupStates();
@@ -73,7 +67,7 @@ void CRenderDevice::UpdateWindowProps()
7367
else
7468
{
7569
int top = 0, left = 0, right = 0, bottom = 0;
76-
//SDL_GetWindowBordersSize(m_sdlWnd, &top, &left, &bottom, &right);
70+
// SDL_GetWindowBordersSize(m_sdlWnd, &top, &left, &bottom, &right);
7771
#ifdef WINDOWS
7872
// XXX: Currently SDL_GetWindowBordersSize is supported only on X11
7973
// For now we must use method below.
@@ -84,6 +78,29 @@ void CRenderDevice::UpdateWindowProps()
8478
#endif
8579
SDL_SetWindowPosition(m_sdlWnd, left, top);
8680
}
81+
82+
SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowClient.x, &m_rcWindowClient.y);
83+
int w = 0, h = 0;
84+
SDL_GetWindowSize(m_sdlWnd, &w, &h);
85+
m_rcWindowClient.w = m_rcWindowClient.x + w;
86+
m_rcWindowClient.h = m_rcWindowClient.y + h;
87+
}
88+
else
89+
{
90+
SDL_SetWindowFullscreen(m_sdlWnd, SDL_WINDOW_FULLSCREEN);
91+
SDL_DisplayMode mode;
92+
SDL_GetWindowDisplayMode(m_sdlWnd, &mode);
93+
mode.w = dwWidth;
94+
mode.h = dwHeight;
95+
96+
if(SDL_SetWindowDisplayMode(m_sdlWnd, &mode) != 0)
97+
Log("Cannot setup video mode:", SDL_GetError());
98+
else
99+
{
100+
SDL_GetWindowPosition(m_sdlWnd, &m_rcWindowClient.x, &m_rcWindowClient.y);
101+
m_rcWindowClient.w = mode.w;
102+
m_rcWindowClient.h = mode.h;
103+
}
87104
}
88105

89106
if (!GEnv.isDedicatedServer)

src/xrEngine/device.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,11 @@ void CRenderDevice::message_loop()
348348
case SDL_WINDOWEVENT_MOVED:
349349
SDL_Log("Window %d moved to %d,%d", event.window.windowID, event.window.data1, event.window.data2);
350350
break;
351+
case SDL_WINDOWEVENT_RESIZED:
351352
case SDL_WINDOWEVENT_SIZE_CHANGED:
352353
SDL_Log(
353354
"Window %d resized to %d,%d", event.window.windowID, event.window.data1, event.window.data2);
355+
OnWM_Activate(1, event.window.data2);
354356
break;
355357
case SDL_WINDOWEVENT_CLOSE: event.type = SDL_QUIT; break;
356358
case SDL_WINDOWEVENT_SHOWN:
@@ -399,7 +401,6 @@ void CRenderDevice::Run()
399401
seqAppStart.Process();
400402
GEnv.Render->ClearTarget();
401403
splash::hide();
402-
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_SYSWMEVENT);
403404
SDL_ShowWindow(m_sdlWnd);
404405
SDL_RaiseWindow(m_sdlWnd);
405406
pInput->ClipCursor(true);

0 commit comments

Comments
 (0)