add slug vertex loading
This commit is contained in:
parent
ff0e689dd4
commit
6ae59dab5b
80
fonts.d
80
fonts.d
@ -102,9 +102,9 @@ struct SlugVertex
|
|||||||
{
|
{
|
||||||
Vec2 em_space_pos;
|
Vec2 em_space_pos;
|
||||||
U16Vec2 glyph_data_coords;
|
U16Vec2 glyph_data_coords;
|
||||||
struct max_bands
|
struct
|
||||||
{
|
{
|
||||||
u8 x, pad, y, e;
|
u8 max_bands_x, pad, max_bands_y, max_bands_e;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -121,13 +121,20 @@ struct SlugVertex
|
|||||||
Vec4 band;
|
Vec4 band;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
Vec4 scale;
|
Vec2 band_scale;
|
||||||
Vec4 offset;
|
Vec2 band_offset;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Vec4 color;
|
Vec4 color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SlugBuffer
|
||||||
|
{
|
||||||
|
SlugVertex[] vertices;
|
||||||
|
u32[] indices;
|
||||||
|
u32 quad_offset;
|
||||||
|
}
|
||||||
|
|
||||||
struct FontAtlas
|
struct FontAtlas
|
||||||
{
|
{
|
||||||
Glyph[128] glyphs;
|
Glyph[128] glyphs;
|
||||||
@ -818,3 +825,68 @@ SlugBuildBands(Arena* arena, u32 index, SlugFontInfo* font_info, u32 band_count)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SlugLoadFontVertex(u8 ch, IVec2 pos, SlugFont* font, SlugBuffer* buffer)
|
||||||
|
{
|
||||||
|
ch = ch > 127 ? 0 : ch;
|
||||||
|
|
||||||
|
SlugGlyph* glyph = &font.glyphs[ch];
|
||||||
|
|
||||||
|
if(ch == ' ')
|
||||||
|
{
|
||||||
|
pos.x += cast(i32)(cast(f32)(glyph.advance) * font.scale);
|
||||||
|
}
|
||||||
|
else if(glyph.curve_count > 0)
|
||||||
|
{
|
||||||
|
Vec2 glyph_pos = Vec2(pos.x, pos.y);
|
||||||
|
|
||||||
|
Vec2 p0 = glyph_pos + glyph.rect.min * font.scale;
|
||||||
|
Vec2 p1 = glyph_pos + glyph.rect.max * font.scale;
|
||||||
|
|
||||||
|
u32 vertex_start = buffer.quad_offset*4;
|
||||||
|
u32 index_start = buffer.quad_offset*6;
|
||||||
|
|
||||||
|
SlugVertex[] vertices = buffer.vertices[vertex_start .. vertex_start+4];
|
||||||
|
u32[] indices = buffer.indices[index_start .. index_start+6];
|
||||||
|
|
||||||
|
const f32 NORMAL = 1.0;
|
||||||
|
|
||||||
|
f32 inv_scale = 1.0f/font.scale;
|
||||||
|
|
||||||
|
foreach(i; 0 .. 4)
|
||||||
|
{
|
||||||
|
vertices[i].band_scale = glyph.band_scale;
|
||||||
|
vertices[i].band_offset = glyph.band_offset;
|
||||||
|
vertices[i].glyph_data_coords = glyph.coords;
|
||||||
|
vertices[i].max_bands_x = glyph.max_bands.x;
|
||||||
|
vertices[i].max_bands_y = glyph.max_bands.y;
|
||||||
|
vertices[i].jac = Vec4(inv_scale, 0.0, 0.0, inv_scale);
|
||||||
|
|
||||||
|
vertices[i].color = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertices[0].vertex_coords = p0;
|
||||||
|
vertices[0].normal = Vec2(-NORMAL, +NORMAL);
|
||||||
|
vertices[0].em_space_pos = Vec2(glyph.rect.min.x, glyph.rect.max.y);
|
||||||
|
|
||||||
|
vertices[1].vertex_coords = Vec2(p0.x, p1.y);
|
||||||
|
vertices[1].normal = -NORMAL;
|
||||||
|
vertices[1].em_space_pos = glyph.rect.min;
|
||||||
|
|
||||||
|
vertices[2].vertex_coords = Vec2(p1.x, p0.y);
|
||||||
|
vertices[2].normal = +NORMAL;
|
||||||
|
vertices[2].em_space_pos = glyph.rect.max;
|
||||||
|
|
||||||
|
vertices[3].vertex_coords = p1;
|
||||||
|
vertices[3].normal = Vec2(+NORMAL, -NORMAL);
|
||||||
|
vertices[3].em_space_pos = Vec2(glyph.rect.max.x, glyph.rect.min.y);
|
||||||
|
|
||||||
|
u32 vidx = vertex_start;
|
||||||
|
indices[0 .. 6] = [vidx+0, vidx+2, vidx+3, vidx+3, vidx+1, vidx+0];
|
||||||
|
|
||||||
|
buffer.quad_offset += 1;
|
||||||
|
|
||||||
|
pos.x += cast(i32)(cast(f32)(glyph.advance) * font.scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user