[renderer] Add Draw_AddFont for registering a font

It's implemented only in the Vulkan renderer, partly because there's a
lot of experimenting going on with it, but the glyphs do get transferred
to the GPU (checked in render doc). No rendering is done yet: still
thinking about whether to do a quick-and-dirty test, or to add HarfBuzz
immediately, and the design surrounding that.
This commit is contained in:
Bill Currie 2022-08-31 19:23:30 +09:00
parent 096ecc7710
commit 599c09e77e
14 changed files with 67 additions and 1 deletions

View file

@ -29,6 +29,7 @@
#define __gl_draw_h
struct qpic_s;
struct rfont_s;
void gl_Draw_Init (void);
void gl_Draw_Shutdown (void);
@ -54,6 +55,7 @@ void gl_Draw_Pic (int x, int y, struct qpic_s *pic);
void gl_Draw_Picf (float x, float y, struct qpic_s *pic);
void gl_Draw_SubPic(int x, int y, struct qpic_s *pic,
int srcx, int srcy, int width, int height);
void gl_Draw_AddFont (struct rfont_s *font);
void GL_Set2D (void);
void GL_Set2DScaled (void);

View file

@ -29,6 +29,7 @@
#define __QF_GLSL_qf_draw_h
struct qpic_s;
struct rfont_s;
void glsl_Draw_Init (void);
void glsl_Draw_Shutdown (void);
@ -54,6 +55,7 @@ void glsl_Draw_Pic (int x, int y, struct qpic_s *pic);
void glsl_Draw_Picf (float x, float y, struct qpic_s *pic);
void glsl_Draw_SubPic(int x, int y, struct qpic_s *pic,
int srcx, int srcy, int width, int height);
void glsl_Draw_AddFont (struct rfont_s *font);
void GLSL_Set2D (void);
void GLSL_Set2DScaled (void);

View file

@ -31,6 +31,7 @@
struct vulkan_ctx_s;
struct qfv_renderframe_s;
struct qpic_s;
struct rfont_s;
void Vulkan_Draw_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Draw_Shutdown (struct vulkan_ctx_s *ctx);
@ -71,6 +72,7 @@ void Vulkan_Draw_Picf (float x, float y, struct qpic_s *pic,
void Vulkan_Draw_SubPic(int x, int y, struct qpic_s *pic,
int srcx, int srcy, int width, int height,
struct vulkan_ctx_s *ctx);
void Vulkan_Draw_AddFont (struct rfont_s *font, struct vulkan_ctx_s *ctx);
void Vulkan_Set2D (struct vulkan_ctx_s *ctx);
void Vulkan_Set2DScaled (struct vulkan_ctx_s *ctx);

View file

@ -243,6 +243,10 @@ void Draw_Picf (float x, float y, qpic_t *pic);
\param height vertical size of the sub-region to be drawn
*/
void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height);
struct rfont_s;
void Draw_AddFont (struct rfont_s *font);
///@}
#endif//__QF_draw_h

View file

@ -78,6 +78,7 @@ typedef struct vid_model_funcs_s {
} vid_model_funcs_t;
struct tex_s;
struct rfont_s;
typedef void (*capfunc_t) (struct tex_s *screencap, void *data);
typedef struct vid_render_funcs_s {
@ -103,6 +104,7 @@ typedef struct vid_render_funcs_s {
void (*Draw_Pic) (int x, int y, qpic_t *pic);
void (*Draw_Picf) (float x, float y, qpic_t *pic);
void (*Draw_SubPic) (int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height);
void (*Draw_AddFont) (struct rfont_s *font);
struct psystem_s *(*ParticleSystem) (void);

View file

@ -1018,3 +1018,8 @@ gl_Draw_BlendScreen (quat_t color)
qfglColor3ubv (color_white);
qfglEnable (GL_TEXTURE_2D);
}
void
gl_Draw_AddFont (struct rfont_s *font)
{
}

View file

@ -841,3 +841,8 @@ glsl_Draw_BlendScreen (quat_t color)
return;
draw_blendscreen (color);
}
void
glsl_Draw_AddFont (struct rfont_s *font)
{
}

View file

