change data structures to include texel info
This commit is contained in:
parent
91d7c75ca4
commit
1a71c3235d
34
fonts.d
34
fonts.d
@ -13,6 +13,13 @@ import std.algorithm.sorting;
|
|||||||
const u64 FONT_MAX_BANDS = 8;
|
const u64 FONT_MAX_BANDS = 8;
|
||||||
const u64 FONT_TEX_WIDTH = 4096;
|
const u64 FONT_TEX_WIDTH = 4096;
|
||||||
|
|
||||||
|
struct SlugTexel(T)
|
||||||
|
{
|
||||||
|
T[] data;
|
||||||
|
u32 height;
|
||||||
|
u32 width;
|
||||||
|
}
|
||||||
|
|
||||||
struct SlugCurveRef
|
struct SlugCurveRef
|
||||||
{
|
{
|
||||||
u32 index;
|
u32 index;
|
||||||
@ -59,8 +66,8 @@ struct SlugGlyph
|
|||||||
struct SlugFontInfo
|
struct SlugFontInfo
|
||||||
{
|
{
|
||||||
SlugCurve[] curves;
|
SlugCurve[] curves;
|
||||||
f32[] curve_texel_data;
|
SlugTexel!(f32) curve_texel;
|
||||||
u32[] band_texel_data;
|
SlugTexel!(u32) band_texel;
|
||||||
SlugGlyphBandData[] glyph_bands;
|
SlugGlyphBandData[] glyph_bands;
|
||||||
SlugFont base;
|
SlugFont base;
|
||||||
|
|
||||||
@ -542,8 +549,12 @@ LoadFontCurves(Arena* arena, SlugFontInfo* font_info, u8[] font_file_data)
|
|||||||
|
|
||||||
u32 curve_texel_height = clamp(cast(u32)((curve_texel_count+FONT_TEX_WIDTH-1) / FONT_TEX_WIDTH), 1, -1);
|
u32 curve_texel_height = clamp(cast(u32)((curve_texel_count+FONT_TEX_WIDTH-1) / FONT_TEX_WIDTH), 1, -1);
|
||||||
|
|
||||||
f32[] curve_texel_data = Alloc!(f32)(arena, FONT_TEX_WIDTH*curve_texel_height*4);
|
|
||||||
u32[] curve_start_indices = Alloc!(u32)(arena, font_info.glyphs.length);
|
u32[] curve_start_indices = Alloc!(u32)(arena, font_info.glyphs.length);
|
||||||
|
SlugTexel!(f32) curve_texel = {
|
||||||
|
data: Alloc!(f32)(arena, FONT_TEX_WIDTH*curve_texel_height*4),
|
||||||
|
height: curve_texel_height,
|
||||||
|
width: FONT_TEX_WIDTH,
|
||||||
|
};
|
||||||
|
|
||||||
curve_index = 1;
|
curve_index = 1;
|
||||||
foreach(i; 0 .. font_info.glyphs.length)
|
foreach(i; 0 .. font_info.glyphs.length)
|
||||||
@ -560,14 +571,14 @@ LoadFontCurves(Arena* arena, SlugFontInfo* font_info, u8[] font_file_data)
|
|||||||
UVec2 t0 = UVec2(curve_index%FONT_TEX_WIDTH, curve_index/FONT_TEX_WIDTH);
|
UVec2 t0 = UVec2(curve_index%FONT_TEX_WIDTH, curve_index/FONT_TEX_WIDTH);
|
||||||
u32 offset = cast(u32)((t0.y*FONT_TEX_WIDTH + t0.x) * 4);
|
u32 offset = cast(u32)((t0.y*FONT_TEX_WIDTH + t0.x) * 4);
|
||||||
|
|
||||||
curve_texel_data[offset .. offset+4] = [curve.p1.x, curve.p1.y, curve.p2.x, curve.p2.y];
|
curve_texel.data[offset .. offset+4] = [curve.p1.x, curve.p1.y, curve.p2.x, curve.p2.y];
|
||||||
|
|
||||||
curve_index += 1;
|
curve_index += 1;
|
||||||
|
|
||||||
UVec2 t1 = UVec2(curve_index%FONT_TEX_WIDTH, curve_index/FONT_TEX_WIDTH);
|
UVec2 t1 = UVec2(curve_index%FONT_TEX_WIDTH, curve_index/FONT_TEX_WIDTH);
|
||||||
offset = cast(u32)((t1.y*FONT_TEX_WIDTH + t1.x) * 4);
|
offset = cast(u32)((t1.y*FONT_TEX_WIDTH + t1.x) * 4);
|
||||||
|
|
||||||
curve_texel_data[offset .. offset+4] = [curve.p3.x, curve.p3.y, 0.0, 0.0];
|
curve_texel.data[offset .. offset+4] = [curve.p3.x, curve.p3.y, 0.0, 0.0];
|
||||||
|
|
||||||
curve_index += 1;
|
curve_index += 1;
|
||||||
}
|
}
|
||||||
@ -600,7 +611,11 @@ LoadFontCurves(Arena* arena, SlugFontInfo* font_info, u8[] font_file_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
u32 band_texel_height = clamp(cast(u32)((band_total_count+FONT_TEX_WIDTH-1) / FONT_TEX_WIDTH), 1U, u32.max);
|
u32 band_texel_height = clamp(cast(u32)((band_total_count+FONT_TEX_WIDTH-1) / FONT_TEX_WIDTH), 1U, u32.max);
|
||||||
u32[] band_texel_data = Alloc!(u32)(arena, FONT_TEX_WIDTH*band_texel_height*4);
|
SlugTexel!(u32) band_texel = {
|
||||||
|
data: Alloc!(u32)(arena, FONT_TEX_WIDTH*band_texel_height*4),
|
||||||
|
width: FONT_TEX_WIDTH,
|
||||||
|
height: band_texel_height,
|
||||||
|
};
|
||||||
|
|
||||||
u32 band_index;
|
u32 band_index;
|
||||||
foreach(i; 0 .. font_info.glyphs.length)
|
foreach(i; 0 .. font_info.glyphs.length)
|
||||||
@ -661,7 +676,7 @@ LoadFontCurves(Arena* arena, SlugFontInfo* font_info, u8[] font_file_data)
|
|||||||
count = band_data.bands[1][index].count;
|
count = band_data.bands[1][index].count;
|
||||||
}
|
}
|
||||||
|
|
||||||
band_texel_data[di .. di+2] = [count, offsets[j]];
|
band_texel.data[di .. di+2] = [count, offsets[j]];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(j; 0 .. band_total)
|
foreach(j; 0 .. band_total)
|
||||||
@ -678,12 +693,15 @@ LoadFontCurves(Arena* arena, SlugFontInfo* font_info, u8[] font_file_data)
|
|||||||
u32 tl = ls+k;
|
u32 tl = ls+k;
|
||||||
u32 di = cast(u32)((tl/FONT_TEX_WIDTH*FONT_TEX_WIDTH + tl%FONT_TEX_WIDTH) * 4);
|
u32 di = cast(u32)((tl/FONT_TEX_WIDTH*FONT_TEX_WIDTH + tl%FONT_TEX_WIDTH) * 4);
|
||||||
|
|
||||||
band_texel_data[di .. di+2] = [ct%FONT_TEX_WIDTH, ct/FONT_TEX_WIDTH];
|
band_texel.data[di .. di+2] = [ct%FONT_TEX_WIDTH, ct/FONT_TEX_WIDTH];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
band_index = glyph_start+band_offset;
|
band_index = glyph_start+band_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
font_info.curve_texel = curve_texel;
|
||||||
|
font_info.band_texel = band_texel;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user