smol i_video cleanup
This commit is contained in:
1 parent
cfebe422d3
commit
54d897fc33
1 file changed
+74
-46
+74
-46
@@ -225,7 +225,7 @@ void RefreshOGLSDLSurface(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
|
||||
static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen, SDL_bool reposition)
|
||||
{
|
||||
static SDL_bool wasfullscreen = SDL_FALSE;
|
||||
Uint32 rmask;
|
||||
@@ -254,16 +254,18 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
|
||||
}
|
||||
// Reposition window only in windowed mode
|
||||
SDL_SetWindowSize(window, width, height);
|
||||
SDL_SetWindowPosition(window,
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)),
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window))
|
||||
);
|
||||
if (reposition)
|
||||
{
|
||||
SDL_SetWindowPosition(window,
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)),
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Impl_CreateWindow(fullscreen);
|
||||
Impl_SetWindowIcon();
|
||||
wasfullscreen = fullscreen;
|
||||
SDL_SetWindowSize(window, width, height);
|
||||
if (fullscreen)
|
||||
@@ -1942,7 +1944,7 @@ INT32 VID_SetMode(INT32 modeNum)
|
||||
I_DownSample();
|
||||
#endif
|
||||
|
||||
SDLSetMode(vid.width, vid.height, USE_FULLSCREEN);
|
||||
SDLSetMode(vid.width, vid.height, USE_FULLSCREEN, (setmodeneeded ? SDL_TRUE : SDL_FALSE));
|
||||
Impl_VideoSetupBuffer();
|
||||
|
||||
if (rendermode == render_soft)
|
||||
@@ -1962,6 +1964,63 @@ INT32 VID_SetMode(INT32 modeNum)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static SDL_bool Impl_CreateContext(void)
|
||||
{
|
||||
// Renderer-specific stuff
|
||||
#ifdef HWRENDER
|
||||
if ((rendermode == render_opengl)
|
||||
&& (vid.glstate != VID_GL_LIBRARY_ERROR))
|
||||
{
|
||||
if (!sdlglcontext)
|
||||
sdlglcontext = SDL_GL_CreateContext(window);
|
||||
if (sdlglcontext == NULL)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
I_Error("Failed to create a GL context: %s\n", SDL_GetError());
|
||||
}
|
||||
SDL_GL_MakeCurrent(window, sdlglcontext);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (rendermode == render_soft)
|
||||
{
|
||||
int flags = 0; // Use this to set SDL_RENDERER_* flags now
|
||||
if (usesdl2soft)
|
||||
flags |= SDL_RENDERER_SOFTWARE;
|
||||
else if (cv_vidwait.value)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 18)
|
||||
// If SDL is new enough, we can turn off vsync later.
|
||||
flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
#else
|
||||
// However, if it isn't, we should just silently turn vid_wait off
|
||||
// This is because the renderer will be created before the config
|
||||
// is read and vid_wait is set from the user's preferences, and thus
|
||||
// vid_wait will have no effect.
|
||||
CV_StealthSetValue(&cv_vidwait, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11");
|
||||
#else
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||
#endif
|
||||
|
||||
if (!renderer)
|
||||
renderer = SDL_CreateRenderer(window, -1, flags);
|
||||
if (renderer == NULL)
|
||||
{
|
||||
CONS_Printf(M_GetText("Couldn't create rendering context: %s\n"), SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT);
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
|
||||
{
|
||||
int flags = 0;
|
||||
@@ -2009,45 +2068,7 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
// Renderer-specific stuff
|
||||
#ifdef HWRENDER
|
||||
if ((rendermode == render_opengl)
|
||||
&& (vid.glstate != VID_GL_LIBRARY_ERROR))
|
||||
{
|
||||
sdlglcontext = SDL_GL_CreateContext(window);
|
||||
if (sdlglcontext == NULL)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
I_Error("Failed to create a GL context: %s\n", SDL_GetError());
|
||||
}
|
||||
SDL_GL_MakeCurrent(window, sdlglcontext);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (rendermode == render_soft)
|
||||
{
|
||||
flags = 0; // Use this to set SDL_RENDERER_* flags now
|
||||
if (usesdl2soft)
|
||||
flags |= SDL_RENDERER_SOFTWARE;
|
||||
else if (cv_vidwait.value)
|
||||
flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11");
|
||||
#else
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||
#endif
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, flags);
|
||||
if (renderer == NULL)
|
||||
{
|
||||
CONS_Printf(M_GetText("Couldn't create rendering context: %s\n"), SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT);
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
return Impl_CreateContext();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2459,6 +2480,13 @@ static void Impl_SetVsync(void)
|
||||
#if SDL_VERSION_ATLEAST(2,0,18)
|
||||
if (renderer)
|
||||
SDL_RenderSetVSync(renderer, cv_vidwait.value);
|
||||
#endif
|
||||
}
|
||||
#ifdef HWRENDER
|
||||
else if (rendermode == render_opengl && sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext)
|
||||
{
|
||||
SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user