Cleanup: Material: Move to IDTypeInfo and remove unused BKE API.
This commit is contained in:
parent
ae6a5629a5
commit
a7fb567c18
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
BKE_animdata_free((ID *)ma, false);
|
||||
Material *material = (Material *)id;
|
||||
|
||||
/* Free gpu material before the ntree */
|
||||
GPU_material_free(&ma->gpumaterial);
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(material, id));
|
||||
|
||||
/* is no lib link block, but material extension */
|
||||
if (ma->nodetree) {
|
||||
ntreeFreeNestedTree(ma->nodetree);
|
||||
MEM_freeN(ma->nodetree);
|
||||
ma->nodetree = NULL;
|
||||
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);
|
||||
}
|
||||
|
||||
MEM_SAFE_FREE(ma->texpaintslot);
|
||||
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
|
||||
BKE_previewimg_id_copy(&material_dst->id, &material_src->id);
|
||||
}
|
||||
else {
|
||||
material_dst->preview = NULL;
|
||||
}
|
||||
|
||||
MEM_SAFE_FREE(ma->gp_style);
|
||||
if (material_src->texpaintslot != NULL) {
|
||||
material_dst->texpaintslot = MEM_dupallocN(material_src->texpaintslot);
|
||||
}
|
||||
|
||||
BKE_icon_id_delete((ID *)ma);
|
||||
BKE_previewimg_free(&ma->preview);
|
||||
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)
|
||||
{
|
||||
Material *material = (Material *)id;
|
||||
|
||||
BKE_animdata_free((ID *)material, false);
|
||||
|
||||
/* Free gpu material before the ntree */
|
||||
GPU_material_free(&material->gpumaterial);
|
||||
|
||||
/* is no lib link block, but material extension */
|
||||
if (material->nodetree) {
|
||||
ntreeFreeNestedTree(material->nodetree);
|
||||
MEM_freeN(material->nodetree);
|
||||
material->nodetree = NULL;
|
||||
}
|
||||
|
||||
MEM_SAFE_FREE(material->texpaintslot);
|
||||
|
||||
MEM_SAFE_FREE(material->gp_style);
|
||||
|
||||
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 that directly,
|
||||
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
|
||||
*
|
||||
* WARNING! This function will not handle ID user count!
|
||||
*
|
||||
* \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
|
||||
*/
|
||||
void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_src, const int flag)
|
||||
{
|
||||
/* We always need allocation of our private ID data. */
|
||||
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
|
||||
|
||||
if (ma_src->nodetree) {
|
||||
BKE_id_copy_ex(bmain, (ID *)ma_src->nodetree, (ID **)&ma_dst->nodetree, flag_private_id_data);
|
||||
}
|
||||
|
||||
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
|
||||
BKE_previewimg_id_copy(&ma_dst->id, &ma_src->id);
|
||||
}
|
||||
else {
|
||||
ma_dst->preview = NULL;
|
||||
}
|
||||
|
||||
if (ma_src->texpaintslot != NULL) {
|
||||
ma_dst->texpaintslot = MEM_dupallocN(ma_src->texpaintslot);
|
||||
}
|
||||
|
||||
if (ma_src->gp_style != NULL) {
|
||||
ma_dst->gp_style = MEM_dupallocN(ma_src->gp_style);
|
||||
}
|
||||
|
||||
BLI_listbase_clear(&ma_dst->gpumaterial);
|
||||
|
||||
/* TODO Duplicate Engine Settings and set runtime to NULL */
|
||||
}
|
||||
|
||||
Material *BKE_material_copy(Main *bmain, const Material *ma)
|
||||
{
|
||||
Material *ma_copy;
|
||||
|
@ -230,11 +246,6 @@ Material *BKE_material_localize(Material *ma)
|
|||
return man;
|
||||
}
|
||||
|
||||
void BKE_material_make_local(Main *bmain, Material *ma, const int flags)
|
||||
{
|
||||
BKE_lib_id_make_local_generic(bmain, &ma->id, flags);
|
||||
}
|
||||
|
||||
Material ***BKE_object_material_array_p(Object *ob)
|
||||
{
|
||||
Mesh *me;
|
||||
|
@ -1686,7 +1697,7 @@ void BKE_material_defaults_free_gpu(void)
|
|||
void BKE_materials_init(void)
|
||||
{
|
||||
for (int i = 0; default_materials[i]; i++) {
|
||||
BKE_material_init(default_materials[i]);
|
||||
material_init_data(&default_materials[i]->id);
|
||||
}
|
||||
|
||||
material_default_surface_init(&default_material_surface);
|
||||
|
@ -1697,6 +1708,6 @@ void BKE_materials_init(void)
|
|||
void BKE_materials_exit(void)
|
||||
{
|
||||
for (int i = 0; default_materials[i]; i++) {
|
||||
BKE_material_free(default_materials[i]);
|
||||
material_free_data(&default_materials[i]->id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue