Skip to content

Commit

Permalink
Add viewport based scaling support
Browse files Browse the repository at this point in the history
  • Loading branch information
temx committed Jan 21, 2023
1 parent d90ec36 commit 64199af
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 130 deletions.
1 change: 1 addition & 0 deletions Quake/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ qpic_t *Draw_TryCachePic (const char *path, unsigned int texflags);
void Draw_NewGame (void);

void GL_Viewport (cb_context_t *cbx, float x, float y, float width, float height, float min_depth, float max_depth);
void GL_Viewport_Scale (cb_context_t *cbx, float x, float y, float width, float height, float min_depth, float max_depth, int scale);
void GL_SetCanvas (cb_context_t *cbx, canvastype newcanvas); // johnfitz

#endif /* _QUAKE_DRAW_H */
19 changes: 15 additions & 4 deletions Quake/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,12 +954,23 @@ GL_Viewport
================
*/
void GL_Viewport (cb_context_t *cbx, float x, float y, float width, float height, float min_depth, float max_depth)
{
GL_Viewport_Scale (cbx, x, y, width, height, min_depth, max_depth, 1);
}

/*
================
GL_Viewport_Scale
================
*/
void GL_Viewport_Scale (cb_context_t *cbx, float x, float y, float width, float height, float min_depth, float max_depth, int scale)
{
VkViewport viewport;
viewport.x = x;
viewport.y = vid.height - (y + height);
viewport.width = width;
viewport.height = height;
// when using scale, always put the viewport flush against the corner (even when viewsize < 100) for simplicity
viewport.x = scale == 1 ? x : 0;
viewport.y = scale == 1 ? vid.height - (y + height) : 0;
viewport.width = (width + scale - 1) / scale;
viewport.height = (height + scale - 1) / scale;
viewport.minDepth = min_depth;
viewport.maxDepth = max_depth;

Expand Down
14 changes: 9 additions & 5 deletions Quake/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ int r_framecount; // used for dlight push checking
mplane_t frustum[4];

qboolean render_warp;
int render_scale;
int render_scale = 1; // used ( > 1 ) when r_simplescale = 0, done in screen effects from a full res main view
int simple_scale = 1; // used ( > 1 ) when r_simplescale = 1, done adjusting the viewport size and upsacaling after screen effects

// johnfitz -- rendering statistics
atomic_uint32_t rs_brushpolys, rs_aliaspolys, rs_skypolys, rs_particles, rs_fogpolys;
Expand Down Expand Up @@ -108,6 +109,7 @@ float map_fallbackalpha;
qboolean r_drawworld_cheatsafe, r_fullbright_cheatsafe, r_lightmap_cheatsafe; // johnfitz

cvar_t r_scale = {"r_scale", "1", CVAR_ARCHIVE};
cvar_t r_simplescale = {"r_simplescale", "1", CVAR_ARCHIVE};

cvar_t r_gpulightmapupdate = {"r_gpulightmapupdate", "1", CVAR_NONE};
cvar_t r_rtshadows = {"r_rtshadows", "1", CVAR_ARCHIVE};
Expand Down Expand Up @@ -349,7 +351,8 @@ R_SetupContext
*/
static void R_SetupContext (cb_context_t *cbx)
{
GL_Viewport (cbx, r_refdef.vrect.x, glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height, 0.0f, 1.0f);
GL_Viewport_Scale (
cbx, r_refdef.vrect.x, glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height, 0.0f, 1.0f, simple_scale);
R_BindPipeline (cbx, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkan_globals.basic_blend_pipeline[cbx->render_pass_index]);
R_PushConstants (cbx, VK_SHADER_STAGE_ALL_GRAPHICS, 0, 16 * sizeof (float), vulkan_globals.view_projection_matrix);
}
Expand Down Expand Up @@ -381,7 +384,6 @@ static void R_SetupViewBeforeMark (void *unused)
r_fovx = r_refdef.fov_x;
r_fovy = r_refdef.fov_y;
render_warp = false;
render_scale = (int)r_scale.value;

if (r_waterwarp.value)
{
Expand Down Expand Up @@ -516,14 +518,16 @@ void R_DrawViewModel (cb_context_t *cbx)
R_BeginDebugUtilsLabel (cbx, "View Model");

// hack the depth range to prevent view model from poking into walls
GL_Viewport (cbx, r_refdef.vrect.x, glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height, 0.7f, 1.0f);
GL_Viewport_Scale (
cbx, r_refdef.vrect.x, glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height, 0.7f, 1.0f, simple_scale);

int aliaspolys = 0;
R_DrawAliasModel (cbx, currententity, &aliaspolys);
Atomic_AddUInt32 (&rs_aliaspolys, aliaspolys);
Atomic_IncrementUInt32 (&rs_aliaspasses);

GL_Viewport (cbx, r_refdef.vrect.x, glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height, 0.0f, 1.0f);
GL_Viewport_Scale (
cbx, r_refdef.vrect.x, glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height, 0.0f, 1.0f, simple_scale);

R_EndDebugUtilsLabel (cbx);
}
Expand Down
19 changes: 12 additions & 7 deletions Quake/gl_rmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ void R_CreatePipelineLayouts ()

ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
push_constant_range.offset = 0;
push_constant_range.size = 3 * sizeof (uint32_t) + 8 * sizeof (float);
push_constant_range.size = 3 * sizeof (uint32_t) + 10 * sizeof (float);
push_constant_range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;

ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
Expand Down Expand Up @@ -1896,12 +1896,15 @@ void R_InitSamplers ()
}
}

if (r_scale.value >= 8)
lod_bias += 3.0f;
else if (r_scale.value >= 4)
lod_bias += 2.0f;
else if (r_scale.value >= 2)
lod_bias += 1.0f;
if (r_simplescale.value == 0)
{
if (r_scale.value >= 8)
lod_bias += 3.0f;
else if (r_scale.value >= 4)
lod_bias += 2.0f;
else if (r_scale.value >= 2)
lod_bias += 1.0f;
}
}

lod_bias += gl_lodbias.value;
Expand Down Expand Up @@ -3409,9 +3412,11 @@ void R_Init (void)
Cvar_RegisterVariable (&r_telealpha);
Cvar_RegisterVariable (&r_slimealpha);
Cvar_RegisterVariable (&r_scale);
Cvar_RegisterVariable (&r_simplescale);
Cvar_RegisterVariable (&r_lodbias);
Cvar_RegisterVariable (&gl_lodbias);
Cvar_SetCallback (&r_scale, R_ScaleChanged_f);
Cvar_SetCallback (&r_simplescale, R_ScaleChanged_f);
Cvar_SetCallback (&r_lodbias, R_ScaleChanged_f);
Cvar_SetCallback (&gl_lodbias, R_ScaleChanged_f);
Cvar_SetCallback (&r_lavaalpha, R_SetLavaalpha_f);
Expand Down
6 changes: 3 additions & 3 deletions Quake/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,9 +1211,6 @@ void SCR_UpdateScreen (qboolean use_tasks)
}
}

if (vid.recalc_refdef)
SCR_CalcRefdef ();

// decide on the height of the console
con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;

Expand All @@ -1224,6 +1221,9 @@ void SCR_UpdateScreen (qboolean use_tasks)
return;
}

if (vid.recalc_refdef)
SCR_CalcRefdef ();

if (use_tasks)
{
if (prev_end_rendering_task != INVALID_TASK_HANDLE)
Expand Down
Loading

0 comments on commit 64199af

Please sign in to comment.