From 807aefd6234f7349d1bef2579def24c8bba9f31f Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Thu, 6 Feb 2020 10:23:55 +0100 Subject: Fix (unreported) timeline missing refresh on VSE selection change Keyframes and channels were not updating immediately (you had to enter channel and main regions with the mouse to force a redraw). Differential Revision: https://developer.blender.org/D6762 --- source/blender/editors/space_action/space_action.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source') diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c index 901efbdf0ff..f06b1a02675 100644 --- a/source/blender/editors/space_action/space_action.c +++ b/source/blender/editors/space_action/space_action.c @@ -546,6 +546,12 @@ static void action_listener(wmWindow *UNUSED(win), break; case NC_SCENE: switch (wmn->data) { + case ND_SEQUENCER: + if (wmn->action == NA_SELECTED) { + saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC; + ED_area_tag_refresh(sa); + } + break; case ND_OB_ACTIVE: case ND_OB_SELECT: /* Selection changed, so force refresh to flush -- cgit v1.2.3 From b088d1e9969d440ffb7cc9614cef0ca81da46433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= Date: Thu, 6 Feb 2020 15:56:02 +0100 Subject: Particle: Added sanity in particle system removal function Added a NULL check since psys_get_modifier() might also return a NULL pointer. --- source/blender/blenkernel/intern/particle.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 97fcef4fd27..eafd530b0d8 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3638,12 +3638,14 @@ void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob } } - /* clear modifier */ + /* Clear modifier, skip empty ones. */ psmd = psys_get_modifier(ob, psys); - BLI_remlink(&ob->modifiers, psmd); - modifier_free((ModifierData *)psmd); + if (psmd) { + BLI_remlink(&ob->modifiers, psmd); + modifier_free((ModifierData *)psmd); + } - /* clear particle system */ + /* Clear particle system. */ BLI_remlink(&ob->particlesystem, psys); if (psys->part) { id_us_min(&psys->part->id); -- cgit v1.2.3 From e7d71ce9cf1eb8ea73d5d77527fc65e7bd6f5d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= Date: Thu, 6 Feb 2020 16:53:00 +0100 Subject: Fluid: Fixed slow cache loading for smoke data Cache files are currently loaded via the Manta Python API. With very big caches this can slow down the viewport playback. Especially smoke simulations, which just load grids and no meshes, can suffer from this. This fix solves this problem by directly loading the cache files from disk (no Python). This fix has been in the works for some time. The developer of this patch is ready to handle any potential fall-out of this patch quickly. --- source/blender/blenkernel/intern/fluid.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index f35aebbae16..8b959e30aff 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -3505,10 +3505,14 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, manta_needs_realloc(mds->fluid, mmd)) { BKE_fluid_reallocate_fluid(mds, mds->res, 1); } - has_noise = manta_read_noise(mds->fluid, mmd, noise_frame); + if (!baking_data && !baking_noise && !mode_replay) { + has_data = manta_update_noise_structures(mds->fluid, mmd, noise_frame); + } + else { + has_noise = manta_read_noise(mds->fluid, mmd, noise_frame); + } - /* In case of using the adaptive domain, copy all data that was read to a new fluid object. - */ + /* When using the adaptive domain, copy all data that was read to a new fluid object. */ if (with_adaptive && baking_noise) { /* Adaptive domain needs to know about current state, so save it, then copy. */ copy_v3_v3_int(o_res, mds->res); @@ -3521,7 +3525,13 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, mds, o_res, mds->res, o_min, mds->res_min, o_max, o_shift, mds->shift); } } - has_data = manta_read_data(mds->fluid, mmd, data_frame); + if (!baking_data && !baking_noise && !mode_replay) { + /* There is no need to call manta_update_smoke_structures() here. + * The noise cache has already been read with manta_update_noise_structures(). */ + } + else { + has_data = manta_read_data(mds->fluid, mmd, data_frame); + } } /* Read data cache only */ else { @@ -3532,7 +3542,12 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, BKE_fluid_reallocate_fluid(mds, mds->res, 1); } /* Read data cache */ - has_data = manta_read_data(mds->fluid, mmd, data_frame); + if (!baking_data && !baking_particles && !baking_mesh && !mode_replay) { + has_data = manta_update_smoke_structures(mds->fluid, mmd, data_frame); + } + else { + has_data = manta_read_data(mds->fluid, mmd, data_frame); + } } if (with_liquid) { if (!baking_data && !baking_particles && !baking_mesh && !mode_replay) { -- cgit v1.2.3 From 921d74dd365661c52dd91dd12d29314ffd9f26ab Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 6 Feb 2020 16:24:19 +0100 Subject: NodeTree: Add access to the address of an ID's nodetree pointer. --- source/blender/blenkernel/BKE_node.h | 3 ++- source/blender/blenkernel/intern/node.c | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index b599e1e1b2c..1c479c92ef5 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -387,7 +387,8 @@ struct bNodeTree *ntreeCopyTree(struct Main *bmain, const struct bNodeTree *ntre void ntreeUserIncrefID(struct bNodeTree *ntree); void ntreeUserDecrefID(struct bNodeTree *ntree); -struct bNodeTree *ntreeFromID(const struct ID *id); +struct bNodeTree **BKE_ntree_ptr_from_id(struct ID *id); +struct bNodeTree *ntreeFromID(struct ID *id); struct ID *BKE_node_tree_find_owner_ID(struct Main *bmain, struct bNodeTree *ntree); void ntreeMakeLocal(struct Main *bmain, diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 75e0d044c7c..94c06e46cb9 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -2242,27 +2242,37 @@ void ntreeSetOutput(bNodeTree *ntree) * might be different for editor or for "real" use... */ } -/* Returns the private NodeTree object of the datablock, if it has one. */ -bNodeTree *ntreeFromID(const ID *id) +/** Get address of potential nodetree pointer of given ID. + * + * \warning Using this function directly is potentially dangerous, if you don't know or are not + * sure, please use `ntreeFromID()` instead. */ +bNodeTree **BKE_ntree_ptr_from_id(ID *id) { switch (GS(id->name)) { case ID_MA: - return ((const Material *)id)->nodetree; + return &((Material *)id)->nodetree; case ID_LA: - return ((const Light *)id)->nodetree; + return &((Light *)id)->nodetree; case ID_WO: - return ((const World *)id)->nodetree; + return &((World *)id)->nodetree; case ID_TE: - return ((const Tex *)id)->nodetree; + return &((Tex *)id)->nodetree; case ID_SCE: - return ((const Scene *)id)->nodetree; + return &((Scene *)id)->nodetree; case ID_LS: - return ((const FreestyleLineStyle *)id)->nodetree; + return &((FreestyleLineStyle *)id)->nodetree; default: return NULL; } } +/* Returns the private NodeTree object of the datablock, if it has one. */ +bNodeTree *ntreeFromID(ID *id) +{ + bNodeTree **nodetree = BKE_ntree_ptr_from_id(id); + return (nodetree != NULL) ? *nodetree : NULL; +} + /* Finds and returns the datablock that privately owns the given tree, or NULL. */ ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree) { -- cgit v1.2.3 From 7954e672c555037733b4ac298d558155d1862055 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 6 Feb 2020 16:25:15 +0100 Subject: Readfile: refactor/factorize more handling of common ID data. - Move handling of private ID data (nodetree and master_collection) under generic ID code. This shortens code a bit, but mostly avoids having to modify all type-specific callback functions if/when we have to add generic processing to IDs there. - Seriously factorize `expand_xxx` area, in the same way we were already doing in `direct_link_xxx` and `lib_link_xxx` areas. Note that this actually also fixes some bugs (at least, potential ones), like e.g. missing call to expand_id() for our beloved 'private ID' (nodetrees & co), in current master code... Differential Revision: https://developer.blender.org/D6764 --- source/blender/blenloader/intern/readfile.c | 422 +++++++++++----------------- 1 file changed, 161 insertions(+), 261 deletions(-) (limited to 'source') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 651f390d23e..c1a39711bf8 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2613,7 +2613,29 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p /** \name Read ID * \{ */ -static void lib_link_id(FileData *fd, Main *UNUSED(bmain), ID *id) +static void lib_link_id(FileData *fd, Main *bmain, ID *id); +static void lib_link_nodetree(FileData *fd, Main *bmain, bNodeTree *ntree); +static void lib_link_collection(FileData *fd, Main *bmain, Collection *collection); + +static void lib_link_id_private_id(FileData *fd, Main *bmain, ID *id) +{ + /* Handle 'private IDs'. */ + bNodeTree *nodetree = ntreeFromID(id); + if (nodetree != NULL) { + lib_link_id(fd, bmain, &nodetree->id); + lib_link_nodetree(fd, bmain, nodetree); + } + + if (GS(id->name) == ID_SCE) { + Scene *scene = (Scene *)id; + if (scene->master_collection != NULL) { + lib_link_id(fd, bmain, &scene->master_collection->id); + lib_link_collection(fd, bmain, scene->master_collection); + } + } +} + +static void lib_link_id(FileData *fd, Main *bmain, ID *id) { /* Note: WM IDProperties are never written to file, hence they should always be NULL here. */ BLI_assert((GS(id->name) != ID_WM) || id->properties == NULL); @@ -2628,6 +2650,8 @@ static void lib_link_id(FileData *fd, Main *UNUSED(bmain), ID *id) id->override_library->reference = newlibadr_us(fd, id->lib, id->override_library->reference); id->override_library->storage = newlibadr_us(fd, id->lib, id->override_library->storage); } + + lib_link_id_private_id(fd, bmain, id); } static void direct_link_id_override_property_operation_cb(FileData *fd, void *data) @@ -2646,6 +2670,30 @@ static void direct_link_id_override_property_cb(FileData *fd, void *data) link_list_ex(fd, &op->operations, direct_link_id_override_property_operation_cb); } +static void direct_link_id(FileData *fd, ID *id); +static void direct_link_nodetree(FileData *fd, bNodeTree *ntree); +static void direct_link_collection(FileData *fd, Collection *collection); + +static void direct_link_id_private_id(FileData *fd, ID *id) +{ + /* Handle 'private IDs'. */ + bNodeTree **nodetree = BKE_ntree_ptr_from_id(id); + if (nodetree != NULL && *nodetree != NULL) { + *nodetree = newdataadr(fd, *nodetree); + direct_link_id(fd, (ID *)*nodetree); + direct_link_nodetree(fd, *nodetree); + } + + if (GS(id->name) == ID_SCE) { + Scene *scene = (Scene *)id; + if (scene->master_collection != NULL) { + scene->master_collection = newdataadr(fd, scene->master_collection); + direct_link_id(fd, &scene->master_collection->id); + direct_link_collection(fd, scene->master_collection); + } + } +} + static void direct_link_id(FileData *fd, ID *id) { /*link direct data of ID properties*/ @@ -2685,6 +2733,9 @@ static void direct_link_id(FileData *fd, ID *id) if (drawdata) { BLI_listbase_clear((ListBase *)drawdata); } + + /* Handle 'private IDs'. */ + direct_link_id_private_id(fd, id); } /** \} */ @@ -3874,14 +3925,9 @@ static void direct_link_camera(FileData *fd, Camera *ca) /** \name Read ID: Light * \{ */ -static void lib_link_light(FileData *fd, Main *bmain, Light *la) +static void lib_link_light(FileData *fd, Main *UNUSED(bmain), Light *la) { la->ipo = newlibadr_us(fd, la->id.lib, la->ipo); // XXX deprecated - old animation system - - if (la->nodetree) { - lib_link_id(fd, bmain, &la->nodetree->id); - lib_link_ntree(fd, la->id.lib, la->nodetree); - } } static void direct_link_light(FileData *fd, Light *la) @@ -3894,12 +3940,6 @@ static void direct_link_light(FileData *fd, Light *la) direct_link_curvemapping(fd, la->curfalloff); } - la->nodetree = newdataadr(fd, la->nodetree); - if (la->nodetree) { - direct_link_id(fd, &la->nodetree->id); - direct_link_nodetree(fd, la->nodetree); - } - la->preview = direct_link_preview_image(fd, la->preview); } @@ -4016,14 +4056,9 @@ static void direct_link_mball(FileData *fd, MetaBall *mb) /** \name Read ID: World * \{ */ -static void lib_link_world(FileData *fd, Main *bmain, World *wrld) +static void lib_link_world(FileData *fd, Main *UNUSED(bmain), World *wrld) { wrld->ipo = newlibadr_us(fd, wrld->id.lib, wrld->ipo); // XXX deprecated - old animation system - - if (wrld->nodetree) { - lib_link_id(fd, bmain, &wrld->nodetree->id); - lib_link_ntree(fd, wrld->id.lib, wrld->nodetree); - } } static void direct_link_world(FileData *fd, World *wrld) @@ -4031,12 +4066,6 @@ static void direct_link_world(FileData *fd, World *wrld) wrld->adt = newdataadr(fd, wrld->adt); direct_link_animdata(fd, wrld->adt); - wrld->nodetree = newdataadr(fd, wrld->nodetree); - if (wrld->nodetree) { - direct_link_id(fd, &wrld->nodetree->id); - direct_link_nodetree(fd, wrld->nodetree); - } - wrld->preview = direct_link_preview_image(fd, wrld->preview); BLI_listbase_clear(&wrld->gpumaterial); } @@ -4278,15 +4307,10 @@ static void direct_link_curve(FileData *fd, Curve *cu) /** \name Read ID: Texture * \{ */ -static void lib_link_texture(FileData *fd, Main *bmain, Tex *tex) +static void lib_link_texture(FileData *fd, Main *UNUSED(bmain), Tex *tex) { tex->ima = newlibadr_us(fd, tex->id.lib, tex->ima); tex->ipo = newlibadr_us(fd, tex->id.lib, tex->ipo); // XXX deprecated - old animation system - - if (tex->nodetree) { - lib_link_id(fd, bmain, &tex->nodetree->id); - lib_link_ntree(fd, tex->id.lib, tex->nodetree); - } } static void direct_link_texture(FileData *fd, Tex *tex) @@ -4296,12 +4320,6 @@ static void direct_link_texture(FileData *fd, Tex *tex) tex->coba = newdataadr(fd, tex->coba); - tex->nodetree = newdataadr(fd, tex->nodetree); - if (tex->nodetree) { - direct_link_id(fd, &tex->nodetree->id); - direct_link_nodetree(fd, tex->nodetree); - } - tex->preview = direct_link_preview_image(fd, tex->preview); tex->iuser.ok = 1; @@ -4314,15 +4332,10 @@ static void direct_link_texture(FileData *fd, Tex *tex) /** \name Read ID: Material * \{ */ -static void lib_link_material(FileData *fd, Main *bmain, Material *ma) +static void lib_link_material(FileData *fd, Main *UNUSED(bmain), Material *ma) { ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo); // XXX deprecated - old animation system - if (ma->nodetree) { - lib_link_id(fd, bmain, &ma->nodetree->id); - lib_link_ntree(fd, ma->id.lib, ma->nodetree); - } - /* relink grease pencil settings */ if (ma->gp_style != NULL) { MaterialGPencilStyle *gp_style = ma->gp_style; @@ -4342,12 +4355,6 @@ static void direct_link_material(FileData *fd, Material *ma) ma->texpaintslot = NULL; - ma->nodetree = newdataadr(fd, ma->nodetree); - if (ma->nodetree) { - direct_link_id(fd, &ma->nodetree->id); - direct_link_nodetree(fd, ma->nodetree); - } - ma->preview = direct_link_preview_image(fd, ma->preview); BLI_listbase_clear(&ma->gpumaterial); @@ -6325,7 +6332,7 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene) } #endif -static void lib_link_scene(FileData *fd, Main *bmain, Scene *sce) +static void lib_link_scene(FileData *fd, Main *UNUSED(bmain), Scene *sce) { lib_link_keyingsets(fd, &sce->id, &sce->keyingsets); @@ -6459,8 +6466,6 @@ static void lib_link_scene(FileData *fd, Main *bmain, Scene *sce) } if (sce->nodetree) { - lib_link_id(fd, bmain, &sce->nodetree->id); - lib_link_ntree(fd, sce->id.lib, sce->nodetree); composite_patch(sce->nodetree, sce); } @@ -6483,11 +6488,6 @@ static void lib_link_scene(FileData *fd, Main *bmain, Scene *sce) } #endif - if (sce->master_collection) { - lib_link_id(fd, bmain, &sce->master_collection->id); - lib_link_collection_data(fd, sce->id.lib, sce->master_collection); - } - for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { lib_link_view_layer(fd, sce->id.lib, view_layer); } @@ -6817,12 +6817,6 @@ static void direct_link_scene(FileData *fd, Scene *sce) link_list(fd, &(srl->freestyleConfig.linesets)); } - sce->nodetree = newdataadr(fd, sce->nodetree); - if (sce->nodetree) { - direct_link_id(fd, &sce->nodetree->id); - direct_link_nodetree(fd, sce->nodetree); - } - direct_link_view_settings(fd, &sce->view_settings); sce->rigidbody_world = newdataadr(fd, sce->rigidbody_world); @@ -6878,13 +6872,6 @@ static void direct_link_scene(FileData *fd, Scene *sce) } #endif - if (sce->master_collection) { - sce->master_collection = newdataadr(fd, sce->master_collection); - /* Needed because this is an ID outside of Main. */ - direct_link_id(fd, &sce->master_collection->id); - direct_link_collection(fd, sce->master_collection); - } - /* insert into global old-new map for reading without UI (link_global accesses it again) */ link_glob_list(fd, &sce->view_layers); for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { @@ -8576,7 +8563,7 @@ static void lib_link_mask(FileData *fd, Main *UNUSED(bmain), Mask *mask) /** \name Read ID: Line Style * \{ */ -static void lib_link_linestyle(FileData *fd, Main *bmain, FreestyleLineStyle *linestyle) +static void lib_link_linestyle(FileData *fd, Main *UNUSED(bmain), FreestyleLineStyle *linestyle) { LineStyleModifier *m; @@ -8617,10 +8604,6 @@ static void lib_link_linestyle(FileData *fd, Main *bmain, FreestyleLineStyle *li mtex->object = newlibadr(fd, linestyle->id.lib, mtex->object); } } - if (linestyle->nodetree) { - lib_link_id(fd, bmain, &linestyle->nodetree->id); - lib_link_ntree(fd, linestyle->id.lib, linestyle->nodetree); - } } static void direct_link_linestyle_color_modifier(FileData *fd, LineStyleModifier *modifier) @@ -8811,11 +8794,6 @@ static void direct_link_linestyle(FileData *fd, FreestyleLineStyle *linestyle) for (a = 0; a < MAX_MTEX; a++) { linestyle->mtex[a] = newdataadr(fd, linestyle->mtex[a]); } - linestyle->nodetree = newdataadr(fd, linestyle->nodetree); - if (linestyle->nodetree) { - direct_link_id(fd, &linestyle->nodetree->id); - direct_link_nodetree(fd, linestyle->nodetree); - } } /** \} */ @@ -10104,39 +10082,6 @@ static void expand_constraint_channels(FileData *fd, Main *mainvar, ListBase *ch } } -static void expand_id(FileData *fd, Main *mainvar, ID *id) -{ - if (id->override_library) { - expand_doit(fd, mainvar, id->override_library->reference); - expand_doit(fd, mainvar, id->override_library->storage); - } -} - -static void expand_idprops(FileData *fd, Main *mainvar, IDProperty *prop) -{ - if (!prop) { - return; - } - - switch (prop->type) { - case IDP_ID: - expand_doit(fd, mainvar, IDP_Id(prop)); - break; - case IDP_IDPARRAY: { - IDProperty *idp_array = IDP_IDPArray(prop); - for (int i = 0; i < prop->len; i++) { - expand_idprops(fd, mainvar, &idp_array[i]); - } - break; - } - case IDP_GROUP: - for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) { - expand_idprops(fd, mainvar, loop); - } - break; - } -} - static void expand_fmodifiers(FileData *fd, Main *mainvar, ListBase *list) { FModifier *fcm; @@ -10179,40 +10124,6 @@ static void expand_fcurves(FileData *fd, Main *mainvar, ListBase *list) } } -static void expand_action(FileData *fd, Main *mainvar, bAction *act) -{ - bActionChannel *chan; - - // XXX deprecated - old animation system -------------- - for (chan = act->chanbase.first; chan; chan = chan->next) { - expand_doit(fd, mainvar, chan->ipo); - expand_constraint_channels(fd, mainvar, &chan->constraintChannels); - } - // --------------------------------------------------- - - /* F-Curves in Action */ - expand_fcurves(fd, mainvar, &act->curves); - - for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { - if (marker->camera) { - expand_doit(fd, mainvar, marker->camera); - } - } -} - -static void expand_keyingsets(FileData *fd, Main *mainvar, ListBase *list) -{ - KeyingSet *ks; - KS_Path *ksp; - - /* expand the ID-pointers in KeyingSets's paths */ - for (ks = list->first; ks; ks = ks->next) { - for (ksp = ks->paths.first; ksp; ksp = ksp->next) { - expand_doit(fd, mainvar, ksp->id); - } - } -} - static void expand_animdata_nlastrips(FileData *fd, Main *mainvar, ListBase *list) { NlaStrip *strip; @@ -10249,6 +10160,104 @@ static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt) } } +static void expand_idprops(FileData *fd, Main *mainvar, IDProperty *prop) +{ + if (!prop) { + return; + } + + switch (prop->type) { + case IDP_ID: + expand_doit(fd, mainvar, IDP_Id(prop)); + break; + case IDP_IDPARRAY: { + IDProperty *idp_array = IDP_IDPArray(prop); + for (int i = 0; i < prop->len; i++) { + expand_idprops(fd, mainvar, &idp_array[i]); + } + break; + } + case IDP_GROUP: + for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) { + expand_idprops(fd, mainvar, loop); + } + break; + } +} + +static void expand_id(FileData *fd, Main *mainvar, ID *id); +static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree); +static void expand_collection(FileData *fd, Main *mainvar, Collection *collection); + +static void expand_id_private_id(FileData *fd, Main *mainvar, ID *id) +{ + /* Handle 'private IDs'. */ + bNodeTree *nodetree = ntreeFromID(id); + if (nodetree != NULL) { + expand_id(fd, mainvar, id); + expand_nodetree(fd, mainvar, nodetree); + } + + if (GS(id->name) == ID_SCE) { + Scene *scene = (Scene *)id; + if (scene->master_collection != NULL) { + expand_id(fd, mainvar, id); + expand_collection(fd, mainvar, scene->master_collection); + } + } +} + +static void expand_id(FileData *fd, Main *mainvar, ID *id) +{ + expand_idprops(fd, mainvar, id->properties); + + if (id->override_library) { + expand_doit(fd, mainvar, id->override_library->reference); + expand_doit(fd, mainvar, id->override_library->storage); + } + + AnimData *adt = BKE_animdata_from_id(id); + if (adt != NULL) { + expand_animdata(fd, mainvar, adt); + } + + expand_id_private_id(fd, mainvar, id); +} + +static void expand_action(FileData *fd, Main *mainvar, bAction *act) +{ + bActionChannel *chan; + + // XXX deprecated - old animation system -------------- + for (chan = act->chanbase.first; chan; chan = chan->next) { + expand_doit(fd, mainvar, chan->ipo); + expand_constraint_channels(fd, mainvar, &chan->constraintChannels); + } + // --------------------------------------------------- + + /* F-Curves in Action */ + expand_fcurves(fd, mainvar, &act->curves); + + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + if (marker->camera) { + expand_doit(fd, mainvar, marker->camera); + } + } +} + +static void expand_keyingsets(FileData *fd, Main *mainvar, ListBase *list) +{ + KeyingSet *ks; + KS_Path *ksp; + + /* expand the ID-pointers in KeyingSets's paths */ + for (ks = list->first; ks; ks = ks->next) { + for (ksp = ks->paths.first; ksp; ksp = ksp->next) { + expand_doit(fd, mainvar, ksp->id); + } + } +} + static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSettings *part) { int a; @@ -10259,10 +10268,6 @@ static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSetting expand_doit(fd, mainvar, part->bb_ob); expand_doit(fd, mainvar, part->collision_group); - if (part->adt) { - expand_animdata(fd, mainvar, part->adt); - } - for (a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { expand_doit(fd, mainvar, part->mtex[a]->tex); @@ -10326,10 +10331,6 @@ static void expand_collection(FileData *fd, Main *mainvar, Collection *collectio static void expand_key(FileData *fd, Main *mainvar, Key *key) { expand_doit(fd, mainvar, key->ipo); // XXX deprecated - old animation system - - if (key->adt) { - expand_animdata(fd, mainvar, key->adt); - } } static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree) @@ -10337,10 +10338,6 @@ static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree) bNode *node; bNodeSocket *sock; - if (ntree->adt) { - expand_animdata(fd, mainvar, ntree->adt); - } - if (ntree->gpd) { expand_doit(fd, mainvar, ntree->gpd); } @@ -10372,14 +10369,6 @@ static void expand_texture(FileData *fd, Main *mainvar, Tex *tex) { expand_doit(fd, mainvar, tex->ima); expand_doit(fd, mainvar, tex->ipo); // XXX deprecated - old animation system - - if (tex->adt) { - expand_animdata(fd, mainvar, tex->adt); - } - - if (tex->nodetree) { - expand_nodetree(fd, mainvar, tex->nodetree); - } } static void expand_brush(FileData *fd, Main *mainvar, Brush *brush) @@ -10397,14 +10386,6 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma) { expand_doit(fd, mainvar, ma->ipo); // XXX deprecated - old animation system - if (ma->adt) { - expand_animdata(fd, mainvar, ma->adt); - } - - if (ma->nodetree) { - expand_nodetree(fd, mainvar, ma->nodetree); - } - if (ma->gp_style) { MaterialGPencilStyle *gp_style = ma->gp_style; expand_doit(fd, mainvar, gp_style->sima); @@ -10415,37 +10396,17 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma) static void expand_light(FileData *fd, Main *mainvar, Light *la) { expand_doit(fd, mainvar, la->ipo); // XXX deprecated - old animation system - - if (la->adt) { - expand_animdata(fd, mainvar, la->adt); - } - - if (la->nodetree) { - expand_nodetree(fd, mainvar, la->nodetree); - } } static void expand_lattice(FileData *fd, Main *mainvar, Lattice *lt) { expand_doit(fd, mainvar, lt->ipo); // XXX deprecated - old animation system expand_doit(fd, mainvar, lt->key); - - if (lt->adt) { - expand_animdata(fd, mainvar, lt->adt); - } } static void expand_world(FileData *fd, Main *mainvar, World *wrld) { expand_doit(fd, mainvar, wrld->ipo); // XXX deprecated - old animation system - - if (wrld->adt) { - expand_animdata(fd, mainvar, wrld->adt); - } - - if (wrld->nodetree) { - expand_nodetree(fd, mainvar, wrld->nodetree); - } } static void expand_mball(FileData *fd, Main *mainvar, MetaBall *mb) @@ -10455,10 +10416,6 @@ static void expand_mball(FileData *fd, Main *mainvar, MetaBall *mb) for (a = 0; a < mb->totcol; a++) { expand_doit(fd, mainvar, mb->mat[a]); } - - if (mb->adt) { - expand_animdata(fd, mainvar, mb->adt); - } } static void expand_curve(FileData *fd, Main *mainvar, Curve *cu) @@ -10478,20 +10435,12 @@ static void expand_curve(FileData *fd, Main *mainvar, Curve *cu) expand_doit(fd, mainvar, cu->bevobj); expand_doit(fd, mainvar, cu->taperobj); expand_doit(fd, mainvar, cu->textoncurve); - - if (cu->adt) { - expand_animdata(fd, mainvar, cu->adt); - } } static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me) { int a; - if (me->adt) { - expand_animdata(fd, mainvar, me->adt); - } - for (a = 0; a < me->totcol; a++) { expand_doit(fd, mainvar, me->mat[a]); } @@ -10560,10 +10509,6 @@ static void expand_bones(FileData *fd, Main *mainvar, Bone *bone) static void expand_armature(FileData *fd, Main *mainvar, bArmature *arm) { - if (arm->adt) { - expand_animdata(fd, mainvar, arm->adt); - } - for (Bone *curBone = arm->bonebase.first; curBone; curBone = curBone->next) { expand_bones(fd, mainvar, curBone); } @@ -10649,10 +10594,6 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) } // XXX deprecated - old animation system (for version patching only) - if (ob->adt) { - expand_animdata(fd, mainvar, ob->adt); - } - for (a = 0; a < ob->totcol; a++) { expand_doit(fd, mainvar, ob->mat[a]); } @@ -10728,19 +10669,12 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) expand_doit(fd, mainvar, sce->camera); expand_doit(fd, mainvar, sce->world); - if (sce->adt) { - expand_animdata(fd, mainvar, sce->adt); - } expand_keyingsets(fd, mainvar, &sce->keyingsets); if (sce->set) { expand_doit(fd, mainvar, sce->set); } - if (sce->nodetree) { - expand_nodetree(fd, mainvar, sce->nodetree); - } - for (srl = sce->r.layers.first; srl; srl = srl->next) { expand_doit(fd, mainvar, srl->mat_override); for (module = srl->freestyleConfig.modules.first; module; module = module->next) { @@ -10826,10 +10760,6 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) } #endif - if (sce->master_collection) { - expand_collection(fd, mainvar, sce->master_collection); - } - if (sce->r.bake.cage_object) { expand_doit(fd, mainvar, sce->r.bake.cage_object); } @@ -10847,26 +10777,17 @@ static void expand_camera(FileData *fd, Main *mainvar, Camera *ca) expand_doit(fd, mainvar, bgpic->ima); } } - - if (ca->adt) { - expand_animdata(fd, mainvar, ca->adt); - } } -static void expand_cachefile(FileData *fd, Main *mainvar, CacheFile *cache_file) +static void expand_cachefile(FileData *UNUSED(fd), + Main *UNUSED(mainvar), + CacheFile *UNUSED(cache_file)) { - if (cache_file->adt) { - expand_animdata(fd, mainvar, cache_file->adt); - } } static void expand_speaker(FileData *fd, Main *mainvar, Speaker *spk) { expand_doit(fd, mainvar, spk->sound); - - if (spk->adt) { - expand_animdata(fd, mainvar, spk->adt); - } } static void expand_sound(FileData *fd, Main *mainvar, bSound *snd) @@ -10874,18 +10795,12 @@ static void expand_sound(FileData *fd, Main *mainvar, bSound *snd) expand_doit(fd, mainvar, snd->ipo); // XXX deprecated - old animation system } -static void expand_lightprobe(FileData *fd, Main *mainvar, LightProbe *prb) +static void expand_lightprobe(FileData *UNUSED(fd), Main *UNUSED(mainvar), LightProbe *UNUSED(prb)) { - if (prb->adt) { - expand_animdata(fd, mainvar, prb->adt); - } } -static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip) +static void expand_movieclip(FileData *UNUSED(fd), Main *UNUSED(mainvar), MovieClip *UNUSED(clip)) { - if (clip->adt) { - expand_animdata(fd, mainvar, clip->adt); - } } static void expand_mask_parent(FileData *fd, Main *mainvar, MaskParent *parent) @@ -10899,10 +10814,6 @@ static void expand_mask(FileData *fd, Main *mainvar, Mask *mask) { MaskLayer *mask_layer; - if (mask->adt) { - expand_animdata(fd, mainvar, mask->adt); - } - for (mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { MaskSpline *spline; @@ -10931,13 +10842,7 @@ static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *li expand_doit(fd, mainvar, linestyle->mtex[a]->object); } } - if (linestyle->nodetree) { - expand_nodetree(fd, mainvar, linestyle->nodetree); - } - if (linestyle->adt) { - expand_animdata(fd, mainvar, linestyle->adt); - } for (m = linestyle->color_modifiers.first; m; m = m->next) { if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { expand_doit(fd, mainvar, ((LineStyleColorModifier_DistanceFromObject *)m)->target); @@ -10957,10 +10862,6 @@ static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *li static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd) { - if (gpd->adt) { - expand_animdata(fd, mainvar, gpd->adt); - } - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { expand_doit(fd, mainvar, gpl->parent); } @@ -11013,7 +10914,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) while (id) { if (id->tag & LIB_TAG_NEED_EXPAND) { expand_id(fd, mainvar, id); - expand_idprops(fd, mainvar, id->properties); switch (GS(id->name)) { case ID_OB: -- cgit v1.2.3 From ffb94e88b0857e8262f9e026444b327dddffa8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= Date: Thu, 6 Feb 2020 19:06:07 +0100 Subject: Fluid: Hide Advanced cache options The Manta script export should not be visible in the UI. At least not to normal users. The export feature is only useful for developers. --- source/blender/blenkernel/BKE_global.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 65c3725d994..93840db49c9 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -77,6 +77,7 @@ typedef struct Global { * * 799: Enable some mysterious new depsgraph behavior (05/2015). * * 1112: Disable new Cloth internal springs handling (09/2014). * * 1234: Disable new dyntopo code fixing skinny faces generation (04/2015). + * * 3001: Enable additional Fluid modifier (Mantaflow) options (02/2020). * * 16384 and above: Reserved for python (add-ons) usage. */ short debug_value; -- cgit v1.2.3 From 753323af15d7d8986efbdc4ad8d81331ddeee470 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 7 Feb 2020 10:58:18 +0100 Subject: Fix crash when linking. Stupid mistake in yesterday's own refactoring of readfile code... --- source/blender/blenloader/intern/readfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c1a39711bf8..9547e4cd05a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -10194,14 +10194,14 @@ static void expand_id_private_id(FileData *fd, Main *mainvar, ID *id) /* Handle 'private IDs'. */ bNodeTree *nodetree = ntreeFromID(id); if (nodetree != NULL) { - expand_id(fd, mainvar, id); + expand_id(fd, mainvar, &nodetree->id); expand_nodetree(fd, mainvar, nodetree); } if (GS(id->name) == ID_SCE) { Scene *scene = (Scene *)id; if (scene->master_collection != NULL) { - expand_id(fd, mainvar, id); + expand_id(fd, mainvar, &scene->master_collection->id); expand_collection(fd, mainvar, scene->master_collection); } } -- cgit v1.2.3 From f2695c9c1d8da179ce155817ba620b56b5ff5e62 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 7 Feb 2020 10:58:07 +0100 Subject: Cleanup: Remove view3d_draw_legacy.c This file was originally a placeholder for all the old functions that have not yet been ported to the new draw system. Over time all the functions that needed refactor were gone, and the functions here are still needed. While moving the functions around I removed dead code and made sure the existent comments start with a capital letter and end with a full stop. --- source/blender/editors/space_view3d/CMakeLists.txt | 1 - source/blender/editors/space_view3d/view3d_draw.c | 473 ++++++++++++++++- .../editors/space_view3d/view3d_draw_legacy.c | 578 --------------------- 3 files changed, 471 insertions(+), 581 deletions(-) delete mode 100644 source/blender/editors/space_view3d/view3d_draw_legacy.c (limited to 'source') diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt index 95d7f79f666..9e3c9d6725d 100644 --- a/source/blender/editors/space_view3d/CMakeLists.txt +++ b/source/blender/editors/space_view3d/CMakeLists.txt @@ -48,7 +48,6 @@ set(SRC view3d_buttons.c view3d_camera_control.c view3d_draw.c - view3d_draw_legacy.c view3d_edit.c view3d_fly.c view3d_gizmo_armature.c diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 0e5592abfd2..6704fc9908f 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -33,7 +33,9 @@ #include "BKE_camera.h" #include "BKE_collection.h" #include "BKE_context.h" +#include "BKE_customdata.h" #include "BKE_global.h" +#include "BKE_layer.h" #include "BKE_key.h" #include "BKE_main.h" #include "BKE_scene.h" @@ -56,11 +58,13 @@ #include "DNA_windowmanager_types.h" #include "DRW_engine.h" +#include "DRW_select_buffer.h" #include "ED_armature.h" #include "ED_keyframing.h" #include "ED_gpencil.h" #include "ED_screen.h" +#include "ED_screen_types.h" #include "ED_transform.h" #include "DEG_depsgraph_query.h" @@ -1936,11 +1940,476 @@ static bool view3d_clipping_test(const float co[3], const float clip[6][4]) return true; } -/* for 'local' ED_view3d_clipping_local must run first - * then all comparisons can be done in localspace */ +/* For 'local' ED_view3d_clipping_local must run first + * then all comparisons can be done in localspace. */ bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local) { return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip); } +/* Legacy 2.7x, now use shaders that use clip distance instead. + * Remove once clipping is working properly. */ +#define USE_CLIP_PLANES + +void ED_view3d_clipping_set(RegionView3D *rv3d) +{ +#ifdef USE_CLIP_PLANES + double plane[4]; + const uint tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6; + + for (unsigned a = 0; a < tot; a++) { + copy_v4db_v4fl(plane, rv3d->clip[a]); + glClipPlane(GL_CLIP_PLANE0 + a, plane); + glEnable(GL_CLIP_PLANE0 + a); + glEnable(GL_CLIP_DISTANCE0 + a); + } +#else + for (unsigned a = 0; a < 6; a++) { + glEnable(GL_CLIP_DISTANCE0 + a); + } +#endif +} + +/* Use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set. */ +void ED_view3d_clipping_disable(void) +{ + for (unsigned a = 0; a < 6; a++) { +#ifdef USE_CLIP_PLANES + glDisable(GL_CLIP_PLANE0 + a); +#endif + glDisable(GL_CLIP_DISTANCE0 + a); + } +} +void ED_view3d_clipping_enable(void) +{ + for (unsigned a = 0; a < 6; a++) { +#ifdef USE_CLIP_PLANES + glEnable(GL_CLIP_PLANE0 + a); +#endif + glEnable(GL_CLIP_DISTANCE0 + a); + } +} + +/* *********************** backdraw for selection *************** */ + +/** + * \note Only use in object mode. + */ +static void validate_object_select_id( + struct Depsgraph *depsgraph, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Object *obact) +{ + Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact); + + BLI_assert(ar->regiontype == RGN_TYPE_WINDOW); + UNUSED_VARS_NDEBUG(ar); + + if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) || + BKE_paint_select_face_test(obact_eval))) { + /* do nothing */ + } + /* texture paint mode sampling */ + else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) && + (v3d->shading.type > OB_WIRE)) { + /* do nothing */ + } + else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) { + /* do nothing */ + } + else { + v3d->flag &= ~V3D_INVALID_BACKBUF; + return; + } + + if (!(v3d->flag & V3D_INVALID_BACKBUF)) { + return; + } + + if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) { + Base *base = BKE_view_layer_base_find(view_layer, obact); + DRW_select_buffer_context_create(&base, 1, -1); + } + + /* TODO: Create a flag in `DRW_manager` because the drawing is no longer + * made on the backbuffer in this case. */ + v3d->flag &= ~V3D_INVALID_BACKBUF; +} + +/* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow. + * Calling this function should be avoided during interactive drawing. */ +static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) +{ + DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(viewport); + + GPUFrameBuffer *tmp_fb = GPU_framebuffer_create(); + GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0); + GPU_framebuffer_bind(tmp_fb); + + glReadPixels(rect->xmin, + rect->ymin, + BLI_rcti_size_x(rect), + BLI_rcti_size_y(rect), + GL_DEPTH_COMPONENT, + GL_FLOAT, + data); + + GPU_framebuffer_restore(); + GPU_framebuffer_free(tmp_fb); +} + +void ED_view3d_select_id_validate(ViewContext *vc) +{ + /* TODO: Create a flag in `DRW_manager` because the drawing is no longer + * made on the backbuffer in this case. */ + if (vc->v3d->flag & V3D_INVALID_BACKBUF) { + validate_object_select_id(vc->depsgraph, vc->view_layer, vc->ar, vc->v3d, vc->obact); + } +} + +void ED_view3d_backbuf_depth_validate(ViewContext *vc) +{ + if (vc->v3d->flag & V3D_INVALID_BACKBUF) { + ARegion *ar = vc->ar; + Object *obact_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact); + + if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) { + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); + DRW_draw_depth_object(vc->ar, vc->v3d, viewport, obact_eval); + } + + vc->v3d->flag &= ~V3D_INVALID_BACKBUF; + } +} + +/** + * allow for small values [0.5 - 2.5], + * and large values, FLT_MAX by clamping by the area size + */ +int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist) +{ + return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx)); +} + +/* *********************** */ + +void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect) +{ + /* clamp rect by region */ + rcti r = { + .xmin = 0, + .xmax = ar->winx - 1, + .ymin = 0, + .ymax = ar->winy - 1, + }; + + /* Constrain rect to depth bounds */ + BLI_rcti_isect(&r, rect, rect); + + /* assign values to compare with the ViewDepths */ + int x = rect->xmin; + int y = rect->ymin; + + int w = BLI_rcti_size_x(rect); + int h = BLI_rcti_size_y(rect); + + if (w <= 0 || h <= 0) { + if (d->depths) { + MEM_freeN(d->depths); + } + d->depths = NULL; + + d->damaged = false; + } + else if (d->w != w || d->h != h || d->x != x || d->y != y || d->depths == NULL) { + d->x = x; + d->y = y; + d->w = w; + d->h = h; + + if (d->depths) { + MEM_freeN(d->depths); + } + + d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset"); + + d->damaged = true; + } + + if (d->damaged) { + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); + view3d_opengl_read_Z_pixels(viewport, rect, d->depths); + glGetDoublev(GL_DEPTH_RANGE, d->depth_range); + d->damaged = false; + } +} + +/* Note, with nouveau drivers the glReadPixels() is very slow. [#24339]. */ +void ED_view3d_depth_update(ARegion *ar) +{ + RegionView3D *rv3d = ar->regiondata; + + /* Create storage for, and, if necessary, copy depth buffer. */ + if (!rv3d->depths) { + rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths"); + } + if (rv3d->depths) { + ViewDepths *d = rv3d->depths; + if (d->w != ar->winx || d->h != ar->winy || !d->depths) { + d->w = ar->winx; + d->h = ar->winy; + if (d->depths) { + MEM_freeN(d->depths); + } + d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths"); + d->damaged = true; + } + + if (d->damaged) { + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); + rcti r = { + .xmin = 0, + .xmax = d->w, + .ymin = 0, + .ymax = d->h, + }; + view3d_opengl_read_Z_pixels(viewport, &r, d->depths); + glGetDoublev(GL_DEPTH_RANGE, d->depth_range); + d->damaged = false; + } + } +} + +/* Utility function to find the closest Z value, use for autodepth. */ +float view3d_depth_near(ViewDepths *d) +{ + /* Convert to float for comparisons. */ + const float near = (float)d->depth_range[0]; + const float far_real = (float)d->depth_range[1]; + float far = far_real; + + const float *depths = d->depths; + float depth = FLT_MAX; + int i = (int)d->w * (int)d->h; /* Cast to avoid short overflow. */ + + /* Far is both the starting 'far' value + * and the closest value found. */ + while (i--) { + depth = *depths++; + if ((depth < far) && (depth > near)) { + far = depth; + } + } + + return far == far_real ? FLT_MAX : far; +} + +void ED_view3d_draw_depth_gpencil(Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d) +{ + /* Setup view matrix. */ + ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL); + + GPU_clear(GPU_DEPTH_BIT); + + GPU_depth_test(true); + + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); + DRW_draw_depth_loop_gpencil(depsgraph, ar, v3d, viewport); + + GPU_depth_test(false); +} + +/* *********************** customdata **************** */ + +void ED_view3d_datamask(const bContext *C, + const Scene *UNUSED(scene), + const View3D *v3d, + CustomData_MeshMasks *r_cddata_masks) +{ + if (ELEM(v3d->shading.type, OB_TEXTURE, OB_MATERIAL, OB_RENDER)) { + r_cddata_masks->lmask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL; + r_cddata_masks->vmask |= CD_MASK_ORCO; + } + else if (v3d->shading.type == OB_SOLID) { + if (v3d->shading.color_type == V3D_SHADING_TEXTURE_COLOR) { + r_cddata_masks->lmask |= CD_MASK_MLOOPUV; + } + if (v3d->shading.color_type == V3D_SHADING_VERTEX_COLOR) { + r_cddata_masks->lmask |= CD_MASK_MLOOPCOL; + } + } + + if ((CTX_data_mode_enum(C) == CTX_MODE_EDIT_MESH) && + (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_WEIGHT)) { + r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT; + } +} + +/* Goes over all modes and view3d settings. */ +void ED_view3d_screen_datamask(const bContext *C, + const Scene *scene, + const bScreen *screen, + CustomData_MeshMasks *r_cddata_masks) +{ + CustomData_MeshMasks_update(r_cddata_masks, &CD_MASK_BAREMESH); + + /* Check if we need tfaces & mcols due to view mode. */ + for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_VIEW3D) { + ED_view3d_datamask(C, scene, sa->spacedata.first, r_cddata_masks); + } + } +} + +/** + * Store values from #RegionView3D, set when drawing. + * This is needed when we draw with to a viewport using a different matrix + * (offscreen drawing for example). + * + * Values set by #ED_view3d_update_viewmat should be handled here. + */ +struct RV3DMatrixStore { + float winmat[4][4]; + float viewmat[4][4]; + float viewinv[4][4]; + float persmat[4][4]; + float persinv[4][4]; + float viewcamtexcofac[4]; + float pixsize; +}; + +struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) +{ + struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__); + copy_m4_m4(rv3dmat->winmat, rv3d->winmat); + copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat); + copy_m4_m4(rv3dmat->persmat, rv3d->persmat); + copy_m4_m4(rv3dmat->persinv, rv3d->persinv); + copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); + copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); + rv3dmat->pixsize = rv3d->pixsize; + return (void *)rv3dmat; +} + +void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt) +{ + struct RV3DMatrixStore *rv3dmat = rv3dmat_pt; + copy_m4_m4(rv3d->winmat, rv3dmat->winmat); + copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat); + copy_m4_m4(rv3d->persmat, rv3dmat->persmat); + copy_m4_m4(rv3d->persinv, rv3dmat->persinv); + copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv); + copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac); + rv3d->pixsize = rv3dmat->pixsize; +} + +/** + * \note The info that this uses is updated in #ED_refresh_viewport_fps, + * which currently gets called during #SCREEN_OT_animation_step. + */ +void ED_scene_draw_fps(Scene *scene, int xoffset, int *yoffset) +{ + ScreenFrameRateInfo *fpsi = scene->fps_info; + char printable[16]; + + if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) { + return; + } + + printable[0] = '\0'; + + /* Doing an average for a more robust calculation. */ + fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / + (fpsi->lredrawtime - fpsi->redrawtime)); + + float fps = 0.0f; + int tot = 0; + for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) { + if (fpsi->redrawtimes_fps[i]) { + fps += fpsi->redrawtimes_fps[i]; + tot++; + } + } + if (tot) { + fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE; + fps = fps / tot; + } + + const int font_id = BLF_default(); + + /* Is this more than half a frame behind? */ + if (fps + 0.5f < (float)(FPS)) { + UI_FontThemeColor(font_id, TH_REDALERT); + BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps); + } + else { + UI_FontThemeColor(font_id, TH_TEXT_HI); + BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps + 0.5f)); + } + + BLF_enable(font_id, BLF_SHADOW); + BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); + BLF_shadow_offset(font_id, 1, -1); + + *yoffset -= U.widget_unit; + +#ifdef WITH_INTERNATIONAL + BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); +#else + BLF_draw_default_ascii(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); +#endif + + BLF_disable(font_id, BLF_SHADOW); +} + +static bool view3d_main_region_do_render_draw(const Scene *scene) +{ + RenderEngineType *type = RE_engines_find(scene->r.engine); + return (type && type->view_update && type->view_draw); +} + +bool ED_view3d_calc_render_border( + const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, rcti *rect) +{ + RegionView3D *rv3d = ar->regiondata; + bool use_border; + + /* Test if there is a 3d view rendering. */ + if (v3d->shading.type != OB_RENDER || !view3d_main_region_do_render_draw(scene)) { + return false; + } + + /* Test if there is a border render. */ + if (rv3d->persp == RV3D_CAMOB) { + use_border = (scene->r.mode & R_BORDER) != 0; + } + else { + use_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0; + } + + if (!use_border) { + return false; + } + + /* Compute border. */ + if (rv3d->persp == RV3D_CAMOB) { + rctf viewborder; + ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false); + + rect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder); + rect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder); + rect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder); + rect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder); + } + else { + rect->xmin = v3d->render_border.xmin * ar->winx; + rect->xmax = v3d->render_border.xmax * ar->winx; + rect->ymin = v3d->render_border.ymin * ar->winy; + rect->ymax = v3d->render_border.ymax * ar->winy; + } + + BLI_rcti_translate(rect, ar->winrct.xmin, ar->winrct.ymin); + BLI_rcti_isect(&ar->winrct, rect, rect); + + return true; +} + /** \} */ diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c deleted file mode 100644 index 38cb5ad8651..00000000000 --- a/source/blender/editors/space_view3d/view3d_draw_legacy.c +++ /dev/null @@ -1,578 +0,0 @@ -/* - * 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. - * - * The Original Code is Copyright (C) 2008 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup spview3d - */ - -#include -#include -#include - -#include "DNA_armature_types.h" -#include "DNA_camera_types.h" -#include "DNA_collection_types.h" -#include "DNA_customdata_types.h" -#include "DNA_object_types.h" -#include "DNA_mesh_types.h" -#include "DNA_key_types.h" -#include "DNA_light_types.h" -#include "DNA_scene_types.h" -#include "DNA_world_types.h" -#include "DNA_brush_types.h" - -#include "MEM_guardedalloc.h" - -#include "BLI_blenlib.h" -#include "BLI_math.h" -#include "BLI_utildefines.h" -#include "BLI_endian_switch.h" -#include "BLI_threads.h" - -#include "BKE_anim.h" -#include "BKE_camera.h" -#include "BKE_context.h" -#include "BKE_customdata.h" -#include "BKE_image.h" -#include "BKE_key.h" -#include "BKE_layer.h" -#include "BKE_object.h" -#include "BKE_global.h" -#include "BKE_paint.h" -#include "BKE_scene.h" -#include "BKE_unit.h" -#include "BKE_movieclip.h" - -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_query.h" - -#include "IMB_imbuf_types.h" -#include "IMB_imbuf.h" -#include "IMB_colormanagement.h" - -#include "BIF_glutil.h" - -#include "WM_api.h" -#include "WM_types.h" - -#include "BLF_api.h" -#include "BLT_translation.h" - -#include "ED_armature.h" -#include "ED_keyframing.h" -#include "ED_gpencil.h" -#include "ED_mesh.h" -#include "ED_screen.h" -#include "ED_space_api.h" -#include "ED_screen_types.h" -#include "ED_transform.h" -#include "ED_view3d.h" - -#include "UI_interface.h" -#include "UI_interface_icons.h" -#include "UI_resources.h" - -#include "GPU_framebuffer.h" -#include "GPU_immediate.h" -#include "GPU_state.h" -#include "GPU_viewport.h" - -#include "RE_engine.h" - -#include "DRW_engine.h" -#include "DRW_select_buffer.h" - -#include "view3d_intern.h" /* own include */ - -/* ********* custom clipping *********** */ - -/* Legacy 2.7x, now use shaders that use clip distance instead. - * Remove once clipping is working properly. */ -#define USE_CLIP_PLANES - -void ED_view3d_clipping_set(RegionView3D *rv3d) -{ -#ifdef USE_CLIP_PLANES - double plane[4]; - const uint tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6; - - for (unsigned a = 0; a < tot; a++) { - copy_v4db_v4fl(plane, rv3d->clip[a]); - glClipPlane(GL_CLIP_PLANE0 + a, plane); - glEnable(GL_CLIP_PLANE0 + a); - glEnable(GL_CLIP_DISTANCE0 + a); - } -#else - for (unsigned a = 0; a < 6; a++) { - glEnable(GL_CLIP_DISTANCE0 + a); - } -#endif -} - -/* use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set */ -void ED_view3d_clipping_disable(void) -{ - for (unsigned a = 0; a < 6; a++) { -#ifdef USE_CLIP_PLANES - glDisable(GL_CLIP_PLANE0 + a); -#endif - glDisable(GL_CLIP_DISTANCE0 + a); - } -} -void ED_view3d_clipping_enable(void) -{ - for (unsigned a = 0; a < 6; a++) { -#ifdef USE_CLIP_PLANES - glEnable(GL_CLIP_PLANE0 + a); -#endif - glEnable(GL_CLIP_DISTANCE0 + a); - } -} - -/* *********************** backdraw for selection *************** */ - -/** - * \note Only use in object mode. - */ -static void validate_object_select_id( - struct Depsgraph *depsgraph, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Object *obact) -{ - Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact); - - BLI_assert(ar->regiontype == RGN_TYPE_WINDOW); - UNUSED_VARS_NDEBUG(ar); - - if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) || - BKE_paint_select_face_test(obact_eval))) { - /* do nothing */ - } - /* texture paint mode sampling */ - else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) && - (v3d->shading.type > OB_WIRE)) { - /* do nothing */ - } - else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) { - /* do nothing */ - } - else { - v3d->flag &= ~V3D_INVALID_BACKBUF; - return; - } - - if (!(v3d->flag & V3D_INVALID_BACKBUF)) { - return; - } - - if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) { - Base *base = BKE_view_layer_base_find(view_layer, obact); - DRW_select_buffer_context_create(&base, 1, -1); - } - - /* TODO: Create a flag in `DRW_manager` because the drawing is no longer - * made on the backbuffer in this case. */ - v3d->flag &= ~V3D_INVALID_BACKBUF; -} - -/* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow. - * Calling this function should be avoided during interactive drawing. */ -static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) -{ - DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(viewport); - - GPUFrameBuffer *tmp_fb = GPU_framebuffer_create(); - GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0); - GPU_framebuffer_bind(tmp_fb); - - glReadPixels(rect->xmin, - rect->ymin, - BLI_rcti_size_x(rect), - BLI_rcti_size_y(rect), - GL_DEPTH_COMPONENT, - GL_FLOAT, - data); - - GPU_framebuffer_restore(); - GPU_framebuffer_free(tmp_fb); -} - -void ED_view3d_select_id_validate(ViewContext *vc) -{ - /* TODO: Create a flag in `DRW_manager` because the drawing is no longer - * made on the backbuffer in this case. */ - if (vc->v3d->flag & V3D_INVALID_BACKBUF) { - validate_object_select_id(vc->depsgraph, vc->view_layer, vc->ar, vc->v3d, vc->obact); - } -} - -void ED_view3d_backbuf_depth_validate(ViewContext *vc) -{ - if (vc->v3d->flag & V3D_INVALID_BACKBUF) { - ARegion *ar = vc->ar; - Object *obact_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact); - - if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) { - GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); - DRW_draw_depth_object(vc->ar, vc->v3d, viewport, obact_eval); - } - - vc->v3d->flag &= ~V3D_INVALID_BACKBUF; - } -} - -/** - * allow for small values [0.5 - 2.5], - * and large values, FLT_MAX by clamping by the area size - */ -int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist) -{ - return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx)); -} - -/* *********************** */ - -void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect) -{ - /* clamp rect by region */ - rcti r = { - .xmin = 0, - .xmax = ar->winx - 1, - .ymin = 0, - .ymax = ar->winy - 1, - }; - - /* Constrain rect to depth bounds */ - BLI_rcti_isect(&r, rect, rect); - - /* assign values to compare with the ViewDepths */ - int x = rect->xmin; - int y = rect->ymin; - - int w = BLI_rcti_size_x(rect); - int h = BLI_rcti_size_y(rect); - - if (w <= 0 || h <= 0) { - if (d->depths) { - MEM_freeN(d->depths); - } - d->depths = NULL; - - d->damaged = false; - } - else if (d->w != w || d->h != h || d->x != x || d->y != y || d->depths == NULL) { - d->x = x; - d->y = y; - d->w = w; - d->h = h; - - if (d->depths) { - MEM_freeN(d->depths); - } - - d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset"); - - d->damaged = true; - } - - if (d->damaged) { - GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); - view3d_opengl_read_Z_pixels(viewport, rect, d->depths); - glGetDoublev(GL_DEPTH_RANGE, d->depth_range); - d->damaged = false; - } -} - -/* note, with nouveau drivers the glReadPixels() is very slow. [#24339] */ -void ED_view3d_depth_update(ARegion *ar) -{ - RegionView3D *rv3d = ar->regiondata; - - /* Create storage for, and, if necessary, copy depth buffer */ - if (!rv3d->depths) { - rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths"); - } - if (rv3d->depths) { - ViewDepths *d = rv3d->depths; - if (d->w != ar->winx || d->h != ar->winy || !d->depths) { - d->w = ar->winx; - d->h = ar->winy; - if (d->depths) { - MEM_freeN(d->depths); - } - d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths"); - d->damaged = true; - } - - if (d->damaged) { - GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); - rcti r = { - .xmin = 0, - .xmax = d->w, - .ymin = 0, - .ymax = d->h, - }; - view3d_opengl_read_Z_pixels(viewport, &r, d->depths); - glGetDoublev(GL_DEPTH_RANGE, d->depth_range); - d->damaged = false; - } - } -} - -/* utility function to find the closest Z value, use for autodepth */ -float view3d_depth_near(ViewDepths *d) -{ - /* convert to float for comparisons */ - const float near = (float)d->depth_range[0]; - const float far_real = (float)d->depth_range[1]; - float far = far_real; - - const float *depths = d->depths; - float depth = FLT_MAX; - int i = (int)d->w * (int)d->h; /* cast to avoid short overflow */ - - /* far is both the starting 'far' value - * and the closest value found. */ - while (i--) { - depth = *depths++; - if ((depth < far) && (depth > near)) { - far = depth; - } - } - - return far == far_real ? FLT_MAX : far; -} - -void ED_view3d_draw_depth_gpencil(Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d) -{ - /* Setup view matrix. */ - ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL); - - GPU_clear(GPU_DEPTH_BIT); - - GPU_depth_test(true); - - GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); - DRW_draw_depth_loop_gpencil(depsgraph, ar, v3d, viewport); - - GPU_depth_test(false); -} - -/* *********************** customdata **************** */ - -void ED_view3d_datamask(const bContext *C, - const Scene *UNUSED(scene), - const View3D *v3d, - CustomData_MeshMasks *r_cddata_masks) -{ - if (ELEM(v3d->shading.type, OB_TEXTURE, OB_MATERIAL, OB_RENDER)) { - r_cddata_masks->lmask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL; - r_cddata_masks->vmask |= CD_MASK_ORCO; - } - else if (v3d->shading.type == OB_SOLID) { - if (v3d->shading.color_type == V3D_SHADING_TEXTURE_COLOR) { - r_cddata_masks->lmask |= CD_MASK_MLOOPUV; - } - if (v3d->shading.color_type == V3D_SHADING_VERTEX_COLOR) { - r_cddata_masks->lmask |= CD_MASK_MLOOPCOL; - } - } - - if ((CTX_data_mode_enum(C) == CTX_MODE_EDIT_MESH) && - (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_WEIGHT)) { - r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT; - } -} - -/* goes over all modes and view3d settings */ -void ED_view3d_screen_datamask(const bContext *C, - const Scene *scene, - const bScreen *screen, - CustomData_MeshMasks *r_cddata_masks) -{ - CustomData_MeshMasks_update(r_cddata_masks, &CD_MASK_BAREMESH); - - /* check if we need tfaces & mcols due to view mode */ - for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - if (sa->spacetype == SPACE_VIEW3D) { - ED_view3d_datamask(C, scene, sa->spacedata.first, r_cddata_masks); - } - } -} - -/** - * Store values from #RegionView3D, set when drawing. - * This is needed when we draw with to a viewport using a different matrix - * (offscreen drawing for example). - * - * Values set by #ED_view3d_update_viewmat should be handled here. - */ -struct RV3DMatrixStore { - float winmat[4][4]; - float viewmat[4][4]; - float viewinv[4][4]; - float persmat[4][4]; - float persinv[4][4]; - float viewcamtexcofac[4]; - float pixsize; -}; - -struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) -{ - struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__); - copy_m4_m4(rv3dmat->winmat, rv3d->winmat); - copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat); - copy_m4_m4(rv3dmat->persmat, rv3d->persmat); - copy_m4_m4(rv3dmat->persinv, rv3d->persinv); - copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); - copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); - rv3dmat->pixsize = rv3d->pixsize; - return (void *)rv3dmat; -} - -void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt) -{ - struct RV3DMatrixStore *rv3dmat = rv3dmat_pt; - copy_m4_m4(rv3d->winmat, rv3dmat->winmat); - copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat); - copy_m4_m4(rv3d->persmat, rv3dmat->persmat); - copy_m4_m4(rv3d->persinv, rv3dmat->persinv); - copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv); - copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac); - rv3d->pixsize = rv3dmat->pixsize; -} - -/** - * \note The info that this uses is updated in #ED_refresh_viewport_fps, - * which currently gets called during #SCREEN_OT_animation_step. - */ -void ED_scene_draw_fps(Scene *scene, int xoffset, int *yoffset) -{ - ScreenFrameRateInfo *fpsi = scene->fps_info; - char printable[16]; - - if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) { - return; - } - - printable[0] = '\0'; - -#if 0 - /* this is too simple, better do an average */ - fps = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime)) -#else - fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / - (fpsi->lredrawtime - fpsi->redrawtime)); - - float fps = 0.0f; - int tot = 0; - for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) { - if (fpsi->redrawtimes_fps[i]) { - fps += fpsi->redrawtimes_fps[i]; - tot++; - } - } - if (tot) { - fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE; - - // fpsi->redrawtime_index++; - // if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE) { - // fpsi->redrawtime = 0; - //} - - fps = fps / tot; - } -#endif - - const int font_id = BLF_default(); - - /* is this more than half a frame behind? */ - if (fps + 0.5f < (float)(FPS)) { - UI_FontThemeColor(font_id, TH_REDALERT); - BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps); - } - else { - UI_FontThemeColor(font_id, TH_TEXT_HI); - BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps + 0.5f)); - } - - BLF_enable(font_id, BLF_SHADOW); - BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); - BLF_shadow_offset(font_id, 1, -1); - - *yoffset -= U.widget_unit; - -#ifdef WITH_INTERNATIONAL - BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); -#else - BLF_draw_default_ascii(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); -#endif - - BLF_disable(font_id, BLF_SHADOW); -} - -static bool view3d_main_region_do_render_draw(const Scene *scene) -{ - RenderEngineType *type = RE_engines_find(scene->r.engine); - return (type && type->view_update && type->view_draw); -} - -bool ED_view3d_calc_render_border( - const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, rcti *rect) -{ - RegionView3D *rv3d = ar->regiondata; - bool use_border; - - /* test if there is a 3d view rendering */ - if (v3d->shading.type != OB_RENDER || !view3d_main_region_do_render_draw(scene)) { - return false; - } - - /* test if there is a border render */ - if (rv3d->persp == RV3D_CAMOB) { - use_border = (scene->r.mode & R_BORDER) != 0; - } - else { - use_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0; - } - - if (!use_border) { - return false; - } - - /* compute border */ - if (rv3d->persp == RV3D_CAMOB) { - rctf viewborder; - ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false); - - rect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder); - rect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder); - rect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder); - rect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder); - } - else { - rect->xmin = v3d->render_border.xmin * ar->winx; - rect->xmax = v3d->render_border.xmax * ar->winx; - rect->ymin = v3d->render_border.ymin * ar->winy; - rect->ymax = v3d->render_border.ymax * ar->winy; - } - - BLI_rcti_translate(rect, ar->winrct.xmin, ar->winrct.ymin); - BLI_rcti_isect(&ar->winrct, rect, rect); - - return true; -} -- cgit v1.2.3 From 0f7a90d4ad2c144b82679c24020e1338a3fc7cef Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 7 Feb 2020 11:58:51 +0100 Subject: Cleanup: `make format` Dear developers remember to set your coding environment to use clang-format. --- source/blender/blenkernel/intern/lattice.c | 11 ++++++----- source/blender/collada/ErrorHandler.cpp | 3 ++- source/blender/editors/mesh/editmesh_tools.c | 10 ++++++++-- source/blender/editors/render/render_preview.c | 3 ++- source/blender/makesrna/intern/rna_brush.c | 6 +++++- source/blender/modifiers/intern/MOD_curve.c | 10 ++++++++-- source/blender/modifiers/intern/MOD_lattice.c | 10 ++++++++-- source/blender/modifiers/intern/MOD_smooth.c | 5 +++-- 8 files changed, 42 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 243c63a8f03..a09e97d4fed 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -783,7 +783,7 @@ void curve_deform_verts(Object *cuOb, if (cu->flag & CU_DEFORM_BOUNDS_OFF) { for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : + const float weight = invert_vgroup ? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : defvert_find_weight(dvert_iter, defgrp_index); if (weight > 0.0f) { @@ -800,7 +800,7 @@ void curve_deform_verts(Object *cuOb, INIT_MINMAX(cd.dmin, cd.dmax); for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : + const float weight = invert_vgroup ? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : defvert_find_weight(dvert_iter, defgrp_index); if (weight > 0.0f) { mul_m4_v3(cd.curvespace, vert_coords[a]); @@ -809,7 +809,7 @@ void curve_deform_verts(Object *cuOb, } for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = invert_vgroup? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : + const float weight = invert_vgroup ? 1.0f - defvert_find_weight(dvert_iter, defgrp_index) : defvert_find_weight(dvert_iter, defgrp_index); if (weight > 0.0f) { @@ -899,8 +899,9 @@ static void lattice_deform_vert_task(void *__restrict userdata, const LatticeDeformUserdata *data = userdata; if (data->dvert != NULL) { - const float weight = data->invert_vgroup? 1.0f - defvert_find_weight(data->dvert + index, data->defgrp_index) : - defvert_find_weight(data->dvert + index, data->defgrp_index); + const float weight = data->invert_vgroup ? + 1.0f - defvert_find_weight(data->dvert + index, data->defgrp_index) : + defvert_find_weight(data->dvert + index, data->defgrp_index); if (weight > 0.0f) { calc_latt_deform(data->lattice_deform_data, data->vert_coords[index], weight * data->fac); } diff --git a/source/blender/collada/ErrorHandler.cpp b/source/blender/collada/ErrorHandler.cpp index 4f70281fb45..286bcbfb759 100644 --- a/source/blender/collada/ErrorHandler.cpp +++ b/source/blender/collada/ErrorHandler.cpp @@ -79,7 +79,8 @@ bool ErrorHandler::handleError(const COLLADASaxFWL::IError *error) error_context = "File access"; } - else if (parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_REQUIRED_ATTRIBUTE_MISSING) { + else if (parserError.getErrorType() == + GeneratedSaxParser::ParserError::ERROR_REQUIRED_ATTRIBUTE_MISSING) { isError = true; } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 0c564bb7593..bd8017acd28 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -3935,7 +3935,10 @@ static Base *mesh_separate_tagged( /* DAG_relations_tag_update(bmain); */ /* new in 2.5 */ - BKE_object_material_array_assign(bmain, base_new->object, BKE_object_material_array(obedit), *BKE_object_material_num(obedit)); + BKE_object_material_array_assign(bmain, + base_new->object, + BKE_object_material_array(obedit), + *BKE_object_material_num(obedit)); ED_object_base_select(base_new, BA_SELECT); @@ -4002,7 +4005,10 @@ static Base *mesh_separate_arrays(Main *bmain, /* DAG_relations_tag_update(bmain); */ /* new in 2.5 */ - BKE_object_material_array_assign(bmain, base_new->object, BKE_object_material_array(obedit), *BKE_object_material_num(obedit)); + BKE_object_material_array_assign(bmain, + base_new->object, + BKE_object_material_array(obedit), + *BKE_object_material_num(obedit)); ED_object_base_select(base_new, BA_SELECT); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 3ea583e5b1f..96bc5648b75 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -465,7 +465,8 @@ static Scene *preview_prepare_scene( copy_v4_v4(base->object->color, sp->color); if (OB_TYPE_SUPPORT_MATERIAL(base->object->type)) { - /* don't use BKE_object_material_assign, it changed mat->id.us, which shows in the UI */ + /* don't use BKE_object_material_assign, it changed mat->id.us, which shows in the UI + */ Material ***matar = BKE_object_material_array(base->object); int actcol = max_ii(base->object->actcol - 1, 0); diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index edbaa13f80c..3c9942f32c7 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -151,7 +151,11 @@ const EnumPropertyItem rna_enum_brush_gpencil_types_items[] = { #ifndef RNA_RUNTIME static EnumPropertyItem rna_enum_gpencil_brush_eraser_modes_items[] = { - {GP_BRUSH_ERASER_SOFT, "SOFT", 0, "Dissolve,", "Erase strokes, fading their points strength and thickness"}, + {GP_BRUSH_ERASER_SOFT, + "SOFT", + 0, + "Dissolve,", + "Erase strokes, fading their points strength and thickness"}, {GP_BRUSH_ERASER_HARD, "HARD", 0, "Point", "Erase stroke points"}, {GP_BRUSH_ERASER_STROKE, "STROKE", 0, "Stroke", "Erase entire strokes"}, {0, NULL, 0, NULL, NULL}, diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index 7bfe63e562a..3f26686d45a 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -119,8 +119,14 @@ static void deformVerts(ModifierData *md, /* silly that defaxis and curve_deform_verts are off by 1 * but leave for now to save having to call do_versions */ - curve_deform_verts( - cmd->object, ctx->object, vertexCos, numVerts, dvert, defgrp_index, cmd->flag, cmd->defaxis - 1); + curve_deform_verts(cmd->object, + ctx->object, + vertexCos, + numVerts, + dvert, + defgrp_index, + cmd->flag, + cmd->defaxis - 1); if (!ELEM(mesh_src, NULL, mesh)) { BKE_id_free(NULL, mesh_src); diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index 3128183060a..21131a7c898 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -101,8 +101,14 @@ static void deformVerts(ModifierData *md, MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */ - lattice_deform_verts( - lmd->object, ctx->object, mesh_src, vertexCos, numVerts, lmd->flag, lmd->name, lmd->strength); + lattice_deform_verts(lmd->object, + ctx->object, + mesh_src, + vertexCos, + numVerts, + lmd->flag, + lmd->name, + lmd->strength); if (!ELEM(mesh_src, NULL, mesh)) { BKE_id_free(NULL, mesh_src); diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 59ed3b0b005..c879b2d3754 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -140,8 +140,9 @@ static void smoothModifier_do( } float *vco_new = accumulated_vecs[i]; - const float f_new = invert_vgroup ? (1.0f - defvert_find_weight(dv, defgrp_index)) * fac_new : - defvert_find_weight(dv, defgrp_index) * fac_new; + const float f_new = invert_vgroup ? + (1.0f - defvert_find_weight(dv, defgrp_index)) * fac_new : + defvert_find_weight(dv, defgrp_index) * fac_new; if (f_new <= 0.0f) { continue; } -- cgit v1.2.3 From 28cd16ec448f57b863f8be0a8f5d303d94bc1f1f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 7 Feb 2020 12:00:57 +0100 Subject: Cleanup: Tracking, reduce scope of variables Mainly affects for() loops. The reason why loop parameter was declared outside of the loop roots back to the times when not all compilers supported C99. --- source/blender/blenkernel/intern/tracking.c | 114 ++++++++------------- source/blender/blenkernel/intern/tracking_auto.c | 24 ++--- source/blender/blenkernel/intern/tracking_detect.c | 7 +- .../blenkernel/intern/tracking_plane_tracker.c | 19 ++-- .../blenkernel/intern/tracking_region_tracker.c | 8 +- source/blender/blenkernel/intern/tracking_solver.c | 35 +++---- .../blender/blenkernel/intern/tracking_stabilize.c | 29 +++--- source/blender/blenkernel/intern/tracking_util.c | 27 ++--- 8 files changed, 97 insertions(+), 166 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 1e7b3af53d5..0b732677dcb 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -80,9 +80,7 @@ static struct { /* Free the whole list of tracks, list's head and tail are set to NULL. */ static void tracking_tracks_free(ListBase *tracks) { - MovieTrackingTrack *track; - - for (track = tracks->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracks->first; track; track = track->next) { BKE_tracking_track_free(track); } @@ -92,9 +90,8 @@ static void tracking_tracks_free(ListBase *tracks) /* Free the whole list of plane tracks, list's head and tail are set to NULL. */ static void tracking_plane_tracks_free(ListBase *plane_tracks) { - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks->first; plane_track; plane_track = plane_track->next) { + for (MovieTrackingPlaneTrack *plane_track = plane_tracks->first; plane_track; + plane_track = plane_track->next) { BKE_tracking_plane_track_free(plane_track); } @@ -128,10 +125,8 @@ static void tracking_object_free(MovieTrackingObject *object) /* Free list of tracking objects, list's head and tail is set to NULL. */ static void tracking_objects_free(ListBase *objects) { - MovieTrackingObject *object; - /* Free objects contents. */ - for (object = objects->first; object; object = object->next) { + for (MovieTrackingObject *object = objects->first; object; object = object->next) { tracking_object_free(object); } @@ -191,13 +186,12 @@ static void tracking_tracks_copy(ListBase *tracks_dst, GHash *tracks_mapping, const int flag) { - MovieTrackingTrack *track_dst, *track_src; - BLI_listbase_clear(tracks_dst); BLI_ghash_clear(tracks_mapping, NULL, NULL); - for (track_src = tracks_src->first; track_src != NULL; track_src = track_src->next) { - track_dst = MEM_dupallocN(track_src); + for (MovieTrackingTrack *track_src = tracks_src->first; track_src != NULL; + track_src = track_src->next) { + MovieTrackingTrack *track_dst = MEM_dupallocN(track_src); if (track_src->markers) { track_dst->markers = MEM_dupallocN(track_src->markers); } @@ -217,13 +211,12 @@ static void tracking_plane_tracks_copy(ListBase *plane_tracks_list_dst, GHash *tracks_mapping, const int flag) { - MovieTrackingPlaneTrack *plane_track_dst, *plane_track_src; - BLI_listbase_clear(plane_tracks_list_dst); - for (plane_track_src = plane_tracks_list_src->first; plane_track_src != NULL; + for (MovieTrackingPlaneTrack *plane_track_src = plane_tracks_list_src->first; + plane_track_src != NULL; plane_track_src = plane_track_src->next) { - plane_track_dst = MEM_dupallocN(plane_track_src); + MovieTrackingPlaneTrack *plane_track_dst = MEM_dupallocN(plane_track_src); if (plane_track_src->markers) { plane_track_dst->markers = MEM_dupallocN(plane_track_src->markers); } @@ -278,12 +271,11 @@ static void tracking_objects_copy(ListBase *objects_dst, GHash *tracks_mapping, const int flag) { - MovieTrackingObject *object_dst, *object_src; - BLI_listbase_clear(objects_dst); - for (object_src = objects_src->first; object_src != NULL; object_src = object_src->next) { - object_dst = MEM_mallocN(sizeof(*object_dst), __func__); + for (MovieTrackingObject *object_src = objects_src->first; object_src != NULL; + object_src = object_src->next) { + MovieTrackingObject *object_dst = MEM_mallocN(sizeof(*object_dst), __func__); tracking_object_copy(object_dst, object_src, tracks_mapping, flag); BLI_addtail(objects_dst, object_dst); } @@ -1180,9 +1172,7 @@ void BKE_tracking_track_deselect(MovieTrackingTrack *track, int area) void BKE_tracking_tracks_deselect_all(ListBase *tracksbase) { - MovieTrackingTrack *track; - - for (track = tracksbase->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { if ((track->flag & TRACK_HIDDEN) == 0) { BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); } @@ -1269,13 +1259,12 @@ void BKE_tracking_marker_delete(MovieTrackingTrack *track, int framenr) void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) { - int a; float pat_min[2], pat_max[2]; BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); if (event == CLAMP_PAT_DIM) { - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ marker->search_min[a] = min_ff(pat_min[a], marker->search_min[a]); marker->search_max[a] = max_ff(pat_max[a], marker->search_max[a]); @@ -1286,7 +1275,7 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) sub_v2_v2v2(dim, pat_max, pat_min); - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { int b; /* pattern shouldn't be moved outside of search */ if (pat_min[a] < marker->search_min[a]) { @@ -1302,7 +1291,7 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) } } else if (event == CLAMP_SEARCH_DIM) { - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ marker->search_min[a] = min_ff(pat_min[a], marker->search_min[a]); marker->search_max[a] = max_ff(pat_max[a], marker->search_max[a]); @@ -1313,7 +1302,7 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) sub_v2_v2v2(dim, marker->search_max, marker->search_min); - for (a = 0; a < 2; a++) { + for (int a = 0; a < 2; a++) { /* search shouldn't be moved inside pattern */ if (marker->search_min[a] > pat_min[a]) { marker->search_min[a] = pat_min[a]; @@ -1552,9 +1541,9 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(MovieTracking *track const char *name) { ListBase *plane_tracks_base = BKE_tracking_object_get_plane_tracks(tracking, object); - MovieTrackingPlaneTrack *plane_track; - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; + plane_track = plane_track->next) { if (STREQ(plane_track->name, name)) { return plane_track; } @@ -1565,13 +1554,11 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(MovieTracking *track MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTracking *tracking) { - ListBase *plane_tracks_base; - if (tracking->act_plane_track == NULL) { return NULL; } - plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); + ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); /* Check that active track is in current plane tracks list */ if (BLI_findindex(plane_tracks_base, tracking->act_plane_track) != -1) { @@ -1583,9 +1570,8 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTrackin void BKE_tracking_plane_tracks_deselect_all(ListBase *plane_tracks_base) { - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; + plane_track = plane_track->next) { plane_track->flag &= ~SELECT; } } @@ -1593,8 +1579,7 @@ void BKE_tracking_plane_tracks_deselect_all(ListBase *plane_tracks_base) bool BKE_tracking_plane_track_has_point_track(MovieTrackingPlaneTrack *plane_track, MovieTrackingTrack *track) { - int i; - for (i = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0; i < plane_track->point_tracksnr; i++) { if (plane_track->point_tracks[i] == track) { return true; } @@ -1605,17 +1590,14 @@ bool BKE_tracking_plane_track_has_point_track(MovieTrackingPlaneTrack *plane_tra bool BKE_tracking_plane_track_remove_point_track(MovieTrackingPlaneTrack *plane_track, MovieTrackingTrack *track) { - int i, track_index; - MovieTrackingTrack **new_point_tracks; - if (plane_track->point_tracksnr <= 4) { return false; } - new_point_tracks = MEM_mallocN(sizeof(*new_point_tracks) * (plane_track->point_tracksnr - 1), - "new point tracks array"); + MovieTrackingTrack **new_point_tracks = MEM_mallocN( + sizeof(*new_point_tracks) * (plane_track->point_tracksnr - 1), "new point tracks array"); - for (i = 0, track_index = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0, track_index = 0; i < plane_track->point_tracksnr; i++) { if (plane_track->point_tracks[i] != track) { new_point_tracks[track_index++] = plane_track->point_tracks[i]; } @@ -1649,8 +1631,7 @@ void BKE_tracking_plane_track_replace_point_track(MovieTrackingPlaneTrack *plane MovieTrackingTrack *old_track, MovieTrackingTrack *new_track) { - int i; - for (i = 0; i < plane_track->point_tracksnr; i++) { + for (int i = 0; i < plane_track->point_tracksnr; i++) { if (plane_track->point_tracks[i] == old_track) { plane_track->point_tracks[i] = new_track; break; @@ -1662,9 +1643,9 @@ void BKE_tracking_plane_tracks_replace_point_track(MovieTracking *tracking, MovieTrackingTrack *old_track, MovieTrackingTrack *new_track) { - MovieTrackingPlaneTrack *plane_track; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; + plane_track = plane_track->next) { if (BKE_tracking_plane_track_has_point_track(plane_track, old_track)) { BKE_tracking_plane_track_replace_point_track(plane_track, old_track, new_track); } @@ -1838,23 +1819,22 @@ void BKE_tracking_plane_marker_get_subframe_corners(MovieTrackingPlaneTrack *pla { MovieTrackingPlaneMarker *marker = BKE_tracking_plane_marker_get(plane_track, (int)framenr); MovieTrackingPlaneMarker *marker_last = plane_track->markers + (plane_track->markersnr - 1); - int i; if (marker != marker_last) { MovieTrackingPlaneMarker *marker_next = marker + 1; if (marker_next->framenr == marker->framenr + 1) { float fac = (framenr - (int)framenr) / (marker_next->framenr - marker->framenr); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { interp_v2_v2v2(corners[i], marker->corners[i], marker_next->corners[i], fac); } } else { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { copy_v2_v2(corners[i], marker->corners[i]); } } } else { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { copy_v2_v2(corners[i], marker->corners[i]); } } @@ -2399,7 +2379,6 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking, bool undistort, float delta[2]) { - int a; float pos[2], warped_pos[2]; const int coord_delta = 5; void (*apply_distortion)(MovieTracking * tracking, const float pos[2], float out[2]); @@ -2413,7 +2392,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking, delta[0] = delta[1] = -FLT_MAX; - for (a = rect->xmin; a <= rect->xmax + coord_delta; a += coord_delta) { + for (int a = rect->xmin; a <= rect->xmax + coord_delta; a += coord_delta) { if (a > rect->xmax) { a = rect->xmax; } @@ -2441,7 +2420,7 @@ void BKE_tracking_max_distortion_delta_across_bound(MovieTracking *tracking, } } - for (a = rect->ymin; a <= rect->ymax + coord_delta; a += coord_delta) { + for (int a = rect->ymin; a <= rect->ymax + coord_delta; a += coord_delta) { if (a > rect->ymax) { a = rect->ymax; } @@ -2515,9 +2494,7 @@ ImBuf *BKE_tracking_sample_pattern(int frame_width, * fractional part of offset */ if (from_anchor) { - int a; - - for (a = 0; a < 5; a++) { + for (int a = 0; a < 5; a++) { src_pixel_x[a] += (double)((track->offset[0] * frame_width) - ((int)(track->offset[0] * frame_width))); src_pixel_y[a] += (double)((track->offset[1] * frame_height) - @@ -2664,9 +2641,6 @@ ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, void BKE_tracking_disable_channels( ImBuf *ibuf, bool disable_red, bool disable_green, bool disable_blue, bool grayscale) { - int x, y; - float scale; - if (!disable_red && !disable_green && !disable_blue && !grayscale) { return; } @@ -2674,11 +2648,11 @@ void BKE_tracking_disable_channels( /* if only some components are selected, it's important to rescale the result * appropriately so that e.g. if only blue is selected, it's not zeroed out. */ - scale = (disable_red ? 0.0f : 0.2126f) + (disable_green ? 0.0f : 0.7152f) + - (disable_blue ? 0.0f : 0.0722f); + float scale = (disable_red ? 0.0f : 0.2126f) + (disable_green ? 0.0f : 0.7152f) + + (disable_blue ? 0.0f : 0.0722f); - for (y = 0; y < ibuf->y; y++) { - for (x = 0; x < ibuf->x; x++) { + for (int y = 0; y < ibuf->y; y++) { + for (int x = 0; x < ibuf->x; x++) { int pixel = ibuf->x * y + x; if (ibuf->rect_float) { @@ -2916,7 +2890,6 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) { MovieTrackingObject *object = BKE_tracking_object_get_active(tracking); MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; - MovieTrackingTrack *track; MovieTrackingReconstruction *reconstruction = BKE_tracking_object_get_reconstruction(tracking, object); ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); @@ -2924,7 +2897,7 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) bool sel_only = (dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY) != 0; bool show_hidden = (dopesheet->flag & TRACKING_DOPE_SHOW_HIDDEN) != 0; - for (track = tracksbase->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { MovieTrackingDopesheetChannel *channel; if (!show_hidden && (track->flag & TRACK_HIDDEN) != 0) { @@ -3012,13 +2985,12 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking) MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; MovieTrackingObject *object = BKE_tracking_object_get_active(tracking); ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); - MovieTrackingTrack *track; int frames, start_frame = INT_MAX, end_frame = -INT_MAX; int *per_frame_counter; int prev_coverage, last_segment_frame; /* find frame boundaries */ - for (track = tracksbase->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { start_frame = min_ii(start_frame, track->markers[0].framenr); end_frame = max_ii(end_frame, track->markers[track->markersnr - 1].framenr); } @@ -3029,7 +3001,7 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking) per_frame_counter = MEM_callocN(sizeof(int) * frames, "per frame track counter"); /* find per-frame markers count */ - for (track = tracksbase->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = &track->markers[i]; diff --git a/source/blender/blenkernel/intern/tracking_auto.c b/source/blender/blenkernel/intern/tracking_auto.c index fad928c12fe..1a4df73c8aa 100644 --- a/source/blender/blenkernel/intern/tracking_auto.c +++ b/source/blender/blenkernel/intern/tracking_auto.c @@ -127,13 +127,12 @@ static void dna_marker_to_libmv_marker(/*const*/ MovieTrackingTrack *track, libmv_Marker *libmv_marker) { const int frame_dimensions[2] = {frame_width, frame_height}; - int i; libmv_marker->clip = clip; libmv_marker->frame = marker->framenr; libmv_marker->track = track_index; normalized_to_libmv_frame(marker->pos, frame_dimensions, libmv_marker->center); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { normalized_relative_to_libmv_frame( marker->pattern_corners[i], marker->pos, frame_dimensions, libmv_marker->patch[i]); } @@ -183,11 +182,10 @@ static void libmv_marker_to_dna_marker(libmv_Marker *libmv_marker, MovieTrackingMarker *marker) { const int frame_dimensions[2] = {frame_width, frame_height}; - int i; marker->framenr = libmv_marker->frame; libmv_frame_to_normalized(libmv_marker->center, frame_dimensions, marker->pos); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { libmv_frame_to_normalized_relative(libmv_marker->patch[i], libmv_marker->center, frame_dimensions, @@ -461,17 +459,16 @@ bool BKE_autotrack_context_step(AutoTrackContext *context) void BKE_autotrack_context_sync(AutoTrackContext *context) { int newframe, frame_delta = context->backwards ? -1 : 1; - int frame; BLI_spin_lock(&context->spin_lock); newframe = context->user.framenr; - for (frame = context->sync_frame; frame != (context->backwards ? newframe - 1 : newframe + 1); + for (int frame = context->sync_frame; + frame != (context->backwards ? newframe - 1 : newframe + 1); frame += frame_delta) { MovieTrackingMarker marker; libmv_Marker libmv_marker; int clip = 0; - int track; - for (track = 0; track < context->num_tracks; track++) { + for (int track = 0; track < context->num_tracks; track++) { AutoTrackOptions *options = &context->options[track]; int track_frame = BKE_movieclip_remap_scene_to_clip_frame( context->clips[options->clip_index], frame); @@ -522,17 +519,14 @@ void BKE_autotrack_context_sync_user(AutoTrackContext *context, MovieClipUser *u void BKE_autotrack_context_finish(AutoTrackContext *context) { - int clip_index; - - for (clip_index = 0; clip_index < context->num_clips; clip_index++) { + for (int clip_index = 0; clip_index < context->num_clips; clip_index++) { MovieClip *clip = context->clips[clip_index]; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(&clip->tracking); - MovieTrackingPlaneTrack *plane_track; - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; + plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) { - int track; - for (track = 0; track < context->num_tracks; track++) { + for (int track = 0; track < context->num_tracks; track++) { if (BKE_tracking_plane_track_has_point_track(plane_track, context->options[track].track)) { BKE_tracking_track_plane_from_existing_motion(plane_track, context->first_frame); diff --git a/source/blender/blenkernel/intern/tracking_detect.c b/source/blender/blenkernel/intern/tracking_detect.c index ec044f14fa8..08719161e1a 100644 --- a/source/blender/blenkernel/intern/tracking_detect.c +++ b/source/blender/blenkernel/intern/tracking_detect.c @@ -38,7 +38,6 @@ /* Check whether point is inside grease pencil stroke. */ static bool check_point_in_stroke(bGPDstroke *stroke, float x, float y) { - int i, prev; int count = 0; bGPDspoint *points = stroke->points; @@ -50,9 +49,7 @@ static bool check_point_in_stroke(bGPDstroke *stroke, float x, float y) * work, but such situation is crappy anyway. */ - prev = stroke->totpoints - 1; - - for (i = 0; i < stroke->totpoints; i++) { + for (int i = 0, prev = stroke->totpoints - 1; i < stroke->totpoints; prev = i, i++) { if ((points[i].y < y && points[prev].y >= y) || (points[prev].y < y && points[i].y >= y)) { float fac = (y - points[i].y) / (points[prev].y - points[i].y); @@ -60,8 +57,6 @@ static bool check_point_in_stroke(bGPDstroke *stroke, float x, float y) count++; } } - - prev = i; } return (count % 2) ? true : false; diff --git a/source/blender/blenkernel/intern/tracking_plane_tracker.c b/source/blender/blenkernel/intern/tracking_plane_tracker.c index 602243a7d50..e0e8a68bb1e 100644 --- a/source/blender/blenkernel/intern/tracking_plane_tracker.c +++ b/source/blender/blenkernel/intern/tracking_plane_tracker.c @@ -39,13 +39,13 @@ typedef double Vec2[2]; static int point_markers_correspondences_on_both_image( MovieTrackingPlaneTrack *plane_track, int frame1, int frame2, Vec2 **x1_r, Vec2 **x2_r) { - int i, correspondence_index; Vec2 *x1, *x2; *x1_r = x1 = MEM_mallocN(sizeof(*x1) * plane_track->point_tracksnr, "point correspondences x1"); *x2_r = x2 = MEM_mallocN(sizeof(*x1) * plane_track->point_tracksnr, "point correspondences x2"); - for (i = 0, correspondence_index = 0; i < plane_track->point_tracksnr; i++) { + int correspondence_index = 0; + for (int i = 0; i < plane_track->point_tracksnr; i++) { MovieTrackingTrack *point_track = plane_track->point_tracks[i]; MovieTrackingMarker *point_marker1, *point_marker2; @@ -77,11 +77,11 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac start_frame); MovieTrackingPlaneMarker *keyframe_plane_marker = NULL; MovieTrackingPlaneMarker new_plane_marker; - int current_frame, frame_delta = direction > 0 ? 1 : -1; + int frame_delta = direction > 0 ? 1 : -1; if (plane_track->flag & PLANE_TRACK_AUTOKEY) { /* Find a keyframe in given direction. */ - for (current_frame = start_frame;; current_frame += frame_delta) { + for (int current_frame = start_frame;; current_frame += frame_delta) { MovieTrackingPlaneMarker *next_plane_marker = BKE_tracking_plane_marker_get_exact( plane_track, current_frame + frame_delta); @@ -102,11 +102,10 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac new_plane_marker = *start_plane_marker; new_plane_marker.flag |= PLANE_MARKER_TRACKED; - for (current_frame = start_frame;; current_frame += frame_delta) { + for (int current_frame = start_frame;; current_frame += frame_delta) { MovieTrackingPlaneMarker *next_plane_marker = BKE_tracking_plane_marker_get_exact( plane_track, current_frame + frame_delta); Vec2 *x1, *x2; - int i, num_correspondences; double H_double[3][3]; float H[3][3]; @@ -118,13 +117,11 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac } } - num_correspondences = point_markers_correspondences_on_both_image( + const int num_correspondences = point_markers_correspondences_on_both_image( plane_track, current_frame, current_frame + frame_delta, &x1, &x2); - if (num_correspondences < 4) { MEM_freeN(x1); MEM_freeN(x2); - break; } @@ -132,7 +129,7 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac copy_m3_m3d(H, H_double); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { float vec[3] = {0.0f, 0.0f, 1.0f}, vec2[3]; copy_v2_v2(vec, new_plane_marker.corners[i]); @@ -155,7 +152,7 @@ static void track_plane_from_existing_motion(MovieTrackingPlaneTrack *plane_trac fac = 3 * fac * fac - 2 * fac * fac * fac; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { interp_v2_v2v2(new_plane_marker.corners[i], new_plane_marker.corners[i], next_plane_marker->corners[i], diff --git a/source/blender/blenkernel/intern/tracking_region_tracker.c b/source/blender/blenkernel/intern/tracking_region_tracker.c index 1d6bb88c3f4..967642c03a8 100644 --- a/source/blender/blenkernel/intern/tracking_region_tracker.c +++ b/source/blender/blenkernel/intern/tracking_region_tracker.c @@ -50,9 +50,7 @@ static void float_rgba_to_gray(const float *rgba, float weight_green, float weight_blue) { - int i; - - for (i = 0; i < num_pixels; i++) { + for (int i = 0; i < num_pixels; i++) { const float *pixel = rgba + 4 * i; gray[i] = weight_red * pixel[0] + weight_green * pixel[1] + weight_blue * pixel[2]; @@ -66,9 +64,7 @@ static void uint8_rgba_to_float_gray(const unsigned char *rgba, float weight_green, float weight_blue) { - int i; - - for (i = 0; i < num_pixels; i++) { + for (int i = 0; i < num_pixels; i++) { const unsigned char *pixel = rgba + i * 4; gray[i] = (weight_red * pixel[0] + weight_green * pixel[1] + weight_blue * pixel[2]) / 255.0f; diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c index ab741eed410..bedb55ae44e 100644 --- a/source/blender/blenkernel/intern/tracking_solver.c +++ b/source/blender/blenkernel/intern/tracking_solver.c @@ -90,13 +90,10 @@ static struct libmv_Tracks *libmv_tracks_new(MovieClip *clip, track = tracksbase->first; while (track) { - FCurve *weight_fcurve; - int a = 0; - - weight_fcurve = id_data_find_fcurve( + FCurve *weight_fcurve = id_data_find_fcurve( &clip->id, track, &RNA_MovieTrackingTrack, "weight", 0, NULL); - for (a = 0; a < track->markersnr; a++) { + for (int a = 0; a < track->markersnr; a++) { MovieTrackingMarker *marker = &track->markers[a]; if ((marker->flag & MARKER_DISABLED) == 0) { @@ -149,7 +146,7 @@ static bool reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context, MovieReconstructedCamera *reconstructed; MovieTrackingTrack *track; ListBase *tracksbase = NULL; - int tracknr = 0, a; + int tracknr = 0; bool ok = true; bool origin_set = false; int sfra = context->sfra, efra = context->efra; @@ -200,16 +197,16 @@ static bool reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context, reconstructed = MEM_callocN((efra - sfra + 1) * sizeof(MovieReconstructedCamera), "temp reconstructed camera"); - for (a = sfra; a <= efra; a++) { + for (int a = sfra; a <= efra; a++) { double matd[4][4]; if (libmv_reprojectionCameraForImage(libmv_reconstruction, a, matd)) { - int i, j; float mat[4][4]; float error = libmv_reprojectionErrorForImage(libmv_reconstruction, a); - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { + /* TODO(sergey): Use transpose utility. */ + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { mat[i][j] = matd[i][j]; } } @@ -591,21 +588,19 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, MovieTrackingReconstruction *reconstruction, const float scale[3]) { - MovieTrackingTrack *track; - int i; float first_camera_delta[3] = {0.0f, 0.0f, 0.0f}; if (reconstruction->camnr > 0) { mul_v3_v3v3(first_camera_delta, reconstruction->cameras[0].mat[3], scale); } - for (i = 0; i < reconstruction->camnr; i++) { + for (int i = 0; i < reconstruction->camnr; i++) { MovieReconstructedCamera *camera = &reconstruction->cameras[i]; mul_v3_v3(camera->mat[3], scale); sub_v3_v3(camera->mat[3], first_camera_delta); } - for (track = tracksbase->first; track; track = track->next) { + for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { if (track->flag & TRACK_HAS_BUNDLE) { mul_v3_v3(track->bundle_pos, scale); sub_v3_v3(track->bundle_pos, first_camera_delta); @@ -618,14 +613,10 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, */ void BKE_tracking_reconstruction_scale(MovieTracking *tracking, float scale[3]) { - MovieTrackingObject *object; - - for (object = tracking->objects.first; object; object = object->next) { - ListBase *tracksbase; - MovieTrackingReconstruction *reconstruction; - - tracksbase = BKE_tracking_object_get_tracks(tracking, object); - reconstruction = BKE_tracking_object_get_reconstruction(tracking, object); + for (MovieTrackingObject *object = tracking->objects.first; object; object = object->next) { + ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); + MovieTrackingReconstruction *reconstruction = BKE_tracking_object_get_reconstruction(tracking, + object); tracking_scale_reconstruction(tracksbase, reconstruction, scale); } diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c index 2c270f10908..d2d60e93a08 100644 --- a/source/blender/blenkernel/intern/tracking_stabilize.c +++ b/source/blender/blenkernel/intern/tracking_stabilize.c @@ -545,7 +545,6 @@ static bool average_track_contributions(StabContext *ctx, { bool ok; float weight_sum; - MovieTrackingTrack *track; MovieTracking *tracking = ctx->tracking; MovieTrackingStabilization *stab = &tracking->stabilization; float ref_pos[2]; @@ -559,7 +558,7 @@ static bool average_track_contributions(StabContext *ctx, ok = false; weight_sum = 0.0f; - for (track = tracking->tracks.first; track; track = track->next) { + for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { if (!is_init_for_stabilization(ctx, track)) { continue; } @@ -597,7 +596,7 @@ static bool average_track_contributions(StabContext *ctx, ok = false; weight_sum = 0.0f; - for (track = tracking->tracks.first; track; track = track->next) { + for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { if (!is_init_for_stabilization(ctx, track)) { continue; } @@ -652,12 +651,11 @@ static void average_marker_positions(StabContext *ctx, int framenr, float r_ref_ { bool ok = false; float weight_sum; - MovieTrackingTrack *track; MovieTracking *tracking = ctx->tracking; zero_v2(r_ref_pos); weight_sum = 0.0f; - for (track = tracking->tracks.first; track; track = track->next) { + for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { if (track->flag & TRACK_USE_2D_STAB) { float weight = 0.0f; MovieTrackingMarker *marker = get_tracking_data_point(ctx, track, framenr, &weight); @@ -680,7 +678,7 @@ static void average_marker_positions(StabContext *ctx, int framenr, float r_ref_ int next_lower = MINAFRAME; int next_higher = MAXFRAME; use_values_from_fcurves(ctx, true); - for (track = tracking->tracks.first; track; track = track->next) { + for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { /* Note: we deliberately do not care if this track * is already initialized for stabilization. */ if (track->flag & TRACK_USE_2D_STAB) { @@ -771,11 +769,10 @@ static bool interpolate_averaged_track_contributions(StabContext *ctx, static int establish_track_initialization_order(StabContext *ctx, TrackInitOrder *order) { size_t tracknr = 0; - MovieTrackingTrack *track; MovieTracking *tracking = ctx->tracking; int anchor_frame = tracking->stabilization.anchor_frame; - for (track = tracking->tracks.first; track != NULL; track = track->next) { + for (MovieTrackingTrack *track = tracking->tracks.first; track != NULL; track = track->next) { MovieTrackingMarker *marker; order[tracknr].data = track; marker = get_closest_marker(ctx, track, anchor_frame); @@ -880,10 +877,9 @@ static void initialize_track_for_stabilization(StabContext *ctx, static void initialize_all_tracks(StabContext *ctx, float aspect) { - size_t i, track_len = 0; + size_t track_len = 0; MovieClip *clip = ctx->clip; MovieTracking *tracking = ctx->tracking; - MovieTrackingTrack *track; TrackInitOrder *order; /* Attempt to start initialization at anchor_frame. @@ -896,7 +892,7 @@ static void initialize_all_tracks(StabContext *ctx, float aspect) zero_v2(pivot); /* Initialize private working data. */ - for (track = tracking->tracks.first; track != NULL; track = track->next) { + for (MovieTrackingTrack *track = tracking->tracks.first; track != NULL; track = track->next) { TrackStabilizationBase *local_data = access_stabilization_baseline_data(ctx, track); if (!local_data) { local_data = MEM_callocN(sizeof(TrackStabilizationBase), @@ -927,8 +923,8 @@ static void initialize_all_tracks(StabContext *ctx, float aspect) average_marker_positions(ctx, reference_frame, average_pos); setup_pivot(average_pos, pivot); - for (i = 0; i < track_len; i++) { - track = order[i].data; + for (int i = 0; i < track_len; i++) { + MovieTrackingTrack *track = order[i].data; if (reference_frame != order[i].reference_frame) { reference_frame = order[i].reference_frame; average_track_contributions(ctx, @@ -1142,12 +1138,11 @@ static float calculate_autoscale_factor(StabContext *ctx, int size, float aspect float pixel_aspect = ctx->tracking->camera.pixel_aspect; int height = size, width = aspect * size; - int sfra = INT_MAX, efra = INT_MIN, cfra; + int sfra = INT_MAX, efra = INT_MIN; float scale = 1.0f, scale_step = 0.0f; - MovieTrackingTrack *track; /* Calculate maximal frame range of tracks where stabilization is active. */ - for (track = ctx->tracking->tracks.first; track; track = track->next) { + for (MovieTrackingTrack *track = ctx->tracking->tracks.first; track; track = track->next) { if ((track->flag & TRACK_USE_2D_STAB) || ((stab->flag & TRACKING_STABILIZE_ROTATION) && (track->flag & TRACK_USE_2D_STAB_ROT))) { int first_frame = track->markers[0].framenr; @@ -1158,7 +1153,7 @@ static float calculate_autoscale_factor(StabContext *ctx, int size, float aspect } use_values_from_fcurves(ctx, true); - for (cfra = sfra; cfra <= efra; cfra++) { + for (int cfra = sfra; cfra <= efra; cfra++) { float translation[2], pivot[2], angle, tmp_scale; float mat[4][4]; const float points[4][2] = {{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}}; diff --git a/source/blender/blenkernel/intern/tracking_util.c b/source/blender/blenkernel/intern/tracking_util.c index ed582dc5b94..ada6ce96d58 100644 --- a/source/blender/blenkernel/intern/tracking_util.c +++ b/source/blender/blenkernel/intern/tracking_util.c @@ -126,7 +126,6 @@ void tracks_map_merge(TracksMap *map, MovieTracking *tracking) MovieTrackingTrack *track; ListBase tracks = {NULL, NULL}, new_tracks = {NULL, NULL}; ListBase *old_tracks; - int a; if (map->is_camera) { old_tracks = &tracking->tracks; @@ -146,7 +145,7 @@ void tracks_map_merge(TracksMap *map, MovieTracking *tracking) * this is needed to keep names in unique state and it's faster to change names * of currently operating tracks (if needed) */ - for (a = 0; a < map->num_tracks; a++) { + for (int a = 0; a < map->num_tracks; a++) { MovieTrackingTrack *old_track; bool mapped_to_old = false; @@ -221,11 +220,9 @@ void tracks_map_merge(TracksMap *map, MovieTracking *tracking) void tracks_map_free(TracksMap *map, void (*customdata_free)(void *customdata)) { - int i = 0; - BLI_ghash_free(map->hash, NULL, NULL); - for (i = 0; i < map->num_tracks; i++) { + for (int i = 0; i < map->num_tracks; i++) { if (map->customdata && customdata_free) { customdata_free(&map->customdata[i * map->customdata_size]); } @@ -345,12 +342,11 @@ void tracking_get_marker_coords_for_tracking(int frame_width, double search_pixel_x[5], double search_pixel_y[5]) { - int i; float unified_coords[2]; float pixel_coords[2]; /* Convert the corners into search space coordinates. */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { marker_unified_to_search_pixel( frame_width, frame_height, marker, marker->pattern_corners[i], pixel_coords); search_pixel_x[i] = pixel_coords[0] - 0.5f; @@ -373,12 +369,11 @@ void tracking_set_marker_coords_from_tracking(int frame_width, const double search_pixel_x[5], const double search_pixel_y[5]) { - int i; float marker_unified[2]; float search_pixel[2]; /* Convert the corners into search space coordinates. */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { search_pixel[0] = search_pixel_x[i] + 0.5; search_pixel[1] = search_pixel_y[i] + 0.5; search_pixel_to_marker_unified( @@ -394,7 +389,7 @@ void tracking_set_marker_coords_from_tracking(int frame_width, * Otherwise, the entire patch shifted, and that delta should be applied to * all the coordinates. */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { marker->pattern_corners[i][0] -= marker_unified[0]; marker->pattern_corners[i][1] -= marker_unified[1]; } @@ -672,8 +667,6 @@ static ImBuf *accessor_get_preprocessed_ibuf(TrackingImageAccessor *accessor, static ImBuf *make_grayscale_ibuf_copy(ImBuf *ibuf) { ImBuf *grayscale = IMB_allocImBuf(ibuf->x, ibuf->y, 32, 0); - size_t size; - int i; BLI_assert(ibuf->channels == 3 || ibuf->channels == 4); @@ -682,13 +675,13 @@ static ImBuf *make_grayscale_ibuf_copy(ImBuf *ibuf) * * Will generalize it later. */ - size = (size_t)grayscale->x * (size_t)grayscale->y * sizeof(float); + const size_t size = (size_t)grayscale->x * (size_t)grayscale->y * sizeof(float); grayscale->channels = 1; if ((grayscale->rect_float = MEM_mapallocN(size, "tracking grayscale image")) != NULL) { grayscale->mall |= IB_rectfloat; grayscale->flags |= IB_rectfloat; - for (i = 0; i < grayscale->x * grayscale->y; i++) { + for (int i = 0; i < grayscale->x * grayscale->y; i++) { const float *pixel = ibuf->rect_float + ibuf->channels * i; grayscale->rect_float[i] = 0.2126f * pixel[0] + 0.7152f * pixel[1] + 0.0722f * pixel[2]; @@ -785,14 +778,12 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor, clamped_height); } else { - int y; /* TODO(sergey): We don't do any color space or alpha conversion * here. Probably Libmv is better to work in the linear space, * but keep sRGB space here for compatibility for now. */ - for (y = 0; y < clamped_height; y++) { - int x; - for (x = 0; x < clamped_width; x++) { + for (int y = 0; y < clamped_height; y++) { + for (int x = 0; x < clamped_width; x++) { int src_x = x + clamped_origin_x, src_y = y + clamped_origin_y; int dst_x = x + dst_offset_x, dst_y = y + dst_offset_y; int dst_index = (dst_y * width + dst_x) * 4, -- cgit v1.2.3 From b1f1a1ca6035e23d66656c97c16fe081caafcae8 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 7 Feb 2020 12:16:23 +0100 Subject: Cleanup: Tracking, reduce scope of more variables --- source/blender/blenkernel/intern/tracking.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 0b732677dcb..37ca6b1885d 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -1276,15 +1276,14 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) sub_v2_v2v2(dim, pat_max, pat_min); for (int a = 0; a < 2; a++) { - int b; /* pattern shouldn't be moved outside of search */ if (pat_min[a] < marker->search_min[a]) { - for (b = 0; b < 4; b++) { + for (int b = 0; b < 4; b++) { marker->pattern_corners[b][a] += marker->search_min[a] - pat_min[a]; } } if (pat_max[a] > marker->search_max[a]) { - for (b = 0; b < 4; b++) { + for (int b = 0; b < 4; b++) { marker->pattern_corners[b][a] -= pat_max[a] - marker->search_max[a]; } } -- cgit v1.2.3 From dfa7e1cd9f6d495c6bdf01a140fdc59b0cced38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Feb 2020 12:58:01 +0100 Subject: Cleanup: reduced indentations by returning/continuing early No functional changes. --- source/blender/blenkernel/intern/fcurve.c | 394 +++++++++++++++--------------- 1 file changed, 196 insertions(+), 198 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 833b8409f7d..5708cb0379b 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -204,29 +204,31 @@ FCurve *id_data_find_fcurve( RNA_pointer_create(id, type, data, &ptr); prop = RNA_struct_find_property(&ptr, prop_name); + if (prop == NULL) { + return NULL; + } - if (prop) { - path = RNA_path_from_ID_to_property(&ptr, prop); - - if (path) { - /* animation takes priority over drivers */ - if ((adt->action) && (adt->action->curves.first)) { - fcu = list_find_fcurve(&adt->action->curves, path, index); - } + path = RNA_path_from_ID_to_property(&ptr, prop); + if (path == NULL) { + return NULL; + } - /* if not animated, check if driven */ - if ((fcu == NULL) && (adt->drivers.first)) { - fcu = list_find_fcurve(&adt->drivers, path, index); - if (fcu && r_driven) { - *r_driven = true; - } - fcu = NULL; - } + /* animation takes priority over drivers */ + if (adt->action && adt->action->curves.first) { + fcu = list_find_fcurve(&adt->action->curves, path, index); + } - MEM_freeN(path); + /* if not animated, check if driven */ + if (fcu == NULL && adt->drivers.first) { + fcu = list_find_fcurve(&adt->drivers, path, index); + if (fcu && r_driven) { + *r_driven = true; } + fcu = NULL; } + MEM_freeN(path); + return fcu; } @@ -309,26 +311,28 @@ int list_find_data_fcurves(ListBase *dst, /* search each F-Curve one by one */ for (fcu = src->first; fcu; fcu = fcu->next) { /* check if quoted string matches the path */ - if ((fcu->rna_path) && strstr(fcu->rna_path, dataPrefix)) { - char *quotedName = BLI_str_quoted_substrN(fcu->rna_path, dataPrefix); + if (fcu->rna_path == NULL || !strstr(fcu->rna_path, dataPrefix)) { + continue; + } - if (quotedName) { - /* check if the quoted name matches the required name */ - if (STREQ(quotedName, dataName)) { - LinkData *ld = MEM_callocN(sizeof(LinkData), __func__); + char *quotedName = BLI_str_quoted_substrN(fcu->rna_path, dataPrefix); + if (quotedName == NULL) { + continue; + } - ld->data = fcu; - BLI_addtail(dst, ld); + /* check if the quoted name matches the required name */ + if (STREQ(quotedName, dataName)) { + LinkData *ld = MEM_callocN(sizeof(LinkData), __func__); - matches++; - } + ld->data = fcu; + BLI_addtail(dst, ld); - /* always free the quoted string, since it needs freeing */ - MEM_freeN(quotedName); - } + matches++; } - } + /* always free the quoted string, since it needs freeing */ + MEM_freeN(quotedName); + } /* return the number of matches */ return matches; } @@ -397,53 +401,58 @@ FCurve *rna_get_fcurve_context_ui(bContext *C, /* Standard F-Curve - Animation (Action) or Drivers */ while (adt && step--) { - if ((adt->action && adt->action->curves.first) || (adt->drivers.first)) { - /* XXX this function call can become a performance bottleneck */ - if (step) { - path = RNA_path_from_ID_to_property(&tptr, prop); - } + if ((adt->action == NULL || adt->action->curves.first == NULL) && + (adt->drivers.first == NULL)) { + continue; + } - // XXX: the logic here is duplicated with a function up above - if (path) { - /* animation takes priority over drivers */ - if (adt->action && adt->action->curves.first) { - fcu = list_find_fcurve(&adt->action->curves, path, rnaindex); + /* XXX this function call can become a performance bottleneck */ + if (step) { + path = RNA_path_from_ID_to_property(&tptr, prop); + } + if (path == NULL) { + continue; + } - if (fcu && r_action) { - *r_action = adt->action; - } - } + // XXX: the logic here is duplicated with a function up above + /* animation takes priority over drivers */ + if (adt->action && adt->action->curves.first) { + fcu = list_find_fcurve(&adt->action->curves, path, rnaindex); - /* if not animated, check if driven */ - if (!fcu && (adt->drivers.first)) { - fcu = list_find_fcurve(&adt->drivers, path, rnaindex); + if (fcu && r_action) { + *r_action = adt->action; + } + } - if (fcu) { - if (r_animdata) { - *r_animdata = adt; - } - *r_driven = true; - } - } + /* if not animated, check if driven */ + if (!fcu && (adt->drivers.first)) { + fcu = list_find_fcurve(&adt->drivers, path, rnaindex); - if (fcu && r_action) { - if (r_animdata) { - *r_animdata = adt; - } - *r_action = adt->action; - break; - } - else if (step) { - char *tpath = BKE_animdata_driver_path_hack(C, &tptr, prop, path); - if (tpath && tpath != path) { - MEM_freeN(path); - path = tpath; - adt = BKE_animdata_from_id(tptr.owner_id); - } - else { - adt = NULL; - } + if (fcu) { + if (r_animdata) { + *r_animdata = adt; } + *r_driven = true; + } + } + + if (fcu && r_action) { + if (r_animdata) { + *r_animdata = adt; + } + *r_action = adt->action; + break; + } + + if (step) { + char *tpath = BKE_animdata_driver_path_hack(C, &tptr, prop, path); + if (tpath && tpath != path) { + MEM_freeN(path); + path = tpath; + adt = BKE_animdata_from_id(tptr.owner_id); + } + else { + adt = NULL; } } } @@ -476,29 +485,28 @@ static int binarysearch_bezt_index_ex( CLOG_WARN(&LOG, "encountered invalid array"); return 0; } - else { - /* check whether to add before/after/on */ - float framenum; - /* 'First' Keyframe (when only one keyframe, this case is used) */ - framenum = array[0].vec[1][0]; - if (IS_EQT(frame, framenum, threshold)) { - *r_replace = true; - return 0; - } - else if (frame < framenum) { - return 0; - } + /* check whether to add before/after/on */ + float framenum; - /* 'Last' Keyframe */ - framenum = array[(arraylen - 1)].vec[1][0]; - if (IS_EQT(frame, framenum, threshold)) { - *r_replace = true; - return (arraylen - 1); - } - else if (frame > framenum) { - return arraylen; - } + /* 'First' Keyframe (when only one keyframe, this case is used) */ + framenum = array[0].vec[1][0]; + if (IS_EQT(frame, framenum, threshold)) { + *r_replace = true; + return 0; + } + if (frame < framenum) { + return 0; + } + + /* 'Last' Keyframe */ + framenum = array[(arraylen - 1)].vec[1][0]; + if (IS_EQT(frame, framenum, threshold)) { + *r_replace = true; + return (arraylen - 1); + } + if (frame > framenum) { + return arraylen; } /* most of the time, this loop is just to find where to put it @@ -1171,41 +1179,42 @@ void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, const bool use_ha */ void sort_time_fcurve(FCurve *fcu) { + if (fcu->bezt == NULL) { + return; + } /* keep adjusting order of beztriples until nothing moves (bubble-sort) */ - if (fcu->bezt) { - BezTriple *bezt; - uint a; - - bool ok = true; - while (ok) { - ok = 0; - /* currently, will only be needed when there are beztriples */ - - /* loop over ALL points to adjust position in array and recalculate handles */ - for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { - /* check if thee's a next beztriple which we could try to swap with current */ - if (a < (fcu->totvert - 1)) { - /* swap if one is after the other (and indicate that order has changed) */ - if (bezt->vec[1][0] > (bezt + 1)->vec[1][0]) { - SWAP(BezTriple, *bezt, *(bezt + 1)); - ok = 1; - } + BezTriple *bezt; + uint a; + + bool ok = true; + while (ok) { + ok = 0; + /* currently, will only be needed when there are beztriples */ + + /* loop over ALL points to adjust position in array and recalculate handles */ + for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { + /* check if thee's a next beztriple which we could try to swap with current */ + if (a < (fcu->totvert - 1)) { + /* swap if one is after the other (and indicate that order has changed) */ + if (bezt->vec[1][0] > (bezt + 1)->vec[1][0]) { + SWAP(BezTriple, *bezt, *(bezt + 1)); + ok = 1; } } } + } - for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { - /* if either one of both of the points exceeds crosses over the keyframe time... */ - if ((bezt->vec[0][0] > bezt->vec[1][0]) && (bezt->vec[2][0] < bezt->vec[1][0])) { - /* swap handles if they have switched sides for some reason */ - swap_v2_v2(bezt->vec[0], bezt->vec[2]); - } - else { - /* clamp handles */ - CLAMP_MAX(bezt->vec[0][0], bezt->vec[1][0]); - CLAMP_MIN(bezt->vec[2][0], bezt->vec[1][0]); - } + for (a = 0, bezt = fcu->bezt; a < fcu->totvert; a++, bezt++) { + /* if either one of both of the points exceeds crosses over the keyframe time... */ + if ((bezt->vec[0][0] > bezt->vec[1][0]) && (bezt->vec[2][0] < bezt->vec[1][0])) { + /* swap handles if they have switched sides for some reason */ + swap_v2_v2(bezt->vec[0], bezt->vec[2]); + } + else { + /* clamp handles */ + CLAMP_MAX(bezt->vec[0][0], bezt->vec[1][0]); + CLAMP_MIN(bezt->vec[2][0], bezt->vec[1][0]); } } } @@ -2539,11 +2548,10 @@ static int findzero(float x, float q0, float q1, float q2, float q3, float *o) if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { return 1; } - else { - return 0; - } + return 0; } - else if (d == 0.0) { + + if (d == 0.0) { t = sqrt3d(-q); o[0] = (float)(2 * t - a); @@ -2555,87 +2563,78 @@ static int findzero(float x, float q0, float q1, float q2, float q3, float *o) if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { return nr + 1; } - else { - return nr; - } + return nr; } - else { - phi = acos(-q / sqrt(-(p * p * p))); - t = sqrt(-p); - p = cos(phi / 3); - q = sqrt(3 - 3 * p * p); - o[0] = (float)(2 * t * p - a); - if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { - nr++; - } - o[nr] = (float)(-t * (p + q) - a); + phi = acos(-q / sqrt(-(p * p * p))); + t = sqrt(-p); + p = cos(phi / 3); + q = sqrt(3 - 3 * p * p); + o[0] = (float)(2 * t * p - a); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { - nr++; - } - o[nr] = (float)(-t * (p - q) - a); + if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { + nr++; + } + o[nr] = (float)(-t * (p + q) - a); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { - return nr + 1; - } - else { - return nr; - } + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { + nr++; } - } - else { - a = c2; - b = c1; - c = c0; + o[nr] = (float)(-t * (p - q) - a); - if (a != 0.0) { - /* discriminant */ - p = b * b - 4 * a * c; + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { + return nr + 1; + } + return nr; + } + a = c2; + b = c1; + c = c0; - if (p > 0) { - p = sqrt(p); - o[0] = (float)((-b - p) / (2 * a)); + if (a != 0.0) { + /* discriminant */ + p = b * b - 4 * a * c; - if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { - nr++; - } - o[nr] = (float)((-b + p) / (2 * a)); + if (p > 0) { + p = sqrt(p); + o[0] = (float)((-b - p) / (2 * a)); - if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { - return nr + 1; - } - else { - return nr; - } + if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { + nr++; } - else if (p == 0) { - o[0] = (float)(-b / (2 * a)); - if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { - return 1; - } - else { - return 0; - } + o[nr] = (float)((-b + p) / (2 * a)); + + if ((o[nr] >= (float)SMALL) && (o[nr] <= 1.000001f)) { + return nr + 1; } + return nr; } - else if (b != 0.0) { - o[0] = (float)(-c / b); + if (p == 0) { + o[0] = (float)(-b / (2 * a)); if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { return 1; } - else { - return 0; - } } - else if (c == 0.0) { - o[0] = 0.0; + + return 0; + } + + if (b != 0.0) { + o[0] = (float)(-c / b); + + if ((o[0] >= (float)SMALL) && (o[0] <= 1.000001f)) { return 1; } - return 0; } + + if (c == 0.0) { + o[0] = 0.0; + return 1; + } + + return 0; } static void berekeny(float f1, float f2, float f3, float f4, float *o, int b) @@ -3244,19 +3243,18 @@ float calculate_fcurve(PathResolvedRNA *anim_rna, FCurve *fcu, float evaltime) /* only calculate + set curval (overriding the existing value) if curve has * any data which warrants this... */ - if (!BKE_fcurve_is_empty(fcu)) { - /* calculate and set curval (evaluates driver too if necessary) */ - float curval; - if (fcu->driver) { - curval = evaluate_fcurve_driver(anim_rna, fcu, fcu->driver, evaltime); - } - else { - curval = evaluate_fcurve(fcu, evaltime); - } - fcu->curval = curval; /* debug display only, not thread safe! */ - return curval; + if (BKE_fcurve_is_empty(fcu)) { + return 0.0f; + } + + /* calculate and set curval (evaluates driver too if necessary) */ + float curval; + if (fcu->driver) { + curval = evaluate_fcurve_driver(anim_rna, fcu, fcu->driver, evaltime); } else { - return 0.0f; + curval = evaluate_fcurve(fcu, evaltime); } + fcu->curval = curval; /* debug display only, not thread safe! */ + return curval; } -- cgit v1.2.3 From 3e738a60d06acc3ebecc8f4e23bf0262d7b57f3c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 7 Feb 2020 12:20:05 +0100 Subject: Cleanup: Tracking, reduce scope of variables --- source/blender/blenkernel/intern/tracking.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 37ca6b1885d..9caecb73e89 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -836,7 +836,7 @@ void BKE_tracking_tracks_join(MovieTracking *tracking, MovieTrackingMarker *marker_a, *marker_b; int start_a = a, start_b = b, len = 0, frame = src_track->markers[a].framenr; - int j, inverse = 0; + int inverse = 0; inverse = (b == 0) || (dst_track->markers[b - 1].flag & MARKER_DISABLED) || (dst_track->markers[b - 1].framenr != frame - 1); @@ -864,7 +864,7 @@ void BKE_tracking_tracks_join(MovieTracking *tracking, b = start_b; /* linear interpolation for intersecting frames */ - for (j = 0; j < len; j++) { + for (int j = 0; j < len; j++) { float fac = 0.5f; if (len > 1) { @@ -2897,8 +2897,6 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) bool show_hidden = (dopesheet->flag & TRACKING_DOPE_SHOW_HIDDEN) != 0; for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { - MovieTrackingDopesheetChannel *channel; - if (!show_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; } @@ -2907,7 +2905,8 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) continue; } - channel = MEM_callocN(sizeof(MovieTrackingDopesheetChannel), "tracking dopesheet channel"); + MovieTrackingDopesheetChannel *channel = MEM_callocN(sizeof(MovieTrackingDopesheetChannel), + "tracking dopesheet channel"); channel->track = track; if (reconstruction->flag & TRACKING_RECONSTRUCTED) { -- cgit v1.2.3 From f81fe8a3a0711a416091081b5e25256031d94e77 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 7 Feb 2020 12:51:18 +0100 Subject: Cleanup: Tracking, use LISTBASE_FOREACH Makes loops declaration shorter and cleaner. --- source/blender/blenkernel/intern/tracking.c | 46 +++++++++------------- source/blender/blenkernel/intern/tracking_auto.c | 11 +++--- source/blender/blenkernel/intern/tracking_solver.c | 2 +- .../blender/blenkernel/intern/tracking_stabilize.c | 18 ++++----- 4 files changed, 33 insertions(+), 44 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 9caecb73e89..86fb2ab58bc 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -80,7 +80,7 @@ static struct { /* Free the whole list of tracks, list's head and tail are set to NULL. */ static void tracking_tracks_free(ListBase *tracks) { - for (MovieTrackingTrack *track = tracks->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) { BKE_tracking_track_free(track); } @@ -90,8 +90,7 @@ static void tracking_tracks_free(ListBase *tracks) /* Free the whole list of plane tracks, list's head and tail are set to NULL. */ static void tracking_plane_tracks_free(ListBase *plane_tracks) { - for (MovieTrackingPlaneTrack *plane_track = plane_tracks->first; plane_track; - plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks) { BKE_tracking_plane_track_free(plane_track); } @@ -126,7 +125,7 @@ static void tracking_object_free(MovieTrackingObject *object) static void tracking_objects_free(ListBase *objects) { /* Free objects contents. */ - for (MovieTrackingObject *object = objects->first; object; object = object->next) { + LISTBASE_FOREACH (MovieTrackingObject *, object, objects) { tracking_object_free(object); } @@ -189,8 +188,7 @@ static void tracking_tracks_copy(ListBase *tracks_dst, BLI_listbase_clear(tracks_dst); BLI_ghash_clear(tracks_mapping, NULL, NULL); - for (MovieTrackingTrack *track_src = tracks_src->first; track_src != NULL; - track_src = track_src->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track_src, tracks_src) { MovieTrackingTrack *track_dst = MEM_dupallocN(track_src); if (track_src->markers) { track_dst->markers = MEM_dupallocN(track_src->markers); @@ -213,9 +211,7 @@ static void tracking_plane_tracks_copy(ListBase *plane_tracks_list_dst, { BLI_listbase_clear(plane_tracks_list_dst); - for (MovieTrackingPlaneTrack *plane_track_src = plane_tracks_list_src->first; - plane_track_src != NULL; - plane_track_src = plane_track_src->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track_src, plane_tracks_list_src) { MovieTrackingPlaneTrack *plane_track_dst = MEM_dupallocN(plane_track_src); if (plane_track_src->markers) { plane_track_dst->markers = MEM_dupallocN(plane_track_src->markers); @@ -273,8 +269,7 @@ static void tracking_objects_copy(ListBase *objects_dst, { BLI_listbase_clear(objects_dst); - for (MovieTrackingObject *object_src = objects_src->first; object_src != NULL; - object_src = object_src->next) { + LISTBASE_FOREACH (MovieTrackingObject *, object_src, objects_src) { MovieTrackingObject *object_dst = MEM_mallocN(sizeof(*object_dst), __func__); tracking_object_copy(object_dst, object_src, tracks_mapping, flag); BLI_addtail(objects_dst, object_dst); @@ -1172,7 +1167,7 @@ void BKE_tracking_track_deselect(MovieTrackingTrack *track, int area) void BKE_tracking_tracks_deselect_all(ListBase *tracksbase) { - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if ((track->flag & TRACK_HIDDEN) == 0) { BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); } @@ -1445,15 +1440,14 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking, { MovieTrackingPlaneTrack *plane_track; MovieTrackingPlaneMarker plane_marker; - MovieTrackingTrack *track; float tracks_min[2], tracks_max[2]; - int track_index, num_selected_tracks = 0; + int num_selected_tracks = 0; (void)tracking; /* Ignored. */ /* Use bounding box of selected markers as an initial size of plane. */ INIT_MINMAX2(tracks_min, tracks_max); - for (track = tracks->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) { if (TRACK_SELECTED(track)) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); float pattern_min[2], pattern_max[2]; @@ -1481,7 +1475,8 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking, /* Use selected tracks from given list as a plane. */ plane_track->point_tracks = MEM_mallocN(sizeof(MovieTrackingTrack *) * num_selected_tracks, "new plane tracks array"); - for (track = tracks->first, track_index = 0; track; track = track->next) { + int track_index = 0; + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) { if (TRACK_SELECTED(track)) { plane_track->point_tracks[track_index] = track; track_index++; @@ -1541,8 +1536,7 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(MovieTracking *track { ListBase *plane_tracks_base = BKE_tracking_object_get_plane_tracks(tracking, object); - for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; - plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if (STREQ(plane_track->name, name)) { return plane_track; } @@ -1569,8 +1563,7 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTrackin void BKE_tracking_plane_tracks_deselect_all(ListBase *plane_tracks_base) { - for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; - plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { plane_track->flag &= ~SELECT; } } @@ -1612,10 +1605,8 @@ bool BKE_tracking_plane_track_remove_point_track(MovieTrackingPlaneTrack *plane_ void BKE_tracking_plane_tracks_remove_point_track(MovieTracking *tracking, MovieTrackingTrack *track) { - MovieTrackingPlaneTrack *plane_track, *next_plane_track; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); - for (plane_track = plane_tracks_base->first; plane_track; plane_track = next_plane_track) { - next_plane_track = plane_track->next; + LISTBASE_FOREACH_MUTABLE (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if (BKE_tracking_plane_track_has_point_track(plane_track, track)) { if (!BKE_tracking_plane_track_remove_point_track(plane_track, track)) { /* Delete planes with less than 3 point tracks in it. */ @@ -1643,8 +1634,7 @@ void BKE_tracking_plane_tracks_replace_point_track(MovieTracking *tracking, MovieTrackingTrack *new_track) { ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking); - for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; - plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if (BKE_tracking_plane_track_has_point_track(plane_track, old_track)) { BKE_tracking_plane_track_replace_point_track(plane_track, old_track, new_track); } @@ -2896,7 +2886,7 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking) bool sel_only = (dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY) != 0; bool show_hidden = (dopesheet->flag & TRACKING_DOPE_SHOW_HIDDEN) != 0; - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (!show_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; } @@ -2988,7 +2978,7 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking) int prev_coverage, last_segment_frame; /* find frame boundaries */ - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { start_frame = min_ii(start_frame, track->markers[0].framenr); end_frame = max_ii(end_frame, track->markers[track->markersnr - 1].framenr); } @@ -2999,7 +2989,7 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking) per_frame_counter = MEM_callocN(sizeof(int) * frames, "per frame track counter"); /* find per-frame markers count */ - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = &track->markers[i]; diff --git a/source/blender/blenkernel/intern/tracking_auto.c b/source/blender/blenkernel/intern/tracking_auto.c index 1a4df73c8aa..9d8395defcd 100644 --- a/source/blender/blenkernel/intern/tracking_auto.c +++ b/source/blender/blenkernel/intern/tracking_auto.c @@ -258,7 +258,7 @@ static void fill_autotrack_tracks(const int frame_width, { /* Count number of markers to be put to a context. */ size_t num_trackable_markers = 0; - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { for (int i = 0; i < track->markersnr; i++) { const MovieTrackingMarker *marker = track->markers + i; if ((marker->flag & MARKER_DISABLED) == 0) { @@ -275,7 +275,7 @@ static void fill_autotrack_tracks(const int frame_width, "libmv markers array"); /* Fill in markers array. */ int track_index = 0, num_filled_libmv_markers = 0; - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = track->markers + i; if ((marker->flag & MARKER_DISABLED) != 0) { @@ -305,7 +305,7 @@ static void create_per_track_tracking_options(const MovieClip *clip, AutoTrackContext *context) { /* Count number of trackable tracks. */ - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (check_track_trackable(clip, track, user)) { context->num_tracks++; } @@ -315,7 +315,7 @@ static void create_per_track_tracking_options(const MovieClip *clip, "auto track options"); /* Fill in all the settings. */ int i = 0, track_index = 0; - for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (!check_track_trackable(clip, track, user)) { track_index++; continue; @@ -523,8 +523,7 @@ void BKE_autotrack_context_finish(AutoTrackContext *context) MovieClip *clip = context->clips[clip_index]; ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(&clip->tracking); - for (MovieTrackingPlaneTrack *plane_track = plane_tracks_base->first; plane_track; - plane_track = plane_track->next) { + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { if ((plane_track->flag & PLANE_TRACK_AUTOKEY) == 0) { for (int track = 0; track < context->num_tracks; track++) { if (BKE_tracking_plane_track_has_point_track(plane_track, diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c index bedb55ae44e..527a2f59491 100644 --- a/source/blender/blenkernel/intern/tracking_solver.c +++ b/source/blender/blenkernel/intern/tracking_solver.c @@ -613,7 +613,7 @@ static void tracking_scale_reconstruction(ListBase *tracksbase, */ void BKE_tracking_reconstruction_scale(MovieTracking *tracking, float scale[3]) { - for (MovieTrackingObject *object = tracking->objects.first; object; object = object->next) { + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object); MovieTrackingReconstruction *reconstruction = BKE_tracking_object_get_reconstruction(tracking, object); diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c index d2d60e93a08..b5b33353ed7 100644 --- a/source/blender/blenkernel/intern/tracking_stabilize.c +++ b/source/blender/blenkernel/intern/tracking_stabilize.c @@ -34,6 +34,7 @@ #include "BLI_sort_utils.h" #include "BLI_ghash.h" #include "BLI_math_vector.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_task.h" @@ -332,8 +333,7 @@ static void find_next_working_frames(StabContext *ctx, int *next_lower, int *next_higher) { - for (MovieTrackingTrack *track = ctx->tracking->tracks.first; track != NULL; - track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &ctx->tracking->tracks) { if (is_usable_for_stabilization(ctx, track)) { int startpoint = search_closest_marker_index(track, framenr); retrieve_next_higher_usable_frame(ctx, track, startpoint, framenr, next_higher); @@ -558,7 +558,7 @@ static bool average_track_contributions(StabContext *ctx, ok = false; weight_sum = 0.0f; - for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { if (!is_init_for_stabilization(ctx, track)) { continue; } @@ -596,7 +596,7 @@ static bool average_track_contributions(StabContext *ctx, ok = false; weight_sum = 0.0f; - for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { if (!is_init_for_stabilization(ctx, track)) { continue; } @@ -655,7 +655,7 @@ static void average_marker_positions(StabContext *ctx, int framenr, float r_ref_ zero_v2(r_ref_pos); weight_sum = 0.0f; - for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { if (track->flag & TRACK_USE_2D_STAB) { float weight = 0.0f; MovieTrackingMarker *marker = get_tracking_data_point(ctx, track, framenr, &weight); @@ -678,7 +678,7 @@ static void average_marker_positions(StabContext *ctx, int framenr, float r_ref_ int next_lower = MINAFRAME; int next_higher = MAXFRAME; use_values_from_fcurves(ctx, true); - for (MovieTrackingTrack *track = tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { /* Note: we deliberately do not care if this track * is already initialized for stabilization. */ if (track->flag & TRACK_USE_2D_STAB) { @@ -772,7 +772,7 @@ static int establish_track_initialization_order(StabContext *ctx, TrackInitOrder MovieTracking *tracking = ctx->tracking; int anchor_frame = tracking->stabilization.anchor_frame; - for (MovieTrackingTrack *track = tracking->tracks.first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { MovieTrackingMarker *marker; order[tracknr].data = track; marker = get_closest_marker(ctx, track, anchor_frame); @@ -892,7 +892,7 @@ static void initialize_all_tracks(StabContext *ctx, float aspect) zero_v2(pivot); /* Initialize private working data. */ - for (MovieTrackingTrack *track = tracking->tracks.first; track != NULL; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) { TrackStabilizationBase *local_data = access_stabilization_baseline_data(ctx, track); if (!local_data) { local_data = MEM_callocN(sizeof(TrackStabilizationBase), @@ -1142,7 +1142,7 @@ static float calculate_autoscale_factor(StabContext *ctx, int size, float aspect float scale = 1.0f, scale_step = 0.0f; /* Calculate maximal frame range of tracks where stabilization is active. */ - for (MovieTrackingTrack *track = ctx->tracking->tracks.first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, &ctx->tracking->tracks) { if ((track->flag & TRACK_USE_2D_STAB) || ((stab->flag & TRACKING_STABILIZE_ROTATION) && (track->flag & TRACK_USE_2D_STAB_ROT))) { int first_frame = track->markers[0].framenr; -- cgit v1.2.3 From 6dc9f89c6a06f3e7870177c5067f58520c6d275c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 7 Feb 2020 13:52:01 +0100 Subject: Constraint: Fix forced request of evaluated camera Constraint stack similarly to modifier stack is fully operate on what have been given to it, without requesting original or evaluated IDs. Validness of datablocks passed to constraint stack are to be handled on dependency graph/evaluation stream levels. --- source/blender/blenkernel/intern/constraint.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index a17a09297c5..708d0600e91 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -4557,9 +4557,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase MovieTracking *tracking; MovieTrackingTrack *track; MovieTrackingObject *tracking_object; - - Object *camob_eval = DEG_get_evaluated_object(depsgraph, - data->camera ? data->camera : scene->camera); + Object *camob = data->camera ? data->camera : scene->camera; float ctime = DEG_get_ctime(depsgraph); float framenr; @@ -4568,7 +4566,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase clip = scene->clip; } - if (!clip || !data->track[0] || !camob_eval) { + if (!clip || !data->track[0] || !camob) { return; } @@ -4602,7 +4600,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) { float imat[4][4]; - copy_m4_m4(mat, camob_eval->obmat); + copy_m4_m4(mat, camob->obmat); BKE_tracking_camera_get_reconstructed_interpolate( tracking, tracking_object, framenr, imat); @@ -4613,7 +4611,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]); } else { - BKE_tracking_get_camera_object_matrix(cob->scene, camob_eval, mat); + BKE_tracking_get_camera_object_matrix(cob->scene, camob, mat); mul_m4_m4m4(cob->matrix, obmat, mat); translate_m4( @@ -4626,7 +4624,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); float len, d; - BKE_object_where_is_calc_mat4(camob_eval, mat); + BKE_object_where_is_calc_mat4(camob, mat); /* camera axis */ vec[0] = 0.0f; @@ -4694,7 +4692,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase } BKE_camera_params_init(¶ms); - BKE_camera_params_from_object(¶ms, camob_eval); + BKE_camera_params_from_object(¶ms, camob); if (params.is_ortho) { vec[0] = params.ortho_scale * (pos[0] - 0.5f + params.shiftx); @@ -4708,9 +4706,9 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase vec[0] *= aspect; } - mul_v3_m4v3(disp, camob_eval->obmat, vec); + mul_v3_m4v3(disp, camob->obmat, vec); - copy_m4_m4(rmat, camob_eval->obmat); + copy_m4_m4(rmat, camob->obmat); zero_v3(rmat[3]); mul_m4_m4m4(cob->matrix, cob->matrix, rmat); @@ -4730,10 +4728,10 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase vec[0] *= aspect; } - mul_v3_m4v3(disp, camob_eval->obmat, vec); + mul_v3_m4v3(disp, camob->obmat, vec); /* apply camera rotation so Z-axis would be co-linear */ - copy_m4_m4(rmat, camob_eval->obmat); + copy_m4_m4(rmat, camob->obmat); zero_v3(rmat[3]); mul_m4_m4m4(cob->matrix, cob->matrix, rmat); @@ -4751,7 +4749,7 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase invert_m4_m4(imat, depth_ob->obmat); - mul_v3_m4v3(ray_start, imat, camob_eval->obmat[3]); + mul_v3_m4v3(ray_start, imat, camob->obmat[3]); mul_v3_m4v3(ray_end, imat, cob->matrix[3]); sub_v3_v3v3(ray_nor, ray_end, ray_start); -- cgit v1.2.3 From ccda7ef9961314a7e60a3f81bd63171dbde0019c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Feb 2020 13:56:04 +0100 Subject: Cleanup: Animation, match parameter names in declaration with implementation The implementation had more descriptive parameter names, so I copied those to the declarations. No functional changes. --- source/blender/blenkernel/BKE_fcurve.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 405b052f477..d389b557503 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -87,7 +87,7 @@ void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt); void fcurve_free_driver(struct FCurve *fcu); struct ChannelDriver *fcurve_copy_driver(const struct ChannelDriver *driver); -void driver_variables_copy(struct ListBase *dst_list, const struct ListBase *src_list); +void driver_variables_copy(struct ListBase *dst_vars, const struct ListBase *src_vars); void BKE_driver_target_matrix_to_rot_channels( float mat[4][4], int auto_order, int rotation_mode, int channel, bool angles, float r_buf[4]); @@ -280,7 +280,7 @@ struct FCurve *rna_get_fcurve_context_ui(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, - struct AnimData **r_adt, + struct AnimData **r_animdata, struct bAction **r_action, bool *r_driven, bool *r_special); -- cgit v1.2.3 From b40ac820524b1fa7124c38ebd2ac02beb23c048a Mon Sep 17 00:00:00 2001 From: mano-wii Date: Fri, 7 Feb 2020 10:02:11 -0300 Subject: Cleanup: transform_convert comment and spacing --- .../blender/editors/transform/transform_convert.h | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source') diff --git a/source/blender/editors/transform/transform_convert.h b/source/blender/editors/transform/transform_convert.h index 53ff9952d05..e81a896e062 100644 --- a/source/blender/editors/transform/transform_convert.h +++ b/source/blender/editors/transform/transform_convert.h @@ -19,6 +19,7 @@ /** \file * \ingroup edtransform + * \brief conversion and adaptation of different datablocks to a common struct. */ #ifndef __TRANSFORM_CONVERT_H__ @@ -60,28 +61,38 @@ void clipUVData(TransInfo *t); /* transform_convert_action.c */ void flushTransIntFrameActionData(TransInfo *t); + /* transform_convert_armature.c */ void restoreMirrorPoseBones(TransDataContainer *tc); void restoreBones(TransDataContainer *tc); + /* transform_convert_graph.c */ void flushTransGraphData(TransInfo *t); + /* transform_convert_mask.c */ void flushTransMasking(TransInfo *t); + /* transform_convert_mesh.c */ void flushTransUVs(TransInfo *t); void trans_mesh_customdata_correction_init(TransInfo *t); void trans_mesh_customdata_correction_apply(struct TransDataContainer *tc, bool is_final); + /* transform_convert_node.c */ void flushTransNodes(TransInfo *t); + /* transform_convert_object.c */ void trans_obdata_in_obmode_update_all(struct TransInfo *t); void trans_obchild_in_obmode_update_all(struct TransInfo *t); + /* transform_convert_paintcurve.c */ void flushTransPaintCurve(TransInfo *t); + /* transform_convert_particle.c */ void flushTransParticles(TransInfo *t); + /* transform_convert_sequencer.c */ void flushTransSeq(TransInfo *t); + /* transform_convert_tracking.c */ void flushTransTracking(TransInfo *t); @@ -96,45 +107,62 @@ bool FrameOnMouseSide(char side, float frame, float cframe); /* transform_convert_action.c */ void createTransActionData(bContext *C, TransInfo *t); + /* transform_convert_armature.c */ struct bKinematicConstraint *has_targetless_ik(struct bPoseChannel *pchan); void createTransPose(TransInfo *t); void createTransArmatureVerts(TransInfo *t); + /* transform_convert_cursor.c */ void createTransCursor_image(TransInfo *t); void createTransCursor_view3d(TransInfo *t); + /* transform_convert_curve.c */ void createTransCurveVerts(TransInfo *t); + /* transform_convert_graph.c */ void createTransGraphEditData(bContext *C, TransInfo *t); + /* transform_convert_gpencil.c */ void createTransGPencil(bContext *C, TransInfo *t); + /* transform_convert_lattice.c */ void createTransLatticeVerts(TransInfo *t); + /* transform_convert_mask.c */ void createTransMaskingData(bContext *C, TransInfo *t); + /* transform_convert_mball.c */ void createTransMBallVerts(TransInfo *t); + /* transform_convert_mesh.c */ void createTransEditVerts(TransInfo *t); void createTransEdge(TransInfo *t); void createTransUVs(bContext *C, TransInfo *t); + /* transform_convert_nla.c */ void createTransNlaData(bContext *C, TransInfo *t); + /* transform_convert_node.c */ void createTransNodeData(bContext *UNUSED(C), TransInfo *t); + /* transform_convert_object.c */ void clear_trans_object_base_flags(TransInfo *t); void createTransObject(bContext *C, TransInfo *t); void createTransTexspace(TransInfo *t); + /* transform_convert_paintcurve.c */ void createTransPaintCurveVerts(bContext *C, TransInfo *t); + /* transform_convert_particle.c */ void createTransParticleVerts(bContext *C, TransInfo *t); + /* transform_convert_sculpt.c */ void createTransSculpt(TransInfo *t); + /* transform_convert_sequence.c */ void createTransSeqData(bContext *C, TransInfo *t); + /* transform_convert_tracking.c */ void createTransTrackingData(bContext *C, TransInfo *t); void cancelTransTracking(TransInfo *t); -- cgit v1.2.3 From 636fe3df0e95999d5a2029c913a8812fd95fe25a Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 7 Feb 2020 14:14:50 +0100 Subject: CodeCleanup: Workbench Code was already hidden by a compile directive. --- .../draw/engines/workbench/workbench_forward.c | 2 +- .../draw/engines/workbench/workbench_studiolight.c | 57 ---------------------- 2 files changed, 1 insertion(+), 58 deletions(-) (limited to 'source') diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c index fcdf24d2d2f..05494b79af0 100644 --- a/source/blender/draw/engines/workbench/workbench_forward.c +++ b/source/blender/draw/engines/workbench/workbench_forward.c @@ -665,7 +665,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob) return; } - WORKBENCH_MaterialData *material; + WORKBENCH_MaterialData *material = NULL; if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) && !DRW_state_is_image_render(); diff --git a/source/blender/draw/engines/workbench/workbench_studiolight.c b/source/blender/draw/engines/workbench/workbench_studiolight.c index 941a6741998..1fb0b394cb1 100644 --- a/source/blender/draw/engines/workbench/workbench_studiolight.c +++ b/source/blender/draw/engines/workbench/workbench_studiolight.c @@ -69,63 +69,6 @@ void studiolight_update_world(WORKBENCH_PrivateData *wpd, } copy_v3_v3(wd->ambient_color, studiolight->light_ambient); - -#if 0 - BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED); - -# if STUDIOLIGHT_SH_BANDS == 2 - /* Use Geomerics non-linear SH. */ - mul_v3_v3fl(wd->spherical_harmonics_coefs[0], sl->spherical_harmonics_coefs[0], M_1_PI); - /* Swizzle to make shader code simpler. */ - for (int i = 0; i < 3; i++) { - copy_v3_fl3(wd->spherical_harmonics_coefs[i + 1], - -sl->spherical_harmonics_coefs[3][i], - sl->spherical_harmonics_coefs[2][i], - -sl->spherical_harmonics_coefs[1][i]); - - /* 1.5f is to improve the contrast a bit. */ - mul_v3_fl(wd->spherical_harmonics_coefs[i + 1], M_1_PI * 1.5f); - } - - /* Precompute as much as we can. See shader code for derivation. */ - float len_r1[3], lr1_r0[3], p[3], a[3]; - for (int i = 0; i < 3; i++) { - mul_v3_fl(wd->spherical_harmonics_coefs[i + 1], 0.5f); - len_r1[i] = len_v3(wd->spherical_harmonics_coefs[i + 1]); - mul_v3_fl(wd->spherical_harmonics_coefs[i + 1], 1.0f / len_r1[i]); - } - /* lr1_r0 = lenR1 / R0; */ - copy_v3_v3(lr1_r0, wd->spherical_harmonics_coefs[0]); - invert_v3(lr1_r0); - mul_v3_v3(lr1_r0, len_r1); - /* p = 1.0 + 2.0 * lr1_r0; */ - copy_v3_v3(p, lr1_r0); - mul_v3_fl(p, 2.0f); - add_v3_fl(p, 1.0f); - /* a = (1.0 - lr1_r0) / (1.0 + lr1_r0); */ - copy_v3_v3(a, lr1_r0); - add_v3_fl(a, 1.0f); - invert_v3(a); - negate_v3(lr1_r0); - add_v3_fl(lr1_r0, 1.0f); - mul_v3_v3(a, lr1_r0); - /* sh_coefs[4] = p; */ - copy_v3_v3(wd->spherical_harmonics_coefs[4], p); - /* sh_coefs[5] = R0 * a; */ - mul_v3_v3v3(wd->spherical_harmonics_coefs[5], wd->spherical_harmonics_coefs[0], a); - /* sh_coefs[0] = R0 * (1.0 - a) * (p + 1.0); */ - negate_v3(a); - add_v3_fl(a, 1.0f); - add_v3_fl(p, 1.0f); - mul_v3_v3(a, p); - mul_v3_v3(wd->spherical_harmonics_coefs[0], a); -# else - for (int i = 0; i < STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN; i++) { - /* Can't memcpy because of alignment */ - copy_v3_v3(wd->spherical_harmonics_coefs[i], sl->spherical_harmonics_coefs[i]); - } -# endif -#endif } static void compute_parallel_lines_nor_and_dist(const float v1[2], -- cgit v1.2.3 From 91c64b5ca330e1e940a9b60507b30e7aff54c7be Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 7 Feb 2020 14:19:08 +0100 Subject: CodeCleanup: Remove unused studiolight algorithm Code was originally added to test a different approach to calculate the irradiance buffer. The approach was just to slow so we never used it. This change will remove it from the code base --- source/blender/blenkernel/intern/studiolight.c | 62 -------------------------- 1 file changed, 62 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c index 9008348ed3b..4a69fcfa9d0 100644 --- a/source/blender/blenkernel/intern/studiolight.c +++ b/source/blender/blenkernel/intern/studiolight.c @@ -56,17 +56,6 @@ static int last_studiolight_id = 0; #define STUDIOLIGHT_IRRADIANCE_EQUIRECT_WIDTH (STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT * 2) #define STUDIOLIGHT_PASSNAME_DIFFUSE "diffuse" #define STUDIOLIGHT_PASSNAME_SPECULAR "specular" -/* - * The method to calculate the irradiance buffers - * The irradiance buffer is only shown in the background when in LookDev. - * - * STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE is very slow, but very accurate - * STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS is faster but has artifacts - * Cannot have both enabled at the same time!!! - */ -// #define STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE -#define STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS - /* Temporarily disabled due to the creation of textures with -nan(ind)s */ #define STUDIOLIGHT_SH_WINDOWING 0.0f /* 0.0 is disabled */ @@ -1024,40 +1013,6 @@ BLI_INLINE void studiolight_evaluate_specular_radiance_buffer(ImBuf *radiance_bu madd_v3_v3fl(color, accum, 1.0f / accum_weight); } -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE -static void studiolight_irradiance_eval(StudioLight *sl, float color[3], const float normal[3]) -{ - copy_v3_fl(color, 0.0f); - - /* XXX: This is madness, iterating over all cubemap pixels for each destination pixels - * even if their weight is 0.0f. - * It should use hemisphere, cosine sampling at least. */ - - /* back */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Y_POS], normal, color, 0, 2, 1, 1); - /* front */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Y_NEG], normal, color, 0, 2, 1, -1); - - /* left */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_X_POS], normal, color, 1, 2, 0, 1); - /* right */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_X_NEG], normal, color, 1, 2, 0, -1); - - /* top */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Z_POS], normal, color, 0, 1, 2, 1); - /* bottom */ - studiolight_evaluate_specular_radiance_buffer( - sl->radiance_cubemap_buffers[STUDIOLIGHT_Z_NEG], normal, color, 0, 1, 2, -1); - - mul_v3_fl(color, 1.0 / M_PI); -} -#endif - static float brdf_approx(float spec_color, float roughness, float NV) { /* Very rough own approx. We don't need it to be correct, just fast. @@ -1185,11 +1140,7 @@ static bool studiolight_load_spherical_harmonics_coefficients(StudioLight *sl) static void studiolight_calculate_irradiance_equirect_image(StudioLight *sl) { if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) { -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED); -#else BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED); -#endif float *colbuf = MEM_mallocN(STUDIOLIGHT_IRRADIANCE_EQUIRECT_WIDTH * STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT * sizeof(float[4]), @@ -1202,11 +1153,7 @@ static void studiolight_calculate_irradiance_equirect_image(StudioLight *sl) STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT) { float dir[3]; equirect_to_direction(dir, x, y); -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - studiolight_irradiance_eval(sl, pixel, dir); -#else studiolight_spherical_harmonics_eval(sl, pixel, dir); -#endif pixel[3] = 1.0f; } ITER_PIXELS_END; @@ -1217,15 +1164,6 @@ static void studiolight_calculate_irradiance_equirect_image(StudioLight *sl) STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT, 4); MEM_freeN(colbuf); - -#ifdef STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - /* - * Only store cached files when using STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE - */ - if (sl->flag & STUDIOLIGHT_USER_DEFINED) { - IMB_saveiff(sl->equirect_irradiance_buffer, sl->path_irr_cache, IB_rectfloat); - } -#endif } sl->flag |= STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED; } -- cgit v1.2.3 From 80415ee2031f1b1b9ef38774fa9a297f7a5018aa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 8 Feb 2020 00:38:40 +1100 Subject: Cleanup: remove legacy OpenGL viewport clipping code --- source/blender/editors/space_view3d/view3d_draw.c | 30 +++-------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 6704fc9908f..d092de4fcce 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1947,45 +1947,23 @@ bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip); } -/* Legacy 2.7x, now use shaders that use clip distance instead. - * Remove once clipping is working properly. */ -#define USE_CLIP_PLANES - -void ED_view3d_clipping_set(RegionView3D *rv3d) +void ED_view3d_clipping_set(RegionView3D *UNUSED(rv3d)) { -#ifdef USE_CLIP_PLANES - double plane[4]; - const uint tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6; - - for (unsigned a = 0; a < tot; a++) { - copy_v4db_v4fl(plane, rv3d->clip[a]); - glClipPlane(GL_CLIP_PLANE0 + a, plane); - glEnable(GL_CLIP_PLANE0 + a); - glEnable(GL_CLIP_DISTANCE0 + a); - } -#else - for (unsigned a = 0; a < 6; a++) { + for (uint a = 0; a < 6; a++) { glEnable(GL_CLIP_DISTANCE0 + a); } -#endif } /* Use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set. */ void ED_view3d_clipping_disable(void) { - for (unsigned a = 0; a < 6; a++) { -#ifdef USE_CLIP_PLANES - glDisable(GL_CLIP_PLANE0 + a); -#endif + for (uint a = 0; a < 6; a++) { glDisable(GL_CLIP_DISTANCE0 + a); } } void ED_view3d_clipping_enable(void) { - for (unsigned a = 0; a < 6; a++) { -#ifdef USE_CLIP_PLANES - glEnable(GL_CLIP_PLANE0 + a); -#endif + for (uint a = 0; a < 6; a++) { glEnable(GL_CLIP_DISTANCE0 + a); } } -- cgit v1.2.3 From 6f3e498e7d5e0c772ef795e7301dd332bccada22 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 8 Feb 2020 01:02:18 +1100 Subject: Cleanup: use of 'unsigned' - Replace 'unsigned' used on it's own with 'uint'. - Replace 'unsigned const char' with 'const uchar'. --- source/blender/blenkernel/BKE_mesh.h | 4 +- source/blender/blenkernel/BKE_paint.h | 5 +- source/blender/blenkernel/intern/mask_evaluate.c | 2 +- source/blender/blenkernel/intern/mesh.c | 2 +- source/blender/blenkernel/intern/paint.c | 4 +- source/blender/blenkernel/intern/pbvh.c | 2 +- source/blender/blenlib/BLI_math_color_blend.h | 64 +++---- source/blender/blenlib/intern/BLI_ghash.c | 10 +- source/blender/blenlib/intern/math_base_inline.c | 2 +- .../blenlib/intern/math_color_blend_inline.c | 200 ++++++++------------- source/blender/blenlib/intern/math_vector.c | 34 ++-- source/blender/blenlib/intern/string_utf8.c | 2 +- source/blender/bmesh/intern/bmesh_log.c | 14 +- .../blender/bmesh/intern/bmesh_polygon_edgenet.c | 2 +- source/blender/bmesh/intern/bmesh_private.h | 2 +- source/blender/bmesh/operators/bmo_connect.c | 2 +- source/blender/bmesh/operators/bmo_fill_grid.c | 2 +- .../blender/bmesh/operators/bmo_join_triangles.c | 2 +- .../bmesh/tools/bmesh_decimate_unsubdivide.c | 4 +- source/blender/collada/MeshImporter.cpp | 4 +- source/blender/editors/include/ED_node.h | 2 +- source/blender/editors/include/ED_view3d.h | 2 +- source/blender/editors/interface/view2d.c | 2 +- source/blender/editors/object/object_vgroup.c | 10 +- source/blender/editors/screen/area.c | 2 +- source/blender/editors/sculpt_paint/sculpt.c | 10 +- source/blender/editors/space_graph/graph_draw.c | 21 +-- source/blender/editors/space_image/image_draw.c | 26 +-- source/blender/editors/space_node/drawnode.c | 25 ++- source/blender/editors/space_node/node_draw.c | 12 +- .../blender/editors/space_outliner/outliner_draw.c | 14 +- source/blender/editors/space_view3d/drawobject.c | 2 +- source/blender/modifiers/intern/MOD_screw.c | 2 +- source/blender/windowmanager/intern/wm_cursors.c | 11 +- 34 files changed, 217 insertions(+), 287 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 570541eb990..d6934e8a7da 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -91,9 +91,7 @@ struct Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap( float (*vertexCos)[3], const struct Mesh *me_settings); -int poly_find_loop_from_vert(const struct MPoly *poly, - const struct MLoop *loopstart, - unsigned vert); +int poly_find_loop_from_vert(const struct MPoly *poly, const struct MLoop *loopstart, uint vert); int poly_get_adj_loops_from_vert(const struct MPoly *poly, const struct MLoop *mloop, unsigned int vert, diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index db35fbde2c8..28e564f0fe2 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -194,10 +194,7 @@ bool paint_is_grid_face_hidden(const unsigned int *grid_hidden, int gridsize, in bool paint_is_bmesh_face_hidden(struct BMFace *f); /* paint masks */ -float paint_grid_paint_mask(const struct GridPaintMask *gpm, - unsigned level, - unsigned x, - unsigned y); +float paint_grid_paint_mask(const struct GridPaintMask *gpm, uint level, uint x, uint y); /* stroke related */ bool paint_calculate_rake_rotation(struct UnifiedPaintSettings *ups, diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index f4f93fcb698..cb8b3b5ecc9 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -198,7 +198,7 @@ float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, float (*BKE_mask_spline_differentiate( MaskSpline *spline, int width, int height, unsigned int *tot_diff_point))[2] { - int unsigned resol = BKE_mask_spline_resolution(spline, width, height); + uint resol = BKE_mask_spline_resolution(spline, width, height); return BKE_mask_spline_differentiate_with_resolution(spline, tot_diff_point, resol); } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 3835e405630..098da997d8f 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1200,7 +1200,7 @@ void BKE_mesh_smooth_flag_set(Mesh *me, const bool use_smooth) * Find the index of the loop in 'poly' which references vertex, * returns -1 if not found */ -int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, unsigned vert) +int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, uint vert) { int j; for (j = 0; j < poly->totloop; j++, loopstart++) { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 46c2f735761..25f6682e9a7 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -846,7 +846,7 @@ bool paint_is_face_hidden(const MLoopTri *lt, const MVert *mvert, const MLoop *m /* returns non-zero if any of the corners of the grid * face whose inner corner is at (x, y) are hidden, * zero otherwise */ -bool paint_is_grid_face_hidden(const unsigned int *grid_hidden, int gridsize, int x, int y) +bool paint_is_grid_face_hidden(const uint *grid_hidden, int gridsize, int x, int y) { /* skip face if any of its corners are hidden */ return (BLI_BITMAP_TEST(grid_hidden, y * gridsize + x) || @@ -871,7 +871,7 @@ bool paint_is_bmesh_face_hidden(BMFace *f) return false; } -float paint_grid_paint_mask(const GridPaintMask *gpm, unsigned level, unsigned x, unsigned y) +float paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y) { int factor = BKE_ccg_factor(level, gpm->level); int gridsize = BKE_ccg_gridsize(gpm->level); diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index ec520e188f1..141e93183fb 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -1410,7 +1410,7 @@ void BKE_pbvh_get_grid_updates(PBVH *bvh, bool clear, void ***r_gridfaces, int * while ((node = pbvh_iter_next(&iter))) { if (node->flag & PBVH_UpdateNormals) { - for (unsigned i = 0; i < node->totprim; i++) { + for (uint i = 0; i < node->totprim; i++) { void *face = bvh->gridfaces[node->prim_indices[i]]; BLI_gset_add(face_set, face); } diff --git a/source/blender/blenlib/BLI_math_color_blend.h b/source/blender/blenlib/BLI_math_color_blend.h index 2e756b14424..a3efb5d72e9 100644 --- a/source/blender/blenlib/BLI_math_color_blend.h +++ b/source/blender/blenlib/BLI_math_color_blend.h @@ -64,53 +64,53 @@ MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], const unsigned char src2[4]); MINLINE void blend_color_overlay_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_hardlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_burn_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_linearburn_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_dodge_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_screen_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_softlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_pinlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_linearlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_vividlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_difference_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_exclusion_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_color_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_hue_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_saturation_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_luminosity_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]); + const uchar src1[4], + const uchar src2[4]); MINLINE void blend_color_interpolate_byte(unsigned char dst[4], const unsigned char src1[4], diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 05ffb02597d..1c518cf1487 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -220,8 +220,8 @@ static void ghash_buckets_resize(GHash *gh, const uint nbuckets) if (nbuckets > nbuckets_old) { for (i = 0; i < nbuckets_old; i++) { for (Entry *e = buckets_old[i], *e_next; e; e = e_next) { - const unsigned hash = ghash_entryhash(gh, e); - const unsigned bucket_index = ghash_bucket_index(gh, hash); + const uint hash = ghash_entryhash(gh, e); + const uint bucket_index = ghash_bucket_index(gh, hash); e_next = e->next; e->next = buckets_new[bucket_index]; buckets_new[bucket_index] = e; @@ -232,8 +232,8 @@ static void ghash_buckets_resize(GHash *gh, const uint nbuckets) for (i = 0; i < nbuckets_old; i++) { #ifdef GHASH_USE_MODULO_BUCKETS for (Entry *e = buckets_old[i], *e_next; e; e = e_next) { - const unsigned hash = ghash_entryhash(gh, e); - const unsigned bucket_index = ghash_bucket_index(gh, hash); + const uint hash = ghash_entryhash(gh, e); + const uint bucket_index = ghash_bucket_index(gh, hash); e_next = e->next; e->next = buckets_new[bucket_index]; buckets_new[bucket_index] = e; @@ -241,7 +241,7 @@ static void ghash_buckets_resize(GHash *gh, const uint nbuckets) #else /* No need to recompute hashes in this case, since our mask is just smaller, * all items in old bucket 'i' will go in same new bucket (i & new_mask)! */ - const unsigned bucket_index = ghash_bucket_index(gh, i); + const uint bucket_index = ghash_bucket_index(gh, i); BLI_assert(!buckets_old[i] || (bucket_index == ghash_bucket_index(gh, ghash_entryhash(gh, buckets_old[i])))); Entry *e; diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index a1c88edca6f..0a496d2bd68 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -224,7 +224,7 @@ MINLINE unsigned int power_of_2_max_u(unsigned int x) return x + 1; } -MINLINE unsigned power_of_2_min_u(unsigned x) +MINLINE unsigned int power_of_2_min_u(unsigned int x) { x |= (x >> 1); x |= (x >> 2); diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c index 7241779b32a..eb82bb81a89 100644 --- a/source/blender/blenlib/intern/math_color_blend_inline.c +++ b/source/blender/blenlib/intern/math_color_blend_inline.c @@ -49,9 +49,7 @@ /* straight alpha byte blending modes */ -MINLINE void blend_color_mix_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_mix_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight over operation */ @@ -64,10 +62,10 @@ MINLINE void blend_color_mix_byte(unsigned char dst[4], tmp[2] = (mt * src1[3] * src1[2]) + (t * 255 * src2[2]); tmp[3] = (mt * src1[3]) + (t * 255); - dst[0] = (unsigned char)divide_round_i(tmp[0], tmp[3]); - dst[1] = (unsigned char)divide_round_i(tmp[1], tmp[3]); - dst[2] = (unsigned char)divide_round_i(tmp[2], tmp[3]); - dst[3] = (unsigned char)divide_round_i(tmp[3], 255); + dst[0] = (uchar)divide_round_i(tmp[0], tmp[3]); + dst[1] = (uchar)divide_round_i(tmp[1], tmp[3]); + dst[2] = (uchar)divide_round_i(tmp[2], tmp[3]); + dst[3] = (uchar)divide_round_i(tmp[3], 255); } else { /* no op */ @@ -75,9 +73,7 @@ MINLINE void blend_color_mix_byte(unsigned char dst[4], } } -MINLINE void blend_color_add_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_add_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight add operation */ @@ -88,9 +84,9 @@ MINLINE void blend_color_add_byte(unsigned char dst[4], tmp[1] = (src1[1] * 255) + (src2[1] * t); tmp[2] = (src1[2] * 255) + (src2[2] * t); - dst[0] = (unsigned char)min_ii(divide_round_i(tmp[0], 255), 255); - dst[1] = (unsigned char)min_ii(divide_round_i(tmp[1], 255), 255); - dst[2] = (unsigned char)min_ii(divide_round_i(tmp[2], 255), 255); + dst[0] = (uchar)min_ii(divide_round_i(tmp[0], 255), 255); + dst[1] = (uchar)min_ii(divide_round_i(tmp[1], 255), 255); + dst[2] = (uchar)min_ii(divide_round_i(tmp[2], 255), 255); dst[3] = src1[3]; } else { @@ -99,9 +95,7 @@ MINLINE void blend_color_add_byte(unsigned char dst[4], } } -MINLINE void blend_color_sub_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_sub_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight sub operation */ @@ -112,9 +106,9 @@ MINLINE void blend_color_sub_byte(unsigned char dst[4], tmp[1] = (src1[1] * 255) - (src2[1] * t); tmp[2] = (src1[2] * 255) - (src2[2] * t); - dst[0] = (unsigned char)max_ii(divide_round_i(tmp[0], 255), 0); - dst[1] = (unsigned char)max_ii(divide_round_i(tmp[1], 255), 0); - dst[2] = (unsigned char)max_ii(divide_round_i(tmp[2], 255), 0); + dst[0] = (uchar)max_ii(divide_round_i(tmp[0], 255), 0); + dst[1] = (uchar)max_ii(divide_round_i(tmp[1], 255), 0); + dst[2] = (uchar)max_ii(divide_round_i(tmp[2], 255), 0); dst[3] = src1[3]; } else { @@ -123,9 +117,7 @@ MINLINE void blend_color_sub_byte(unsigned char dst[4], } } -MINLINE void blend_color_mul_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_mul_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight multiply operation */ @@ -137,9 +129,9 @@ MINLINE void blend_color_mul_byte(unsigned char dst[4], tmp[1] = (mt * src1[1] * 255) + (t * src1[1] * src2[1]); tmp[2] = (mt * src1[2] * 255) + (t * src1[2] * src2[2]); - dst[0] = (unsigned char)divide_round_i(tmp[0], 255 * 255); - dst[1] = (unsigned char)divide_round_i(tmp[1], 255 * 255); - dst[2] = (unsigned char)divide_round_i(tmp[2], 255 * 255); + dst[0] = (uchar)divide_round_i(tmp[0], 255 * 255); + dst[1] = (uchar)divide_round_i(tmp[1], 255 * 255); + dst[2] = (uchar)divide_round_i(tmp[2], 255 * 255); dst[3] = src1[3]; } else { @@ -148,9 +140,7 @@ MINLINE void blend_color_mul_byte(unsigned char dst[4], } } -MINLINE void blend_color_lighten_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_lighten_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight lighten operation */ @@ -162,9 +152,9 @@ MINLINE void blend_color_lighten_byte(unsigned char dst[4], tmp[1] = (mt * src1[1]) + (t * max_ii(src1[1], src2[1])); tmp[2] = (mt * src1[2]) + (t * max_ii(src1[2], src2[2])); - dst[0] = (unsigned char)divide_round_i(tmp[0], 255); - dst[1] = (unsigned char)divide_round_i(tmp[1], 255); - dst[2] = (unsigned char)divide_round_i(tmp[2], 255); + dst[0] = (uchar)divide_round_i(tmp[0], 255); + dst[1] = (uchar)divide_round_i(tmp[1], 255); + dst[2] = (uchar)divide_round_i(tmp[2], 255); dst[3] = src1[3]; } else { @@ -173,9 +163,7 @@ MINLINE void blend_color_lighten_byte(unsigned char dst[4], } } -MINLINE void blend_color_darken_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_darken_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight darken operation */ @@ -187,9 +175,9 @@ MINLINE void blend_color_darken_byte(unsigned char dst[4], tmp[1] = (mt * src1[1]) + (t * min_ii(src1[1], src2[1])); tmp[2] = (mt * src1[2]) + (t * min_ii(src1[2], src2[2])); - dst[0] = (unsigned char)divide_round_i(tmp[0], 255); - dst[1] = (unsigned char)divide_round_i(tmp[1], 255); - dst[2] = (unsigned char)divide_round_i(tmp[2], 255); + dst[0] = (uchar)divide_round_i(tmp[0], 255); + dst[1] = (uchar)divide_round_i(tmp[1], 255); + dst[2] = (uchar)divide_round_i(tmp[2], 255); dst[3] = src1[3]; } else { @@ -198,9 +186,7 @@ MINLINE void blend_color_darken_byte(unsigned char dst[4], } } -MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_erase_alpha_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight so just modify alpha channel */ @@ -209,7 +195,7 @@ MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], dst[0] = src1[0]; dst[1] = src1[1]; dst[2] = src1[2]; - dst[3] = (unsigned char)max_ii(src1[3] - divide_round_i(t * src2[3], 255), 0); + dst[3] = (uchar)max_ii(src1[3] - divide_round_i(t * src2[3], 255), 0); } else { /* no op */ @@ -217,9 +203,7 @@ MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], } } -MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4]) +MINLINE void blend_color_add_alpha_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { if (src2[3] != 0) { /* straight so just modify alpha channel */ @@ -228,7 +212,7 @@ MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], dst[0] = src1[0]; dst[1] = src1[1]; dst[2] = src1[2]; - dst[3] = (unsigned char)min_ii(src1[3] + divide_round_i(t * src2[3], 255), 255); + dst[3] = (uchar)min_ii(src1[3] + divide_round_i(t * src2[3], 255), 255); } else { /* no op */ @@ -236,9 +220,7 @@ MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], } } -MINLINE void blend_color_overlay_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_overlay_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = (int)src2[3]; if (fac != 0) { @@ -254,7 +236,7 @@ MINLINE void blend_color_overlay_byte(unsigned char dst[4], else { temp = (2 * src1[i] * src2[i]) >> 8; } - dst[i] = (unsigned char)min_ii((temp * fac + src1[i] * mfac) / 255, 255); + dst[i] = (uchar)min_ii((temp * fac + src1[i] * mfac) / 255, 255); } } else { @@ -263,9 +245,7 @@ MINLINE void blend_color_overlay_byte(unsigned char dst[4], } } -MINLINE void blend_color_hardlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_hardlight_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = (int)src2[3]; if (fac != 0) { @@ -281,7 +261,7 @@ MINLINE void blend_color_hardlight_byte(unsigned char dst[4], else { temp = (2 * src2[i] * src1[i]) >> 8; } - dst[i] = (unsigned char)min_ii((temp * fac + src1[i] * mfac) / 255, 255); + dst[i] = (uchar)min_ii((temp * fac + src1[i] * mfac) / 255, 255); } } else { @@ -290,9 +270,7 @@ MINLINE void blend_color_hardlight_byte(unsigned char dst[4], } } -MINLINE void blend_color_burn_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_burn_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -301,7 +279,7 @@ MINLINE void blend_color_burn_byte(unsigned char dst[4], while (i--) { const int temp = (src2[i] == 0) ? 0 : max_ii(255 - ((255 - src1[i]) * 255) / src2[i], 0); - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -310,9 +288,7 @@ MINLINE void blend_color_burn_byte(unsigned char dst[4], } } -MINLINE void blend_color_linearburn_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_linearburn_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -321,7 +297,7 @@ MINLINE void blend_color_linearburn_byte(unsigned char dst[4], while (i--) { const int temp = max_ii(src1[i] + src2[i] - 255, 0); - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -330,9 +306,7 @@ MINLINE void blend_color_linearburn_byte(unsigned char dst[4], } } -MINLINE void blend_color_dodge_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_dodge_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -341,7 +315,7 @@ MINLINE void blend_color_dodge_byte(unsigned char dst[4], while (i--) { const int temp = (src2[i] == 255) ? 255 : min_ii((src1[i] * 255) / (255 - src2[i]), 255); - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -350,9 +324,7 @@ MINLINE void blend_color_dodge_byte(unsigned char dst[4], } } -MINLINE void blend_color_screen_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_screen_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -361,7 +333,7 @@ MINLINE void blend_color_screen_byte(unsigned char dst[4], while (i--) { const int temp = max_ii(255 - (((255 - src1[i]) * (255 - src2[i])) / 255), 0); - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -370,9 +342,7 @@ MINLINE void blend_color_screen_byte(unsigned char dst[4], } } -MINLINE void blend_color_softlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_softlight_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -388,7 +358,7 @@ MINLINE void blend_color_softlight_byte(unsigned char dst[4], else { temp = 255 - (2 * (255 - ((src2[i] / 2) + 64)) * (255 - src1[i]) / 255); } - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -397,9 +367,7 @@ MINLINE void blend_color_softlight_byte(unsigned char dst[4], } } -MINLINE void blend_color_pinlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_pinlight_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -415,7 +383,7 @@ MINLINE void blend_color_pinlight_byte(unsigned char dst[4], else { temp = min_ii(2 * src2[i], src1[i]); } - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -424,9 +392,7 @@ MINLINE void blend_color_pinlight_byte(unsigned char dst[4], } } -MINLINE void blend_color_linearlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_linearlight_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -442,7 +408,7 @@ MINLINE void blend_color_linearlight_byte(unsigned char dst[4], else { temp = max_ii(src1[i] + 2 * src2[i] - 255, 0); } - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -451,9 +417,7 @@ MINLINE void blend_color_linearlight_byte(unsigned char dst[4], } } -MINLINE void blend_color_vividlight_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_vividlight_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -475,7 +439,7 @@ MINLINE void blend_color_vividlight_byte(unsigned char dst[4], else { temp = max_ii(255 - ((255 - src1[i]) * 255 / (2 * src2[i])), 0); } - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -484,9 +448,7 @@ MINLINE void blend_color_vividlight_byte(unsigned char dst[4], } } -MINLINE void blend_color_difference_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_difference_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -495,7 +457,7 @@ MINLINE void blend_color_difference_byte(unsigned char dst[4], while (i--) { const int temp = abs(src1[i] - src2[i]); - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -504,9 +466,7 @@ MINLINE void blend_color_difference_byte(unsigned char dst[4], } } -MINLINE void blend_color_exclusion_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_exclusion_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -515,7 +475,7 @@ MINLINE void blend_color_exclusion_byte(unsigned char dst[4], while (i--) { const int temp = 127 - ((2 * (src1[i] - 127) * (src2[i] - 127)) / 255); - dst[i] = (unsigned char)((temp * fac + src1[i] * mfac) / 255); + dst[i] = (uchar)((temp * fac + src1[i] * mfac) / 255); } } else { @@ -524,9 +484,7 @@ MINLINE void blend_color_exclusion_byte(unsigned char dst[4], } } -MINLINE void blend_color_color_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_color_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -542,9 +500,9 @@ MINLINE void blend_color_color_byte(unsigned char dst[4], hsv_to_rgb(h1, s1, v1, &r, &g, &b); - dst[0] = (unsigned char)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); - dst[1] = (unsigned char)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); - dst[2] = (unsigned char)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); + dst[0] = (uchar)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); + dst[1] = (uchar)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); + dst[2] = (uchar)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); } else { /* no op */ @@ -552,9 +510,7 @@ MINLINE void blend_color_color_byte(unsigned char dst[4], } } -MINLINE void blend_color_hue_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_hue_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -569,9 +525,9 @@ MINLINE void blend_color_hue_byte(unsigned char dst[4], hsv_to_rgb(h1, s1, v1, &r, &g, &b); - dst[0] = (unsigned char)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); - dst[1] = (unsigned char)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); - dst[2] = (unsigned char)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); + dst[0] = (uchar)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); + dst[1] = (uchar)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); + dst[2] = (uchar)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); } else { /* no op */ @@ -579,9 +535,7 @@ MINLINE void blend_color_hue_byte(unsigned char dst[4], } } -MINLINE void blend_color_saturation_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_saturation_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -598,9 +552,9 @@ MINLINE void blend_color_saturation_byte(unsigned char dst[4], hsv_to_rgb(h1, s1, v1, &r, &g, &b); - dst[0] = (unsigned char)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); - dst[1] = (unsigned char)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); - dst[2] = (unsigned char)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); + dst[0] = (uchar)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); + dst[1] = (uchar)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); + dst[2] = (uchar)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); } else { /* no op */ @@ -608,9 +562,7 @@ MINLINE void blend_color_saturation_byte(unsigned char dst[4], } } -MINLINE void blend_color_luminosity_byte(unsigned char dst[4], - unsigned const char src1[4], - unsigned const char src2[4]) +MINLINE void blend_color_luminosity_byte(uchar dst[4], const uchar src1[4], const uchar src2[4]) { const int fac = src2[3]; if (fac != 0) { @@ -625,9 +577,9 @@ MINLINE void blend_color_luminosity_byte(unsigned char dst[4], hsv_to_rgb(h1, s1, v1, &r, &g, &b); - dst[0] = (unsigned char)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); - dst[1] = (unsigned char)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); - dst[2] = (unsigned char)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); + dst[0] = (uchar)(((int)(r * 255.0f) * fac + src1[0] * mfac) / 255); + dst[1] = (uchar)(((int)(g * 255.0f) * fac + src1[1] * mfac) / 255); + dst[2] = (uchar)(((int)(b * 255.0f) * fac + src1[2] * mfac) / 255); } else { /* no op */ @@ -635,9 +587,9 @@ MINLINE void blend_color_luminosity_byte(unsigned char dst[4], } } -MINLINE void blend_color_interpolate_byte(unsigned char dst[4], - const unsigned char src1[4], - const unsigned char src2[4], +MINLINE void blend_color_interpolate_byte(uchar dst[4], + const uchar src1[4], + const uchar src2[4], float ft) { /* do color interpolation, but in premultiplied space so that RGB colors @@ -647,10 +599,10 @@ MINLINE void blend_color_interpolate_byte(unsigned char dst[4], int tmp = (mt * src1[3] + t * src2[3]); if (tmp > 0) { - dst[0] = (unsigned char)divide_round_i(mt * src1[0] * src1[3] + t * src2[0] * src2[3], tmp); - dst[1] = (unsigned char)divide_round_i(mt * src1[1] * src1[3] + t * src2[1] * src2[3], tmp); - dst[2] = (unsigned char)divide_round_i(mt * src1[2] * src1[3] + t * src2[2] * src2[3], tmp); - dst[3] = (unsigned char)divide_round_i(tmp, 255); + dst[0] = (uchar)divide_round_i(mt * src1[0] * src1[3] + t * src2[0] * src2[3], tmp); + dst[1] = (uchar)divide_round_i(mt * src1[1] * src1[3] + t * src2[1] * src2[3], tmp); + dst[2] = (uchar)divide_round_i(mt * src1[2] * src1[3] + t * src2[2] * src2[3], tmp); + dst[3] = (uchar)divide_round_i(tmp, 255); } else { copy_v4_v4_uchar(dst, src1); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 55f21250659..5919b7e1dd6 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -240,10 +240,7 @@ void interp_v3_v3v3v3_uv( p[2] = v1[2] + ((v2[2] - v1[2]) * uv[0]) + ((v3[2] - v1[2]) * uv[1]); } -void interp_v3_v3v3_uchar(char unsigned target[3], - const unsigned char a[3], - const unsigned char b[3], - const float t) +void interp_v3_v3v3_uchar(uchar target[3], const uchar a[3], const uchar b[3], const float t) { const float s = 1.0f - t; @@ -253,14 +250,10 @@ void interp_v3_v3v3_uchar(char unsigned target[3], } void interp_v3_v3v3_char(char target[3], const char a[3], const char b[3], const float t) { - interp_v3_v3v3_uchar( - (unsigned char *)target, (const unsigned char *)a, (const unsigned char *)b, t); + interp_v3_v3v3_uchar((uchar *)target, (const uchar *)a, (const uchar *)b, t); } -void interp_v4_v4v4_uchar(char unsigned target[4], - const unsigned char a[4], - const unsigned char b[4], - const float t) +void interp_v4_v4v4_uchar(uchar target[4], const uchar a[4], const uchar b[4], const float t) { const float s = 1.0f - t; @@ -271,8 +264,7 @@ void interp_v4_v4v4_uchar(char unsigned target[4], } void interp_v4_v4v4_char(char target[4], const char a[4], const char b[4], const float t) { - interp_v4_v4v4_uchar( - (unsigned char *)target, (const unsigned char *)a, (const unsigned char *)b, t); + interp_v4_v4v4_uchar((uchar *)target, (const uchar *)a, (const uchar *)b, t); } void mid_v3_v3v3(float v[3], const float v1[3], const float v2[3]) @@ -303,12 +295,12 @@ void mid_v3_v3v3v3v3( v[2] = (v1[2] + v2[2] + v3[2] + v4[2]) / 4.0f; } -void mid_v3_v3_array(float r[3], const float (*vec_arr)[3], const unsigned int nbr) +void mid_v3_v3_array(float r[3], const float (*vec_arr)[3], const uint nbr) { const float factor = 1.0f / (float)nbr; zero_v3(r); - for (unsigned int i = 0; i < nbr; i++) { + for (uint i = 0; i < nbr; i++) { madd_v3_v3fl(r, vec_arr[i], factor); } } @@ -1119,10 +1111,10 @@ void range_vn_i(int *array_tar, const int size, const int start) } } -void range_vn_u(unsigned int *array_tar, const int size, const unsigned int start) +void range_vn_u(uint *array_tar, const int size, const uint start) { - unsigned int *array_pt = array_tar + (size - 1); - unsigned int j = start + (unsigned int)(size - 1); + uint *array_pt = array_tar + (size - 1); + uint j = start + (uint)(size - 1); int i = size; while (i--) { *(array_pt--) = j--; @@ -1329,18 +1321,18 @@ void copy_vn_short(short *array_tar, const int size, const short val) } } -void copy_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val) +void copy_vn_ushort(ushort *array_tar, const int size, const ushort val) { - unsigned short *tar = array_tar + (size - 1); + ushort *tar = array_tar + (size - 1); int i = size; while (i--) { *(tar--) = val; } } -void copy_vn_uchar(unsigned char *array_tar, const int size, const unsigned char val) +void copy_vn_uchar(uchar *array_tar, const int size, const uchar val) { - unsigned char *tar = array_tar + (size - 1); + uchar *tar = array_tar + (size - 1); int i = size; while (i--) { *(tar--) = val; diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 63657f33bba..7fc95a33092 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -600,7 +600,7 @@ uint BLI_str_utf8_as_unicode(const char *p) uint BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) { int i, len; - unsigned mask = 0; + uint mask = 0; uint result; const unsigned char c = (unsigned char)*p; diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c index 8cbbf765f66..d14b7a51a94 100644 --- a/source/blender/bmesh/intern/bmesh_log.c +++ b/source/blender/bmesh/intern/bmesh_log.c @@ -476,7 +476,7 @@ BMLog *BM_log_create(BMesh *bm) BMLog *log = MEM_callocN(sizeof(*log), __func__); const uint reserve_num = (uint)(bm->totvert + bm->totface); - log->unused_ids = range_tree_uint_alloc(0, (unsigned)-1); + log->unused_ids = range_tree_uint_alloc(0, (uint)-1); log->id_to_elem = BLI_ghash_new_ex(logkey_hash, logkey_cmp, __func__, reserve_num); log->elem_to_id = BLI_ghash_ptr_new_ex(__func__, reserve_num); @@ -618,7 +618,7 @@ void BM_log_mesh_elems_reorder(BMesh *bm, BMLog *log) /* Create BMVert index remap array */ id_to_idx = bm_log_compress_ids_to_indices(varr, (uint)bm->totvert); BM_ITER_MESH_INDEX (v, &bm_iter, bm, BM_VERTS_OF_MESH, i) { - const unsigned id = bm_log_vert_id_get(log, v); + const uint id = bm_log_vert_id_get(log, v); const void *key = POINTER_FROM_UINT(id); const void *val = BLI_ghash_lookup(id_to_idx, key); varr[i] = POINTER_AS_UINT(val); @@ -628,7 +628,7 @@ void BM_log_mesh_elems_reorder(BMesh *bm, BMLog *log) /* Create BMFace index remap array */ id_to_idx = bm_log_compress_ids_to_indices(farr, (uint)bm->totface); BM_ITER_MESH_INDEX (f, &bm_iter, bm, BM_FACES_OF_MESH, i) { - const unsigned id = bm_log_face_id_get(log, f); + const uint id = bm_log_face_id_get(log, f); const void *key = POINTER_FROM_UINT(id); const void *val = BLI_ghash_lookup(id_to_idx, key); farr[i] = POINTER_AS_UINT(val); @@ -1039,7 +1039,7 @@ const float *BM_log_original_vert_co(BMLog *log, BMVert *v) { BMLogEntry *entry = log->current_entry; const BMLogVert *lv; - unsigned v_id = bm_log_vert_id_get(log, v); + uint v_id = bm_log_vert_id_get(log, v); void *key = POINTER_FROM_UINT(v_id); BLI_assert(entry); @@ -1057,7 +1057,7 @@ const short *BM_log_original_vert_no(BMLog *log, BMVert *v) { BMLogEntry *entry = log->current_entry; const BMLogVert *lv; - unsigned v_id = bm_log_vert_id_get(log, v); + uint v_id = bm_log_vert_id_get(log, v); void *key = POINTER_FROM_UINT(v_id); BLI_assert(entry); @@ -1075,7 +1075,7 @@ float BM_log_original_mask(BMLog *log, BMVert *v) { BMLogEntry *entry = log->current_entry; const BMLogVert *lv; - unsigned v_id = bm_log_vert_id_get(log, v); + uint v_id = bm_log_vert_id_get(log, v); void *key = POINTER_FROM_UINT(v_id); BLI_assert(entry); @@ -1090,7 +1090,7 @@ void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const { BMLogEntry *entry = log->current_entry; const BMLogVert *lv; - unsigned v_id = bm_log_vert_id_get(log, v); + uint v_id = bm_log_vert_id_get(log, v); void *key = POINTER_FROM_UINT(v_id); BLI_assert(entry); diff --git a/source/blender/bmesh/intern/bmesh_polygon_edgenet.c b/source/blender/bmesh/intern/bmesh_polygon_edgenet.c index 374c912e3f5..f6ed95d322d 100644 --- a/source/blender/bmesh/intern/bmesh_polygon_edgenet.c +++ b/source/blender/bmesh/intern/bmesh_polygon_edgenet.c @@ -1298,7 +1298,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, if (use_partial_connect) { for (uint i = 0; i < edge_net_init_len; i++) { - for (unsigned j = 0; j < 2; j++) { + for (uint j = 0; j < 2; j++) { BMVert *v_delimit = (&edge_arr[i]->v1)[j]; BMVert *v_other; diff --git a/source/blender/bmesh/intern/bmesh_private.h b/source/blender/bmesh/intern/bmesh_private.h index d5cbe947293..8b4a59d5b9b 100644 --- a/source/blender/bmesh/intern/bmesh_private.h +++ b/source/blender/bmesh/intern/bmesh_private.h @@ -86,7 +86,7 @@ enum { } \ (void)0 -void poly_rotate_plane(const float normal[3], float (*verts)[3], unsigned const int nverts); +void poly_rotate_plane(const float normal[3], float (*verts)[3], const uint nverts); /* include the rest of our private declarations */ #include "bmesh_structure.h" diff --git a/source/blender/bmesh/operators/bmo_connect.c b/source/blender/bmesh/operators/bmo_connect.c index e52467614ac..2f0b21667e4 100644 --- a/source/blender/bmesh/operators/bmo_connect.c +++ b/source/blender/bmesh/operators/bmo_connect.c @@ -41,7 +41,7 @@ static int bm_face_connect_verts(BMesh *bm, BMFace *f, const bool check_degenerate) { - const unsigned pair_split_max = f->len / 2; + const uint pair_split_max = f->len / 2; BMLoop *(*loops_split)[2] = BLI_array_alloca(loops_split, pair_split_max); STACK_DECLARE(loops_split); BMVert *(*verts_pair)[2] = BLI_array_alloca(verts_pair, pair_split_max); diff --git a/source/blender/bmesh/operators/bmo_fill_grid.c b/source/blender/bmesh/operators/bmo_fill_grid.c index c3d19862ffb..adc612cfb54 100644 --- a/source/blender/bmesh/operators/bmo_fill_grid.c +++ b/source/blender/bmesh/operators/bmo_fill_grid.c @@ -205,7 +205,7 @@ static void barycentric_weights_v2_grid_cache(const uint xtot, static void bm_grid_fill_array(BMesh *bm, BMVert **v_grid, const uint xtot, - unsigned const int ytot, + const uint ytot, const short mat_nr, const bool use_smooth, const bool use_flip, diff --git a/source/blender/bmesh/operators/bmo_join_triangles.c b/source/blender/bmesh/operators/bmo_join_triangles.c index 848669301c3..efb8b810581 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.c +++ b/source/blender/bmesh/operators/bmo_join_triangles.c @@ -260,7 +260,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) BMEdge *e; /* data: edge-to-join, sort_value: error weight */ struct SortPtrByFloat *jedges; - unsigned i, totedge; + uint i, totedge; uint totedge_tag = 0; struct DelimitData delimit_data = {0}; diff --git a/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c b/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c index 2cc86a7c93f..e2741b806c2 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c +++ b/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.c @@ -177,8 +177,8 @@ void BM_mesh_decimate_unsubdivide_ex(BMesh *bm, const int iterations, const bool #else BMVert **vert_seek_a = MEM_mallocN(sizeof(BMVert *) * bm->totvert, __func__); BMVert **vert_seek_b = MEM_mallocN(sizeof(BMVert *) * bm->totvert, __func__); - unsigned vert_seek_a_tot = 0; - unsigned vert_seek_b_tot = 0; + uint vert_seek_a_tot = 0; + uint vert_seek_b_tot = 0; #endif BMIter iter; diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index c76cb8c80a6..32f5463a0e7 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -279,7 +279,7 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) const std::string &name = bc_get_dae_name(mesh); - for (unsigned i = 0; i < prim_arr.getCount(); i++) { + for (unsigned int i = 0; i < prim_arr.getCount(); i++) { COLLADAFW::MeshPrimitive *mp = prim_arr[i]; COLLADAFW::MeshPrimitive::PrimitiveType type = mp->getPrimitiveType(); @@ -683,7 +683,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) // XXX The proper function of TRIANGLE_FANS is not tested!!! // XXX In particular the handling of the normal_indices looks very wrong to me if (collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLE_FANS) { - unsigned grouped_vertex_count = mp->getGroupedVertexElementsCount(); + unsigned int grouped_vertex_count = mp->getGroupedVertexElementsCount(); for (unsigned int group_index = 0; group_index < grouped_vertex_count; group_index++) { unsigned int first_vertex = position_indices[0]; // Store first trifan vertex unsigned int first_normal = normal_indices[0]; // Store first trifan vertex normal diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h index d2d8972c245..de7d2e1a395 100644 --- a/source/blender/editors/include/ED_node.h +++ b/source/blender/editors/include/ED_node.h @@ -72,7 +72,7 @@ void ED_init_standard_node_socket_type(struct bNodeSocketType *stype); void ED_init_node_socket_type_virtual(struct bNodeSocketType *stype); void ED_node_sample_set(const float col[4]); void ED_node_draw_snap( - struct View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos); + struct View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned int pos); /* node_draw.c */ void ED_node_tree_update(const struct bContext *C); diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 37ffb1b9d6d..622b64f547f 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -452,7 +452,7 @@ float ED_view3d_radius_to_dist(const struct View3D *v3d, const bool use_aspect, const float radius); -void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned pos); +void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned int pos); /* backbuffer select and draw support */ void ED_view3d_backbuf_depth_validate(struct ViewContext *vc); diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index a23bd7dad35..8af3664d41b 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1343,7 +1343,7 @@ void UI_view2d_multi_grid_draw(View2D *v2d, int colorid, float step, int level_s uchar grid_line_color[3]; /* Make an estimate of at least how many vertices will be needed */ - unsigned vertex_count = 4; + uint vertex_count = 4; vertex_count += 2 * ((int)((v2d->cur.xmax - v2d->cur.xmin) / lstep) + 1); vertex_count += 2 * ((int)((v2d->cur.ymax - v2d->cur.ymin) / lstep) + 1); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 05fa78aab1c..9ccbc7a1a0a 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -701,7 +701,7 @@ const EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(const bContext * PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free, - const unsigned int selection_mask) + const uint selection_mask) { Object *ob; EnumPropertyItem *item = NULL; @@ -1807,10 +1807,10 @@ static void vgroup_smooth_subset(Object *ob, float *weight_accum_prev; float *weight_accum_curr; - unsigned int subset_index; + uint subset_index; /* vertex indices that will be smoothed, (only to avoid iterating over verts that do nothing) */ - unsigned int *verts_used; + uint *verts_used; STACK_DECLARE(verts_used); BKE_object_defgroup_subset_to_index_array(vgroup_validmap, vgroup_tot, vgroup_subset_map); @@ -1882,12 +1882,12 @@ static void vgroup_smooth_subset(Object *ob, memcpy(weight_accum_curr, weight_accum_prev, sizeof(*weight_accum_curr) * dvert_tot); for (iter = 0; iter < repeat; iter++) { - unsigned *vi_step, *vi_end = verts_used + STACK_SIZE(verts_used); + uint *vi_step, *vi_end = verts_used + STACK_SIZE(verts_used); /* avoid looping over all verts */ // for (i = 0; i < dvert_tot; i++) for (vi_step = verts_used; vi_step != vi_end; vi_step++) { - const unsigned int i = *vi_step; + const uint i = *vi_step; float weight_tot = 0.0f; float weight = 0.0f; diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 7db634660af..c85beefe1f4 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -3290,7 +3290,7 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy, float x0, float if (count_fine > 0) { GPU_vertformat_clear(format); pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - unsigned color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); immBegin(GPU_PRIM_LINES, 4 * count_fine + 4 * count_large); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 015657318b2..cf66ba14328 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -291,7 +291,7 @@ static void sculpt_vertex_neighbors_get_faces(SculptSession *ss, for (i = 0; i < ss->pmap[(int)index].count; i++) { const MPoly *p = &ss->mpoly[vert_map->indices[i]]; - unsigned f_adj_v[2]; + uint f_adj_v[2]; if (poly_get_adj_loops_from_vert(p, ss->mloop, (int)index, f_adj_v) != -1) { int j; for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) { @@ -2203,7 +2203,7 @@ static void update_brush_local_mat(Sculpt *sd, Object *ob) /* For the smooth brush, uses the neighboring vertices around vert to calculate * a smoothed location for vert. Skips corner vertices (used by only one * polygon.) */ -static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert) +static void neighbor_average(SculptSession *ss, float avg[3], uint vert) { const MeshElemMap *vert_map = &ss->pmap[vert]; const MVert *mvert = ss->mvert; @@ -2217,7 +2217,7 @@ static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert) for (i = 0; i < vert_map->count; i++) { const MPoly *p = &ss->mpoly[vert_map->indices[i]]; - unsigned f_adj_v[2]; + uint f_adj_v[2]; if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) { int j; @@ -2243,7 +2243,7 @@ static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert) /* Similar to neighbor_average(), but returns an averaged mask value * instead of coordinate. Also does not restrict based on border or * corner vertices. */ -static float neighbor_average_mask(SculptSession *ss, unsigned vert) +static float neighbor_average_mask(SculptSession *ss, uint vert) { const float *vmask = ss->vmask; float avg = 0; @@ -2251,7 +2251,7 @@ static float neighbor_average_mask(SculptSession *ss, unsigned vert) for (i = 0; i < ss->pmap[vert].count; i++) { const MPoly *p = &ss->mpoly[ss->pmap[vert].indices[i]]; - unsigned f_adj_v[2]; + uint f_adj_v[2]; if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) { int j; diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 42a1566629a..8dd5a7c7d0c 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -164,7 +164,7 @@ static void set_fcurve_vertex_color(FCurve *fcu, bool sel) } static void draw_fcurve_selected_keyframe_vertices( - FCurve *fcu, View2D *v2d, bool edit, bool sel, unsigned pos) + FCurve *fcu, View2D *v2d, bool edit, bool sel, uint pos) { const float fac = 0.05f * BLI_rctf_size_x(&v2d->cur); @@ -200,7 +200,7 @@ static void draw_fcurve_selected_keyframe_vertices( } /* helper func - draw keyframe vertices only for an F-Curve */ -static void draw_fcurve_keyframe_vertices(FCurve *fcu, View2D *v2d, bool edit, unsigned pos) +static void draw_fcurve_keyframe_vertices(FCurve *fcu, View2D *v2d, bool edit, uint pos) { immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA); @@ -214,7 +214,7 @@ static void draw_fcurve_keyframe_vertices(FCurve *fcu, View2D *v2d, bool edit, u /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */ static void draw_fcurve_selected_handle_vertices( - FCurve *fcu, View2D *v2d, bool sel, bool sel_handle_only, unsigned pos) + FCurve *fcu, View2D *v2d, bool sel, bool sel_handle_only, uint pos) { (void)v2d; /* TODO: use this to draw only points in view */ @@ -259,10 +259,7 @@ static void draw_fcurve_selected_handle_vertices( } /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */ -static void draw_fcurve_handle_vertices(FCurve *fcu, - View2D *v2d, - bool sel_handle_only, - unsigned pos) +static void draw_fcurve_handle_vertices(FCurve *fcu, View2D *v2d, bool sel_handle_only, uint pos) { /* smooth outlines for more consistent appearance */ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA); @@ -353,7 +350,7 @@ static void draw_fcurve_handles(SpaceGraph *sipo, FCurve *fcu) BezTriple *bezt = fcu->bezt, *prevbezt = NULL; int basecol = (sel) ? TH_HANDLE_SEL_FREE : TH_HANDLE_FREE; const float *fp; - unsigned char col[4]; + uchar col[4]; for (b = 0; b < fcu->totvert; b++, prevbezt = bezt, bezt++) { /* if only selected keyframes can get their handles shown, @@ -428,7 +425,7 @@ static void draw_fcurve_handles(SpaceGraph *sipo, FCurve *fcu) * have a consistent appearance (due to off-pixel alignments)... */ static void draw_fcurve_sample_control( - float x, float y, float xscale, float yscale, float hsize, unsigned int pos) + float x, float y, float xscale, float yscale, float hsize, uint pos) { /* adjust view transform before starting */ GPU_matrix_push(); @@ -491,8 +488,7 @@ static void draw_fcurve_samples(SpaceGraph *sipo, ARegion *ar, FCurve *fcu) /* Helper func - just draw the F-Curve by sampling the visible region * (for drawing curves with modifiers). */ -static void draw_fcurve_curve( - bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, unsigned int pos) +static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, uint pos) { SpaceGraph *sipo = (SpaceGraph *)ac->sl; float samplefreq; @@ -684,8 +680,7 @@ static bool fcurve_can_use_simple_bezt_drawing(FCurve *fcu) } /* helper func - draw one repeat of an F-Curve (using Bezier curve approximations) */ -static void draw_fcurve_curve_bezts( - bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, unsigned int pos) +static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, uint pos) { BezTriple *prevbezt = fcu->bezt; BezTriple *bezt = prevbezt + 1; diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 3f563fe9033..c455b7d7c54 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -147,7 +147,7 @@ void ED_image_draw_info(Scene *scene, int channels, int x, int y, - const unsigned char cp[4], + const uchar cp[4], const float fp[4], const float linearcol[4], int *zp, @@ -164,13 +164,13 @@ void ED_image_draw_info(Scene *scene, /* text colors */ /* XXX colored text not allowed in Blender UI */ #if 0 - unsigned char red[3] = {255, 50, 50}; - unsigned char green[3] = {0, 255, 0}; - unsigned char blue[3] = {100, 100, 255}; + uchar red[3] = {255, 50, 50}; + uchar green[3] = {0, 255, 0}; + uchar blue[3] = {100, 100, 255}; #else - unsigned char red[3] = {255, 255, 255}; - unsigned char green[3] = {255, 255, 255}; - unsigned char blue[3] = {255, 255, 255}; + uchar red[3] = {255, 255, 255}; + uchar green[3] = {255, 255, 255}; + uchar blue[3] = {255, 255, 255}; #endif float hue = 0, sat = 0, val = 0, lum = 0, u = 0, v = 0; float col[4], finalcol[4]; @@ -613,7 +613,7 @@ static void draw_image_buffer(const bContext *C, } else { float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - unsigned char *display_buffer; + uchar *display_buffer; void *cache_handle; ColorManagedViewSettings *view_settings; ColorManagedDisplaySettings *display_settings; @@ -760,7 +760,7 @@ static void draw_image_paint_helpers( float col[4] = {1.0f, 1.0f, 1.0f, brush->clone.alpha}; UI_view2d_view_to_region(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y); - unsigned char *display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + uchar *display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); if (!display_buffer) { BKE_image_release_ibuf(brush->clone.image, ibuf, NULL); @@ -794,8 +794,8 @@ static void draw_image_paint_helpers( } } -static void draw_udim_tile_grid(unsigned int pos_attr, - unsigned int color_attr, +static void draw_udim_tile_grid(uint pos_attr, + uint color_attr, ARegion *ar, int x, int y, @@ -832,8 +832,8 @@ static void draw_udim_tile_grids(ARegion *ar, SpaceImage *sima, Image *ima) float stepy = BLI_rcti_size_y(&ar->v2d.mask) / BLI_rctf_size_y(&ar->v2d.cur); GPUVertFormat *format = immVertexFormat(); - unsigned int pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - unsigned color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); immBegin(GPU_PRIM_LINES, 8 * num_tiles); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 35c9082b54c..121c597c1bb 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -376,7 +376,7 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp const int font_size = data->label_size / aspect; const float margin = (float)(NODE_DY / 4); int label_height; - unsigned char color[3]; + uchar color[3]; nodeLabel(ntree, node, label, sizeof(label)); @@ -3483,7 +3483,7 @@ void draw_nodespace_back_pix(const bContext *C, y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof; if (ibuf->rect || ibuf->rect_float) { - unsigned char *display_buffer = NULL; + uchar *display_buffer = NULL; void *cache_handle = NULL; if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B | SNODE_SHOW_ALPHA)) { @@ -3707,11 +3707,11 @@ static struct { GPUBatch *batch; /* for batching line together */ GPUBatch *batch_single; /* for single line */ GPUVertBuf *inst_vbo; - unsigned int p0_id, p1_id, p2_id, p3_id; - unsigned int colid_id; + uint p0_id, p1_id, p2_id, p3_id; + uint colid_id; GPUVertBufRaw p0_step, p1_step, p2_step, p3_step; GPUVertBufRaw colid_step; - unsigned int count; + uint count; bool enabled; } g_batch_link = {0}; @@ -3727,11 +3727,11 @@ static void nodelink_batch_reset(void) } static void set_nodelink_vertex(GPUVertBuf *vbo, - unsigned int uv_id, - unsigned int pos_id, - unsigned int exp_id, - unsigned int v, - const unsigned char uv[2], + uint uv_id, + uint pos_id, + uint exp_id, + uint v, + const uchar uv[2], const float pos[2], const float exp[2]) { @@ -3756,7 +3756,7 @@ static void nodelink_batch_init(void) int v = 0; for (int k = 0; k < 2; k++) { - unsigned char uv[2] = {0, 0}; + uchar uv[2] = {0, 0}; float pos[2] = {0.0f, 0.0f}; float exp[2] = {0.0f, 1.0f}; @@ -4000,8 +4000,7 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); } -void ED_node_draw_snap( - View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos) +void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border, uint pos) { immBegin(GPU_PRIM_LINES, 4); diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 2081c69a1a4..6e165df3e2b 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -722,18 +722,18 @@ static void node_socket_draw(const bContext *C, bNodeTree *ntree, PointerRNA node_ptr, bNodeSocket *sock, - unsigned pos_id, - unsigned col_id, - unsigned shape_id, - unsigned size_id, - unsigned outline_col_id, + uint pos_id, + uint col_id, + uint shape_id, + uint size_id, + uint outline_col_id, float size, bool selected) { PointerRNA ptr; float color[4]; float outline_color[4]; - unsigned int flags = 0; + uint flags = 0; RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color); diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index a341be5bf65..8bd1fae645f 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -2700,7 +2700,7 @@ static void outliner_draw_iconrow_number(const uiFontStyle *fstyle, color); /* Now the numbers. */ - unsigned char text_col[4]; + uchar text_col[4]; UI_GetThemeColor4ubv(TH_TEXT_HI, text_col); text_col[3] = 255; @@ -2953,7 +2953,7 @@ static void outliner_draw_tree_element(bContext *C, float ufac = UI_UNIT_X / 20.0f; int offsx = 0; eOLDrawState active = OL_DRAWSEL_NONE; - unsigned char text_color[4]; + uchar text_color[4]; UI_GetThemeColor4ubv(TH_TEXT, text_color); float icon_bgcolor[4], icon_border[4]; outliner_icon_background_colors(icon_bgcolor, icon_border); @@ -3208,11 +3208,11 @@ static void outliner_draw_tree_element(bContext *C, } } -static void outliner_draw_hierarchy_lines_recursive(unsigned pos, +static void outliner_draw_hierarchy_lines_recursive(uint pos, SpaceOutliner *soops, ListBase *lb, int startx, - const unsigned char col[4], + const uchar col[4], bool draw_grayed_out, int *starty) { @@ -3234,7 +3234,7 @@ static void outliner_draw_hierarchy_lines_recursive(unsigned pos, dash.step_len = UI_UNIT_X / dash.steps_num; dash.gap_len = dash.step_len / 2; - const unsigned char grayed_alpha = col[3] / 2; + const uchar grayed_alpha = col[3] / 2; /* For vertical lines between objects. */ y1 = y2 = y1_dashed = y2_dashed = *starty; @@ -3316,7 +3316,7 @@ static void outliner_draw_hierarchy_lines(SpaceOutliner *soops, { GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - unsigned char col[4]; + uchar col[4]; immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.4f, col); @@ -3369,7 +3369,7 @@ static void outliner_draw_struct_marks(ARegion *ar, } } -static void outliner_draw_highlights_recursive(unsigned pos, +static void outliner_draw_highlights_recursive(uint pos, const ARegion *ar, const SpaceOutliner *soops, const ListBase *lb, diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 2cdfd8039c1..0daa5aa53ae 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -87,7 +87,7 @@ static void circball_array_fill(float verts[CIRCLE_RESOL][3], } } -void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned pos) +void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], uint pos) { float verts[CIRCLE_RESOL][3]; diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 773cbf72d5b..51ad40bdd87 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -1090,7 +1090,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes /* validate loop edges */ #if 0 { - unsigned i = 0; + uint i = 0; printf("\n"); for (; i < maxPolys * 4; i += 4) { uint ii; diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c index b82865a727d..e22863bc602 100644 --- a/source/blender/windowmanager/intern/wm_cursors.c +++ b/source/blender/windowmanager/intern/wm_cursors.c @@ -132,11 +132,8 @@ static GHOST_TStandardCursor convert_to_ghost_standard_cursor(WMCursorType curs) } } -static void window_set_custom_cursor(wmWindow *win, - unsigned const char mask[16][2], - unsigned char bitmap[16][2], - int hotx, - int hoty) +static void window_set_custom_cursor( + wmWindow *win, const uchar mask[16][2], uchar bitmap[16][2], int hotx, int hoty) { GHOST_SetCustomCursorShape( win->ghostwin, (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 16, 16, hotx, hoty, true); @@ -380,8 +377,8 @@ void WM_cursor_time(wmWindow *win, int nr) {0, 60, 66, 66, 60, 66, 66, 60}, {0, 56, 68, 68, 120, 64, 68, 56}, }; - unsigned char mask[16][2]; - unsigned char bitmap[16][2] = {{0}}; + uchar mask[16][2]; + uchar bitmap[16][2] = {{0}}; int i, idx; if (win->lastcursor == 0) { -- cgit v1.2.3 From 08a4cb0727d2a176fd541676bf0cabcb6d9541d9 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 7 Feb 2020 15:26:35 +0100 Subject: Cleanup: `make format` Remember to run `make format` after cleanups/renames/... --- source/blender/blenlib/BLI_math_color_blend.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_math_color_blend.h b/source/blender/blenlib/BLI_math_color_blend.h index a3efb5d72e9..47bafff3a49 100644 --- a/source/blender/blenlib/BLI_math_color_blend.h +++ b/source/blender/blenlib/BLI_math_color_blend.h @@ -69,9 +69,7 @@ MINLINE void blend_color_overlay_byte(unsigned char dst[4], MINLINE void blend_color_hardlight_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4]); -MINLINE void blend_color_burn_byte(unsigned char dst[4], - const uchar src1[4], - const uchar src2[4]); +MINLINE void blend_color_burn_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4]); MINLINE void blend_color_linearburn_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4]); @@ -102,9 +100,7 @@ MINLINE void blend_color_exclusion_byte(unsigned char dst[4], MINLINE void blend_color_color_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4]); -MINLINE void blend_color_hue_byte(unsigned char dst[4], - const uchar src1[4], - const uchar src2[4]); +MINLINE void blend_color_hue_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4]); MINLINE void blend_color_saturation_byte(unsigned char dst[4], const uchar src1[4], const uchar src2[4]); -- cgit v1.2.3 From faf08954d572c84d42de074effbca02fee3b27df Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 7 Feb 2020 16:29:02 +0100 Subject: Cleanup: Rename `BKE_library_idmap` file to `BKE_main_idmap` Part of T72604: > Proposal: BKE_library and BKE_main API naming: prefixes conventions --- source/blender/blenkernel/BKE_library_idmap.h | 45 ----- source/blender/blenkernel/BKE_main_idmap.h | 45 +++++ source/blender/blenkernel/CMakeLists.txt | 4 +- source/blender/blenkernel/intern/library_idmap.c | 214 ----------------------- source/blender/blenkernel/intern/main_idmap.c | 214 +++++++++++++++++++++++ source/blender/blenloader/intern/readfile.c | 2 +- 6 files changed, 262 insertions(+), 262 deletions(-) delete mode 100644 source/blender/blenkernel/BKE_library_idmap.h create mode 100644 source/blender/blenkernel/BKE_main_idmap.h delete mode 100644 source/blender/blenkernel/intern/library_idmap.c create mode 100644 source/blender/blenkernel/intern/main_idmap.c (limited to 'source') diff --git a/source/blender/blenkernel/BKE_library_idmap.h b/source/blender/blenkernel/BKE_library_idmap.h deleted file mode 100644 index 0285699dea3..00000000000 --- a/source/blender/blenkernel/BKE_library_idmap.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ -#ifndef __BKE_LIBRARY_IDMAP_H__ -#define __BKE_LIBRARY_IDMAP_H__ - -/** \file - * \ingroup bke - */ - -#include "BLI_compiler_attrs.h" - -struct ID; -struct IDNameLib_Map; -struct Main; - -struct IDNameLib_Map *BKE_main_idmap_create(struct Main *bmain, - const bool create_valid_ids_set, - struct Main *old_bmain) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(1); -void BKE_main_idmap_destroy(struct IDNameLib_Map *id_typemap) ATTR_NONNULL(); -struct Main *BKE_main_idmap_main_get(struct IDNameLib_Map *id_typemap) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); -struct ID *BKE_main_idmap_lookup(struct IDNameLib_Map *id_typemap, - short id_type, - const char *name, - const struct Library *lib) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(1, 3); -struct ID *BKE_main_idmap_lookup_id(struct IDNameLib_Map *id_typemap, - const struct ID *id) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(1, 2); - -#endif /* __BKE_LIBRARY_IDMAP_H__ */ diff --git a/source/blender/blenkernel/BKE_main_idmap.h b/source/blender/blenkernel/BKE_main_idmap.h new file mode 100644 index 00000000000..d95f32b162a --- /dev/null +++ b/source/blender/blenkernel/BKE_main_idmap.h @@ -0,0 +1,45 @@ +/* + * 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. + */ +#ifndef __BKE_MAIN_IDMAP_H__ +#define __BKE_MAIN_IDMAP_H__ + +/** \file + * \ingroup bke + */ + +#include "BLI_compiler_attrs.h" + +struct ID; +struct IDNameLib_Map; +struct Main; + +struct IDNameLib_Map *BKE_main_idmap_create(struct Main *bmain, + const bool create_valid_ids_set, + struct Main *old_bmain) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1); +void BKE_main_idmap_destroy(struct IDNameLib_Map *id_typemap) ATTR_NONNULL(); +struct Main *BKE_main_idmap_main_get(struct IDNameLib_Map *id_typemap) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(); +struct ID *BKE_main_idmap_lookup(struct IDNameLib_Map *id_typemap, + short id_type, + const char *name, + const struct Library *lib) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 3); +struct ID *BKE_main_idmap_lookup_id(struct IDNameLib_Map *id_typemap, + const struct ID *id) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 2); + +#endif /* __BKE_MAIN_IDMAP_H__ */ diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 0aa4f0fe677..2f839aafa2c 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -136,7 +136,6 @@ set(SRC intern/layer.c intern/layer_utils.c intern/library.c - intern/library_idmap.c intern/library_override.c intern/library_query.c intern/library_remap.c @@ -144,6 +143,7 @@ set(SRC intern/lightprobe.c intern/linestyle.c intern/main.c + intern/main_idmap.c intern/mask.c intern/mask_evaluate.c intern/mask_rasterize.c @@ -299,7 +299,6 @@ set(SRC BKE_lattice.h BKE_layer.h BKE_library.h - BKE_library_idmap.h BKE_library_override.h BKE_library_query.h BKE_library_remap.h @@ -307,6 +306,7 @@ set(SRC BKE_lightprobe.h BKE_linestyle.h BKE_main.h + BKE_main_idmap.h BKE_mask.h BKE_material.h BKE_mball.h diff --git a/source/blender/blenkernel/intern/library_idmap.c b/source/blender/blenkernel/intern/library_idmap.c deleted file mode 100644 index ab0ff5b0096..00000000000 --- a/source/blender/blenkernel/intern/library_idmap.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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. - */ - -#include -#include - -#include "MEM_guardedalloc.h" - -#include "BLI_utildefines.h" -#include "BLI_ghash.h" -#include "BLI_listbase.h" - -#include "DNA_ID.h" - -#include "BKE_idcode.h" -#include "BKE_library_idmap.h" /* own include */ -#include "BKE_main.h" - -/** \file - * \ingroup bke - * - * Utility functions for faster ID lookups. - */ - -/** \name BKE_main_idmap API - * - * Cache ID (name, library lookups). - * This doesn't account for adding/removing data-blocks, - * and should only be used when performing many lookups. - * - * \note GHash's are initialized on demand, - * since its likely some types will never have lookups run on them, - * so its a waste to create and never use. - * \{ */ - -struct IDNameLib_Key { - /** ``ID.name + 2``: without the ID type prefix, since each id type gets it's own 'map' */ - const char *name; - /** ``ID.lib``: */ - const Library *lib; -}; - -struct IDNameLib_TypeMap { - GHash *map; - short id_type; - /* only for storage of keys in the ghash, avoid many single allocs */ - struct IDNameLib_Key *keys; -}; - -/** - * Opaque structure, external API users only see this. - */ -struct IDNameLib_Map { - struct IDNameLib_TypeMap type_maps[MAX_LIBARRAY]; - struct Main *bmain; - struct GSet *valid_id_pointers; -}; - -static struct IDNameLib_TypeMap *main_idmap_from_idcode(struct IDNameLib_Map *id_map, - short id_type) -{ - for (int i = 0; i < MAX_LIBARRAY; i++) { - if (id_map->type_maps[i].id_type == id_type) { - return &id_map->type_maps[i]; - } - } - return NULL; -} - -/** - * Generate mapping from ID type/name to ID pointer for given \a bmain. - * - * \note When used during undo/redo, there is no guaranty that ID pointers from UI area - * are not pointing to freed memory (when some IDs have been deleted). To avoid crashes - * in those cases, one can provide the 'old' (aka current) Main database as reference. - * #BKE_main_idmap_lookup_id will then check that given ID does exist in \a old_bmain - * before trying to use it. - * - * \param create_valid_ids_set: If \a true, generate a reference to prevent freed memory accesses. - * \param old_bmain: If not NULL, its IDs will be added the valid references set. - */ -struct IDNameLib_Map *BKE_main_idmap_create(struct Main *bmain, - const bool create_valid_ids_set, - struct Main *old_bmain) -{ - struct IDNameLib_Map *id_map = MEM_mallocN(sizeof(*id_map), __func__); - - int index = 0; - while (index < MAX_LIBARRAY) { - struct IDNameLib_TypeMap *type_map = &id_map->type_maps[index]; - type_map->map = NULL; - type_map->id_type = BKE_idcode_iter_step(&index); - BLI_assert(type_map->id_type != 0); - } - BLI_assert(index == MAX_LIBARRAY); - - id_map->bmain = bmain; - - if (create_valid_ids_set) { - id_map->valid_id_pointers = BKE_main_gset_create(bmain, NULL); - if (old_bmain != NULL) { - id_map->valid_id_pointers = BKE_main_gset_create(old_bmain, id_map->valid_id_pointers); - } - } - else { - id_map->valid_id_pointers = NULL; - } - - return id_map; -} - -struct Main *BKE_main_idmap_main_get(struct IDNameLib_Map *id_map) -{ - return id_map->bmain; -} - -static unsigned int idkey_hash(const void *ptr) -{ - const struct IDNameLib_Key *idkey = ptr; - unsigned int key = BLI_ghashutil_strhash(idkey->name); - if (idkey->lib) { - key ^= BLI_ghashutil_ptrhash(idkey->lib); - } - return key; -} - -static bool idkey_cmp(const void *a, const void *b) -{ - const struct IDNameLib_Key *idkey_a = a; - const struct IDNameLib_Key *idkey_b = b; - return strcmp(idkey_a->name, idkey_b->name) || (idkey_a->lib != idkey_b->lib); -} - -ID *BKE_main_idmap_lookup(struct IDNameLib_Map *id_map, - short id_type, - const char *name, - const Library *lib) -{ - struct IDNameLib_TypeMap *type_map = main_idmap_from_idcode(id_map, id_type); - - if (UNLIKELY(type_map == NULL)) { - return NULL; - } - - /* lazy init */ - if (type_map->map == NULL) { - ListBase *lb = which_libbase(id_map->bmain, id_type); - const int lb_len = BLI_listbase_count(lb); - if (lb_len == 0) { - return NULL; - } - type_map->map = BLI_ghash_new_ex(idkey_hash, idkey_cmp, __func__, lb_len); - type_map->keys = MEM_mallocN(sizeof(struct IDNameLib_Key) * lb_len, __func__); - - GHash *map = type_map->map; - struct IDNameLib_Key *key = type_map->keys; - - for (ID *id = lb->first; id; id = id->next, key++) { - key->name = id->name + 2; - key->lib = id->lib; - BLI_ghash_insert(map, key, id); - } - } - - const struct IDNameLib_Key key_lookup = {name, lib}; - return BLI_ghash_lookup(type_map->map, &key_lookup); -} - -ID *BKE_main_idmap_lookup_id(struct IDNameLib_Map *id_map, const ID *id) -{ - /* When used during undo/redo, this function cannot assume that given id points to valid memory - * (i.e. has not been freed), - * so it has to check that it does exist in 'old' (aka current) Main database. - * Otherwise, we cannot provide new ID pointer that way (would crash accessing freed memory - * when trying to get ID name). - */ - if (id_map->valid_id_pointers == NULL || BLI_gset_haskey(id_map->valid_id_pointers, id)) { - return BKE_main_idmap_lookup(id_map, GS(id->name), id->name + 2, id->lib); - } - return NULL; -} - -void BKE_main_idmap_destroy(struct IDNameLib_Map *id_map) -{ - struct IDNameLib_TypeMap *type_map = id_map->type_maps; - for (int i = 0; i < MAX_LIBARRAY; i++, type_map++) { - if (type_map->map) { - BLI_ghash_free(type_map->map, NULL, NULL); - type_map->map = NULL; - MEM_freeN(type_map->keys); - } - } - - if (id_map->valid_id_pointers != NULL) { - BLI_gset_free(id_map->valid_id_pointers, NULL); - } - - MEM_freeN(id_map); -} - -/** \} */ diff --git a/source/blender/blenkernel/intern/main_idmap.c b/source/blender/blenkernel/intern/main_idmap.c new file mode 100644 index 00000000000..a210961b212 --- /dev/null +++ b/source/blender/blenkernel/intern/main_idmap.c @@ -0,0 +1,214 @@ +/* + * 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. + */ + +#include +#include + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" +#include "BLI_ghash.h" +#include "BLI_listbase.h" + +#include "DNA_ID.h" + +#include "BKE_idcode.h" +#include "BKE_main.h" +#include "BKE_main_idmap.h" /* own include */ + +/** \file + * \ingroup bke + * + * Utility functions for faster ID lookups. + */ + +/** \name BKE_main_idmap API + * + * Cache ID (name, library lookups). + * This doesn't account for adding/removing data-blocks, + * and should only be used when performing many lookups. + * + * \note GHash's are initialized on demand, + * since its likely some types will never have lookups run on them, + * so its a waste to create and never use. + * \{ */ + +struct IDNameLib_Key { + /** ``ID.name + 2``: without the ID type prefix, since each id type gets it's own 'map' */ + const char *name; + /** ``ID.lib``: */ + const Library *lib; +}; + +struct IDNameLib_TypeMap { + GHash *map; + short id_type; + /* only for storage of keys in the ghash, avoid many single allocs */ + struct IDNameLib_Key *keys; +}; + +/** + * Opaque structure, external API users only see this. + */ +struct IDNameLib_Map { + struct IDNameLib_TypeMap type_maps[MAX_LIBARRAY]; + struct Main *bmain; + struct GSet *valid_id_pointers; +}; + +static struct IDNameLib_TypeMap *main_idmap_from_idcode(struct IDNameLib_Map *id_map, + short id_type) +{ + for (int i = 0; i < MAX_LIBARRAY; i++) { + if (id_map->type_maps[i].id_type == id_type) { + return &id_map->type_maps[i]; + } + } + return NULL; +} + +/** + * Generate mapping from ID type/name to ID pointer for given \a bmain. + * + * \note When used during undo/redo, there is no guaranty that ID pointers from UI area + * are not pointing to freed memory (when some IDs have been deleted). To avoid crashes + * in those cases, one can provide the 'old' (aka current) Main database as reference. + * #BKE_main_idmap_lookup_id will then check that given ID does exist in \a old_bmain + * before trying to use it. + * + * \param create_valid_ids_set: If \a true, generate a reference to prevent freed memory accesses. + * \param old_bmain: If not NULL, its IDs will be added the valid references set. + */ +struct IDNameLib_Map *BKE_main_idmap_create(struct Main *bmain, + const bool create_valid_ids_set, + struct Main *old_bmain) +{ + struct IDNameLib_Map *id_map = MEM_mallocN(sizeof(*id_map), __func__); + + int index = 0; + while (index < MAX_LIBARRAY) { + struct IDNameLib_TypeMap *type_map = &id_map->type_maps[index]; + type_map->map = NULL; + type_map->id_type = BKE_idcode_iter_step(&index); + BLI_assert(type_map->id_type != 0); + } + BLI_assert(index == MAX_LIBARRAY); + + id_map->bmain = bmain; + + if (create_valid_ids_set) { + id_map->valid_id_pointers = BKE_main_gset_create(bmain, NULL); + if (old_bmain != NULL) { + id_map->valid_id_pointers = BKE_main_gset_create(old_bmain, id_map->valid_id_pointers); + } + } + else { + id_map->valid_id_pointers = NULL; + } + + return id_map; +} + +struct Main *BKE_main_idmap_main_get(struct IDNameLib_Map *id_map) +{ + return id_map->bmain; +} + +static unsigned int idkey_hash(const void *ptr) +{ + const struct IDNameLib_Key *idkey = ptr; + unsigned int key = BLI_ghashutil_strhash(idkey->name); + if (idkey->lib) { + key ^= BLI_ghashutil_ptrhash(idkey->lib); + } + return key; +} + +static bool idkey_cmp(const void *a, const void *b) +{ + const struct IDNameLib_Key *idkey_a = a; + const struct IDNameLib_Key *idkey_b = b; + return strcmp(idkey_a->name, idkey_b->name) || (idkey_a->lib != idkey_b->lib); +} + +ID *BKE_main_idmap_lookup(struct IDNameLib_Map *id_map, + short id_type, + const char *name, + const Library *lib) +{ + struct IDNameLib_TypeMap *type_map = main_idmap_from_idcode(id_map, id_type); + + if (UNLIKELY(type_map == NULL)) { + return NULL; + } + + /* lazy init */ + if (type_map->map == NULL) { + ListBase *lb = which_libbase(id_map->bmain, id_type); + const int lb_len = BLI_listbase_count(lb); + if (lb_len == 0) { + return NULL; + } + type_map->map = BLI_ghash_new_ex(idkey_hash, idkey_cmp, __func__, lb_len); + type_map->keys = MEM_mallocN(sizeof(struct IDNameLib_Key) * lb_len, __func__); + + GHash *map = type_map->map; + struct IDNameLib_Key *key = type_map->keys; + + for (ID *id = lb->first; id; id = id->next, key++) { + key->name = id->name + 2; + key->lib = id->lib; + BLI_ghash_insert(map, key, id); + } + } + + const struct IDNameLib_Key key_lookup = {name, lib}; + return BLI_ghash_lookup(type_map->map, &key_lookup); +} + +ID *BKE_main_idmap_lookup_id(struct IDNameLib_Map *id_map, const ID *id) +{ + /* When used during undo/redo, this function cannot assume that given id points to valid memory + * (i.e. has not been freed), + * so it has to check that it does exist in 'old' (aka current) Main database. + * Otherwise, we cannot provide new ID pointer that way (would crash accessing freed memory + * when trying to get ID name). + */ + if (id_map->valid_id_pointers == NULL || BLI_gset_haskey(id_map->valid_id_pointers, id)) { + return BKE_main_idmap_lookup(id_map, GS(id->name), id->name + 2, id->lib); + } + return NULL; +} + +void BKE_main_idmap_destroy(struct IDNameLib_Map *id_map) +{ + struct IDNameLib_TypeMap *type_map = id_map->type_maps; + for (int i = 0; i < MAX_LIBARRAY; i++, type_map++) { + if (type_map->map) { + BLI_ghash_free(type_map->map, NULL, NULL); + type_map->map = NULL; + MEM_freeN(type_map->keys); + } + } + + if (id_map->valid_id_pointers != NULL) { + BLI_gset_free(id_map->valid_id_pointers, NULL); + } + + MEM_freeN(id_map); +} + +/** \} */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 9547e4cd05a..2ad79b4e252 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -121,7 +121,7 @@ #include "BKE_idprop.h" #include "BKE_layer.h" #include "BKE_library.h" -#include "BKE_library_idmap.h" +#include "BKE_main_idmap.h" #include "BKE_library_override.h" #include "BKE_library_query.h" #include "BKE_main.h" // for Main -- cgit v1.2.3 From 677e027f2069dac18891db931c860542cbcb4bbe Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 7 Feb 2020 16:35:26 +0100 Subject: Fix T73625: GPencil array offset wrong whe use Scale or Rotation This is not 100% a bug but a design change. The old method used the object origin as pivot point for Scale a nd Rotation, so when you moved the stroke in edit mode, the whole array ittems where offset because the pivot point distance changed. Now, before applying scale and rotation, the stroke is moved to object origin to keep the offset when scale or rotate, so these transformations are done in stroke local space. --- .../gpencil_modifiers/intern/MOD_gpencilarray.c | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c index bb70b548675..e258fbdccd1 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c @@ -228,24 +228,34 @@ static void generate_geometry(GpencilModifierData *md, for (gps = gpf->strokes.first, idx = 0; gps; gps = gps->next, idx++) { /* check if stroke can be duplicated */ if (valid_strokes[idx]) { - /* Duplicate stroke */ - bGPDstroke *gps_dst = MEM_dupallocN(gps); - gps_dst->points = MEM_dupallocN(gps->points); - if (gps->dvert) { - gps_dst->dvert = MEM_dupallocN(gps->dvert); - BKE_gpencil_stroke_weights_duplicate(gps, gps_dst); + /* Calculate original stroke center (only first loop). */ + float r_min[3], r_max[3], center[3]; + if (x == 1) { + INIT_MINMAX(r_min, r_max); + BKE_gpencil_stroke_minmax(gps, false, r_min, r_max); + add_v3_v3v3(center, r_min, r_max); + mul_v3_fl(center, 0.5f); + sub_v3_v3v3(center, center, ob->obmat[3]); } - gps_dst->triangles = MEM_dupallocN(gps->triangles); + + /* Duplicate stroke */ + bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps); /* Move points */ for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps_dst->points[i]; + /* Apply object local transform (Rot/Scale). */ if (mmd->object) { - /* apply local changes (rot/scale) */ mul_m4_v3(mat, &pt->x); } - /* global changes */ - mul_m4_v3(current_offset, &pt->x); + /* Translate to object origin. */ + float fpt[3]; + sub_v3_v3v3(fpt, &pt->x, center); + /* Global Rotate and scale. */ + mul_mat3_m4_v3(current_offset, fpt); + /* Global translate. */ + add_v3_v3(fpt, center); + add_v3_v3v3(&pt->x, fpt, current_offset[3]); } /* if replace material, use new one */ -- cgit v1.2.3