@ -343,7 +343,7 @@ bi_Font_Load (progs_t *pr, void *_res)
QFile *font_file = QFS_FOpenFile (font_path);
rfont_t *font = R_FontLoad (font_file, font_size, preload);
(void)font;
r_funcs->Draw_AddFont (font);
}
static const char *

View file

@ -974,3 +974,8 @@ Draw_BlendScreen (quat_t color)
}
vid.vid_internal->set_palette (vid.vid_internal->data, pal);
}
void
Draw_AddFont (struct rfont_s *font)
{
}

View file

@ -507,6 +507,7 @@ vid_render_funcs_t gl_vid_render_funcs = {
gl_Draw_Pic,
gl_Draw_Picf,
gl_Draw_SubPic,
gl_Draw_AddFont,
gl_ParticleSystem,
gl_R_Init,

View file

@ -451,6 +451,7 @@ vid_render_funcs_t glsl_vid_render_funcs = {
glsl_Draw_Pic,
glsl_Draw_Picf,
glsl_Draw_SubPic,
glsl_Draw_AddFont,
glsl_ParticleSystem,
glsl_R_Init,

View file

@ -471,6 +471,7 @@ vid_render_funcs_t sw_vid_render_funcs = {
Draw_Pic,
Draw_Picf,
Draw_SubPic,
Draw_AddFont,
sw_ParticleSystem,
sw_R_Init,

View file

@ -261,6 +261,12 @@ vulkan_Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, in
Vulkan_Draw_SubPic (x, y, pic, srcx, srcy, width, height, vulkan_ctx);
}
static void
vulkan_Draw_AddFont (struct rfont_s *font)
{
Vulkan_Draw_AddFont (font, vulkan_ctx);
}
static void
vulkan_begin_frame (void)
{
@ -749,6 +755,7 @@ vid_render_funcs_t vulkan_vid_render_funcs = {
vulkan_Draw_Pic,
vulkan_Draw_Picf,
vulkan_Draw_SubPic,
vulkan_Draw_AddFont,
vulkan_ParticleSystem,
vulkan_R_Init,

View file

@ -52,6 +52,7 @@
#include "compat.h"
#include "QF/Vulkan/qf_draw.h"
#include "QF/Vulkan/qf_matrices.h"
#include "QF/Vulkan/qf_texture.h"
#include "QF/Vulkan/qf_vid.h"
#include "QF/Vulkan/barrier.h"
#include "QF/Vulkan/buffer.h"
@ -66,6 +67,7 @@
#include "QF/Vulkan/staging.h"
#include "QF/ui/view.h"
#include "r_font.h"
#include "r_internal.h"
#include "vid_vulkan.h"
@ -97,6 +99,8 @@ typedef struct drawframeset_s
typedef struct drawctx_s {
VkSampler sampler;
scrap_t *scrap;
rfont_t *font;
qfv_tex_t *font_tex;
qfv_stagebuf_t *stage;
qpic_t *crosshair;
qpic_t *conchars;
@ -369,6 +373,9 @@ Vulkan_Draw_Shutdown (vulkan_ctx_t *ctx)
delete_memsuper (dctx->string_memsuper);
QFV_DestroyScrap (dctx->scrap);
QFV_DestroyStagingBuffer (dctx->stage);
if (dctx->font_tex) {
Vulkan_UnloadTex (ctx, dctx->font_tex);
}
}
void
@ -943,3 +950,25 @@ Vulkan_Draw_BlendScreen (quat_t color, vulkan_ctx_t *ctx)
draw_blendscreen (c, ctx);
}
}
void
Vulkan_Draw_AddFont (rfont_t *font, vulkan_ctx_t *ctx)
{
drawctx_t *dctx = ctx->draw_context;
if (dctx->font_tex) {
Vulkan_UnloadTex (ctx, dctx->font_tex);
dctx->font_tex = 0;
}
dctx->font = font;
if (dctx->font) {
tex_t tex = {
.width = font->scrap.width,
.height = font->scrap.height,
.format = tex_l,
.loaded = 1,
.data = font->scrap_bitmap,
};
dctx->font_tex = Vulkan_LoadTex (ctx, &tex, 0, "draw.font");
}
}