adjust how the font loading works

This commit is contained in:
Allen Webster 2016-05-27 21:11:48 -04:00
parent a90c33f09b
commit a208c045e3
3 changed files with 58 additions and 49 deletions

View File

@ -385,9 +385,8 @@ draw_font_info_load(Partition *partition,
return(result); return(result);
} }
// TODO(allen): Why the hell am I not just passing in a partition here?
internal i32 internal i32
draw_font_load(void *base_block, i32 size, draw_font_load(Partition *part,
Render_Font *font_out, Render_Font *font_out,
char *filename_untranslated, char *filename_untranslated,
i32 pt_size, i32 pt_size,
@ -400,19 +399,16 @@ draw_font_load(void *base_block, i32 size,
if (!translate_success) return 0; if (!translate_success) return 0;
i32 result = 1; i32 result = 1;
File_Data file;
file = sysshared_load_file(filename.str);
Partition partition_ = make_part(base_block, size);
Partition *partition = &partition_;
stbtt_packedchar *chardata = font_out->chardata; stbtt_packedchar *chardata = font_out->chardata;
Temp_Memory temp = begin_temp_memory(part);
i32 tex_width, tex_height; i32 tex_width = pt_size*16*oversample;
tex_width = pt_size*128*oversample; i32 tex_height = pt_size*16*oversample;
tex_height = pt_size*2*oversample; void *block = sysshared_push_block(part, tex_width * tex_height);
void *block = push_block(partition, tex_width * tex_height);
File_Data file = sysshared_load_file(filename.str);
if (!file.data.data){ if (!file.data.data){
result = 0; result = 0;
@ -446,13 +442,14 @@ draw_font_load(void *base_block, i32 size,
stbtt_pack_context spc; stbtt_pack_context spc;
if (stbtt_PackBegin(&spc, (u8*)block, tex_width, tex_height, tex_width, 1, partition)){ // TODO(allen): If this fails we can just expand the partition here now
// rather than forcing the user to do it.
if (stbtt_PackBegin(&spc, (u8*)block, tex_width, tex_height,
tex_width, 1, part)){
stbtt_PackSetOversampling(&spc, oversample, oversample); stbtt_PackSetOversampling(&spc, oversample, oversample);
if (stbtt_PackFontRange(&spc, (u8*)file.data.data, 0, if (!stbtt_PackFontRange(&spc, (u8*)file.data.data, 0,
STBTT_POINT_SIZE((f32)pt_size), 0, 128, chardata)){ STBTT_POINT_SIZE((f32)pt_size),
// do nothing 0, 128, chardata)){
}
else{
result = 0; result = 0;
} }
@ -500,7 +497,9 @@ draw_font_load(void *base_block, i32 size,
system_free_memory(file.data.data); system_free_memory(file.data.data);
} }
return result; end_temp_memory(temp);
return(result);
} }
internal internal

View File

@ -153,7 +153,7 @@ sysshared_partition_grow(Partition *part, i32 new_size){
void *data = 0; void *data = 0;
if (new_size > part->max){ if (new_size > part->max){
// TODO(allen): attempt to grow in place by just // TODO(allen): attempt to grow in place by just
// acquiring larger vpages?! // acquiring next vpages?!
data = system_get_memory(new_size); data = system_get_memory(new_size);
memcpy(data, part->base, part->pos); memcpy(data, part->base, part->pos);
system_free_memory(part->base); system_free_memory(part->base);
@ -166,6 +166,17 @@ sysshared_partition_double(Partition *part){
sysshared_partition_grow(part, part->max*2); sysshared_partition_grow(part, part->max*2);
} }
internal void*
sysshared_push_block(Partition *part, i32 size){
void *result = 0;
result = push_block(part, size);
if (!result){
sysshared_partition_grow(part, size+part->max);
result = push_block(part, size);
}
return(result);
}
internal b32 internal b32
sysshared_to_binary_path(String *out_filename, char *filename){ sysshared_to_binary_path(String *out_filename, char *filename){
b32 translate_success = 0; b32 translate_success = 0;

View File

@ -1172,8 +1172,7 @@ Font_Load_Sig(system_draw_font_load){
i32 oversample = 2; i32 oversample = 2;
for (b32 success = 0; success == 0;){ for (b32 success = 0; success == 0;){
success = draw_font_load(win32vars.font_part.base, success = draw_font_load(&win32vars.font_part,
win32vars.font_part.max,
font_out, font_out,
filename, filename,
pt_size, pt_size,