Mercurial > repos > blastem
comparison nuklear_ui/nuklear.h @ 2011:579fe3f6fe76
Improved texture atlas size estimation in Nuklear
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 01 Nov 2020 12:35:08 -0800 |
parents | 92532eb6986d |
children | 638eb2d25696 86dfcf3f418a |
comparison
equal
deleted
inserted
replaced
2010:19957e7353a4 | 2011:579fe3f6fe76 |
---|---|
11366 NK_ASSERT(config_list); | 11366 NK_ASSERT(config_list); |
11367 NK_ASSERT(count); | 11367 NK_ASSERT(count); |
11368 NK_ASSERT(alloc); | 11368 NK_ASSERT(alloc); |
11369 | 11369 |
11370 if (!image_memory || !width || !height || !config_list || !count) return nk_false; | 11370 if (!image_memory || !width || !height || !config_list || !count) return nk_false; |
11371 int pixel_area_estimate = 0; | |
11371 for (config_iter = config_list; config_iter; config_iter = config_iter->next) { | 11372 for (config_iter = config_list; config_iter; config_iter = config_iter->next) { |
11372 range_count = nk_range_count(config_iter->range); | 11373 range_count = nk_range_count(config_iter->range); |
11373 total_range_count += range_count; | 11374 total_range_count += range_count; |
11374 total_glyph_count += nk_range_glyph_count(config_iter->range, range_count); | 11375 int glyphs = nk_range_glyph_count(config_iter->range, range_count); |
11376 total_glyph_count += glyphs; | |
11377 pixel_area_estimate += glyphs * config_iter->size * config_iter->size; | |
11375 } | 11378 } |
11376 | 11379 |
11377 /* setup font baker from temporary memory */ | 11380 /* setup font baker from temporary memory */ |
11378 for (config_iter = config_list; config_iter; config_iter = config_iter->next) { | 11381 for (config_iter = config_list; config_iter; config_iter = config_iter->next) { |
11379 const struct nk_font_config *cfg = config_iter; | 11382 const struct nk_font_config *cfg = config_iter; |
11380 if (!nk_tt_InitFont(&baker->build[i++].info, (const unsigned char*)cfg->ttf_blob, 0)) | 11383 if (!nk_tt_InitFont(&baker->build[i++].info, (const unsigned char*)cfg->ttf_blob, 0)) |
11381 return nk_false; | 11384 return nk_false; |
11382 } | 11385 } |
11383 | 11386 |
11384 *height = 0; | 11387 *height = 0; |
11385 *width = (total_glyph_count > 1000) ? 1024 : 512; | 11388 int width_estimate = sqrt(pixel_area_estimate) + 0.5; |
11389 *width = 128; | |
11390 while (*width < width_estimate) | |
11391 { | |
11392 *width *= 2; | |
11393 } | |
11394 //*width = (total_glyph_count > 1000) ? 1024 : 512; | |
11386 nk_tt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc); | 11395 nk_tt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc); |
11387 { | 11396 { |
11388 int input_i = 0; | 11397 int input_i = 0; |
11389 int range_n = 0; | 11398 int range_n = 0; |
11390 int rect_n = 0; | 11399 int rect_n = 0; |