mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-14 08:50:58 +00:00
[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:
parent
0e64f959e2
commit
9f6c367fce
17 changed files with 108 additions and 34 deletions
|
@ -35,6 +35,7 @@ struct draw_charbuffer_s;
|
||||||
void gl_Draw_Init (void);
|
void gl_Draw_Init (void);
|
||||||
void gl_Draw_Shutdown (void);
|
void gl_Draw_Shutdown (void);
|
||||||
void gl_Draw_CharBuffer (int x, int y, struct draw_charbuffer_s *buffer);
|
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_Character (int x, int y, unsigned ch);
|
||||||
void gl_Draw_String (int x, int y, const char *str);
|
void gl_Draw_String (int x, int y, const char *str);
|
||||||
void gl_Draw_nString (int x, int y, const char *str, int count);
|
void gl_Draw_nString (int x, int y, const char *str, int count);
|
||||||
|
|
|
@ -35,6 +35,7 @@ struct draw_charbuffer_s;
|
||||||
void glsl_Draw_Init (void);
|
void glsl_Draw_Init (void);
|
||||||
void glsl_Draw_Shutdown (void);
|
void glsl_Draw_Shutdown (void);
|
||||||
void glsl_Draw_CharBuffer (int x, int y, struct draw_charbuffer_s *buffer);
|
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_Character (int x, int y, unsigned ch);
|
||||||
void glsl_Draw_String (int x, int y, const char *str);
|
void glsl_Draw_String (int x, int y, const char *str);
|
||||||
void glsl_Draw_nString (int x, int y, const char *str, int count);
|
void glsl_Draw_nString (int x, int y, const char *str, int count);
|
||||||
|
|
|
@ -61,6 +61,9 @@ void Draw_ScrollBuffer (draw_charbuffer_t *buffer, int lines);
|
||||||
void Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer);
|
void Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer);
|
||||||
int Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str);
|
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;
|
extern byte *draw_chars;
|
||||||
|
|
||||||
/** Initialize the draw stuff.
|
/** Initialize the draw stuff.
|
||||||
|
|
|
@ -52,7 +52,6 @@ typedef struct console_data_s {
|
||||||
void (*quit) (void);
|
void (*quit) (void);
|
||||||
struct cbuf_s *cbuf;
|
struct cbuf_s *cbuf;
|
||||||
struct view_s *screen_view;
|
struct view_s *screen_view;
|
||||||
//struct view_s *view;
|
|
||||||
struct view_s *status_view;
|
struct view_s *status_view;
|
||||||
float lines;
|
float lines;
|
||||||
int (*exec_line)(void *data, const char *line);
|
int (*exec_line)(void *data, const char *line);
|
||||||
|
|
|
@ -88,6 +88,7 @@ typedef void (*capfunc_t) (struct tex_s *screencap, void *data);
|
||||||
typedef struct vid_render_funcs_s {
|
typedef struct vid_render_funcs_s {
|
||||||
void (*init) (void);
|
void (*init) (void);
|
||||||
void (*Draw_CharBuffer) (int x, int y, struct draw_charbuffer_s *buffer);
|
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_Character) (int x, int y, unsigned ch);
|
||||||
void (*Draw_String) (int x, int y, const char *str);
|
void (*Draw_String) (int x, int y, const char *str);
|
||||||
void (*Draw_nString) (int x, int y, const char *str, int count);
|
void (*Draw_nString) (int x, int y, const char *str, int count);
|
||||||
|
|
|
@ -98,6 +98,7 @@ typedef struct vulkan_ctx_s {
|
||||||
// size of window
|
// size of window
|
||||||
int window_width;
|
int window_width;
|
||||||
int window_height;
|
int window_height;
|
||||||
|
int twod_scale;
|
||||||
|
|
||||||
//FIXME this is for the parser
|
//FIXME this is for the parser
|
||||||
qfv_output_t output;
|
qfv_output_t output;
|
||||||
|
|
|
@ -165,20 +165,11 @@ static SCR_Func *scr_funcs[] = {
|
||||||
scr_funcs_intermission,
|
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
|
void
|
||||||
CL_Init_Screen (void)
|
CL_Init_Screen (void)
|
||||||
{
|
{
|
||||||
qpic_t *pic;
|
qpic_t *pic;
|
||||||
|
|
||||||
VID_OnVidResize_AddListener (cl_vidsize_listener, 0);
|
|
||||||
|
|
||||||
HUD_Init ();
|
HUD_Init ();
|
||||||
|
|
||||||
cl_screen_view = View_New (hud_registry, nullview);
|
cl_screen_view = View_New (hud_registry, nullview);
|
||||||
|
|
|
@ -70,6 +70,16 @@ static con_buffer_t *con;
|
||||||
|
|
||||||
static float con_cursorspeed = 4;
|
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 float con_notifytime;
|
||||||
static cvar_t con_notifytime_cvar = {
|
static cvar_t con_notifytime_cvar = {
|
||||||
.name = "con_notifytime",
|
.name = "con_notifytime",
|
||||||
|
@ -807,6 +817,24 @@ exec_line (inputline_t *il)
|
||||||
Con_ExecLine (il->line);
|
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
|
// 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
|
// get resized automatically when the screen changes size. However, since the
|
||||||
// console has to process input events anyway, handling ie_app_window is a
|
// console has to process input events anyway, handling ie_app_window is a
|
||||||
|
@ -814,15 +842,21 @@ exec_line (inputline_t *il)
|
||||||
static void
|
static void
|
||||||
con_app_window (const IE_event_t *event)
|
con_app_window (const IE_event_t *event)
|
||||||
{
|
{
|
||||||
static int old_xlen = -1;
|
if (win_xlen != event->app_window.xlen
|
||||||
static int old_ylen = -1;
|
|| win_ylen != event->app_window.ylen) {
|
||||||
if (old_xlen != event->app_window.xlen
|
win_xlen = event->app_window.xlen;
|
||||||
|| old_ylen != event->app_window.ylen) {
|
win_ylen = event->app_window.ylen;
|
||||||
old_xlen = event->app_window.xlen;
|
con_set_size ();
|
||||||
old_ylen = event->app_window.ylen;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
View_SetLen (screen_view, old_xlen, old_ylen);
|
static void
|
||||||
View_UpdateHierarchy (screen_view);
|
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_notifytime_cvar, 0, 0);
|
||||||
|
|
||||||
|
Cvar_Register (&con_scale_cvar, con_scale_f, 0);
|
||||||
Cvar_Register (&con_alpha_cvar, 0, 0);
|
Cvar_Register (&con_alpha_cvar, 0, 0);
|
||||||
Cvar_Register (&con_size_cvar, 0, 0);
|
Cvar_Register (&con_size_cvar, 0, 0);
|
||||||
Cvar_Register (&con_speed_cvar, 0, 0);
|
Cvar_Register (&con_speed_cvar, 0, 0);
|
||||||
|
|
|
@ -115,6 +115,7 @@ static int numcachepics;
|
||||||
|
|
||||||
static byte menuplyr_pixels[4096];
|
static byte menuplyr_pixels[4096];
|
||||||
|
|
||||||
|
static int gl_2d_scale = 1;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Draw_InitText (void)
|
Draw_InitText (void)
|
||||||
|
@ -836,7 +837,7 @@ gl_Draw_ConsoleBackground (int lines, byte alpha)
|
||||||
if (gl_constretch) {
|
if (gl_constretch) {
|
||||||
ofs = 0;
|
ofs = 0;
|
||||||
} else
|
} else
|
||||||
ofs = (vid.height - lines) / (float) vid.height;
|
ofs = (vid.height - gl_2d_scale * lines) / (float) vid.height;
|
||||||
|
|
||||||
color_0_8[3] = alpha;
|
color_0_8[3] = alpha;
|
||||||
qfglColor4ubv (color_0_8);
|
qfglColor4ubv (color_0_8);
|
||||||
|
@ -851,9 +852,9 @@ gl_Draw_ConsoleBackground (int lines, byte alpha)
|
||||||
qfglTexCoord2f (0, 0 + ofs);
|
qfglTexCoord2f (0, 0 + ofs);
|
||||||
qfglVertex2f (0, 0);
|
qfglVertex2f (0, 0);
|
||||||
qfglTexCoord2f (1, 0 + ofs);
|
qfglTexCoord2f (1, 0 + ofs);
|
||||||
qfglVertex2f (vid.width, 0);
|
qfglVertex2f (vid.width / gl_2d_scale, 0);
|
||||||
qfglTexCoord2f (1, 1);
|
qfglTexCoord2f (1, 1);
|
||||||
qfglVertex2f (vid.width, lines);
|
qfglVertex2f (vid.width / gl_2d_scale, lines);
|
||||||
qfglTexCoord2f (0, 1);
|
qfglTexCoord2f (0, 1);
|
||||||
qfglVertex2f (0, lines);
|
qfglVertex2f (0, lines);
|
||||||
qfglEnd ();
|
qfglEnd ();
|
||||||
|
@ -995,7 +996,13 @@ GL_Set2D (void)
|
||||||
void
|
void
|
||||||
GL_Set2DScaled (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
|
void
|
||||||
|
|
|
@ -112,6 +112,7 @@ static qpic_t *white_pic;
|
||||||
static qpic_t *backtile_pic;
|
static qpic_t *backtile_pic;
|
||||||
static hashtab_t *pic_cache;
|
static hashtab_t *pic_cache;
|
||||||
static int glsl_conback_texnum;
|
static int glsl_conback_texnum;
|
||||||
|
static int glsl_2d_scale = 1;
|
||||||
static cvar_t glsl_conback_texnum_cvar = {
|
static cvar_t glsl_conback_texnum_cvar = {
|
||||||
.name = "glsl_conback_texnum",
|
.name = "glsl_conback_texnum",
|
||||||
.description =
|
.description =
|
||||||
|
@ -647,15 +648,16 @@ glsl_Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width,
|
||||||
void
|
void
|
||||||
glsl_Draw_ConsoleBackground (int lines, byte alpha)
|
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};
|
quat_t color = {1, 1, 1, bound (0, alpha, 255) / 255.0};
|
||||||
drawvert_t verts[] = {
|
drawvert_t verts[] = {
|
||||||
{{ 0, 0, 0, ofs}},
|
{{ 0, 0, 0, ofs}},
|
||||||
{{vid.width, 0, 1, ofs}},
|
{{vid.width / s, 0, 1, ofs}},
|
||||||
{{vid.width, lines, 1, 1}},
|
{{vid.width / s, lines, 1, 1}},
|
||||||
{{ 0, 0, 0, ofs}},
|
{{ 0, 0, 0, ofs}},
|
||||||
{{vid.width, lines, 1, 1}},
|
{{vid.width / s, lines, 1, 1}},
|
||||||
{{ 0, lines, 0, 1}},
|
{{ 0, lines, 0, 1}},
|
||||||
};
|
};
|
||||||
|
|
||||||
GLSL_FlushText (); // Flush text that should be rendered before the console
|
GLSL_FlushText (); // Flush text that should be rendered before the console
|
||||||
|
@ -828,7 +830,13 @@ GLSL_Set2D (void)
|
||||||
void
|
void
|
||||||
GLSL_Set2DScaled (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
|
void
|
||||||
|
|
|
@ -141,3 +141,17 @@ Draw_PrintBuffer (draw_charbuffer_t *buffer, const char *str)
|
||||||
}
|
}
|
||||||
return lines;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -502,6 +502,7 @@ vid_render_funcs_t gl_vid_render_funcs = {
|
||||||
.init = gl_vid_render_init,
|
.init = gl_vid_render_init,
|
||||||
|
|
||||||
.Draw_CharBuffer = gl_Draw_CharBuffer,
|
.Draw_CharBuffer = gl_Draw_CharBuffer,
|
||||||
|
.Draw_SetScale = gl_Draw_SetScale,
|
||||||
.Draw_Character = gl_Draw_Character,
|
.Draw_Character = gl_Draw_Character,
|
||||||
.Draw_String = gl_Draw_String,
|
.Draw_String = gl_Draw_String,
|
||||||
.Draw_nString = gl_Draw_nString,
|
.Draw_nString = gl_Draw_nString,
|
||||||
|
|
|
@ -446,6 +446,7 @@ vid_render_funcs_t glsl_vid_render_funcs = {
|
||||||
.init = glsl_vid_render_init,
|
.init = glsl_vid_render_init,
|
||||||
|
|
||||||
.Draw_CharBuffer = glsl_Draw_CharBuffer,
|
.Draw_CharBuffer = glsl_Draw_CharBuffer,
|
||||||
|
.Draw_SetScale = glsl_Draw_SetScale,
|
||||||
.Draw_Character = glsl_Draw_Character,
|
.Draw_Character = glsl_Draw_Character,
|
||||||
.Draw_String = glsl_Draw_String,
|
.Draw_String = glsl_Draw_String,
|
||||||
.Draw_nString = glsl_Draw_nString,
|
.Draw_nString = glsl_Draw_nString,
|
||||||
|
|
|
@ -145,6 +145,12 @@ vulkan_Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer)
|
||||||
Vulkan_Draw_CharBuffer (x, y, buffer, vulkan_ctx);
|
Vulkan_Draw_CharBuffer (x, y, buffer, vulkan_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vulkan_Draw_SetScale (int scale)
|
||||||
|
{
|
||||||
|
vulkan_ctx->twod_scale = max (1, scale);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vulkan_Draw_Character (int x, int y, unsigned ch)
|
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
|
//FIXME this should not be done every frame
|
||||||
__auto_type mctx = vulkan_ctx->matrix_context;
|
__auto_type mctx = vulkan_ctx->matrix_context;
|
||||||
__auto_type mat = &mctx->matrices;
|
__auto_type mat = &mctx->matrices;
|
||||||
|
int scale = vulkan_ctx->twod_scale;
|
||||||
|
|
||||||
float left = -0.5;
|
float left = -0.5;
|
||||||
float top = -0.5;
|
float top = -0.5;
|
||||||
float right = left + vid.width; //FIXME vid
|
float right = left + vid.width / scale;
|
||||||
float bottom = top + vid.height;
|
float bottom = top + vid.height / scale;
|
||||||
QFV_Orthographic (mat->Projection2d, left, right, top, bottom, 0, 99999);
|
QFV_Orthographic (mat->Projection2d, left, right, top, bottom, 0, 99999);
|
||||||
|
|
||||||
mctx->dirty = mctx->frames.size;
|
mctx->dirty = mctx->frames.size;
|
||||||
|
@ -780,6 +787,7 @@ vid_render_funcs_t vulkan_vid_render_funcs = {
|
||||||
.init = vulkan_vid_render_init,
|
.init = vulkan_vid_render_init,
|
||||||
|
|
||||||
.Draw_CharBuffer = vulkan_Draw_CharBuffer,
|
.Draw_CharBuffer = vulkan_Draw_CharBuffer,
|
||||||
|
.Draw_SetScale = vulkan_Draw_SetScale,
|
||||||
.Draw_Character = vulkan_Draw_Character,
|
.Draw_Character = vulkan_Draw_Character,
|
||||||
.Draw_String = vulkan_Draw_String,
|
.Draw_String = vulkan_Draw_String,
|
||||||
.Draw_nString = vulkan_Draw_nString,
|
.Draw_nString = vulkan_Draw_nString,
|
||||||
|
|
|
@ -897,10 +897,11 @@ Vulkan_Draw_ConsoleBackground (int lines, byte alpha, vulkan_ctx_t *ctx)
|
||||||
quat_t color = { a, a, a, a};
|
quat_t color = { a, a, a, a};
|
||||||
qpic_t *cpic;
|
qpic_t *cpic;
|
||||||
cpic = Vulkan_Draw_CachePic ("gfx/conback.lmp", false, ctx);
|
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;
|
int ofs = frac * cpic->height;
|
||||||
subpic_t *subpic = *(subpic_t **) cpic->data;
|
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,
|
0, ofs, cpic->width, cpic->height - ofs, color,
|
||||||
&frame->quad_verts);
|
&frame->quad_verts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ Win_Vulkan_Context (void)
|
||||||
ctx->create_surface = win_vulkan_create_surface;
|
ctx->create_surface = win_vulkan_create_surface;
|
||||||
ctx->required_extensions = required_extensions;
|
ctx->required_extensions = required_extensions;
|
||||||
ctx->va_ctx = va_create_context (4);
|
ctx->va_ctx = va_create_context (4);
|
||||||
|
ctx->twod_scale = 1;
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,6 +224,7 @@ X11_Vulkan_Context (void)
|
||||||
ctx->create_surface = x11_vulkan_create_surface;
|
ctx->create_surface = x11_vulkan_create_surface;
|
||||||
ctx->required_extensions = required_extensions;
|
ctx->required_extensions = required_extensions;
|
||||||
ctx->va_ctx = va_create_context (32);
|
ctx->va_ctx = va_create_context (32);
|
||||||
|
ctx->twod_scale = 1;
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue