Support vsync in classic mode (SDL 2.x only), and properly handle failure to enable "adaptive" vsync on systems that don't support it.

git-svn-id: https://svn.eduke32.com/eduke32@5938 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2016-11-15 21:55:30 +00:00
parent cd8775dd28
commit be6069fc6d
7 changed files with 64 additions and 44 deletions

View file

@ -86,9 +86,8 @@ struct glinfo_t {
};
extern struct glinfo_t glinfo;
extern void setvsync(int32_t sync);
#endif
extern int setvsync(int newSync);
extern char inputdevices;
// keys

View file

@ -257,6 +257,8 @@ void makeasmwriteable(void)
#endif
}
int32_t vsync=0;
#ifdef USE_OPENGL
extern int32_t nofog;

View file

@ -32,7 +32,6 @@ extern char textfont[2048], smalltextfont[2048];
int32_t rendmode=0;
int32_t usemodels=1;
int32_t usehightile=1;
int32_t vsync=0;
#include <math.h> //<-important!
#include <float.h>
@ -5955,7 +5954,7 @@ static int32_t osdcmd_cvar_set_polymost(const osdfuncparm_t *parm)
if (r == OSDCMD_OK)
{
if (!Bstrcasecmp(parm->name, "r_swapinterval"))
setvsync(vsync);
vsync = setvsync(vsync);
else if (!Bstrcasecmp(parm->name, "r_downsize"))
{
if (r_downsizevar == -1)

View file

@ -103,8 +103,8 @@ static uint16_t sysgamma[3][256];
#ifdef USE_OPENGL
// OpenGL stuff
char nogl=0;
static int32_t vsync_render=0;
#endif
static int sdl_vsync=0;
int32_t maxrefreshfreq=0;
// last gamma, contrast, brightness
@ -499,18 +499,48 @@ int32_t main(int32_t argc, char *argv[])
return r;
}
#ifdef USE_OPENGL
void setvsync(int32_t sync);
#if SDL_MAJOR_VERSION != 1
void setvsync(int32_t sync)
{
if (vsync_render == sync) return;
vsync_render = sync;
int setvsync(int newSync);
#if SDL_MAJOR_VERSION != 1
int setvsync(int newSync)
{
if (sdl_vsync == newSync)
return newSync;
#ifdef USE_OPENGL
if (sdl_context)
SDL_GL_SetSwapInterval(vsync_render);
}
{
int result = SDL_GL_SetSwapInterval(newSync);
if (result == -1)
{
if (newSync == -1)
{
newSync = 1;
result = SDL_GL_SetSwapInterval(newSync);
}
if (result == -1)
{
newSync = 0;
OSD_Printf("Unable to enable VSync!\n");
}
}
sdl_vsync = newSync;
}
else
#endif
{
sdl_vsync = newSync;
resetvideomode();
if (setgamemode(fullscreen, xdim, ydim, bpp))
OSD_Printf("restartvid: Reset failed...\n");
}
return sdl_vsync;
}
#endif
int32_t sdlayer_checkversion(void);
@ -625,9 +655,7 @@ void uninitsystem(void)
//
void system_getcvars(void)
{
#ifdef USE_OPENGL
setvsync(vsync);
#endif
vsync = setvsync(vsync);
}
//
@ -1523,7 +1551,9 @@ static void sdl_trycreaterenderer_fail(char const * const failurepoint)
static void sdl_trycreaterenderer(int32_t const x, int32_t const y)
{
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0);
int const flags = SDL_RENDERER_ACCELERATED | (sdl_vsync ? SDL_RENDERER_PRESENTVSYNC : 0);
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, flags);
if (!sdl_renderer)
{
sdl_trycreaterenderer_fail("SDL_CreateRenderer");
@ -1628,7 +1658,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
return -1;
}
SDL_GL_SetSwapInterval(vsync_render);
SDL_GL_SetSwapInterval(sdl_vsync);
setrefreshrate();

View file

