Skip to content

Commit 36c8961

Browse files
temxNovum
authored andcommitted
Add viewport based scaling support
1 parent ef82605 commit 36c8961

8 files changed

Lines changed: 278 additions & 130 deletions

File tree

Quake/draw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ qpic_t *Draw_TryCachePic (const char *path, unsigned int texflags);
4646
void Draw_NewGame (void);
4747

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

5152
#endif /* _QUAKE_DRAW_H */

Quake/gl_draw.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,12 +954,23 @@ GL_Viewport
954954
================
955955
*/
956956
void GL_Viewport (cb_context_t *cbx, float x, float y, float width, float height, float min_depth, float max_depth)
957+
{
958+
GL_Viewport_Scale (cbx, x, y, width, height, min_depth, max_depth, 1);
959+
}
960+
961+
/*
962+
================
963+
GL_Viewport_Scale
964+
================
965+
*/
966+
void GL_Viewport_Scale (cb_context_t *cbx, float x, float y, float width, float height, float min_depth, float max_depth, int scale)
957967
{
958968
VkViewport viewport;
959-
viewport.x = x;
960-
viewport.y = vid.height - (y + height);
961-
viewport.width = width;
962-
viewport.height = height;
969+
// when using scale, always put the viewport flush against the corner (even when viewsize < 100) for simplicity
970+
viewport.x = scale == 1 ? x : 0;
971+
viewport.y = scale == 1 ? vid.height - (y + height) : 0;
972+
viewport.width = (width + scale - 1) / scale;
973+
viewport.height = (height + scale - 1) / scale;
963974
viewport.minDepth = min_depth;
964975
viewport.maxDepth = max_depth;
965976

Quake/gl_rmain.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ int r_framecount; // used for dlight push checking
3131
mplane_t frustum[4];
3232

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

3637
// johnfitz -- rendering statistics
3738
atomic_uint32_t rs_brushpolys, rs_aliaspolys, rs_skypolys, rs_particles, rs_fogpolys;
@@ -109,6 +110,7 @@ float map_fallbackalpha;
109110
qboolean r_drawworld_cheatsafe, r_fullbright_cheatsafe, r_lightmap_cheatsafe; // johnfitz
110111

111112
cvar_t r_scale = {"r_scale", "1", CVAR_ARCHIVE};
113+
cvar_t r_simplescale = {"r_simplescale", "1", CVAR_ARCHIVE};
112114

113115
cvar_t r_gpulightmapupdate = {"r_gpulightmapupdate", "1", CVAR_NONE};
114116
cvar_t r_rtshadows = {"r_rtshadows", "1", CVAR_ARCHIVE};
@@ -352,7 +354,8 @@ R_SetupContext
352354
*/
353355
static void R_SetupContext (cb_context_t *cbx)
354356
{
355-
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);
357+
GL_Viewport_Scale (
358+
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);
356359
R_BindPipeline (cbx, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkan_globals.basic_blend_pipeline[cbx->render_pass_index]);
357360
R_PushConstants (cbx, VK_SHADER_STAGE_ALL_GRAPHICS, 0, 16 * sizeof (float), vulkan_globals.view_projection_matrix);
358361
}
@@ -384,7 +387,6 @@ static void R_SetupViewBeforeMark (void *unused)
384387
r_fovx = r_refdef.fov_x;
385388
r_fovy = r_refdef.fov_y;
386389
render_warp = false;
387-
render_scale = (int)r_scale.value;
388390

389391
if (r_waterwarp.value)
390392
{
@@ -554,14 +556,16 @@ void R_DrawViewModel (cb_context_t *cbx)
554556
R_BeginDebugUtilsLabel (cbx, "View Model");
555557

556558
// hack the depth range to prevent view model from poking into walls
557-
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);
559+
GL_Viewport_Scale (
560+
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);
558561

559562
int aliaspolys = 0;
560563
R_DrawAliasModel (cbx, currententity, &aliaspolys);
561564
Atomic_AddUInt32 (&rs_aliaspolys, aliaspolys);
562565
Atomic_IncrementUInt32 (&rs_aliaspasses);
563566

564-
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);
567+
GL_Viewport_Scale (
568+
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);
565569

566570
R_EndDebugUtilsLabel (cbx);
567571
}

Quake/gl_rmisc.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ void R_CreatePipelineLayouts ()
17021702

17031703
ZEROED_STRUCT (VkPushConstantRange, push_constant_range);
17041704
push_constant_range.offset = 0;
1705-
push_constant_range.size = 3 * sizeof (uint32_t) + 8 * sizeof (float);
1705+
push_constant_range.size = 3 * sizeof (uint32_t) + 10 * sizeof (float);
17061706
push_constant_range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
17071707

17081708
ZEROED_STRUCT (VkPipelineLayoutCreateInfo, pipeline_layout_create_info);
@@ -1972,12 +1972,15 @@ void R_InitSamplers ()
19721972
}
19731973
}
19741974

1975-
if (r_scale.value >= 8)
1976-
lod_bias += 3.0f;
1977-
else if (r_scale.value >= 4)
1978-
lod_bias += 2.0f;
1979-
else if (r_scale.value >= 2)
1980-
lod_bias += 1.0f;
1975+
if (r_simplescale.value == 0)
1976+
{
1977+
if (r_scale.value >= 8)
1978+
lod_bias += 3.0f;
1979+
else if (r_scale.value >= 4)
1980+
lod_bias += 2.0f;
1981+
else if (r_scale.value >= 2)
1982+
lod_bias += 1.0f;
1983+
}
19811984
}
19821985

19831986
lod_bias += gl_lodbias.value;
@@ -3618,9 +3621,11 @@ void R_Init (void)
36183621
Cvar_RegisterVariable (&r_telealpha);
36193622
Cvar_RegisterVariable (&r_slimealpha);
36203623
Cvar_RegisterVariable (&r_scale);
3624+
Cvar_RegisterVariable (&r_simplescale);
36213625
Cvar_RegisterVariable (&r_lodbias);
36223626
Cvar_RegisterVariable (&gl_lodbias);
36233627
Cvar_SetCallback (&r_scale, R_ScaleChanged_f);
3628+
Cvar_SetCallback (&r_simplescale, R_ScaleChanged_f);
36243629
Cvar_SetCallback (&r_lodbias, R_ScaleChanged_f);
36253630
Cvar_SetCallback (&gl_lodbias, R_ScaleChanged_f);
36263631
Cvar_SetCallback (&r_lavaalpha, R_SetLavaalpha_f);

Quake/gl_screen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,9 +1211,6 @@ void SCR_UpdateScreen (qboolean use_tasks)
12111211
}
12121212
}
12131213

1214-
if (vid.recalc_refdef)
1215-
SCR_CalcRefdef ();
1216-
12171214
// decide on the height of the console
12181215
con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;
12191216

@@ -1224,6 +1221,9 @@ void SCR_UpdateScreen (qboolean use_tasks)
12241221
return;
12251222
}
12261223

1224+
if (vid.recalc_refdef)
1225+
SCR_CalcRefdef ();
1226+
12271227
if (use_tasks)
12281228
{
12291229
if (prev_end_rendering_task != INVALID_TASK_HANDLE)

0 commit comments

Comments
 (0)