Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add desktop-fullscreen option and optionally decouple aspect ratio from window resolution. #204

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion Quake/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,10 @@ void GL_Set2D (void)
glcanvas.type = CANVAS_INVALID;
glcanvas.texture = NULL;
glcanvas.blendmode = GLS_BLEND_ALPHA;
glViewport (glx, gly, glwidth, glheight);
if (GL_NeedsPostprocess ())
glViewport (0, 0, glwidth, glheight);
else
glViewport (glx, gly, glwidth, glheight);
GL_SetCanvas (CANVAS_DEFAULT);
GL_SetCanvasColor (1.f, 1.f, 1.f, 1.f);
}
25 changes: 19 additions & 6 deletions Quake/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ void GL_PostProcess (void)
GL_BindNative (GL_TEXTURE0, GL_TEXTURE_2D, framebufs.composite.color_tex);
GL_BindNative (GL_TEXTURE1, GL_TEXTURE_3D, gl_palette_lut);
GL_BindBufferRange (GL_SHADER_STORAGE_BUFFER, 0, gl_palette_buffer[palidx], 0, 256 * sizeof (GLuint));
if (variant != 2) // some AMD drivers optimize out the uniform in variant #2
GL_Uniform3fFunc (0, vid_gamma.value, q_min(2.0f, q_max(1.0f, vid_contrast.value)), 1.f/r_refdef.scale);
GL_Uniform4fFunc (0, vid_gamma.value, q_min(2.0f, q_max(1.0f, vid_contrast.value)), 1.f/r_refdef.scale, glx);

glDrawArrays (GL_TRIANGLES, 0, 3);

