summaryrefslogtreecommitdiff
path: root/nuklear_ui
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2020-11-01 12:35:08 -0800
committerMike Pavone <pavone@retrodev.com>2020-11-01 12:35:08 -0800
commit7ea6b7c380286ba6935fa1d904b70be2c82b74bf (patch)
tree4be5dd77e998051d0282b44bc1618a20b11787ce /nuklear_ui
parent2c54fbbbedc03dfc028472c32489b11b7059c4b3 (diff)
Improved texture atlas size estimation in Nuklear
Diffstat (limited to 'nuklear_ui')
-rw-r--r--nuklear_ui/nuklear.h13
-rw-r--r--nuklear_ui/nuklear_sdl_gles2.h5
2 files changed, 16 insertions, 2 deletions
diff --git a/nuklear_ui/nuklear.h b/nuklear_ui/nuklear.h
index 4347f45..b28008c 100644
--- a/nuklear_ui/nuklear.h
+++ b/nuklear_ui/nuklear.h
@@ -11368,10 +11368,13 @@ nk_font_bake_pack(struct nk_font_baker *baker,
NK_ASSERT(alloc);
if (!image_memory || !width || !height || !config_list || !count) return nk_false;
+ int pixel_area_estimate = 0;
for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
range_count = nk_range_count(config_iter->range);
total_range_count += range_count;
- total_glyph_count += nk_range_glyph_count(config_iter->range, range_count);
+ int glyphs = nk_range_glyph_count(config_iter->range, range_count);
+ total_glyph_count += glyphs;
+ pixel_area_estimate += glyphs * config_iter->size * config_iter->size;
}
/* setup font baker from temporary memory */
@@ -11382,7 +11385,13 @@ nk_font_bake_pack(struct nk_font_baker *baker,
}
*height = 0;
- *width = (total_glyph_count > 1000) ? 1024 : 512;
+ int width_estimate = sqrt(pixel_area_estimate) + 0.5;
+ *width = 128;
+ while (*width < width_estimate)
+ {
+ *width *= 2;
+ }
+ //*width = (total_glyph_count > 1000) ? 1024 : 512;
nk_tt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc);
{
int input_i = 0;
diff --git a/nuklear_ui/nuklear_sdl_gles2.h b/nuklear_ui/nuklear_sdl_gles2.h
index 9dd3852..d7f2151 100644
--- a/nuklear_ui/nuklear_sdl_gles2.h
+++ b/nuklear_ui/nuklear_sdl_gles2.h
@@ -166,8 +166,13 @@ nk_sdl_device_upload_atlas(const void *image, int width, int height)
glBindTexture(GL_TEXTURE_2D, dev->font_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ printf("Creating texture atlas texture with size %dx%d\n", width, height);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image);
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR) {
+ printf("glTexImage2D failed with error %d\n", err);
+ }
}
NK_API void