Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/texture.c
| Show First 20 Lines • Show All 840 Lines • ▼ Show 20 Lines | MTex *BKE_texture_mtex_add_id(ID *id, int slot) | ||||
| mtex_ar[slot] = BKE_texture_mtex_add(); | mtex_ar[slot] = BKE_texture_mtex_add(); | ||||
| return mtex_ar[slot]; | return mtex_ar[slot]; | ||||
| } | } | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| Tex *BKE_texture_copy(Main *bmain, const Tex *tex) | /** | ||||
| * Only copy internal data of Texture ID from source to already allocated/initialized destination. | |||||
| * You probably nerver want to use that directly, use 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_library.h's LIB_ID_COPY_... flags for more). | |||||
| */ | |||||
| void BKE_texture_copy_data(Main *bmain, Tex *tex_dst, const Tex *tex_src, const int flag) | |||||
| { | { | ||||
| Tex *texn; | /* We never handle usercount here for own data. */ | ||||
| const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT; | |||||
| texn = BKE_libblock_copy(bmain, &tex->id); | if (!BKE_texture_is_image_user(tex_src)) { | ||||
| if (BKE_texture_is_image_user(tex)) { | tex_dst->ima = NULL; | ||||
| id_us_plus((ID *)texn->ima); | |||||
| } | |||||
| else { | |||||
| texn->ima = NULL; | |||||
| } | } | ||||
| if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); | if (tex_dst->coba) { | ||||
| if (texn->env) texn->env = BKE_texture_envmap_copy(texn->env); | tex_dst->coba = MEM_dupallocN(tex_dst->coba); | ||||
| if (texn->pd) texn->pd = BKE_texture_pointdensity_copy(texn->pd); | } | ||||
| if (texn->vd) texn->vd = MEM_dupallocN(texn->vd); | if (tex_dst->env) { | ||||
| if (texn->ot) texn->ot = BKE_texture_ocean_copy(texn->ot); | tex_dst->env = BKE_texture_envmap_copy(tex_dst->env, flag_subdata); | ||||
| } | |||||
| if (tex->nodetree) { | if (tex_dst->pd) { | ||||
| if (tex->nodetree->execdata) { | tex_dst->pd = BKE_texture_pointdensity_copy(tex_dst->pd, flag_subdata); | ||||
| ntreeTexEndExecTree(tex->nodetree->execdata); | } | ||||
| if (tex_dst->vd) { | |||||
| tex_dst->vd = MEM_dupallocN(tex_dst->vd); | |||||
| } | } | ||||
| texn->nodetree = ntreeCopyTree(bmain, tex->nodetree); | if (tex_dst->ot) { | ||||
| tex_dst->ot = BKE_texture_ocean_copy(tex_dst->ot, flag_subdata); | |||||
| } | } | ||||
| BKE_previewimg_id_copy(&texn->id, &tex->id); | if (tex_src->nodetree) { | ||||
| if (tex_src->nodetree->execdata) { | |||||
| ntreeTexEndExecTree(tex_src->nodetree->execdata); | |||||
| } | |||||
| BKE_id_copy_ex(bmain, (ID *)tex_src->nodetree, (ID **)&tex_dst->nodetree, flag, false); | |||||
| } | |||||
| BKE_id_copy_ensure_local(bmain, &tex->id, &texn->id); | if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) { | ||||
| BKE_previewimg_id_copy(&tex_dst->id, &tex_src->id); | |||||
| } | |||||
| else { | |||||
| tex_dst->preview = NULL; | |||||
| } | |||||
| } | |||||
| return texn; | Tex *BKE_texture_copy(Main *bmain, const Tex *tex) | ||||
| { | |||||
| Tex *tex_copy; | |||||
| BKE_id_copy_ex(bmain, &tex->id, (ID **)&tex_copy, 0, false); | |||||
| return tex_copy; | |||||
| } | } | ||||
| /* texture copy without adding to main dbase */ | /* texture copy without adding to main dbase */ | ||||
| Tex *BKE_texture_localize(Tex *tex) | Tex *BKE_texture_localize(Tex *tex) | ||||
| { | { | ||||
| /* TODO replace with something like | |||||
| * Tex *tex_copy; | |||||
| * BKE_id_copy_ex(bmain, &tex->id, (ID **)&tex_copy, LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT, false); | |||||
| * return tex_copy; | |||||
| * | |||||
| * ... Once f*** nodes are fully converted to that too :( */ | |||||
| Tex *texn; | Tex *texn; | ||||
| texn = BKE_libblock_copy_nolib(&tex->id, false); | texn = BKE_libblock_copy_nolib(&tex->id, false); | ||||
| /* image texture: BKE_texture_free also doesn't decrease */ | /* image texture: BKE_texture_free also doesn't decrease */ | ||||
| if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); | if (texn->coba) texn->coba = MEM_dupallocN(texn->coba); | ||||
| if (texn->env) { | if (texn->env) { | ||||
| texn->env = BKE_texture_envmap_copy(texn->env); | texn->env = BKE_texture_envmap_copy(texn->env, LIB_ID_COPY_NO_USER_REFCOUNT); | ||||
| id_us_min(&texn->env->ima->id); | id_us_min(&texn->env->ima->id); | ||||
| } | } | ||||
| if (texn->pd) texn->pd = BKE_texture_pointdensity_copy(texn->pd); | if (texn->pd) texn->pd = BKE_texture_pointdensity_copy(texn->pd, LIB_ID_COPY_NO_USER_REFCOUNT); | ||||
| if (texn->vd) { | if (texn->vd) { | ||||
| texn->vd = MEM_dupallocN(texn->vd); | texn->vd = MEM_dupallocN(texn->vd); | ||||
| if (texn->vd->dataset) | if (texn->vd->dataset) | ||||
| texn->vd->dataset = MEM_dupallocN(texn->vd->dataset); | texn->vd->dataset = MEM_dupallocN(texn->vd->dataset); | ||||
| } | } | ||||
| if (texn->ot) { | if (texn->ot) { | ||||
| texn->ot = BKE_texture_ocean_copy(tex->ot); | texn->ot = BKE_texture_ocean_copy(tex->ot, LIB_ID_COPY_NO_USER_REFCOUNT); | ||||
| } | } | ||||
| texn->preview = NULL; | texn->preview = NULL; | ||||
| if (tex->nodetree) { | if (tex->nodetree) { | ||||
| texn->nodetree = ntreeLocalize(tex->nodetree); | texn->nodetree = ntreeLocalize(tex->nodetree); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | EnvMap *BKE_texture_envmap_add(void) | ||||
| env->cuberes = 512; | env->cuberes = 512; | ||||
| env->viewscale = 0.5; | env->viewscale = 0.5; | ||||
| return env; | return env; | ||||
| } | } | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| EnvMap *BKE_texture_envmap_copy(const EnvMap *env) | EnvMap *BKE_texture_envmap_copy(const EnvMap *env, const int flag) | ||||
| { | { | ||||
| EnvMap *envn; | EnvMap *envn; | ||||
| int a; | int a; | ||||
| envn = MEM_dupallocN(env); | envn = MEM_dupallocN(env); | ||||
| envn->ok = 0; | envn->ok = 0; | ||||
| for (a = 0; a < 6; a++) envn->cube[a] = NULL; | for (a = 0; a < 6; a++) { | ||||
| if (envn->ima) id_us_plus((ID *)envn->ima); | envn->cube[a] = NULL; | ||||
| } | |||||
| if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) { | |||||
| id_us_plus((ID *)envn->ima); | |||||
| } | |||||
| return envn; | return envn; | ||||
| } | } | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| void BKE_texture_envmap_free_data(EnvMap *env) | void BKE_texture_envmap_free_data(EnvMap *env) | ||||
| { | { | ||||
| unsigned int part; | unsigned int part; | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| PointDensity *BKE_texture_pointdensity_add(void) | PointDensity *BKE_texture_pointdensity_add(void) | ||||
| { | { | ||||
| PointDensity *pd = MEM_callocN(sizeof(PointDensity), "pointdensity"); | PointDensity *pd = MEM_callocN(sizeof(PointDensity), "pointdensity"); | ||||
| BKE_texture_pointdensity_init_data(pd); | BKE_texture_pointdensity_init_data(pd); | ||||
| return pd; | return pd; | ||||
| } | } | ||||
| PointDensity *BKE_texture_pointdensity_copy(const PointDensity *pd) | PointDensity *BKE_texture_pointdensity_copy(const PointDensity *pd, const int UNUSED(flag)) | ||||
| { | { | ||||
| PointDensity *pdn; | PointDensity *pdn; | ||||
| pdn = MEM_dupallocN(pd); | pdn = MEM_dupallocN(pd); | ||||
| pdn->point_tree = NULL; | pdn->point_tree = NULL; | ||||
| pdn->point_data = NULL; | pdn->point_data = NULL; | ||||
| if (pdn->coba) pdn->coba = MEM_dupallocN(pdn->coba); | if (pdn->coba) { | ||||
| pdn->coba = MEM_dupallocN(pdn->coba); | |||||
| } | |||||
| pdn->falloff_curve = curvemapping_copy(pdn->falloff_curve); /* can be NULL */ | pdn->falloff_curve = curvemapping_copy(pdn->falloff_curve); /* can be NULL */ | ||||
| return pdn; | return pdn; | ||||
| } | } | ||||
| void BKE_texture_pointdensity_free_data(PointDensity *pd) | void BKE_texture_pointdensity_free_data(PointDensity *pd) | ||||
| { | { | ||||
| if (pd->point_tree) { | if (pd->point_tree) { | ||||
| BLI_bvhtree_free(pd->point_tree); | BLI_bvhtree_free(pd->point_tree); | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | OceanTex *BKE_texture_ocean_add(void) | ||||
| ot = MEM_callocN(sizeof(struct OceanTex), "ocean texture"); | ot = MEM_callocN(sizeof(struct OceanTex), "ocean texture"); | ||||
| ot->output = TEX_OCN_DISPLACEMENT; | ot->output = TEX_OCN_DISPLACEMENT; | ||||
| ot->object = NULL; | ot->object = NULL; | ||||
| return ot; | return ot; | ||||
| } | } | ||||
| OceanTex *BKE_texture_ocean_copy(const OceanTex *ot) | OceanTex *BKE_texture_ocean_copy(const OceanTex *ot, const int UNUSED(flag)) | ||||
| { | { | ||||
| OceanTex *otn = MEM_dupallocN(ot); | OceanTex *otn = MEM_dupallocN(ot); | ||||
| return otn; | return otn; | ||||
| } | } | ||||
| void BKE_texture_ocean_free(struct OceanTex *ot) | void BKE_texture_ocean_free(struct OceanTex *ot) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines | |||||