From 7d0fc25d3a84155daa554bd3d62ae93effd389f2 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 1 May 2017 00:00:38 -0600 Subject: [PATCH] wip 1 --- quakespasm/Quake/gl_rmain.c | 2 +- quakespasm/Quake/gl_vidsdl.c | 39 ++++++++++++++++++++++++++++++++++-- quakespasm/Quake/vid.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/quakespasm/Quake/gl_rmain.c b/quakespasm/Quake/gl_rmain.c index 78d6828a..8c97b3e9 100644 --- a/quakespasm/Quake/gl_rmain.c +++ b/quakespasm/Quake/gl_rmain.c @@ -237,7 +237,7 @@ void GLSLGamma_GammaCorrect (void) glDisable (GL_ALPHA_TEST); glDisable (GL_DEPTH_TEST); - glViewport (glx, gly, glwidth, glheight); + glViewport (0, 0, vid.unscaled_width, vid.unscaled_height); smax = glwidth/(float)r_gamma_texture_width; tmax = glheight/(float)r_gamma_texture_height; diff --git a/quakespasm/Quake/gl_vidsdl.c b/quakespasm/Quake/gl_vidsdl.c index 00a62a94..802aca8a 100644 --- a/quakespasm/Quake/gl_vidsdl.c +++ b/quakespasm/Quake/gl_vidsdl.c @@ -154,6 +154,7 @@ static cvar_t vid_borderless = {"vid_borderless", "0", CVAR_ARCHIVE}; // QuakeSp cvar_t vid_gamma = {"gamma", "1", CVAR_ARCHIVE}; //johnfitz -- moved here from view.c cvar_t vid_contrast = {"contrast", "1", CVAR_ARCHIVE}; //QuakeSpasm, MarkV +cvar_t vid_scaled = {"vid_scaled", "0", CVAR_ARCHIVE}; // QuakeSpasm, MarkV //========================================================================== // @@ -350,6 +351,37 @@ static int VID_GetCurrentHeight (void) #endif } +/* +======================= +VID_CalcRenderSize + +returns the size that we will render to, possilby smaller than the actual +framebuffer size if the vid_scaled cvar is in use. +======================= +*/ +static void VID_GetRenderSize (int *w, int *h) +{ + float scale_factor; + +#if defined(USE_SDL2) + SDL_GetWindowSize(draw_context, w, h); +#else + *w = draw_context->w; + *h = draw_context->h; +#endif + + if (vid_scaled.value == 1) { + scale_factor = 1/2.0f; + } else if (vid_scaled.value == 2) { + scale_factor = 1/3.0f; + } else { + scale_factor = 1.0f; + } + + *w *= scale_factor; + *h *= scale_factor; +} + /* ==================== VID_GetCurrentBPP @@ -667,8 +699,9 @@ static qboolean VID_SetMode (int width, int height, int bpp, qboolean fullscreen SDL_WM_SetCaption(caption, caption); #endif /* !defined(USE_SDL2) */ - vid.width = VID_GetCurrentWidth(); - vid.height = VID_GetCurrentHeight(); + VID_GetRenderSize(&vid.width, &vid.height); + vid.unscaled_width = VID_GetCurrentWidth(); + vid.unscaled_height = VID_GetCurrentHeight(); vid.conwidth = vid.width & 0xFFFFFFF8; vid.conheight = vid.conwidth * vid.height / vid.width; vid.numpages = 2; @@ -1520,6 +1553,7 @@ void VID_Init (void) Cvar_RegisterVariable (&vid_fsaa); //QuakeSpasm Cvar_RegisterVariable (&vid_desktopfullscreen); //QuakeSpasm Cvar_RegisterVariable (&vid_borderless); //QuakeSpasm + Cvar_RegisterVariable (&vid_scaled); //QuakeSpasm Cvar_SetCallback (&vid_fullscreen, VID_Changed_f); Cvar_SetCallback (&vid_width, VID_Changed_f); Cvar_SetCallback (&vid_height, VID_Changed_f); @@ -1528,6 +1562,7 @@ void VID_Init (void) Cvar_SetCallback (&vid_fsaa, VID_FSAA_f); Cvar_SetCallback (&vid_desktopfullscreen, VID_Changed_f); Cvar_SetCallback (&vid_borderless, VID_Changed_f); + Cvar_SetCallback (&vid_scaled, VID_Changed_f); Cmd_AddCommand ("vid_unlock", VID_Unlock); //johnfitz Cmd_AddCommand ("vid_restart", VID_Restart); //johnfitz diff --git a/quakespasm/Quake/vid.h b/quakespasm/Quake/vid.h index 0fef5356..821bb82e 100644 --- a/quakespasm/Quake/vid.h +++ b/quakespasm/Quake/vid.h @@ -54,6 +54,8 @@ typedef struct int rowbytes; // may be > width if displayed in a window int width; int height; + int unscaled_width; + int unscaled_height; float aspect; // width / height -- < 0 is taller than wide int numpages; int recalc_refdef; // if true, recalc vid-based stuff