@ -56,14 +56,18 @@ HWND win_gethwnd(void)
#endif
#ifdef USE_OPENGL
void setvsync(int32_t sync)
int setvsync(int newSync)
{
if (vsync_render == sync) return;
vsync_render = sync;
if (sdl_vsync == newSync)
return newSync;
sdl_vsync = newSync;
resetvideomode();
if (setgamemode(fullscreen, xdim, ydim, bpp))
OSD_Printf("restartvid: Reset failed...\n");
return sdl_vsync;
}
#endif
@ -390,7 +394,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
{ SDL_GL_MULTISAMPLESAMPLES, glmultisample },
{ SDL_GL_STENCIL_SIZE, 1 },
{ SDL_GL_ACCELERATED_VISUAL, 1 },
{ SDL_GL_SWAP_CONTROL, vsync_render },
{ SDL_GL_SWAP_CONTROL, sdl_vsync },
};
do
@ -400,7 +404,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
/* HACK: changing SDL GL attribs only works before surface creation,
so we have to create a new surface in a different format first
to force the surface we WANT to be recreated instead of reused. */
if (vsync_render != ovsync)
if (sdl_vsync != ovsync)
{
if (sdl_surface)
{
@ -409,7 +413,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
SDL_SetVideoMode(1, 1, 8, SDL_NOFRAME | SURFACE_FLAGS | ((fs & 1) ? SDL_FULLSCREEN : 0));
SDL_FreeSurface(sdl_surface);
}
ovsync = vsync_render;
ovsync = sdl_vsync;
}
sdl_surface = SDL_SetVideoMode(x, y, c, SDL_OPENGL | ((fs & 1) ? SDL_FULLSCREEN : 0));
if (!sdl_surface)

View file

@ -1743,16 +1743,16 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
#define CHECK(w,h) if ((w < maxx) && (h < maxy))
#ifdef USE_OPENGL
void setvsync(int32_t sync)
int setvsync(int newSync)
{
if (!glinfo.vsync)
{
vsync_render = 0;
return;
}
vsync_render = sync;
vsync_render = newSync;
# ifdef USE_GLEXT
bwglSwapIntervalEXT(sync);
bwglSwapIntervalEXT(newSync);
# endif
}

View file

@ -1726,9 +1726,7 @@ static void Menu_Pre(MenuID_t cm)
MenuEntry_DisableOnCondition(&ME_VIDEOSETUP_APPLY,
(xdim == resolution[nr].xdim && ydim == resolution[nr].ydim &&
getrendermode() == newrendermode && fullscreen == newfullscreen
#ifdef USE_OPENGL
&& vsync == newvsync
#endif
)
|| (newfullscreen ? !(resolution[nr].flags & RES_FS) : !(resolution[nr].flags & RES_WIN))
|| (newrendermode != REND_CLASSIC && resolution[nr].bppmax <= 8));
@ -2685,16 +2683,12 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
{
resolution_t p ={ xdim, ydim, fullscreen, bpp, 0 };
int32_t prend = getrendermode();
#ifdef USE_OPENGL
int32_t pvsync = vsync;
#endif
resolution_t n = { resolution[newresolution].xdim, resolution[newresolution].ydim, newfullscreen,
(newrendermode == REND_CLASSIC) ? 8 : resolution[newresolution].bppmax, 0 };
int32_t nrend = newrendermode;
#ifdef USE_OPENGL
int32_t nvsync = newvsync;
#endif
if (setgamemode(n.flags, n.xdim, n.ydim, n.bppmax) < 0)
{
@ -2706,10 +2700,7 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
else
{
onvideomodechange(p.bppmax > 8);
#ifdef USE_OPENGL
setvsync(pvsync);
vsync = pvsync;
#endif
vsync = setvsync(pvsync);
}
}
else onvideomodechange(n.bppmax > 8);
@ -2717,10 +2708,7 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
g_restorePalette = -1;
G_UpdateScreenArea();
setrendermode(nrend);
#ifdef USE_OPENGL
setvsync(nvsync);
vsync = nvsync;
#endif
vsync = setvsync(nvsync);
ud.config.ScreenMode = fullscreen;
ud.config.ScreenWidth = xdim;
ud.config.ScreenHeight = ydim;
@ -3553,9 +3541,7 @@ int Menu_Change(MenuID_t cm)
}
newrendermode = getrendermode();
newfullscreen = fullscreen;
#ifdef USE_OPENGL
newvsync = vsync;
#endif
break;
case MENU_ADVSOUND: