Commit: a7fb567c18b5a831f7276a7d9a01646a177e6b5b Author: Bastien Montagne Date: Fri Mar 6 16:38:04 2020 +0100 Branches: master https://developer.blender.org/rBa7fb567c18b5a831f7276a7d9a01646a177e6b5b
Cleanup: Material: Move to IDTypeInfo and remove unused BKE API. =================================================================== M source/blender/blenkernel/BKE_idtype.h M source/blender/blenkernel/BKE_lattice.h M source/blender/blenkernel/BKE_material.h M source/blender/blenkernel/intern/idtype.c M source/blender/blenkernel/intern/lattice.c M source/blender/blenkernel/intern/lib_id.c M source/blender/blenkernel/intern/lib_id_delete.c M source/blender/blenkernel/intern/material.c =================================================================== diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index 21154ecf497..7df7fc88428 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -130,7 +130,7 @@ extern IDTypeInfo IDType_ID_OB; extern IDTypeInfo IDType_ID_ME; extern IDTypeInfo IDType_ID_CU; extern IDTypeInfo IDType_ID_MB; -// extern IDTypeInfo IDType_ID_MA; +extern IDTypeInfo IDType_ID_MA; // extern IDTypeInfo IDType_ID_TE; // extern IDTypeInfo IDType_ID_IM; extern IDTypeInfo IDType_ID_LT; diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index 8616ab19d69..3cd8c69a263 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -43,7 +43,6 @@ struct bGPDstroke; void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *ltOb); struct Lattice *BKE_lattice_add(struct Main *bmain, const char *name); struct Lattice *BKE_lattice_copy(struct Main *bmain, const struct Lattice *lt); -void BKE_lattice_make_local(struct Main *bmain, struct Lattice *lt, const int flags); void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du); struct LatticeDeformData *init_latt_deform(struct Object *oblatt, diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 03f556ab500..ffa1970d8c6 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -42,27 +42,20 @@ void BKE_materials_exit(void); /* Materials */ -void BKE_material_free(struct Material *ma); void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id); void BKE_objects_materials_test_all(struct Main *bmain, struct ID *id); void BKE_object_material_resize(struct Main *bmain, struct Object *ob, const short totcol, bool do_id_user); -void BKE_material_init(struct Material *ma); void BKE_object_material_remap(struct Object *ob, const unsigned int *remap); void BKE_object_material_remap_calc(struct Object *ob_dst, struct Object *ob_src, short *remap_src_to_dst); struct Material *BKE_material_add(struct Main *bmain, const char *name); struct Material *BKE_gpencil_material_add(struct Main *bmain, const char *name); -void BKE_material_copy_data(struct Main *bmain, - struct Material *ma_dst, - const struct Material *ma_src, - const int flag); struct Material *BKE_material_copy(struct Main *bmain, const struct Material *ma); struct Material *BKE_material_localize(struct Material *ma); -void BKE_material_make_local(struct Main *bmain, struct Material *ma, const int flags); void BKE_gpencil_material_attr_init(struct Material *ma); /* UNUSED */ diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index 85ba9c6d2a8..b02fb7b5a7d 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -57,7 +57,7 @@ static void id_type_init(void) INIT_TYPE(ID_ME); INIT_TYPE(ID_CU); INIT_TYPE(ID_MB); - // INIT_TYPE(ID_MA); + INIT_TYPE(ID_MA); // INIT_TYPE(ID_TE); // INIT_TYPE(ID_IM); INIT_TYPE(ID_LT); diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 3b50e81e392..d4f25b781bd 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -344,11 +344,6 @@ Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt) return lt_copy; } -void BKE_lattice_make_local(Main *bmain, Lattice *lt, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, <->id, flags); -} - typedef struct LatticeDeformData { Object *object; float *latticedata; diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 0f1dd16fdc5..33240dbeec8 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -482,9 +482,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags BLI_assert(0); return true; case ID_MA: - if (!test) { - BKE_material_make_local(bmain, (Material *)id, flags); - } + BLI_assert(0); return true; case ID_TE: if (!test) { @@ -497,9 +495,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags } return true; case ID_LT: - if (!test) { - BKE_lattice_make_local(bmain, (Lattice *)id, flags); - } + BLI_assert(0); return true; case ID_LA: BLI_assert(0); @@ -717,7 +713,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) BLI_assert(0); break; case ID_MA: - BKE_material_copy_data(bmain, (Material *)*r_newid, (Material *)id, flag); + BLI_assert(0); break; case ID_TE: BKE_texture_copy_data(bmain, (Tex *)*r_newid, (Tex *)id, flag); @@ -1338,7 +1334,7 @@ void BKE_libblock_init_empty(ID *id) BLI_assert(0); break; case ID_MA: - BKE_material_init((Material *)id); + BLI_assert(0); break; case ID_TE: BKE_texture_default((Tex *)id); diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 9b8b0b8c418..aeb7462e080 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -155,7 +155,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BLI_assert(0); break; case ID_MA: - BKE_material_free((Material *)id); + BLI_assert(0); break; case ID_TE: BKE_texture_free((Tex *)id); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 219d4eaa407..10f32a6b0bc 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -49,11 +49,14 @@ #include "BLI_utildefines.h" #include "BLI_array_utils.h" +#include "BLT_translation.h" + #include "BKE_animsys.h" #include "BKE_brush.h" #include "BKE_displist.h" #include "BKE_gpencil.h" #include "BKE_icons.h" +#include "BKE_idtype.h" #include "BKE_image.h" #include "BKE_lib_id.h" #include "BKE_main.h" @@ -74,29 +77,88 @@ static CLG_LogRef LOG = {"bke.material"}; -/** Free (or release) any data used by this material (does not free the material itself). */ -void BKE_material_free(Material *ma) +static void material_init_data(ID *id) +{ + Material *material = (Material *)id; + + BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(material, id)); + + MEMCPY_STRUCT_AFTER(material, DNA_struct_default_get(Material), id); +} + +static void material_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag) +{ + Material *material_dst = (Material *)id_dst; + const Material *material_src = (const Material *)id_src; + + /* We always need allocation of our private ID data. */ + const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE; + + if (material_src->nodetree) { + BKE_id_copy_ex( + bmain, (ID *)material_src->nodetree, (ID **)&material_dst->nodetree, flag_private_id_data); + } + + if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { + BKE_previewimg_id_copy(&material_dst->id, &material_src->id); + } + else { + material_dst->preview = NULL; + } + + if (material_src->texpaintslot != NULL) { + material_dst->texpaintslot = MEM_dupallocN(material_src->texpaintslot); + } + + if (material_src->gp_style != NULL) { + material_dst->gp_style = MEM_dupallocN(material_src->gp_style); + } + + BLI_listbase_clear(&material_dst->gpumaterial); + + /* TODO Duplicate Engine Settings and set runtime to NULL */ +} + +static void material_free_data(ID *id) { - BKE_animdata_free((ID *)ma, false); + Material *material = (Material *)id; + + BKE_animdata_free((ID *)material, false); /* Free gpu material before the ntree */ - GPU_material_free(&ma->gpumaterial); + GPU_material_free(&material->gpumaterial); /* is no lib link block, but material extension */ - if (ma->nodetree) { - ntreeFreeNestedTree(ma->nodetree); - MEM_freeN(ma->nodetree); - ma->nodetree = NULL; + if (material->nodetree) { + ntreeFreeNestedTree(material->nodetree); + MEM_freeN(material->nodetree); + material->nodetree = NULL; } - MEM_SAFE_FREE(ma->texpaintslot); + MEM_SAFE_FREE(material->texpaintslot); - MEM_SAFE_FREE(ma->gp_style); + MEM_SAFE_FREE(material->gp_style); - BKE_icon_id_delete((ID *)ma); - BKE_previewimg_free(&ma->preview); + BKE_icon_id_delete((ID *)material); + BKE_previewimg_free(&material->preview); } +IDTypeInfo IDType_ID_MA = { + .id_code = ID_MA, + .id_filter = FILTER_ID_MA, + .main_listbase_index = INDEX_ID_MA, + .struct_size = sizeof(Material), + .name = "Material", + .name_plural = "materials", + .translation_context = BLT_I18NCONTEXT_ID_MATERIAL, + .flags = 0, + + .init_data = material_init_data, + .copy_data = material_copy_data, + .free_data = material_free_data, + .make_local = NULL, +}; + void BKE_gpencil_material_attr_init(Material *ma) { if ((ma) && (ma->gp_style == NULL)) { @@ -118,20 +180,13 @@ void BKE_gpencil_material_attr_init(Material *ma) } } -void BKE_material_init(Material *ma) -{ - BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ma, id)); - - MEMCPY_STRUCT_AFTER(ma, DNA_struct_default_get(Material), id); -} - Material *BKE_material_add(Main *bmain, const char *name) { Material *ma; ma = BKE_libblock_alloc(bmain, ID_MA, name, 0); - BKE_material_init(ma); + material_init_data(&ma->id); return ma; } @@ -149,45 +204,6 @@ Material *BKE_gpencil_material_add(Main *bmain, const char *name) return ma; } -/** - * Only copy internal data of Material ID from source - * to already allocated/initialized destination. - * You probably never want to use tha @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs