mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
[renderer] Remove rglyph_t struct
It didn't really add anything of value as the glyph bitmap rects and the bearings were never used together, and the rest of the fields were entirely redundant. A small step towards using a component system for text.
This commit is contained in:
parent
06ccc3023b
commit
6189142c60
5 changed files with 33 additions and 39 deletions
|
@ -39,13 +39,6 @@
|
|||
|
||||
#include "r_scrap.h"
|
||||
|
||||
typedef struct rglyph_s {
|
||||
struct rfont_s *font;
|
||||
vrect_t *rect;
|
||||
vec2i_t bearing;
|
||||
int advance;
|
||||
int charcode;
|
||||
} rglyph_t;
|
||||
|
||||
typedef struct rfont_s {
|
||||
void *font_resource;
|
||||
|
@ -53,7 +46,8 @@ typedef struct rfont_s {
|
|||
rscrap_t scrap;
|
||||
byte *scrap_bitmap;
|
||||
FT_Long num_glyphs;
|
||||
rglyph_t *glyphs;
|
||||
vrect_t *glyph_rects;
|
||||
vec2i_t *glyph_bearings;
|
||||
} rfont_t;
|
||||
|
||||
void R_FontInit (void);
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct r_hb_featureset_s DARRAY_TYPE (hb_feature_t) r_hb_featureset_t;
|
|||
|
||||
struct rfont_s;
|
||||
struct rglyph_s;
|
||||
typedef void rtext_render_t (struct rglyph_s *glyph, int x, int y, void *data);
|
||||
typedef void rtext_render_t (uint32_t glyphid, int x, int y, void *data);
|
||||
|
||||
typedef struct rshaper_s {
|
||||
struct rfont_s *rfont;
|
||||
|
|
|
@ -43,10 +43,10 @@
|
|||
static FT_Library ft;
|
||||
|
||||
static void
|
||||
copy_glyph (rglyph_t *glyph, FT_GlyphSlot src_glyph)
|
||||
copy_glyph (vrect_t *rect, FT_GlyphSlot src_glyph, rfont_t *font)
|
||||
{
|
||||
int dst_pitch = glyph->font->scrap.width;
|
||||
byte *dst = glyph->font->scrap_bitmap + glyph->rect->x + glyph->rect->y * dst_pitch;
|
||||
int dst_pitch = font->scrap.width;
|
||||
byte *dst = font->scrap_bitmap + rect->x + rect->y * dst_pitch;
|
||||
int src_pitch = src_glyph->bitmap.pitch;
|
||||
byte *src = src_glyph->bitmap.buffer;
|
||||
|
||||
|
@ -74,7 +74,8 @@ R_FontFree (rfont_t *font)
|
|||
if (font->scrap.rects || font->scrap.free_rects) {
|
||||
R_ScrapDelete (&font->scrap);
|
||||
}
|
||||
free (font->glyphs);
|
||||
free (font->glyph_rects);
|
||||
free (font->glyph_bearings);
|
||||
free (font->scrap_bitmap);
|
||||
free (font->font_resource);
|
||||
free (font);
|
||||
|
@ -108,22 +109,21 @@ R_FontLoad (QFile *font_file, int size)
|
|||
R_ScrapInit (&font->scrap, pixels, pixels);
|
||||
font->scrap_bitmap = calloc (1, pixels * pixels);
|
||||
font->num_glyphs = font->face->num_glyphs;
|
||||
font->glyphs = malloc (font->num_glyphs * sizeof (rglyph_t));
|
||||
font->glyph_rects = malloc (font->num_glyphs * sizeof (vrect_t));
|
||||
font->glyph_bearings = malloc (font->num_glyphs * sizeof (vec2i_t));
|
||||
|
||||
for (FT_Long gind = 0; gind < font->face->num_glyphs; gind++) {
|
||||
rglyph_t *glyph = &font->glyphs[gind];
|
||||
vrect_t *rect = &font->glyph_rects[gind];
|
||||
vec2i_t *bearing = &font->glyph_bearings[gind];
|
||||
FT_Load_Glyph (font->face, gind, FT_LOAD_DEFAULT);
|
||||
__auto_type slot = font->face->glyph;
|
||||
FT_Render_Glyph (slot, FT_RENDER_MODE_NORMAL);
|
||||
int width = slot->bitmap.width;
|
||||
int height = slot->bitmap.rows;
|
||||
glyph->font = font;
|
||||
glyph->rect = R_ScrapAlloc (&font->scrap, width, height);
|
||||
glyph->bearing = (vec2i_t) { slot->bitmap_left, slot->bitmap_top };
|
||||
glyph->advance = slot->advance.x;
|
||||
glyph->charcode = gind;
|
||||
*rect = *R_ScrapAlloc (&font->scrap, width, height);
|
||||
*bearing = (vec2i_t) { slot->bitmap_left, slot->bitmap_top };
|
||||
|
||||
copy_glyph (glyph, slot);
|
||||
copy_glyph (rect, slot, font);
|
||||
}
|
||||
|
||||
return font;
|
||||
|
|
|
@ -97,16 +97,16 @@ RText_RenderText (rshaper_t *shaper, rtext_t *text, int x, int y,
|
|||
|
||||
rfont_t *font = shaper->rfont;
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
rglyph_t *glyph = &font->glyphs[glyphInfo[i].codepoint];
|
||||
vec2i_t bearing = font->glyph_bearings[glyphInfo[i].codepoint];
|
||||
|
||||
int xp = x + glyphPos[i].x_offset / 64;
|
||||
int yp = y + glyphPos[i].y_offset / 64;
|
||||
int xa = glyphPos[i].x_advance / 64;
|
||||
int ya = glyphPos[i].y_advance / 64;
|
||||
|
||||
xp += glyph->bearing[0];
|
||||
yp -= glyph->bearing[1];
|
||||
render (glyph, xp, yp, data);
|
||||
xp += bearing[0];
|
||||
yp -= bearing[1];
|
||||
render (glyphInfo[i].codepoint, xp, yp, data);
|
||||
x += xa;
|
||||
y += ya;
|
||||
}
|
||||
|
|
|
@ -1209,30 +1209,30 @@ Vulkan_Draw_AddFont (rfont_t *rfont, vulkan_ctx_t *ctx)
|
|||
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
||||
glyphvert_t *verts = QFV_PacketExtend (packet, glyph_data->buffer.size);
|
||||
for (FT_Long i = 0; i < rfont->num_glyphs; i++) {
|
||||
rglyph_t *glyph = &rfont->glyphs[i];
|
||||
float x = 0;//glyph->bearing[0];
|
||||
float y = 0;//-glyph->bearing[1]; // glyph +Y goes up
|
||||
float w = glyph->rect->width;
|
||||
float h = glyph->rect->height;
|
||||
float u = glyph->rect->x;
|
||||
float v = glyph->rect->y;
|
||||
// assumes the glyph image is square
|
||||
vrect_t *rect = &rfont->glyph_rects[i];
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float w = rect->width;
|
||||
float h = rect->height;
|
||||
float u = rect->x;
|
||||
float v = rect->y;
|
||||
float s = 1.0 / rfont->scrap.width;
|
||||
float t = 1.0 / rfont->scrap.height;
|
||||
verts[i * 4 + 0] = (glyphvert_t) {
|
||||
.offset = { x + 0, y + 0 },
|
||||
.uv = {(u + 0.25) * s, (v + 0.25) * s },
|
||||
.uv = {(u + 0.25) * s, (v + 0.25) * t },
|
||||
};
|
||||
verts[i * 4 + 1] = (glyphvert_t) {
|
||||
.offset = { x + 0, y + h },
|
||||
.uv = {(u + 0.25) * s, (v + h - 0.25) * s },
|
||||
.uv = {(u + 0.25) * s, (v + h - 0.25) * t },
|
||||
};
|
||||
verts[i * 4 + 2] = (glyphvert_t) {
|
||||
.offset = { x + w, y + 0 },
|
||||
.uv = {(u + w - 0.25) * s, (v + 0.25) * s },
|
||||
.uv = {(u + w - 0.25) * s, (v + 0.25) * t },
|
||||
};
|
||||
verts[i * 4 + 3] = (glyphvert_t) {
|
||||
.offset = { x + w, y + h },
|
||||
.uv = {(u + w - 0.25) * s, (v + h - 0.25) * s },
|
||||
.uv = {(u + w - 0.25) * s, (v + h - 0.25) * t },
|
||||
};
|
||||
}
|
||||
QFV_PacketCopyBuffer (packet, glyph_data->buffer.buffer,
|
||||
|
@ -1280,7 +1280,7 @@ typedef struct {
|
|||
} rgctx_t;
|
||||
|
||||
static void
|
||||
vulkan_render_glyph (rglyph_t *glyph, int x, int y, void *_rgctx)
|
||||
vulkan_render_glyph (uint32_t glyphid, int x, int y, void *_rgctx)
|
||||
{
|
||||
rgctx_t *rgctx = _rgctx;
|
||||
glyphqueue_t *queue = &rgctx->dframe->glyph_insts;;
|
||||
|
@ -1291,7 +1291,7 @@ vulkan_render_glyph (rglyph_t *glyph, int x, int y, void *_rgctx)
|
|||
|
||||
rgctx->batch->count++;
|
||||
glyphinst_t *inst = &queue->glyphs[queue->count++];
|
||||
inst->index = glyph->charcode;
|
||||
inst->index = glyphid;
|
||||
QuatCopy (rgctx->color, inst->color);
|
||||
inst->position[0] = x;
|
||||
inst->position[1] = y;
|
||||
|
|
Loading…
Reference in a new issue