- Notifications
You must be signed in to change notification settings - Fork 650
stb_truetype memory management through the nk_font_atlas allocator #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stb_truetype memory management through the nk_font_atlas allocator #186
Conversation
| #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) | ||
| #endif | ||
| | ||
| #ifdef NK_IMPLEMENTATION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is rebuilt with paq.sh.
| @@ -1,3 +1,3 @@ | |||
| #!/bin/sh | |||
| python build.py --macro NK --intro HEADER --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS | |||
| python build.py --macro NK --intro HEADER --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ../nuklear.h | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added redirect to prebuilt nuklear.h file, as in paq.bat.
| #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) | ||
| #endif | ||
| | ||
| #ifdef NK_IMPLEMENTATION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from here into src/nuklear_internal.h.
These are internal implementation details that do not need to be exposed.
| for (config_iter = config_list; config_iter; config_iter = config_iter->next) { | ||
| it = config_iter; | ||
| do {if (!stbtt_InitFont(&baker->build[i++].info, (const unsigned char*)it->ttf_blob, 0)) | ||
| struct stbtt_fontinfo *font_info = &baker->build[i++].info; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stb_truetype passes the userdata field of stbtt_fontinfo as the second argument to STBTT_malloc/STBTT_free.
Set the userdata here to point to the allocator (alloc), and use it in the custom implementations of STBTT_malloc/STBTT_free.
| NK_LIB void nk_do_property(nk_flags *ws, struct nk_command_buffer *out, struct nk_rect property, const char *name, struct nk_property_variant *variant, float inc_per_pixel, char *buffer, int *len, int *state, int *cursor, int *select_begin, int *select_end, const struct nk_style_property *style, enum nk_property_filter filter, struct nk_input *in, const struct nk_user_font *font, struct nk_text_edit *text_edit, enum nk_button_behavior behavior); | ||
| NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant *variant, float inc_per_pixel, const enum nk_property_filter filter); | ||
| | ||
| #ifdef NK_INCLUDE_FONT_BAKING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved here from src/nuklear_internal.h.
These are internal implementation details that do not need to be exposed.
| @dumblob could you please take a look at this PR? |
| @2asoft sorry for the delay. Yeah, I've looked at it and technically it LGTM. Please take a look at https://github.com/Immediate-Mode-UI/Nuklear#reviewers-guide to add some more bits to have this PR accepted 😉 (e.g. version bump), thanks! |
…by default And allow the consumer to customize by redefining STBTT_malloc/STBTT_free
488deb4 to d30e07f Compare | Thanks. I updated the version, and as far as I can tell all the recommendations in the guide are covered. |
| Thanks for patience and great feedback! Btw. would you want to get commit permissions to the repo? It's basically only about reviews (essentially the things from the Reviewer's guide). As you see, there are only very few reviewers currently and the library development is very slow which is a pity, but we can't afford more time. |
| I'll gladly take the commit bit, but I can't devote a large amount of time to Nuklear at the moment. |
| @2asoft invitation sent out 😉. Just follow the reviewers guidelines (especially the point "at least two reviewers (both different from the PR author) shall approve |
| Btw. as you noticed we sometimes break these guidelines, despite we always try hard to stick with them (otherwise issues like #198 tend to appear). |
| @2asoft I'm glad you managed - so welcome to our organization 😉! |
After the tremendous work done to update stb_truetype to a newer version, Nuklear lost the ability to control stb_truetype's memory management via Nuklear's allocators, instead delegating it to the default (
malloc/free) allocation scheme.In cases where Nuklear is compiled without the default allocation scheme, the entire library would fail to build.
More details in this comment.
This PR implements stb_truetype
STBTT_malloc/STBTT_freeto delegate to thenk_allocatorused bynk_font_atlas.It also leaves the ability for the consumer to define own
STBTT_malloc/STBTT_freeimplementations if they so desire.