mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-29 23:52:22 +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"
|
#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 {
|
typedef struct rfont_s {
|
||||||
void *font_resource;
|
void *font_resource;
|
||||||
|
@ -53,7 +46,8 @@ typedef struct rfont_s {
|
||||||
rscrap_t scrap;
|
rscrap_t scrap;
|
||||||
byte *scrap_bitmap;
|
byte *scrap_bitmap;
|
||||||
FT_Long num_glyphs;
|
FT_Long num_glyphs;
|
||||||
rglyph_t *glyphs;
|
vrect_t *glyph_rects;
|
||||||
|
vec2i_t *glyph_bearings;
|
||||||
} rfont_t;
|
} rfont_t;
|
||||||
|
|
||||||
void R_FontInit (void);
|
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 rfont_s;
|
||||||
struct rglyph_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 {
|
typedef struct rshaper_s {
|
||||||
struct rfont_s *rfont;
|
struct rfont_s *rfont;
|
||||||
|
|
|
@ -43,10 +43,10 @@
|
||||||
static FT_Library ft;
|
static FT_Library ft;
|
||||||
|
|
||||||
static void
|
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;
|
int dst_pitch = font->scrap.width;
|
||||||
byte *dst = glyph->font->scrap_bitmap + glyph->rect->x + glyph->rect->y * dst_pitch;
|
byte *dst = font->scrap_bitmap + rect->x + rect->y * dst_pitch;
|
||||||
int src_pitch = src_glyph->bitmap.pitch;
|
int src_pitch = src_glyph->bitmap.pitch;
|
||||||
byte *src = src_glyph->bitmap.buffer;
|
byte *src = src_glyph->bitmap.buffer;
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ R_FontFree (rfont_t *font)
|
||||||
if (font->scrap.rects || font->scrap.free_rects) {
|
if (font->scrap.rects || font->scrap.free_rects) {
|
||||||
R_ScrapDelete (&font->scrap);
|
R_ScrapDelete (&font->scrap);
|
||||||
}
|
}
|
||||||
free (font->glyphs);
|
free (font->glyph_rects);
|
||||||
|
free (font->glyph_bearings);
|
||||||
free (font->scrap_bitmap);
|
free (font->scrap_bitmap);
|
||||||
free (font->font_resource);
|
free (font->font_resource);
|
||||||
free (font);
|
free (font);
|
||||||
|
@ -108,22 +109,21 @@ R_FontLoad (QFile *font_file, int size)
|
||||||
R_ScrapInit (&font->scrap, pixels, pixels);
|
R_ScrapInit (&font->scrap, pixels, pixels);
|
||||||
font->scrap_bitmap = calloc (1, pixels * pixels);
|
font->scrap_bitmap = calloc (1, pixels * pixels);
|
||||||
font->num_glyphs = font->face->num_glyphs;
|
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++) {
|
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);
|
FT_Load_Glyph (font->face, gind, FT_LOAD_DEFAULT);
|
||||||
__auto_type slot = font->face->glyph;
|
__auto_type slot = font->face->glyph;
|
||||||
FT_Render_Glyph (slot, FT_RENDER_MODE_NORMAL);
|
FT_Render_Glyph (slot, FT_RENDER_MODE_NORMAL);
|
||||||
int width = slot->bitmap.width;
|
int width = slot->bitmap.width;
|
||||||
int height = slot->bitmap.rows;
|
int height = slot->bitmap.rows;
|
||||||
glyph->font = font;
|
*rect = *R_ScrapAlloc (&font->scrap, width, height);
|
||||||
glyph->rect = R_ScrapAlloc (&font->scrap, width, height);
|
*bearing = (vec2i_t) { slot->bitmap_left, slot->bitmap_top };
|
||||||
glyph->bearing = (vec2i_t) { slot->bitmap_left, slot->bitmap_top };
|
|
||||||
glyph->advance = slot->advance.x;
|
|
||||||
glyph->charcode = gind;
|
|
||||||
|
|
||||||
copy_glyph (glyph, slot);
|
copy_glyph (rect, slot, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
|
|
|
@ -97,16 +97,16 @@ RText_RenderText (rshaper_t *shaper, rtext_t *text, int x, int y,
|
||||||
|
|
||||||
rfont_t *font = shaper->rfont;
|
rfont_t *font = shaper->rfont;
|
||||||
for (unsigned i = 0; i < count; i++) {
|
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 xp = x + glyphPos[i].x_offset / 64;
|
||||||
int yp = y + glyphPos[i].y_offset / 64;
|
int yp = y + glyphPos[i].y_offset / 64;
|
||||||
int xa = glyphPos[i].x_advance / 64;
|
int xa = glyphPos[i].x_advance / 64;
|
||||||
int ya = glyphPos[i].y_advance / 64;
|
int ya = glyphPos[i].y_advance / 64;
|
||||||
|
|
||||||
xp += glyph->bearing[0];
|
xp += bearing[0];
|
||||||
yp -= glyph->bearing[1];
|
yp -= bearing[1];
|
||||||
render (glyph, xp, yp, data);
|
render (glyphInfo[i].codepoint, xp, yp, data);
|
||||||
x += xa;
|
x += xa;
|
||||||
y += ya;
|
y += ya;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1209,30 +1209,30 @@ Vulkan_Draw_AddFont (rfont_t *rfont, vulkan_ctx_t *ctx)
|
||||||
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
||||||
glyphvert_t *verts = QFV_PacketExtend (packet, glyph_data->buffer.size);
|
glyphvert_t *verts = QFV_PacketExtend (packet, glyph_data->buffer.size);
|
||||||
for (FT_Long i = 0; i < rfont->num_glyphs; i++) {
|
for (FT_Long i = 0; i < rfont->num_glyphs; i++) {
|
||||||
rglyph_t *glyph = &rfont->glyphs[i];
|
vrect_t *rect = &rfont->glyph_rects[i];
|
||||||
float x = 0;//glyph->bearing[0];
|
float x = 0;
|
||||||
float y = 0;//-glyph->bearing[1]; // glyph +Y goes up
|
float y = 0;
|
||||||
float w = glyph->rect->width;
|
float w = rect->width;
|
||||||
float h = glyph->rect->height;
|
float h = rect->height;
|
||||||
float u = glyph->rect->x;
|
float u = rect->x;
|
||||||
float v = glyph->rect->y;
|
float v = rect->y;
|
||||||
// assumes the glyph image is square
|
|
||||||
float s = 1.0 / rfont->scrap.width;
|
float s = 1.0 / rfont->scrap.width;
|
||||||
|
float t = 1.0 / rfont->scrap.height;
|
||||||
verts[i * 4 + 0] = (glyphvert_t) {
|
verts[i * 4 + 0] = (glyphvert_t) {
|
||||||
.offset = { x + 0, y + 0 },
|
.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) {
|
verts[i * 4 + 1] = (glyphvert_t) {
|
||||||
.offset = { x + 0, y + h },
|
.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) {
|
verts[i * 4 + 2] = (glyphvert_t) {
|
||||||
.offset = { x + w, y + 0 },
|
.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) {
|
verts[i * 4 + 3] = (glyphvert_t) {
|
||||||
.offset = { x + w, y + h },
|
.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,
|
QFV_PacketCopyBuffer (packet, glyph_data->buffer.buffer,
|
||||||
|
@ -1280,7 +1280,7 @@ typedef struct {
|
||||||
} rgctx_t;
|
} rgctx_t;
|
||||||
|
|
||||||
static void
|
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;
|
rgctx_t *rgctx = _rgctx;
|
||||||
glyphqueue_t *queue = &rgctx->dframe->glyph_insts;;
|
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++;
|
rgctx->batch->count++;
|
||||||
glyphinst_t *inst = &queue->glyphs[queue->count++];
|
glyphinst_t *inst = &queue->glyphs[queue->count++];
|
||||||
inst->index = glyph->charcode;
|
inst->index = glyphid;
|
||||||
QuatCopy (rgctx->color, inst->color);
|
QuatCopy (rgctx->color, inst->color);
|
||||||
inst->position[0] = x;
|
inst->position[0] = x;
|
||||||
inst->position[1] = y;
|
inst->position[1] = y;
|
||||||
|
|
Loading…
Reference in a new issue