diff options
author | Hans Goudey <h.goudey@me.com> | 2020-09-10 16:56:29 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-09-10 16:56:29 +0300 |
commit | 09217fc22def6917d8b096f096f5186f83dcd8f8 (patch) | |
tree | 9b91da6f8765795975a9ccbc79fea68ce0eeeed8 /source | |
parent | 58488c08b869a42f81c2acec5b14504a59d5b500 (diff) | |
parent | 66f5008b33fe71caa177cdc2ee849f6081389002 (diff) |
Merge branch 'property-search-add-theme-color' into property-search-single-tab
Diffstat (limited to 'source')
206 files changed, 2772 insertions, 2944 deletions
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index ef74bb61a7e..fa3c59c781d 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -46,6 +46,10 @@ struct Scene; struct bAction; struct bActionGroup; struct bContext; +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; +struct BlendExpander; /* Container for data required to do FCurve and Driver evaluation. */ typedef struct AnimationEvalContext { @@ -101,6 +105,13 @@ void BKE_keyingset_free(struct KeyingSet *ks); /* Free all the KeyingSets in the given list */ void BKE_keyingsets_free(struct ListBase *list); +void BKE_keyingsets_blend_write(struct BlendWriter *writer, struct ListBase *list); +void BKE_keyingsets_blend_read_data(struct BlendDataReader *reader, struct ListBase *list); +void BKE_keyingsets_blend_read_lib(struct BlendLibReader *reader, + struct ID *id, + struct ListBase *list); +void BKE_keyingsets_blend_read_expand(struct BlendExpander *expander, struct ListBase *list); + /* ************************************* */ /* Path Fixing API */ diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h index 8a4fc78eb97..e40489a80da 100644 --- a/source/blender/blenkernel/BKE_icons.h +++ b/source/blender/blenkernel/BKE_icons.h @@ -78,6 +78,8 @@ struct ImBuf; struct PreviewImage; struct StudioLight; struct bGPDlayer; +struct BlendWriter; +struct BlendDataReader; enum eIconSizes; @@ -156,6 +158,9 @@ struct PreviewImage *BKE_previewimg_cached_thumbnail_read(const char *name, void BKE_previewimg_cached_release(const char *name); void BKE_previewimg_cached_release_pointer(struct PreviewImage *prv); +void BKE_previewimg_blend_write(struct BlendWriter *writer, const struct PreviewImage *prv); +void BKE_previewimg_blend_read(struct BlendDataReader *reader, struct PreviewImage *prv); + int BKE_icon_geom_ensure(struct Icon_Geom *geom); struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len); struct Icon_Geom *BKE_icon_geom_from_file(const char *filename); diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index b903545bd3b..024d58174e8 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -99,7 +99,7 @@ void BKE_main_collection_sync(const struct Main *bmain); void BKE_scene_collection_sync(const struct Scene *scene); void BKE_layer_collection_sync(const struct Scene *scene, struct ViewLayer *view_layer); void BKE_layer_collection_local_sync(struct ViewLayer *view_layer, const struct View3D *v3d); -void BKE_layer_collection_local_sync_all(struct Main *bmain); +void BKE_layer_collection_local_sync_all(const struct Main *bmain); void BKE_main_collection_sync_remap(const struct Main *bmain); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 3829000a045..5e8b371e604 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -72,6 +72,10 @@ struct bNodeTree; struct bNodeTreeExec; struct bNodeTreeType; struct uiLayout; +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; +struct BlendExpander; /* -------------------------------------------------------------------- */ /** \name Node Type Definitions @@ -453,6 +457,11 @@ struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree); void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree); void ntreeLocalMerge(struct Main *bmain, struct bNodeTree *localtree, struct bNodeTree *ntree); +void ntreeBlendWrite(struct BlendWriter *writer, struct bNodeTree *ntree); +void ntreeBlendReadData(struct BlendDataReader *reader, struct bNodeTree *ntree); +void ntreeBlendReadLib(struct BlendLibReader *reader, struct bNodeTree *ntree); +void ntreeBlendReadExpand(struct BlendExpander *expander, struct bNodeTree *ntree); + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenkernel/BKE_packedFile.h b/source/blender/blenkernel/BKE_packedFile.h index 9890399f8a2..f818f5f25fd 100644 --- a/source/blender/blenkernel/BKE_packedFile.h +++ b/source/blender/blenkernel/BKE_packedFile.h @@ -37,6 +37,8 @@ struct ReportList; struct VFont; struct Volume; struct bSound; +struct BlendWriter; +struct BlendDataReader; enum ePF_FileCompare { PF_CMP_EQUAL = 0, @@ -121,6 +123,9 @@ void BKE_packedfile_id_unpack(struct Main *bmain, struct ReportList *reports, enum ePF_FileStatus how); +void BKE_packedfile_blend_write(struct BlendWriter *writer, struct PackedFile *pf); +void BKE_packedfile_blend_read(struct BlendDataReader *reader, struct PackedFile **pf_p); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 089d8bef09e..64a8ae15fd3 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -28,6 +28,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_constraint_types.h" @@ -63,6 +66,8 @@ #include "RNA_access.h" +#include "BLO_read_write.h" + #include "CLG_log.h" static CLG_LogRef LOG = {"bke.action"}; @@ -169,6 +174,105 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bAction *act = (bAction *)id; + if (act->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, bAction, id_address, &act->id); + BKE_id_blend_write(writer, &act->id); + + BKE_fcurve_blend_write(writer, &act->curves); + + LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) { + BLO_write_struct(writer, bActionGroup, grp); + } + + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { + BLO_write_struct(writer, TimeMarker, marker); + } + } +} + +static void action_blend_read_data(BlendDataReader *reader, ID *id) +{ + bAction *act = (bAction *)id; + + BLO_read_list(reader, &act->curves); + BLO_read_list(reader, &act->chanbase); // XXX deprecated - old animation system + BLO_read_list(reader, &act->groups); + BLO_read_list(reader, &act->markers); + + // XXX deprecated - old animation system <<< + LISTBASE_FOREACH (bActionChannel *, achan, &act->chanbase) { + BLO_read_data_address(reader, &achan->grp); + + BLO_read_list(reader, &achan->constraintChannels); + } + // >>> XXX deprecated - old animation system + + BKE_fcurve_blend_read_data(reader, &act->curves); + + LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { + BLO_read_data_address(reader, &agrp->channels.first); + BLO_read_data_address(reader, &agrp->channels.last); + } +} + +static void blend_read_lib_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase) +{ + LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) { + BLO_read_id_address(reader, id->lib, &chan->ipo); + } +} + +static void action_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bAction *act = (bAction *)id; + + // XXX deprecated - old animation system <<< + LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { + BLO_read_id_address(reader, act->id.lib, &chan->ipo); + blend_read_lib_constraint_channels(reader, &act->id, &chan->constraintChannels); + } + // >>> XXX deprecated - old animation system + + BKE_fcurve_blend_read_lib(reader, &act->id, &act->curves); + + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { + if (marker->camera) { + BLO_read_id_address(reader, act->id.lib, &marker->camera); + } + } +} + +static void blend_read_expand_constraint_channels(BlendExpander *expander, ListBase *chanbase) +{ + LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) { + BLO_expand(expander, chan->ipo); + } +} + +static void action_blend_read_expand(BlendExpander *expander, ID *id) +{ + bAction *act = (bAction *)id; + + // XXX deprecated - old animation system -------------- + LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { + BLO_expand(expander, chan->ipo); + blend_read_expand_constraint_channels(expander, &chan->constraintChannels); + } + // --------------------------------------------------- + + /* F-Curves in Action */ + BKE_fcurve_blend_read_expand(expander, &act->curves); + + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { + if (marker->camera) { + BLO_expand(expander, marker->camera); + } + } +} + IDTypeInfo IDType_ID_AC = { .id_code = ID_AC, .id_filter = FILTER_ID_AC, @@ -186,10 +290,10 @@ IDTypeInfo IDType_ID_AC = { .foreach_id = action_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = action_blend_write, + .blend_read_data = action_blend_read_data, + .blend_read_lib = action_blend_read_lib, + .blend_read_expand = action_blend_read_expand, }; /* ***************** Library data level operations on action ************** */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 69e70cffdb2..98c01351f32 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -69,6 +69,8 @@ #include "RNA_access.h" +#include "BLO_read_write.h" + #include "nla_private.h" #include "atomic_ops.h" @@ -308,6 +310,55 @@ void BKE_keyingsets_free(ListBase *list) } } +void BKE_keyingsets_blend_write(BlendWriter *writer, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + /* KeyingSet */ + BLO_write_struct(writer, KeyingSet, ks); + + /* Paths */ + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + /* Path */ + BLO_write_struct(writer, KS_Path, ksp); + + if (ksp->rna_path) { + BLO_write_string(writer, ksp->rna_path); + } + } + } +} + +void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + /* paths */ + BLO_read_list(reader, &ks->paths); + + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + /* rna path */ + BLO_read_data_address(reader, &ksp->rna_path); + } + } +} + +void BKE_keyingsets_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + BLO_read_id_address(reader, id->lib, &ksp->id); + } + } +} + +void BKE_keyingsets_blend_read_expand(BlendExpander *expander, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + BLO_expand(expander, ksp->id); + } + } +} + /* ***************************************** */ /* Evaluation Data-Setting Backend */ diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index 82ccd33a53b..df7d308a87c 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -181,7 +181,6 @@ void BKE_fluid_reallocate_copy_fluid(FluidDomainSettings *fds, float *n_b = manta_smoke_get_color_b(fds->fluid); /* Noise smoke fields. */ - int wt_res_old[3]; float *o_wt_dens = manta_noise_get_density(fluid_old); float *o_wt_react = manta_noise_get_react(fluid_old); float *o_wt_flame = manta_noise_get_flame(fluid_old); @@ -210,6 +209,7 @@ void BKE_fluid_reallocate_copy_fluid(FluidDomainSettings *fds, float *n_wt_tcv2 = manta_noise_get_texture_v2(fds->fluid); float *n_wt_tcw2 = manta_noise_get_texture_w2(fds->fluid); + int wt_res_old[3]; manta_noise_get_res(fluid_old, wt_res_old); for (int z = o_min[2]; z < o_max[2]; z++) { @@ -3815,6 +3815,13 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, } } + /* Adaptive domain needs to know about current state, so save it here. */ + int o_res[3], o_min[3], o_max[3], o_shift[3]; + copy_v3_v3_int(o_res, fds->res); + copy_v3_v3_int(o_min, fds->res_min); + copy_v3_v3_int(o_max, fds->res_max); + copy_v3_v3_int(o_shift, fds->shift); + /* Ensure that time parameters are initialized correctly before every step. */ float fps = scene->r.frs_sec / scene->r.frs_sec_base; fds->frame_length = DT_DEFAULT * (25.0f / fps) * fds->time_scale; @@ -3903,8 +3910,6 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, bool with_gdomain; with_gdomain = (fds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN); - int o_res[3], o_min[3], o_max[3], o_shift[3]; - /* Cache mode specific settings. */ switch (mode) { case FLUID_DOMAIN_CACHE_ALL: @@ -3968,13 +3973,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, break; } - /* Adaptive domain needs to know about current state, so save it here. */ - copy_v3_v3_int(o_res, fds->res); - copy_v3_v3_int(o_min, fds->res_min); - copy_v3_v3_int(o_max, fds->res_max); - copy_v3_v3_int(o_shift, fds->shift); - bool read_partial = false, read_all = false; + bool grid_display = fds->use_coba; + /* Try to read from cache and keep track of read success. */ if (read_cache) { @@ -4038,7 +4039,8 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, } } - read_partial = !baking_data && !baking_particles && !baking_mesh && next_data; + read_partial = !baking_data && !baking_particles && !baking_mesh && next_data && + !grid_display; read_all = !read_partial && with_resumable_cache; has_data = manta_read_data(fds->fluid, fmd, data_frame, read_all); } diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 604637e2350..88d91cf5640 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -57,6 +57,8 @@ #include "BKE_main.h" #include "BKE_packedFile.h" +#include "BLO_read_write.h" + static CLG_LogRef LOG = {"bke.data_transfer"}; static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER; @@ -120,6 +122,31 @@ static void vfont_free_data(ID *id) } } +static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + VFont *vf = (VFont *)id; + if (vf->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + vf->data = NULL; + vf->temp_pf = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, VFont, id_address, &vf->id); + BKE_id_blend_write(writer, &vf->id); + + /* direct data */ + BKE_packedfile_blend_write(writer, vf->packedfile); + } +} + +static void vfont_blend_read_data(BlendDataReader *reader, ID *id) +{ + VFont *vf = (VFont *)id; + vf->data = NULL; + vf->temp_pf = NULL; + BKE_packedfile_blend_read(reader, &vf->packedfile); +} + IDTypeInfo IDType_ID_VF = { .id_code = ID_VF, .id_filter = FILTER_ID_VF, @@ -137,8 +164,8 @@ IDTypeInfo IDType_ID_VF = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = vfont_blend_write, + .blend_read_data = vfont_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index 6f181cc74d5..01e3eef4e19 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -59,6 +59,8 @@ #include "IMB_imbuf_types.h" #include "IMB_thumbs.h" +#include "BLO_read_write.h" + /** * Only allow non-managed icons to be removed (by Python for eg). * Previews & ID's have their own functions to remove icons. @@ -515,6 +517,48 @@ void BKE_previewimg_ensure(PreviewImage *prv, const int size) } } +void BKE_previewimg_blend_write(BlendWriter *writer, const PreviewImage *prv) +{ + /* Note we write previews also for undo steps. It takes up some memory, + * but not doing so would causes all previews to be re-rendered after + * undo which is too expensive. */ + + if (prv == NULL) { + return; + } + + PreviewImage prv_copy = *prv; + /* don't write out large previews if not requested */ + if (!(U.flag & USER_SAVE_PREVIEWS)) { + prv_copy.w[1] = 0; + prv_copy.h[1] = 0; + prv_copy.rect[1] = NULL; + } + BLO_write_struct_at_address(writer, PreviewImage, prv, &prv_copy); + if (prv_copy.rect[0]) { + BLO_write_uint32_array(writer, prv_copy.w[0] * prv_copy.h[0], prv_copy.rect[0]); + } + if (prv_copy.rect[1]) { + BLO_write_uint32_array(writer, prv_copy.w[1] * prv_copy.h[1], prv_copy.rect[1]); + } +} + +void BKE_previewimg_blend_read(BlendDataReader *reader, PreviewImage *prv) +{ + if (prv == NULL) { + return; + } + + for (int i = 0; i < NUM_ICON_SIZES; i++) { + if (prv->rect[i]) { + BLO_read_data_address(reader, &prv->rect[i]); + } + prv->gputexture[i] = NULL; + } + prv->icon_id = 0; + prv->tag = 0; +} + void BKE_icon_changed(const int icon_id) { BLI_assert(BLI_thread_is_main()); diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 2f1ad2559f9..1ad34fde0fa 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -1248,9 +1248,9 @@ void BKE_layer_collection_local_sync(ViewLayer *view_layer, const View3D *v3d) } /** - * Sync the local collection for all the viewports. + * Sync the local collection for all the view-ports. */ -void BKE_layer_collection_local_sync_all(Main *bmain) +void BKE_layer_collection_local_sync_all(const Main *bmain) { LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 8dc44a32eaa..f0f06b6402a 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -39,6 +39,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_context.h" @@ -51,6 +52,8 @@ #include "BKE_node.h" #include "BKE_texture.h" +#include "BLO_read_write.h" + static void linestyle_init_data(ID *id) { FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; @@ -189,6 +192,558 @@ static void linestyle_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } + for (m = modifiers->first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + BLO_write_struct( + writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + BLO_write_struct( + writer, ColorBand, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + break; + case LS_MODIFIER_MATERIAL: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Material *)m)->color_ramp); + break; + case LS_MODIFIER_TANGENT: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Tangent *)m)->color_ramp); + break; + case LS_MODIFIER_NOISE: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Noise *)m)->color_ramp); + break; + case LS_MODIFIER_CREASE_ANGLE: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); + break; + case LS_MODIFIER_CURVATURE_3D: + BLO_write_struct( + writer, ColorBand, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); + break; + } + } +} + +static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } + for (m = modifiers->first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + BKE_curvemapping_blend_write(writer, + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + BKE_curvemapping_blend_write(writer, + ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_NOISE: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Noise *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); + break; + } + } +} + +static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); + break; + case LS_MODIFIER_CALLIGRAPHY: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } + for (m = modifiers->first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + BKE_curvemapping_blend_write(writer, + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + BKE_curvemapping_blend_write(writer, + ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + BKE_curvemapping_blend_write(writer, + ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); + break; + } + } +} + +static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_SAMPLING: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); + break; + case LS_MODIFIER_BEZIER_CURVE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); + break; + case LS_MODIFIER_SPATIAL_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); + break; + case LS_MODIFIER_TIP_REMOVER: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); + break; + case LS_MODIFIER_POLYGONIZATION: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); + break; + case LS_MODIFIER_GUIDING_LINES: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); + break; + case LS_MODIFIER_BLUEPRINT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); + break; + case LS_MODIFIER_2D_OFFSET: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); + break; + case LS_MODIFIER_2D_TRANSFORM: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); + break; + case LS_MODIFIER_SIMPLIFICATION: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } +} + +static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); + BKE_id_blend_write(writer, &linestyle->id); + + if (linestyle->adt) { + BKE_animdata_blend_write(writer, linestyle->adt); + } + + write_linestyle_color_modifiers(writer, &linestyle->color_modifiers); + write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers); + write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers); + write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers); + for (int a = 0; a < MAX_MTEX; a++) { + if (linestyle->mtex[a]) { + BLO_write_struct(writer, MTex, linestyle->mtex[a]); + } + } + if (linestyle->nodetree) { + BLO_write_struct(writer, bNodeTree, linestyle->nodetree); + ntreeBlendWrite(writer, linestyle->nodetree); + } + } +} + +static void direct_link_linestyle_color_modifier(BlendDataReader *reader, + LineStyleModifier *modifier) +{ + switch (modifier->type) { + case LS_MODIFIER_ALONG_STROKE: { + LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_DISTANCE_FROM_CAMERA: { + LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *) + modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *) + modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_MATERIAL: { + LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_TANGENT: { + LineStyleColorModifier_Tangent *m = (LineStyleColorModifier_Tangent *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_NOISE: { + LineStyleColorModifier_Noise *m = (LineStyleColorModifier_Noise *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_CREASE_ANGLE: { + LineStyleColorModifier_CreaseAngle *m = (LineStyleColorModifier_CreaseAngle *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_CURVATURE_3D: { + LineStyleColorModifier_Curvature_3D *m = (LineStyleColorModifier_Curvature_3D *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + } +} + +static void direct_link_linestyle_alpha_modifier(BlendDataReader *reader, + LineStyleModifier *modifier) +{ + switch (modifier->type) { + case LS_MODIFIER_ALONG_STROKE: { + LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_CAMERA: { + LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_MATERIAL: { + LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_TANGENT: { + LineStyleAlphaModifier_Tangent *m = (LineStyleAlphaModifier_Tangent *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_NOISE: { + LineStyleAlphaModifier_Noise *m = (LineStyleAlphaModifier_Noise *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CREASE_ANGLE: { + LineStyleAlphaModifier_CreaseAngle *m = (LineStyleAlphaModifier_CreaseAngle *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CURVATURE_3D: { + LineStyleAlphaModifier_Curvature_3D *m = (LineStyleAlphaModifier_Curvature_3D *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + } +} + +static void direct_link_linestyle_thickness_modifier(BlendDataReader *reader, + LineStyleModifier *modifier) +{ + switch (modifier->type) { + case LS_MODIFIER_ALONG_STROKE: { + LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_CAMERA: { + LineStyleThicknessModifier_DistanceFromCamera *m = + (LineStyleThicknessModifier_DistanceFromCamera *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleThicknessModifier_DistanceFromObject *m = + (LineStyleThicknessModifier_DistanceFromObject *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_MATERIAL: { + LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_TANGENT: { + LineStyleThicknessModifier_Tangent *m = (LineStyleThicknessModifier_Tangent *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CREASE_ANGLE: { + LineStyleThicknessModifier_CreaseAngle *m = (LineStyleThicknessModifier_CreaseAngle *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CURVATURE_3D: { + LineStyleThicknessModifier_Curvature_3D *m = (LineStyleThicknessModifier_Curvature_3D *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + } +} + +static void direct_link_linestyle_geometry_modifier(BlendDataReader *UNUSED(reader), + LineStyleModifier *UNUSED(modifier)) +{ +} + +static void linestyle_blend_read_data(BlendDataReader *reader, ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + BLO_read_data_address(reader, &linestyle->adt); + BKE_animdata_blend_read_data(reader, linestyle->adt); + BLO_read_list(reader, &linestyle->color_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->color_modifiers) { + direct_link_linestyle_color_modifier(reader, modifier); + } + BLO_read_list(reader, &linestyle->alpha_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->alpha_modifiers) { + direct_link_linestyle_alpha_modifier(reader, modifier); + } + BLO_read_list(reader, &linestyle->thickness_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->thickness_modifiers) { + direct_link_linestyle_thickness_modifier(reader, modifier); + } + BLO_read_list(reader, &linestyle->geometry_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->geometry_modifiers) { + direct_link_linestyle_geometry_modifier(reader, modifier); + } + for (int a = 0; a < MAX_MTEX; a++) { + BLO_read_data_address(reader, &linestyle->mtex[a]); + } +} + +static void linestyle_blend_read_lib(BlendLibReader *reader, ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { + switch (m->type) { + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleColorModifier_DistanceFromObject *cm = + (LineStyleColorModifier_DistanceFromObject *)m; + BLO_read_id_address(reader, linestyle->id.lib, &cm->target); + break; + } + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { + switch (m->type) { + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleAlphaModifier_DistanceFromObject *am = + (LineStyleAlphaModifier_DistanceFromObject *)m; + BLO_read_id_address(reader, linestyle->id.lib, &am->target); + break; + } + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { + switch (m->type) { + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleThicknessModifier_DistanceFromObject *tm = + (LineStyleThicknessModifier_DistanceFromObject *)m; + BLO_read_id_address(reader, linestyle->id.lib, &tm->target); + break; + } + } + } + for (int a = 0; a < MAX_MTEX; a++) { + MTex *mtex = linestyle->mtex[a]; + if (mtex) { + BLO_read_id_address(reader, linestyle->id.lib, &mtex->tex); + BLO_read_id_address(reader, linestyle->id.lib, &mtex->object); + } + } +} + +static void linestyle_blend_read_expand(BlendExpander *expander, ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + for (int a = 0; a < MAX_MTEX; a++) { + if (linestyle->mtex[a]) { + BLO_expand(expander, linestyle->mtex[a]->tex); + BLO_expand(expander, linestyle->mtex[a]->object); + } + } + + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + BLO_expand(expander, ((LineStyleColorModifier_DistanceFromObject *)m)->target); + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + BLO_expand(expander, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target); + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); + } + } +} + IDTypeInfo IDType_ID_LS = { .id_code = ID_LS, .id_filter = FILTER_ID_LS, @@ -206,10 +761,10 @@ IDTypeInfo IDType_ID_LS = { .foreach_id = linestyle_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = linestyle_blend_write, + .blend_read_data = linestyle_blend_read_data, + .blend_read_lib = linestyle_blend_read_lib, + .blend_read_expand = linestyle_blend_read_expand, }; static const char *modifier_name[LS_MODIFIER_NUM] = { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index b70b1ff036b..3ea0f800178 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -35,6 +35,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_constraint_types.h" #include "DNA_gpencil_types.h" #include "DNA_movieclip_types.h" @@ -54,6 +57,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_idtype.h" @@ -74,6 +78,8 @@ #include "GPU_texture.h" +#include "BLO_read_write.h" + #ifdef WITH_OPENEXR # include "intern/openexr/openexr_multi.h" #endif @@ -146,6 +152,179 @@ static void movie_clip_foreach_cache(ID *id, function_callback(id, &key, (void **)&movie_clip->tracking.camera.intrinsics, 0, user_data); } +static void write_movieTracks(BlendWriter *writer, ListBase *tracks) +{ + MovieTrackingTrack *track; + + track = tracks->first; + while (track) { + BLO_write_struct(writer, MovieTrackingTrack, track); + + if (track->markers) { + BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers); + } + + track = track->next; + } +} + +static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) +{ + MovieTrackingPlaneTrack *plane_track; + + for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); + + BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); + BLO_write_struct_array( + writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); + } +} + +static void write_movieReconstruction(BlendWriter *writer, + MovieTrackingReconstruction *reconstruction) +{ + if (reconstruction->camnr) { + BLO_write_struct_array( + writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); + } +} + +static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + MovieClip *clip = (MovieClip *)id; + if (clip->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + clip->anim = NULL; + clip->tracking_context = NULL; + clip->tracking.stats = NULL; + + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *object; + + BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); + BKE_id_blend_write(writer, &clip->id); + + if (clip->adt) { + BKE_animdata_blend_write(writer, clip->adt); + } + + write_movieTracks(writer, &tracking->tracks); + write_moviePlaneTracks(writer, &tracking->plane_tracks); + write_movieReconstruction(writer, &tracking->reconstruction); + + object = tracking->objects.first; + while (object) { + BLO_write_struct(writer, MovieTrackingObject, object); + + write_movieTracks(writer, &object->tracks); + write_moviePlaneTracks(writer, &object->plane_tracks); + write_movieReconstruction(writer, &object->reconstruction); + + object = object->next; + } + } +} + +static void direct_link_movieReconstruction(BlendDataReader *reader, + MovieTrackingReconstruction *reconstruction) +{ + BLO_read_data_address(reader, &reconstruction->cameras); +} + +static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) +{ + BLO_read_list(reader, tracksbase); + + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + BLO_read_data_address(reader, &track->markers); + } +} + +static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) +{ + BLO_read_list(reader, plane_tracks_base); + + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { + BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); + for (int i = 0; i < plane_track->point_tracksnr; i++) { + BLO_read_data_address(reader, &plane_track->point_tracks[i]); + } + + BLO_read_data_address(reader, &plane_track->markers); + } +} + +static void movieclip_blend_read_data(BlendDataReader *reader, ID *id) +{ + MovieClip *clip = (MovieClip *)id; + MovieTracking *tracking = &clip->tracking; + + BLO_read_data_address(reader, &clip->adt); + + direct_link_movieTracks(reader, &tracking->tracks); + direct_link_moviePlaneTracks(reader, &tracking->plane_tracks); + direct_link_movieReconstruction(reader, &tracking->reconstruction); + + BLO_read_data_address(reader, &clip->tracking.act_track); + BLO_read_data_address(reader, &clip->tracking.act_plane_track); + + clip->anim = NULL; + clip->tracking_context = NULL; + clip->tracking.stats = NULL; + + /* TODO we could store those in undo cache storage as well, and preserve them instead of + * re-creating them... */ + BLI_listbase_clear(&clip->runtime.gputextures); + + /* Needed for proper versioning, will be NULL for all newer files anyway. */ + BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track); + + clip->tracking.dopesheet.ok = 0; + BLI_listbase_clear(&clip->tracking.dopesheet.channels); + BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments); + + BLO_read_list(reader, &tracking->objects); + + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + direct_link_movieTracks(reader, &object->tracks); + direct_link_moviePlaneTracks(reader, &object->plane_tracks); + direct_link_movieReconstruction(reader, &object->reconstruction); + } +} + +static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) +{ + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + BLO_read_id_address(reader, clip->id.lib, &track->gpd); + } +} + +static void lib_link_moviePlaneTracks(BlendLibReader *reader, + MovieClip *clip, + ListBase *tracksbase) +{ + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { + BLO_read_id_address(reader, clip->id.lib, &plane_track->image); + } +} + +static void movieclip_blend_read_lib(BlendLibReader *reader, ID *id) +{ + MovieClip *clip = (MovieClip *)id; + MovieTracking *tracking = &clip->tracking; + + BLO_read_id_address(reader, clip->id.lib, &clip->gpd); + + lib_link_movieTracks(reader, clip, &tracking->tracks); + lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks); + + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + lib_link_movieTracks(reader, clip, &object->tracks); + lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks); + } +} + IDTypeInfo IDType_ID_MC = { .id_code = ID_MC, .id_filter = FILTER_ID_MC, @@ -163,9 +342,9 @@ IDTypeInfo IDType_ID_MC = { .foreach_id = movie_clip_foreach_id, .foreach_cache = movie_clip_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, + .blend_write = movieclip_blend_write, + .blend_read_data = movieclip_blend_read_data, + .blend_read_lib = movieclip_blend_read_lib, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 0c3abc70a43..b7d6c7a5a28 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1284,12 +1284,11 @@ static void nlastrip_fix_resize_overlaps(NlaStrip *strip) nls->start = strip->end; } else { - /* shrink transition down to 1 frame long (so that it can still be found), - * then offset everything else by the remaining defict to give the strip room - */ + /* Shrink transition down to 1 frame long (so that it can still be found), + * then offset everything else by the remaining deficit to give the strip room. */ nls->start = nls->end - 1.0f; - /* XXX: review whether preventing fractionals is good here... */ + /* XXX: review whether preventing fractional values is good here... */ offset = ceilf(strip->end - nls->start); /* apply necessary offset to ensure that the strip has enough space */ @@ -1333,12 +1332,11 @@ static void nlastrip_fix_resize_overlaps(NlaStrip *strip) nls->end = strip->start; } else { - /* shrink transition down to 1 frame long (so that it can still be found), - * then offset everything else by the remaining defict to give the strip room - */ + /* Shrink transition down to 1 frame long (so that it can still be found), + * then offset everything else by the remaining deficit to give the strip room. */ nls->end = nls->start + 1.0f; - /* XXX: review whether preventing fractionals is good here... */ + /* XXX: review whether preventing fractional values is good here... */ offset = ceilf(nls->end - strip->start); /* apply necessary offset to ensure that the strip has enough space */ diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 900817a0513..1c7060541db 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -30,6 +30,9 @@ #include <stdlib.h> #include <string.h> +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_gpencil_types.h" @@ -54,6 +57,7 @@ #include "BKE_anim_data.h" #include "BKE_animsys.h" +#include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_idprop.h" #include "BKE_idtype.h" @@ -79,6 +83,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" +#include "BLO_read_write.h" + #define NODE_DEFAULT_MAX_WIDTH 700 /* Fallback types for undefined tree, nodes, sockets */ @@ -337,6 +343,511 @@ static void node_foreach_cache(ID *id, } } +static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) +{ + if (sock->default_value == NULL) { + return; + } + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_FLOAT: + BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value); + break; + case SOCK_VECTOR: + BLO_write_struct(writer, bNodeSocketValueVector, sock->default_value); + break; + case SOCK_RGBA: + BLO_write_struct(writer, bNodeSocketValueRGBA, sock->default_value); + break; + case SOCK_BOOLEAN: + BLO_write_struct(writer, bNodeSocketValueBoolean, sock->default_value); + break; + case SOCK_INT: + BLO_write_struct(writer, bNodeSocketValueInt, sock->default_value); + break; + case SOCK_STRING: + BLO_write_struct(writer, bNodeSocketValueString, sock->default_value); + break; + case SOCK_OBJECT: + BLO_write_struct(writer, bNodeSocketValueObject, sock->default_value); + break; + case SOCK_IMAGE: + BLO_write_struct(writer, bNodeSocketValueImage, sock->default_value); + break; + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_EMITTERS: + case SOCK_EVENTS: + case SOCK_FORCES: + case SOCK_CONTROL_FLOW: + BLI_assert(false); + break; + } +} + +static void write_node_socket(BlendWriter *writer, bNodeSocket *sock) +{ + /* actual socket writing */ + BLO_write_struct(writer, bNodeSocket, sock); + + if (sock->prop) { + IDP_BlendWrite(writer, sock->prop); + } + + write_node_socket_default_value(writer, sock); +} +static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) +{ + /* actual socket writing */ + BLO_write_struct(writer, bNodeSocket, sock); + + if (sock->prop) { + IDP_BlendWrite(writer, sock->prop); + } + + write_node_socket_default_value(writer, sock); +} + +/* this is only direct data, tree itself should have been written */ +void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) +{ + /* for link_list() speed, we write per list */ + + if (ntree->adt) { + BKE_animdata_blend_write(writer, ntree->adt); + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + BLO_write_struct(writer, bNode, node); + + if (node->prop) { + IDP_BlendWrite(writer, node->prop); + } + + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + write_node_socket(writer, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + write_node_socket(writer, sock); + } + + LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { + BLO_write_struct(writer, bNodeLink, link); + } + + if (node->storage) { + /* could be handlerized at some point, now only 1 exception still */ + if ((ntree->type == NTREE_SHADER) && + ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) { + BKE_curvemapping_blend_write(writer, node->storage); + } + else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) { + NodeShaderScript *nss = (NodeShaderScript *)node->storage; + if (nss->bytecode) { + BLO_write_string(writer, nss->bytecode); + } + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, + CMP_NODE_TIME, + CMP_NODE_CURVE_VEC, + CMP_NODE_CURVE_RGB, + CMP_NODE_HUECORRECT)) { + BKE_curvemapping_blend_write(writer, node->storage); + } + else if ((ntree->type == NTREE_TEXTURE) && + (node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) { + BKE_curvemapping_blend_write(writer, node->storage); + } + else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) { + /* pass */ + } + else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) { + /* Simple forward compatibility for fix for T50736. + * Not ideal (there is no ideal solution here), but should do for now. */ + NodeGlare *ndg = node->storage; + /* Not in undo case. */ + if (!BLO_write_is_undo(writer)) { + switch (ndg->type) { + case 2: /* Grrrr! magic numbers :( */ + ndg->angle = ndg->streaks; + break; + case 0: + ndg->angle = ndg->star_45; + break; + default: + break; + } + } + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) { + NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; + if (nc->matte_id) { + BLO_write_string(writer, nc->matte_id); + } + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + else if (node->typeinfo != &NodeTypeUndefined) { + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + } + + if (node->type == CMP_NODE_OUTPUT_FILE) { + /* inputs have own storage data */ + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage); + } + } + if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) { + /* write extra socket info */ + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + BLO_write_struct(writer, NodeImageLayer, sock->storage); + } + } + } + + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + BLO_write_struct(writer, bNodeLink, link); + } + + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { + write_node_socket_interface(writer, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { + write_node_socket_interface(writer, sock); + } +} + +static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bNodeTree *ntree = (bNodeTree *)id; + if (ntree->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + ntree->init = 0; /* to set callbacks and force setting types */ + ntree->is_updating = false; + ntree->typeinfo = NULL; + ntree->interface_type = NULL; + ntree->progress = NULL; + ntree->execdata = NULL; + + BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id); + /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot + * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ + BKE_id_blend_write(writer, &ntree->id); + + ntreeBlendWrite(writer, ntree); + } +} + +static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) +{ + BLO_read_data_address(reader, &sock->prop); + IDP_BlendDataRead(reader, &sock->prop); + + BLO_read_data_address(reader, &sock->link); + sock->typeinfo = NULL; + BLO_read_data_address(reader, &sock->storage); + BLO_read_data_address(reader, &sock->default_value); + sock->cache = NULL; +} + +/* ntree itself has been read! */ +void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) +{ + /* note: writing and reading goes in sync, for speed */ + ntree->init = 0; /* to set callbacks and force setting types */ + ntree->is_updating = false; + ntree->typeinfo = NULL; + ntree->interface_type = NULL; + + ntree->progress = NULL; + ntree->execdata = NULL; + + BLO_read_data_address(reader, &ntree->adt); + BKE_animdata_blend_read_data(reader, ntree->adt); + + BLO_read_list(reader, &ntree->nodes); + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + node->typeinfo = NULL; + + BLO_read_list(reader, &node->inputs); + BLO_read_list(reader, &node->outputs); + + BLO_read_data_address(reader, &node->prop); + IDP_BlendDataRead(reader, &node->prop); + + BLO_read_list(reader, &node->internal_links); + LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { + BLO_read_data_address(reader, &link->fromnode); + BLO_read_data_address(reader, &link->fromsock); + BLO_read_data_address(reader, &link->tonode); + BLO_read_data_address(reader, &link->tosock); + } + + if (node->type == CMP_NODE_MOVIEDISTORTION) { + /* Do nothing, this is runtime cache and hence handled by generic code using + * `IDTypeInfo.foreach_cache` callback. */ + } + else { + BLO_read_data_address(reader, &node->storage); + } + + if (node->storage) { + /* could be handlerized at some point */ + switch (node->type) { + case SH_NODE_CURVE_VEC: + case SH_NODE_CURVE_RGB: + case CMP_NODE_TIME: + case CMP_NODE_CURVE_VEC: + case CMP_NODE_CURVE_RGB: + case CMP_NODE_HUECORRECT: + case TEX_NODE_CURVE_RGB: + case TEX_NODE_CURVE_TIME: { + BKE_curvemapping_blend_read(reader, node->storage); + break; + } + case SH_NODE_SCRIPT: { + NodeShaderScript *nss = (NodeShaderScript *)node->storage; + BLO_read_data_address(reader, &nss->bytecode); + break; + } + case SH_NODE_TEX_POINTDENSITY: { + NodeShaderTexPointDensity *npd = (NodeShaderTexPointDensity *)node->storage; + memset(&npd->pd, 0, sizeof(npd->pd)); + break; + } + case SH_NODE_TEX_IMAGE: { + NodeTexImage *tex = (NodeTexImage *)node->storage; + tex->iuser.ok = 1; + tex->iuser.scene = NULL; + break; + } + case SH_NODE_TEX_ENVIRONMENT: { + NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; + tex->iuser.ok = 1; + tex->iuser.scene = NULL; + break; + } + case CMP_NODE_IMAGE: + case CMP_NODE_R_LAYERS: + case CMP_NODE_VIEWER: + case CMP_NODE_SPLITVIEWER: { + ImageUser *iuser = node->storage; + iuser->ok = 1; + iuser->scene = NULL; + break; + } + case CMP_NODE_CRYPTOMATTE: { + NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; + BLO_read_data_address(reader, &nc->matte_id); + break; + } + case TEX_NODE_IMAGE: { + ImageUser *iuser = node->storage; + iuser->ok = 1; + iuser->scene = NULL; + break; + } + default: + break; + } + } + } + BLO_read_list(reader, &ntree->links); + + /* and we connect the rest */ + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + BLO_read_data_address(reader, &node->parent); + node->lasty = 0; + + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + direct_link_node_socket(reader, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + direct_link_node_socket(reader, sock); + } + } + + /* interface socket lists */ + BLO_read_list(reader, &ntree->inputs); + BLO_read_list(reader, &ntree->outputs); + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { + direct_link_node_socket(reader, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { + direct_link_node_socket(reader, sock); + } + + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + BLO_read_data_address(reader, &link->fromnode); + BLO_read_data_address(reader, &link->tonode); + BLO_read_data_address(reader, &link->fromsock); + BLO_read_data_address(reader, &link->tosock); + } + + /* TODO, should be dealt by new generic cache handling of IDs... */ + ntree->previews = NULL; + + /* type verification is in lib-link */ +} + +static void ntree_blend_read_data(BlendDataReader *reader, ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntreeBlendReadData(reader, ntree); +} + +static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSocket *sock) +{ + IDP_BlendReadLib(reader, sock->prop); + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_OBJECT: { + bNodeSocketValueObject *default_value = sock->default_value; + BLO_read_id_address(reader, lib, &default_value->value); + break; + } + case SOCK_IMAGE: { + bNodeSocketValueImage *default_value = sock->default_value; + BLO_read_id_address(reader, lib, &default_value->value); + break; + } + case SOCK_FLOAT: + case SOCK_VECTOR: + case SOCK_RGBA: + case SOCK_BOOLEAN: + case SOCK_INT: + case SOCK_STRING: + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_EMITTERS: + case SOCK_EVENTS: + case SOCK_FORCES: + case SOCK_CONTROL_FLOW: + break; + } +} + +static void lib_link_node_sockets(BlendLibReader *reader, Library *lib, ListBase *sockets) +{ + LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { + lib_link_node_socket(reader, lib, sock); + } +} + +void ntreeBlendReadLib(struct BlendLibReader *reader, struct bNodeTree *ntree) +{ + Library *lib = ntree->id.lib; + + BLO_read_id_address(reader, lib, &ntree->gpd); + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + /* Link ID Properties -- and copy this comment EXACTLY for easy finding + * of library blocks that implement this.*/ + IDP_BlendReadLib(reader, node->prop); + + BLO_read_id_address(reader, lib, &node->id); + + lib_link_node_sockets(reader, lib, &node->inputs); + lib_link_node_sockets(reader, lib, &node->outputs); + } + + lib_link_node_sockets(reader, lib, &ntree->inputs); + lib_link_node_sockets(reader, lib, &ntree->outputs); + + /* Set node->typeinfo pointers. This is done in lib linking, after the + * first versioning that can change types still without functions that + * update the typeinfo pointers. Versioning after lib linking needs + * these top be valid. */ + ntreeSetTypes(NULL, ntree); + + /* For nodes with static socket layout, add/remove sockets as needed + * to match the static layout. */ + if (!BLO_read_lib_is_undo(reader)) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + node_verify_socket_templates(ntree, node); + } + } +} + +static void ntree_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntreeBlendReadLib(reader, ntree); +} + +static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) +{ + IDP_BlendReadExpand(expander, sock->prop); + + if (sock->default_value != NULL) { + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_OBJECT: { + bNodeSocketValueObject *default_value = sock->default_value; + BLO_expand(expander, default_value->value); + break; + } + case SOCK_IMAGE: { + bNodeSocketValueImage *default_value = sock->default_value; + BLO_expand(expander, default_value->value); + break; + } + case SOCK_FLOAT: + case SOCK_VECTOR: + case SOCK_RGBA: + case SOCK_BOOLEAN: + case SOCK_INT: + case SOCK_STRING: + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_EMITTERS: + case SOCK_EVENTS: + case SOCK_FORCES: + case SOCK_CONTROL_FLOW: + break; + } + } +} + +static void expand_node_sockets(BlendExpander *expander, ListBase *sockets) +{ + LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { + expand_node_socket(expander, sock); + } +} + +void ntreeBlendReadExpand(BlendExpander *expander, bNodeTree *ntree) +{ + if (ntree->gpd) { + BLO_expand(expander, ntree->gpd); + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->id && node->type != CMP_NODE_R_LAYERS) { + BLO_expand(expander, node->id); + } + + IDP_BlendReadExpand(expander, node->prop); + + expand_node_sockets(expander, &node->inputs); + expand_node_sockets(expander, &node->outputs); + } + + expand_node_sockets(expander, &ntree->inputs); + expand_node_sockets(expander, &ntree->outputs); +} + +static void ntree_blend_read_expand(BlendExpander *expander, ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntreeBlendReadExpand(expander, ntree); +} + IDTypeInfo IDType_ID_NT = { .id_code = ID_NT, .id_filter = FILTER_ID_NT, @@ -354,10 +865,10 @@ IDTypeInfo IDType_ID_NT = { .foreach_id = node_foreach_id, .foreach_cache = node_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = ntree_blend_write, + .blend_read_data = ntree_blend_read_data, + .blend_read_lib = ntree_blend_read_lib, + .blend_read_expand = ntree_blend_read_expand, }; static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType *ntype) diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 6793f5e1169..ac3686a021b 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -51,6 +51,8 @@ #include "BKE_sound.h" #include "BKE_volume.h" +#include "BLO_read_write.h" + int BKE_packedfile_seek(PackedFile *pf, int offset, int whence) { int oldseek = -1, seek = 0; @@ -852,3 +854,29 @@ void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, enum ePF break; } } + +void BKE_packedfile_blend_write(BlendWriter *writer, PackedFile *pf) +{ + if (pf == NULL) { + return; + } + BLO_write_struct(writer, PackedFile, pf); + BLO_write_raw(writer, pf->size, pf->data); +} + +void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p) +{ + BLO_read_packed_address(reader, pf_p); + PackedFile *pf = *pf_p; + if (pf == NULL) { + return; + } + + BLO_read_packed_address(reader, &pf->data); + if (pf->data == NULL) { + /* We cannot allow a PackedFile with a NULL data field, + * the whole code assumes this is not possible. See T70315. */ + printf("%s: NULL packedfile data, cleaning up...\n", __func__); + MEM_SAFE_FREE(pf); + } +} diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 92c5af127fc..6c950c4b33f 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -1529,20 +1529,17 @@ static int evaluate_seq_frame_gen(Sequence **seq_arr, ListBase *seqbase, int cfr /* Drop strips which are used for effect inputs, we don't want * them to blend into render stack in any other way than effect - * string rendering. - */ + * string rendering. */ for (LinkNode *seq_item = effect_inputs.list; seq_item; seq_item = seq_item->next) { Sequence *seq = seq_item->link; - /* It's possible that effetc strip would be placed to the same + /* It's possible that effect strip would be placed to the same * 'machine' as it's inputs. We don't want to clear such strips - * from the stack. - */ + * from the stack. */ if (seq_arr[seq->machine] && seq_arr[seq->machine]->type & SEQ_TYPE_EFFECT) { continue; } - /* If we're shown a specified channel, then we want to see the stirps - * which belongs to this machine. - */ + /* If we're shown a specified channel, then we want to see the strips + * which belongs to this machine. */ if (chanshown != 0 && chanshown <= seq->machine) { continue; } @@ -1776,7 +1773,7 @@ static void seq_open_anim_file(Scene *scene, Sequence *seq, bool openfile) seq->strip->colorspace_settings.name); } - /* no individual view files - monoscopic, stereo 3d or exr multiview */ + /* No individual view files - monoscopic, stereo 3d or EXR multi-view. */ totfiles = 1; } @@ -1829,7 +1826,7 @@ static bool seq_proxy_get_custom_file_fname(Sequence *seq, char *name, const int if (view_id > 0) { BLI_snprintf(suffix, sizeof(suffix), "_%d", view_id); /* TODO(sergey): This will actually append suffix after extension - * which is weird but how was originally coded in multiview branch. + * which is weird but how was originally coded in multi-view branch. */ BLI_snprintf(name, PROXY_MAXFILE, "%s_%s", fname, suffix); } @@ -1855,7 +1852,7 @@ static bool seq_proxy_get_fname(Editing *ed, return false; } - /* Multiview suffix. */ + /* Multi-view suffix. */ if (view_id > 0) { BLI_snprintf(suffix, sizeof(suffix), "_%d", view_id); } @@ -2566,7 +2563,9 @@ static void *color_balance_do_thread(void *thread_data_v) return NULL; } -/* cfra is offset by fra_offset only in case we are using a real mask. */ +/** + * \a cfra is offset by \a fra_offset only in case we are using a real mask. + */ ImBuf *BKE_sequencer_render_mask_input(const SeqRenderData *context, int mask_input_type, Sequence *mask_sequence, @@ -2968,7 +2967,7 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, break; case EARLY_DO_EFFECT: for (i = 0; i < 3; i++) { - /* Speed effect requires time remapping of cfra for input(s). */ + /* Speed effect requires time remapping of `cfra` for input(s). */ if (input[0] && seq->type == SEQ_TYPE_SPEED) { float target_frame = BKE_sequencer_speed_effect_target_frame_get(context, seq, cfra, i); ibuf[i] = seq_render_strip(context, state, input[0], target_frame); @@ -3013,7 +3012,9 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, return out; } -/* Render individual view for multiview or single (default view) for monoview. */ +/** + * Render individual view for multi-view or single (default view) for mono-view. + */ static ImBuf *seq_render_image_strip_view(const SeqRenderData *context, Sequence *seq, char *name, @@ -3048,7 +3049,7 @@ static ImBuf *seq_render_image_strip_view(const SeqRenderData *context, imb_freerectImBuf(ibuf); } - /* All sequencer color is done in SRGB space, linear gives odd crossfades. */ + /* All sequencer color is done in SRGB space, linear gives odd cross-fades. */ BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false); return ibuf; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 1ebbc1e2d77..88b32e194cf 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -211,7 +211,7 @@ static float sb_time_scale(Object *ob) * will cause unwanted responses of the softbody system (which does inter frame calculations ) * so first 'cure' would be: interpolate linear in time .. * Q: why do i write this? - * A: because it happened once, that some eger coder 'streamlined' code to fail. + * A: because it happened once, that some eager coder 'streamlined' code to fail. * We DO linear interpolation for goals .. and i think we should do on animated properties as well */ diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index bde9b9ab9b8..c1f2c66badb 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -55,6 +55,8 @@ #include "BKE_node.h" #include "BKE_text.h" +#include "BLO_read_write.h" + #ifdef WITH_PYTHON # include "BPY_extern.h" #endif @@ -167,6 +169,72 @@ static void text_free_data(ID *id) #endif } +static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Text *text = (Text *)id; + + /* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */ + if ((text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { + text->flags &= ~TXT_ISEXT; + } + + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + text->compiled = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, Text, id_address, &text->id); + BKE_id_blend_write(writer, &text->id); + + if (text->filepath) { + BLO_write_string(writer, text->filepath); + } + + if (!(text->flags & TXT_ISEXT)) { + /* now write the text data, in two steps for optimization in the readfunction */ + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { + BLO_write_struct(writer, TextLine, tmp); + } + + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { + BLO_write_raw(writer, tmp->len + 1, tmp->line); + } + } +} + +static void text_blend_read_data(BlendDataReader *reader, ID *id) +{ + Text *text = (Text *)id; + BLO_read_data_address(reader, &text->filepath); + + text->compiled = NULL; + +#if 0 + if (text->flags & TXT_ISEXT) { + BKE_text_reload(text); + } + /* else { */ +#endif + + BLO_read_list(reader, &text->lines); + + BLO_read_data_address(reader, &text->curl); + BLO_read_data_address(reader, &text->sell); + + LISTBASE_FOREACH (TextLine *, ln, &text->lines) { + BLO_read_data_address(reader, &ln->line); + ln->format = NULL; + + if (ln->len != (int)strlen(ln->line)) { + printf("Error loading text, line lengths differ\n"); + ln->len = strlen(ln->line); + } + } + + text->flags = (text->flags) & ~TXT_ISEXT; + + id_us_ensure_real(&text->id); +} + IDTypeInfo IDType_ID_TXT = { .id_code = ID_TXT, .id_filter = FILTER_ID_TXT, @@ -184,8 +252,8 @@ IDTypeInfo IDType_ID_TXT = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = text_blend_write, + .blend_read_data = text_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc index 17da3b9f493..d64587b85b4 100644 --- a/source/blender/blenlib/intern/string_search.cc +++ b/source/blender/blenlib/intern/string_search.cc @@ -108,7 +108,7 @@ int damerau_levenshtein_distance(StringRef a, StringRef b) */ int get_fuzzy_match_errors(StringRef query, StringRef full) { - /* If it is a perfect partial match, return immediatly. */ + /* If it is a perfect partial match, return immediately. */ if (full.find(query) != StringRef::not_found) { return 0; } @@ -180,8 +180,8 @@ int get_fuzzy_match_errors(StringRef query, StringRef full) * So "bose" does not match "select boundary". However, individual words can be skipped. For * example, "rocc" matches "rotate edge ccw". * - * Returns true when the match was successfull. If it was successfull, the used words are tagged in - * r_word_is_matched. + * \return true when the match was successful. + * If it was successful, the used words are tagged in \a r_word_is_matched. */ static bool match_word_initials(StringRef query, Span<StringRef> words, @@ -384,7 +384,7 @@ void extract_normalized_words(StringRef str, } offset += size; } - /* If the last word is not followed by a separator, it has to be handld separately. */ + /* If the last word is not followed by a separator, it has to be handled separately. */ if (is_in_word) { r_words.append(str_copy.drop_prefix(static_cast<int>(word_start))); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 18d563cb365..1c638079230 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -113,6 +113,7 @@ #include "BKE_action.h" #include "BKE_anim_data.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_brush.h" #include "BKE_collection.h" @@ -128,6 +129,7 @@ #include "BKE_global.h" // for G #include "BKE_gpencil_modifier.h" #include "BKE_hair.h" +#include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_image.h" @@ -145,6 +147,7 @@ #include "BKE_nla.h" #include "BKE_node.h" // for tree type defines #include "BKE_object.h" +#include "BKE_packedFile.h" #include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_pointcache.h" @@ -2246,35 +2249,10 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */ /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read Image Preview - * \{ */ - -static PreviewImage *direct_link_preview_image(BlendDataReader *reader, PreviewImage *old_prv) -{ - PreviewImage *prv = BLO_read_get_new_data_address(reader, old_prv); - - if (prv) { - for (int i = 0; i < NUM_ICON_SIZES; i++) { - if (prv->rect[i]) { - BLO_read_data_address(reader, &prv->rect[i]); - } - prv->gputexture[i] = NULL; - } - prv->icon_id = 0; - prv->tag = 0; - } - - return prv; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID * \{ */ static void lib_link_id(BlendLibReader *reader, ID *id); -static void lib_link_nodetree(BlendLibReader *reader, bNodeTree *ntree); static void lib_link_collection(BlendLibReader *reader, Collection *collection); static void lib_link_id_embedded_id(BlendLibReader *reader, ID *id) @@ -2284,7 +2262,7 @@ static void lib_link_id_embedded_id(BlendLibReader *reader, ID *id) bNodeTree *nodetree = ntreeFromID(id); if (nodetree != NULL) { lib_link_id(reader, &nodetree->id); - lib_link_nodetree(reader, nodetree); + ntreeBlendReadLib(reader, nodetree); } if (GS(id->name) == ID_SCE) { @@ -2338,7 +2316,6 @@ static void direct_link_id_override_property_cb(BlendDataReader *reader, void *d static void direct_link_id_common( BlendDataReader *reader, Library *current_library, ID *id, ID *id_old, const int tag); -static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree); static void direct_link_collection(BlendDataReader *reader, Collection *collection); static void direct_link_id_embedded_id(BlendDataReader *reader, @@ -2355,7 +2332,7 @@ static void direct_link_id_embedded_id(BlendDataReader *reader, (ID *)*nodetree, id_old != NULL ? (ID *)ntreeFromID(id_old) : NULL, 0); - direct_link_nodetree(reader, *nodetree); + ntreeBlendReadData(reader, *nodetree); } if (GS(id->name) == ID_SCE) { @@ -2629,29 +2606,6 @@ static void direct_link_paint_curve(BlendDataReader *reader, PaintCurve *pc) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read PackedFile - * \{ */ - -static PackedFile *direct_link_packedfile(BlendDataReader *reader, PackedFile *pf) -{ - BLO_read_packed_address(reader, &pf); - - if (pf) { - BLO_read_packed_address(reader, &pf->data); - if (pf->data == NULL) { - /* We cannot allow a PackedFile with a NULL data field, - * the whole code assumes this is not possible. See T70315. */ - printf("%s: NULL packedfile data, cleaning up...\n", __func__); - MEM_SAFE_FREE(pf); - } - } - - return pf; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Animation (legacy for version patching) * \{ */ @@ -2711,80 +2665,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Action - * \{ */ - -static void lib_link_action(BlendLibReader *reader, bAction *act) -{ - // XXX deprecated - old animation system <<< - LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { - BLO_read_id_address(reader, act->id.lib, &chan->ipo); - lib_link_constraint_channels(reader, &act->id, &chan->constraintChannels); - } - // >>> XXX deprecated - old animation system - - BKE_fcurve_blend_read_lib(reader, &act->id, &act->curves); - - LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { - if (marker->camera) { - BLO_read_id_address(reader, act->id.lib, &marker->camera); - } - } -} - -static void direct_link_action(BlendDataReader *reader, bAction *act) -{ - BLO_read_list(reader, &act->curves); - BLO_read_list(reader, &act->chanbase); // XXX deprecated - old animation system - BLO_read_list(reader, &act->groups); - BLO_read_list(reader, &act->markers); - - // XXX deprecated - old animation system <<< - LISTBASE_FOREACH (bActionChannel *, achan, &act->chanbase) { - BLO_read_data_address(reader, &achan->grp); - - BLO_read_list(reader, &achan->constraintChannels); - } - // >>> XXX deprecated - old animation system - - BKE_fcurve_blend_read_data(reader, &act->curves); - - LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { - BLO_read_data_address(reader, &agrp->channels.first); - BLO_read_data_address(reader, &agrp->channels.last); - } -} - -/* ------- */ - -static void lib_link_keyingsets(BlendLibReader *reader, ID *id, ListBase *list) -{ - /* here, we're only interested in the ID pointer stored in some of the paths */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - BLO_read_id_address(reader, id->lib, &ksp->id); - } - } -} - -/* NOTE: this assumes that BLO_read_list has already been called on the list */ -static void direct_link_keyingsets(BlendDataReader *reader, ListBase *list) -{ - /* link KeyingSet data to KeyingSet again (non ID-libs) */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - /* paths */ - BLO_read_list(reader, &ks->paths); - - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - /* rna path */ - BLO_read_data_address(reader, &ksp->rna_path); - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: CacheFiles * \{ */ @@ -2878,246 +2758,6 @@ static void lib_link_workspace_instance_hook(BlendLibReader *reader, /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Node Tree - * \{ */ - -static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSocket *sock) -{ - IDP_BlendReadLib(reader, sock->prop); - - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); - break; - } - case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); - break; - } - case SOCK_FLOAT: - case SOCK_VECTOR: - case SOCK_RGBA: - case SOCK_BOOLEAN: - case SOCK_INT: - case SOCK_STRING: - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_EMITTERS: - case SOCK_EVENTS: - case SOCK_FORCES: - case SOCK_CONTROL_FLOW: - break; - } -} - -static void lib_link_node_sockets(BlendLibReader *reader, Library *lib, ListBase *sockets) -{ - LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { - lib_link_node_socket(reader, lib, sock); - } -} - -/* Single node tree (also used for material/scene trees), ntree is not NULL */ -static void lib_link_ntree(BlendLibReader *reader, Library *lib, bNodeTree *ntree) -{ - ntree->id.lib = lib; - - BLO_read_id_address(reader, lib, &ntree->gpd); - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - /* Link ID Properties -- and copy this comment EXACTLY for easy finding - * of library blocks that implement this.*/ - IDP_BlendReadLib(reader, node->prop); - - BLO_read_id_address(reader, lib, &node->id); - - lib_link_node_sockets(reader, lib, &node->inputs); - lib_link_node_sockets(reader, lib, &node->outputs); - } - - lib_link_node_sockets(reader, lib, &ntree->inputs); - lib_link_node_sockets(reader, lib, &ntree->outputs); - - /* Set node->typeinfo pointers. This is done in lib linking, after the - * first versioning that can change types still without functions that - * update the typeinfo pointers. Versioning after lib linking needs - * these top be valid. */ - ntreeSetTypes(NULL, ntree); - - /* For nodes with static socket layout, add/remove sockets as needed - * to match the static layout. */ - if (!BLO_read_lib_is_undo(reader)) { - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - node_verify_socket_templates(ntree, node); - } - } -} - -/* library ntree linking after fileread */ -static void lib_link_nodetree(BlendLibReader *reader, bNodeTree *ntree) -{ - lib_link_ntree(reader, ntree->id.lib, ntree); -} - -static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) -{ - BLO_read_data_address(reader, &sock->prop); - IDP_BlendDataRead(reader, &sock->prop); - - BLO_read_data_address(reader, &sock->link); - sock->typeinfo = NULL; - BLO_read_data_address(reader, &sock->storage); - BLO_read_data_address(reader, &sock->default_value); - sock->cache = NULL; -} - -/* ntree itself has been read! */ -static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) -{ - /* note: writing and reading goes in sync, for speed */ - - ntree->init = 0; /* to set callbacks and force setting types */ - ntree->is_updating = false; - ntree->typeinfo = NULL; - ntree->interface_type = NULL; - - ntree->progress = NULL; - ntree->execdata = NULL; - - BLO_read_data_address(reader, &ntree->adt); - BKE_animdata_blend_read_data(reader, ntree->adt); - - BLO_read_list(reader, &ntree->nodes); - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - node->typeinfo = NULL; - - BLO_read_list(reader, &node->inputs); - BLO_read_list(reader, &node->outputs); - - BLO_read_data_address(reader, &node->prop); - IDP_BlendDataRead(reader, &node->prop); - - BLO_read_list(reader, &node->internal_links); - LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { - BLO_read_data_address(reader, &link->fromnode); - BLO_read_data_address(reader, &link->fromsock); - BLO_read_data_address(reader, &link->tonode); - BLO_read_data_address(reader, &link->tosock); - } - - if (node->type == CMP_NODE_MOVIEDISTORTION) { - /* Do nothing, this is runtime cache and hence handled by generic code using - * `IDTypeInfo.foreach_cache` callback. */ - } - else { - BLO_read_data_address(reader, &node->storage); - } - - if (node->storage) { - /* could be handlerized at some point */ - switch (node->type) { - case SH_NODE_CURVE_VEC: - case SH_NODE_CURVE_RGB: - case CMP_NODE_TIME: - case CMP_NODE_CURVE_VEC: - case CMP_NODE_CURVE_RGB: - case CMP_NODE_HUECORRECT: - case TEX_NODE_CURVE_RGB: - case TEX_NODE_CURVE_TIME: { - BKE_curvemapping_blend_read(reader, node->storage); - break; - } - case SH_NODE_SCRIPT: { - NodeShaderScript *nss = (NodeShaderScript *)node->storage; - BLO_read_data_address(reader, &nss->bytecode); - break; - } - case SH_NODE_TEX_POINTDENSITY: { - NodeShaderTexPointDensity *npd = (NodeShaderTexPointDensity *)node->storage; - memset(&npd->pd, 0, sizeof(npd->pd)); - break; - } - case SH_NODE_TEX_IMAGE: { - NodeTexImage *tex = (NodeTexImage *)node->storage; - tex->iuser.ok = 1; - tex->iuser.scene = NULL; - break; - } - case SH_NODE_TEX_ENVIRONMENT: { - NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; - tex->iuser.ok = 1; - tex->iuser.scene = NULL; - break; - } - case CMP_NODE_IMAGE: - case CMP_NODE_R_LAYERS: - case CMP_NODE_VIEWER: - case CMP_NODE_SPLITVIEWER: { - ImageUser *iuser = node->storage; - iuser->ok = 1; - iuser->scene = NULL; - break; - } - case CMP_NODE_CRYPTOMATTE: { - NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; - BLO_read_data_address(reader, &nc->matte_id); - break; - } - case TEX_NODE_IMAGE: { - ImageUser *iuser = node->storage; - iuser->ok = 1; - iuser->scene = NULL; - break; - } - default: - break; - } - } - } - BLO_read_list(reader, &ntree->links); - - /* and we connect the rest */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - BLO_read_data_address(reader, &node->parent); - node->lasty = 0; - - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - direct_link_node_socket(reader, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { - direct_link_node_socket(reader, sock); - } - } - - /* interface socket lists */ - BLO_read_list(reader, &ntree->inputs); - BLO_read_list(reader, &ntree->outputs); - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { - direct_link_node_socket(reader, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { - direct_link_node_socket(reader, sock); - } - - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - BLO_read_data_address(reader, &link->fromnode); - BLO_read_data_address(reader, &link->tonode); - BLO_read_data_address(reader, &link->fromsock); - BLO_read_data_address(reader, &link->tosock); - } - - /* TODO, should be dealt by new generic cache handling of IDs... */ - ntree->previews = NULL; - - /* type verification is in lib-link */ -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: Armature * \{ */ @@ -3383,7 +3023,8 @@ static void direct_link_light(BlendDataReader *reader, Light *la) BKE_curvemapping_blend_read(reader, la->curfalloff); } - la->preview = direct_link_preview_image(reader, la->preview); + BLO_read_data_address(reader, &la->preview); + BKE_previewimg_blend_read(reader, la->preview); } /** \} */ @@ -3502,73 +3143,14 @@ static void direct_link_world(BlendDataReader *reader, World *wrld) BLO_read_data_address(reader, &wrld->adt); BKE_animdata_blend_read_data(reader, wrld->adt); - wrld->preview = direct_link_preview_image(reader, wrld->preview); + BLO_read_data_address(reader, &wrld->preview); + BKE_previewimg_blend_read(reader, wrld->preview); BLI_listbase_clear(&wrld->gpumaterial); } /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: VFont - * \{ */ - -static void lib_link_vfont(BlendLibReader *UNUSED(reader), VFont *UNUSED(vf)) -{ -} - -static void direct_link_vfont(BlendDataReader *reader, VFont *vf) -{ - vf->data = NULL; - vf->temp_pf = NULL; - vf->packedfile = direct_link_packedfile(reader, vf->packedfile); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Text - * \{ */ - -static void lib_link_text(BlendLibReader *UNUSED(reader), Text *UNUSED(text)) -{ -} - -static void direct_link_text(BlendDataReader *reader, Text *text) -{ - BLO_read_data_address(reader, &text->filepath); - - text->compiled = NULL; - -#if 0 - if (text->flags & TXT_ISEXT) { - BKE_text_reload(text); - } - /* else { */ -#endif - - BLO_read_list(reader, &text->lines); - - BLO_read_data_address(reader, &text->curl); - BLO_read_data_address(reader, &text->sell); - - LISTBASE_FOREACH (TextLine *, ln, &text->lines) { - BLO_read_data_address(reader, &ln->line); - ln->format = NULL; - - if (ln->len != (int)strlen(ln->line)) { - printf("Error loading text, line lengths differ\n"); - ln->len = strlen(ln->line); - } - } - - text->flags = (text->flags) & ~TXT_ISEXT; - - id_us_ensure_real(&text->id); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: Image * \{ */ @@ -3598,16 +3180,17 @@ static void direct_link_image(BlendDataReader *reader, Image *ima) if (ima->packedfiles.first) { LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { - imapf->packedfile = direct_link_packedfile(reader, imapf->packedfile); + BKE_packedfile_blend_read(reader, &imapf->packedfile); } ima->packedfile = NULL; } else { - ima->packedfile = direct_link_packedfile(reader, ima->packedfile); + BKE_packedfile_blend_read(reader, &ima->packedfile); } BLI_listbase_clear(&ima->anims); - ima->preview = direct_link_preview_image(reader, ima->preview); + BLO_read_data_address(reader, &ima->preview); + BKE_previewimg_blend_read(reader, ima->preview); BLO_read_data_address(reader, &ima->stereo3d_format); LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { tile->ok = IMA_OK; @@ -3724,7 +3307,8 @@ static void direct_link_texture(BlendDataReader *reader, Tex *tex) BLO_read_data_address(reader, &tex->coba); - tex->preview = direct_link_preview_image(reader, tex->preview); + BLO_read_data_address(reader, &tex->preview); + BKE_previewimg_blend_read(reader, tex->preview); tex->iuser.ok = 1; tex->iuser.scene = NULL; @@ -3759,7 +3343,9 @@ static void direct_link_material(BlendDataReader *reader, Material *ma) ma->texpaintslot = NULL; - ma->preview = direct_link_preview_image(reader, ma->preview); + BLO_read_data_address(reader, &ma->preview); + BKE_previewimg_blend_read(reader, ma->preview); + BLI_listbase_clear(&ma->gpumaterial); BLO_read_data_address(reader, &ma->gp_style); @@ -4989,7 +4575,8 @@ static void direct_link_object(BlendDataReader *reader, Object *ob) } } - ob->preview = direct_link_preview_image(reader, ob->preview); + BLO_read_data_address(reader, &ob->preview); + BKE_previewimg_blend_read(reader, ob->preview); } static void direct_link_view_settings(BlendDataReader *reader, @@ -5131,7 +4718,8 @@ static void direct_link_collection(BlendDataReader *reader, Collection *collecti BLO_read_list(reader, &collection->gobject); BLO_read_list(reader, &collection->children); - collection->preview = direct_link_preview_image(reader, collection->preview); + BLO_read_data_address(reader, &collection->preview); + BKE_previewimg_blend_read(reader, collection->preview); collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; collection->tag = 0; @@ -5315,7 +4903,7 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene) static void lib_link_scene(BlendLibReader *reader, Scene *sce) { - lib_link_keyingsets(reader, &sce->id, &sce->keyingsets); + BKE_keyingsets_blend_read_lib(reader, &sce->id, &sce->keyingsets); BLO_read_id_address(reader, sce->id.lib, &sce->camera); BLO_read_id_address(reader, sce->id.lib, &sce->world); @@ -5594,7 +5182,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) BKE_animdata_blend_read_data(reader, sce->adt); BLO_read_list(reader, &sce->keyingsets); - direct_link_keyingsets(reader, &sce->keyingsets); + BKE_keyingsets_blend_read_data(reader, &sce->keyingsets); BLO_read_data_address(reader, &sce->basact); @@ -5843,7 +5431,8 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) } } - sce->preview = direct_link_preview_image(reader, sce->preview); + BLO_read_data_address(reader, &sce->preview); + BKE_previewimg_blend_read(reader, sce->preview); BKE_curvemapping_blend_read(reader, &sce->r.mblur_shutter_curve); @@ -7147,7 +6736,8 @@ static bool direct_link_screen(BlendDataReader *reader, bScreen *screen) screen->context = NULL; screen->active_region = NULL; - screen->preview = direct_link_preview_image(reader, screen->preview); + BLO_read_data_address(reader, &screen->preview); + BKE_previewimg_blend_read(reader, screen->preview); if (!direct_link_area_map(reader, AREAMAP_FROM_SCREEN(screen))) { printf("Error reading Screen %s... removing it.\n", screen->id.name + 2); @@ -7205,7 +6795,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) // printf("direct_link_library: filepath_abs %s\n", lib->filepath_abs); BlendDataReader reader = {fd}; - lib->packedfile = direct_link_packedfile(&reader, lib->packedfile); + BKE_packedfile_blend_read(&reader, &lib->packedfile); /* new main */ newmain = BKE_main_new(); @@ -7318,8 +6908,8 @@ static void direct_link_sound(BlendDataReader *reader, bSound *sound) /* clear waveform loading flag */ sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING; - sound->packedfile = direct_link_packedfile(reader, sound->packedfile); - sound->newpackedfile = direct_link_packedfile(reader, sound->newpackedfile); + BKE_packedfile_blend_read(reader, &sound->packedfile); + BKE_packedfile_blend_read(reader, &sound->newpackedfile); } static void lib_link_sound(BlendLibReader *reader, bSound *sound) @@ -7331,109 +6921,6 @@ static void lib_link_sound(BlendLibReader *reader, bSound *sound) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Movie Clip - * \{ */ - -static void direct_link_movieReconstruction(BlendDataReader *reader, - MovieTrackingReconstruction *reconstruction) -{ - BLO_read_data_address(reader, &reconstruction->cameras); -} - -static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) -{ - BLO_read_list(reader, tracksbase); - - LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { - BLO_read_data_address(reader, &track->markers); - } -} - -static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) -{ - BLO_read_list(reader, plane_tracks_base); - - LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { - BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); - for (int i = 0; i < plane_track->point_tracksnr; i++) { - BLO_read_data_address(reader, &plane_track->point_tracks[i]); - } - - BLO_read_data_address(reader, &plane_track->markers); - } -} - -static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip) -{ - MovieTracking *tracking = &clip->tracking; - - BLO_read_data_address(reader, &clip->adt); - - direct_link_movieTracks(reader, &tracking->tracks); - direct_link_moviePlaneTracks(reader, &tracking->plane_tracks); - direct_link_movieReconstruction(reader, &tracking->reconstruction); - - BLO_read_data_address(reader, &clip->tracking.act_track); - BLO_read_data_address(reader, &clip->tracking.act_plane_track); - - clip->anim = NULL; - clip->tracking_context = NULL; - clip->tracking.stats = NULL; - - /* TODO we could store those in undo cache storage as well, and preserve them instead of - * re-creating them... */ - BLI_listbase_clear(&clip->runtime.gputextures); - - /* Needed for proper versioning, will be NULL for all newer files anyway. */ - BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track); - - clip->tracking.dopesheet.ok = 0; - BLI_listbase_clear(&clip->tracking.dopesheet.channels); - BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments); - - BLO_read_list(reader, &tracking->objects); - - LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { - direct_link_movieTracks(reader, &object->tracks); - direct_link_moviePlaneTracks(reader, &object->plane_tracks); - direct_link_movieReconstruction(reader, &object->reconstruction); - } -} - -static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) -{ - LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { - BLO_read_id_address(reader, clip->id.lib, &track->gpd); - } -} - -static void lib_link_moviePlaneTracks(BlendLibReader *reader, - MovieClip *clip, - ListBase *tracksbase) -{ - LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { - BLO_read_id_address(reader, clip->id.lib, &plane_track->image); - } -} - -static void lib_link_movieclip(BlendLibReader *reader, MovieClip *clip) -{ - MovieTracking *tracking = &clip->tracking; - - BLO_read_id_address(reader, clip->id.lib, &clip->gpd); - - lib_link_movieTracks(reader, clip, &tracking->tracks); - lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks); - - LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { - lib_link_movieTracks(reader, clip, &object->tracks); - lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks); - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: Masks * \{ */ @@ -7516,243 +7003,6 @@ static void lib_link_mask(BlendLibReader *reader, Mask *mask) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Line Style - * \{ */ - -static void lib_link_linestyle(BlendLibReader *reader, FreestyleLineStyle *linestyle) -{ - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { - switch (m->type) { - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleColorModifier_DistanceFromObject *cm = - (LineStyleColorModifier_DistanceFromObject *)m; - BLO_read_id_address(reader, linestyle->id.lib, &cm->target); - break; - } - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { - switch (m->type) { - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleAlphaModifier_DistanceFromObject *am = - (LineStyleAlphaModifier_DistanceFromObject *)m; - BLO_read_id_address(reader, linestyle->id.lib, &am->target); - break; - } - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { - switch (m->type) { - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleThicknessModifier_DistanceFromObject *tm = - (LineStyleThicknessModifier_DistanceFromObject *)m; - BLO_read_id_address(reader, linestyle->id.lib, &tm->target); - break; - } - } - } - for (int a = 0; a < MAX_MTEX; a++) { - MTex *mtex = linestyle->mtex[a]; - if (mtex) { - BLO_read_id_address(reader, linestyle->id.lib, &mtex->tex); - BLO_read_id_address(reader, linestyle->id.lib, &mtex->object); - } - } -} - -static void direct_link_linestyle_color_modifier(BlendDataReader *reader, - LineStyleModifier *modifier) -{ - switch (modifier->type) { - case LS_MODIFIER_ALONG_STROKE: { - LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_DISTANCE_FROM_CAMERA: { - LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *) - modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *) - modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_MATERIAL: { - LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_TANGENT: { - LineStyleColorModifier_Tangent *m = (LineStyleColorModifier_Tangent *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_NOISE: { - LineStyleColorModifier_Noise *m = (LineStyleColorModifier_Noise *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_CREASE_ANGLE: { - LineStyleColorModifier_CreaseAngle *m = (LineStyleColorModifier_CreaseAngle *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_CURVATURE_3D: { - LineStyleColorModifier_Curvature_3D *m = (LineStyleColorModifier_Curvature_3D *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - } -} - -static void direct_link_linestyle_alpha_modifier(BlendDataReader *reader, - LineStyleModifier *modifier) -{ - switch (modifier->type) { - case LS_MODIFIER_ALONG_STROKE: { - LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_CAMERA: { - LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_MATERIAL: { - LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_TANGENT: { - LineStyleAlphaModifier_Tangent *m = (LineStyleAlphaModifier_Tangent *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_NOISE: { - LineStyleAlphaModifier_Noise *m = (LineStyleAlphaModifier_Noise *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CREASE_ANGLE: { - LineStyleAlphaModifier_CreaseAngle *m = (LineStyleAlphaModifier_CreaseAngle *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CURVATURE_3D: { - LineStyleAlphaModifier_Curvature_3D *m = (LineStyleAlphaModifier_Curvature_3D *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - } -} - -static void direct_link_linestyle_thickness_modifier(BlendDataReader *reader, - LineStyleModifier *modifier) -{ - switch (modifier->type) { - case LS_MODIFIER_ALONG_STROKE: { - LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_CAMERA: { - LineStyleThicknessModifier_DistanceFromCamera *m = - (LineStyleThicknessModifier_DistanceFromCamera *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleThicknessModifier_DistanceFromObject *m = - (LineStyleThicknessModifier_DistanceFromObject *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_MATERIAL: { - LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_TANGENT: { - LineStyleThicknessModifier_Tangent *m = (LineStyleThicknessModifier_Tangent *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CREASE_ANGLE: { - LineStyleThicknessModifier_CreaseAngle *m = (LineStyleThicknessModifier_CreaseAngle *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CURVATURE_3D: { - LineStyleThicknessModifier_Curvature_3D *m = (LineStyleThicknessModifier_Curvature_3D *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - } -} - -static void direct_link_linestyle_geometry_modifier(BlendDataReader *UNUSED(reader), - LineStyleModifier *UNUSED(modifier)) -{ -} - -static void direct_link_linestyle(BlendDataReader *reader, FreestyleLineStyle *linestyle) -{ - BLO_read_data_address(reader, &linestyle->adt); - BKE_animdata_blend_read_data(reader, linestyle->adt); - BLO_read_list(reader, &linestyle->color_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->color_modifiers) { - direct_link_linestyle_color_modifier(reader, modifier); - } - BLO_read_list(reader, &linestyle->alpha_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->alpha_modifiers) { - direct_link_linestyle_alpha_modifier(reader, modifier); - } - BLO_read_list(reader, &linestyle->thickness_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->thickness_modifiers) { - direct_link_linestyle_thickness_modifier(reader, modifier); - } - BLO_read_list(reader, &linestyle->geometry_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->geometry_modifiers) { - direct_link_linestyle_geometry_modifier(reader, modifier); - } - for (int a = 0; a < MAX_MTEX; a++) { - BLO_read_data_address(reader, &linestyle->mtex[a]); - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: Hair * \{ */ @@ -7826,7 +7076,7 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume) BLO_read_data_address(reader, &volume->adt); BKE_animdata_blend_read_data(reader, volume->adt); - volume->packedfile = direct_link_packedfile(reader, volume->packedfile); + BKE_packedfile_blend_read(reader, &volume->packedfile); volume->runtime.frame = 0; /* materials */ @@ -8043,12 +7293,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_LA: direct_link_light(&reader, (Light *)id); break; - case ID_VF: - direct_link_vfont(&reader, (VFont *)id); - break; - case ID_TXT: - direct_link_text(&reader, (Text *)id); - break; case ID_IP: direct_link_ipo(&reader, (Ipo *)id); break; @@ -8079,12 +7323,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_AR: direct_link_armature(&reader, (bArmature *)id); break; - case ID_AC: - direct_link_action(&reader, (bAction *)id); - break; - case ID_NT: - direct_link_nodetree(&reader, (bNodeTree *)id); - break; case ID_BR: direct_link_brush(&reader, (Brush *)id); break; @@ -8094,15 +7332,9 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_GD: direct_link_gpencil(&reader, (bGPdata *)id); break; - case ID_MC: - direct_link_movieclip(&reader, (MovieClip *)id); - break; case ID_MSK: direct_link_mask(&reader, (Mask *)id); break; - case ID_LS: - direct_link_linestyle(&reader, (FreestyleLineStyle *)id); - break; case ID_PAL: direct_link_palette(&reader, (Palette *)id); break; @@ -8129,6 +7361,12 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * break; case ID_ME: case ID_LT: + case ID_AC: + case ID_NT: + case ID_LS: + case ID_TXT: + case ID_VF: + case ID_MC: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8747,9 +7985,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_SCE: lib_link_scene(&reader, (Scene *)id); break; - case ID_LS: - lib_link_linestyle(&reader, (FreestyleLineStyle *)id); - break; case ID_OB: lib_link_object(&reader, (Object *)id); break; @@ -8758,9 +7993,6 @@ static void lib_link_all(FileData *fd, Main *bmain) * 3D viewport may contains pointers to other ID data (like bgpic)! See T41411. */ lib_link_screen(&reader, (bScreen *)id); break; - case ID_MC: - lib_link_movieclip(&reader, (MovieClip *)id); - break; case ID_WO: lib_link_world(&reader, (World *)id); break; @@ -8785,9 +8017,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_SO: lib_link_sound(&reader, (bSound *)id); break; - case ID_TXT: - lib_link_text(&reader, (Text *)id); - break; case ID_CA: lib_link_camera(&reader, (Camera *)id); break; @@ -8806,9 +8035,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_AR: lib_link_armature(&reader, (bArmature *)id); break; - case ID_VF: - lib_link_vfont(&reader, (VFont *)id); - break; case ID_HA: lib_link_hair(&reader, (Hair *)id); break; @@ -8827,10 +8053,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_IM: lib_link_image(&reader, (Image *)id); break; - case ID_NT: - /* Has to be done after node users (scene/materials/...), this will verify group nodes. */ - lib_link_nodetree(&reader, (bNodeTree *)id); - break; case ID_GD: lib_link_gpencil(&reader, (bGPdata *)id); break; @@ -8840,9 +8062,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_KE: lib_link_key(&reader, (Key *)id); break; - case ID_AC: - lib_link_action(&reader, (bAction *)id); - break; case ID_SIM: lib_link_simulation(&reader, (Simulation *)id); break; @@ -8855,6 +8074,12 @@ static void lib_link_all(FileData *fd, Main *bmain) break; case ID_ME: case ID_LT: + case ID_AC: + case ID_NT: + case ID_LS: + case ID_TXT: + case ID_VF: + case ID_MC: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -9438,7 +8663,6 @@ static void expand_constraint_channels(BlendExpander *expander, ListBase *chanba } static void expand_id(BlendExpander *expander, ID *id); -static void expand_nodetree(BlendExpander *expander, bNodeTree *ntree); static void expand_collection(BlendExpander *expander, Collection *collection); static void expand_id_embedded_id(BlendExpander *expander, ID *id) @@ -9447,7 +8671,7 @@ static void expand_id_embedded_id(BlendExpander *expander, ID *id) bNodeTree *nodetree = ntreeFromID(id); if (nodetree != NULL) { expand_id(expander, &nodetree->id); - expand_nodetree(expander, nodetree); + ntreeBlendReadExpand(expander, nodetree); } if (GS(id->name) == ID_SCE) { @@ -9476,35 +8700,6 @@ static void expand_id(BlendExpander *expander, ID *id) expand_id_embedded_id(expander, id); } -static void expand_action(BlendExpander *expander, bAction *act) -{ - // XXX deprecated - old animation system -------------- - LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { - BLO_expand(expander, chan->ipo); - expand_constraint_channels(expander, &chan->constraintChannels); - } - // --------------------------------------------------- - - /* F-Curves in Action */ - BKE_fcurve_blend_read_expand(expander, &act->curves); - - LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { - if (marker->camera) { - BLO_expand(expander, marker->camera); - } - } -} - -static void expand_keyingsets(BlendExpander *expander, ListBase *list) -{ - /* expand the ID-pointers in KeyingSets's paths */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - BLO_expand(expander, ksp->id); - } - } -} - static void expand_particlesettings(BlendExpander *expander, ParticleSettings *part) { BLO_expand(expander, part->instance_object); @@ -9575,69 +8770,6 @@ static void expand_key(BlendExpander *expander, Key *key) BLO_expand(expander, key->ipo); // XXX deprecated - old animation system } -static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) -{ - IDP_BlendReadExpand(expander, sock->prop); - - if (sock->default_value != NULL) { - - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_FLOAT: - case SOCK_VECTOR: - case SOCK_RGBA: - case SOCK_BOOLEAN: - case SOCK_INT: - case SOCK_STRING: - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_EMITTERS: - case SOCK_EVENTS: - case SOCK_FORCES: - case SOCK_CONTROL_FLOW: - break; - } - } -} - -static void expand_node_sockets(BlendExpander *expander, ListBase *sockets) -{ - LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { - expand_node_socket(expander, sock); - } -} - -static void expand_nodetree(BlendExpander *expander, bNodeTree *ntree) -{ - if (ntree->gpd) { - BLO_expand(expander, ntree->gpd); - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->id && node->type != CMP_NODE_R_LAYERS) { - BLO_expand(expander, node->id); - } - - IDP_BlendReadExpand(expander, node->prop); - - expand_node_sockets(expander, &node->inputs); - expand_node_sockets(expander, &node->outputs); - } - - expand_node_sockets(expander, &ntree->inputs); - expand_node_sockets(expander, &ntree->outputs); -} - static void expand_texture(BlendExpander *expander, Tex *tex) { BLO_expand(expander, tex->ima); @@ -9862,7 +8994,7 @@ static void expand_scene(BlendExpander *expander, Scene *sce) BLO_expand(expander, sce->camera); BLO_expand(expander, sce->world); - expand_keyingsets(expander, &sce->keyingsets); + BKE_keyingsets_blend_read_expand(expander, &sce->keyingsets); if (sce->set) { BLO_expand(expander, sce->set); @@ -9990,10 +9122,6 @@ static void expand_lightprobe(BlendExpander *UNUSED(expander), LightProbe *UNUSE { } -static void expand_movieclip(BlendExpander *UNUSED(expander), MovieClip *UNUSED(clip)) -{ -} - static void expand_mask_parent(BlendExpander *expander, MaskParent *parent) { if (parent->id) { @@ -10015,32 +9143,6 @@ static void expand_mask(BlendExpander *expander, Mask *mask) } } -static void expand_linestyle(BlendExpander *expander, FreestyleLineStyle *linestyle) -{ - for (int a = 0; a < MAX_MTEX; a++) { - if (linestyle->mtex[a]) { - BLO_expand(expander, linestyle->mtex[a]->tex); - BLO_expand(expander, linestyle->mtex[a]->object); - } - } - - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { - if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { - BLO_expand(expander, ((LineStyleColorModifier_DistanceFromObject *)m)->target); - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { - if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { - BLO_expand(expander, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target); - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { - if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { - BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); - } - } -} - static void expand_gpencil(BlendExpander *expander, bGPdata *gpd) { LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { @@ -10172,15 +9274,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_AR: expand_armature(&expander, (bArmature *)id); break; - case ID_AC: - expand_action(&expander, (bAction *)id); // XXX deprecated - old animation system - break; case ID_GR: expand_collection(&expander, (Collection *)id); break; - case ID_NT: - expand_nodetree(&expander, (bNodeTree *)id); - break; case ID_BR: expand_brush(&expander, (Brush *)id); break; @@ -10190,15 +9286,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_PA: expand_particlesettings(&expander, (ParticleSettings *)id); break; - case ID_MC: - expand_movieclip(&expander, (MovieClip *)id); - break; case ID_MSK: expand_mask(&expander, (Mask *)id); break; - case ID_LS: - expand_linestyle(&expander, (FreestyleLineStyle *)id); - break; case ID_GD: expand_gpencil(&expander, (bGPdata *)id); break; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 7b089ec0f8f..82cf8887396 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -153,6 +153,7 @@ #include "BKE_action.h" #include "BKE_anim_data.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_blender_version.h" #include "BKE_bpath.h" @@ -166,6 +167,7 @@ #include "BKE_fcurve_driver.h" #include "BKE_global.h" // for G #include "BKE_gpencil_modifier.h" +#include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_layer.h" @@ -175,6 +177,7 @@ #include "BKE_modifier.h" #include "BKE_node.h" #include "BKE_object.h" +#include "BKE_packedFile.h" #include "BKE_pointcache.h" #include "BKE_report.h" #include "BKE_sequencer.h" @@ -659,242 +662,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co * These functions are used by blender's .blend system for file saving/loading. * \{ */ -static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig) -{ - /* Note we write previews also for undo steps. It takes up some memory, - * but not doing so would causes all previews to be re-rendered after - * undo which is too expensive. */ - if (prv_orig) { - PreviewImage prv = *prv_orig; - - /* don't write out large previews if not requested */ - if (!(U.flag & USER_SAVE_PREVIEWS)) { - prv.w[1] = 0; - prv.h[1] = 0; - prv.rect[1] = NULL; - } - BLO_write_struct_at_address(writer, PreviewImage, prv_orig, &prv); - if (prv.rect[0]) { - BLO_write_uint32_array(writer, prv.w[0] * prv.h[0], prv.rect[0]); - } - if (prv.rect[1]) { - BLO_write_uint32_array(writer, prv.w[1] * prv.h[1], prv.rect[1]); - } - } -} - -static void write_action(BlendWriter *writer, bAction *act, const void *id_address) -{ - if (act->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, bAction, id_address, &act->id); - BKE_id_blend_write(writer, &act->id); - - BKE_fcurve_blend_write(writer, &act->curves); - - LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) { - BLO_write_struct(writer, bActionGroup, grp); - } - - LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { - BLO_write_struct(writer, TimeMarker, marker); - } - } -} - -static void write_keyingsets(BlendWriter *writer, ListBase *list) -{ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - /* KeyingSet */ - BLO_write_struct(writer, KeyingSet, ks); - - /* Paths */ - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - /* Path */ - BLO_write_struct(writer, KS_Path, ksp); - - if (ksp->rna_path) { - BLO_write_string(writer, ksp->rna_path); - } - } - } -} - -static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) -{ - if (sock->default_value == NULL) { - return; - } - - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_FLOAT: - BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value); - break; - case SOCK_VECTOR: - BLO_write_struct(writer, bNodeSocketValueVector, sock->default_value); - break; - case SOCK_RGBA: - BLO_write_struct(writer, bNodeSocketValueRGBA, sock->default_value); - break; - case SOCK_BOOLEAN: - BLO_write_struct(writer, bNodeSocketValueBoolean, sock->default_value); - break; - case SOCK_INT: - BLO_write_struct(writer, bNodeSocketValueInt, sock->default_value); - break; - case SOCK_STRING: - BLO_write_struct(writer, bNodeSocketValueString, sock->default_value); - break; - case SOCK_OBJECT: - BLO_write_struct(writer, bNodeSocketValueObject, sock->default_value); - break; - case SOCK_IMAGE: - BLO_write_struct(writer, bNodeSocketValueImage, sock->default_value); - break; - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_EMITTERS: - case SOCK_EVENTS: - case SOCK_FORCES: - case SOCK_CONTROL_FLOW: - BLI_assert(false); - break; - } -} - -static void write_node_socket(BlendWriter *writer, bNodeSocket *sock) -{ - /* actual socket writing */ - BLO_write_struct(writer, bNodeSocket, sock); - - if (sock->prop) { - IDP_BlendWrite(writer, sock->prop); - } - - write_node_socket_default_value(writer, sock); -} -static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) -{ - /* actual socket writing */ - BLO_write_struct(writer, bNodeSocket, sock); - - if (sock->prop) { - IDP_BlendWrite(writer, sock->prop); - } - - write_node_socket_default_value(writer, sock); -} -/* this is only direct data, tree itself should have been written */ -static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree) -{ - /* for link_list() speed, we write per list */ - - if (ntree->adt) { - BKE_animdata_blend_write(writer, ntree->adt); - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - BLO_write_struct(writer, bNode, node); - - if (node->prop) { - IDP_BlendWrite(writer, node->prop); - } - - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - write_node_socket(writer, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { - write_node_socket(writer, sock); - } - - LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { - BLO_write_struct(writer, bNodeLink, link); - } - - if (node->storage) { - /* could be handlerized at some point, now only 1 exception still */ - if ((ntree->type == NTREE_SHADER) && - ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) { - BKE_curvemapping_blend_write(writer, node->storage); - } - else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) { - NodeShaderScript *nss = (NodeShaderScript *)node->storage; - if (nss->bytecode) { - BLO_write_string(writer, nss->bytecode); - } - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, - CMP_NODE_TIME, - CMP_NODE_CURVE_VEC, - CMP_NODE_CURVE_RGB, - CMP_NODE_HUECORRECT)) { - BKE_curvemapping_blend_write(writer, node->storage); - } - else if ((ntree->type == NTREE_TEXTURE) && - (node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) { - BKE_curvemapping_blend_write(writer, node->storage); - } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) { - /* pass */ - } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) { - /* Simple forward compatibility for fix for T50736. - * Not ideal (there is no ideal solution here), but should do for now. */ - NodeGlare *ndg = node->storage; - /* Not in undo case. */ - if (!BLO_write_is_undo(writer)) { - switch (ndg->type) { - case 2: /* Grrrr! magic numbers :( */ - ndg->angle = ndg->streaks; - break; - case 0: - ndg->angle = ndg->star_45; - break; - default: - break; - } - } - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) { - NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; - if (nc->matte_id) { - BLO_write_string(writer, nc->matte_id); - } - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - else if (node->typeinfo != &NodeTypeUndefined) { - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - } - - if (node->type == CMP_NODE_OUTPUT_FILE) { - /* inputs have own storage data */ - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage); - } - } - if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) { - /* write extra socket info */ - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { - BLO_write_struct(writer, NodeImageLayer, sock->storage); - } - } - } - - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - BLO_write_struct(writer, bNodeLink, link); - } - - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { - write_node_socket_interface(writer, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { - write_node_socket_interface(writer, sock); - } -} - /** * Take care using 'use_active_win', since we wont want the currently active window * to change which scene renders (currently only used for undo). @@ -1622,27 +1389,7 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address BLO_write_struct_list(writer, LinkData, &ob->pc_ids); - write_previews(writer, ob->preview); - } -} - -static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address) -{ - if (vf->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - vf->data = NULL; - vf->temp_pf = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, VFont, id_address, &vf->id); - BKE_id_blend_write(writer, &vf->id); - - /* direct data */ - if (vf->packedfile) { - PackedFile *pf = vf->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } + BKE_previewimg_blend_write(writer, ob->preview); } } @@ -1776,14 +1523,10 @@ static void write_image(BlendWriter *writer, Image *ima, const void *id_address) for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { BLO_write_struct(writer, ImagePackedFile, imapf); - if (imapf->packedfile) { - PackedFile *pf = imapf->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } + BKE_packedfile_blend_write(writer, imapf->packedfile); } - write_previews(writer, ima->preview); + BKE_previewimg_blend_write(writer, ima->preview); LISTBASE_FOREACH (ImageView *, iv, &ima->views) { BLO_write_struct(writer, ImageView, iv); @@ -1817,10 +1560,10 @@ static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address) /* nodetree is integral part of texture, no libdata */ if (tex->nodetree) { BLO_write_struct(writer, bNodeTree, tex->nodetree); - write_nodetree_nolib(writer, tex->nodetree); + ntreeBlendWrite(writer, tex->nodetree); } - write_previews(writer, tex->preview); + BKE_previewimg_blend_write(writer, tex->preview); } } @@ -1842,10 +1585,10 @@ static void write_material(BlendWriter *writer, Material *ma, const void *id_add /* nodetree is integral part of material, no libdata */ if (ma->nodetree) { BLO_write_struct(writer, bNodeTree, ma->nodetree); - write_nodetree_nolib(writer, ma->nodetree); + ntreeBlendWrite(writer, ma->nodetree); } - write_previews(writer, ma->preview); + BKE_previewimg_blend_write(writer, ma->preview); /* grease pencil settings */ if (ma->gp_style) { @@ -1871,10 +1614,10 @@ static void write_world(BlendWriter *writer, World *wrld, const void *id_address /* nodetree is integral part of world, no libdata */ if (wrld->nodetree) { BLO_write_struct(writer, bNodeTree, wrld->nodetree); - write_nodetree_nolib(writer, wrld->nodetree); + ntreeBlendWrite(writer, wrld->nodetree); } - write_previews(writer, wrld->preview); + BKE_previewimg_blend_write(writer, wrld->preview); } } @@ -1896,17 +1639,17 @@ static void write_light(BlendWriter *writer, Light *la, const void *id_address) /* Node-tree is integral part of lights, no libdata. */ if (la->nodetree) { BLO_write_struct(writer, bNodeTree, la->nodetree); - write_nodetree_nolib(writer, la->nodetree); + ntreeBlendWrite(writer, la->nodetree); } - write_previews(writer, la->preview); + BKE_previewimg_blend_write(writer, la->preview); } } static void write_collection_nolib(BlendWriter *writer, Collection *collection) { /* Shared function for collection data-blocks and scene master collection. */ - write_previews(writer, collection->preview); + BKE_previewimg_blend_write(writer, collection->preview); LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { BLO_write_struct(writer, CollectionObject, cob); @@ -2059,7 +1802,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) if (sce->adt) { BKE_animdata_blend_write(writer, sce->adt); } - write_keyingsets(writer, &sce->keyingsets); + BKE_keyingsets_blend_write(writer, &sce->keyingsets); /* direct data */ ToolSettings *tos = sce->toolsettings; @@ -2234,7 +1977,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) if (sce->nodetree) { BLO_write_struct(writer, bNodeTree, sce->nodetree); - write_nodetree_nolib(writer, sce->nodetree); + ntreeBlendWrite(writer, sce->nodetree); } write_view_settings(writer, &sce->view_settings); @@ -2251,7 +1994,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) write_pointcaches(writer, &(sce->rigidbody_world->shared->ptcaches)); } - write_previews(writer, sce->preview); + BKE_previewimg_blend_write(writer, sce->preview); BKE_curvemapping_curves_blend_write(writer, &sce->r.mblur_shutter_curve); LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) { @@ -2599,7 +2342,7 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen); BKE_id_blend_write(writer, &screen->id); - write_previews(writer, screen->preview); + BKE_previewimg_blend_write(writer, screen->preview); /* direct data */ write_area_map(writer, AREAMAP_FROM_SCREEN(screen)); @@ -2650,36 +2393,6 @@ static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_a } } -static void write_text(BlendWriter *writer, Text *text, const void *id_address) -{ - /* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */ - if ((text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { - text->flags &= ~TXT_ISEXT; - } - - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - text->compiled = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, Text, id_address, &text->id); - BKE_id_blend_write(writer, &text->id); - - if (text->filepath) { - BLO_write_string(writer, text->filepath); - } - - if (!(text->flags & TXT_ISEXT)) { - /* now write the text data, in two steps for optimization in the readfunction */ - LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { - BLO_write_struct(writer, TextLine, tmp); - } - - LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { - BLO_write_raw(writer, tmp->len + 1, tmp->line); - } - } -} - static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_address) { if (spk->id.us > 0 || BLO_write_is_undo(writer)) { @@ -2706,11 +2419,7 @@ static void write_sound(BlendWriter *writer, bSound *sound, const void *id_addre BLO_write_id_struct(writer, bSound, id_address, &sound->id); BKE_id_blend_write(writer, &sound->id); - if (sound->packedfile) { - PackedFile *pf = sound->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } + BKE_packedfile_blend_write(writer, sound->packedfile); } } @@ -2727,26 +2436,6 @@ static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_add } } -static void write_nodetree(BlendWriter *writer, bNodeTree *ntree, const void *id_address) -{ - if (ntree->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - ntree->init = 0; /* to set callbacks and force setting types */ - ntree->is_updating = false; - ntree->typeinfo = NULL; - ntree->interface_type = NULL; - ntree->progress = NULL; - ntree->execdata = NULL; - - BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id); - /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot - * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ - BKE_id_blend_write(writer, &ntree->id); - - write_nodetree_nolib(writer, ntree); - } -} - static void write_brush(BlendWriter *writer, Brush *brush, const void *id_address) { if (brush->id.us > 0 || BLO_write_is_undo(writer)) { @@ -2817,79 +2506,6 @@ static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id } } -static void write_movieTracks(BlendWriter *writer, ListBase *tracks) -{ - MovieTrackingTrack *track; - - track = tracks->first; - while (track) { - BLO_write_struct(writer, MovieTrackingTrack, track); - - if (track->markers) { - BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers); - } - - track = track->next; - } -} - -static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) -{ - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { - BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); - - BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); - BLO_write_struct_array( - writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); - } -} - -static void write_movieReconstruction(BlendWriter *writer, - MovieTrackingReconstruction *reconstruction) -{ - if (reconstruction->camnr) { - BLO_write_struct_array( - writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); - } -} - -static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id_address) -{ - if (clip->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - clip->anim = NULL; - clip->tracking_context = NULL; - clip->tracking.stats = NULL; - - MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *object; - - BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); - BKE_id_blend_write(writer, &clip->id); - - if (clip->adt) { - BKE_animdata_blend_write(writer, clip->adt); - } - - write_movieTracks(writer, &tracking->tracks); - write_moviePlaneTracks(writer, &tracking->plane_tracks); - write_movieReconstruction(writer, &tracking->reconstruction); - - object = tracking->objects.first; - while (object) { - BLO_write_struct(writer, MovieTrackingObject, object); - - write_movieTracks(writer, &object->tracks); - write_moviePlaneTracks(writer, &object->plane_tracks); - write_movieReconstruction(writer, &object->reconstruction); - - object = object->next; - } - } -} - static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) { if (mask->id.us > 0 || BLO_write_is_undo(writer)) { @@ -2938,296 +2554,6 @@ static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) } } -static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); - break; - case LS_MODIFIER_MATERIAL: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); - break; - case LS_MODIFIER_TANGENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); - break; - case LS_MODIFIER_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); - break; - case LS_MODIFIER_CURVATURE_3D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } - for (m = modifiers->first; m; m = m->next) { - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - BLO_write_struct( - writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - BLO_write_struct( - writer, ColorBand, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); - break; - case LS_MODIFIER_MATERIAL: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Material *)m)->color_ramp); - break; - case LS_MODIFIER_TANGENT: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Tangent *)m)->color_ramp); - break; - case LS_MODIFIER_NOISE: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Noise *)m)->color_ramp); - break; - case LS_MODIFIER_CREASE_ANGLE: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); - break; - case LS_MODIFIER_CURVATURE_3D: - BLO_write_struct( - writer, ColorBand, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); - break; - } - } -} - -static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); - break; - case LS_MODIFIER_MATERIAL: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); - break; - case LS_MODIFIER_TANGENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); - break; - case LS_MODIFIER_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); - break; - case LS_MODIFIER_CURVATURE_3D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } - for (m = modifiers->first; m; m = m->next) { - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - BKE_curvemapping_blend_write(writer, - ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - BKE_curvemapping_blend_write(writer, - ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_NOISE: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Noise *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); - break; - } - } -} - -static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); - break; - case LS_MODIFIER_MATERIAL: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); - break; - case LS_MODIFIER_CALLIGRAPHY: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); - break; - case LS_MODIFIER_TANGENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); - break; - case LS_MODIFIER_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); - break; - case LS_MODIFIER_CURVATURE_3D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } - for (m = modifiers->first; m; m = m->next) { - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - BKE_curvemapping_blend_write(writer, - ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - BKE_curvemapping_blend_write(writer, - ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - BKE_curvemapping_blend_write(writer, - ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); - break; - } - } -} - -static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_SAMPLING: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); - break; - case LS_MODIFIER_BEZIER_CURVE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); - break; - case LS_MODIFIER_SINUS_DISPLACEMENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); - break; - case LS_MODIFIER_SPATIAL_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); - break; - case LS_MODIFIER_PERLIN_NOISE_1D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); - break; - case LS_MODIFIER_PERLIN_NOISE_2D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); - break; - case LS_MODIFIER_BACKBONE_STRETCHER: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); - break; - case LS_MODIFIER_TIP_REMOVER: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); - break; - case LS_MODIFIER_POLYGONIZATION: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); - break; - case LS_MODIFIER_GUIDING_LINES: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); - break; - case LS_MODIFIER_BLUEPRINT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); - break; - case LS_MODIFIER_2D_OFFSET: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); - break; - case LS_MODIFIER_2D_TRANSFORM: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); - break; - case LS_MODIFIER_SIMPLIFICATION: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } -} - -static void write_linestyle(BlendWriter *writer, - FreestyleLineStyle *linestyle, - const void *id_address) -{ - if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); - BKE_id_blend_write(writer, &linestyle->id); - - if (linestyle->adt) { - BKE_animdata_blend_write(writer, linestyle->adt); - } - - write_linestyle_color_modifiers(writer, &linestyle->color_modifiers); - write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers); - write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers); - write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers); - for (int a = 0; a < MAX_MTEX; a++) { - if (linestyle->mtex[a]) { - BLO_write_struct(writer, MTex, linestyle->mtex[a]); - } - } - if (linestyle->nodetree) { - BLO_write_struct(writer, bNodeTree, linestyle->nodetree); - write_nodetree_nolib(writer, linestyle->nodetree); - } - } -} - static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const void *id_address) { if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) { @@ -3334,11 +2660,7 @@ static void write_volume(BlendWriter *writer, Volume *volume, const void *id_add BKE_animdata_blend_write(writer, volume->adt); } - if (volume->packedfile) { - PackedFile *pf = volume->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } + BKE_packedfile_blend_write(writer, volume->packedfile); } } @@ -3355,7 +2677,7 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const /* nodetree is integral part of simulation, no libdata */ if (simulation->nodetree) { BLO_write_struct(writer, bNodeTree, simulation->nodetree); - write_nodetree_nolib(writer, simulation->nodetree); + ntreeBlendWrite(writer, simulation->nodetree); } LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { @@ -3440,9 +2762,7 @@ static void write_libraries(WriteData *wd, Main *main) BKE_id_blend_write(&writer, &main->curlib->id); if (main->curlib->packedfile) { - PackedFile *pf = main->curlib->packedfile; - writestruct(wd, DATA, PackedFile, 1, pf); - writedata(wd, DATA, pf->size, pf->data); + BKE_packedfile_blend_write(&writer, main->curlib->packedfile); if (wd->use_memfile == false) { printf("write packed .blend: %s\n", main->curlib->filepath); } @@ -3663,9 +2983,6 @@ static bool write_file_handle(Main *mainvar, case ID_SCR: write_screen(&writer, (bScreen *)id_buffer, id); break; - case ID_MC: - write_movieclip(&writer, (MovieClip *)id_buffer, id); - break; case ID_MSK: write_mask(&writer, (Mask *)id_buffer, id); break; @@ -3687,18 +3004,12 @@ static bool write_file_handle(Main *mainvar, case ID_LA: write_light(&writer, (Light *)id_buffer, id); break; - case ID_VF: - write_vfont(&writer, (VFont *)id_buffer, id); - break; case ID_KE: write_key(&writer, (Key *)id_buffer, id); break; case ID_WO: write_world(&writer, (World *)id_buffer, id); break; - case ID_TXT: - write_text(&writer, (Text *)id_buffer, id); - break; case ID_SPK: write_speaker(&writer, (Speaker *)id_buffer, id); break; @@ -3714,9 +3025,6 @@ static bool write_file_handle(Main *mainvar, case ID_AR: write_armature(&writer, (bArmature *)id_buffer, id); break; - case ID_AC: - write_action(&writer, (bAction *)id_buffer, id); - break; case ID_OB: write_object(&writer, (Object *)id_buffer, id); break; @@ -3729,9 +3037,6 @@ static bool write_file_handle(Main *mainvar, case ID_PA: write_particlesettings(&writer, (ParticleSettings *)id_buffer, id); break; - case ID_NT: - write_nodetree(&writer, (bNodeTree *)id_buffer, id); - break; case ID_BR: write_brush(&writer, (Brush *)id_buffer, id); break; @@ -3744,9 +3049,6 @@ static bool write_file_handle(Main *mainvar, case ID_GD: write_gpencil(&writer, (bGPdata *)id_buffer, id); break; - case ID_LS: - write_linestyle(&writer, (FreestyleLineStyle *)id_buffer, id); - break; case ID_CF: write_cachefile(&writer, (CacheFile *)id_buffer, id); break; @@ -3764,6 +3066,12 @@ static bool write_file_handle(Main *mainvar, break; case ID_ME: case ID_LT: + case ID_AC: + case ID_NT: + case ID_LS: + case ID_TXT: + case ID_VF: + case ID_MC: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: diff --git a/source/blender/bmesh/operators/bmo_bisect_plane.c b/source/blender/bmesh/operators/bmo_bisect_plane.c index ef59ebf1f2f..337437fb607 100644 --- a/source/blender/bmesh/operators/bmo_bisect_plane.c +++ b/source/blender/bmesh/operators/bmo_bisect_plane.c @@ -65,9 +65,9 @@ void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op) BM_mesh_bisect_plane(bm, plane, use_snap_center, true, ELE_CUT, ELE_NEW, dist); if (clear_outer || clear_inner) { - /* Use an array of vertices because 'geom' contains both vers and edges that may use them. - * Removing a vert may remove and edge which is later checked by BMO_ITER. - * over-alloc the total possible vert count */ + /* Use an array of vertices because 'geom' contains both verts and edges that may use them. + * Removing a vert may remove and edge which is later checked by #BMO_ITER. + * over-allocate the total possible vert count. */ const int vert_arr_max = min_ii(bm->totvert, BMO_slot_buffer_count(op->slots_in, "geom")); BMVert **vert_arr = MEM_mallocN(sizeof(*vert_arr) * (size_t)vert_arr_max, __func__); BMOIter siter; diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.h b/source/blender/compositor/operations/COM_BokehImageOperation.h index db1d3976d44..7e3c026ace8 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.h +++ b/source/blender/compositor/operations/COM_BokehImageOperation.h @@ -29,7 +29,7 @@ * - angle offset of the flaps * - rounding of the flaps (also used to make a circular lens) * - simulate catadioptric - * - simulate lensshift + * - simulate lens-shift * * Per pixel the algorithm determines the edge of the bokeh on the same line as the center of the *image and the pixel is evaluating. diff --git a/source/blender/depsgraph/intern/depsgraph_physics.cc b/source/blender/depsgraph/intern/depsgraph_physics.cc index f51e707284b..bc73700e1ba 100644 --- a/source/blender/depsgraph/intern/depsgraph_physics.cc +++ b/source/blender/depsgraph/intern/depsgraph_physics.cc @@ -80,7 +80,7 @@ ListBase *DEG_get_effector_relations(const Depsgraph *graph, Collection *collect if (hash == nullptr) { return nullptr; } - /* Note: nullptr is a valid loolup key here as it means that the relation is not bound to a + /* Note: nullptr is a valid lookup key here as it means that the relation is not bound to a * specific collection. */ ID *collection_orig = DEG_get_original_id(object_id_safe(collection)); return hash->lookup_default(collection_orig, nullptr); diff --git a/source/blender/draw/engines/basic/basic_engine.c b/source/blender/draw/engines/basic/basic_engine.c index 94c380b3b50..89b659cfa8a 100644 --- a/source/blender/draw/engines/basic/basic_engine.c +++ b/source/blender/draw/engines/basic/basic_engine.c @@ -46,7 +46,7 @@ extern char datatoc_common_view_lib_glsl[]; /* *********** LISTS *********** */ /* GPUViewport.storage - * Is freed everytime the viewport engine changes */ + * Is freed every time the viewport engine changes. */ typedef struct BASIC_StorageList { struct BASIC_PrivateData *g_data; } BASIC_StorageList; diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c index f23cca41215..4904f34a00b 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.c +++ b/source/blender/draw/engines/eevee/eevee_lightcache.c @@ -388,8 +388,8 @@ LightCache *EEVEE_lightcache_create(const int grid_len, static bool eevee_lightcache_static_load(LightCache *lcache) { /* We use fallback if a texture is not setup and there is no data to restore it. */ - if ((!lcache->grid_tx.tex && !lcache->grid_tx.data) || - (!lcache->cube_tx.tex && !lcache->cube_tx.data)) { + if ((!lcache->grid_tx.tex && !lcache->grid_tx.data) || !lcache->grid_data || + (!lcache->cube_tx.tex && !lcache->cube_tx.data) || !lcache->cube_data) { return false; } /* If cache is too big for this GPU. */ diff --git a/source/blender/draw/engines/eevee/shaders/closure_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_lib.glsl index e572245ace9..b56a186ab3f 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_lib.glsl @@ -36,7 +36,7 @@ struct Closure { Closure nodetree_exec(void); /* clang-format off */ -/* Avoid multiline defines. */ +/* Avoid multi-line defines. */ #ifdef VOLUMETRICS # define CLOSURE_DEFAULT Closure(vec3(0), vec3(0), vec3(0), 0.0) #elif !defined(USE_SSS) diff --git a/source/blender/draw/engines/external/external_engine.c b/source/blender/draw/engines/external/external_engine.c index 36d295d1dde..f7303f8cc6f 100644 --- a/source/blender/draw/engines/external/external_engine.c +++ b/source/blender/draw/engines/external/external_engine.c @@ -52,7 +52,7 @@ extern char datatoc_common_view_lib_glsl[]; /* *********** LISTS *********** */ /* GPUViewport.storage - * Is freed everytime the viewport engine changes */ + * Is freed every time the viewport engine changes. */ typedef struct EXTERNAL_Storage { int dummy; } EXTERNAL_Storage; diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index 3b15cd794d8..4d5ff33d5cf 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -355,9 +355,8 @@ int ANIM_add_driver_with_target(ReportList *reports, int src_len = (RNA_property_array_check(prop)) ? RNA_property_array_length(&ptr2, prop2) : 1; int len = MIN2(dst_len, src_len); - int i; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { done_tot += add_driver_with_target(reports, dst_id, dst_path, @@ -378,9 +377,8 @@ int ANIM_add_driver_with_target(ReportList *reports, case CREATEDRIVER_MAPPING_1_N: /* 1-N - Specified target index for all */ default: { int len = (RNA_property_array_check(prop)) ? RNA_property_array_length(&ptr, prop) : 1; - int i; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { done_tot += add_driver_with_target(reports, dst_id, dst_path, diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 9d54be61171..a8fb0be4fbf 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -177,7 +177,6 @@ static void draw_modifier__generator(uiLayout *layout, const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; float *cp = NULL; char xval[32]; - uint i; int maxXWidth; /* draw polynomial order selector */ @@ -221,7 +220,7 @@ static void draw_modifier__generator(uiLayout *layout, UI_block_func_set(block, deg_update, fcurve_owner_id, NULL); cp = data->coefficients; - for (i = 0; (i < data->arraysize) && (cp); i++, cp++) { + for (uint i = 0; (i < data->arraysize) && (cp); i++, cp++) { /* To align with first line... */ if (i) { uiDefBut(block, @@ -319,7 +318,6 @@ static void draw_modifier__generator(uiLayout *layout, case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* Factorized polynomial expression */ { float *cp = NULL; - uint i; /* draw polynomial order selector */ row = uiLayoutRow(layout, false); @@ -351,7 +349,7 @@ static void draw_modifier__generator(uiLayout *layout, UI_block_func_set(block, deg_update, fcurve_owner_id, NULL); cp = data->coefficients; - for (i = 0; (i < data->poly_order) && (cp); i++, cp += 2) { + for (uint i = 0; (i < data->poly_order) && (cp); i++, cp += 2) { /* To align with first line */ if (i) { uiDefBut(block, diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index ef86b132a60..de2525ee150 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -943,11 +943,8 @@ KeyframeEditFunc ANIM_editkeyframes_snap(short mode) static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center) { - float diff; - int i; - - for (i = 0; i < 3; i++) { - diff = (center - bezt->vec[i][0]); + for (int i = 0; i < 3; i++) { + float diff = (center - bezt->vec[i][0]); bezt->vec[i][0] = (center + diff); } swap_v3_v3(bezt->vec[0], bezt->vec[2]); @@ -958,11 +955,8 @@ static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center) static void mirror_bezier_yaxis_ex(BezTriple *bezt, const float center) { - float diff; - int i; - - for (i = 0; i < 3; i++) { - diff = (center - bezt->vec[i][1]); + for (int i = 0; i < 3; i++) { + float diff = (center - bezt->vec[i][1]); bezt->vec[i][1] = (center + diff); } } diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 64065d6d633..ea032446fc6 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -108,7 +108,6 @@ void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc) /* Delete selected keyframes in given F-Curve */ bool delete_fcurve_keys(FCurve *fcu) { - int i; bool changed = false; if (fcu->bezt == NULL) { /* ignore baked curves */ @@ -116,7 +115,7 @@ bool delete_fcurve_keys(FCurve *fcu) } /* Delete selected BezTriples */ - for (i = 0; i < fcu->totvert; i++) { + for (int i = 0; i < fcu->totvert; i++) { if (fcu->bezt[i].f2 & SELECT) { memmove(&fcu->bezt[i], &fcu->bezt[i + 1], sizeof(BezTriple) * (fcu->totvert - i - 1)); fcu->totvert--; @@ -148,19 +147,16 @@ void clear_fcurve_keys(FCurve *fcu) /* duplicate selected keyframes for the given F-Curve */ void duplicate_fcurve_keys(FCurve *fcu) { - BezTriple *newbezt; - int i; - /* this can only work when there is an F-Curve, and also when there are some BezTriples */ if (ELEM(NULL, fcu, fcu->bezt)) { return; } - for (i = 0; i < fcu->totvert; i++) { + for (int i = 0; i < fcu->totvert; i++) { /* If a key is selected */ if (fcu->bezt[i].f2 & SELECT) { /* Expand the list */ - newbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple"); + BezTriple *newbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple"); memcpy(newbezt, fcu->bezt, sizeof(BezTriple) * (i + 1)); memcpy(newbezt + i + 1, fcu->bezt + i, sizeof(BezTriple)); @@ -489,16 +485,15 @@ typedef struct tSmooth_Bezt { // TODO: introduce scaling factor for weighting falloff void smooth_fcurve(FCurve *fcu) { - BezTriple *bezt; - int i, x, totSel = 0; + int totSel = 0; if (fcu->bezt == NULL) { return; } /* first loop through - count how many verts are selected */ - bezt = fcu->bezt; - for (i = 0; i < fcu->totvert; i++, bezt++) { + BezTriple *bezt = fcu->bezt; + for (int i = 0; i < fcu->totvert; i++, bezt++) { if (BEZT_ISSEL_ANY(bezt)) { totSel++; } @@ -513,7 +508,7 @@ void smooth_fcurve(FCurve *fcu) /* populate tarray with data of selected points */ bezt = fcu->bezt; - for (i = 0, x = 0; (i < fcu->totvert) && (x < totSel); i++, bezt++) { + for (int i = 0, x = 0; (i < fcu->totvert) && (x < totSel); i++, bezt++) { if (BEZT_ISSEL_ANY(bezt)) { /* tsb simply needs pointer to vec, and index */ tsb->h1 = &bezt->vec[0][1]; @@ -539,7 +534,7 @@ void smooth_fcurve(FCurve *fcu) /* round 1: calculate smoothing deltas and new values */ tsb = tarray; - for (i = 0; i < totSel; i++, tsb++) { + for (int i = 0; i < totSel; i++, tsb++) { /* Don't touch end points (otherwise, curves slowly explode, * as we don't have enough data there). */ if (ELEM(i, 0, (totSel - 1)) == 0) { @@ -564,7 +559,7 @@ void smooth_fcurve(FCurve *fcu) /* round 2: apply new values */ tsb = tarray; - for (i = 0; i < totSel; i++, tsb++) { + for (int i = 0; i < totSel; i++, tsb++) { /* don't touch end points, as their values weren't touched above */ if (ELEM(i, 0, (totSel - 1)) == 0) { /* y2 takes the average of the 2 points */ diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 66d4882cf9d..fb4c0ae0758 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -618,22 +618,19 @@ enum { */ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) { - BezTriple *bezt = NULL, *prev = NULL; - int totCount, i; - float valA = 0.0f, valB = 0.0f; - /* safety checking */ if (fcu == NULL) { return KEYNEEDED_JUSTADD; } - totCount = fcu->totvert; + int totCount = fcu->totvert; if (totCount == 0) { return KEYNEEDED_JUSTADD; } /* loop through checking if any are the same */ - bezt = fcu->bezt; - for (i = 0; i < totCount; i++) { + BezTriple *bezt = fcu->bezt; + BezTriple *prev = NULL; + for (int i = 0; i < totCount; i++) { float prevPosi = 0.0f, prevVal = 0.0f; float beztPosi = 0.0f, beztVal = 0.0f; @@ -712,8 +709,8 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) * keyframe is not equal to last keyframe. */ bezt = (fcu->bezt + (fcu->totvert - 1)); - valA = bezt->vec[1][1]; - + float valA = bezt->vec[1][1]; + float valB; if (prev) { valB = prev->vec[1][1]; } diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index 7fba855ffdb..4c5efb304c9 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -177,11 +177,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode void *firstunSel = NULL, *firstSel = NULL, *data; Base *firstunSel_base = NULL, *firstSel_base = NULL; uint hitresult; - short i; bool takeNext = false; int minsel = 0xffffffff, minunsel = 0xffffffff; - for (i = 0; i < hits; i++) { + for (short i = 0; i < hits; i++) { hitresult = buffer[3 + (i * 4)]; if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */ diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index ea9b0eb92b9..aa742d4b7ba 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -212,10 +212,6 @@ static void envelope_bone_weighting(Object *ob, { /* Create vertex group weights from envelopes */ - Bone *bone; - bDeformGroup *dgroup; - float distance; - int i, iflip, j; bool use_topology = (mesh->editflag & ME_EDIT_MIRROR_TOPO) != 0; bool use_mask = false; @@ -225,30 +221,30 @@ static void envelope_bone_weighting(Object *ob, } /* for each vertex in the mesh */ - for (i = 0; i < mesh->totvert; i++) { + for (int i = 0; i < mesh->totvert; i++) { if (use_mask && !(mesh->mvert[i].flag & SELECT)) { continue; } - iflip = (dgroupflip) ? mesh_get_x_mirror_vert(ob, NULL, i, use_topology) : -1; + int iflip = (dgroupflip) ? mesh_get_x_mirror_vert(ob, NULL, i, use_topology) : -1; /* for each skinnable bone */ - for (j = 0; j < numbones; j++) { + for (int j = 0; j < numbones; j++) { if (!selected[j]) { continue; } - bone = bonelist[j]; - dgroup = dgrouplist[j]; + Bone *bone = bonelist[j]; + bDeformGroup *dgroup = dgrouplist[j]; /* store the distance-factor from the vertex to the bone */ - distance = distfactor_to_bone(verts[i], - root[j], - tip[j], - bone->rad_head * scale, - bone->rad_tail * scale, - bone->dist * scale); + float distance = distfactor_to_bone(verts[i], + root[j], + tip[j], + bone->rad_head * scale, + bone->rad_tail * scale, + bone->dist * scale); /* add the vert to the deform group if (weight != 0.0) */ if (distance != 0.0f) { @@ -300,7 +296,7 @@ static void add_verts_to_dgroups(ReportList *reports, Mat4 bbone_array[MAX_BBONE_SUBDIV], *bbone = NULL; float(*root)[3], (*tip)[3], (*verts)[3]; int *selected; - int numbones, vertsfilled = 0, i, j, segments = 0; + int numbones, vertsfilled = 0, segments = 0; const bool wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT); struct { Object *armob; @@ -346,7 +342,7 @@ static void add_verts_to_dgroups(ReportList *reports, tip = MEM_callocN(sizeof(float[3]) * numbones, "tip"); selected = MEM_callocN(sizeof(int) * numbones, "selected"); - for (j = 0; j < numbones; j++) { + for (int j = 0; j < numbones; j++) { bone = bonelist[j]; dgroup = dgrouplist[j]; @@ -427,7 +423,7 @@ static void add_verts_to_dgroups(ReportList *reports, } /* transform verts to global space */ - for (i = 0; i < mesh->totvert; i++) { + for (int i = 0; i < mesh->totvert; i++) { if (!vertsfilled) { copy_v3_v3(verts[i], mesh->mvert[i].co); } diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 04c1ec97841..1c8c5ba9d94 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -198,27 +198,26 @@ bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebon */ EditBone *ED_armature_ebone_find_shared_parent(EditBone *ebone_child[], const uint ebone_child_tot) { - uint i; - EditBone *ebone_iter; - #define EBONE_TEMP_UINT(ebone) (*((uint *)(&((ebone)->temp)))) /* clear all */ - for (i = 0; i < ebone_child_tot; i++) { - for (ebone_iter = ebone_child[i]; ebone_iter; ebone_iter = ebone_iter->parent) { + for (uint i = 0; i < ebone_child_tot; i++) { + for (EditBone *ebone_iter = ebone_child[i]; ebone_iter; ebone_iter = ebone_iter->parent) { EBONE_TEMP_UINT(ebone_iter) = 0; } } /* accumulate */ - for (i = 0; i < ebone_child_tot; i++) { - for (ebone_iter = ebone_child[i]->parent; ebone_iter; ebone_iter = ebone_iter->parent) { + for (uint i = 0; i < ebone_child_tot; i++) { + for (EditBone *ebone_iter = ebone_child[i]->parent; ebone_iter; + ebone_iter = ebone_iter->parent) { EBONE_TEMP_UINT(ebone_iter) += 1; } } /* only need search the first chain */ - for (ebone_iter = ebone_child[0]->parent; ebone_iter; ebone_iter = ebone_iter->parent) { + for (EditBone *ebone_iter = ebone_child[0]->parent; ebone_iter; + ebone_iter = ebone_iter->parent) { if (EBONE_TEMP_UINT(ebone_iter) == ebone_child_tot) { return ebone_iter; } diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 1534ea3287f..cf64cfc849d 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -1041,7 +1041,6 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, MDefBoundIsect *isect; float(*mp_cagecos)[3] = BLI_array_alloca(mp_cagecos, mp->totloop); - int i; /* create MDefBoundIsect, and extra for 'poly_weights[]' */ isect = BLI_memarena_alloc(mdb->memarena, sizeof(*isect) + (sizeof(float) * mp->totloop)); @@ -1056,7 +1055,7 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, isect->len = max_ff(len_v3v3(co1, isect->co), MESHDEFORM_LEN_THRESHOLD); /* compute mean value coordinates for interpolation */ - for (i = 0; i < mp->totloop; i++) { + for (int i = 0; i < mp->totloop; i++) { copy_v3_v3(mp_cagecos[i], cagecos[mloop[mp->loopstart + i].v]); } @@ -1225,9 +1224,8 @@ static float meshdeform_boundary_phi(const MeshDeformBind *mdb, { const MLoop *mloop = mdb->cagemesh_cache.mloop; const MPoly *mp = &mdb->cagemesh_cache.mpoly[isect->poly_index]; - int i; - for (i = 0; i < mp->totloop; i++) { + for (int i = 0; i < mp->totloop; i++) { if (mloop[mp->loopstart + i].v == cagevert) { return isect->poly_weights[i]; } @@ -1241,16 +1239,18 @@ static float meshdeform_interp_w(MeshDeformBind *mdb, float *UNUSED(vec), int UNUSED(cagevert)) { - float dvec[3], ivec[3], wx, wy, wz, result = 0.0f; - float weight, totweight = 0.0f; - int i, a, x, y, z; + float dvec[3], ivec[3], result = 0.0f; + float totweight = 0.0f; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { ivec[i] = (int)gridvec[i]; dvec[i] = gridvec[i] - ivec[i]; } - for (i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { + int x, y, z; + float wx, wy, wz; + if (i & 1) { x = ivec[0] + 1; wx = dvec[0]; @@ -1282,8 +1282,8 @@ static float meshdeform_interp_w(MeshDeformBind *mdb, CLAMP(y, 0, mdb->size - 1); CLAMP(z, 0, mdb->size - 1); - a = meshdeform_index(mdb, x, y, z, 0); - weight = wx * wy * wz; + int a = meshdeform_index(mdb, x, y, z, 0); + float weight = wx * wy * wz; result += weight * mdb->phi[a]; totweight += weight; } diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 0cd3afc9cf9..85948f3abc3 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -742,7 +742,6 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) int maxLayers = (RNA_boolean_get(op->ptr, "all")) ? 32 : 16; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */ bool layers[32] = {false}; - int i; /* sanity checking */ if (arm == NULL) { @@ -755,7 +754,7 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) */ RNA_id_pointer_create(&arm->id, &ptr); - for (i = 0; i < maxLayers; i++) { + for (int i = 0; i < maxLayers; i++) { layers[i] = 1; } diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c index cb7c68178d9..ffa28bf9e36 100644 --- a/source/blender/editors/armature/pose_group.c +++ b/source/blender/editors/armature/pose_group.c @@ -381,8 +381,6 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op)) bPoseChannel *pchan; tSortActionGroup *agrp_array; bActionGroup *agrp; - int agrp_count; - int i; if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; @@ -392,8 +390,9 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op)) } /* create temporary array with bone groups and indices */ - agrp_count = BLI_listbase_count(&pose->agroups); + int agrp_count = BLI_listbase_count(&pose->agroups); agrp_array = MEM_mallocN(sizeof(tSortActionGroup) * agrp_count, "sort bone groups"); + int i; for (agrp = pose->agroups.first, i = 0; agrp; agrp = agrp->next, i++) { BLI_assert(i < agrp_count); agrp_array[i].agrp = agrp; diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index fb102574a85..2b3df79476a 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1144,7 +1144,7 @@ static int *init_index_map(Object *obedit, int *r_old_totvert) Nurb *nu; CVKeyIndex *keyIndex; int *old_to_new_map; - int old_totvert, i; + int old_totvert; int vertex_index; for (nu = curve->nurb.first, old_totvert = 0; nu != NULL; nu = nu->next) { @@ -1157,7 +1157,7 @@ static int *init_index_map(Object *obedit, int *r_old_totvert) } old_to_new_map = MEM_mallocN(old_totvert * sizeof(int), "curve old to new index map"); - for (i = 0; i < old_totvert; i++) { + for (int i = 0; i < old_totvert; i++) { old_to_new_map[i] = -1; } @@ -2804,19 +2804,15 @@ static void smooth_single_bezt(BezTriple *bezt, const BezTriple *bezt_orig_next, float factor) { - int i; - BLI_assert(IN_RANGE_INCL(factor, 0.0f, 1.0f)); - for (i = 0; i < 3; i++) { - float val_old, val_new, offset; - + for (int i = 0; i < 3; i++) { /* get single dimension pos of the mid handle */ - val_old = bezt->vec[1][i]; + float val_old = bezt->vec[1][i]; /* get the weights of the previous/next mid handles and calc offset */ - val_new = (bezt_orig_prev->vec[1][i] * 0.5f) + (bezt_orig_next->vec[1][i] * 0.5f); - offset = (val_old * (1.0f - factor)) + (val_new * factor) - val_old; + float val_new = (bezt_orig_prev->vec[1][i] * 0.5f) + (bezt_orig_next->vec[1][i] * 0.5f); + float offset = (val_old * (1.0f - factor)) + (val_new * factor) - val_old; /* offset midpoint and 2 handles */ bezt->vec[1][i] += offset; @@ -2833,11 +2829,9 @@ static void smooth_single_bp(BPoint *bp, const BPoint *bp_orig_next, float factor) { - int i; - BLI_assert(IN_RANGE_INCL(factor, 0.0f, 1.0f)); - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { float val_old, val_new, offset; val_old = bp->vec[i]; @@ -3472,7 +3466,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) BezTriple *bezt, *beztnew, *beztn; BPoint *bp, *prevbp, *bpnew, *bpn; float vec[15]; - int a, b, sel, amount, *usel, *vsel, i; + int a, b, sel, amount, *usel, *vsel; float factor; // printf("*** subdivideNurb: entering subdivide\n"); @@ -3525,7 +3519,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) memcpy(prevvec, bezt->vec, sizeof(float[9])); - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = 1.0f / (number_cuts + 1 - i); memcpy(beztn, nextbezt, sizeof(BezTriple)); @@ -3615,7 +3609,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) if ((bp->f1 & SELECT) && (nextbp->f1 & SELECT)) { // printf("*** subdivideNurb: insert 'linear' point\n"); - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); memcpy(bpn, nextbp, sizeof(BPoint)); @@ -3718,7 +3712,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) bp++; if (b < nu->pntsu - 1) { prevbp = bp - 1; - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); *bpn = *bp; interp_v4_v4v4(bpn->vec, prevbp->vec, bp->vec, factor); @@ -3736,7 +3730,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) for (b = 0; b < (number_cuts + 1) * nu->pntsu - number_cuts; b++) { BPoint *tmp = bpn; - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); *tmp = *bp; interp_v4_v4v4(tmp->vec, prevbp->vec, bp->vec, factor); @@ -3778,7 +3772,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) bp++; } if ((a < nu->pntsv - 1) && vsel[a] == nu->pntsu && vsel[a + 1] == nu->pntsu) { - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); prevbp = bp - nu->pntsu; for (b = 0; b < nu->pntsu; b++) { @@ -3834,7 +3828,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) * handle at most 3rd order curves? I miss * some symmetry here... */ - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); prevbp = bp - 1; *bpn = *prevbp; diff --git a/source/blender/editors/curve/editcurve_select.c b/source/blender/editors/curve/editcurve_select.c index b60eb258916..4b502e9e336 100644 --- a/source/blender/editors/curve/editcurve_select.c +++ b/source/blender/editors/curve/editcurve_select.c @@ -1874,10 +1874,6 @@ static void curve_select_shortest_path_curve(Nurb *nu, int vert_src, int vert_ds static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst) { - HeapSimple *heap; - - int i, vert_curr; - int totu = nu->pntsu; int totv = nu->pntsv; int vert_num = totu * totv; @@ -1890,34 +1886,32 @@ static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst /* init connectivity data */ data = MEM_mallocN(sizeof(*data) * vert_num, __func__); - for (i = 0; i < vert_num; i++) { + for (int i = 0; i < vert_num; i++) { data[i].vert = i; data[i].vert_prev = -1; data[i].cost = FLT_MAX; } /* init heap */ - heap = BLI_heapsimple_new(); + HeapSimple *heap = BLI_heapsimple_new(); - vert_curr = data[vert_src].vert; + int vert_curr = data[vert_src].vert; BLI_heapsimple_insert(heap, 0.0f, &data[vert_src].vert); data[vert_src].cost = 0.0f; data[vert_src].vert_prev = vert_src; /* nop */ while (!BLI_heapsimple_is_empty(heap)) { - int axis, sign; - int u, v; - vert_curr = *((int *)BLI_heapsimple_pop_min(heap)); if (vert_curr == vert_dst) { break; } + int u, v; BKE_nurb_index_to_uv(nu, vert_curr, &u, &v); /* loop over 4 adjacent verts */ - for (sign = -1; sign != 3; sign += 2) { - for (axis = 0; axis != 2; axis += 1) { + for (int sign = -1; sign != 3; sign += 2) { + for (int axis = 0; axis != 2; axis += 1) { int uv_other[2] = {u, v}; int vert_other; @@ -1943,7 +1937,7 @@ static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst BLI_heapsimple_free(heap, NULL); if (vert_curr == vert_dst) { - i = 0; + int i = 0; while (vert_curr != vert_src && i++ < vert_num) { if (nu->type == CU_BEZIER) { select_beztriple(&nu->bezt[vert_curr], SELECT, SELECT, HIDDEN); diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index 8237e6cfd62..ab3b1525e9e 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -1119,7 +1119,6 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, bGPDspoint *pt1, *pt2; int pc1[2] = {0}; int pc2[2] = {0}; - int i; int mval_i[2]; round_v2i_v2fl(mval_i, mval); @@ -1152,7 +1151,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, * we don't miss anything, though things will be * slightly slower as a result */ - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps->points[i]; pt->flag &= ~GP_SPOINT_TAG; } @@ -1161,7 +1160,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, * 1) Thin out parts of the stroke under the brush * 2) Tag "too thin" parts for removal (in second pass) */ - for (i = 0; (i + 1) < gps->totpoints; i++) { + for (int i = 0; (i + 1) < gps->totpoints; i++) { /* get points to work with */ pt1 = gps->points + i; pt2 = gps->points + i + 1; diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index 21d755bea52..3b62b44c7cd 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -371,10 +371,9 @@ static void gpencil_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, int *nbr_gaps, float *tot_gaps_time) { - int i; float delta_time = 0.0f; - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { if (gtd->times[i] < 0 && i) { (*nbr_gaps)++; gtd->times[i] = -gtd->times[i] - delta_time; @@ -420,14 +419,11 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, float delta_time = 0.0f, next_delta_time = 0.0f; int nbr_done_gaps = 0; - int i; - float cfra; - /* This is a bit tricky, as: * - We can't add arbitrarily close points on FCurve (in time). * - We *must* have all "caps" points of all strokes in FCurve, as much as possible! */ - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { /* If new stroke... */ if (i > end_stroke_idx) { start_stroke_idx = i; @@ -442,7 +438,7 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, /* Simple proportional stuff... */ cu->ctime = gtd->dists[i] / gtd->tot_dist * cu->pathlen; - cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); + float cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); /* And now, the checks about timing... */ if (i == start_stroke_idx) { @@ -527,7 +523,7 @@ static void gpencil_stroke_path_animation(bContext *C, FCurve *fcu; PointerRNA ptr; PropertyRNA *prop = NULL; - int nbr_gaps = 0, i; + int nbr_gaps = 0; if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) { return; @@ -551,7 +547,7 @@ static void gpencil_stroke_path_animation(bContext *C, if (G.debug & G_DEBUG) { printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } } @@ -628,7 +624,7 @@ static void gpencil_stroke_path_animation(bContext *C, if (G.debug & G_DEBUG) { printf("%s: \ntot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } printf("\n\n"); @@ -1251,12 +1247,10 @@ static void gpencil_stroke_finalize_curve_endpoints(Curve *cu) static void gpencil_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2]) { - Nurb *nu; const float delta = minmax_weights[0]; - float fac; - int i; /* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */ + float fac; if (IS_EQF(delta, minmax_weights[1])) { fac = 1.0f; } @@ -1264,16 +1258,16 @@ static void gpencil_stroke_norm_curve_weights(Curve *cu, const float minmax_weig fac = 1.0f / (minmax_weights[1] - delta); } - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (i = 0; i < nu->pntsu; i++, bezt++) { + for (int i = 0; i < nu->pntsu; i++, bezt++) { bezt->weight = (bezt->weight - delta) * fac; } } else if (nu->bp) { BPoint *bp = nu->bp; - for (i = 0; i < nu->pntsu; i++, bp++) { + for (int i = 0; i < nu->pntsu; i++, bp++) { bp->weight = (bp->weight - delta) * fac; } } diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 37338ec4592..ac8085f0e53 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -4725,7 +4725,6 @@ static int gpencil_cutter_lasso_select(bContext *C, const float scale = ts->gp_sculpt.isect_threshold; bGPDspoint *pt; - int i; GP_SpaceConversion gsc = {NULL}; bool changed = false; @@ -4741,6 +4740,7 @@ static int gpencil_cutter_lasso_select(bContext *C, /* deselect all strokes first */ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { pt->flag &= ~GP_SPOINT_SELECT; } @@ -4753,7 +4753,7 @@ static int gpencil_cutter_lasso_select(bContext *C, GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { int tot_inside = 0; const int oldtot = gps->totpoints; - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { pt = &gps->points[i]; if ((pt->flag & GP_SPOINT_SELECT) || (pt->flag & GP_SPOINT_TAG)) { continue; @@ -4777,7 +4777,7 @@ static int gpencil_cutter_lasso_select(bContext *C, } /* if mark all points inside lasso set to remove all stroke */ if ((tot_inside == oldtot) || ((tot_inside == 1) && (oldtot == 2))) { - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { pt = &gps->points[i]; pt->flag |= GP_SPOINT_SELECT; } diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 4aae0b97e05..ca93e8de844 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -200,7 +200,6 @@ static void gpencil_calc_points_factor(bContext *C, tGPencilPointCache *src_array) { bGPDspoint *pt; - int i; int idx = 0; /* create selected point array an fill it */ @@ -214,6 +213,7 @@ static void gpencil_calc_points_factor(bContext *C, } LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (gps->flag & GP_STROKE_SELECT) { + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { if (clear_stroke) { pt->flag |= GP_SPOINT_TAG; @@ -252,7 +252,7 @@ static void gpencil_calc_points_factor(bContext *C, /* calc center */ float center[2] = {0.0f, 0.0f}; - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { center[0] += points2d[i][0]; center[1] += points2d[i][1]; } @@ -261,7 +261,7 @@ static void gpencil_calc_points_factor(bContext *C, /* calc angle and distance to center for each point */ const float axis[2] = {1.0f, 0.0f}; float v1[3]; - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { float ln = len_v2v2(center, points2d[i]); sub_v2_v2v2(v1, points2d[i], center); float angle = angle_signed_v2v2(axis, v1); @@ -337,10 +337,9 @@ static void gpencil_get_extremes( tGPencilPointCache *src_array, int totpoints, bGPDstroke *gps_filter, float *start, float *end) { tGPencilPointCache *array_pt = NULL; - int i; /* find first point */ - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { array_pt = &src_array[i]; if (gps_filter == array_pt->gps) { copy_v3_v3(start, &array_pt->x); @@ -348,7 +347,7 @@ static void gpencil_get_extremes( } } /* find last point */ - for (i = totpoints - 1; i >= 0; i--) { + for (int i = totpoints - 1; i >= 0; i--) { array_pt = &src_array[i]; if (gps_filter == array_pt->gps) { copy_v3_v3(end, &array_pt->x); diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 09fb65b654e..6748211a1bc 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -941,7 +941,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) const bool is_depth = (bool)(*align_flag & (GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE)); const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) && (rv3d->persp == RV3D_CAMOB) && (!is_depth); - int i, totelem; + int totelem; /* For very low pressure at the end, truncate stroke. */ if (p->paintmode == GP_PAINTMODE_DRAW) { @@ -1079,7 +1079,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* reproject to plane (only in 3d space) */ gpencil_reproject_toplane(p, gps); pt = gps->points; - for (i = 0; i < gps->totpoints; i++, pt++) { + for (int i = 0; i < gps->totpoints; i++, pt++) { /* if parented change position relative to parent object */ gpencil_apply_parent_point(depsgraph, obact, gpl, pt); } @@ -1099,7 +1099,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) int found_depth = 0; depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points"); - + int i; for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) { round_v2i_v2fl(mval_i, &ptc->x); @@ -1169,6 +1169,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) dvert = gps->dvert; /* convert all points (normal behavior) */ + int i; for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc; i++, ptc++, pt++) { /* convert screen-coordinates to appropriate coordinates (and store them) */ @@ -1266,7 +1267,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* add weights */ if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { BKE_gpencil_dvert_ensure(gps); - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { MDeformVert *ve = &gps->dvert[i]; MDeformWeight *dw = BKE_defvert_ensure_index(ve, def_nr); if (dw) { diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 04e440a1960..c03ff05ac73 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -773,7 +773,6 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* get an array of depths, far depths are blended */ float *depth_arr = NULL; if (is_depth) { - int i; int mval_i[2], mval_prev[2] = {0}; bool interp_depth = false; bool found_depth = false; @@ -787,7 +786,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) depth_arr = MEM_mallocN(sizeof(float) * gps->totpoints, "depth_points"); tGPspoint *ptc = &points2D[0]; - for (i = 0; i < gps->totpoints; i++, ptc++) { + for (int i = 0; i < gps->totpoints; i++, ptc++) { round_v2i_v2fl(mval_i, &ptc->x); if ((ED_view3d_autodist_depth(tgpi->region, mval_i, depth_margin, depth_arr + i) == 0) && (i && (ED_view3d_autodist_depth_seg( @@ -801,14 +800,14 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) } if (!found_depth) { - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { depth_arr[i] = 0.9999f; } } else { /* if all depth are too high disable */ bool valid_depth = false; - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { if (depth_arr[i] < 0.9999f) { valid_depth = true; break; @@ -826,6 +825,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) int last_valid = 0; /* find first valid contact point */ + int i; for (i = 0; i < gps->totpoints; i++) { if (depth_arr[i] != FLT_MAX) { break; diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c index 4a5da10cdbf..7b4af648800 100644 --- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c +++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c @@ -546,12 +546,11 @@ static void gpencil_brush_grab_apply_cached(tGP_BrushEditData *gso, return; } - int i; float inverse_diff_mat[4][4]; invert_m4_m4(inverse_diff_mat, diff_mat); /* Apply dvec to all of the stored points */ - for (i = 0; i < data->size; i++) { + for (int i = 0; i < data->size; i++) { bGPDspoint *pt = &gps->points[data->points[i]]; float delta[3] = {0.0f}; @@ -1106,7 +1105,7 @@ static bool gpencil_sculpt_brush_apply_clone(bContext *C, tGP_BrushEditData *gso gpencil_brush_clone_adjust(gso); } else { - /* Continuous - Just keep pasting everytime we move */ + /* Continuous - Just keep pasting every time we move. */ /* TODO: The spacing of repeat should be controlled using a * "stepsize" or similar property? */ gpencil_brush_clone_add(C, gso); diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c index 36ce7d3dc47..69e50beb66e 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_ops.c +++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c @@ -682,7 +682,6 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) char name[32] = ""; Material *ma = NULL; GPMatArray *mat_elm = NULL; - int i; bool changed = false; @@ -744,6 +743,7 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) /* Check if material exist. */ bool found = false; + int i; for (i = 0; i < totmat; i++) { mat_elm = &mat_table[i]; if (mat_elm->ma == NULL) { @@ -796,6 +796,7 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) /* Update all points. */ bGPDspoint *pt; + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { copy_v3_v3(pt->vert_color, gp_style->stroke_rgba); pt->vert_color[3] = 1.0f; diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c index e92adc8a2ec..d626c57b121 100644 --- a/source/blender/editors/interface/interface_align.c +++ b/source/blender/editors/interface/interface_align.c @@ -393,7 +393,6 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) ButAlign *butal_array; ButAlign *butal, *butal_other; int side; - int i, j; /* First loop: we count number of buttons belonging to an align group, * and clear their align flag. @@ -452,9 +451,11 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) /* Third loop: for each pair of buttons in the same align group, * we compute their potential proximity. Note that each pair is checked only once, and that we * break early in case we know all remaining pairs will always be too far away. */ + int i; for (i = 0, butal = butal_array; i < num_buttons; i++, butal++) { const short alignnr = butal->but->alignnr; + int j; for (j = i + 1, butal_other = &butal_array[i + 1]; j < num_buttons; j++, butal_other++) { const float max_delta = MAX_DELTA; diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 4d53018cd32..bcb8a10be02 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -2162,7 +2162,6 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, const uiWidgetColors *wcol, const rcti *rect) { - uint i; float fx, fy; uiButCurveProfile *but_profile = (uiButCurveProfile *)but; @@ -2241,7 +2240,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, /* Create array of the positions of the table's points. */ float(*table_coords)[2] = MEM_mallocN(sizeof(*table_coords) * tot_points, "table x coords"); - for (i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); + for (uint i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); i++) { /* Only add the points from the table here. */ table_coords[i][0] = pts[i].x; table_coords[i][1] = pts[i].y; @@ -2284,7 +2283,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_ALPHA); GPU_polygon_smooth(false); immBegin(GPU_PRIM_TRIS, 3 * tot_triangles); - for (i = 0; i < tot_triangles; i++) { + for (uint i = 0; i < tot_triangles; i++) { for (uint j = 0; j < 3; j++) { uint *tri = tri_indices[i]; fx = rect->xmin + zoomx * (table_coords[tri[j]][0] - offsx); @@ -2301,7 +2300,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, immUniformColor3ubvAlpha((const uchar *)wcol->item, 255); GPU_line_smooth(true); immBegin(GPU_PRIM_LINE_STRIP, tot_points - 1); - for (i = 0; i < tot_points - 1; i++) { + for (uint i = 0; i < tot_points - 1; i++) { fx = rect->xmin + zoomx * (table_coords[i][0] - offsx); fy = rect->ymin + zoomy * (table_coords[i][1] - offsy); immVertex2f(pos, fx, fy); @@ -2313,7 +2312,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, pts = profile->path; tot_points = (uint)profile->path_len; int selected_free_points = 0; - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { selected_free_points++; } @@ -2325,7 +2324,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_line_smooth(true); immBegin(GPU_PRIM_LINES, selected_free_points * 4); float ptx, pty; - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { ptx = rect->xmin + zoomx * (pts[i].x - offsx); pty = rect->ymin + zoomy * (pts[i].y - offsy); @@ -2372,7 +2371,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_NONE); GPU_point_size(max_ff(3.0f, min_ff(UI_DPI_FAC / but->block->aspect * 5.0f, 5.0f))); immBegin(GPU_PRIM_POINTS, tot_points); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { fx = rect->xmin + zoomx * (pts[i].x - offsx); fy = rect->ymin + zoomy * (pts[i].y - offsy); immAttr4fv(col, (pts[i].flag & PROF_SELECT) ? color_vert_select : color_vert); @@ -2386,7 +2385,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_NONE); GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 4.0f, 4.0f))); immBegin(GPU_PRIM_POINTS, selected_free_points * 2); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { fx = rect->xmin + zoomx * (pts[i].h1_loc[0] - offsx); fy = rect->ymin + zoomy * (pts[i].h1_loc[1] - offsy); @@ -2408,7 +2407,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, if (tot_points > 0 && pts) { GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 3.0f, 3.0f))); immBegin(GPU_PRIM_POINTS, tot_points); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { fx = rect->xmin + zoomx * (pts[i].x - offsx); fy = rect->ymin + zoomy * (pts[i].y - offsy); immAttr4fv(col, color_sample); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index cadc2264bf4..b5f902adfb5 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -975,7 +975,7 @@ static void init_iconfile_list(struct ListBase *list) { IconFile *ifile; struct direntry *dir; - int totfile, i, index = 1; + int index = 1; const char *icondir; BLI_listbase_clear(list); @@ -985,9 +985,9 @@ static void init_iconfile_list(struct ListBase *list) return; } - totfile = BLI_filelist_dir_contents(icondir, &dir); + int totfile = BLI_filelist_dir_contents(icondir, &dir); - for (i = 0; i < totfile; i++) { + for (int i = 0; i < totfile; i++) { if ((dir[i].type & S_IFREG)) { const char *filename = dir[i].relname; diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 4b767b530f0..659d985b7bb 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -466,14 +466,14 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index) uiBut *but = arg_but; PointerRNA *ptr = &but->rnapoin; PropertyRNA *prop = but->rnaprop; - int i, index = POINTER_AS_INT(arg_index); + int index = POINTER_AS_INT(arg_index); const int shift = win->eventstate->shift; const int len = RNA_property_array_length(ptr, prop); if (!shift) { RNA_property_boolean_set_index(ptr, prop, index, true); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { if (i != index) { RNA_property_boolean_set_index(ptr, prop, i, 0); } @@ -2644,14 +2644,14 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname } const EnumPropertyItem *item; - int totitem, i; + int totitem; bool free; uiLayout *split = uiLayoutSplit(layout, 0.0f, false); uiLayout *column = uiLayoutColumn(split, false); RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free); - for (i = 0; i < totitem; i++) { + for (int i = 0; i < totitem; i++) { if (item[i].identifier[0]) { uiItemEnumR_prop(column, item[i].name, item[i].icon, ptr, prop, item[i].value); ui_but_tip_from_enum_item(block->buttons.last, &item[i]); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 4e33bc4f8bd..e99dcacec21 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1700,8 +1700,6 @@ static void align_sub_panels(Panel *panel) /* returns 1 when it did something */ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) { - int i; - /* count active, not tabbed panels */ int tot = 0; LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { @@ -1730,6 +1728,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) /* While we are dragging, we sort on location and update #Panel.sortorder. */ qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel); + int i; for (ps = panelsort, i = 0; i < tot; i++, ps++) { ps->orig->sortorder = i; } @@ -1746,7 +1745,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) ps->panel->ofsy = -get_panel_size_y(ps->panel); ps->panel->ofsx += ps->panel->runtime.region_ofsx; - for (i = 0; i < tot - 1; i++, ps++) { + for (int i = 0; i < tot - 1; i++, ps++) { PanelSort *psnext = ps + 1; const bool use_box = ps->panel->type && ps->panel->type->flag & PNL_DRAW_BOX; @@ -1768,7 +1767,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) /* we interpolate */ bool changed = false; ps = panelsort; - for (i = 0; i < tot; i++, ps++) { + for (int i = 0; i < tot; i++, ps++) { if ((ps->panel->flag & PNL_SELECT) == 0) { if ((ps->orig->ofsx != ps->panel->ofsx) || (ps->orig->ofsy != ps->panel->ofsy)) { ps->orig->ofsx = round_fl_to_int(fac * (float)ps->panel->ofsx + @@ -1790,6 +1789,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) } /* Free `panelsort` array. */ + int i; for (ps = panelsort, i = 0; i < tot; i++, ps++) { MEM_freeN(ps->panel); } diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index f472c56e280..0edc755902a 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -167,7 +167,6 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region float background_color[3]; float tone_bg; - int i; wmOrtho2_region_pixelspace(region); @@ -204,7 +203,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.xmin += 0.5f * pad_px; /* add padding to the text */ bbox.ymax -= 0.25f * pad_px; - for (i = 0; i < data->fields_len; i++) { + for (int i = 0; i < data->fields_len; i++) { const uiTooltipField *field = &data->fields[i]; const uiTooltipField *field_next = (i + 1) != data->fields_len ? &data->fields[i + 1] : NULL; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index f47cee1c1a5..9141a46499e 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -4255,7 +4255,7 @@ static void curvemap_buttons_layout(uiLayout *layout, uiBut *bt; const float dx = UI_UNIT_X; int icon, size; - int bg = -1, i; + int bg = -1; block = uiLayoutGetBlock(layout); @@ -4464,7 +4464,7 @@ static void curvemap_buttons_layout(uiLayout *layout, curve_but->gradient_type = bg; /* sliders for selected point */ - for (i = 0; i < cm->totpoint; i++) { + for (int i = 0; i < cm->totpoint; i++) { if (cm->curve[i].flag & CUMA_SELECT) { cmp = &cm->curve[i]; break; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ab0f6d90caa..0cbb8f268a2 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -5002,12 +5002,7 @@ static void draw_disk_shaded(float start, bool shaded) { const float radius_ext_scale = (0.5f / radius_ext); /* 1 / (2 * radius_ext) */ - int i; - float s, c; - float y1, y2; - float fac; - uchar r_col[4]; uint pos, col; GPUVertFormat *format = immVertexFormat(); @@ -5022,24 +5017,24 @@ static void draw_disk_shaded(float start, } immBegin(GPU_PRIM_TRI_STRIP, subd * 2); - for (i = 0; i < subd; i++) { - float a; - - a = start + ((i) / (float)(subd - 1)) * angle; - s = sinf(a); - c = cosf(a); - y1 = s * radius_int; - y2 = s * radius_ext; + for (int i = 0; i < subd; i++) { + float a = start + ((i) / (float)(subd - 1)) * angle; + float s = sinf(a); + float c = cosf(a); + float y1 = s * radius_int; + float y2 = s * radius_ext; if (shaded) { - fac = (y1 + radius_ext) * radius_ext_scale; + uchar r_col[4]; + float fac = (y1 + radius_ext) * radius_ext_scale; color_blend_v4_v4v4(r_col, col1, col2, fac); immAttr4ubv(col, r_col); } immVertex2f(pos, c * radius_int, s * radius_int); if (shaded) { - fac = (y2 + radius_ext) * radius_ext_scale; + uchar r_col[4]; + float fac = (y2 + radius_ext) * radius_ext_scale; color_blend_v4_v4v4(r_col, col1, col2, fac); immAttr4ubv(col, r_col); } diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index c6b29f79137..32caf043119 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1723,13 +1723,10 @@ static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b) const float cent_b[2] = {BLI_rctf_cent_x(rect_b), BLI_rctf_cent_y(rect_b)}; float fac_max = 0.0f; - float tfac; - int i; - - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { /* axis translation normalized to scale */ - tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); + float tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); fac_max = max_ff(fac_max, tfac); if (fac_max >= 1.0f) { break; diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c index 49cf4779496..4497ca1a379 100644 --- a/source/blender/editors/lattice/editlattice_select.c +++ b/source/blender/editors/lattice/editlattice_select.c @@ -177,9 +177,6 @@ void LATTICE_OT_select_random(wmOperatorType *ot) static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool extend) { const int tot = lt->pntsu * lt->pntsv * lt->pntsw; - int i; - BPoint *bp; - BLI_bitmap *selpoints; bool flip_uvw[3] = {false}; flip_uvw[axis] = true; @@ -190,13 +187,13 @@ static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool e } /* store "original" selection */ - selpoints = BLI_BITMAP_NEW(tot, __func__); + BLI_bitmap *selpoints = BLI_BITMAP_NEW(tot, __func__); BKE_lattice_bitmap_from_flag(lt, selpoints, SELECT, false, false); /* actual (de)selection */ - for (i = 0; i < tot; i++) { + for (int i = 0; i < tot; i++) { const int i_flip = BKE_lattice_index_flip(lt, i, flip_uvw[0], flip_uvw[1], flip_uvw[2]); - bp = <->def[i]; + BPoint *bp = <->def[i]; if (!bp->hide) { if (BLI_BITMAP_TEST(selpoints, i_flip)) { bp->f1 |= SELECT; diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index e43eea35a91..770a53d8691 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -76,8 +76,7 @@ static void setup_vertex_point(Mask *mask, */ int point_index = reference_point - spline->points; int delta = new_point == spline->points ? 1 : -1; - int i = 0; - for (i = 0; i < spline->tot_point - 1; i++) { + for (int i = 0; i < spline->tot_point - 1; i++) { MaskSplinePoint *current_point; point_index += delta; @@ -199,9 +198,7 @@ static void finSelectedSplinePoint(MaskLayer *mask_layer, } while (cur_spline) { - int i; - - for (i = 0; i < cur_spline->tot_point; i++) { + for (int i = 0; i < cur_spline->tot_point; i++) { MaskSplinePoint *cur_point = &cur_spline->points[i]; if (MASKPOINT_ISSEL_ANY(cur_point)) { @@ -694,19 +691,17 @@ static int create_primitive_from_points( bContext *C, wmOperator *op, const float (*points)[2], int num_points, char handle_type) { ScrArea *area = CTX_wm_area(C); - Mask *mask; - MaskLayer *mask_layer; - MaskSpline *new_spline; - float scale, location[2], frame_size[2]; - int i, width, height; int size = RNA_float_get(op->ptr, "size"); + int width, height; ED_mask_get_size(area, &width, &height); - scale = (float)size / max_ii(width, height); + float scale = (float)size / max_ii(width, height); /* Get location in mask space. */ + float frame_size[2]; frame_size[0] = width; frame_size[1] = height; + float location[2]; RNA_float_get_array(op->ptr, "location", location); location[0] /= width; location[1] /= height; @@ -717,12 +712,12 @@ static int create_primitive_from_points( location[1] -= 0.5f * scale; bool added_mask = false; - mask_layer = ED_mask_layer_ensure(C, &added_mask); - mask = CTX_data_edit_mask(C); + MaskLayer *mask_layer = ED_mask_layer_ensure(C, &added_mask); + Mask *mask = CTX_data_edit_mask(C); ED_mask_select_toggle_all(mask, SEL_DESELECT); - new_spline = BKE_mask_spline_add(mask_layer); + MaskSpline *new_spline = BKE_mask_spline_add(mask_layer); new_spline->flag = MASK_SPLINE_CYCLIC | SELECT; new_spline->points = MEM_recallocN(new_spline->points, sizeof(MaskSplinePoint) * num_points); @@ -731,7 +726,7 @@ static int create_primitive_from_points( const int spline_index = BKE_mask_layer_shape_spline_to_index(mask_layer, new_spline); - for (i = 0; i < num_points; i++) { + for (int i = 0; i < num_points; i++) { new_spline->tot_point = i + 1; MaskSplinePoint *new_point = &new_spline->points[i]; diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 51f3a94efde..c9fe03dc599 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -262,15 +262,16 @@ static bool spline_under_mouse_get(const bContext *C, const float threshold = 19.0f; ScrArea *area = CTX_wm_area(C); SpaceClip *sc = CTX_wm_space_clip(C); - int width, height; - float pixel_co[2]; float closest_dist_squared = 0.0f; MaskLayer *closest_layer = NULL; MaskSpline *closest_spline = NULL; bool undistort = false; *r_mask_layer = NULL; *r_mask_spline = NULL; + + int width, height; ED_mask_get_size(area, &width, &height); + float pixel_co[2]; pixel_co[0] = co[0] * width; pixel_co[1] = co[1] * height; if (sc != NULL) { @@ -285,16 +286,13 @@ static bool spline_under_mouse_get(const bContext *C, for (MaskSpline *spline = mask_layer->splines.first; spline != NULL; spline = spline->next) { MaskSplinePoint *points_array; float min[2], max[2], center[2]; - float dist_squared; - int i; - float max_bb_side; if ((spline->flag & SELECT) == 0) { continue; } points_array = BKE_mask_spline_point_array(spline); INIT_MINMAX2(min, max); - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point_deform = &points_array[i]; BezTriple *bezt = &point_deform->bezt; @@ -311,8 +309,8 @@ static bool spline_under_mouse_get(const bContext *C, center[0] = (min[0] + max[0]) / 2.0f * width; center[1] = (min[1] + max[1]) / 2.0f * height; - dist_squared = len_squared_v2v2(pixel_co, center); - max_bb_side = min_ff((max[0] - min[0]) * width, (max[1] - min[1]) * height); + float dist_squared = len_squared_v2v2(pixel_co, center); + float max_bb_side = min_ff((max[0] - min[0]) * width, (max[1] - min[1]) * height); if (dist_squared <= max_bb_side * max_bb_side * 0.5f && (closest_spline == NULL || dist_squared < closest_dist_squared)) { closest_layer = mask_layer; @@ -350,9 +348,7 @@ static bool spline_under_mouse_get(const bContext *C, static bool slide_point_check_initial_feather(MaskSpline *spline) { - int i; - - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (point->bezt.weight != 0.0f) { @@ -569,9 +565,7 @@ static int slide_point_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void slide_point_delta_all_feather(SlidePointData *data, float delta) { - int i; - - for (i = 0; i < data->spline->tot_point; i++) { + for (int i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; MaskSplinePoint *orig_point = &data->orig_spline->points[i]; @@ -584,16 +578,13 @@ static void slide_point_delta_all_feather(SlidePointData *data, float delta) static void slide_point_restore_spline(SlidePointData *data) { - int i; - - for (i = 0; i < data->spline->tot_point; i++) { + for (int i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; MaskSplinePoint *orig_point = &data->orig_spline->points[i]; - int j; point->bezt = orig_point->bezt; - for (j = 0; j < point->tot_uw; j++) { + for (int j = 0; j < point->tot_uw; j++) { point->uw[j] = orig_point->uw[j]; } } @@ -818,13 +809,11 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event) } } else if (data->action == SLIDE_ACTION_SPLINE) { - int i; - if (data->orig_spline == NULL) { data->orig_spline = BKE_mask_spline_copy(data->spline); } - for (i = 0; i < data->spline->tot_point; i++) { + for (int i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; add_v2_v2(point->bezt.vec[0], delta); add_v2_v2(point->bezt.vec[1], delta); @@ -1330,13 +1319,13 @@ void MASK_OT_cyclic_toggle(wmOperatorType *ot) static void delete_feather_points(MaskSplinePoint *point) { - int i, count = 0; + int count = 0; if (!point->tot_uw) { return; } - for (i = 0; i < point->tot_uw; i++) { + for (int i = 0; i < point->tot_uw; i++) { if ((point->uw[i].flag & SELECT) == 0) { count++; } @@ -1353,7 +1342,7 @@ static void delete_feather_points(MaskSplinePoint *point) new_uw = MEM_callocN(count * sizeof(MaskSplinePointUW), "new mask uw points"); - for (i = 0; i < point->tot_uw; i++) { + for (int i = 0; i < point->tot_uw; i++) { if ((point->uw[i].flag & SELECT) == 0) { new_uw[j++] = point->uw[i]; } @@ -1383,11 +1372,11 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) while (spline) { const int tot_point_orig = spline->tot_point; - int i, count = 0; + int count = 0; MaskSpline *next_spline = spline->next; /* count unselected points */ - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (!MASKPOINT_ISSEL_ANY(point)) { @@ -1409,11 +1398,10 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) } else { MaskSplinePoint *new_points; - int j; new_points = MEM_callocN(count * sizeof(MaskSplinePoint), "deleteMaskPoints"); - for (i = 0, j = 0; i < tot_point_orig; i++) { + for (int i = 0, j = 0; i < tot_point_orig; i++) { MaskSplinePoint *point = &spline->points[i]; if (!MASKPOINT_ISSEL_ANY(point)) { diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index 82d8a1dc85f..cdc6ece1e84 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -55,9 +55,7 @@ /* 'check' select */ bool ED_mask_spline_select_check(const MaskSpline *spline) { - int i; - - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (MASKPOINT_ISSEL_ANY(point)) { @@ -97,8 +95,6 @@ bool ED_mask_select_check(const Mask *mask) /* 'sel' select */ void ED_mask_spline_select_set(MaskSpline *spline, const bool do_select) { - int i; - if (do_select) { spline->flag |= SELECT; } @@ -106,7 +102,7 @@ void ED_mask_spline_select_set(MaskSpline *spline, const bool do_select) spline->flag &= ~SELECT; } - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; BKE_mask_point_select_set(point, do_select); @@ -151,8 +147,7 @@ void ED_mask_select_toggle_all(Mask *mask, int action) continue; } LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; BKE_mask_point_select_set(point, !MASKPOINT_ISSEL_ANY(point)); } @@ -654,7 +649,6 @@ static int circle_select_exec(bContext *C, wmOperator *op) ARegion *region = CTX_wm_region(C); Mask *mask = CTX_data_edit_mask(C); - int i; float zoomx, zoomy, offset[2], ellipse[2]; int width, height; @@ -692,7 +686,7 @@ static int circle_select_exec(bContext *C, wmOperator *op) LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; MaskSplinePoint *point_deform = &points_array[i]; @@ -871,10 +865,9 @@ static int mask_select_more_less(bContext *C, bool more) LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { const bool cyclic = (spline->flag & MASK_SPLINE_CYCLIC) != 0; bool start_sel, end_sel, prev_sel, cur_sel; - int i; /* reselect point if any handle is selected to make the result more predictable */ - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { BKE_mask_point_select_set(spline->points + i, MASKPOINT_ISSEL_ANY(spline->points + i)); } @@ -892,7 +885,7 @@ static int mask_select_more_less(bContext *C, bool more) end_sel = false; } - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { if (i == 0 && !cyclic) { continue; } @@ -908,7 +901,7 @@ static int mask_select_more_less(bContext *C, bool more) } } - for (i = spline->tot_point - 1; i >= 0; i--) { + for (int i = spline->tot_point - 1; i >= 0; i--) { if (i == spline->tot_point - 1 && !cyclic) { continue; } diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index b303c4c7e4e..b349def4637 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -58,7 +58,6 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) MPoly *polys, *mp_orig; const int *index_array = NULL; int totpoly; - int i; BLI_assert((flag & ~(SELECT | ME_HIDE)) == 0); @@ -87,7 +86,7 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) if (me_orig != NULL && me_eval != NULL && me_orig->totpoly == me->totpoly) { /* Update the COW copy of the mesh. */ - for (i = 0; i < me->totpoly; i++) { + for (int i = 0; i < me->totpoly; i++) { me_orig->mpoly[i].flag = me->mpoly[i].flag; } @@ -101,7 +100,7 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) totpoly = me_eval->totpoly; /* loop over final derived polys */ - for (i = 0; i < totpoly; i++) { + for (int i = 0; i < totpoly; i++) { if (index_array[i] != ORIGINDEX_NONE) { /* Copy flags onto the final derived poly from the original mesh poly */ mp_orig = me->mpoly + index_array[i]; diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 515fbab86bc..90ef42c6f48 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -672,12 +672,10 @@ static int linehit_compare(const void *vlh1, const void *vlh2) */ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) { - KnifeLineHit *linehits, *lhi, *lhj; - int i, j, n; bool is_double = false; - n = kcd->totlinehit; - linehits = kcd->linehits; + int n = kcd->totlinehit; + KnifeLineHit *linehits = kcd->linehits; if (n == 0) { return; } @@ -688,11 +686,11 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) * by a vertex hit that is very near. Mark such edge hits using * l == -1 and then do another pass to actually remove. * Also remove all but one of a series of vertex hits for the same vertex. */ - for (i = 0; i < n; i++) { - lhi = &linehits[i]; + for (int i = 0; i < n; i++) { + KnifeLineHit *lhi = &linehits[i]; if (lhi->v) { - for (j = i - 1; j >= 0; j--) { - lhj = &linehits[j]; + for (int j = i - 1; j >= 0; j--) { + KnifeLineHit *lhj = &linehits[j]; if (!lhj->kfe || fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { break; @@ -703,8 +701,8 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) is_double = true; } } - for (j = i + 1; j < n; j++) { - lhj = &linehits[j]; + for (int j = i + 1; j < n; j++) { + KnifeLineHit *lhj = &linehits[j]; if (fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { break; @@ -719,11 +717,11 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) if (is_double) { /* delete-in-place loop: copying from pos j to pos i+1 */ - i = 0; - j = 1; + int i = 0; + int j = 1; while (j < n) { - lhi = &linehits[i]; - lhj = &linehits[j]; + KnifeLineHit *lhi = &linehits[i]; + KnifeLineHit *lhj = &linehits[j]; if (lhj->l == -1.0f) { j++; /* skip copying this one */ } diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 22ea222cf01..1537be0aef6 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -171,11 +171,10 @@ static void mesh_uv_reset_array(float **fuv, const int len) } else if (len > 2) { float fac = 0.0f, dfac = 1.0f / (float)len; - int i; dfac *= (float)M_PI * 2.0f; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { fuv[i][0] = 0.5f * sinf(fac) + 0.5f; fuv[i][1] = 0.5f * cosf(fac) + 0.5f; @@ -201,9 +200,8 @@ static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset) static void mesh_uv_reset_mface(MPoly *mp, MLoopUV *mloopuv) { float **fuv = BLI_array_alloca(fuv, mp->totloop); - int i; - for (i = 0; i < mp->totloop; i++) { + for (int i = 0; i < mp->totloop; i++) { fuv[i] = mloopuv[mp->loopstart + i].uv; } @@ -234,13 +232,10 @@ void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum) } else { /* Collect Mesh UVs */ - MLoopUV *mloopuv; - int i; - BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV)); - mloopuv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); + MLoopUV *mloopuv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); - for (i = 0; i < me->totpoly; i++) { + for (int i = 0; i < me->totpoly; i++) { mesh_uv_reset_mface(&me->mpoly[i], mloopuv); } } @@ -1061,15 +1056,12 @@ void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_lo static void mesh_add_verts(Mesh *mesh, int len) { - CustomData vdata; - MVert *mvert; - int i, totvert; - if (len == 0) { return; } - totvert = mesh->totvert + len; + int totvert = mesh->totvert + len; + CustomData vdata; CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH.vmask, CD_DEFAULT, totvert); CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert); @@ -1084,8 +1076,8 @@ static void mesh_add_verts(Mesh *mesh, int len) /* scan the input list and insert the new vertices */ /* set default flags */ - mvert = &mesh->mvert[mesh->totvert]; - for (i = 0; i < len; i++, mvert++) { + MVert *mvert = &mesh->mvert[mesh->totvert]; + for (int i = 0; i < len; i++, mvert++) { mvert->flag |= SELECT; } diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 4d55aff1d1f..19097d95743 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -301,8 +301,7 @@ static bool write_internal_bake_pixels(Image *image, /* force OpenGL reload */ static void refresh_images(BakeImages *bake_images) { - int i; - for (i = 0; i < bake_images->size; i++) { + for (int i = 0; i < bake_images->size; i++) { Image *ima = bake_images->data[i].image; LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { if (tile->ok == IMA_OK_LOADED) { @@ -413,10 +412,7 @@ static bool is_noncolor_pass(eScenePassType pass_type) /* if all is good tag image and return true */ static bool bake_object_check(ViewLayer *view_layer, Object *ob, ReportList *reports) { - Image *image; Base *base = BKE_view_layer_base_find(view_layer, ob); - void *lock; - int i; if (base == NULL) { BKE_reportf(reports, RPT_ERROR, "Object \"%s\" is not in view layer", ob->id.name + 2); @@ -440,10 +436,11 @@ static bool bake_object_check(ViewLayer *view_layer, Object *ob, ReportList *rep return false; } - for (i = 0; i < ob->totcol; i++) { + for (int i = 0; i < ob->totcol; i++) { bNodeTree *ntree = NULL; bNode *node = NULL; const int mat_nr = i + 1; + Image *image; ED_object_get_active_image(ob, mat_nr, &image, NULL, &node, &ntree); if (image) { @@ -462,6 +459,7 @@ static bool bake_object_check(ViewLayer *view_layer, Object *ob, ReportList *rep } } + void *lock; ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); if (ibuf) { @@ -637,13 +635,12 @@ static void bake_images_clear(Main *bmain, const bool is_tangent) static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images) { const int tot_mat = ob->totcol; - int i, j; int tot_images = 0; /* error handling and tag (in case multiple materials share the same image) */ BKE_main_id_tag_idcode(bmain, ID_IM, LIB_TAG_DOIT, false); - for (i = 0; i < tot_mat; i++) { + for (int i = 0; i < tot_mat; i++) { Image *image; ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL); @@ -652,7 +649,7 @@ static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images) bake_images->lookup[i] = -1; } else if (image->id.tag & LIB_TAG_DOIT) { - for (j = 0; j < i; j++) { + for (int j = 0; j < i; j++) { if (bake_images->data[j].image == image) { bake_images->lookup[i] = j; break; @@ -675,15 +672,12 @@ static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images) */ static size_t init_internal_images(BakeImages *bake_images, ReportList *reports) { - int i; size_t tot_size = 0; - for (i = 0; i < bake_images->size; i++) { - ImBuf *ibuf; - void *lock; - + for (int i = 0; i < bake_images->size; i++) { BakeImage *bk_image = &bake_images->data[i]; - ibuf = BKE_image_acquire_ibuf(bk_image->image, NULL, &lock); + void *lock; + ImBuf *ibuf = BKE_image_acquire_ibuf(bk_image->image, NULL, &lock); if (ibuf) { bk_image->width = ibuf->x; @@ -1228,8 +1222,7 @@ static int bake(Render *re, cleanup: if (highpoly) { - int i; - for (i = 0; i < tot_highpoly; i++) { + for (int i = 0; i < tot_highpoly; i++) { if (highpoly[i].me != NULL) { BKE_id_free(NULL, &highpoly[i].me->id); } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 2f9917a2674..8b10a865a68 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -107,9 +107,12 @@ ListBase *ED_object_constraint_active_list(Object *ob) * ED_object_constraint_active_list, such constraints are not excluded here). */ ListBase *ED_object_pose_constraint_list(const bContext *C) { - bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data; + bPoseChannel *pose_bone = CTX_data_pointer_get(C, "active_pose_bone").data; if (pose_bone == NULL) { - return NULL; + pose_bone = CTX_data_pointer_get(C, "pose_bone").data; + if (pose_bone == NULL) { + return NULL; + } } return &pose_bone->constraints; diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index da00a88ab65..4884df1edb6 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -153,21 +153,18 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, Object *ob_src = CTX_data_active_object(C); if (ob_src) { - Mesh *me_eval; - int num_data, i; - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; cddata_masks.lmask |= CD_MASK_MLOOPUV; - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); - num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPUV); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + int num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPUV); RNA_enum_item_add_separator(&item, &totitem); - for (i = 0; i < num_data; i++) { + for (int i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name( &me_eval->ldata, CD_MLOOPUV, i); @@ -179,21 +176,18 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, Object *ob_src = CTX_data_active_object(C); if (ob_src) { - Mesh *me_eval; - int num_data, i; - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; cddata_masks.lmask |= CD_MASK_MLOOPCOL; - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); - num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + int num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL); RNA_enum_item_add_separator(&item, &totitem); - for (i = 0; i < num_data; i++) { + for (int i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name( &me_eval->ldata, CD_MLOOPCOL, i); diff --git a/source/blender/editors/object/object_facemap_ops.c b/source/blender/editors/object/object_facemap_ops.c index 32668598df1..4e2b1eb21b6 100644 --- a/source/blender/editors/object/object_facemap_ops.c +++ b/source/blender/editors/object/object_facemap_ops.c @@ -136,10 +136,8 @@ static void object_fmap_remap_object_mode(Object *ob, const int *remap) Mesh *me = ob->data; if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) { int *map = CustomData_get_layer(&me->pdata, CD_FACEMAP); - int i; - if (map) { - for (i = 0; i < me->totpoly; i++) { + for (int i = 0; i < me->totpoly; i++) { if (map[i] != -1) { map[i] = remap[map[i]]; } diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 52b572fb0dd..e2d043c3206 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -834,11 +834,10 @@ static int apply_objects_internal(bContext *C, } else if (ob->type == OB_FONT) { Curve *cu = ob->data; - int i; scale = mat3_to_scale(rsmat); - for (i = 0; i < cu->totbox; i++) { + for (int i = 0; i < cu->totbox; i++) { TextBox *tb = &cu->tb[i]; tb->x *= scale; tb->y *= scale; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index de9cca38a6e..b8811408339 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -148,11 +148,9 @@ void ED_vgroup_data_clamp_range(ID *id, const int total) int dvert_tot; if (ED_vgroup_parray_alloc(id, &dvert_arr, &dvert_tot, false)) { - int i; - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { MDeformVert *dv = dvert_arr[i]; - int j; - for (j = 0; j < dv->totweight; j++) { + for (int j = 0; j < dv->totweight; j++) { if (dv->dw[j].def_nr >= total) { BKE_defvert_remove_group(dv, &dv->dw[j]); j--; @@ -213,18 +211,17 @@ bool ED_vgroup_parray_alloc(ID *id, if (me->dvert) { MVert *mvert = me->mvert; MDeformVert *dvert = me->dvert; - int i; *dvert_tot = me->totvert; *dvert_arr = MEM_mallocN(sizeof(void *) * me->totvert, "vgroup parray from me"); if (use_vert_sel) { - for (i = 0; i < me->totvert; i++) { + for (int i = 0; i < me->totvert; i++) { (*dvert_arr)[i] = (mvert[i].flag & SELECT) ? &dvert[i] : NULL; } } else { - for (i = 0; i < me->totvert; i++) { + for (int i = 0; i < me->totvert; i++) { (*dvert_arr)[i] = me->dvert + i; } } @@ -234,8 +231,6 @@ bool ED_vgroup_parray_alloc(ID *id, return false; } case ID_LT: { - int i = 0; - Lattice *lt = (Lattice *)id; lt = (lt->editlatt) ? lt->editlatt->latt : lt; @@ -245,12 +240,12 @@ bool ED_vgroup_parray_alloc(ID *id, *dvert_arr = MEM_mallocN(sizeof(void *) * (*dvert_tot), "vgroup parray from me"); if (use_vert_sel) { - for (i = 0; i < *dvert_tot; i++) { + for (int i = 0; i < *dvert_tot; i++) { (*dvert_arr)[i] = (def->f1 & SELECT) ? <->dvert[i] : NULL; } } else { - for (i = 0; i < *dvert_tot; i++) { + for (int i = 0; i < *dvert_tot; i++) { (*dvert_arr)[i] = lt->dvert + i; } } @@ -328,7 +323,6 @@ void ED_vgroup_parray_mirror_assign(Object *ob, MDeformVert **dvert_array, const BMEditMesh *em = BKE_editmesh_from_object(ob); MDeformVert **dvert_array_all = NULL; int dvert_tot_all; - int i; /* get an array of all verts, not only selected */ if (ED_vgroup_parray_alloc(ob->data, &dvert_array_all, &dvert_tot_all, false) == false) { @@ -340,7 +334,7 @@ void ED_vgroup_parray_mirror_assign(Object *ob, MDeformVert **dvert_array, const BM_mesh_elem_table_ensure(em->bm, BM_VERT); } - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { if (dvert_array[i] == NULL) { /* its unselected, check if its mirror is */ int i_sel = ED_mesh_mirror_get_vert(ob, i); @@ -362,17 +356,14 @@ void ED_vgroup_parray_remove_zero(MDeformVert **dvert_array, const bool keep_single) { MDeformVert *dv; - int i; - - for (i = 0; i < dvert_tot; i++) { - int j; + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } - j = dv->totweight; + int j = dv->totweight; while (j--) { MDeformWeight *dw; @@ -482,9 +473,7 @@ void ED_vgroup_parray_to_weight_array(const MDeformVert **dvert_array, float *dvert_weights, const int def_nr) { - int i; - - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { const MDeformVert *dv = dvert_array[i]; dvert_weights[i] = dv ? BKE_defvert_find_weight(dv, def_nr) : 0.0f; } @@ -1163,7 +1152,7 @@ static bool vgroup_normalize(Object *ob) { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; - int i, dvert_tot = 0; + int dvert_tot = 0; const int def_nr = ob->actdef - 1; const bool use_vert_sel = vertex_group_use_vert_sel(ob); @@ -1177,7 +1166,7 @@ static bool vgroup_normalize(Object *ob) if (dvert_array) { float weight_max = 0.0f; - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { @@ -1191,7 +1180,7 @@ static bool vgroup_normalize(Object *ob) } if (weight_max > 0.0f) { - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { @@ -1599,7 +1588,7 @@ static void vgroup_levels_subset(Object *ob, { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; - int i, dvert_tot = 0; + int dvert_tot = 0; const bool use_vert_sel = vertex_group_use_vert_sel(ob); const bool use_mirror = (ob->type == OB_MESH) ? @@ -1610,15 +1599,13 @@ static void vgroup_levels_subset(Object *ob, if (dvert_array) { - for (i = 0; i < dvert_tot; i++) { - int j; - + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } - j = vgroup_tot; + int j = vgroup_tot; while (j--) { if (vgroup_validmap[j]) { dw = BKE_defvert_find_index(dv, j); @@ -1857,7 +1844,7 @@ static void vgroup_invert_subset(Object *ob, { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; - int i, dvert_tot = 0; + int dvert_tot = 0; const bool use_vert_sel = vertex_group_use_vert_sel(ob); const bool use_mirror = (ob->type == OB_MESH) ? (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X) != 0 : @@ -1866,15 +1853,13 @@ static void vgroup_invert_subset(Object *ob, ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, use_vert_sel); if (dvert_array) { - for (i = 0; i < dvert_tot; i++) { - int j; - + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } - j = vgroup_tot; + int j = vgroup_tot; while (j--) { if (vgroup_validmap[j]) { @@ -2271,21 +2256,20 @@ static void vgroup_quantize_subset(Object *ob, if (dvert_array) { const float steps_fl = steps; MDeformVert *dv; - int i; if (use_mirror && use_vert_sel) { ED_vgroup_parray_mirror_assign(ob, dvert_array, dvert_tot); } - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { MDeformWeight *dw; - int j; /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } + int j; for (j = 0, dw = dv->dw; j < dv->totweight; j++, dw++) { if ((dw->def_nr < vgroup_tot) && vgroup_validmap[dw->def_nr]) { dw->weight = floorf((dw->weight * steps_fl) + 0.5f) / steps_fl; @@ -2628,18 +2612,14 @@ static void vgroup_assign_verts(Object *ob, const float weight) } } else { - MVert *mv; - MDeformVert *dv; - int i; - if (!me->dvert) { BKE_object_defgroup_data_create(&me->id); } - mv = me->mvert; - dv = me->dvert; + MVert *mv = me->mvert; + MDeformVert *dv = me->dvert; - for (i = 0; i < me->totvert; i++, mv++, dv++) { + for (int i = 0; i < me->totvert; i++, mv++, dv++) { if (mv->flag & SELECT) { MDeformWeight *dw; dw = BKE_defvert_ensure_index(dv, def_nr); diff --git a/source/blender/editors/object/object_warp.c b/source/blender/editors/object/object_warp.c index 00f9330c8a7..b36a8543d67 100644 --- a/source/blender/editors/object/object_warp.c +++ b/source/blender/editors/object/object_warp.c @@ -71,11 +71,8 @@ static void object_warp_transverts_minmax_x(TransVertStore *tvs, const float x_ofs = (mat_view[3][0] - center_view[0]); float min = FLT_MAX, max = -FLT_MAX; - TransVert *tv; - int i; - - tv = tvs->transverts; - for (i = 0; i < tvs->transverts_tot; i++, tv++) { + TransVert *tv = tvs->transverts; + for (int i = 0; i < tvs->transverts_tot; i++, tv++) { float val; /* convert objectspace->viewspace */ @@ -97,7 +94,6 @@ static void object_warp_transverts(TransVertStore *tvs, const float max) { TransVert *tv; - int i; const float angle = -angle_; /* cache vars for tiny speedup */ #if 1 @@ -123,7 +119,7 @@ static void object_warp_transverts(TransVertStore *tvs, } tv = tvs->transverts; - for (i = 0; i < tvs->transverts_tot; i++, tv++) { + for (int i = 0; i < tvs->transverts_tot; i++, tv++) { float co[3], co_add[2]; float val, phi; diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c index 205c04f54a9..8db6c4c853e 100644 --- a/source/blender/editors/physics/particle_edit_undo.c +++ b/source/blender/editors/physics/particle_edit_undo.c @@ -57,7 +57,6 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) { PTCacheEditPoint *point; - int i; size_t mem_used_prev = MEM_get_memory_in_use(); @@ -68,7 +67,7 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) pa = undo->particles = MEM_dupallocN(edit->psys->particles); - for (i = 0; i < edit->totpoint; i++, pa++) { + for (int i = 0; i < edit->totpoint; i++, pa++) { pa->hair = MEM_dupallocN(pa->hair); } @@ -81,7 +80,7 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) pm = undo->mem_cache.first; for (; pm; pm = pm->next) { - for (i = 0; i < BPHYS_TOT_DATA; i++) { + for (int i = 0; i < BPHYS_TOT_DATA; i++) { pm->data[i] = MEM_dupallocN(pm->data[i]); } } @@ -90,7 +89,7 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) point = undo->points = MEM_dupallocN(edit->points); undo->totpoint = edit->totpoint; - for (i = 0; i < edit->totpoint; i++, point++) { + for (int i = 0; i < edit->totpoint; i++, point++) { point->keys = MEM_dupallocN(point->keys); /* no need to update edit key->co & key->time pointers here */ } diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 41e30adf724..0eda5877bb4 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -721,7 +721,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, MVert *mvert; Mesh *mesh, *target_mesh; int numverts; - int i, k; + int k; float from_ob_imat[4][4], to_ob_imat[4][4]; float from_imat[4][4], to_imat[4][4]; @@ -763,7 +763,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, mvert = mesh->mvert; /* convert to global coordinates */ - for (i = 0; i < numverts; i++) { + for (int i = 0; i < numverts; i++) { mul_m4_v3(to_mat, mvert[i].co); } @@ -780,6 +780,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, return false; } + int i; for (i = 0, tpa = target_psys->particles, pa = psys->particles; i < target_psys->totpart; i++, tpa++, pa++) { float from_co[3]; diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index c145dfd0278..01c6ef8cdd2 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -3346,7 +3346,6 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const char temp_str[MAX_METADATA_STR]; int line_width; int ofs_y = 0; - short i; int len; const float height = BLF_height_max(fontid); const float margin = height / 8; @@ -3360,7 +3359,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const const float ymax = (rect->ymax - margin) - descender; if (is_top) { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { /* first line */ if (i == 0) { bool do_newline = false; @@ -3425,7 +3424,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const IMB_metadata_foreach(ibuf, metadata_custom_draw_fields, &ctx); int ofs_x = 0; ofs_y = ctx.current_y; - for (i = 5; i < 10; i++) { + for (int i = 5; i < 10; i++) { len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index f4d7869e40a..3d8c718c8a9 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -911,7 +911,6 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) GPU_matrix_translate_2f(vc->region->winrct.xmin, vc->region->winrct.ymin); if (brush->paint_curve && brush->paint_curve->points) { - int i; PaintCurve *pc = brush->paint_curve; PaintCurvePoint *cp = pc->points; @@ -928,7 +927,7 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) UI_GetThemeColorType4fv(TH_PAINT_CURVE_HANDLE, SPACE_VIEW3D, handle_col); UI_GetThemeColorType4fv(TH_PAINT_CURVE_PIVOT, SPACE_VIEW3D, pivot_col); - for (i = 0; i < pc->tot_points - 1; i++, cp++) { + for (int i = 0; i < pc->tot_points - 1; i++, cp++) { int j; PaintCurvePoint *cp_next = cp + 1; float data[(PAINT_CURVE_NUM_SEGMENTS + 1) * 2]; diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index 458f021ddb4..c63af64a87a 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -189,23 +189,20 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) Paint *p = BKE_paint_get_active_from_context(C); Brush *br = p->brush; Main *bmain = CTX_data_main(C); - PaintCurve *pc; - PaintCurvePoint *pcp; wmWindow *window = CTX_wm_window(C); ARegion *region = CTX_wm_region(C); const float vec[3] = {loc[0], loc[1], 0.0}; - int add_index; - int i; - pc = br->paint_curve; + PaintCurve *pc = br->paint_curve; if (!pc) { br->paint_curve = pc = BKE_paint_curve_add(bmain, "PaintCurve"); } ED_paintcurve_undo_push_begin(op->type->name); - pcp = MEM_mallocN((pc->tot_points + 1) * sizeof(PaintCurvePoint), "PaintCurvePoint"); - add_index = pc->add_index; + PaintCurvePoint *pcp = MEM_mallocN((pc->tot_points + 1) * sizeof(PaintCurvePoint), + "PaintCurvePoint"); + int add_index = pc->add_index; if (pc->points) { if (add_index > 0) { @@ -229,7 +226,7 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) copy_v3_v3(pcp[add_index].bez.vec[2], vec); /* last step, clear selection from all bezier handles expect the next */ - for (i = 0; i < pc->tot_points; i++) { + for (int i = 0; i < pc->tot_points; i++) { pcp[i].bez.f1 = pcp[i].bez.f2 = pcp[i].bez.f3 = 0; } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 3886b78286b..d44654f4fd5 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -2676,7 +2676,6 @@ static void project_bucket_clip_face(const bool is_ortho, /* calc center */ float cent[2] = {0.0f, 0.0f}; /*float up[2] = {0.0f, 1.0f};*/ - int i; bool doubles; (*tot) = 0; @@ -2757,7 +2756,7 @@ static void project_bucket_clip_face(const bool is_ortho, /* now we have all points we need, collect their angles and sort them clockwise */ - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { cent[0] += isectVCosSS[i][0]; cent[1] += isectVCosSS[i][1]; } @@ -2767,7 +2766,7 @@ static void project_bucket_clip_face(const bool is_ortho, /* Collect angles for every point around the center point */ #if 0 /* uses a few more cycles then the above loop */ - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { isectVCosSS[i][2] = angle_2d_clockwise(up, cent, isectVCosSS[i]); } #endif @@ -2776,7 +2775,7 @@ static void project_bucket_clip_face(const bool is_ortho, v1_clipSS[0] = cent[0]; v1_clipSS[1] = cent[1] + 1.0f; - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { v2_clipSS[0] = isectVCosSS[i][0] - cent[0]; v2_clipSS[1] = isectVCosSS[i][1] - cent[1]; isectVCosSS[i][2] = atan2f(v1_clipSS[0] * v2_clipSS[1] - v1_clipSS[1] * v2_clipSS[0], @@ -2794,11 +2793,10 @@ static void project_bucket_clip_face(const bool is_ortho, while (doubles == true) { doubles = false; - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { if (fabsf(isectVCosSS[(i + 1) % *tot][0] - isectVCosSS[i][0]) < PROJ_PIXEL_TOLERANCE && fabsf(isectVCosSS[(i + 1) % *tot][1] - isectVCosSS[i][1]) < PROJ_PIXEL_TOLERANCE) { - int j; - for (j = i; j < (*tot) - 1; j++) { + for (int j = i; j < (*tot) - 1; j++) { isectVCosSS[j][0] = isectVCosSS[j + 1][0]; isectVCosSS[j][1] = isectVCosSS[j + 1][1]; } @@ -2817,13 +2815,13 @@ static void project_bucket_clip_face(const bool is_ortho, } if (is_ortho) { - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { barycentric_weights_v2(v1coSS, v2coSS, v3coSS, isectVCosSS[i], w); interp_v2_v2v2v2(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); } } else { - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { barycentric_weights_v2_persp(v1coSS, v2coSS, v3coSS, isectVCosSS[i], w); interp_v2_v2v2v2(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); } @@ -2864,7 +2862,7 @@ static void project_bucket_clip_face(const bool is_ortho, uv3co[1]); printf("["); - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { printf("(%f, %f),", bucket_bounds_uv[i][0], bucket_bounds_uv[i][1]); } printf("]),\\\n"); @@ -5874,8 +5872,6 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m ProjStrokeHandle *ps_handle; Scene *scene = CTX_data_scene(C); ToolSettings *settings = scene->toolsettings; - int i; - bool is_multi_view; char symmetry_flag_views[ARRAY_SIZE(ps_handle->ps_views)] = {0}; ps_handle = MEM_callocN(sizeof(ProjStrokeHandle), "ProjStrokeHandle"); @@ -5893,9 +5889,9 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m ps_handle->symmetry_flags = settings->imapaint.paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; ps_handle->ps_views_tot = 1 + (pow_i(2, count_bits_i(ps_handle->symmetry_flags)) - 1); - is_multi_view = (ps_handle->ps_views_tot != 1); + bool is_multi_view = (ps_handle->ps_views_tot != 1); - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = MEM_callocN(sizeof(ProjPaintState), "ProjectionPaintState"); ps_handle->ps_views[i] = ps; } @@ -5918,7 +5914,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m BLI_assert(index == ps_handle->ps_views_tot); } - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = ps_handle->ps_views[i]; project_state_init(C, ob, ps, mode); @@ -5936,7 +5932,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m /* allocate and initialize spatial data structures */ - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = ps_handle->ps_views[i]; ps->source = (ps->tool == PAINT_TOOL_FILL) ? PROJ_SRC_VIEW_FILL : PROJ_SRC_VIEW; @@ -5961,7 +5957,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m return ps_handle; fail: - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = ps_handle->ps_views[i]; MEM_freeN(ps); } diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index e709224f370..db7120ed301 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -711,15 +711,12 @@ static float paint_space_stroke_spacing(bContext *C, static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing) { - int i; const int n = 100 / spacing; const float h = spacing / 50.0f; const float x0 = x - 1; - float sum; - - sum = 0; - for (i = 0; i < n; i++) { + float sum = 0; + for (int i = 0; i < n; i++) { float xx; xx = fabsf(x0 + i * h); @@ -734,21 +731,16 @@ static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing) static float paint_stroke_integrate_overlap(Brush *br, float factor) { - int i; - int m; - float g; - float max; - float spacing = br->spacing * factor; if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) { return 1.0; } - m = 10; - g = 1.0f / m; - max = 0; - for (i = 0; i < m; i++) { + int m = 10; + float g = 1.0f / m; + float max = 0; + for (int i = 0; i < m; i++) { float overlap = fabs(paint_stroke_overlapped_curve(br, i * g, spacing)); if (overlap > max) { @@ -1151,13 +1143,11 @@ static void paint_stroke_add_sample( static void paint_stroke_sample_average(const PaintStroke *stroke, PaintSample *average) { - int i; - memset(average, 0, sizeof(*average)); BLI_assert(stroke->num_samples > 0); - for (i = 0; i < stroke->num_samples; i++) { + for (int i = 0; i < stroke->num_samples; i++) { add_v2_v2(average->mouse, stroke->samples[i].mouse); average->pressure += stroke->samples[i].pressure; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c index d05b1673c9a..b831687ca67 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c @@ -68,9 +68,6 @@ static void tag_object_after_update(Object *object) static bool vertex_color_set(Object *ob, uint paintcol) { Mesh *me; - const MPoly *mp; - int i, j; - if (((me = BKE_mesh_from_object(ob)) == NULL) || (ED_mesh_color_ensure(me, NULL) == false)) { return false; } @@ -78,15 +75,15 @@ static bool vertex_color_set(Object *ob, uint paintcol) const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; - mp = me->mpoly; - for (i = 0; i < me->totpoly; i++, mp++) { + const MPoly *mp = me->mpoly; + for (int i = 0; i < me->totpoly; i++, mp++) { MLoopCol *lcol = me->mloopcol + mp->loopstart; if (use_face_sel && !(mp->flag & ME_FACE_SEL)) { continue; } - j = 0; + int j = 0; do { uint vidx = me->mloop[mp->loopstart + j].v; if (!(use_vert_sel && !(me->mvert[vidx].flag & SELECT))) { @@ -211,7 +208,6 @@ static void vertex_color_smooth_looptag(Mesh *me, const bool *mlooptag) const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const MPoly *mp; int(*scol)[4]; - int i, j; bool has_shared = false; /* if no mloopcol: do not do */ @@ -223,11 +219,12 @@ static void vertex_color_smooth_looptag(Mesh *me, const bool *mlooptag) scol = MEM_callocN(sizeof(int) * me->totvert * 5, "scol"); + int i; for (i = 0, mp = me->mpoly; i < me->totpoly; i++, mp++) { if ((use_face_sel == false) || (mp->flag & ME_FACE_SEL)) { const MLoop *ml = me->mloop + mp->loopstart; MLoopCol *lcol = me->mloopcol + mp->loopstart; - for (j = 0; j < mp->totloop; j++, ml++, lcol++) { + for (int j = 0; j < mp->totloop; j++, ml++, lcol++) { scol[ml->v][0] += lcol->r; scol[ml->v][1] += lcol->g; scol[ml->v][2] += lcol->b; @@ -250,7 +247,7 @@ static void vertex_color_smooth_looptag(Mesh *me, const bool *mlooptag) if ((use_face_sel == false) || (mp->flag & ME_FACE_SEL)) { const MLoop *ml = me->mloop + mp->loopstart; MLoopCol *lcol = me->mloopcol + mp->loopstart; - for (j = 0; j < mp->totloop; j++, ml++, lcol++) { + for (int j = 0; j < mp->totloop; j++, ml++, lcol++) { if (mlooptag[mp->loopstart + j]) { lcol->r = scol[ml->v][0]; lcol->g = scol[ml->v][1]; diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c index 637ce8193c1..7120f6a8748 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c @@ -435,9 +435,7 @@ BLI_INLINE uint mcol_softlight(uint col_src, uint col_dst, int fac) cp_dst = (uchar *)&col_dst; cp_mix = (uchar *)&col_mix; - int i = 0; - - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { if (cp_src[i] < 127) { temp = ((2 * ((cp_dst[i] / 2) + 64)) * cp_src[i]) / 255; } diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index fd800ca2c18..287e1eb03d1 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -327,17 +327,14 @@ static bool sculpt_undo_restore_color(bContext *C, SculptUndoNode *unode) ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); SculptSession *ss = ob->sculpt; - MVert *mvert; - MPropCol *vcol; - int *index, i; if (unode->maxvert) { /* regular mesh restore */ - index = unode->index; - mvert = ss->mvert; - vcol = ss->vcol; + int *index = unode->index; + MVert *mvert = ss->mvert; + MPropCol *vcol = ss->vcol; - for (i = 0; i < unode->totvert; i++) { + for (int i = 0; i < unode->totvert; i++) { copy_v4_v4(vcol[index[i]].color, unode->col[i]); mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE; } @@ -927,16 +924,14 @@ SculptUndoNode *SCULPT_undo_get_first_node() static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, SculptUndoNode *unode) { PBVHNode *node = unode->node; - BLI_bitmap **grid_hidden; - int i, *grid_indices, totgrid; - - grid_hidden = BKE_pbvh_grid_hidden(pbvh); + BLI_bitmap **grid_hidden = BKE_pbvh_grid_hidden(pbvh); + int *grid_indices, totgrid; BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, NULL, NULL, NULL); unode->grid_hidden = MEM_callocN(sizeof(*unode->grid_hidden) * totgrid, "unode->grid_hidden"); - for (i = 0; i < totgrid; i++) { + for (int i = 0; i < totgrid; i++) { if (grid_hidden[grid_indices[i]]) { unode->grid_hidden[i] = MEM_dupallocN(grid_hidden[grid_indices[i]]); } @@ -1087,11 +1082,10 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode) MVert *mvert; const int *vert_indices; int allvert; - int i; BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert); BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert); - for (i = 0; i < allvert; i++) { + for (int i = 0; i < allvert; i++) { BLI_BITMAP_SET(unode->vert_hidden, i, mvert[vert_indices[i]].flag & ME_HIDE); } } diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 38b22464761..2e10cc94004 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -333,11 +333,10 @@ static bool buttons_context_path_material(ButsContextPath *path) if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { ma = BKE_object_material_get(ob, ob->actcol); - if (ma == NULL) { - return false; + if (ma != NULL) { + RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); + path->len++; } - RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); - path->len++; return true; } } diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 609d53ccc55..ecca593fe3d 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -648,8 +648,8 @@ static void buttons_id_remap(ScrArea *UNUSED(area), SpaceLink *slink, ID *old_id if (sbuts->path) { ButsContextPath *path = sbuts->path; - int i; + int i; for (i = 0; i < path->len; i++) { if (path->ptr[i].owner_id == old_id) { break; diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c index 2e7ee3498b5..f3bac697044 100644 --- a/source/blender/editors/space_clip/clip_buttons.c +++ b/source/blender/editors/space_clip/clip_buttons.c @@ -384,7 +384,6 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event) } else if (event == B_MARKER_OFFSET) { float offset[2], delta[2]; - int i; offset[0] = cb->track_offset[0] / width; offset[1] = cb->track_offset[1] / height; @@ -392,7 +391,7 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event) sub_v2_v2v2(delta, offset, cb->track->offset); copy_v2_v2(cb->track->offset, offset); - for (i = 0; i < cb->track->markersnr; i++) { + for (int i = 0; i < cb->track->markersnr; i++) { sub_v2_v2(cb->track->markers[i].pos, delta); } diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index e12e4eb2231..4759075555b 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -871,16 +871,11 @@ static void draw_marker_areas(SpaceClip *sc, static float get_shortest_pattern_side(MovieTrackingMarker *marker) { - int i, next; float len_sq = FLT_MAX; - for (i = 0; i < 4; i++) { - float cur_len; - - next = (i + 1) % 4; - - cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); - + for (int i = 0; i < 4; i++) { + int next = (i + 1) % 4; + float cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); len_sq = min_ff(cur_len, len_sq); } @@ -983,7 +978,6 @@ static void draw_marker_slide_zones(SpaceClip *sc, } if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) { - int i; float pat_min[2], pat_max[2]; /* float dx = 12.0f / width, dy = 12.0f / height;*/ /* XXX UNUSED */ float tilt_ctrl[2]; @@ -993,7 +987,7 @@ static void draw_marker_slide_zones(SpaceClip *sc, } /* pattern's corners sliding squares */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { draw_marker_slide_square(marker->pattern_corners[i][0], marker->pattern_corners[i][1], patdx / 1.5f, @@ -1381,8 +1375,7 @@ static void draw_plane_marker_ex(SpaceClip *sc, immUniformColor3fv(selected_color); } - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1], 3.0f * px[0], diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 83096b4eded..b2c80faec0b 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -940,11 +940,10 @@ static void start_prefetch_threads(MovieClip *clip, short *do_update, float *progress) { - PrefetchQueue queue; - TaskPool *task_pool; - int i, tot_thread = BLI_task_scheduler_num_threads(); + int tot_thread = BLI_task_scheduler_num_threads(); /* initialize queue */ + PrefetchQueue queue; BLI_spin_init(&queue.spin); queue.current_frame = current_frame; @@ -959,8 +958,8 @@ static void start_prefetch_threads(MovieClip *clip, queue.do_update = do_update; queue.progress = progress; - task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); - for (i = 0; i < tot_thread; i++) { + TaskPool *task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); + for (int i = 0; i < tot_thread; i++) { BLI_task_pool_push(task_pool, prefetch_task_func, clip, false, NULL); } BLI_task_pool_work_and_wait(task_pool); diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 8532d8420f9..013731a50d6 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -1412,17 +1412,16 @@ static void do_sequence_proxy(void *pjv, ProxyJob *pj = pjv; MovieClip *clip = pj->clip; Scene *scene = pj->scene; - TaskPool *task_pool; int sfra = SFRA, efra = EFRA; ProxyThread *handles; - int i, tot_thread = BLI_task_scheduler_num_threads(); + int tot_thread = BLI_task_scheduler_num_threads(); int width, height; - ProxyQueue queue; if (build_undistort_count) { BKE_movieclip_get_size(clip, NULL, &width, &height); } + ProxyQueue queue; BLI_spin_init(&queue.spin); queue.cfra = sfra; @@ -1432,9 +1431,9 @@ static void do_sequence_proxy(void *pjv, queue.do_update = do_update; queue.progress = progress; - task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); + TaskPool *task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); handles = MEM_callocN(sizeof(ProxyThread) * tot_thread, "proxy threaded handles"); - for (i = 0; i < tot_thread; i++) { + for (int i = 0; i < tot_thread; i++) { ProxyThread *handle = &handles[i]; handle->clip = clip; @@ -1456,7 +1455,7 @@ static void do_sequence_proxy(void *pjv, BLI_task_pool_free(task_pool); if (build_undistort_count) { - for (i = 0; i < tot_thread; i++) { + for (int i = 0; i < tot_thread; i++) { ProxyThread *handle = &handles[i]; BKE_tracking_distortion_free(handle->distortion); } diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index bcbf843f51c..cbf43bb7ff0 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -297,11 +297,8 @@ void clip_graph_tracking_iterate(SpaceClip *sc, MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); - MovieTrackingTrack *track; - - for (track = tracksbase->first; track; track = track->next) { - int i; + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; } @@ -310,7 +307,7 @@ void clip_graph_tracking_iterate(SpaceClip *sc, continue; } - for (i = 0; i < track->markersnr; i++) { + for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = &track->markers[i]; if (marker->flag & MARKER_DISABLED) { diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 177a0bc2bcf..05fa7a6b587 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -511,7 +511,6 @@ static int mouse_to_tilt_distance_squared(const MovieTrackingMarker *marker, static bool slide_check_corners(float (*corners)[2]) { - int i, next, prev; float cross = 0.0f; const float p[2] = {0.0f, 0.0f}; @@ -519,16 +518,16 @@ static bool slide_check_corners(float (*corners)[2]) return false; } - for (i = 0; i < 4; i++) { - float v1[2], v2[2], cur_cross; + for (int i = 0; i < 4; i++) { + float v1[2], v2[2]; - next = (i + 1) % 4; - prev = (4 + i - 1) % 4; + int next = (i + 1) % 4; + int prev = (4 + i - 1) % 4; sub_v2_v2v2(v1, corners[i], corners[prev]); sub_v2_v2v2(v2, corners[next], corners[i]); - cur_cross = cross_v2v2(v1, v2); + float cur_cross = cross_v2v2(v1, v2); if (fabsf(cur_cross) > FLT_EPSILON) { if (cross == 0.0f) { diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index 80d0dd773b2..08b95bd46c5 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -546,9 +546,8 @@ static int box_select_exec(bContext *C, wmOperator *op) for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { if (BLI_rctf_isect_pt_v(&rectf, plane_marker->corners[i])) { if (select) { plane_track->flag |= SELECT; @@ -651,9 +650,8 @@ static int do_lasso_select_marker(bContext *C, for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { float screen_co[2]; /* marker in screen coords */ @@ -812,9 +810,8 @@ static int circle_select_exec(bContext *C, wmOperator *op) for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { if (point_inside_ellipse(plane_marker->corners[i], offset, ellipse)) { if (select) { plane_track->flag |= SELECT; diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 0ade50814e0..5f0e6c8361e 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -943,11 +943,9 @@ void filelist_init_icons(void) void filelist_free_icons(void) { - int i; - BLI_assert(G.background == false); - for (i = 0; i < SPECIAL_IMG_MAX; i++) { + for (int i = 0; i < SPECIAL_IMG_MAX; i++) { IMB_freeImBuf(gSpecialFileImages[i]); gSpecialFileImages[i] = NULL; } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 88c8c6b2939..306d6cba50e 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -861,15 +861,13 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche { int match = 0; - int i; - FileDirEntry *file; int n = filelist_files_ensure(sfile->files); /* select any file that matches the pattern, this includes exact match * if the user selects a single file by entering the filename */ - for (i = 0; i < n; i++) { - file = filelist_file(sfile->files, i); + for (int i = 0; i < n; i++) { + FileDirEntry *file = filelist_file(sfile->files, i); /* Do not check whether file is a file or dir here! Causes T44243 * (we do accept dirs at this stage). */ if (fnmatch(pattern, file->relpath, 0) == 0) { @@ -941,9 +939,8 @@ int autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) if (str[0] && sfile->files) { AutoComplete *autocpl = UI_autocomplete_begin(str, FILE_MAX); int nentries = filelist_files_ensure(sfile->files); - int i; - for (i = 0; i < nentries; i++) { + for (int i = 0; i < nentries; i++) { FileDirEntry *file = filelist_file(sfile->files, i); UI_autocomplete_update_name(autocpl, file->relpath); } diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 0b3c98a392e..329b5fe67fd 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -645,11 +645,10 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) wchar_t wline[FILE_MAXDIR]; __int64 tmp; char tmps[4], *name; - int i; tmp = GetLogicalDrives(); - for (i = 0; i < 26; i++) { + for (int i = 0; i < 26; i++) { if ((tmp >> i) & 1) { tmps[0] = 'A' + i; tmps[1] = ':'; diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 70d29b52630..a99fcf60b23 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -500,11 +500,7 @@ static void draw_fcurve_samples(SpaceGraph *sipo, ARegion *region, FCurve *fcu) static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, uint pos) { SpaceGraph *sipo = (SpaceGraph *)ac->sl; - float samplefreq; - float stime, etime; - float unitFac, offset; short mapping_flag = ANIM_get_normalization_flags(ac); - int i, n; /* when opening a blend file on a different sized screen or while dragging the toolbar this can * happen best just bail out in this case. */ @@ -517,7 +513,9 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 fcurve_for_draw.driver = NULL; /* compute unit correction factor */ - unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, &fcurve_for_draw, mapping_flag, &offset); + float offset; + float unitFac = ANIM_unit_mapping_get_factor( + ac->scene, id, &fcurve_for_draw, mapping_flag, &offset); /* Note about sampling frequency: * Ideally, this is chosen such that we have 1-2 pixels = 1 segment @@ -535,7 +533,7 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 /* TODO: perhaps we should have 1.0 frames * as upper limit so that curves don't get too distorted? */ float pixels_per_sample = 1.5f; - samplefreq = pixels_per_sample / UI_view2d_scale_get_x(v2d); + float samplefreq = pixels_per_sample / UI_view2d_scale_get_x(v2d); if (sipo->flag & SIPO_BEAUTYDRAW_OFF) { /* Low Precision = coarse lower-bound clamping @@ -559,20 +557,21 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 } /* the start/end times are simply the horizontal extents of the 'cur' rect */ - stime = v2d->cur.xmin; - etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */ + float stime = v2d->cur.xmin; + float etime = v2d->cur.xmax + + samplefreq; /* + samplefreq here so that last item gets included... */ /* at each sampling interval, add a new vertex * - apply the unit correction factor to the calculated values so that * the displayed values appear correctly in the viewport */ - n = roundf((etime - stime) / samplefreq); + int n = roundf((etime - stime) / samplefreq); if (n > 0) { immBegin(GPU_PRIM_LINE_STRIP, (n + 1)); - for (i = 0; i <= n; i++) { + for (int i = 0; i <= n; i++) { float ctime = stime + i * samplefreq; immVertex2f(pos, ctime, (evaluate_fcurve(&fcurve_for_draw, ctime) + offset) * unitFac); } diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index 68f4bd0ff38..f8382a17c59 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -100,12 +100,10 @@ static bool add_reroute_intersect_check(bNodeLink *link, float result[2]) { float coord_array[NODE_LINK_RESOL + 1][2]; - int i, b; if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) { - for (b = 0; b < NODE_LINK_RESOL; b++) { + for (int i = 0; i < tot - 1; i++) { + for (int b = 0; b < NODE_LINK_RESOL; b++) { if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index a09c70b794a..57fd84a4521 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -322,7 +322,7 @@ static void snode_autoconnect(Main *bmain, ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list"); bNodeListItem *nli; bNode *node; - int i, numlinks = 0; + int numlinks = 0; for (node = ntree->nodes.first; node; node = node->next) { if (node->flag & NODE_SELECT) { @@ -376,7 +376,7 @@ static void snode_autoconnect(Main *bmain, /* no selected inputs, connect by finding suitable match */ int num_inputs = BLI_listbase_count(&node_to->inputs); - for (i = 0; i < num_inputs; i++) { + for (int i = 0; i < num_inputs; i++) { /* find the best guess input socket */ sock_to = best_socket_input(ntree, node_to, i, replace); @@ -1007,12 +1007,10 @@ void NODE_OT_link_make(wmOperatorType *ot) static bool cut_links_intersect(bNodeLink *link, const float mcoords[][2], int tot) { float coord_array[NODE_LINK_RESOL + 1][2]; - int i, b; if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) { - for (b = 0; b < NODE_LINK_RESOL; b++) { + for (int i = 0; i < tot - 1; i++) { + for (int b = 0; b < NODE_LINK_RESOL; b++) { if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { return 1; } @@ -1536,11 +1534,10 @@ void ED_node_link_intersect_test(ScrArea *area, int test) if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { float dist = FLT_MAX; - int i; /* loop over link coords to find shortest dist to * upper left node edge of a intersected line segment */ - for (i = 0; i < NODE_LINK_RESOL; i++) { + for (int i = 0; i < NODE_LINK_RESOL; i++) { /* check if the node rect intersetcts the line from this point to next one */ if (BLI_rctf_isect_segment(&select->totr, coord_array[i], coord_array[i + 1])) { /* store the shortest distance to the upper left edge diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index c5be96470ec..a7e2ad8fc1c 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -500,20 +500,20 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) int totitems; char name[UI_MAX_NAME_STR]; const char *cur_node_name = NULL; - int i, num = 0; + int num = 0; int icon = ICON_NONE; arg->node_type = ntype; ui_node_link_items(arg, SOCK_OUT, &items, &totitems); - for (i = 0; i < totitems; i++) { + for (int i = 0; i < totitems; i++) { if (ui_compatible_sockets(items[i].socket_type, sock->type)) { num++; } } - for (i = 0; i < totitems; i++) { + for (int i = 0; i < totitems; i++) { if (!ui_compatible_sockets(items[i].socket_type, sock->type)) { continue; } diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index a35feb62c9d..962c4e4c59d 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -823,7 +823,6 @@ int sequencer_image_seq_get_minmax_frame(wmOperator *op, void sequencer_image_seq_reserve_frames( wmOperator *op, StripElem *se, int len, int minframe, int numdigits) { - int i; char *filename = NULL; RNA_BEGIN (op->ptr, itemptr, "files") { filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0); @@ -837,7 +836,7 @@ void sequencer_image_seq_reserve_frames( /* Strip the frame from filename and substitute with `#`. */ BLI_path_frame_strip(filename, ext); - for (i = 0; i < len; i++, se++) { + for (int i = 0; i < len; i++, se++) { BLI_strncpy(filename_stripped, filename, sizeof(filename_stripped)); BLI_path_frame(filename_stripped, minframe + i, numdigits); BLI_snprintf(se->name, sizeof(se->name), "%s%s", filename_stripped, ext); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 70735a8ec82..662be2491a0 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -242,7 +242,6 @@ static void draw_seq_waveform(View2D *v2d, int x2_offset = min_ff(v2d->cur.xmax + 1.0f, x2); if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) { - int i, j, p; int length = floor((x2_offset - x1_offset) / stepsize) + 1; float ymid = (y1 + y2) / 2.0f; float yscale = (y2 - y1) / 2.0f; @@ -303,15 +302,15 @@ static void draw_seq_waveform(View2D *v2d, immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); immBegin(GPU_PRIM_TRI_STRIP, length * 2); - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { float sampleoffset = startsample + ((x1_offset - x1) / stepsize + i) * samplestep; - p = sampleoffset; + int p = sampleoffset; value1 = waveform->data[p * 3]; value2 = waveform->data[p * 3 + 1]; if (samplestep > 1.0f) { - for (j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) { + for (int j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) { if (value1 > waveform->data[j * 3]) { value1 = waveform->data[j * 3]; } diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index f175c2a7419..e446a1a5ed7 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -1482,7 +1482,7 @@ static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *eve Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); float mouseloc[2]; - int num_seq, i; + int num_seq; View2D *v2d = UI_view2d_fromcontext(C); /* Recursively count the trimmed elements. */ @@ -1506,7 +1506,7 @@ static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *eve slip_add_sequences_recursive(ed->seqbasep, data->seq_array, data->trim, 0, true); - for (i = 0; i < num_seq; i++) { + for (int i = 0; i < num_seq; i++) { transseq_backup(data->ts + i, data->seq_array[i]); } @@ -1611,21 +1611,19 @@ static void sequencer_slip_apply_limits(SlipData *data, int *offset) static int sequencer_slip_exec(bContext *C, wmOperator *op) { - SlipData *data; Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); - int num_seq, i; int offset = RNA_int_get(op->ptr, "offset"); bool success = false; /* Recursively count the trimmed elements. */ - num_seq = slip_count_sequences_recursive(ed->seqbasep, true); + int num_seq = slip_count_sequences_recursive(ed->seqbasep, true); if (num_seq == 0) { return OPERATOR_CANCELLED; } - data = op->customdata = MEM_mallocN(sizeof(SlipData), "trimdata"); + SlipData *data = op->customdata = MEM_mallocN(sizeof(SlipData), "trimdata"); data->ts = MEM_mallocN(num_seq * sizeof(TransSeq), "trimdata_transform"); data->seq_array = MEM_mallocN(num_seq * sizeof(Sequence *), "trimdata_sequences"); data->trim = MEM_mallocN(num_seq * sizeof(bool), "trimdata_trim"); @@ -1633,7 +1631,7 @@ static int sequencer_slip_exec(bContext *C, wmOperator *op) slip_add_sequences_recursive(ed->seqbasep, data->seq_array, data->trim, 0, true); - for (i = 0; i < num_seq; i++) { + for (int i = 0; i < num_seq; i++) { transseq_backup(data->ts + i, data->seq_array[i]); } @@ -1749,14 +1747,13 @@ static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *even case EVT_ESCKEY: case RIGHTMOUSE: { - int i; Editing *ed = BKE_sequencer_editing_get(scene, false); - for (i = 0; i < data->num_seq; i++) { + for (int i = 0; i < data->num_seq; i++) { transseq_restore(data->ts + i, data->seq_array[i]); } - for (i = 0; i < data->num_seq; i++) { + for (int i = 0; i < data->num_seq; i++) { Sequence *seq = data->seq_array[i]; BKE_sequence_reload_new_file(bmain, scene, seq, false); BKE_sequence_calc(scene, seq); diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c index 58a6f274310..1639870fee2 100644 --- a/source/blender/editors/space_sequencer/sequencer_scopes.c +++ b/source/blender/editors/space_sequencer/sequencer_scopes.c @@ -123,11 +123,9 @@ static void wform_put_border(uchar *tgt, int w, int h) static void wform_put_gridrow(uchar *tgt, float perc, int w, int h) { - int i; - tgt += (int)(perc / 100.0f * h) * w * 4; - for (i = 0; i < w * 2; i++) { + for (int i = 0; i < w * 2; i++) { tgt[0] = 255; tgt += 4; @@ -415,11 +413,10 @@ static void draw_histogram_marker(ImBuf *ibuf, int x) { uchar *p = (uchar *)ibuf->rect; int barh = ibuf->y * 0.1; - int i; p += 4 * (x + ibuf->x * (ibuf->y - barh + 1)); - for (i = 0; i < barh - 1; i++) { + for (int i = 0; i < barh - 1; i++) { p[0] = p[1] = p[2] = 255; p += ibuf->x * 4; } @@ -429,11 +426,10 @@ static void draw_histogram_bar(ImBuf *ibuf, int x, float val, int col) { uchar *p = (uchar *)ibuf->rect; int barh = ibuf->y * val * 0.9f; - int i; p += 4 * (x + ibuf->x); - for (i = 0; i < barh; i++) { + for (int i = 0; i < barh; i++) { p[col] = 255; p += ibuf->x * 4; } diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 955b4dba5e8..96a1776d763 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -1388,9 +1388,8 @@ static bool select_grouped_effect(Editing *ed, Sequence *actseq, const int chann Sequence *seq; bool changed = false; bool effects[SEQ_TYPE_MAX + 1]; - int i; - for (i = 0; i <= SEQ_TYPE_MAX; i++) { + for (int i = 0; i <= SEQ_TYPE_MAX; i++) { effects[i] = false; } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 688dce3c54e..2ae8d4cde7a 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2914,9 +2914,9 @@ typedef struct SetSelection { static int flatten_width(SpaceText *st, const char *str) { - int i, total = 0; + int total = 0; - for (i = 0; str[i]; i += BLI_str_utf8_size_safe(str + i)) { + for (int i = 0; str[i]; i += BLI_str_utf8_size_safe(str + i)) { if (str[i] == '\t') { total += st->tabnumber - total % st->tabnumber; } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index da44815b31a..f3300f21628 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -905,7 +905,7 @@ void ED_view3d_grid_steps(const Scene *scene, float r_grid_steps[STEPS_LEN]) { const void *usys; - int i, len; + int len; BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len); float grid_scale = v3d->grid; BLI_assert(STEPS_LEN >= len); @@ -918,6 +918,7 @@ void ED_view3d_grid_steps(const Scene *scene, grid_scale /= scene->unit.scale_length; + int i; for (i = 0; i < len; i++) { r_grid_steps[i] = (float)BKE_unit_scalar_get(usys, len - 1 - i) * grid_scale; } @@ -932,7 +933,7 @@ void ED_view3d_grid_steps(const Scene *scene, grid_scale /= powf(v3d->gridsubdiv, 3); } int subdiv = 1; - for (i = 0;; i++) { + for (int i = 0;; i++) { r_grid_steps[i] = grid_scale * subdiv; if (i == STEPS_LEN - 1) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index ab08c9a804a..8b9f0fdb972 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -333,10 +333,9 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) { Curve *cu = ob_act_eval->data; EditFont *ef = cu->editfont; - int i; zero_v3(lastofs); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { add_v2_v2(lastofs, ef->textcurs[i]); } mul_v2_fl(lastofs, 1.0f / 4.0f); @@ -4877,11 +4876,10 @@ static void calc_local_clipping(float clip_local[6][4], { BoundBox clipbb_local; float imat[4][4]; - int i; invert_m4_m4(imat, mat); - for (i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { mul_v3_m4v3(clipbb_local.vec[i], imat, clipbb->vec[i]); } diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 7562bf6f75c..4bc64a337f5 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1658,8 +1658,7 @@ static Base *object_mouse_select_menu(bContext *C, static bool selectbuffer_has_bones(const uint *buffer, const uint hits) { - uint i; - for (i = 0; i < hits; i++) { + for (uint i = 0; i < hits; i++) { if (buffer[(4 * i) + 3] & 0xFFFF0000) { return true; } @@ -2127,11 +2126,10 @@ static bool ed_object_select_pick(bContext *C, if (basact->object->type == OB_CAMERA) { MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, false); if (clip != NULL && oldbasact == basact) { - int i, hitresult; bool changed = false; - for (i = 0; i < hits; i++) { - hitresult = buffer[3 + (i * 4)]; + for (int i = 0; i < hits; i++) { + int hitresult = buffer[3 + (i * 4)]; /* if there's bundles in buffer select bundles first, * so non-camera elements should be ignored in buffer */ diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 54a3ebb8c0c..84eac3bbf8f 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -913,12 +913,11 @@ static void drawObjectConstraint(TransInfo *t) * Without drawing the first light, users have little clue what they are doing. */ short options = DRAWLIGHT; - int i; float tmp_axismtx[3][3]; FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; - for (i = 0; i < tc->data_len; i++, td++) { + for (int i = 0; i < tc->data_len; i++, td++) { float co[3]; float(*axismtx)[3]; diff --git a/source/blender/editors/transform/transform_convert_mask.c b/source/blender/editors/transform/transform_convert_mask.c index 6f34c49bdac..340f14c6800 100644 --- a/source/blender/editors/transform/transform_convert_mask.c +++ b/source/blender/editors/transform/transform_convert_mask.c @@ -138,12 +138,11 @@ static void MaskPointToTransData(Scene *scene, invert_m3_m3(parent_inverse_matrix, parent_matrix); if (is_prop_edit || is_sel_point) { - int i; tdm->point = point; copy_m3_m3(tdm->vec, bezt->vec); - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { copy_m3_m3(tdm->parent_matrix, parent_matrix); copy_m3_m3(tdm->parent_inverse_matrix, parent_inverse_matrix); diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 8d30dc19732..0ae167c117e 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -1231,17 +1231,16 @@ static PFace *p_face_add_fill(PChart *chart, PVert *v1, PVert *v2, PVert *v3) static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys) { - /* slight bias to prefer one edge over the other in case they are equal, so + /* Slight bias to prefer one edge over the other in case they are equal, so * that in symmetric models we choose the same split direction instead of - * depending on floating point errors to decide */ + * depending on floating point errors to decide. */ float bias = 1.0f + 1e-6f; float fac = len_v3v3(co[0], co[2]) * bias - len_v3v3(co[1], co[3]); PBool dir = (fac <= 0.0f); - /* the face exists check is there because of a special case: when - * two quads share three vertices, they can each be split into two - * triangles, resulting in two identical triangles. for example in - * suzanne's nose. */ + /* The face exists check is there because of a special case: + * when two quads share three vertices, they can each be split into two triangles, + * resulting in two identical triangles. For example in Suzanne's nose. */ if (dir) { if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3)) { return !dir; diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index bb50cd3744f..72dc610f3c8 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -93,6 +93,7 @@ set(SRC opengl/gl_context.cc opengl/gl_drawlist.cc opengl/gl_debug.cc + opengl/gl_debug_layer.cc opengl/gl_framebuffer.cc opengl/gl_immediate.cc opengl/gl_index_buffer.cc diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index c8d57a20a38..edaa84cdcf8 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -178,7 +178,7 @@ static bool detect_mip_render_workaround(void) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClear(GL_COLOR_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, 0); - glDrawBuffer(GL_BACK); + /* Read mip 1. If color is not the same as the clear_color, the rendering failed. */ glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA, GL_FLOAT, source_pix); bool enable_workaround = !equals_v4v4(clear_color, source_pix); @@ -207,11 +207,22 @@ static void detect_workarounds(void) printf(" version: %s\n\n", version); GCaps.depth_blitting_workaround = true; GCaps.mip_render_workaround = true; + GLContext::debug_layer_workaround = true; GLContext::unused_fb_slot_workaround = true; - GLContext::texture_copy_workaround = true; /* Turn off extensions. */ GLContext::base_instance_support = false; + GLContext::clear_texture_support = false; + GLContext::copy_image_support = false; + GLContext::debug_layer_support = false; + GLContext::direct_state_access_support = false; + GLContext::fixed_restart_index_support = false; + GLContext::multi_bind_support = false; + GLContext::multi_draw_indirect_support = false; + GLContext::shader_draw_parameters_support = false; GLContext::texture_cube_map_array_support = false; + GLContext::texture_filter_anisotropic_support = false; + GLContext::texture_gather_support = false; + GLContext::vertex_attrib_binding_support = false; return; } @@ -266,7 +277,7 @@ static void detect_workarounds(void) * covered since they only support GL 4.4 on windows. * This fixes some issues with workbench anti-aliasing on Win + Intel GPU. (see T76273) */ if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && !GLEW_VERSION_4_5) { - GLContext::texture_copy_workaround = true; + GLContext::copy_image_support = false; } /* Special fix for theses specific GPUs. * Without this workaround, blender crashes on startup. (see T72098) */ @@ -303,6 +314,11 @@ static void detect_workarounds(void) strstr(version, "Mesa 19.1") || strstr(version, "Mesa 19.2"))) { GLContext::unused_fb_slot_workaround = true; } + /* There is a bug on older Nvidia GPU where GL_ARB_texture_gather + * is reported to be supported but yield a compile error (see T55802). */ + if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) && !GLEW_VERSION_4_0) { + GLContext::texture_gather_support = false; + } /* dFdx/dFdy calculation factors, those are dependent on driver. */ if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY) && @@ -321,6 +337,15 @@ static void detect_workarounds(void) GLContext::derivative_signs[1] = 1.0; } } + + /* Disable multidraw if the base instance cannot be read. */ + if (GLContext::shader_draw_parameters_support == false) { + GLContext::multi_draw_indirect_support = false; + } + /* Enable our own incomplete debug layer if no other is available. */ + if (GLContext::debug_layer_support == false) { + GLContext::debug_layer_workaround = true; + } } /** Internal capabilities. */ @@ -330,10 +355,20 @@ GLint GLContext::max_ubo_size; GLint GLContext::max_ubo_binds; /** Extensions. */ bool GLContext::base_instance_support = false; +bool GLContext::clear_texture_support = false; +bool GLContext::copy_image_support = false; bool GLContext::debug_layer_support = false; +bool GLContext::direct_state_access_support = false; +bool GLContext::fixed_restart_index_support = false; +bool GLContext::multi_bind_support = false; +bool GLContext::multi_draw_indirect_support = false; +bool GLContext::shader_draw_parameters_support = false; bool GLContext::texture_cube_map_array_support = false; +bool GLContext::texture_filter_anisotropic_support = false; +bool GLContext::texture_gather_support = false; +bool GLContext::vertex_attrib_binding_support = false; /** Workarounds. */ -bool GLContext::texture_copy_workaround = false; +bool GLContext::debug_layer_workaround = false; bool GLContext::unused_fb_slot_workaround = false; float GLContext::derivative_signs[2] = {1.0f, 1.0f}; @@ -354,15 +389,26 @@ void GLBackend::capabilities_init(void) glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GLContext::max_ubo_binds); glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GLContext::max_ubo_size); GLContext::base_instance_support = GLEW_ARB_base_instance; + GLContext::clear_texture_support = GLEW_ARB_clear_texture; + GLContext::copy_image_support = GLEW_ARB_copy_image; + GLContext::debug_layer_support = GLEW_VERSION_4_3 || GLEW_KHR_debug || GLEW_ARB_debug_output; + GLContext::direct_state_access_support = GLEW_ARB_direct_state_access; + GLContext::fixed_restart_index_support = GLEW_ARB_ES3_compatibility; + GLContext::multi_bind_support = GLEW_ARB_multi_bind; + GLContext::multi_draw_indirect_support = GLEW_ARB_multi_draw_indirect; + GLContext::shader_draw_parameters_support = GLEW_ARB_shader_draw_parameters; GLContext::texture_cube_map_array_support = GLEW_ARB_texture_cube_map_array; - GLContext::debug_layer_support = (GLEW_VERSION_4_3 || GLEW_KHR_debug); + GLContext::texture_filter_anisotropic_support = GLEW_EXT_texture_filter_anisotropic; + GLContext::texture_gather_support = GLEW_ARB_texture_gather; + GLContext::vertex_attrib_binding_support = GLEW_ARB_vertex_attrib_binding; + + detect_workarounds(); + /* Disable this feature entirely when not debugging. */ if ((G.debug & G_DEBUG_GPU) == 0) { - /* Disable this feature entierly when not debugging. */ GLContext::debug_layer_support = false; + GLContext::debug_layer_workaround = false; } - - detect_workarounds(); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc index b25bafad6a3..ca627775e1f 100644 --- a/source/blender/gpu/opengl/gl_batch.cc +++ b/source/blender/gpu/opengl/gl_batch.cc @@ -307,7 +307,7 @@ void GLBatch::bind(int i_first) #if GPU_TRACK_INDEX_RANGE /* Can be removed if GL 4.3 is required. */ - if (!GLEW_ARB_ES3_compatibility && (elem != NULL)) { + if (!GLContext::fixed_restart_index_support && (elem != NULL)) { glPrimitiveRestartIndex(this->elem_()->restart_index()); } #endif @@ -324,7 +324,6 @@ void GLBatch::bind(int i_first) void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) { GL_CHECK_RESOURCES("Batch"); - GL_CHECK_ERROR("Batch Pre drawing"); this->bind(i_first); @@ -346,7 +345,6 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) glDrawElementsInstancedBaseVertex( gl_type, v_count, index_type, v_first_ofs, i_count, base_index); } - GL_CHECK_ERROR("Batch Post-drawing Indexed"); } else { #ifdef __APPLE__ @@ -361,7 +359,6 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) #ifdef __APPLE__ glEnable(GL_PRIMITIVE_RESTART); #endif - GL_CHECK_ERROR("Batch Post-drawing Non-indexed"); } } diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index 6b3b06ef12b..9c98953f469 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -74,6 +74,9 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list GHOST_DisposeRectangle(bounds); if (default_fbo != 0) { + /* Bind default framebuffer, otherwise state might be undefined because of + * detect_mip_render_workaround(). */ + glBindFramebuffer(GL_FRAMEBUFFER, default_fbo); front_left = new GLFrameBuffer("front_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h); back_left = new GLFrameBuffer("back_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h); } @@ -81,6 +84,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list front_left = new GLFrameBuffer("front_left", this, GL_FRONT_LEFT, 0, w, h); back_left = new GLFrameBuffer("back_left", this, GL_BACK_LEFT, 0, w, h); } + GLboolean supports_stereo_quad_buffer = GL_FALSE; glGetBooleanv(GL_STEREO, &supports_stereo_quad_buffer); if (supports_stereo_quad_buffer) { @@ -95,7 +99,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list active_fb = back_left; static_cast<GLStateManager *>(state_manager)->active_fb = static_cast<GLFrameBuffer *>( - back_left); + active_fb); } GLContext::~GLContext() diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 10ae396d138..9822c842ce7 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -62,10 +62,20 @@ class GLContext : public Context { static GLint max_ubo_binds; /** Extensions. */ static bool base_instance_support; + static bool clear_texture_support; + static bool copy_image_support; static bool debug_layer_support; + static bool direct_state_access_support; + static bool fixed_restart_index_support; + static bool multi_bind_support; + static bool multi_draw_indirect_support; + static bool shader_draw_parameters_support; static bool texture_cube_map_array_support; + static bool texture_filter_anisotropic_support; + static bool texture_gather_support; + static bool vertex_attrib_binding_support; /** Workarounds. */ - static bool texture_copy_workaround; + static bool debug_layer_workaround; static bool unused_fb_slot_workaround; static float derivative_signs[2]; diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index 468d1514d60..de88fdc154c 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -112,17 +112,13 @@ static void APIENTRY debug_callback(GLenum UNUSED(source), #undef APIENTRY +/* This function needs to be called once per context. */ void init_gl_callbacks(void) { -#ifdef __APPLE__ - fprintf(stderr, "GPUDebug: OpenGL debug callback is not available on Apple\n"); - return; -#endif /* not Apple */ - char msg[256] = ""; const char format[] = "Successfully hooked OpenGL debug callback using %s"; - if (GLContext::debug_layer_support) { + if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { SNPRINTF(msg, format, GLEW_VERSION_4_3 ? "OpenGL 4.3" : "KHR_debug extension"); glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); @@ -148,7 +144,8 @@ void init_gl_callbacks(void) msg); } else { - fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback\n"); + fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback. Use fallback debug layer.\n"); + init_debug_layer(); } } @@ -243,4 +240,68 @@ void raise_gl_error(const char *info) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Object Label + * + * Useful for debugging through renderdoc. Only defined if using --debug-gpu. + * Make sure to bind the object first so that it gets defined by the GL implementation. + * \{ */ + +static const char *to_str_prefix(GLenum type) +{ + switch (type) { + case GL_FRAGMENT_SHADER: + case GL_GEOMETRY_SHADER: + case GL_VERTEX_SHADER: + case GL_SHADER: + case GL_PROGRAM: + return "SHD-"; + case GL_SAMPLER: + return "SAM-"; + case GL_TEXTURE: + return "TEX-"; + case GL_FRAMEBUFFER: + return "FBO-"; + case GL_VERTEX_ARRAY: + return "VAO-"; + case GL_UNIFORM_BUFFER: + return "UBO-"; + case GL_BUFFER: + return "BUF-"; + default: + return ""; + } +} +static const char *to_str_suffix(GLenum type) +{ + switch (type) { + case GL_FRAGMENT_SHADER: + return "-Frag"; + case GL_GEOMETRY_SHADER: + return "-Geom"; + case GL_VERTEX_SHADER: + return "-Vert"; + default: + return ""; + } +} + +void object_label(GLenum type, GLuint object, const char *name) +{ + if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) { + char label[64]; + SNPRINTF(label, "%s%s%s", to_str_prefix(type), name, to_str_suffix(type)); + /* Small convenience for caller. */ + if (ELEM(type, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER, GL_VERTEX_SHADER)) { + type = GL_SHADER; + } + if (ELEM(type, GL_UNIFORM_BUFFER)) { + type = GL_BUFFER; + } + glObjectLabel(type, object, -1, label); + } +} + +/** \} */ + } // namespace blender::gpu::debug diff --git a/source/blender/gpu/opengl/gl_debug.hh b/source/blender/gpu/opengl/gl_debug.hh index 5537147d0fe..892fb1d2ddb 100644 --- a/source/blender/gpu/opengl/gl_debug.hh +++ b/source/blender/gpu/opengl/gl_debug.hh @@ -20,16 +20,60 @@ #pragma once -namespace blender { -namespace gpu { -namespace debug { +#include "gl_context.hh" -/* Enabled on MacOS by default since there is no support for debug callbacks. */ -#if defined(DEBUG) && defined(__APPLE__) -# define GL_CHECK_ERROR(info) debug::check_gl_error(info) -#else -# define GL_CHECK_ERROR(info) -#endif +#include "glew-mx.h" + +/* Manual line breaks for readability. */ +/* clang-format off */ +#define _VA_ARG_LIST1(t) t +#define _VA_ARG_LIST2(t, a) t a +#define _VA_ARG_LIST4(t, a, b, c) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST2(b, c) +#define _VA_ARG_LIST6(t, a, b, c, d, e) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST4(b, c, d, e) +#define _VA_ARG_LIST8(t, a, b, c, d, e, f, g) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST6(b, c, d, e, f, g) +#define _VA_ARG_LIST10(t, a, b, c, d, e, f, g, h, i) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST8(b, c, d, e, f, g, h, i) +#define _VA_ARG_LIST12(t, a, b, c, d, e, f, g, h, i, j, k) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST10(b, c, d, e, f, g, h, i, j, k) +#define _VA_ARG_LIST14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST12(b, c, d, e, f, g, h, i, j, k, l, m) +#define _VA_ARG_LIST16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST14(b, c, d, e, f, g, h, i, j, k, l, m, o, p) +#define _VA_ARG_LIST18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) +#define _VA_ARG_LIST20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) +#define _VA_ARG_LIST22(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST20(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) +#define ARG_LIST(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST, __VA_ARGS__) + +#define _VA_ARG_LIST_CALL1(t) +#define _VA_ARG_LIST_CALL2(t, a) a +#define _VA_ARG_LIST_CALL4(t, a, b, c) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL2(b, c) +#define _VA_ARG_LIST_CALL6(t, a, b, c, d, e) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL4(b, c, d, e) +#define _VA_ARG_LIST_CALL8(t, a, b, c, d, e, f, g) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL6(b, c, d, e, f, g) +#define _VA_ARG_LIST_CALL10(t, a, b, c, d, e, f, g, h, i) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL8(b, c, d, e, f, g, h, i) +#define _VA_ARG_LIST_CALL12(t, a, b, c, d, e, f, g, h, i, j, k) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL10(b, c, d, e, f, g, h, i, j, k) +#define _VA_ARG_LIST_CALL14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL12(b, c, d, e, f, g, h, i, j, k, l, m) +#define _VA_ARG_LIST_CALL16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL14(b, c, d, e, f, g, h, i, j, k, l, m, o, p) +#define _VA_ARG_LIST_CALL18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) +#define _VA_ARG_LIST_CALL20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) +#define _VA_ARG_LIST_CALL22(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL20(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) +#define ARG_LIST_CALL(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST_CALL, __VA_ARGS__) +/* clang-format on */ #ifdef DEBUG # define GL_CHECK_RESOURCES(info) debug::check_gl_resources(info) @@ -37,11 +81,52 @@ namespace debug { # define GL_CHECK_RESOURCES(info) #endif +namespace blender { +namespace gpu { +namespace debug { + void raise_gl_error(const char *info); void check_gl_error(const char *info); void check_gl_resources(const char *info); void init_gl_callbacks(void); +void init_debug_layer(void); + +void object_label(GLenum type, GLuint object, const char *name); + } // namespace debug + +#define DEBUG_FUNC_OVERRIDE(func, ...) \ + inline void func(ARG_LIST(__VA_ARGS__)) \ + { \ + if (GLContext::debug_layer_workaround) { \ + debug::check_gl_error("generated before " #func); \ + ::func(ARG_LIST_CALL(__VA_ARGS__)); \ + debug::check_gl_error("" #func); \ + } \ + else { \ + ::func(ARG_LIST_CALL(__VA_ARGS__)); \ + } \ + } + +/* Avoid very long declarations. */ +/* clang-format off */ +DEBUG_FUNC_OVERRIDE(glClear, GLbitfield, mask); +DEBUG_FUNC_OVERRIDE(glDeleteTextures, GLsizei, n, const GLuint *, textures); +DEBUG_FUNC_OVERRIDE(glDrawArrays, GLenum, mode, GLint, first, GLsizei, count); +DEBUG_FUNC_OVERRIDE(glFinish, void); +DEBUG_FUNC_OVERRIDE(glFlush, void); +DEBUG_FUNC_OVERRIDE(glGenTextures, GLsizei, n, GLuint *, textures); +DEBUG_FUNC_OVERRIDE(glGetTexImage, GLenum, target, GLint, level, GLenum, format, GLenum, type, void *, pixels); +DEBUG_FUNC_OVERRIDE(glReadBuffer, GLenum, mode); +DEBUG_FUNC_OVERRIDE(glReadPixels, GLint, x, GLint, y, GLsizei, width, GLsizei, height, GLenum, format, GLenum, type, void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexImage1D, GLenum, target, GLint, level, GLint, internalformat, GLsizei, width, GLint, border, GLenum, format, GLenum, type, const void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexImage2D, GLenum, target, GLint, level, GLint, internalformat, GLsizei, width, GLsizei, height, GLint, border, GLenum, format, GLenum, type, const void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexParameteri, GLenum, target, GLenum, pname, GLint, param); +DEBUG_FUNC_OVERRIDE(glTexParameteriv, GLenum, target, GLenum, pname, const GLint *, params); +DEBUG_FUNC_OVERRIDE(glTexSubImage1D, GLenum, target, GLint, level, GLint, xoffset, GLsizei, width, GLenum, format, GLenum, type, const void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexSubImage2D, GLenum, target, GLint, level, GLint, xoffset, GLint, yoffset, GLsizei, width, GLsizei, height, GLenum, format, GLenum, type, const void *, pixels); +/* clang-format on */ + } // namespace gpu } // namespace blender diff --git a/source/blender/gpu/opengl/gl_debug_layer.cc b/source/blender/gpu/opengl/gl_debug_layer.cc new file mode 100644 index 00000000000..801cb9dbfbd --- /dev/null +++ b/source/blender/gpu/opengl/gl_debug_layer.cc @@ -0,0 +1,165 @@ +/* + * 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) 2005 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Implement our own subset of KHR_debug extension. + * We override the functions pointers by our own implementation that just checks glGetError. + */ + +#include "BLI_utildefines.h" + +#include "glew-mx.h" + +#include "gl_debug.hh" + +typedef void *GPUvoidptr; + +#define GPUvoidptr_set void *ret = +#define GPUvoidptr_ret return ret + +#define GLboolean_set GLboolean ret = +#define GLboolean_ret return ret + +#define void_set +#define void_ret + +#define DEBUG_FUNC_DECLARE(pfn, rtn_type, fn, ...) \ + pfn real_##fn; \ + static rtn_type GLAPIENTRY debug_##fn(ARG_LIST(__VA_ARGS__)) \ + { \ + debug::check_gl_error("generated before " #fn); \ + rtn_type##_set real_##fn(ARG_LIST_CALL(__VA_ARGS__)); \ + debug::check_gl_error("" #fn); \ + rtn_type##_ret; \ + } + +namespace blender::gpu::debug { + +/* List of wrapped functions. We dont have to support all of them. + * Some functions might be declared as extern in GLEW. We cannot override them in this case. + * Keep the list in alphabetical order. */ + +/* Avoid very long declarations. */ +/* clang-format off */ +DEBUG_FUNC_DECLARE(PFNGLBEGINQUERYPROC, void, glBeginQuery, GLenum, target, GLuint, id); +DEBUG_FUNC_DECLARE(PFNGLBEGINTRANSFORMFEEDBACKPROC, void, glBeginTransformFeedback, GLenum, primitiveMode); +DEBUG_FUNC_DECLARE(PFNGLBINDBUFFERBASEPROC, void, glBindBufferBase, GLenum, target, GLuint, index, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLBINDBUFFERPROC, void, glBindBuffer, GLenum, target, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLBINDFRAMEBUFFERPROC, void, glBindFramebuffer, GLenum, target, GLuint, framebuffer); +DEBUG_FUNC_DECLARE(PFNGLBINDSAMPLERPROC, void, glBindSampler, GLuint, unit, GLuint, sampler); +DEBUG_FUNC_DECLARE(PFNGLBINDVERTEXARRAYPROC, void, glBindVertexArray, GLuint, array); +DEBUG_FUNC_DECLARE(PFNGLBLITFRAMEBUFFERPROC, void, glBlitFramebuffer, GLint, srcX0, GLint, srcY0, GLint, srcX1, GLint, srcY1, GLint, dstX0, GLint, dstY0, GLint, dstX1, GLint, dstY1, GLbitfield, mask, GLenum, filter); +DEBUG_FUNC_DECLARE(PFNGLBUFFERDATAPROC, void, glBufferData, GLenum, target, GLsizeiptr, size, const void *, data, GLenum, usage); +DEBUG_FUNC_DECLARE(PFNGLBUFFERSUBDATAPROC, void, glBufferSubData, GLenum, target, GLintptr, offset, GLsizeiptr, size, const void *, data); +DEBUG_FUNC_DECLARE(PFNGLDELETEBUFFERSPROC, void, glDeleteBuffers, GLsizei, n, const GLuint *, buffers); +DEBUG_FUNC_DECLARE(PFNGLDELETEFRAMEBUFFERSPROC, void, glDeleteFramebuffers, GLsizei, n, const GLuint*, framebuffers); +DEBUG_FUNC_DECLARE(PFNGLDELETEPROGRAMPROC, void, glDeleteProgram, GLuint, program); +DEBUG_FUNC_DECLARE(PFNGLDELETEQUERIESPROC, void, glDeleteQueries, GLsizei, n, const GLuint *, ids); +DEBUG_FUNC_DECLARE(PFNGLDELETESAMPLERSPROC, void, glDeleteSamplers, GLsizei, count, const GLuint *, samplers); +DEBUG_FUNC_DECLARE(PFNGLDELETESHADERPROC, void, glDeleteShader, GLuint, shader); +DEBUG_FUNC_DECLARE(PFNGLDELETEVERTEXARRAYSPROC, void, glDeleteVertexArrays, GLsizei, n, const GLuint *, arrays); +DEBUG_FUNC_DECLARE(PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC, void, glDrawArraysInstancedBaseInstance, GLenum, mode, GLint, first, GLsizei, count, GLsizei, primcount, GLuint, baseinstance); +DEBUG_FUNC_DECLARE(PFNGLDRAWARRAYSINSTANCEDPROC, void, glDrawArraysInstanced, GLenum, mode, GLint, first, GLsizei, count, GLsizei, primcount); +DEBUG_FUNC_DECLARE(PFNGLDRAWBUFFERSPROC, void, glDrawBuffers, GLsizei, n, const GLenum*, bufs); +DEBUG_FUNC_DECLARE(PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC, void, glDrawElementsInstancedBaseVertexBaseInstance, GLenum, mode, GLsizei, count, GLenum, type, const void *, indices, GLsizei, primcount, GLint, basevertex, GLuint, baseinstance); +DEBUG_FUNC_DECLARE(PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC, void, glDrawElementsInstancedBaseVertex, GLenum, mode, GLsizei, count, GLenum, type, const void *, indices, GLsizei, instancecount, GLint, basevertex); +DEBUG_FUNC_DECLARE(PFNGLENDQUERYPROC, void, glEndQuery, GLenum, target); +DEBUG_FUNC_DECLARE(PFNGLENDTRANSFORMFEEDBACKPROC, void, glEndTransformFeedback, void); +DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTURE2DPROC, void, glFramebufferTexture2D, GLenum, target, GLenum, attachment, GLenum, textarget, GLuint, texture, GLint, level); +DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTURELAYERPROC, void, glFramebufferTextureLayer, GLenum, target, GLenum, attachment, GLuint, texture, GLint, level, GLint, layer); +DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTUREPROC, void, glFramebufferTexture, GLenum, target, GLenum, attachment, GLuint, texture, GLint, level); +DEBUG_FUNC_DECLARE(PFNGLGENBUFFERSPROC, void, glGenBuffers, GLsizei, n, GLuint *, buffers); +DEBUG_FUNC_DECLARE(PFNGLGENERATEMIPMAPPROC, void, glGenerateMipmap, GLenum, target); +DEBUG_FUNC_DECLARE(PFNGLGENERATETEXTUREMIPMAPPROC, void, glGenerateTextureMipmap, GLuint, texture); +DEBUG_FUNC_DECLARE(PFNGLGENFRAMEBUFFERSPROC, void, glGenFramebuffers, GLsizei, n, GLuint *, framebuffers); +DEBUG_FUNC_DECLARE(PFNGLGENQUERIESPROC, void, glGenQueries, GLsizei, n, GLuint *, ids); +DEBUG_FUNC_DECLARE(PFNGLGENSAMPLERSPROC, void, glGenSamplers, GLsizei, n, GLuint *, samplers); +DEBUG_FUNC_DECLARE(PFNGLGENVERTEXARRAYSPROC, void, glGenVertexArrays, GLsizei, n, GLuint *, arrays); +DEBUG_FUNC_DECLARE(PFNGLLINKPROGRAMPROC, void, glLinkProgram, GLuint, program); +DEBUG_FUNC_DECLARE(PFNGLMAPBUFFERRANGEPROC, GPUvoidptr, glMapBufferRange, GLenum, target, GLintptr, offset, GLsizeiptr, length, GLbitfield, access); +DEBUG_FUNC_DECLARE(PFNGLTEXBUFFERPROC, void, glTexBuffer, GLenum, target, GLenum, internalFormat, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLTEXIMAGE3DPROC, void, glTexImage3D, GLenum, target, GLint, level, GLint, internalFormat, GLsizei, width, GLsizei, height, GLsizei, depth, GLint, border, GLenum, format, GLenum, type, const GLvoid *,pixels); +DEBUG_FUNC_DECLARE(PFNGLTEXSUBIMAGE3DPROC, void, glTexSubImage3D, GLenum, target, GLint, level, GLint, xoffset, GLint, yoffset, GLint, zoffset, GLsizei, width, GLsizei, height, GLsizei, depth, GLenum, format, GLenum, type, const GLvoid *, pixels); +DEBUG_FUNC_DECLARE(PFNGLTEXTUREBUFFERPROC, void, glTextureBuffer, GLuint, texture, GLenum, internalformat, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLUNMAPBUFFERPROC, GLboolean, glUnmapBuffer, GLenum, target); +DEBUG_FUNC_DECLARE(PFNGLUSEPROGRAMPROC, void, glUseProgram, GLuint, program); +/* clang-format on */ + +#undef DEBUG_FUNC_DECLARE + +/* Init a fallback layer (to KHR_debug) that covers only some functions. + * We override the functions pointers by our own implementation that just checks glGetError. + * Some additional functions (not overridable) are covered inside the header using wrappers. */ +void init_debug_layer(void) +{ +#define DEBUG_WRAP(function) \ + do { \ + real_##function = ::function; \ + ::function = &debug_##function; \ + } while (0) + + DEBUG_WRAP(glBeginQuery); + DEBUG_WRAP(glBeginTransformFeedback); + DEBUG_WRAP(glBindBuffer); + DEBUG_WRAP(glBindBufferBase); + DEBUG_WRAP(glBindFramebuffer); + DEBUG_WRAP(glBindSampler); + DEBUG_WRAP(glBindVertexArray); + DEBUG_WRAP(glBlitFramebuffer); + DEBUG_WRAP(glBufferData); + DEBUG_WRAP(glBufferSubData); + DEBUG_WRAP(glDeleteBuffers); + DEBUG_WRAP(glDeleteFramebuffers); + DEBUG_WRAP(glDeleteProgram); + DEBUG_WRAP(glDeleteQueries); + DEBUG_WRAP(glDeleteSamplers); + DEBUG_WRAP(glDeleteShader); + DEBUG_WRAP(glDeleteVertexArrays); + DEBUG_WRAP(glDrawArraysInstanced); + DEBUG_WRAP(glDrawArraysInstancedBaseInstance); + DEBUG_WRAP(glDrawBuffers); + DEBUG_WRAP(glDrawElementsInstancedBaseVertex); + DEBUG_WRAP(glDrawElementsInstancedBaseVertexBaseInstance); + DEBUG_WRAP(glEndQuery); + DEBUG_WRAP(glEndTransformFeedback); + DEBUG_WRAP(glFramebufferTexture); + DEBUG_WRAP(glFramebufferTexture2D); + DEBUG_WRAP(glFramebufferTextureLayer); + DEBUG_WRAP(glGenBuffers); + DEBUG_WRAP(glGenerateMipmap); + DEBUG_WRAP(glGenerateTextureMipmap); + DEBUG_WRAP(glGenFramebuffers); + DEBUG_WRAP(glGenQueries); + DEBUG_WRAP(glGenSamplers); + DEBUG_WRAP(glGenVertexArrays); + DEBUG_WRAP(glLinkProgram); + DEBUG_WRAP(glMapBufferRange); + DEBUG_WRAP(glTexBuffer); + DEBUG_WRAP(glTexImage3D); + DEBUG_WRAP(glTexSubImage3D); + DEBUG_WRAP(glTextureBuffer); + DEBUG_WRAP(glUnmapBuffer); + DEBUG_WRAP(glUseProgram); + +#undef DEBUG_WRAP +} + +} // namespace blender::gpu::debug
\ No newline at end of file diff --git a/source/blender/gpu/opengl/gl_drawlist.cc b/source/blender/gpu/opengl/gl_drawlist.cc index 6e3b1107b9c..990e1a8014b 100644 --- a/source/blender/gpu/opengl/gl_drawlist.cc +++ b/source/blender/gpu/opengl/gl_drawlist.cc @@ -41,8 +41,6 @@ #include <limits.h> -#define USE_MULTI_DRAW_INDIRECT 1 - using namespace blender::gpu; typedef struct GLDrawCommand { @@ -75,8 +73,7 @@ GLDrawList::GLDrawList(int length) data_size_ = 0; data_ = NULL; - if (USE_MULTI_DRAW_INDIRECT && GLEW_ARB_multi_draw_indirect && - GLContext::base_instance_support) { + if (GLContext::multi_draw_indirect_support) { /* Alloc the biggest possible command list, which is indexed. */ buffer_size_ = sizeof(GLDrawCommandIndexed) * length; } diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index bfc8a2f74eb..1578c5fa619 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -26,10 +26,12 @@ #include "GPU_capabilities.h" #include "gl_backend.hh" -#include "gl_framebuffer.hh" +#include "gl_debug.hh" #include "gl_state.hh" #include "gl_texture.hh" +#include "gl_framebuffer.hh" + namespace blender::gpu { /* -------------------------------------------------------------------- */ @@ -63,10 +65,8 @@ GLFrameBuffer::GLFrameBuffer( viewport_[2] = scissor_[2] = w; viewport_[3] = scissor_[3] = h; - if (fbo_id_ && GLContext::debug_layer_support) { - char sh_name[32]; - SNPRINTF(sh_name, "FrameBuffer-%s", name); - glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name); + if (fbo_id_) { + debug::object_label(GL_FRAMEBUFFER, fbo_id_, name_); } } @@ -97,14 +97,11 @@ void GLFrameBuffer::init(void) context_ = GLContext::get(); state_manager_ = static_cast<GLStateManager *>(context_->state_manager); glGenFramebuffers(1, &fbo_id_); + /* Binding before setting the label is needed on some drivers. + * This is not an issue since we call this function only before binding. */ + glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "FrameBuffer-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_); - glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name); - } + debug::object_label(GL_FRAMEBUFFER, fbo_id_, name_); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_immediate.cc b/source/blender/gpu/opengl/gl_immediate.cc index 7afbbf9965c..fd31d77cc80 100644 --- a/source/blender/gpu/opengl/gl_immediate.cc +++ b/source/blender/gpu/opengl/gl_immediate.cc @@ -60,11 +60,9 @@ GLImmediate::GLImmediate() glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); - if (GLContext::debug_layer_support) { - glObjectLabel(GL_VERTEX_ARRAY, vao_id_, -1, "VAO-Immediate"); - glObjectLabel(GL_BUFFER, buffer.vbo_id, -1, "VBO-ImmediateBuffer"); - glObjectLabel(GL_BUFFER, buffer_strict.vbo_id, -1, "VBO-ImmediateBufferStrict"); - } + debug::object_label(GL_VERTEX_ARRAY, vao_id_, "Immediate"); + debug::object_label(GL_BUFFER, buffer.vbo_id, "ImmediateVbo"); + debug::object_label(GL_BUFFER, buffer_strict.vbo_id, "ImmediateVboStrict"); } GLImmediate::~GLImmediate() @@ -89,7 +87,6 @@ uchar *GLImmediate::begin() const size_t available_bytes = buffer_size() - buffer_offset(); GL_CHECK_RESOURCES("Immediate"); - GL_CHECK_ERROR("Immediate Pre-Begin"); glBindBuffer(GL_ARRAY_BUFFER, vbo_id()); @@ -133,7 +130,6 @@ uchar *GLImmediate::begin() } void *data = glMapBufferRange(GL_ARRAY_BUFFER, buffer_offset(), bytes_needed, access); BLI_assert(data != NULL); - GL_CHECK_ERROR("Immediate Post-Begin"); bytes_mapped_ = bytes_needed; return (uchar *)data; @@ -155,8 +151,6 @@ void GLImmediate::end(void) } glUnmapBuffer(GL_ARRAY_BUFFER); - GL_CHECK_ERROR("Immediate Post-Unmap"); - if (vertex_len > 0) { GLContext::get()->state_manager->apply_state(); @@ -180,8 +174,6 @@ void GLImmediate::end(void) * They are not required so just comment them. (T55722) */ // glBindBuffer(GL_ARRAY_BUFFER, 0); // glBindVertexArray(0); - - GL_CHECK_ERROR("Immediate Post-drawing"); } buffer_offset() += buffer_bytes_used; diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 4314ecfa6be..c400f218f5a 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -28,6 +28,7 @@ #include "GPU_platform.h" #include "gl_backend.hh" +#include "gl_debug.hh" #include "gl_vertex_buffer.hh" #include "gl_shader.hh" @@ -48,11 +49,7 @@ GLShader::GLShader(const char *name) : Shader(name) #endif shader_program_ = glCreateProgram(); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "ShaderProgram-%s", name); - glObjectLabel(GL_PROGRAM, shader_program_, -1, sh_name); - } + debug::object_label(GL_PROGRAM, shader_program_, name); } GLShader::~GLShader(void) @@ -88,25 +85,15 @@ char *GLShader::glsl_patch_get(void) /* Enable extensions for features that are not part of our base GLSL version * don't use an extension for something already available! */ - if (GLEW_ARB_texture_gather) { - /* There is a bug on older Nvidia GPU where GL_ARB_texture_gather - * is reported to be supported but yield a compile error (see T55802). */ - if (!GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) || GLEW_VERSION_4_0) { - STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n"); - - /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the - * shader so double check the preprocessor define (see T56544). */ - if (!GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) && !GLEW_VERSION_4_0) { - STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n"); - STR_CONCAT(patch, slen, "# define GPU_ARB_texture_gather\n"); - STR_CONCAT(patch, slen, "#endif\n"); - } - else { - STR_CONCAT(patch, slen, "#define GPU_ARB_texture_gather\n"); - } - } + if (GLContext::texture_gather_support) { + STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n"); + /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the + * shader so double check the preprocessor define (see T56544). */ + STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n"); + STR_CONCAT(patch, slen, "# define GPU_ARB_texture_gather\n"); + STR_CONCAT(patch, slen, "#endif\n"); } - if (GLEW_ARB_shader_draw_parameters) { + if (GLContext::shader_draw_parameters_support) { STR_CONCAT(patch, slen, "#extension GL_ARB_shader_draw_parameters : enable\n"); STR_CONCAT(patch, slen, "#define GPU_ARB_shader_draw_parameters\n"); } @@ -163,21 +150,7 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *> return 0; } - if (GLContext::debug_layer_support) { - char sh_name[64]; - switch (gl_stage) { - case GL_VERTEX_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "VertShader-%s", name); - break; - case GL_GEOMETRY_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "GeomShader-%s", name); - break; - case GL_FRAGMENT_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "FragShader-%s", name); - break; - } - glObjectLabel(GL_SHADER, shader, -1, sh_name); - } + debug::object_label(gl_stage, shader, name); glAttachShader(shader_program_, shader); return shader; diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc index 6dcb56288e8..03762edac93 100644 --- a/source/blender/gpu/opengl/gl_state.cc +++ b/source/blender/gpu/opengl/gl_state.cc @@ -30,6 +30,7 @@ #include "glew-mx.h" #include "gl_context.hh" +#include "gl_debug.hh" #include "gl_framebuffer.hh" #include "gl_texture.hh" @@ -55,7 +56,7 @@ GLStateManager::GLStateManager(void) : GPUStateManager() glPrimitiveRestartIndex((GLuint)0xFFFFFFFF); /* TODO: Should become default. But needs at least GL 4.3 */ - if (GLEW_ARB_ES3_compatibility) { + if (GLContext::fixed_restart_index_support) { /* Takes precedence over #GL_PRIMITIVE_RESTART. */ glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); } @@ -453,7 +454,6 @@ void GLStateManager::texture_bind(Texture *tex_, eGPUSamplerState sampler_type, /* Bind the texture to slot 0 for editing purpose. Used by legacy pipeline. */ void GLStateManager::texture_bind_temp(GLTexture *tex) { - // BLI_assert(!GLEW_ARB_direct_state_access); glActiveTexture(GL_TEXTURE0); glBindTexture(tex->target_, tex->tex_id_); /* Will reset the first texture that was originally bound to slot 0 back before drawing. */ @@ -505,7 +505,7 @@ void GLStateManager::texture_bind_apply(void) int last = 64 - bitscan_reverse_uint64(dirty_bind); int count = last - first; - if (GLEW_ARB_multi_bind) { + if (GLContext::multi_bind_support) { glBindTextures(first, count, textures_ + first); glBindSamplers(first, count, samplers_ + first); } diff --git a/source/blender/gpu/opengl/gl_state.hh b/source/blender/gpu/opengl/gl_state.hh index db9b9721ad5..fb2ed3403f7 100644 --- a/source/blender/gpu/opengl/gl_state.hh +++ b/source/blender/gpu/opengl/gl_state.hh @@ -42,8 +42,8 @@ class GLTexture; **/ class GLStateManager : public GPUStateManager { public: - /** Anothter reference to tje active framebuffer. */ - GLFrameBuffer *active_fb; + /** Anothter reference to the active framebuffer. */ + GLFrameBuffer *active_fb = nullptr; private: /** Current state of the GL implementation. Avoids resetting the whole state for every change. */ diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc index ec08b736af2..ef4b2d1d4d3 100644 --- a/source/blender/gpu/opengl/gl_texture.cc +++ b/source/blender/gpu/opengl/gl_texture.cc @@ -89,21 +89,14 @@ bool GLTexture::init_internal(void) this->ensure_mipmaps(0); /* Avoid issue with incomplete textures. */ - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureParameteri(tex_id_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } else { glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "Texture-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); - } - - GL_CHECK_ERROR("Post-texture creation"); + debug::object_label(GL_TEXTURE, tex_id_, name_); return true; } @@ -118,21 +111,15 @@ bool GLTexture::init_internal(GPUVertBuf *vbo) GLenum internal_format = to_gl_internal_format(format_); - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureBuffer(tex_id_, internal_format, gl_vbo->vbo_id_); } else { glTexBuffer(target_, internal_format, gl_vbo->vbo_id_); } - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "Texture-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); - } + debug::object_label(GL_TEXTURE, tex_id_, name_); - GL_CHECK_ERROR("Post-texture buffer creation"); return true; } @@ -193,8 +180,6 @@ void GLTexture::ensure_mipmaps(int miplvl) break; } } - - GL_CHECK_ERROR("Post-mipmap creation"); } this->mip_range_set(0, mipmaps_); @@ -240,7 +225,6 @@ void GLTexture::update_sub_direct_state_access( break; } } - GL_CHECK_ERROR("Post-update_sub_direct_state_access"); } void GLTexture::update_sub( @@ -260,8 +244,8 @@ void GLTexture::update_sub( GLenum gl_format = to_gl_data_format(format_); GLenum gl_type = to_gl(type); - /* Some drivers have issues with cubemap & glTextureSubImage3D even if it correct. */ - if (GLEW_ARB_direct_state_access && (type_ != GPU_TEXTURE_CUBE)) { + /* Some drivers have issues with cubemap & glTextureSubImage3D even if it is correct. */ + if (GLContext::direct_state_access_support && (type_ != GPU_TEXTURE_CUBE)) { this->update_sub_direct_state_access(mip, offset, extent, gl_format, gl_type, data); return; } @@ -304,8 +288,6 @@ void GLTexture::update_sub( break; } } - - GL_CHECK_ERROR("Post-update_sub"); } /** This will create the mipmap images and populate them with filtered data from base level. @@ -324,7 +306,7 @@ void GLTexture::generate_mipmap(void) } /* Downsample from mip 0 using implementation. */ - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glGenerateTextureMipmap(tex_id_); } else { @@ -337,7 +319,7 @@ void GLTexture::clear(eGPUDataFormat data_format, const void *data) { BLI_assert(validate_data_format(format_, data_format)); - if (GLEW_ARB_clear_texture && !(G.debug & G_DEBUG_GPU_FORCE_WORKAROUNDS)) { + if (GLContext::clear_texture_support) { int mip = 0; GLenum gl_format = to_gl_data_format(format_); GLenum gl_type = to_gl(data_format); @@ -366,8 +348,7 @@ void GLTexture::copy_to(Texture *dst_) /* TODO support array / 3D textures. */ BLI_assert(dst->d_ == 0); - if (GLEW_ARB_copy_image && !GLContext::texture_copy_workaround) { - /* Opengl 4.3 */ + if (GLContext::copy_image_support) { int mip = 0; /* NOTE: mip_size_get() won't override any dimension that is equal to 0. */ int extent[3] = {1, 1, 1}; @@ -403,7 +384,7 @@ void *GLTexture::read(int mip, eGPUDataFormat type) GLenum gl_format = to_gl_data_format(format_); GLenum gl_type = to_gl(type); - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glGetTextureImage(tex_id_, mip, gl_format, gl_type, texture_size, data); } else { @@ -434,7 +415,7 @@ void GLTexture::swizzle_set(const char swizzle[4]) (GLint)swizzle_to_gl(swizzle[1]), (GLint)swizzle_to_gl(swizzle[2]), (GLint)swizzle_to_gl(swizzle[3])}; - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureParameteriv(tex_id_, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle); } else { @@ -448,7 +429,7 @@ void GLTexture::mip_range_set(int min, int max) BLI_assert(min <= max && min >= 0 && max <= mipmaps_); mip_min_ = min; mip_max_ = max; - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureParameteri(tex_id_, GL_TEXTURE_BASE_LEVEL, min); glTextureParameteri(tex_id_, GL_TEXTURE_MAX_LEVEL, max); } @@ -510,22 +491,20 @@ void GLTexture::samplers_init(void) * - GL_TEXTURE_LOD_BIAS is 0.0f. **/ - if (GLContext::debug_layer_support) { - char sampler_name[128]; - SNPRINTF(sampler_name, - "Sampler%s%s%s%s%s%s%s%s%s%s", - (state == GPU_SAMPLER_DEFAULT) ? "_default" : "", - (state & GPU_SAMPLER_FILTER) ? "_filter" : "", - (state & GPU_SAMPLER_MIPMAP) ? "_mipmap" : "", - (state & GPU_SAMPLER_REPEAT) ? "_repeat-" : "", - (state & GPU_SAMPLER_REPEAT_S) ? "S" : "", - (state & GPU_SAMPLER_REPEAT_T) ? "T" : "", - (state & GPU_SAMPLER_REPEAT_R) ? "R" : "", - (state & GPU_SAMPLER_CLAMP_BORDER) ? "_clamp_border" : "", - (state & GPU_SAMPLER_COMPARE) ? "_compare" : "", - (state & GPU_SAMPLER_ANISO) ? "_aniso" : ""); - glObjectLabel(GL_SAMPLER, samplers_[i], -1, sampler_name); - } + char sampler_name[128] = "\0\0"; + SNPRINTF(sampler_name, + "%s%s%s%s%s%s%s%s%s%s", + (state == GPU_SAMPLER_DEFAULT) ? "_default" : "", + (state & GPU_SAMPLER_FILTER) ? "_filter" : "", + (state & GPU_SAMPLER_MIPMAP) ? "_mipmap" : "", + (state & GPU_SAMPLER_REPEAT) ? "_repeat-" : "", + (state & GPU_SAMPLER_REPEAT_S) ? "S" : "", + (state & GPU_SAMPLER_REPEAT_T) ? "T" : "", + (state & GPU_SAMPLER_REPEAT_R) ? "R" : "", + (state & GPU_SAMPLER_CLAMP_BORDER) ? "_clamp_border" : "", + (state & GPU_SAMPLER_COMPARE) ? "_compare" : "", + (state & GPU_SAMPLER_ANISO) ? "_aniso" : ""); + debug::object_label(GL_SAMPLER, samplers_[i], &sampler_name[1]); } samplers_update(); @@ -535,14 +514,12 @@ void GLTexture::samplers_init(void) glSamplerParameteri(icon_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameterf(icon_sampler, GL_TEXTURE_LOD_BIAS, -0.5f); - if (GLContext::debug_layer_support) { - glObjectLabel(GL_SAMPLER, icon_sampler, -1, "Sampler-icons"); - } + debug::object_label(GL_SAMPLER, icon_sampler, "icons"); } void GLTexture::samplers_update(void) { - if (!GLEW_EXT_texture_filter_anisotropic) { + if (!GLContext::texture_filter_anisotropic_support) { return; } diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc index 74453a08bfe..dd305fca555 100644 --- a/source/blender/gpu/opengl/gl_uniform_buffer.cc +++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc @@ -29,6 +29,7 @@ #include "gpu_context_private.hh" #include "gl_backend.hh" +#include "gl_debug.hh" #include "gl_uniform_buffer.hh" namespace blender::gpu { @@ -62,11 +63,7 @@ void GLUniformBuf::init(void) glBindBuffer(GL_UNIFORM_BUFFER, ubo_id_); glBufferData(GL_UNIFORM_BUFFER, size_in_bytes_, NULL, GL_DYNAMIC_DRAW); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "UBO-%s", name_); - glObjectLabel(GL_BUFFER, ubo_id_, -1, sh_name); - } + debug::object_label(GL_UNIFORM_BUFFER, ubo_id_, name_); } void GLUniformBuf::update(const void *data) diff --git a/source/blender/gpu/opengl/gl_vertex_array.cc b/source/blender/gpu/opengl/gl_vertex_array.cc index 732221cfab3..14a7b4deb7d 100644 --- a/source/blender/gpu/opengl/gl_vertex_array.cc +++ b/source/blender/gpu/opengl/gl_vertex_array.cc @@ -135,7 +135,7 @@ void GLVertArray::update_bindings(const GLuint vao, } } - if (attr_mask != 0 && GLEW_ARB_vertex_attrib_binding) { + if (attr_mask != 0 && GLContext::vertex_attrib_binding_support) { for (uint16_t mask = 1, a = 0; a < 16; a++, mask <<= 1) { if (attr_mask & mask) { GLContext *ctx = GLContext::get(); diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl index 640ceb97e5b..bdc0d37a7ae 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl @@ -11,29 +11,33 @@ uniform vec4 calls_data[MAX_CALLS * 3]; out vec2 texCoord_interp; flat out vec4 finalColor; +in vec2 pos; + void main() { - vec4 pos = calls_data[gl_InstanceID * 3]; + vec4 rect = calls_data[gl_InstanceID * 3]; vec4 tex = calls_data[gl_InstanceID * 3 + 1]; finalColor = calls_data[gl_InstanceID * 3 + 2]; - if (gl_VertexID == 0) { - pos.xy = pos.xz; + /* Use pos to select the right swizzle (instead of gl_VertexID) + * in order to workaround an OSX driver bug. */ + if (pos == vec2(0.0, 0.0)) { + rect.xy = rect.xz; tex.xy = tex.xz; } - else if (gl_VertexID == 1) { - pos.xy = pos.xw; + else if (pos == vec2(0.0, 1.0)) { + rect.xy = rect.xw; tex.xy = tex.xw; } - else if (gl_VertexID == 2) { - pos.xy = pos.yw; + else if (pos == vec2(1.0, 1.0)) { + rect.xy = rect.yw; tex.xy = tex.yw; } else { - pos.xy = pos.yz; + rect.xy = rect.yz; tex.xy = tex.yz; } - gl_Position = vec4(pos.xy, 0.0f, 1.0f); + gl_Position = vec4(rect.xy, 0.0f, 1.0f); texCoord_interp = tex.xy; } diff --git a/source/blender/io/alembic/exporter/abc_archive.cc b/source/blender/io/alembic/exporter/abc_archive.cc index 5fbf74f0705..a181a721de9 100644 --- a/source/blender/io/alembic/exporter/abc_archive.cc +++ b/source/blender/io/alembic/exporter/abc_archive.cc @@ -37,9 +37,7 @@ # include "utfconv.h" #endif -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::ErrorHandler; using Alembic::Abc::kWrapExisting; @@ -260,6 +258,4 @@ void ABCArchive::update_bounding_box(const Imath::Box3d &bounds) abc_archive_bbox_.set(bounds); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_archive.h b/source/blender/io/alembic/exporter/abc_archive.h index 43d0acf2520..8e6e5e40663 100644 --- a/source/blender/io/alembic/exporter/abc_archive.h +++ b/source/blender/io/alembic/exporter/abc_archive.h @@ -36,9 +36,7 @@ struct Main; struct Scene; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Container for an Alembic archive and time sampling info. * @@ -82,6 +80,4 @@ class ABCArchive { Alembic::Abc::OBox3dProperty abc_archive_bbox_; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_export_capi.cc b/source/blender/io/alembic/exporter/abc_export_capi.cc index 6412379c126..c22864a5433 100644 --- a/source/blender/io/alembic/exporter/abc_export_capi.cc +++ b/source/blender/io/alembic/exporter/abc_export_capi.cc @@ -62,9 +62,7 @@ struct ExportJobData { bool export_ok; }; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { // Construct the depsgraph for exporting. static void build_depsgraph(Depsgraph *depsgraph, const bool visible_objects_only) @@ -197,9 +195,7 @@ static void export_endjob(void *customdata) WM_set_locked_interface(data->wm, false); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic bool ABC_export(Scene *scene, bContext *C, diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc index 4cb6ca0c601..e2be241c144 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc @@ -40,9 +40,7 @@ #include "DNA_layer_types.h" #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { ABCHierarchyIterator::ABCHierarchyIterator(Depsgraph *depsgraph, ABCArchive *abc_archive, @@ -275,6 +273,4 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_particle_writer( return particle_writer.release(); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h index 5bc82564cdb..a0d9257b822 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h @@ -32,9 +32,7 @@ struct Depsgraph; struct ID; struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCAbstractWriter; class ABCHierarchyIterator; @@ -93,6 +91,4 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator { const HierarchyContext *context, const ABCWriterConstructorArgs &writer_args); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc b/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc index 7c147076975..255803a6bfb 100644 --- a/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc +++ b/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc @@ -32,9 +32,7 @@ #include "BKE_modifier.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { SubdivModifierDisabler::SubdivModifierDisabler(Depsgraph *depsgraph) : depsgraph_(depsgraph) { @@ -102,6 +100,4 @@ ModifierData *SubdivModifierDisabler::get_subdiv_modifier(Scene *scene, Object * return nullptr; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_subdiv_disabler.h b/source/blender/io/alembic/exporter/abc_subdiv_disabler.h index 677847f3f63..3556df7ff31 100644 --- a/source/blender/io/alembic/exporter/abc_subdiv_disabler.h +++ b/source/blender/io/alembic/exporter/abc_subdiv_disabler.h @@ -25,9 +25,7 @@ struct ModifierData; struct Object; struct Scene; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /** * Temporarily all subdivision modifiers on mesh objects. @@ -50,6 +48,4 @@ class SubdivModifierDisabler final { static ModifierData *get_subdiv_modifier(Scene *scene, Object *ob); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_abstract.cc b/source/blender/io/alembic/exporter/abc_writer_abstract.cc index 84527a12e85..0b08d8c4e58 100644 --- a/source/blender/io/alembic/exporter/abc_writer_abstract.cc +++ b/source/blender/io/alembic/exporter/abc_writer_abstract.cc @@ -32,9 +32,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; using Alembic::Abc::TimeSamplingPtr; @@ -112,6 +110,4 @@ void ABCAbstractWriter::write_visibility(const HierarchyContext &context) Alembic::AbcGeom::kVisibilityHidden); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_abstract.h b/source/blender/io/alembic/exporter/abc_writer_abstract.h index fefa9c356f2..59c55330443 100644 --- a/source/blender/io/alembic/exporter/abc_writer_abstract.h +++ b/source/blender/io/alembic/exporter/abc_writer_abstract.h @@ -30,9 +30,7 @@ struct Material; struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCAbstractWriter : public AbstractHierarchyWriter { protected: @@ -77,6 +75,4 @@ class ABCAbstractWriter : public AbstractHierarchyWriter { void write_visibility(const HierarchyContext &context); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_camera.cc b/source/blender/io/alembic/exporter/abc_writer_camera.cc index 6f13f791c4e..0ce6c3dc07f 100644 --- a/source/blender/io/alembic/exporter/abc_writer_camera.cc +++ b/source/blender/io/alembic/exporter/abc_writer_camera.cc @@ -31,9 +31,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::AbcGeom::CameraSample; using Alembic::AbcGeom::OCamera; @@ -105,6 +103,4 @@ void ABCCameraWriter::do_write(HierarchyContext &context) abc_camera_schema_.set(camera_sample); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_camera.h b/source/blender/io/alembic/exporter/abc_writer_camera.h index ceaa352d162..1b3e5898517 100644 --- a/source/blender/io/alembic/exporter/abc_writer_camera.h +++ b/source/blender/io/alembic/exporter/abc_writer_camera.h @@ -23,9 +23,7 @@ #include <Alembic/AbcGeom/OCamera.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCCameraWriter : public ABCAbstractWriter { private: @@ -47,6 +45,4 @@ class ABCCameraWriter : public ABCAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_curves.cc b/source/blender/io/alembic/exporter/abc_writer_curves.cc index 9d65830c699..6a12e4c59f3 100644 --- a/source/blender/io/alembic/exporter/abc_writer_curves.cc +++ b/source/blender/io/alembic/exporter/abc_writer_curves.cc @@ -41,9 +41,7 @@ using Alembic::AbcGeom::OInt16Property; using Alembic::AbcGeom::ON3fGeomParam; using Alembic::AbcGeom::OV2fGeomParam; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { const std::string ABC_CURVE_RESOLUTION_U_PROPNAME("blender:resolution"); @@ -196,6 +194,4 @@ Mesh *ABCCurveMeshWriter::get_export_mesh(Object *object_eval, bool &r_needsfree return BKE_mesh_new_nomain_from_curve(object_eval); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_curves.h b/source/blender/io/alembic/exporter/abc_writer_curves.h index cd6621c398d..d15f008f947 100644 --- a/source/blender/io/alembic/exporter/abc_writer_curves.h +++ b/source/blender/io/alembic/exporter/abc_writer_curves.h @@ -27,9 +27,7 @@ #include <Alembic/AbcGeom/OCurves.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { extern const std::string ABC_CURVE_RESOLUTION_U_PROPNAME; @@ -56,6 +54,4 @@ class ABCCurveMeshWriter : public ABCGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.cc b/source/blender/io/alembic/exporter/abc_writer_hair.cc index 1e1d2cf32ca..80034245b84 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.cc +++ b/source/blender/io/alembic/exporter/abc_writer_hair.cc @@ -43,9 +43,7 @@ using Alembic::AbcGeom::OCurvesSchema; using Alembic::AbcGeom::ON3fGeomParam; using Alembic::AbcGeom::OV2fGeomParam; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { ABCHairWriter::ABCHairWriter(const ABCWriterConstructorArgs &args) : ABCAbstractWriter(args), uv_warning_shown_(false) @@ -306,6 +304,4 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context, } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.h b/source/blender/io/alembic/exporter/abc_writer_hair.h index 0e149b0d045..f7d988ecbc4 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.h +++ b/source/blender/io/alembic/exporter/abc_writer_hair.h @@ -26,9 +26,7 @@ struct ParticleSettings; struct ParticleSystem; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCHairWriter : public ABCAbstractWriter { private: @@ -63,6 +61,4 @@ class ABCHairWriter : public ABCAbstractWriter { std::vector<int32_t> &hvertices); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_instance.cc b/source/blender/io/alembic/exporter/abc_writer_instance.cc index 581d94ee961..14c65e2a2e2 100644 --- a/source/blender/io/alembic/exporter/abc_writer_instance.cc +++ b/source/blender/io/alembic/exporter/abc_writer_instance.cc @@ -26,9 +26,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; @@ -69,6 +67,4 @@ void ABCInstanceWriter::do_write(HierarchyContext & /*context*/) /* Instances don't have data to be written. Just creating them is enough. */ } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_instance.h b/source/blender/io/alembic/exporter/abc_writer_instance.h index 74379b9d6bd..067c4af7aed 100644 --- a/source/blender/io/alembic/exporter/abc_writer_instance.h +++ b/source/blender/io/alembic/exporter/abc_writer_instance.h @@ -21,9 +21,7 @@ #include "abc_writer_abstract.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Writer for Alembic instances, i.e. data that references another Alembic object. * @@ -43,6 +41,4 @@ class ABCInstanceWriter : public ABCAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mball.cc b/source/blender/io/alembic/exporter/abc_writer_mball.cc index 167e392eb96..a797310f864 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mball.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mball.cc @@ -32,9 +32,7 @@ #include "DNA_mesh_types.h" #include "DNA_meta_types.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { ABCMetaballWriter::ABCMetaballWriter(const ABCWriterConstructorArgs &args) : ABCGenericMeshWriter(args) @@ -85,6 +83,4 @@ bool ABCMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const return ob == basis_ob; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mball.h b/source/blender/io/alembic/exporter/abc_writer_mball.h index 90d8c4d4b15..f96daa6d84b 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mball.h +++ b/source/blender/io/alembic/exporter/abc_writer_mball.h @@ -21,9 +21,7 @@ #include "abc_writer_mesh.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCMetaballWriter : public ABCGenericMeshWriter { public: @@ -40,6 +38,4 @@ class ABCMetaballWriter : public ABCGenericMeshWriter { bool is_basis_ball(Scene *scene, Object *ob) const; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index a9c722cae91..b762ad47932 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -66,9 +66,7 @@ using Alembic::AbcGeom::OSubDSchema; using Alembic::AbcGeom::OV2fGeomParam; using Alembic::AbcGeom::UInt32ArraySample; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* NOTE: Alembic's polygon winding order is clockwise, to match with Renderman. */ @@ -551,6 +549,4 @@ Mesh *ABCMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/ return BKE_object_get_evaluated_mesh(object_eval); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.h b/source/blender/io/alembic/exporter/abc_writer_mesh.h index 2bb5b687c47..956587df7c0 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.h +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.h @@ -27,9 +27,7 @@ struct ModifierData; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Writer for Alembic geometry. Does not assume the object is a mesh object. */ class ABCGenericMeshWriter : public ABCAbstractWriter { @@ -90,6 +88,4 @@ class ABCMeshWriter : public ABCGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_nurbs.cc b/source/blender/io/alembic/exporter/abc_writer_nurbs.cc index a2dc4441b75..de1870fefd9 100644 --- a/source/blender/io/alembic/exporter/abc_writer_nurbs.cc +++ b/source/blender/io/alembic/exporter/abc_writer_nurbs.cc @@ -31,9 +31,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; using Alembic::AbcGeom::FloatArraySample; @@ -181,6 +179,4 @@ void ABCNurbsWriter::do_write(HierarchyContext &context) } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_nurbs.h b/source/blender/io/alembic/exporter/abc_writer_nurbs.h index f7fd8ffe91a..691390ffc9f 100644 --- a/source/blender/io/alembic/exporter/abc_writer_nurbs.h +++ b/source/blender/io/alembic/exporter/abc_writer_nurbs.h @@ -23,9 +23,7 @@ #include "abc_writer_mesh.h" #include <vector> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCNurbsWriter : public ABCAbstractWriter { private: @@ -52,6 +50,4 @@ class ABCNurbsMeshWriter : public ABCGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_points.cc b/source/blender/io/alembic/exporter/abc_writer_points.cc index 350b70b9552..83d33577b3b 100644 --- a/source/blender/io/alembic/exporter/abc_writer_points.cc +++ b/source/blender/io/alembic/exporter/abc_writer_points.cc @@ -36,9 +36,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::AbcGeom::kVertexScope; using Alembic::AbcGeom::OPoints; @@ -143,6 +141,4 @@ void ABCPointsWriter::do_write(HierarchyContext &context) abc_points_schema_.set(sample); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_points.h b/source/blender/io/alembic/exporter/abc_writer_points.h index 88dd424ca2a..fec5e84f3f2 100644 --- a/source/blender/io/alembic/exporter/abc_writer_points.h +++ b/source/blender/io/alembic/exporter/abc_writer_points.h @@ -26,9 +26,7 @@ #include <Alembic/AbcGeom/OPoints.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCPointsWriter : public ABCAbstractWriter { Alembic::AbcGeom::OPoints abc_points_; @@ -47,6 +45,4 @@ class ABCPointsWriter : public ABCAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_transform.cc b/source/blender/io/alembic/exporter/abc_writer_transform.cc index 93ffd847bf2..a72a6b47aa9 100644 --- a/source/blender/io/alembic/exporter/abc_writer_transform.cc +++ b/source/blender/io/alembic/exporter/abc_writer_transform.cc @@ -33,9 +33,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; using Alembic::AbcGeom::OXform; @@ -115,6 +113,4 @@ bool ABCTransformWriter::check_is_animated(const HierarchyContext &context) cons return BKE_object_moves_in_time(context.object, context.animation_check_include_parent); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_transform.h b/source/blender/io/alembic/exporter/abc_writer_transform.h index 9d172531d1f..a334fe610ee 100644 --- a/source/blender/io/alembic/exporter/abc_writer_transform.h +++ b/source/blender/io/alembic/exporter/abc_writer_transform.h @@ -23,9 +23,7 @@ #include <Alembic/AbcGeom/OXform.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCTransformWriter : public ABCAbstractWriter { private: @@ -42,6 +40,4 @@ class ABCTransformWriter : public ABCAbstractWriter { virtual Alembic::Abc::OObject get_alembic_object() const override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.cc b/source/blender/io/alembic/intern/abc_axis_conversion.cc index 396c8fdb28b..23b24d2fd9a 100644 --- a/source/blender/io/alembic/intern/abc_axis_conversion.cc +++ b/source/blender/io/alembic/intern/abc_axis_conversion.cc @@ -25,9 +25,7 @@ #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { void create_swapped_rotation_matrix(float rot_x_mat[3][3], float rot_y_mat[3][3], @@ -168,6 +166,4 @@ void create_transform_matrix(Object *obj, copy_m44_axis_swap(r_yup_mat, zup_mat, ABC_YUP_FROM_ZUP); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.h b/source/blender/io/alembic/intern/abc_axis_conversion.h index 797592d9eee..30988222fb7 100644 --- a/source/blender/io/alembic/intern/abc_axis_conversion.h +++ b/source/blender/io/alembic/intern/abc_axis_conversion.h @@ -26,9 +26,7 @@ struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* TODO(kevin): for now keeping these transformations hardcoded to make sure * everything works properly, and also because Alembic is almost exclusively @@ -98,6 +96,4 @@ void create_transform_matrix(Object *obj, AbcMatrixMode mode, Object *proxy_from); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index 408894a8de2..66e05504303 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -50,9 +50,7 @@ using Alembic::Abc::V2fArraySample; using Alembic::AbcGeom::OC4fGeomParam; using Alembic::AbcGeom::OV2fGeomParam; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { static void get_uvs(const CDStreamConfig &config, std::vector<Imath::V2f> &uvs, @@ -489,6 +487,4 @@ void read_custom_data(const std::string &iobject_full_name, } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h index 8f4accb70dc..e98ec271b9f 100644 --- a/source/blender/io/alembic/intern/abc_customdata.h +++ b/source/blender/io/alembic/intern/abc_customdata.h @@ -36,9 +36,7 @@ struct Mesh; using Alembic::Abc::ICompoundProperty; using Alembic::Abc::OCompoundProperty; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { struct UVSample { std::vector<Imath::V2f> uvs; @@ -113,6 +111,4 @@ void read_custom_data(const std::string &iobject_full_name, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_archive.cc b/source/blender/io/alembic/intern/abc_reader_archive.cc index 776b8955d47..4951dc0e035 100644 --- a/source/blender/io/alembic/intern/abc_reader_archive.cc +++ b/source/blender/io/alembic/intern/abc_reader_archive.cc @@ -39,9 +39,7 @@ using Alembic::Abc::Exception; using Alembic::Abc::IArchive; using Alembic::Abc::kWrapExisting; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { static IArchive open_archive(const std::string &filename, const std::vector<std::istream *> &input_streams) @@ -108,6 +106,4 @@ Alembic::Abc::IObject ArchiveReader::getTop() return m_archive.getTop(); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_archive.h b/source/blender/io/alembic/intern/abc_reader_archive.h index aea62b46cce..2a4fd6bd8fb 100644 --- a/source/blender/io/alembic/intern/abc_reader_archive.h +++ b/source/blender/io/alembic/intern/abc_reader_archive.h @@ -30,9 +30,7 @@ struct Main; struct Scene; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Wrappers around input and output archives. The goal is to be able to use * streams so that unicode paths work on Windows (T49112), and to make sure that @@ -52,6 +50,4 @@ class ArchiveReader { Alembic::Abc::IObject getTop(); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_camera.cc b/source/blender/io/alembic/intern/abc_reader_camera.cc index 3affb35908d..d7a096a4ed8 100644 --- a/source/blender/io/alembic/intern/abc_reader_camera.cc +++ b/source/blender/io/alembic/intern/abc_reader_camera.cc @@ -37,9 +37,7 @@ using Alembic::AbcGeom::IFloatProperty; using Alembic::AbcGeom::ISampleSelector; using Alembic::AbcGeom::kWrapExisting; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcCameraReader::AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -114,6 +112,4 @@ void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_ m_object->data = bcam; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_camera.h b/source/blender/io/alembic/intern/abc_reader_camera.h index b733269407b..408e9623970 100644 --- a/source/blender/io/alembic/intern/abc_reader_camera.h +++ b/source/blender/io/alembic/intern/abc_reader_camera.h @@ -21,9 +21,7 @@ #include "abc_reader_object.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcCameraReader : public AbcObjectReader { Alembic::AbcGeom::ICameraSchema m_schema; @@ -39,6 +37,4 @@ class AbcCameraReader : public AbcObjectReader { void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_curves.cc b/source/blender/io/alembic/intern/abc_reader_curves.cc index a505dfd654b..e29b6eda6fc 100644 --- a/source/blender/io/alembic/intern/abc_reader_curves.cc +++ b/source/blender/io/alembic/intern/abc_reader_curves.cc @@ -54,9 +54,7 @@ using Alembic::AbcGeom::IInt16Property; using Alembic::AbcGeom::ISampleSelector; using Alembic::AbcGeom::kWrapExisting; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcCurveReader::AbcCurveReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -356,6 +354,4 @@ Mesh *AbcCurveReader::read_mesh(Mesh *existing_mesh, return BKE_mesh_new_nomain_from_curve(m_object); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_curves.h b/source/blender/io/alembic/intern/abc_reader_curves.h index 7488adb9b24..075ed5ca6a1 100644 --- a/source/blender/io/alembic/intern/abc_reader_curves.h +++ b/source/blender/io/alembic/intern/abc_reader_curves.h @@ -29,9 +29,7 @@ struct Curve; #define ABC_CURVE_RESOLUTION_U_PROPNAME "blender:resolution" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcCurveReader : public AbcObjectReader { Alembic::AbcGeom::ICurvesSchema m_curves_schema; @@ -55,6 +53,4 @@ class AbcCurveReader : public AbcObjectReader { const Alembic::Abc::ISampleSelector &sample_selector); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 98130eb28cd..5a42be2bb02 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -60,9 +60,7 @@ using Alembic::AbcGeom::N3fArraySamplePtr; using Alembic::AbcGeom::UInt32ArraySamplePtr; using Alembic::AbcGeom::V2fArraySamplePtr; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* NOTE: Alembic's polygon winding order is clockwise, to match with Renderman. */ @@ -936,6 +934,4 @@ Mesh *AbcSubDReader::read_mesh(Mesh *existing_mesh, return config.mesh; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.h b/source/blender/io/alembic/intern/abc_reader_mesh.h index 363a74b8b5f..a29eeb71dff 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.h +++ b/source/blender/io/alembic/intern/abc_reader_mesh.h @@ -24,9 +24,7 @@ struct Mesh; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcMeshReader : public AbcObjectReader { Alembic::AbcGeom::IPolyMeshSchema m_schema; @@ -85,6 +83,4 @@ void read_mverts(MVert *mverts, CDStreamConfig get_config(struct Mesh *mesh); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_nurbs.cc b/source/blender/io/alembic/intern/abc_reader_nurbs.cc index 3ca3f6229ab..27d4ec44a27 100644 --- a/source/blender/io/alembic/intern/abc_reader_nurbs.cc +++ b/source/blender/io/alembic/intern/abc_reader_nurbs.cc @@ -44,9 +44,7 @@ using Alembic::AbcGeom::INuPatch; using Alembic::AbcGeom::INuPatchSchema; using Alembic::AbcGeom::IObject; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcNurbsReader::AbcNurbsReader(const IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -227,6 +225,4 @@ void AbcNurbsReader::getNurbsPatches(const IObject &obj) } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_nurbs.h b/source/blender/io/alembic/intern/abc_reader_nurbs.h index 738da82885d..e8be2efba9f 100644 --- a/source/blender/io/alembic/intern/abc_reader_nurbs.h +++ b/source/blender/io/alembic/intern/abc_reader_nurbs.h @@ -21,9 +21,7 @@ #include "abc_reader_object.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcNurbsReader : public AbcObjectReader { std::vector<std::pair<Alembic::AbcGeom::INuPatchSchema, Alembic::Abc::IObject>> m_schemas; @@ -39,6 +37,4 @@ class AbcNurbsReader : public AbcObjectReader { void getNurbsPatches(const Alembic::Abc::IObject &obj); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 06b0c07f4c5..1e832de1f47 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -41,9 +41,7 @@ using Alembic::AbcGeom::IObject; using Alembic::AbcGeom::IXform; using Alembic::AbcGeom::IXformSchema; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcObjectReader::AbcObjectReader(const IObject &object, ImportSettings &settings) : m_name(""), @@ -335,6 +333,4 @@ void AbcObjectReader::decref() BLI_assert(m_refcount >= 0); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_object.h b/source/blender/io/alembic/intern/abc_reader_object.h index 0bde60b06b5..8e00ed42777 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.h +++ b/source/blender/io/alembic/intern/abc_reader_object.h @@ -31,9 +31,7 @@ struct Object; using Alembic::AbcCoreAbstract::chrono_t; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { struct ImportSettings { bool do_convert_mat; @@ -168,6 +166,4 @@ class AbcObjectReader { Imath::M44d get_matrix(const Alembic::AbcGeom::IXformSchema &schema, const float time); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_points.cc b/source/blender/io/alembic/intern/abc_reader_points.cc index b805da4daa3..f8cc6b0314a 100644 --- a/source/blender/io/alembic/intern/abc_reader_points.cc +++ b/source/blender/io/alembic/intern/abc_reader_points.cc @@ -43,9 +43,7 @@ using Alembic::AbcGeom::IPoints; using Alembic::AbcGeom::IPointsSchema; using Alembic::AbcGeom::ISampleSelector; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcPointsReader::AbcPointsReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -158,6 +156,4 @@ struct Mesh *AbcPointsReader::read_mesh(struct Mesh *existing_mesh, return new_mesh ? new_mesh : existing_mesh; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_points.h b/source/blender/io/alembic/intern/abc_reader_points.h index 8a970ac35b3..aed66699c75 100644 --- a/source/blender/io/alembic/intern/abc_reader_points.h +++ b/source/blender/io/alembic/intern/abc_reader_points.h @@ -25,9 +25,7 @@ #include "abc_customdata.h" #include "abc_reader_object.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcPointsReader : public AbcObjectReader { Alembic::AbcGeom::IPointsSchema m_schema; @@ -53,6 +51,4 @@ void read_points_sample(const Alembic::AbcGeom::IPointsSchema &schema, const Alembic::AbcGeom::ISampleSelector &selector, CDStreamConfig &config); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_transform.cc b/source/blender/io/alembic/intern/abc_reader_transform.cc index 456d1da2c68..3aab2f2d339 100644 --- a/source/blender/io/alembic/intern/abc_reader_transform.cc +++ b/source/blender/io/alembic/intern/abc_reader_transform.cc @@ -29,9 +29,7 @@ using Alembic::Abc::ISampleSelector; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcEmptyReader::AbcEmptyReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -77,6 +75,4 @@ void AbcEmptyReader::readObjectData(Main *bmain, const ISampleSelector &UNUSED(s m_object->data = NULL; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_transform.h b/source/blender/io/alembic/intern/abc_reader_transform.h index 812d3bdfc92..e515560912f 100644 --- a/source/blender/io/alembic/intern/abc_reader_transform.h +++ b/source/blender/io/alembic/intern/abc_reader_transform.h @@ -23,9 +23,7 @@ #include <Alembic/AbcGeom/All.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcEmptyReader : public AbcObjectReader { Alembic::AbcGeom::IXformSchema m_schema; @@ -41,6 +39,4 @@ class AbcEmptyReader : public AbcObjectReader { void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_util.cc b/source/blender/io/alembic/intern/abc_util.cc index 04febd7bfcb..edb20da89a5 100644 --- a/source/blender/io/alembic/intern/abc_util.cc +++ b/source/blender/io/alembic/intern/abc_util.cc @@ -38,9 +38,7 @@ #include "PIL_time.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { std::string get_id_name(const Object *const ob) { @@ -261,6 +259,4 @@ std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger) return os; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_util.h b/source/blender/io/alembic/intern/abc_util.h index 4689173ab5f..98f4b0376a7 100644 --- a/source/blender/io/alembic/intern/abc_util.h +++ b/source/blender/io/alembic/intern/abc_util.h @@ -36,9 +36,7 @@ using Alembic::Abc::chrono_t; struct ID; struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcObjectReader; struct ImportSettings; @@ -161,6 +159,4 @@ class SimpleLogger { */ std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/tests/abc_export_test.cc b/source/blender/io/alembic/tests/abc_export_test.cc index c602868b07e..625dbfd176f 100644 --- a/source/blender/io/alembic/tests/abc_export_test.cc +++ b/source/blender/io/alembic/tests/abc_export_test.cc @@ -12,9 +12,7 @@ #include "DEG_depsgraph.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AlembicExportTest : public testing::Test { protected: @@ -159,6 +157,4 @@ TEST_F(AlembicExportTest, TimeSamples180degShutter) EXPECT_NEAR(32 + 0.15, frames[9], 1e-5); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/tests/abc_matrix_test.cc b/source/blender/io/alembic/tests/abc_matrix_test.cc index b58e989b1a1..02ef1a99348 100644 --- a/source/blender/io/alembic/tests/abc_matrix_test.cc +++ b/source/blender/io/alembic/tests/abc_matrix_test.cc @@ -6,9 +6,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { TEST(abc_matrix, CreateRotationMatrixY_YfromZ) { @@ -287,6 +285,4 @@ TEST(abc_matrix, CopyM44AxisSwapWithScale_gimbal_ZfromY) EXPECT_M4_NEAR(expect, result, 1e-5f); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/common/IO_abstract_hierarchy_iterator.h b/source/blender/io/common/IO_abstract_hierarchy_iterator.h index 1d78cc38746..e3ed3dd70a2 100644 --- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h +++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h @@ -51,8 +51,7 @@ struct Object; struct ParticleSystem; struct ViewLayer; -namespace blender { -namespace io { +namespace blender::io { class AbstractHierarchyWriter; class DupliParentFinder; @@ -356,5 +355,4 @@ class AbstractHierarchyIterator { ExportChildren &graph_children(const HierarchyContext *parent_context); }; -} // namespace io -} // namespace blender +} // namespace blender::io diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc index d825625cafc..6e763c29631 100644 --- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc +++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc @@ -44,8 +44,7 @@ #include "DEG_depsgraph_query.h" -namespace blender { -namespace io { +namespace blender::io { const HierarchyContext *HierarchyContext::root() { @@ -755,5 +754,4 @@ bool AbstractHierarchyIterator::should_visit_dupli_object(const DupliObject *dup return !dupli_object->no_draw; } -} // namespace io -} // namespace blender +} // namespace blender::io diff --git a/source/blender/io/common/intern/object_identifier.cc b/source/blender/io/common/intern/object_identifier.cc index 696bc5d2c34..a2d2d998bec 100644 --- a/source/blender/io/common/intern/object_identifier.cc +++ b/source/blender/io/common/intern/object_identifier.cc @@ -26,8 +26,7 @@ extern "C" { #include <cstring> #include <sstream> -namespace blender { -namespace io { +namespace blender::io { ObjectIdentifier::ObjectIdentifier(Object *object, Object *duplicated_by, @@ -112,5 +111,4 @@ bool operator==(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj return obj_ident_a.persistent_id == obj_ident_b.persistent_id; } -} // namespace io -} // namespace blender +} // namespace blender::io diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc index 52075728e3e..4717f27dbd9 100644 --- a/source/blender/io/usd/intern/usd_capi.cc +++ b/source/blender/io/usd/intern/usd_capi.cc @@ -46,9 +46,7 @@ #include "WM_api.h" #include "WM_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { struct ExportJobData { Main *bmain; @@ -185,9 +183,7 @@ static void export_endjob(void *customdata) WM_set_locked_interface(data->wm, false); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd bool USD_export(bContext *C, const char *filepath, diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h index 5513768b527..41ff34b327e 100644 --- a/source/blender/io/usd/intern/usd_exporter_context.h +++ b/source/blender/io/usd/intern/usd_exporter_context.h @@ -26,9 +26,7 @@ struct Depsgraph; struct Object; -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDHierarchyIterator; @@ -40,6 +38,4 @@ struct USDExporterContext { const USDExportParams &export_params; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 39fbef70e81..66dfc21441e 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -42,9 +42,7 @@ #include "DNA_layer_types.h" #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDHierarchyIterator::USDHierarchyIterator(Depsgraph *depsgraph, pxr::UsdStageRefPtr stage, @@ -149,6 +147,4 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_particle_writer( return nullptr; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.h b/source/blender/io/usd/intern/usd_hierarchy_iterator.h index 03e80ce735a..922ab761bd9 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.h +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.h @@ -31,9 +31,7 @@ struct Depsgraph; struct ID; struct Object; -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { using blender::io::AbstractHierarchyIterator; using blender::io::AbstractHierarchyWriter; @@ -71,6 +69,4 @@ class USDHierarchyIterator : public AbstractHierarchyIterator { USDExporterContext create_usd_export_context(const HierarchyContext *context); }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index 0edfbc62d6b..3f5babdee56 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -34,9 +34,7 @@ static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal); static const pxr::TfToken surface("surface", pxr::TfToken::Immortal); } // namespace usdtokens -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDAbstractWriter::USDAbstractWriter(const USDExporterContext &usd_export_context) : usd_export_context_(usd_export_context), @@ -155,6 +153,4 @@ bool USDAbstractWriter::mark_as_instance(const HierarchyContext &context, const return true; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_abstract.h b/source/blender/io/usd/intern/usd_writer_abstract.h index 6cf7c79c5fa..6a3b8d515dc 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.h +++ b/source/blender/io/usd/intern/usd_writer_abstract.h @@ -35,9 +35,7 @@ struct Material; struct Object; -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { using blender::io::AbstractHierarchyWriter; using blender::io::HierarchyContext; @@ -82,6 +80,4 @@ class USDAbstractWriter : public AbstractHierarchyWriter { virtual bool mark_as_instance(const HierarchyContext &context, const pxr::UsdPrim &prim); }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_camera.cc b/source/blender/io/usd/intern/usd_writer_camera.cc index d51eb32d3fd..f21a0444888 100644 --- a/source/blender/io/usd/intern/usd_writer_camera.cc +++ b/source/blender/io/usd/intern/usd_writer_camera.cc @@ -28,9 +28,7 @@ #include "DNA_camera_types.h" #include "DNA_scene_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDCameraWriter::USDCameraWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -108,6 +106,4 @@ void USDCameraWriter::do_write(HierarchyContext &context) } } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_camera.h b/source/blender/io/usd/intern/usd_writer_camera.h index 1c613d7879b..f6d7e777f2f 100644 --- a/source/blender/io/usd/intern/usd_writer_camera.h +++ b/source/blender/io/usd/intern/usd_writer_camera.h @@ -20,9 +20,7 @@ #include "usd_writer_abstract.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { /* Writer for writing camera data to UsdGeomCamera. */ class USDCameraWriter : public USDAbstractWriter { @@ -34,6 +32,4 @@ class USDCameraWriter : public USDAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_hair.cc b/source/blender/io/usd/intern/usd_writer_hair.cc index 0fd5c4ce727..df09aa2f187 100644 --- a/source/blender/io/usd/intern/usd_writer_hair.cc +++ b/source/blender/io/usd/intern/usd_writer_hair.cc @@ -26,9 +26,7 @@ #include "DNA_particle_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDHairWriter::USDHairWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -87,6 +85,4 @@ bool USDHairWriter::check_is_animated(const HierarchyContext &UNUSED(context)) c return true; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_hair.h b/source/blender/io/usd/intern/usd_writer_hair.h index b9a28013875..8dc256fdb8e 100644 --- a/source/blender/io/usd/intern/usd_writer_hair.h +++ b/source/blender/io/usd/intern/usd_writer_hair.h @@ -20,9 +20,7 @@ #include "usd_writer_abstract.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { /* Writer for writing hair particle data as USD curves. */ class USDHairWriter : public USDAbstractWriter { @@ -34,6 +32,4 @@ class USDHairWriter : public USDAbstractWriter { virtual bool check_is_animated(const HierarchyContext &context) const override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_light.cc b/source/blender/io/usd/intern/usd_writer_light.cc index 19115dd1a4e..b6a81c973d2 100644 --- a/source/blender/io/usd/intern/usd_writer_light.cc +++ b/source/blender/io/usd/intern/usd_writer_light.cc @@ -30,9 +30,7 @@ #include "DNA_light_types.h" #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDLightWriter::USDLightWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -109,6 +107,4 @@ void USDLightWriter::do_write(HierarchyContext &context) usd_light.CreateSpecularAttr().Set(light->spec_fac, timecode); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_light.h b/source/blender/io/usd/intern/usd_writer_light.h index 082050ad071..9be82bfe214 100644 --- a/source/blender/io/usd/intern/usd_writer_light.h +++ b/source/blender/io/usd/intern/usd_writer_light.h @@ -20,9 +20,7 @@ #include "usd_writer_abstract.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDLightWriter : public USDAbstractWriter { public: @@ -33,6 +31,4 @@ class USDLightWriter : public USDAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 2073d4cbe87..3f9cb78ea3b 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -44,9 +44,7 @@ #include <iostream> -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDGenericMeshWriter::USDGenericMeshWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -462,6 +460,4 @@ Mesh *USDMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/ return BKE_object_get_evaluated_mesh(object_eval); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_mesh.h b/source/blender/io/usd/intern/usd_writer_mesh.h index 078daa05501..6345f2d4240 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.h +++ b/source/blender/io/usd/intern/usd_writer_mesh.h @@ -22,9 +22,7 @@ #include <pxr/usd/usdGeom/mesh.h> -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { struct USDMeshData; @@ -62,6 +60,4 @@ class USDMeshWriter : public USDGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_metaball.cc b/source/blender/io/usd/intern/usd_writer_metaball.cc index f003fba18a4..8e32bd4705a 100644 --- a/source/blender/io/usd/intern/usd_writer_metaball.cc +++ b/source/blender/io/usd/intern/usd_writer_metaball.cc @@ -34,9 +34,7 @@ #include "DNA_mesh_types.h" #include "DNA_meta_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDMetaballWriter::USDMetaballWriter(const USDExporterContext &ctx) : USDGenericMeshWriter(ctx) { @@ -78,6 +76,4 @@ bool USDMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const return ob == basis_ob; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_metaball.h b/source/blender/io/usd/intern/usd_writer_metaball.h index 216f5a2638f..f82c001154e 100644 --- a/source/blender/io/usd/intern/usd_writer_metaball.h +++ b/source/blender/io/usd/intern/usd_writer_metaball.h @@ -20,9 +20,7 @@ #include "usd_writer_mesh.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDMetaballWriter : public USDGenericMeshWriter { public: @@ -38,6 +36,4 @@ class USDMetaballWriter : public USDGenericMeshWriter { bool is_basis_ball(Scene *scene, Object *ob) const; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_transform.cc b/source/blender/io/usd/intern/usd_writer_transform.cc index 49983115455..632a6dd0f3f 100644 --- a/source/blender/io/usd/intern/usd_writer_transform.cc +++ b/source/blender/io/usd/intern/usd_writer_transform.cc @@ -28,9 +28,7 @@ #include "DNA_layer_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDTransformWriter::USDTransformWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -64,6 +62,4 @@ bool USDTransformWriter::check_is_animated(const HierarchyContext &context) cons return BKE_object_moves_in_time(context.object, context.animation_check_include_parent); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_transform.h b/source/blender/io/usd/intern/usd_writer_transform.h index 39a1f20e7e8..eba87b28faa 100644 --- a/source/blender/io/usd/intern/usd_writer_transform.h +++ b/source/blender/io/usd/intern/usd_writer_transform.h @@ -22,9 +22,7 @@ #include <pxr/usd/usdGeom/xform.h> -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDTransformWriter : public USDAbstractWriter { private: @@ -38,6 +36,4 @@ class USDTransformWriter : public USDAbstractWriter { bool check_is_animated(const HierarchyContext &context) const override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index c7076d6c631..7134b085fe7 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -1852,7 +1852,7 @@ int rna_property_override_diff_default(Main *bmain, if (is_first_insert) { /* We need to clean up all possible existing insertion operations, - * otherwise we'd end up with a mess of ops everytime something changes. */ + * otherwise we'd end up with a mess of ops every time something changes. */ for (IDOverrideLibraryPropertyOperation *opop = op->operations.first; opop != NULL;) { IDOverrideLibraryPropertyOperation *opop_next = opop->next; diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index b8615d22753..229fa125455 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2981,7 +2981,11 @@ static void rna_def_space_outliner(BlenderRNA *brna) ICON_RENDER_RESULT, "View Layer", "Display collections and objects in the view layer"}, - {SO_SEQUENCE, "SEQUENCE", ICON_SEQUENCE, "Sequence", "Display sequence data-blocks"}, + {SO_SEQUENCE, + "SEQUENCE", + ICON_SEQUENCE, + "Video Sequencer", + "Display data belonging to the Video Sequencer"}, {SO_LIBRARIES, "LIBRARIES", ICON_FILE_BLEND, diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 98bbb328007..94a9a922ff7 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -313,10 +313,19 @@ static void deformVerts_do(HookModifierData *hmd, MOD_get_vgroup(ob, mesh, hmd->name, &dvert, &hd.defgrp_index); int cd_dvert_offset = -1; - if ((em != NULL) && (hd.defgrp_index != -1)) { - cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); - if (cd_dvert_offset == -1) { - hd.defgrp_index = -1; + if (hd.defgrp_index != -1) { + /* Edit-mesh. */ + if (em != NULL) { + cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + if (cd_dvert_offset == -1) { + hd.defgrp_index = -1; + } + } + else { + /* Regular mesh. */ + if (dvert == NULL) { + hd.defgrp_index = -1; + } } } diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index 179996d5acf..cc844e53603 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -229,7 +229,7 @@ Mesh *MOD_deform_mesh_eval_get(Object *ob, * that's properly generated for curves. */ mesh = BKE_mesh_new_nomain_from_curve(ob); - /* Currently, that may not be the case everytime + /* Currently, that may not be the case every time * (texts e.g. tend to give issues, * also when deforming curve points instead of generated curve geometry... ). */ if (mesh != NULL && mesh->totvert != num_verts) { diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 37ed9f89bc7..b1a469d1365 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -400,7 +400,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) rect->ymin = rect->ymax = cursory; } - /* XXX todo, multiline drag draws... but maybe not, more types mixed wont work well */ + /* Should we support multi-line drag draws? Maybe not, more types mixed wont work well. */ GPU_blend(GPU_BLEND_ALPHA); for (drag = wm->drags.first; drag; drag = drag->next) { const uchar text_col[] = {255, 255, 255, 255}; |