[console] Resurrect console scaling

Currently only for gl/glsl/vulkan. However, rather than futzing with
con_width and con_height (and trying to guess good values), con_scale
(currently an integer) gives consistent pixel scaling regardless of
window size.
This commit is contained in:
Bill Currie 2022-11-13 22:23:56 +09:00
parent 0e64f959e2
commit 9f6c367fce
17 changed files with 108 additions and 34 deletions

View file

@ -35,6 +35,7 @@ struct draw_charbuffer_s;
void gl_Draw_Init (void);
void gl_Draw_Shutdown (void);
void gl_Draw_CharBuffer (int x, int y, struct draw_charbuffer_s *buffer);
void gl_Draw_SetScale (int scale);
void gl_Draw_Character (int x, int y, unsigned ch);
void gl_Draw_String (int x, int y, const char *str);
void gl_Draw_nString (int x, int y, const char *str, int count);

View file

@ -35,6 +35,7 @@ struct draw_charbuffer_s;
void glsl_Draw_Init (void);
void glsl_Draw_Shutdown (void);
void glsl_Draw_CharBuffer (int x, int y, struct draw_charbuffer_s *buffer);
void glsl_Draw_SetScale (int scale);
void glsl_Draw_Character (int x, int y, unsigned ch);
void glsl_Draw_String (int x, int y, const char *str);
void glsl_Draw_nString (int x, int y, const char *str, int count);

View file