Expand Down Expand Up @@ -850,10 +849,19 @@ void R_SetupGL (void)
{
if (!GL_NeedsSceneEffects ())
{
GL_BindFramebufferFunc (GL_FRAMEBUFFER, GL_NeedsPostprocess () ? framebufs.composite.fbo : 0u);
qboolean needpostprocess = GL_NeedsPostprocess ();
int xoffset = 0;
int yoffset = 0;
if (!needpostprocess)
{
xoffset = glx;
yoffset = gly;
}

GL_BindFramebufferFunc (GL_FRAMEBUFFER, needpostprocess ? framebufs.composite.fbo : 0u);
framesetup.scene_fbo = framebufs.composite.fbo;
framesetup.oit_fbo = framebufs.oit.fbo_composite;
glViewport (glx + r_refdef.vrect.x, gly + glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height);
glViewport (xoffset+r_refdef.vrect.x, yoffset+glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height);
}
else
{
Expand Down Expand Up @@ -1750,8 +1758,13 @@ void R_WarpScaleView (void)
if (!GL_NeedsSceneEffects ())
return;

srcx = glx + r_refdef.vrect.x;
srcy = gly + glheight - r_refdef.vrect.y - r_refdef.vrect.height;
srcx = r_refdef.vrect.x;
srcy = glheight - r_refdef.vrect.y - r_refdef.vrect.height;
if (!GL_NeedsPostprocess ())
{
srcx += glx;
srcy += gly;
}
srcw = r_refdef.vrect.width / r_refdef.scale;
srch = r_refdef.vrect.height / r_refdef.scale;

Expand Down
5 changes: 3 additions & 2 deletions Quake/gl_shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static const char postprocess_fragment_shader[] =
PALETTE_BUFFER
NOISE_FUNCTIONS
"\n"
"layout(location=0) uniform vec3 Params;\n"
"layout(location=0) uniform vec4 Params;\n"
"\n"
"layout(location=0) out vec4 out_fragcolor;\n"
"\n"
Expand All @@ -254,7 +254,8 @@ NOISE_FUNCTIONS
" float gamma = Params.x;\n"
" float contrast = Params.y;\n"
" float scale = Params.z;\n"
" out_fragcolor = texelFetch(GammaTexture, ivec2(gl_FragCoord), 0);\n"
" ivec2 texelpos = ivec2(gl_FragCoord.x-Params.w, gl_FragCoord.y);\n"
" out_fragcolor = texelFetch(GammaTexture, texelpos, 0);\n"
"#if PALETTIZE == 1\n"
" vec2 noiseuv = floor(gl_FragCoord.xy * scale) + 0.5;\n"
" out_fragcolor.rgb = sqrt(out_fragcolor.rgb);\n"
Expand Down
77 changes: 63 additions & 14 deletions Quake/gl_vidsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ cvar_t vid_fsaa = {"vid_fsaa", "0", CVAR_ARCHIVE}; // QuakeSpasm
cvar_t vid_fsaamode = {"vid_fsaamode", "0", CVAR_ARCHIVE};
cvar_t vid_desktopfullscreen = {"vid_desktopfullscreen", "0", CVAR_ARCHIVE}; // QuakeSpasm
cvar_t vid_borderless = {"vid_borderless", "0", CVAR_ARCHIVE}; // QuakeSpasm
cvar_t vid_maxaspect = { "vid_maxaspect", "0", CVAR_ARCHIVE };
//johnfitz
cvar_t vid_saveresize = {"vid_saveresize", "0", CVAR_ARCHIVE};

Expand Down Expand Up @@ -410,6 +411,46 @@ static qboolean VID_ValidMode (int width, int height, int refreshrate, qboolean
return true;
}

/*
================
VID_GetAspectRatioCVarValue

get an aspect ratio from a cvar.
if the cvar string is in the format x:y, such as 16:9, the fractional float aspect ratio is calculated.
otherwise the cvars float value is returned.
================
*/
static float VID_GetAspectRatioCVarValue (cvar_t* cvar)
{
float aspect = cvar->value;
if (cvar->string && *cvar->string)
{
float num, denom;
if (sscanf (cvar->string, "%f:%f", &num, &denom) == 2)
if (num && denom)
aspect = num / denom;
}
return aspect;
}

/*
================
VID_UpdateRes

setup vid.width and vid.height and account for vid_maxaspect.
================
*/
static void VID_UpdateRes ()
{
float maxaspect = VID_GetAspectRatioCVarValue (&vid_maxaspect);

vid.width = VID_GetCurrentWidth ();
vid.height = VID_GetCurrentHeight ();

if (maxaspect > 0)
vid.width = q_min (vid.width, (int)floor (vid.height*maxaspect+0.5f));
}

/*
================
VID_SetMode
Expand Down Expand Up @@ -535,8 +576,7 @@ static qboolean VID_SetMode (int width, int height, int refreshrate, qboolean fu
}
}

vid.width = VID_GetCurrentWidth();
vid.height = VID_GetCurrentHeight();
VID_UpdateRes ();
vid.maxscale = q_max (4, vid.height / 240);
vid.refreshrate = VID_GetCurrentRefreshRate();
vid.conwidth = vid.width & 0xFFFFFFF8;
Expand Down Expand Up @@ -656,6 +696,11 @@ void VID_Changed_f (cvar_t *var)
vid_changed = true;
}

void VID_Resized_f (cvar_t* var)
{
vid.resized = true;
}

void VID_RecalcConsoleSize (void)
{
vid.conwidth = (scr_conwidth.value > 0) ? (int)scr_conwidth.value : (scr_conscale.value > 0) ? (int)(vid.guiwidth/scr_conscale.value) : vid.guiwidth;
Expand All @@ -666,18 +711,9 @@ void VID_RecalcConsoleSize (void)

void VID_RecalcInterfaceSize (void)
{
vid.guipixelaspect = 1.f;
if (scr_pixelaspect.string && *scr_pixelaspect.string)
{
float num, denom;
if (sscanf (scr_pixelaspect.string, "%f:%f", &num, &denom) == 2)
{
if (num && denom)
vid.guipixelaspect = CLAMP (0.5f, num / denom, 2.f);
}
else if (scr_pixelaspect.value)
vid.guipixelaspect = CLAMP (0.5f, scr_pixelaspect.value, 2.f);
}
vid.guipixelaspect = VID_GetAspectRatioCVarValue(&scr_pixelaspect);
vid.guipixelaspect = CLAMP (0.5f, vid.guipixelaspect, 2.f);

vid.guiwidth = vid.width / q_max (vid.guipixelaspect, 1.f);
vid.guiheight = vid.height * q_min (vid.guipixelaspect, 1.f);
if (vid.width && vid.height)
Expand Down Expand Up @@ -1319,6 +1355,7 @@ void GL_BeginRendering (int *x, int *y, int *width, int *height)
{
vid.resized = false;
vid.recalc_refdef = true;
VID_UpdateRes ();
if (vid_saveresize.value)
{
qboolean was_locked = vid_locked;
Expand All @@ -1336,6 +1373,16 @@ void GL_BeginRendering (int *x, int *y, int *width, int *height)
*width = vid.width;
*height = vid.height;

if (vid.width != VID_GetCurrentWidth ())
{
// center within window if vid width is less than window width.
*x = (VID_GetCurrentWidth ()-vid.width)/2;

// if vid width is not equal to window width the window needs to be cleared.
glClearColor (0, 0, 0, 0);
glClear (GL_COLOR_BUFFER_BIT);
}

// reset state/bindings, just in case some other process
// injects code that makes changes without cleaning up
GL_ResetState ();
Expand Down Expand Up @@ -1580,6 +1627,7 @@ void VID_Init (void)
Cvar_RegisterVariable (&vid_fsaamode);
Cvar_RegisterVariable (&vid_desktopfullscreen); //QuakeSpasm
Cvar_RegisterVariable (&vid_borderless); //QuakeSpasm
Cvar_RegisterVariable (&vid_maxaspect);
Cvar_RegisterVariable (&vid_saveresize);
Cvar_SetCallback (&vid_fullscreen, VID_Changed_f);
Cvar_SetCallback (&vid_width, VID_Changed_f);
Expand All @@ -1590,6 +1638,7 @@ void VID_Init (void)
Cvar_SetCallback (&vid_fsaamode, VID_FSAAMode_f);
Cvar_SetCallback (&vid_desktopfullscreen, VID_Changed_f);
Cvar_SetCallback (&vid_borderless, VID_Changed_f);
Cvar_SetCallback (&vid_maxaspect, VID_Resized_f);

Cvar_SetCompletion (&vid_width, VID_Width_Completion_f);
Cvar_SetCompletion (&vid_height, VID_Height_Completion_f);
Expand Down
2 changes: 0 additions & 2 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,6 @@ void IN_SendKeyEvents (void)
}
else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
vid.width = event.window.data1;
vid.height = event.window.data2;
vid.resized = true;
}
break;
Expand Down
Loading