diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-06-09 22:17:33 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-09 22:17:33 +0300 |
commit | a15180669891dcb4f0a4dff891e8a129b3788776 (patch) | |
tree | 3907a8c7a4dc3afc3289e57dba93e0fbf9514fd9 /source/blender/editors | |
parent | 10d57f991b06ae7c0a0b5e492eec8c7163debf80 (diff) | |
parent | d733826708f9b562687b78424e5c0835cba8c3c9 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/editors')
18 files changed, 401 insertions, 164 deletions
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 172f2b9069e..66b3a63c669 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -2035,7 +2035,7 @@ bool autokeyframe_cfra_can_key(Scene *scene, ID *id) else { /* Normal Mode (or treat as being normal mode): * - * Just in case the flags are't set properly (i.e. only on/off is set, without a mode) + * Just in case the flags aren't set properly (i.e. only on/off is set, without a mode) * let's set the "normal" flag too, so that it will all be sane everywhere... */ scene->toolsettings->autokey_mode = AUTOKEY_MODE_NORMAL; diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt index ebdf6bb43ff..2f5b2ab6e87 100644 --- a/source/blender/editors/curve/CMakeLists.txt +++ b/source/blender/editors/curve/CMakeLists.txt @@ -43,6 +43,7 @@ set(SRC editcurve_paint.c editcurve_select.c editfont.c + editfont_undo.c curve_intern.h ) diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 7c1fe0cadf0..053a7ee5023 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1794,64 +1794,6 @@ void FONT_OT_unlink(wmOperatorType *ot) ot->exec = font_unlink_exec; } - -/* **************** undo for font object ************** */ - -static void undoFont_to_editFont(void *strv, void *ecu, void *UNUSED(obdata)) -{ - Curve *cu = (Curve *)ecu; - EditFont *ef = cu->editfont; - const char *str = strv; - - ef->pos = *((const short *)str); - ef->len = *((const short *)(str + 2)); - - memcpy(ef->textbuf, str + 4, (ef->len + 1) * sizeof(wchar_t)); - memcpy(ef->textbufinfo, str + 4 + (ef->len + 1) * sizeof(wchar_t), ef->len * sizeof(CharInfo)); - - ef->selstart = ef->selend = 0; - -} - -static void *editFont_to_undoFont(void *ecu, void *UNUSED(obdata)) -{ - Curve *cu = (Curve *)ecu; - EditFont *ef = cu->editfont; - char *str; - - /* The undo buffer includes [MAXTEXT+6]=actual string and [MAXTEXT+4]*sizeof(CharInfo)=charinfo */ - str = MEM_callocN((MAXTEXT + 6) * sizeof(wchar_t) + (MAXTEXT + 4) * sizeof(CharInfo), "string undo"); - - /* Copy the string and string information */ - memcpy(str + 4, ef->textbuf, (ef->len + 1) * sizeof(wchar_t)); - memcpy(str + 4 + (ef->len + 1) * sizeof(wchar_t), ef->textbufinfo, ef->len * sizeof(CharInfo)); - - *((short *)(str + 0)) = ef->pos; - *((short *)(str + 2)) = ef->len; - - return str; -} - -static void free_undoFont(void *strv) -{ - MEM_freeN(strv); -} - -static void *get_undoFont(bContext *C) -{ - Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_FONT) { - return obedit->data; - } - return NULL; -} - -/* and this is all the undo system needs to know */ -void undo_push_font(bContext *C, const char *name) -{ - undo_editmode_push(C, name, get_undoFont, free_undoFont, undoFont_to_editFont, editFont_to_undoFont, NULL); -} - /** * TextBox selection */ diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c new file mode 100644 index 00000000000..a0453f9694d --- /dev/null +++ b/source/blender/editors/curve/editfont_undo.c @@ -0,0 +1,311 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/curve/editfont_undo.c + * \ingroup edcurve + */ + +#include <stdlib.h> +#include <string.h> +#include <wchar.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" + +#include "DNA_curve_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BKE_context.h" +#include "BKE_font.h" + +#include "ED_curve.h" +#include "ED_util.h" + +#define USE_ARRAY_STORE + +#ifdef USE_ARRAY_STORE +// # define DEBUG_PRINT +# include "BLI_array_store.h" +# include "BLI_array_store_utils.h" +# include "BLI_listbase.h" +# define ARRAY_CHUNK_SIZE 32 +#endif + +typedef struct UndoFont { + wchar_t *textbuf; + struct CharInfo *textbufinfo; + + int len, pos; + +#ifdef USE_ARRAY_STORE + struct { + BArrayState *textbuf; + BArrayState *textbufinfo; + } store; +#endif +} UndoFont; + + +#ifdef USE_ARRAY_STORE + +/** \name Array Store + * \{ */ + +static struct { + struct BArrayStore_AtSize bs_stride; + int users; + + /* We could have the undo API pass in the previous state, for now store a local list */ + ListBase local_links; + +} uf_arraystore = {NULL}; + +/** + * \param create: When false, only free the arrays. + * This is done since when reading from an undo state, they must be temporarily expanded. + * then discarded afterwards, having this argument avoids having 2x code paths. + */ +static void uf_arraystore_compact_ex( + UndoFont *uf, const UndoFont *uf_ref, + bool create) +{ +#define STATE_COMPACT(uf, id, len) \ + if ((uf)->id) { \ + BLI_assert(create == ((uf)->store.id == NULL)); \ + if (create) { \ + BArrayState *state_reference = uf_ref ? uf_ref->store.id : NULL; \ + const size_t stride = sizeof(*(uf)->id); \ + BArrayStore *bs = BLI_array_store_at_size_ensure(&uf_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE); \ + (uf)->store.id = BLI_array_store_state_add( \ + bs, (uf)->id, (size_t)(len) * stride, state_reference); \ + } \ + /* keep uf->len for validation */ \ + MEM_freeN((uf)->id); \ + (uf)->id = NULL; \ + } ((void)0) + + STATE_COMPACT(uf, textbuf, uf->len + 1); + STATE_COMPACT(uf, textbufinfo, uf->len + 1); + +#undef STATE_COMPACT + + if (create) { + uf_arraystore.users += 1; + } +} + +/** + * Move data from allocated arrays to de-duplicated states and clear arrays. + */ +static void uf_arraystore_compact(UndoFont *um, const UndoFont *uf_ref) +{ + uf_arraystore_compact_ex(um, uf_ref, true); +} + +static void uf_arraystore_compact_with_info(UndoFont *um, const UndoFont *uf_ref) +{ +#ifdef DEBUG_PRINT + size_t size_expanded_prev, size_compacted_prev; + BLI_array_store_at_size_calc_memory_usage(&uf_arraystore.bs_stride, &size_expanded_prev, &size_compacted_prev); +#endif + + uf_arraystore_compact(um, uf_ref); + +#ifdef DEBUG_PRINT + { + size_t size_expanded, size_compacted; + BLI_array_store_at_size_calc_memory_usage(&uf_arraystore.bs_stride, &size_expanded, &size_compacted); + + const double percent_total = size_expanded ? + (((double)size_compacted / (double)size_expanded) * 100.0) : -1.0; + + size_t size_expanded_step = size_expanded - size_expanded_prev; + size_t size_compacted_step = size_compacted - size_compacted_prev; + const double percent_step = size_expanded_step ? + (((double)size_compacted_step / (double)size_expanded_step) * 100.0) : -1.0; + + printf("overall memory use: %.8f%% of expanded size\n", percent_total); + printf("step memory use: %.8f%% of expanded size\n", percent_step); + } +#endif +} + +/** + * Remove data we only expanded for temporary use. + */ +static void uf_arraystore_expand_clear(UndoFont *um) +{ + uf_arraystore_compact_ex(um, NULL, false); +} + +static void uf_arraystore_expand(UndoFont *uf) +{ +#define STATE_EXPAND(uf, id, len) \ + if ((uf)->store.id) { \ + const size_t stride = sizeof(*(uf)->id); \ + BArrayState *state = (uf)->store.id; \ + size_t state_len; \ + (uf)->id = BLI_array_store_state_data_get_alloc(state, &state_len); \ + BLI_assert((len) == (state_len / stride)); \ + UNUSED_VARS_NDEBUG(stride); \ + } ((void)0) + + STATE_EXPAND(uf, textbuf, uf->len + 1); + STATE_EXPAND(uf, textbufinfo, uf->len + 1); + +#undef STATE_EXPAND +} + +static void uf_arraystore_free(UndoFont *uf) +{ +#define STATE_FREE(uf, id) \ + if ((uf)->store.id) { \ + const size_t stride = sizeof(*(uf)->id); \ + BArrayStore *bs = BLI_array_store_at_size_get(&uf_arraystore.bs_stride, stride); \ + BArrayState *state = (uf)->store.id; \ + BLI_array_store_state_remove(bs, state); \ + (uf)->store.id = NULL; \ + } ((void)0) + + STATE_FREE(uf, textbuf); + STATE_FREE(uf, textbufinfo); + +#undef STATE_FREE + + uf_arraystore.users -= 1; + + BLI_assert(uf_arraystore.users >= 0); + + if (uf_arraystore.users == 0) { +#ifdef DEBUG_PRINT + printf("editfont undo store: freeing all data!\n"); +#endif + + BLI_array_store_at_size_clear(&uf_arraystore.bs_stride); + } + +} + +/** \} */ + +#endif /* USE_ARRAY_STORE */ + +static void undoFont_to_editFont(void *uf_v, void *ecu, void *UNUSED(obdata)) +{ + Curve *cu = (Curve *)ecu; + EditFont *ef = cu->editfont; + const UndoFont *uf = uf_v; + + size_t final_size; + +#ifdef USE_ARRAY_STORE + uf_arraystore_expand(uf_v); +#endif + + final_size = sizeof(wchar_t) * (uf->len + 1); + memcpy(ef->textbuf, uf->textbuf, final_size); + + final_size = sizeof(CharInfo) * (uf->len + 1); + memcpy(ef->textbufinfo, uf->textbufinfo, final_size); + + ef->pos = uf->pos; + ef->len = uf->len; + + ef->selstart = ef->selend = 0; + +#ifdef USE_ARRAY_STORE + uf_arraystore_expand_clear(uf_v); +#endif +} + +static void *editFont_to_undoFont(void *ecu, void *UNUSED(obdata)) +{ + Curve *cu = (Curve *)ecu; + EditFont *ef = cu->editfont; + + UndoFont *uf = MEM_callocN(sizeof(*uf), __func__); + + size_t final_size; + + final_size = sizeof(wchar_t) * (ef->len + 1); + uf->textbuf = MEM_mallocN(final_size, __func__); + memcpy(uf->textbuf, ef->textbuf, final_size); + + final_size = sizeof(CharInfo) * (ef->len + 1); + uf->textbufinfo = MEM_mallocN(final_size, __func__); + memcpy(uf->textbufinfo, ef->textbufinfo, final_size); + + uf->pos = ef->pos; + uf->len = ef->len; + +#ifdef USE_ARRAY_STORE + { + const UndoFont *uf_ref = uf_arraystore.local_links.last ? + ((LinkData *)uf_arraystore.local_links.last)->data : NULL; + + /* add oursrlves */ + BLI_addtail(&uf_arraystore.local_links, BLI_genericNodeN(uf)); + + uf_arraystore_compact_with_info(uf, uf_ref); + } +#endif + + return uf; +} + +static void free_undoFont(void *uf_v) +{ + UndoFont *uf = uf_v; + +#ifdef USE_ARRAY_STORE + { + LinkData *link = BLI_findptr(&uf_arraystore.local_links, uf, offsetof(LinkData, data)); + BLI_remlink(&uf_arraystore.local_links, link); + MEM_freeN(link); + } + uf_arraystore_free(uf); +#endif + + if (uf->textbuf) { + MEM_freeN(uf->textbuf); + } + if (uf->textbufinfo) { + MEM_freeN(uf->textbufinfo); + } + + MEM_freeN(uf); +} + +static void *get_undoFont(bContext *C) +{ + Object *obedit = CTX_data_edit_object(C); + if (obedit && obedit->type == OB_FONT) { + return obedit->data; + } + return NULL; +} + +/* and this is all the undo system needs to know */ +void undo_push_font(bContext *C, const char *name) +{ + undo_editmode_push(C, name, get_undoFont, free_undoFont, undoFont_to_editFont, editFont_to_undoFont, NULL); +} diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index 0ac5c17a552..d3d2c465d46 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -94,6 +94,7 @@ void glutil_draw_filled_arc(float start, float angle, float radius, int nsegment * The param must cause only one value to be gotten from GL. */ float glaGetOneFloat(int param); +int glaGetOneInt(int param); /** * Functions like glRasterPos2i, except ensures that the resulting diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 05ac39b9879..eacf769270b 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -606,7 +606,7 @@ typedef enum eAnimUnitConv_Flags { ANIM_UNITCONV_SKIPKNOTS = (1 << 4), /* Scale FCurve i a way it fits to -1..1 space */ ANIM_UNITCONV_NORMALIZE = (1 << 5), - /* Only whennormalization is used: use scale factor from previous run, + /* Only when normalization is used: use scale factor from previous run, * prevents curves from jumping all over the place when tweaking them. */ ANIM_UNITCONV_NORMALIZE_FREEZE = (1 << 6), diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h index 278e3f97ba7..859d45e9c86 100644 --- a/source/blender/editors/include/ED_curve.h +++ b/source/blender/editors/include/ED_curve.h @@ -72,8 +72,7 @@ void ED_curve_deselect_all(struct EditNurb *editnurb); void ED_curve_select_all(struct EditNurb *editnurb); void ED_curve_select_swap(struct EditNurb *editnurb, bool hide_handles); -/* editfont.h */ -void undo_push_font(struct bContext *C, const char *name); +/* editfont.c */ void ED_curve_editfont_load(struct Object *obedit); void ED_curve_editfont_make(struct Object *obedit); void ED_curve_editfont_free(struct Object *obedit); @@ -89,6 +88,9 @@ bool ED_curve_active_center(struct Curve *cu, float center[3]); bool ED_curve_editfont_select_pick(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); +/* editfont_undo.c */ +void undo_push_font(struct bContext *C, const char *name); + #if 0 /* debug only */ void printknots(struct Object *obedit); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 5b8b8ae5bdb..ff4e11ac58b 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -8436,6 +8436,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *ar, uiListDyn *dyn_data; int retval = WM_UI_HANDLER_CONTINUE; int type = event->type, val = event->val; + bool redraw = false; int mx, my; ui_list = listbox->custom_data; @@ -8525,7 +8526,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *ar, ui_apply_but_undo(listbox); ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM; - ED_region_tag_redraw(ar); + redraw = true; } retval = WM_UI_HANDLER_BREAK; } @@ -8537,8 +8538,8 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *ar, ui_list->list_grip += (type == WHEELUPMOUSE) ? -1 : 1; ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM; - ED_region_tag_redraw(ar); + redraw = true; retval = WM_UI_HANDLER_BREAK; } else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE)) { @@ -8546,13 +8547,22 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *ar, /* list template will clamp */ ui_list->list_scroll += (type == WHEELUPMOUSE) ? -1 : 1; - ED_region_tag_redraw(ar); - + redraw = true; retval = WM_UI_HANDLER_BREAK; } } } + if (redraw) { + if (listbox->block->flag & UI_BLOCK_POPUP) { + /* popups need special refreshing */ + ED_region_tag_refresh_ui(ar); + } + else { + ED_region_tag_redraw(ar); + } + } + return retval; } @@ -9794,11 +9804,21 @@ static int ui_handle_menus_recursive( } else { uiBlock *block = menu->region->uiblocks.first; + uiBut *listbox = ui_list_find_mouse_over(menu->region, event); - if (block->flag & UI_BLOCK_RADIAL) + if (block->flag & UI_BLOCK_RADIAL) { retval = ui_pie_handler(C, event, menu); - else if (event->type == LEFTMOUSE || event->val != KM_DBL_CLICK) - retval = ui_handle_menu_event(C, event, menu, level, is_parent_inside, is_parent_menu, is_floating); + } + else if (event->type == LEFTMOUSE || event->val != KM_DBL_CLICK) { + if (listbox) { + retval = ui_handle_list_event(C, event, menu->region, listbox); + } + if (retval == WM_UI_HANDLER_CONTINUE) { + retval = ui_handle_menu_event( + C, event, menu, level, + is_parent_inside, is_parent_menu, is_floating); + } + } } } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index b7096583376..f1f9c4ef0cb 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2783,7 +2783,7 @@ static void uilist_prepare( layoutdata->end_idx = min_ii(layoutdata->start_idx + rows * columns, len); } -static void uilist_resize_update_cb(bContext *UNUSED(C), void *arg1, void *UNUSED(arg2)) +static void uilist_resize_update_cb(bContext *C, void *arg1, void *UNUSED(arg2)) { uiList *ui_list = arg1; uiListDyn *dyn_data = ui_list->dyn_data; @@ -2796,6 +2796,9 @@ static void uilist_resize_update_cb(bContext *UNUSED(C), void *arg1, void *UNUSE dyn_data->resize_prev += diff * UI_UNIT_Y; ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM; } + + /* In case uilist is in popup, we need special refreshing */ + ED_region_tag_refresh_ui(CTX_wm_menu(C)); } static void *uilist_item_use_dynamic_tooltip(PointerRNA *itemptr, const char *propname) diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index b9d3fd6c8be..8b16b2a977e 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -49,7 +49,7 @@ # endif # include "BLI_array_store.h" -# include "BLI_math_base.h" +# include "BLI_array_store_utils.h" /* check on best size later... */ # define ARRAY_CHUNK_SIZE 256 @@ -89,8 +89,7 @@ typedef struct UndoMesh { #ifdef USE_ARRAY_STORE /* NULL arrays are considered empty */ - struct { - /* most data is stored as 'custom' data */ + struct { /* most data is stored as 'custom' data */ BArrayCustomData *vdata, *edata, *ldata, *pdata; BArrayState **keyblocks; BArrayState *mselect; @@ -105,8 +104,7 @@ typedef struct UndoMesh { * \{ */ static struct { - BArrayStore **bs_all; - int bs_all_len; + struct BArrayStore_AtSize bs_stride; int users; /* We could have the undo API pass in the previous state, for now store a local list */ @@ -118,57 +116,6 @@ static struct { } um_arraystore = {NULL}; -static BArrayStore *array_store_at_size_ensure(const int stride) -{ - if (um_arraystore.bs_all_len < stride) { - um_arraystore.bs_all_len = stride; - um_arraystore.bs_all = MEM_recallocN(um_arraystore.bs_all, sizeof(*um_arraystore.bs_all) * stride); - } - BArrayStore **bs_p = &um_arraystore.bs_all[stride - 1]; - - if ((*bs_p) == NULL) { -#if 0 - unsigned int chunk_count = ARRAY_CHUNK_SIZE; -#else - /* calculate best chunk-count to fit a power of two */ - unsigned int chunk_count = ARRAY_CHUNK_SIZE; - { - unsigned int size = chunk_count * stride; - size = power_of_2_max_u(size); - size = MEM_SIZE_OPTIMAL(size); - chunk_count = size / stride; - } -#endif - - (*bs_p) = BLI_array_store_create(stride, chunk_count); - } - return *bs_p; -} - -static BArrayStore *array_store_at_size_get(const int stride) -{ - BLI_assert(stride > 0 && stride <= um_arraystore.bs_all_len); - return um_arraystore.bs_all[stride - 1]; -} - -#ifdef DEBUG_PRINT -static void um_arraystore_memory_usage(size_t *r_size_expanded, size_t *r_size_compacted) -{ - size_t size_compacted = 0; - size_t size_expanded = 0; - for (int i = 0; i < um_arraystore.bs_all_len; i++) { - BArrayStore *bs = um_arraystore.bs_all[i]; - if (bs) { - size_compacted += BLI_array_store_calc_size_compacted_get(bs); - size_expanded += BLI_array_store_calc_size_expanded_get(bs); - } - } - - *r_size_expanded = size_expanded; - *r_size_compacted = size_compacted; -} -#endif - static void um_arraystore_cd_compact( struct CustomData *cdata, const size_t data_len, bool create, @@ -194,7 +141,7 @@ static void um_arraystore_cd_compact( } const int stride = CustomData_sizeof(type); - BArrayStore *bs = create ? array_store_at_size_ensure(stride) : NULL; + BArrayStore *bs = create ? BLI_array_store_at_size_ensure(&um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE) : NULL; const int layer_len = layer_end - layer_start; if (create) { @@ -299,7 +246,7 @@ static void um_arraystore_cd_free(BArrayCustomData *bcd) while (bcd) { BArrayCustomData *bcd_next = bcd->next; const int stride = CustomData_sizeof(bcd->type); - BArrayStore *bs = array_store_at_size_get(stride); + BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride, stride); for (int i = 0; i < bcd->states_len; i++) { if (bcd->states[i]) { BLI_array_store_state_remove(bs, bcd->states[i]); @@ -328,7 +275,7 @@ static void um_arraystore_compact_ex( if (me->key && me->key->totkey) { const size_t stride = me->key->elemsize; - BArrayStore *bs = create ? array_store_at_size_ensure(stride) : NULL; + BArrayStore *bs = create ? BLI_array_store_at_size_ensure(&um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE) : NULL; if (create) { um->store.keyblocks = MEM_mallocN(me->key->totkey * sizeof(*um->store.keyblocks), __func__); } @@ -355,7 +302,7 @@ static void um_arraystore_compact_ex( if (create) { BArrayState *state_reference = um_ref ? um_ref->store.mselect : NULL; const size_t stride = sizeof(*me->mselect); - BArrayStore *bs = array_store_at_size_ensure(stride); + BArrayStore *bs = BLI_array_store_at_size_ensure(&um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE); um->store.mselect = BLI_array_store_state_add( bs, me->mselect, (size_t)me->totselect * stride, state_reference); } @@ -384,7 +331,7 @@ static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref { #ifdef DEBUG_PRINT size_t size_expanded_prev, size_compacted_prev; - um_arraystore_memory_usage(&size_expanded_prev, &size_compacted_prev); + BLI_array_store_at_size_calc_memory_usage(&um_arraystore.bs_stride, &size_expanded_prev, &size_compacted_prev); #endif #ifdef DEBUG_TIME @@ -400,7 +347,7 @@ static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref #ifdef DEBUG_PRINT { size_t size_expanded, size_compacted; - um_arraystore_memory_usage(&size_expanded, &size_compacted); + BLI_array_store_at_size_calc_memory_usage(&um_arraystore.bs_stride, &size_expanded, &size_compacted); const double percent_total = size_expanded ? (((double)size_compacted / (double)size_expanded) * 100.0) : -1.0; @@ -483,7 +430,7 @@ static void um_arraystore_free(UndoMesh *um) if (um->store.keyblocks) { const size_t stride = me->key->elemsize; - BArrayStore *bs = array_store_at_size_get(stride); + BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride, stride); for (int i = 0; i < me->key->totkey; i++) { BArrayState *state = um->store.keyblocks[i]; BLI_array_store_state_remove(bs, state); @@ -494,7 +441,7 @@ static void um_arraystore_free(UndoMesh *um) if (um->store.mselect) { const size_t stride = sizeof(*me->mselect); - BArrayStore *bs = array_store_at_size_get(stride); + BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride, stride); BArrayState *state = um->store.mselect; BLI_array_store_state_remove(bs, state); um->store.mselect = NULL; @@ -508,15 +455,7 @@ static void um_arraystore_free(UndoMesh *um) #ifdef DEBUG_PRINT printf("mesh undo store: freeing all data!\n"); #endif - for (int i = 0; i < um_arraystore.bs_all_len; i += 1) { - if (um_arraystore.bs_all[i]) { - BLI_array_store_destroy(um_arraystore.bs_all[i]); - } - } - - MEM_freeN(um_arraystore.bs_all); - um_arraystore.bs_all = NULL; - um_arraystore.bs_all_len = 0; + BLI_array_store_at_size_clear(&um_arraystore.bs_stride); #ifdef USE_ARRAY_STORE_THREAD BLI_task_pool_free(um_arraystore.task_pool); diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 014268262c4..93bac3f6660 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -327,6 +327,13 @@ float glaGetOneFloat(int param) return v; } +int glaGetOneInt(int param) +{ + GLint v; + glGetIntegerv(param, &v); + return v; +} + void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y) { GLubyte dummy = 0; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index d273f8320a1..e4c26064fec 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -202,7 +202,7 @@ typedef struct ProjPaintImage { */ typedef struct ProjStrokeHandle { /* Support for painting from multiple views at once, - * currently used to impliment summetry painting, + * currently used to impliment symmetry painting, * we can assume at least the first is set while painting. */ struct ProjPaintState *ps_views[8]; int ps_views_tot; @@ -717,7 +717,7 @@ static bool project_paint_PickColor( } /** - * Check if 'pt' is infront of the 3 verts on the Z axis (used for screenspace occlusuion test) + * Check if 'pt' is infront of the 3 verts on the Z axis (used for screenspace occlusion test) * \return * - `0`: no occlusion * - `-1`: no occlusion but 2D intersection is true diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 92be88bd5c6..fe80bba9f0b 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1322,7 +1322,7 @@ static bool do_weight_paint_normalize_all_locked( /** * \note same as function above except it does a second pass without active group - * if nomalize fails with it. + * if normalize fails with it. */ static void do_weight_paint_normalize_all_locked_try_active( MDeformVert *dvert, const int defbase_tot, const bool *vgroup_validmap, @@ -1339,7 +1339,7 @@ static void do_weight_paint_normalize_all_locked_try_active( * - With 1.0 weight painted into active: * nonzero locked weight; first pass zeroed out unlocked weight; scale 1 down to fit. * - With 0.0 weight painted into active: - * no unlocked groups; first pass did nothing; increaze 0 to fit. + * no unlocked groups; first pass did nothing; increase 0 to fit. */ do_weight_paint_normalize_all_locked(dvert, defbase_tot, vgroup_validmap, lock_flags); } diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index f4171221816..f1309de3726 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -983,10 +983,11 @@ static GLubyte bm_dot7[] = {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38}; static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone) { + /* call this once, avoid constant changing */ + BLI_assert(glaGetOneInt(GL_UNPACK_ALIGNMENT) == 1); + float length; - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (pchan) length = pchan->bone->length; else @@ -2692,6 +2693,11 @@ bool draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, if (v3d->flag2 & V3D_RENDER_OVERRIDE) return true; + /* needed for 'draw_line_bone' which draws pixel. */ + if (arm->drawtype == ARM_LINE) { + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + } + if (dt > OB_WIRE) { /* we use color for solid lighting */ if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) { @@ -2767,5 +2773,9 @@ bool draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, /* restore */ glFrontFace(GL_CCW); + if (arm->drawtype == ARM_LINE) { + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + } + return retval; } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 1c1068eff78..d8364011036 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -369,15 +369,18 @@ static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material } if (c_badtex) lit = 0; - if (lit != c_lit || ma != c_ma) { - if (lit) { - int options = GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR; + if (lit != c_lit || ma != c_ma || textured != c_textured) { + int options = GPU_SHADER_USE_COLOR; - if (gtexdraw.two_sided_lighting) - options |= GPU_SHADER_TWO_SIDED; - if (c_textured && !c_badtex) - options |= GPU_SHADER_TEXTURE_2D; + if (c_textured && !c_badtex) { + options |= GPU_SHADER_TEXTURE_2D; + } + if (gtexdraw.two_sided_lighting) { + options |= GPU_SHADER_TWO_SIDED; + } + if (lit) { + options |= GPU_SHADER_LIGHTING; if (!ma) ma = give_current_material_or_def(NULL, 0); /* default material */ @@ -385,12 +388,10 @@ static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material mul_v3_v3fl(specular, &ma->specr, ma->spec); GPU_basic_shader_colors(NULL, specular, ma->har, 1.0f); - GPU_basic_shader_bind(options); - } - else { - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); } + GPU_basic_shader_bind(options); + c_lit = lit; c_ma = ma; } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 48701ed1db6..1f0ea4eaf9b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -4907,7 +4907,7 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg * Get the world-space 3d location from a screen-space 2d point. * * \param mval: Input screen-space pixel location. - * \param mouse_worldloc: Output world-space loction. + * \param mouse_worldloc: Output world-space location. * \param fallback_depth_pt: Use this points depth when no depth can be found. */ bool ED_view3d_autodist( diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 5d49d1d9315..2fb92d73515 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -686,7 +686,7 @@ static void TRANSFORM_OT_tilt(struct wmOperatorType *ot) { /* identifiers */ ot->name = "Tilt"; - /* optionals - + /* optional - * "Tilt selected vertices" * "Specify an extra axis rotation for selected vertices of 3D curve" */ ot->description = "Tilt selected control vertices of 3D curve"; diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index b11a2d5d01e..d706c574d1f 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -198,7 +198,7 @@ static void raycast_all_cb(void *userdata, int index, const BVHTreeRay *ray, BVH mul_m3_v3((float(*)[3])data->timat, normal); normalize_v3(normal); - /* currently unused, and causes issues when looptri's havn't been calculated. + /* currently unused, and causes issues when looptri's haven't been calculated. * since theres some overhead in ensuring this data is valid, it may need to be optional. */ #if 0 if (data->dm) { @@ -735,7 +735,7 @@ static bool snapDerivedMesh( if (bb) { BoundBox bb_temp; - /* We cannot aford a bbox with some null dimension, which may happen in some cases... + /* We cannot afford a bounding box with some null dimension, which may happen in some cases... * Threshold is rather high, but seems to be needed to get good behavior, see T46099. */ bb = BKE_boundbox_ensure_minimum_dimensions(bb, &bb_temp, 1e-1f); |