@ -61,6 +61,9 @@ void Draw_ScrollBuffer (draw_charbuffer_t *buffer, int lines);
void Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer);
int Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str);
void Draw_SetScale (int scale);
int Draw_MaxScale (void) __attribute__((pure));
extern byte *draw_chars;
/** Initialize the draw stuff.

View file

@ -52,7 +52,6 @@ typedef struct console_data_s {
void (*quit) (void);
struct cbuf_s *cbuf;
struct view_s *screen_view;
//struct view_s *view;
struct view_s *status_view;
float lines;
int (*exec_line)(void *data, const char *line);

View file

@ -88,6 +88,7 @@ typedef void (*capfunc_t) (struct tex_s *screencap, void *data);
typedef struct vid_render_funcs_s {
void (*init) (void);
void (*Draw_CharBuffer) (int x, int y, struct draw_charbuffer_s *buffer);
void (*Draw_SetScale) (int scale);
void (*Draw_Character) (int x, int y, unsigned ch);
void (*Draw_String) (int x, int y, const char *str);
void (*Draw_nString) (int x, int y, const char *str, int count);

View file

@ -98,6 +98,7 @@ typedef struct vulkan_ctx_s {
// size of window
int window_width;
int window_height;
int twod_scale;
//FIXME this is for the parser
qfv_output_t output;

View file

@ -165,20 +165,11 @@ static SCR_Func *scr_funcs[] = {
scr_funcs_intermission,
};
static void
cl_vidsize_listener (void *data, const viddef_t *vdef)
{
View_SetLen (cl_screen_view, vdef->width, vdef->height);
View_UpdateHierarchy (cl_screen_view);
}
void
CL_Init_Screen (void)
{
qpic_t *pic;
VID_OnVidResize_AddListener (cl_vidsize_listener, 0);
HUD_Init ();
cl_screen_view = View_New (hud_registry, nullview);

View file

@ -70,6 +70,16 @@ static con_buffer_t *con;
static float con_cursorspeed = 4;
static int con_scale;
static cvar_t con_scale_cvar = {
.name = "con_scale",
.description =
"Pixel scale factor for the console and all 2D user interface "
"elements",
.default_value = "1",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &con_scale },
};
static float con_notifytime;
static cvar_t con_notifytime_cvar = {
.name = "con_notifytime",
@ -807,6 +817,24 @@ exec_line (inputline_t *il)
Con_ExecLine (il->line);
}
static int win_xlen = -1;
static int win_ylen = -1;
static void
con_set_size (void)
{
int xlen = win_xlen / con_scale;
int ylen = win_ylen / con_scale;
if (xlen > 0 && ylen > 0) {
View_SetLen (screen_view, xlen, ylen);
View_UpdateHierarchy (screen_view);
if (con_data.screen_view) {
View_SetLen (*con_data.screen_view, xlen, ylen);
View_UpdateHierarchy (*con_data.screen_view);
}
}
}
// The console view is not a child of the client's screen view, so it won't
// get resized automatically when the screen changes size. However, since the
// console has to process input events anyway, handling ie_app_window is a
@ -814,15 +842,21 @@ exec_line (inputline_t *il)
static void
con_app_window (const IE_event_t *event)
{
static int old_xlen = -1;
static int old_ylen = -1;
if (old_xlen != event->app_window.xlen
|| old_ylen != event->app_window.ylen) {
old_xlen = event->app_window.xlen;
old_ylen = event->app_window.ylen;
if (win_xlen != event->app_window.xlen
|| win_ylen != event->app_window.ylen) {
win_xlen = event->app_window.xlen;
win_ylen = event->app_window.ylen;
con_set_size ();
}
}
View_SetLen (screen_view, old_xlen, old_ylen);
View_UpdateHierarchy (screen_view);
static void
con_scale_f (void *data, const cvar_t *cvar)
{
con_scale = bound (1, con_scale, Draw_MaxScale ());
Draw_SetScale (con_scale);
if (con_initialized) {
con_set_size ();
}
}
@ -1001,6 +1035,7 @@ C_Init (void)
Cvar_Register (&con_notifytime_cvar, 0, 0);
Cvar_Register (&con_scale_cvar, con_scale_f, 0);
Cvar_Register (&con_alpha_cvar, 0, 0);
Cvar_Register (&con_size_cvar, 0, 0);
Cvar_Register (&con_speed_cvar, 0, 0);

View file

@ -115,6 +115,7 @@ static int numcachepics;
static byte menuplyr_pixels[4096];
static int gl_2d_scale = 1;
static void
Draw_InitText (void)
@ -836,7 +837,7 @@ gl_Draw_ConsoleBackground (int lines, byte alpha)
if (gl_constretch) {
ofs = 0;
} else
ofs = (vid.height - lines) / (float) vid.height;
ofs = (vid.height - gl_2d_scale * lines) / (float) vid.height;
color_0_8[3] = alpha;
qfglColor4ubv (color_0_8);
@ -851,9 +852,9 @@ gl_Draw_ConsoleBackground (int lines, byte alpha)
qfglTexCoord2f (0, 0 + ofs);
qfglVertex2f (0, 0);
qfglTexCoord2f (1, 0 + ofs);
qfglVertex2f (vid.width, 0);
qfglVertex2f (vid.width / gl_2d_scale, 0);
qfglTexCoord2f (1, 1);
qfglVertex2f (vid.width, lines);
qfglVertex2f (vid.width / gl_2d_scale, lines);
qfglTexCoord2f (0, 1);
qfglVertex2f (0, lines);
qfglEnd ();
@ -995,7 +996,13 @@ GL_Set2D (void)
void
GL_Set2DScaled (void)
{
set_2d (vid.width, vid.height);
set_2d (vid.width / gl_2d_scale, vid.height / gl_2d_scale);
}
void
gl_Draw_SetScale (int scale)
{
gl_2d_scale = scale;
}
void

View file

@ -112,6 +112,7 @@ static qpic_t *white_pic;
static qpic_t *backtile_pic;
static hashtab_t *pic_cache;
static int glsl_conback_texnum;
static int glsl_2d_scale = 1;
static cvar_t glsl_conback_texnum_cvar = {
.name = "glsl_conback_texnum",
.description =
@ -647,15 +648,16 @@ glsl_Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width,
void
glsl_Draw_ConsoleBackground (int lines, byte alpha)
{
float ofs = (vid.height - lines) / (float) vid.height;
int s = glsl_2d_scale;
float ofs = (vid.height - s * lines) / (float) vid.height;
quat_t color = {1, 1, 1, bound (0, alpha, 255) / 255.0};
drawvert_t verts[] = {
{{ 0, 0, 0, ofs}},
{{vid.width, 0, 1, ofs}},
{{vid.width, lines, 1, 1}},
{{ 0, 0, 0, ofs}},
{{vid.width, lines, 1, 1}},
{{ 0, lines, 0, 1}},
{{ 0, 0, 0, ofs}},
{{vid.width / s, 0, 1, ofs}},
{{vid.width / s, lines, 1, 1}},
{{ 0, 0, 0, ofs}},
{{vid.width / s, lines, 1, 1}},
{{ 0, lines, 0, 1}},
};
GLSL_FlushText (); // Flush text that should be rendered before the console
@ -828,7 +830,13 @@ GLSL_Set2D (void)
void
GLSL_Set2DScaled (void)
{
set_2d (vid.width, vid.height);
set_2d (vid.width / glsl_2d_scale, vid.height / glsl_2d_scale);
}
void
glsl_Draw_SetScale (int scale)
{
glsl_2d_scale = scale;
}
void

View file

@ -141,3 +141,17 @@ Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str)
}
return lines;
}
void
Draw_SetScale (int scale)
{
if (r_funcs->Draw_SetScale) {
r_funcs->Draw_SetScale (scale);
}
}
int
Draw_MaxScale (void)
{
return r_funcs->Draw_SetScale ? 20 : 1;
}

View file

@ -502,6 +502,7 @@ vid_render_funcs_t gl_vid_render_funcs = {
.init = gl_vid_render_init,
.Draw_CharBuffer = gl_Draw_CharBuffer,
.Draw_SetScale = gl_Draw_SetScale,
.Draw_Character = gl_Draw_Character,
.Draw_String = gl_Draw_String,
.Draw_nString = gl_Draw_nString,

View file

@ -446,6 +446,7 @@ vid_render_funcs_t glsl_vid_render_funcs = {
.init = glsl_vid_render_init,
.Draw_CharBuffer = glsl_Draw_CharBuffer,
.Draw_SetScale = glsl_Draw_SetScale,
.Draw_Character = glsl_Draw_Character,
.Draw_String = glsl_Draw_String,
.Draw_nString = glsl_Draw_nString,

View file

@ -145,6 +145,12 @@ vulkan_Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer)
Vulkan_Draw_CharBuffer (x, y, buffer, vulkan_ctx);
}
static void
vulkan_Draw_SetScale (int scale)
{
vulkan_ctx->twod_scale = max (1, scale);
}
static void
vulkan_Draw_Character (int x, int y, unsigned ch)
{
@ -360,11 +366,12 @@ vulkan_set_2d (int scaled)
//FIXME this should not be done every frame
__auto_type mctx = vulkan_ctx->matrix_context;
__auto_type mat = &mctx->matrices;
int scale = vulkan_ctx->twod_scale;
float left = -0.5;
float top = -0.5;
float right = left + vid.width; //FIXME vid
float bottom = top + vid.height;
float right = left + vid.width / scale;
float bottom = top + vid.height / scale;
QFV_Orthographic (mat->Projection2d, left, right, top, bottom, 0, 99999);
mctx->dirty = mctx->frames.size;
@ -780,6 +787,7 @@ vid_render_funcs_t vulkan_vid_render_funcs = {
.init = vulkan_vid_render_init,
.Draw_CharBuffer = vulkan_Draw_CharBuffer,
.Draw_SetScale = vulkan_Draw_SetScale,
.Draw_Character = vulkan_Draw_Character,
.Draw_String = vulkan_Draw_String,
.Draw_nString = vulkan_Draw_nString,

View file

@ -897,10 +897,11 @@ Vulkan_Draw_ConsoleBackground (int lines, byte alpha, vulkan_ctx_t *ctx)
quat_t color = { a, a, a, a};
qpic_t *cpic;
cpic = Vulkan_Draw_CachePic ("gfx/conback.lmp", false, ctx);
float frac = (vid.height - lines) / (float) vid.height;
int s = ctx->twod_scale;
float frac = (vid.height - s * lines) / (float) vid.height;
int ofs = frac * cpic->height;
subpic_t *subpic = *(subpic_t **) cpic->data;
draw_pic (0, 0, vid.width, lines, subpic,
draw_pic (0, 0, vid.width / s, lines, subpic,
0, ofs, cpic->width, cpic->height - ofs, color,
&frame->quad_verts);
}

View file

@ -185,6 +185,7 @@ Win_Vulkan_Context (void)
ctx->create_surface = win_vulkan_create_surface;
ctx->required_extensions = required_extensions;
ctx->va_ctx = va_create_context (4);
ctx->twod_scale = 1;
return ctx;
}

View file

@ -224,6 +224,7 @@ X11_Vulkan_Context (void)
ctx->create_surface = x11_vulkan_create_surface;
ctx->required_extensions = required_extensions;
ctx->va_ctx = va_create_context (32);
ctx->twod_scale = 1;
return ctx;
}