Cleanup: move some files that use nodes to C++

This commit is contained in:
2022-11-18 11:08:39 +01:00
parent bc886bc8d7
commit dec459e424
13 changed files with 752 additions and 704 deletions

View File

@@ -168,7 +168,7 @@ set(SRC
intern/keyconfig.c
intern/lattice.c
intern/lattice_deform.c
intern/layer.c
intern/layer.cc
intern/layer_utils.c
intern/lib_id.c
intern/lib_id_delete.c
@@ -181,14 +181,14 @@ set(SRC
intern/library.c
intern/light.c
intern/lightprobe.c
intern/linestyle.c
intern/linestyle.cc
intern/main.c
intern/main_idmap.c
intern/main_namemap.cc
intern/mask.c
intern/mask_evaluate.c
intern/mask_rasterize.c
intern/material.c
intern/material.cc
intern/mball.cc
intern/mball_tessellate.cc
intern/mesh.cc
@@ -282,7 +282,7 @@ set(SRC
intern/subsurf_ccg.c
intern/text.c
intern/text_suggestions.c
intern/texture.c
intern/texture.cc
intern/tracking.c
intern/tracking_auto.c
intern/tracking_detect.c

View File

@@ -71,7 +71,7 @@ static void object_bases_iterator_next(BLI_Iterator *iter, const int flag);
static LayerCollection *layer_collection_add(ListBase *lb_parent, Collection *collection)
{
LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base");
LayerCollection *lc = MEM_cnew<LayerCollection>("Collection Base");
lc->collection = collection;
lc->local_collections_bits = ~(0);
BLI_addtail(lb_parent, lc);
@@ -94,7 +94,7 @@ static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc)
static Base *object_base_new(Object *ob)
{
Base *base = MEM_callocN(sizeof(Base), "Object Base");
Base *base = MEM_cnew<Base>("Object Base");
base->object = ob;
base->local_view_bits = ~(0);
if (ob->base_flag & BASE_SELECTED) {
@@ -120,7 +120,7 @@ ViewLayer *BKE_view_layer_default_view(const Scene *scene)
}
BLI_assert(scene->view_layers.first);
return scene->view_layers.first;
return static_cast<ViewLayer *>(scene->view_layers.first);
}
ViewLayer *BKE_view_layer_default_render(const Scene *scene)
@@ -132,7 +132,7 @@ ViewLayer *BKE_view_layer_default_render(const Scene *scene)
}
BLI_assert(scene->view_layers.first);
return scene->view_layers.first;
return static_cast<ViewLayer *>(scene->view_layers.first);
}
ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name)
@@ -149,7 +149,7 @@ ViewLayer *BKE_view_layer_find(const Scene *scene, const char *layer_name)
ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene)
{
BLI_assert(scene->view_layers.first);
return scene->view_layers.first;
return static_cast<ViewLayer *>(scene->view_layers.first);
}
static ViewLayer *view_layer_add(const char *name)
@@ -158,7 +158,7 @@ static ViewLayer *view_layer_add(const char *name)
name = DATA_("ViewLayer");
}
ViewLayer *view_layer = MEM_callocN(sizeof(ViewLayer), "View Layer");
ViewLayer *view_layer = MEM_cnew<ViewLayer>("View Layer");
view_layer->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE;
BLI_strncpy_utf8(view_layer->name, name, sizeof(view_layer->name));
@@ -176,7 +176,8 @@ static ViewLayer *view_layer_add(const char *name)
static void layer_collection_exclude_all(LayerCollection *layer_collection)
{
LayerCollection *sub_collection = layer_collection->layer_collections.first;
LayerCollection *sub_collection = static_cast<LayerCollection *>(
layer_collection->layer_collections.first);
for (; sub_collection != NULL; sub_collection = sub_collection->next) {
sub_collection->flag |= LAYER_COLLECTION_EXCLUDE;
layer_collection_exclude_all(sub_collection);
@@ -204,7 +205,7 @@ ViewLayer *BKE_view_layer_add(Scene *scene,
}
case VIEWLAYER_ADD_COPY: {
/* Allocate and copy view layer data */
view_layer_new = MEM_callocN(sizeof(ViewLayer), "View Layer");
view_layer_new = MEM_cnew<ViewLayer>("View Layer");
*view_layer_new = *view_layer_source;
BKE_view_layer_copy_data(scene, scene, view_layer_new, view_layer_source, 0);
BLI_addtail(&scene->view_layers, view_layer_new);
@@ -218,7 +219,8 @@ ViewLayer *BKE_view_layer_add(Scene *scene,
/* Initialize layer-collections. */
BKE_layer_collection_sync(scene, view_layer_new);
layer_collection_exclude_all(view_layer_new->layer_collections.first);
layer_collection_exclude_all(
static_cast<LayerCollection *>(view_layer_new->layer_collections.first));
/* Update collections after changing visibility */
BKE_layer_collection_sync(scene, view_layer_new);
@@ -387,7 +389,7 @@ Base *BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
view_layer_bases_hash_create(view_layer, false);
}
return BLI_ghash_lookup(view_layer->object_bases_hash, ob);
return static_cast<Base *>(BLI_ghash_lookup(view_layer->object_bases_hash, ob));
}
void BKE_view_layer_base_deselect_all(const Scene *scene, ViewLayer *view_layer)
@@ -421,8 +423,8 @@ static void layer_aov_copy_data(ViewLayer *view_layer_dst,
BLI_duplicatelist(aovs_dst, aovs_src);
}
ViewLayerAOV *aov_dst = aovs_dst->first;
const ViewLayerAOV *aov_src = aovs_src->first;
ViewLayerAOV *aov_dst = static_cast<ViewLayerAOV *>(aovs_dst->first);
const ViewLayerAOV *aov_src = static_cast<const ViewLayerAOV *>(aovs_src->first);
while (aov_dst != NULL) {
BLI_assert(aov_src);
@@ -444,8 +446,9 @@ static void layer_lightgroup_copy_data(ViewLayer *view_layer_dst,
BLI_duplicatelist(lightgroups_dst, lightgroups_src);
}
ViewLayerLightgroup *lightgroup_dst = lightgroups_dst->first;
const ViewLayerLightgroup *lightgroup_src = lightgroups_src->first;
ViewLayerLightgroup *lightgroup_dst = static_cast<ViewLayerLightgroup *>(lightgroups_dst->first);
const ViewLayerLightgroup *lightgroup_src = static_cast<const ViewLayerLightgroup *>(
lightgroups_src->first);
while (lightgroup_dst != NULL) {
BLI_assert(lightgroup_src);
@@ -465,8 +468,10 @@ static void layer_collections_copy_data(ViewLayer *view_layer_dst,
{
BLI_duplicatelist(layer_collections_dst, layer_collections_src);
LayerCollection *layer_collection_dst = layer_collections_dst->first;
const LayerCollection *layer_collection_src = layer_collections_src->first;
LayerCollection *layer_collection_dst = static_cast<LayerCollection *>(
layer_collections_dst->first);
const LayerCollection *layer_collection_src = static_cast<const LayerCollection *>(
layer_collections_src->first);
while (layer_collection_dst != NULL) {
layer_collections_copy_data(view_layer_dst,
@@ -508,7 +513,7 @@ void BKE_view_layer_copy_data(Scene *scene_dst,
BLI_assert_msg((view_layer_src->flag & VIEW_LAYER_OUT_OF_SYNC) == 0,
"View Layer Object Base out of sync, invoke BKE_view_layer_synced_ensure.");
LISTBASE_FOREACH (const Base *, base_src, &view_layer_src->object_bases) {
Base *base_dst = MEM_dupallocN(base_src);
Base *base_dst = static_cast<Base *>(MEM_dupallocN(base_src));
BLI_addtail(&view_layer_dst->object_bases, base_dst);
if (view_layer_src->basact == base_src) {
view_layer_dst->basact = base_dst;
@@ -521,7 +526,8 @@ void BKE_view_layer_copy_data(Scene *scene_dst,
&view_layer_dst->layer_collections,
&view_layer_src->layer_collections);
LayerCollection *lc_scene_dst = view_layer_dst->layer_collections.first;
LayerCollection *lc_scene_dst = static_cast<LayerCollection *>(
view_layer_dst->layer_collections.first);
lc_scene_dst->collection = scene_dst->master_collection;
BLI_listbase_clear(&view_layer_dst->aovs);
@@ -555,7 +561,7 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con
bNode *node;
int index = BLI_findindex(&scene->view_layers, view_layer);
for (node = scene->nodetree->nodes.first; node; node = node->next) {
for (node = static_cast<bNode *>(scene->nodetree->nodes.first); node; node = node->next) {
if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
if (node->custom1 == index) {
BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR);
@@ -568,7 +574,7 @@ void BKE_view_layer_rename(Main *bmain, Scene *scene, ViewLayer *view_layer, con
BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name);
/* WM can be missing on startup. */
wmWindowManager *wm = bmain->wm.first;
wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
if (wm) {
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
if (win->scene == scene && STREQ(win->view_layer_name, oldname)) {
@@ -620,7 +626,7 @@ static bool layer_collection_hidden(ViewLayer *view_layer, LayerCollection *lc)
}
/* Restriction flags stay set, so we need to check parents */
CollectionParent *parent = lc->collection->parents.first;
CollectionParent *parent = static_cast<CollectionParent *>(lc->collection->parents.first);
if (parent) {
lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection);
@@ -656,7 +662,7 @@ bool BKE_layer_collection_activate(ViewLayer *view_layer, LayerCollection *lc)
LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, LayerCollection *lc)
{
CollectionParent *parent = lc->collection->parents.first;
CollectionParent *parent = static_cast<CollectionParent *>(lc->collection->parents.first);
if (parent) {
lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection);
@@ -672,7 +678,7 @@ LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, Lay
}
if (!lc) {
lc = view_layer->layer_collections.first;
lc = static_cast<LayerCollection *>(view_layer->layer_collections.first);
}
view_layer->active_collection = lc;
@@ -808,7 +814,8 @@ typedef struct LayerCollectionResync {
static LayerCollectionResync *layer_collection_resync_create_recurse(
LayerCollectionResync *parent_layer_resync, LayerCollection *layer, BLI_mempool *mempool)
{
LayerCollectionResync *layer_resync = BLI_mempool_calloc(mempool);
LayerCollectionResync *layer_resync = static_cast<LayerCollectionResync *>(
BLI_mempool_calloc(mempool));
layer_resync->layer = layer;
layer_resync->collection = layer->collection;
@@ -984,7 +991,8 @@ void BKE_scene_view_layers_synced_ensure(const Scene *scene)
void BKE_main_view_layers_synced_ensure(const Main *bmain)
{
for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
for (const Scene *scene = static_cast<const Scene *>(bmain->scenes.first); scene;
scene = static_cast<const Scene *>(scene->id.next)) {
BKE_scene_view_layers_synced_ensure(scene);
}
@@ -1019,7 +1027,7 @@ static void layer_collection_objects_sync(ViewLayer *view_layer,
/* Move from old base list to new base list. Base might have already
* been moved to the new base list and the first/last test ensure that
* case also works. */
base = *base_p;
base = static_cast<Base *>(*base_p);
if (!ELEM(base, r_lb_new_object_bases->first, r_lb_new_object_bases->last)) {
BLI_remlink(&view_layer->object_bases, base);
BLI_addtail(r_lb_new_object_bases, base);
@@ -1137,7 +1145,8 @@ static void layer_collection_sync(ViewLayer *view_layer,
LayerCollection *child_layer = layer_collection_add(&new_lb_layer, child_collection);
child_layer->flag = parent_layer_flag;
child_layer_resync = BLI_mempool_calloc(layer_resync_mempool);
child_layer_resync = static_cast<LayerCollectionResync *>(
BLI_mempool_calloc(layer_resync_mempool));
child_layer_resync->collection = child_collection;
child_layer_resync->layer = child_layer;
child_layer_resync->is_usable = true;
@@ -1215,7 +1224,7 @@ static bool view_layer_objects_base_cache_validate(ViewLayer *view_layer, LayerC
bool is_valid = true;
if (layer == NULL) {
layer = view_layer->layer_collections.first;
layer = static_cast<LayerCollection *>(view_layer->layer_collections.first);
}
/* Only check for a collection's objects if its layer is not excluded. */
@@ -1257,7 +1266,8 @@ static bool view_layer_objects_base_cache_validate(ViewLayer *UNUSED(view_layer)
void BKE_layer_collection_doversion_2_80(const Scene *scene, ViewLayer *view_layer)
{
LayerCollection *first_layer_collection = view_layer->layer_collections.first;
LayerCollection *first_layer_collection = static_cast<LayerCollection *>(
view_layer->layer_collections.first);
if (BLI_listbase_count_at_most(&view_layer->layer_collections, 2) > 1 ||
first_layer_collection->collection != scene->master_collection) {
/* In some cases (from older files) we do have a master collection, but no matching layer,
@@ -1296,7 +1306,8 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
"ViewLayer's first level of children layer collections should always have "
"exactly one item");
LayerCollection *first_layer_collection = view_layer->layer_collections.first;
LayerCollection *first_layer_collection = static_cast<LayerCollection *>(
view_layer->layer_collections.first);
BLI_assert_msg(first_layer_collection->collection == scene->master_collection,
"ViewLayer's first layer collection should always be the one for the scene's "
"master collection");
@@ -1322,10 +1333,12 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
BLI_mempool *layer_resync_mempool = BLI_mempool_create(
sizeof(LayerCollectionResync), 1024, 1024, BLI_MEMPOOL_NOP);
LayerCollectionResync *master_layer_resync = layer_collection_resync_create_recurse(
NULL, view_layer->layer_collections.first, layer_resync_mempool);
NULL,
static_cast<LayerCollection *>(view_layer->layer_collections.first),
layer_resync_mempool);
/* Generate new layer connections and object bases when collections changed. */
ListBase new_object_bases = {.first = NULL, .last = NULL};
ListBase new_object_bases{};
const short parent_exclude = 0, parent_restrict = 0, parent_layer_restrict = 0;
layer_collection_sync(view_layer,
master_layer_resync,
@@ -1372,7 +1385,8 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
BKE_layer_collection_activate_parent(view_layer, active);
}
else if (active == NULL) {
view_layer->active_collection = view_layer->layer_collections.first;
view_layer->active_collection = static_cast<LayerCollection *>(
view_layer->layer_collections.first);
}
}
@@ -1398,7 +1412,8 @@ void BKE_main_collection_sync(const Main *bmain)
/* TODO: optimize for file load so only linked collections get checked? */
for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
for (const Scene *scene = static_cast<const Scene *>(bmain->scenes.first); scene;
scene = static_cast<const Scene *>(scene->id.next)) {
BKE_scene_collection_sync(scene);
}
@@ -1414,7 +1429,8 @@ void BKE_main_collection_sync_remap(const Main *bmain)
/* On remapping of object or collection pointers free caches. */
/* TODO: try to make this faster */
for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
for (Scene *scene = static_cast<Scene *>(bmain->scenes.first); scene;
scene = static_cast<Scene *>(scene->id.next)) {
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
MEM_SAFE_FREE(view_layer->object_bases_array);
@@ -1434,8 +1450,8 @@ void BKE_main_collection_sync_remap(const Main *bmain)
DEG_id_tag_update_ex((Main *)bmain, &scene->id, ID_RECALC_COPY_ON_WRITE);
}
for (Collection *collection = bmain->collections.first; collection;
collection = collection->id.next) {
for (Collection *collection = static_cast<Collection *>(bmain->collections.first); collection;
collection = static_cast<Collection *>(collection->id.next)) {
BKE_collection_object_cache_free(collection);
DEG_id_tag_update_ex((Main *)bmain, &collection->id, ID_RECALC_COPY_ON_WRITE);
}
@@ -1639,7 +1655,7 @@ void BKE_layer_collection_isolate_global(Scene *UNUSED(scene),
LayerCollection *lc,
bool extend)
{
LayerCollection *lc_master = view_layer->layer_collections.first;
LayerCollection *lc_master = static_cast<LayerCollection *>(view_layer->layer_collections.first);
bool hide_it = extend && (lc->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER);
if (!extend) {
@@ -1761,7 +1777,7 @@ void BKE_layer_collection_local_sync_all(const Main *bmain)
if (area->spacetype != SPACE_VIEW3D) {
continue;
}
View3D *v3d = area->spacedata.first;
View3D *v3d = static_cast<View3D *>(area->spacedata.first);
if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
BKE_layer_collection_local_sync(scene, view_layer, v3d);
}
@@ -1774,7 +1790,7 @@ void BKE_layer_collection_local_sync_all(const Main *bmain)
void BKE_layer_collection_isolate_local(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d, LayerCollection *lc, bool extend)
{
LayerCollection *lc_master = view_layer->layer_collections.first;
LayerCollection *lc_master = static_cast<LayerCollection *>(view_layer->layer_collections.first);
bool hide_it = extend && ((v3d->local_collections_uuid & lc->local_collections_bits) != 0);
if (!extend) {
@@ -1992,10 +2008,10 @@ static bool object_bases_iterator_is_valid(const View3D *v3d, Base *base, const
static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, const int flag)
{
ObjectsVisibleIteratorData *data_in = data_in_v;
ObjectsVisibleIteratorData *data_in = static_cast<ObjectsVisibleIteratorData *>(data_in_v);
ViewLayer *view_layer = data_in->view_layer;
const View3D *v3d = data_in->v3d;
Base *base = BKE_view_layer_object_bases_get(view_layer)->first;
Base *base = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first);
/* when there are no objects */
if (base == NULL) {
@@ -2004,7 +2020,7 @@ static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, con
return;
}
LayerObjectBaseIteratorData *data = MEM_callocN(sizeof(LayerObjectBaseIteratorData), __func__);
LayerObjectBaseIteratorData *data = MEM_cnew<LayerObjectBaseIteratorData>(__func__);
iter->data = data;
data->v3d = v3d;
@@ -2020,7 +2036,7 @@ static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, con
static void object_bases_iterator_next(BLI_Iterator *iter, const int flag)
{
LayerObjectBaseIteratorData *data = iter->data;
LayerObjectBaseIteratorData *data = static_cast<LayerObjectBaseIteratorData *>(iter->data);
Base *base = data->base->next;
while (base) {
@@ -2199,7 +2215,7 @@ static bool base_is_in_mode(struct ObjectsInModeIteratorData *data, Base *base)
void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in)
{
struct ObjectsInModeIteratorData *data = data_in;
struct ObjectsInModeIteratorData *data = static_cast<ObjectsInModeIteratorData *>(data_in);
Base *base = data->base_active;
/* In this case the result will always be empty, the caller must check for no mode. */
@@ -2225,12 +2241,12 @@ void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_
void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter)
{
struct ObjectsInModeIteratorData *data = iter->data;
Base *base = iter->current;
struct ObjectsInModeIteratorData *data = static_cast<ObjectsInModeIteratorData *>(iter->data);
Base *base = static_cast<Base *>(iter->current);
if (base == data->base_active) {
/* first step */
base = data->view_layer->object_bases.first;
base = static_cast<Base *>(data->view_layer->object_bases.first);
if ((base == data->base_active) && BKE_base_is_visible(data->v3d, base)) {
base = base->next;
}
@@ -2303,8 +2319,8 @@ static void layer_eval_view_layer(struct Depsgraph *depsgraph,
BKE_view_layer_synced_ensure(scene, view_layer);
const int num_object_bases = BLI_listbase_count(BKE_view_layer_object_bases_get(view_layer));
MEM_SAFE_FREE(view_layer->object_bases_array);
view_layer->object_bases_array = MEM_malloc_arrayN(
num_object_bases, sizeof(Base *), "view_layer->object_bases_array");
view_layer->object_bases_array = static_cast<Base **>(
MEM_malloc_arrayN(num_object_bases, sizeof(Base *), "view_layer->object_bases_array"));
int base_index = 0;
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
view_layer->object_bases_array[base_index++] = base;
@@ -2316,7 +2332,8 @@ void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph,
int view_layer_index)
{
BLI_assert(view_layer_index >= 0);
ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index);
ViewLayer *view_layer = static_cast<ViewLayer *>(
BLI_findlink(&scene->view_layers, view_layer_index));
BLI_assert(view_layer != NULL);
layer_eval_view_layer(depsgraph, scene, view_layer);
}
@@ -2488,7 +2505,7 @@ static void viewlayer_aov_active_set(ViewLayer *view_layer, ViewLayerAOV *aov)
struct ViewLayerAOV *BKE_view_layer_add_aov(struct ViewLayer *view_layer)
{
ViewLayerAOV *aov;
aov = MEM_callocN(sizeof(ViewLayerAOV), __func__);
aov = MEM_cnew<ViewLayerAOV>(__func__);
aov->type = AOV_TYPE_COLOR;
BLI_strncpy(aov->name, DATA_("AOV"), sizeof(aov->name));
BLI_addtail(&view_layer->aovs, aov);
@@ -2525,7 +2542,7 @@ static void bke_view_layer_verify_aov_cb(void *userdata,
const char *UNUSED(chanid),
eNodeSocketDatatype UNUSED(type))
{
GHash *name_count = userdata;
GHash *name_count = static_cast<GHash *>(userdata);
void **value_p;
void *key = BLI_strdup(name);
@@ -2550,7 +2567,7 @@ void BKE_view_layer_verify_aov(struct RenderEngine *engine,
RE_engine_update_render_passes(
engine, scene, view_layer, bke_view_layer_verify_aov_cb, name_count);
LISTBASE_FOREACH (ViewLayerAOV *, aov, &view_layer->aovs) {
void **value_p = BLI_ghash_lookup(name_count, aov->name);
void **value_p = static_cast<void **>(BLI_ghash_lookup(name_count, aov->name));
int count = POINTER_AS_INT(value_p);
SET_FLAG_FROM_TEST(aov->flag, count > 1, AOV_CONFLICT);
}
@@ -2612,7 +2629,7 @@ struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer *view
const char *name)
{
ViewLayerLightgroup *lightgroup;
lightgroup = MEM_callocN(sizeof(ViewLayerLightgroup), __func__);
lightgroup = MEM_cnew<ViewLayerLightgroup>(__func__);
if (name && name[0]) {
BLI_strncpy(lightgroup->name, name, sizeof(lightgroup->name));
}
@@ -2710,7 +2727,7 @@ void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char
{
if (name[0] != '\0') {
if (*lgm == NULL) {
*lgm = MEM_callocN(sizeof(LightgroupMembership), __func__);
*lgm = MEM_cnew<LightgroupMembership>(__func__);
}
BLI_strncpy((*lgm)->name, name, sizeof((*lgm)->name));
}

View File

@@ -47,7 +47,7 @@ static void linestyle_init_data(ID *id)
MEMCPY_STRUCT_AFTER(linestyle, DNA_struct_default_get(FreestyleLineStyle), id);
BKE_linestyle_geometry_modifier_add(linestyle, NULL, LS_MODIFIER_SAMPLING);
BKE_linestyle_geometry_modifier_add(linestyle, nullptr, LS_MODIFIER_SAMPLING);
}
static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
@@ -62,8 +62,8 @@ static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const
for (int a = 0; a < MAX_MTEX; a++) {
if (linestyle_src->mtex[a]) {
linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__);
*linestyle_dst->mtex[a] = *linestyle_src->mtex[a];
linestyle_dst->mtex[a] = MEM_new<MTex>(__func__);
*linestyle_dst->mtex[a] = blender::dna::shallow_copy(*linestyle_src->mtex[a]);
}
}
@@ -118,7 +118,7 @@ static void linestyle_free_data(ID *id)
if (linestyle->nodetree) {
ntreeFreeEmbeddedTree(linestyle->nodetree);
MEM_freeN(linestyle->nodetree);
linestyle->nodetree = NULL;
linestyle->nodetree = nullptr;
}
while ((linestyle_modifier = (LineStyleModifier *)linestyle->color_modifiers.first)) {
@@ -184,7 +184,7 @@ static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modif
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
@@ -216,7 +216,7 @@ static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modif
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
@@ -253,7 +253,7 @@ static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modif
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
@@ -285,7 +285,7 @@ static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modif
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve);
@@ -321,7 +321,7 @@ static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *m
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
@@ -356,7 +356,7 @@ static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *m
}
BLO_write_struct_by_id(writer, struct_nr, m);
}
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
switch (m->type) {
case LS_MODIFIER_ALONG_STROKE:
BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve);
@@ -390,7 +390,7 @@ static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *mo
{
LineStyleModifier *m;
for (m = modifiers->first; m; m = m->next) {
for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) {
int struct_nr;
switch (m->type) {
case LS_MODIFIER_SAMPLING:
@@ -732,60 +732,42 @@ static void linestyle_blend_read_expand(BlendExpander *expander, ID *id)
}
IDTypeInfo IDType_ID_LS = {
.id_code = ID_LS,
.id_filter = FILTER_ID_LS,
.main_listbase_index = INDEX_ID_LS,
.struct_size = sizeof(FreestyleLineStyle),
.name = "FreestyleLineStyle",
.name_plural = "linestyles",
.translation_context = BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE,
.flags = IDTYPE_FLAGS_APPEND_IS_REUSABLE,
.asset_type_info = NULL,
/* id_code */ ID_LS,
/* id_filter */ FILTER_ID_LS,
/* main_listbase_index */ INDEX_ID_LS,
/* struct_size */ sizeof(FreestyleLineStyle),
/* name */ "FreestyleLineStyle",
/* name_plural */ "linestyles",
/* translation_context */ BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE,
/* flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
/* asset_type_info */ nullptr,
.init_data = linestyle_init_data,
.copy_data = linestyle_copy_data,
.free_data = linestyle_free_data,
.make_local = NULL,
.foreach_id = linestyle_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_pointer_get = NULL,
/* init_data */ linestyle_init_data,
/* copy_data */ linestyle_copy_data,
/* free_data */ linestyle_free_data,
/* make_local */ nullptr,
/* foreach_id */ linestyle_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_pointer_get */ nullptr,
.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,
/* 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,
.blend_read_undo_preserve = NULL,
/* blend_read_undo_preserve */ nullptr,
.lib_override_apply_post = NULL,
/* lib_override_apply_post */ nullptr,
};
static const char *modifier_name[LS_MODIFIER_NUM] = {
NULL,
"Along Stroke",
"Distance from Camera",
"Distance from Object",
"Material",
"Sampling",
"Bezier Curve",
"Sinus Displacement",
"Spatial Noise",
"Perlin Noise 1D",
"Perlin Noise 2D",
"Backbone Stretcher",
"Tip Remover",
"Calligraphy",
"Polygonalization",
"Guiding Lines",
"Blueprint",
"2D Offset",
"2D Transform",
"Tangent",
"Noise",
"Crease Angle",
"Simplification",
"Curvature 3D",
nullptr, "Along Stroke", "Distance from Camera", "Distance from Object",
"Material", "Sampling", "Bezier Curve", "Sinus Displacement",
"Spatial Noise", "Perlin Noise 1D", "Perlin Noise 2D", "Backbone Stretcher",
"Tip Remover", "Calligraphy", "Polygonalization", "Guiding Lines",
"Blueprint", "2D Offset", "2D Transform", "Tangent",
"Noise", "Crease Angle", "Simplification", "Curvature 3D",
};
void BKE_linestyle_init(FreestyleLineStyle *linestyle)
@@ -808,7 +790,7 @@ FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer)
{
FreestyleConfig *config = &view_layer->freestyle_config;
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
return (lineset) ? lineset->linestyle : NULL;
return (lineset) ? lineset->linestyle : nullptr;
}
static LineStyleModifier *new_modifier(const char *name, int type, size_t size)
@@ -864,7 +846,7 @@ static LineStyleModifier *alloc_color_modifier(const char *name, int type)
size = sizeof(LineStyleColorModifier_Curvature_3D);
break;
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
return new_modifier(name, type, size);
@@ -877,8 +859,8 @@ LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyl
LineStyleModifier *m;
m = alloc_color_modifier(name, type);
if (UNLIKELY(m == NULL)) {
return NULL;
if (UNLIKELY(m == nullptr)) {
return nullptr;
}
m->blend = MA_RAMP_BLEND;
@@ -892,7 +874,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyl
((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f;
break;
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
((LineStyleColorModifier_DistanceFromObject *)m)->target = nullptr;
((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = BKE_colorband_add(true);
((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f;
((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f;
@@ -921,7 +903,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyl
((LineStyleColorModifier_Curvature_3D *)m)->max_curvature = 0.5f;
break;
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->color_modifiers, m);
@@ -935,8 +917,8 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
LineStyleModifier *new_m;
new_m = alloc_color_modifier(m->name, m->type);
if (UNLIKELY(new_m == NULL)) {
return NULL;
if (UNLIKELY(new_m == nullptr)) {
return nullptr;
}
new_m->influence = m->influence;
new_m->flags = m->flags;
@@ -946,7 +928,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
case LS_MODIFIER_ALONG_STROKE: {
LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m;
LineStyleColorModifier_AlongStroke *q = (LineStyleColorModifier_AlongStroke *)new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
break;
}
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
@@ -954,7 +936,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
m;
LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *)
new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
q->range_min = p->range_min;
q->range_max = p->range_max;
break;
@@ -968,7 +950,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)q->target);
}
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
q->range_min = p->range_min;
q->range_max = p->range_max;
break;
@@ -976,7 +958,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
case LS_MODIFIER_MATERIAL: {
LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m;
LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
q->flags = p->flags;
q->mat_attr = p->mat_attr;
break;
@@ -984,13 +966,13 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
case LS_MODIFIER_TANGENT: {
LineStyleColorModifier_Tangent *p = (LineStyleColorModifier_Tangent *)m;
LineStyleColorModifier_Tangent *q = (LineStyleColorModifier_Tangent *)new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
break;
}
case LS_MODIFIER_NOISE: {
LineStyleColorModifier_Noise *p = (LineStyleColorModifier_Noise *)m;
LineStyleColorModifier_Noise *q = (LineStyleColorModifier_Noise *)new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
q->amplitude = p->amplitude;
q->period = p->period;
q->seed = p->seed;
@@ -999,7 +981,7 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
case LS_MODIFIER_CREASE_ANGLE: {
LineStyleColorModifier_CreaseAngle *p = (LineStyleColorModifier_CreaseAngle *)m;
LineStyleColorModifier_CreaseAngle *q = (LineStyleColorModifier_CreaseAngle *)new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
q->min_angle = p->min_angle;
q->max_angle = p->max_angle;
break;
@@ -1007,13 +989,13 @@ LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linesty
case LS_MODIFIER_CURVATURE_3D: {
LineStyleColorModifier_Curvature_3D *p = (LineStyleColorModifier_Curvature_3D *)m;
LineStyleColorModifier_Curvature_3D *q = (LineStyleColorModifier_Curvature_3D *)new_m;
q->color_ramp = MEM_dupallocN(p->color_ramp);
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
q->min_curvature = p->min_curvature;
q->max_curvature = p->max_curvature;
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->color_modifiers, new_m);
@@ -1085,7 +1067,7 @@ static LineStyleModifier *alloc_alpha_modifier(const char *name, int type)
size = sizeof(LineStyleAlphaModifier_Curvature_3D);
break;
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
return new_modifier(name, type, size);
}
@@ -1116,7 +1098,7 @@ LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyl
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
m;
p->target = NULL;
p->target = nullptr;
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
p->range_min = 0.0f;
p->range_max = 10000.0f;
@@ -1156,7 +1138,7 @@ LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyl
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->alpha_modifiers, m);
@@ -1252,7 +1234,7 @@ LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linesty
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->alpha_modifiers, new_m);
@@ -1327,7 +1309,7 @@ static LineStyleModifier *alloc_thickness_modifier(const char *name, int type)
size = sizeof(LineStyleThicknessModifier_Curvature_3D);
break;
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
return new_modifier(name, type, size);
@@ -1363,7 +1345,7 @@ LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *line
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
LineStyleThicknessModifier_DistanceFromObject *p =
(LineStyleThicknessModifier_DistanceFromObject *)m;
p->target = NULL;
p->target = nullptr;
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
p->range_min = 0.0f;
p->range_max = 1000.0f;
@@ -1420,7 +1402,7 @@ LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *line
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->thickness_modifiers, m);
@@ -1435,7 +1417,7 @@ LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *lin
new_m = alloc_thickness_modifier(m->name, m->type);
if (!new_m) {
return NULL;
return nullptr;
}
new_m->influence = m->influence;
new_m->flags = m->flags;
@@ -1541,7 +1523,7 @@ LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *lin
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->thickness_modifiers, new_m);
@@ -1630,7 +1612,7 @@ static LineStyleModifier *alloc_geometry_modifier(const char *name, int type)
size = sizeof(LineStyleGeometryModifier_Simplification);
break;
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
return new_modifier(name, type, size);
@@ -1744,7 +1726,7 @@ LineStyleModifier *BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *lines
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->geometry_modifiers, m);
@@ -1882,7 +1864,7 @@ LineStyleModifier *BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *line
break;
}
default:
return NULL; /* unknown modifier type */
return nullptr; /* unknown modifier type */
}
add_to_modifier_list(&linestyle->geometry_modifiers, new_m);
@@ -2010,7 +1992,7 @@ char *BKE_linestyle_path_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand
}
}
printf("BKE_linestyle_path_to_color_ramp: No color ramps correspond to the given pointer.\n");
return NULL;
return nullptr;
}
bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_shading_nodes)
@@ -2019,7 +2001,8 @@ bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_sh
if (linestyle && linestyle->use_nodes && linestyle->nodetree) {
bNode *node;
for (node = linestyle->nodetree->nodes.first; node; node = node->next) {
for (node = static_cast<bNode *>(linestyle->nodetree->nodes.first); node;
node = node->next) {
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
return true;
}
@@ -2028,7 +2011,7 @@ bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_sh
}
else {
if (linestyle && (linestyle->flag & LS_TEXTURE)) {
return (linestyle->mtex[0] != NULL);
return (linestyle->mtex[0] != nullptr);
}
}
return false;
@@ -2040,9 +2023,9 @@ void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linesty
bNodeSocket *fromsock, *tosock;
bNodeTree *ntree;
BLI_assert(linestyle->nodetree == NULL);
BLI_assert(linestyle->nodetree == nullptr);
ntree = ntreeAddTreeEmbedded(NULL, &linestyle->id, "stroke_shader", "ShaderNodeTree");
ntree = ntreeAddTreeEmbedded(nullptr, &linestyle->id, "stroke_shader", "ShaderNodeTree");
uv_along_stroke = nodeAddStaticNode(C, ntree, SH_NODE_UVALONGSTROKE);
uv_along_stroke->locx = 0.0f;
@@ -2061,13 +2044,13 @@ void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linesty
nodeSetActive(ntree, input_texture);
fromsock = BLI_findlink(&uv_along_stroke->outputs, 0); /* UV */
tosock = BLI_findlink(&input_texture->inputs, 0); /* UV */
fromsock = static_cast<bNodeSocket *>(BLI_findlink(&uv_along_stroke->outputs, 0)); /* UV */
tosock = static_cast<bNodeSocket *>(BLI_findlink(&input_texture->inputs, 0)); /* UV */
nodeAddLink(ntree, uv_along_stroke, fromsock, input_texture, tosock);
fromsock = BLI_findlink(&input_texture->outputs, 0); /* Color */
tosock = BLI_findlink(&output_linestyle->inputs, 0); /* Color */
fromsock = static_cast<bNodeSocket *>(BLI_findlink(&input_texture->outputs, 0)); /* Color */
tosock = static_cast<bNodeSocket *>(BLI_findlink(&output_linestyle->inputs, 0)); /* Color */
nodeAddLink(ntree, input_texture, fromsock, output_linestyle, tosock);
BKE_ntree_update_main_tree(CTX_data_main(C), ntree, NULL);
BKE_ntree_update_main_tree(CTX_data_main(C), ntree, nullptr);
}

View File

@@ -92,7 +92,7 @@ static void material_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const
/* 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 != NULL) {
if (material_src->nodetree != nullptr) {
if (is_localized) {
material_dst->nodetree = ntreeLocalize(material_src->nodetree);
}
@@ -109,21 +109,24 @@ static void material_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const
BKE_previewimg_id_copy(&material_dst->id, &material_src->id);
}
else {
material_dst->preview = NULL;
material_dst->preview = nullptr;
}
if (material_src->texpaintslot != NULL) {
if (material_src->texpaintslot != nullptr) {
/* TODO: Think we can also skip copying this data in the more generic `NO_MAIN` case? */
material_dst->texpaintslot = is_localized ? NULL : MEM_dupallocN(material_src->texpaintslot);
material_dst->texpaintslot = is_localized ? nullptr :
static_cast<TexPaintSlot *>(
MEM_dupallocN(material_src->texpaintslot));
}
if (material_src->gp_style != NULL) {
material_dst->gp_style = MEM_dupallocN(material_src->gp_style);
if (material_src->gp_style != nullptr) {
material_dst->gp_style = static_cast<MaterialGPencilStyle *>(
MEM_dupallocN(material_src->gp_style));
}
BLI_listbase_clear(&material_dst->gpumaterial);
/* TODO: Duplicate Engine Settings and set runtime to NULL. */
/* TODO: Duplicate Engine Settings and set runtime to nullptr. */
}
static void material_free_data(ID *id)
@@ -137,7 +140,7 @@ static void material_free_data(ID *id)
if (material->nodetree) {
ntreeFreeEmbeddedTree(material->nodetree);
MEM_freeN(material->nodetree);
material->nodetree = NULL;
material->nodetree = nullptr;
}
MEM_SAFE_FREE(material->texpaintslot);
@@ -154,10 +157,10 @@ static void material_foreach_id(ID *id, LibraryForeachIDData *data)
/* Nodetrees **are owned by IDs**, treat them as mere sub-data and not real ID! */
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
data, BKE_library_foreach_ID_embedded(data, (ID **)&material->nodetree));
if (material->texpaintslot != NULL) {
if (material->texpaintslot != nullptr) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, material->texpaintslot->ima, IDWALK_CB_NOP);
}
if (material->gp_style != NULL) {
if (material->gp_style != nullptr) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, material->gp_style->sima, IDWALK_CB_USER);
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, material->gp_style->ima, IDWALK_CB_USER);
}
@@ -168,7 +171,7 @@ static void material_blend_write(BlendWriter *writer, ID *id, const void *id_add
Material *ma = (Material *)id;
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ma->texpaintslot = NULL;
ma->texpaintslot = nullptr;
BLI_listbase_clear(&ma->gpumaterial);
/* write LibData */
@@ -199,7 +202,7 @@ static void material_blend_read_data(BlendDataReader *reader, ID *id)
BLO_read_data_address(reader, &ma->adt);
BKE_animdata_blend_read_data(reader, ma->adt);
ma->texpaintslot = NULL;
ma->texpaintslot = nullptr;
BLO_read_data_address(reader, &ma->preview);
BKE_previewimg_blend_read(reader, ma->preview);
@@ -215,12 +218,12 @@ static void material_blend_read_lib(BlendLibReader *reader, ID *id)
BLO_read_id_address(reader, ma->id.lib, &ma->ipo); /* XXX deprecated - old animation system */
/* relink grease pencil settings */
if (ma->gp_style != NULL) {
if (ma->gp_style != nullptr) {
MaterialGPencilStyle *gp_style = ma->gp_style;
if (gp_style->sima != NULL) {
if (gp_style->sima != nullptr) {
BLO_read_id_address(reader, ma->id.lib, &gp_style->sima);
}
if (gp_style->ima != NULL) {
if (gp_style->ima != nullptr) {
BLO_read_id_address(reader, ma->id.lib, &gp_style->ima);
}
}
@@ -239,39 +242,40 @@ static void material_blend_read_expand(BlendExpander *expander, ID *id)
}
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 = IDTYPE_FLAGS_APPEND_IS_REUSABLE,
.asset_type_info = NULL,
/* 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 */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
/* asset_type_info */ nullptr,
.init_data = material_init_data,
.copy_data = material_copy_data,
.free_data = material_free_data,
.make_local = NULL,
.foreach_id = material_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_pointer_get = NULL,
/* init_data */ material_init_data,
/* copy_data */ material_copy_data,
/* free_data */ material_free_data,
/* make_local */ nullptr,
/* foreach_id */ material_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_pointer_get */ nullptr,
.blend_write = material_blend_write,
.blend_read_data = material_blend_read_data,
.blend_read_lib = material_blend_read_lib,
.blend_read_expand = material_blend_read_expand,
/* blend_write */ material_blend_write,
/* blend_read_data */ material_blend_read_data,
/* blend_read_lib */ material_blend_read_lib,
/* blend_read_expand */ material_blend_read_expand,
.blend_read_undo_preserve = NULL,
/* blend_read_undo_preserve */ nullptr,
.lib_override_apply_post = NULL,
/* lib_override_apply_post */ nullptr,
};
void BKE_gpencil_material_attr_init(Material *ma)
{
if ((ma) && (ma->gp_style == NULL)) {
ma->gp_style = MEM_callocN(sizeof(MaterialGPencilStyle), "Grease Pencil Material Settings");
if ((ma) && (ma->gp_style == nullptr)) {
ma->gp_style = static_cast<MaterialGPencilStyle *>(
MEM_callocN(sizeof(MaterialGPencilStyle), "Grease Pencil Material Settings"));
MaterialGPencilStyle *gp_style = ma->gp_style;
/* set basic settings */
@@ -291,7 +295,7 @@ Material *BKE_material_add(Main *bmain, const char *name)
{
Material *ma;
ma = BKE_id_new(bmain, ID_MA, name);
ma = static_cast<Material *>(BKE_id_new(bmain, ID_MA, name));
return ma;
}
@@ -303,7 +307,7 @@ Material *BKE_gpencil_material_add(Main *bmain, const char *name)
ma = BKE_material_add(bmain, name);
/* grease pencil settings */
if (ma != NULL) {
if (ma != nullptr) {
BKE_gpencil_material_attr_init(ma);
}
return ma;
@@ -312,67 +316,67 @@ Material *BKE_gpencil_material_add(Main *bmain, const char *name)
Material ***BKE_object_material_array_p(Object *ob)
{
if (ob->type == OB_MESH) {
Mesh *me = ob->data;
Mesh *me = static_cast<Mesh *>(ob->data);
return &(me->mat);
}
if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
Curve *cu = ob->data;
Curve *cu = static_cast<Curve *>(ob->data);
return &(cu->mat);
}
if (ob->type == OB_MBALL) {
MetaBall *mb = ob->data;
MetaBall *mb = static_cast<MetaBall *>(ob->data);
return &(mb->mat);
}
if (ob->type == OB_GPENCIL) {
bGPdata *gpd = ob->data;
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
return &(gpd->mat);
}
if (ob->type == OB_CURVES) {
Curves *curves = ob->data;
Curves *curves = static_cast<Curves *>(ob->data);
return &(curves->mat);
}
if (ob->type == OB_POINTCLOUD) {
PointCloud *pointcloud = ob->data;
PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
return &(pointcloud->mat);
}
if (ob->type == OB_VOLUME) {
Volume *volume = ob->data;
Volume *volume = static_cast<Volume *>(ob->data);
return &(volume->mat);
}
return NULL;
return nullptr;
}
short *BKE_object_material_len_p(Object *ob)
{
if (ob->type == OB_MESH) {
Mesh *me = ob->data;
Mesh *me = static_cast<Mesh *>(ob->data);
return &(me->totcol);
}
if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
Curve *cu = ob->data;
Curve *cu = static_cast<Curve *>(ob->data);
return &(cu->totcol);
}
if (ob->type == OB_MBALL) {
MetaBall *mb = ob->data;
MetaBall *mb = static_cast<MetaBall *>(ob->data);
return &(mb->totcol);
}
if (ob->type == OB_GPENCIL) {
bGPdata *gpd = ob->data;
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
return &(gpd->totcol);
}
if (ob->type == OB_CURVES) {
Curves *curves = ob->data;
Curves *curves = static_cast<Curves *>(ob->data);
return &(curves->totcol);
}
if (ob->type == OB_POINTCLOUD) {
PointCloud *pointcloud = ob->data;
PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
return &(pointcloud->totcol);
}
if (ob->type == OB_VOLUME) {
Volume *volume = ob->data;
Volume *volume = static_cast<Volume *>(ob->data);
return &(volume->totcol);
}
return NULL;
return nullptr;
}
Material ***BKE_id_material_array_p(ID *id)
@@ -398,7 +402,7 @@ Material ***BKE_id_material_array_p(ID *id)
default:
break;
}
return NULL;
return nullptr;
}
short *BKE_id_material_len_p(ID *id)
@@ -424,7 +428,7 @@ short *BKE_id_material_len_p(ID *id)
default:
break;
}
return NULL;
return nullptr;
}
static void material_data_index_remove_id(ID *id, short index)
@@ -462,8 +466,8 @@ bool BKE_object_material_slot_used(Object *object, short actcol)
}
}
ID *ob_data = object->data;
if (ob_data == NULL || !OB_DATA_SUPPORT_ID(GS(ob_data->name))) {
ID *ob_data = static_cast<ID *>(object->data);
if (ob_data == nullptr || !OB_DATA_SUPPORT_ID(GS(ob_data->name))) {
return false;
}
@@ -515,7 +519,7 @@ void BKE_id_materials_copy(Main *bmain, ID *id_src, ID *id_dst)
*materials_len_p_dst = *materials_len_p_src;
if (*materials_len_p_src != 0) {
(*matar_dst) = MEM_dupallocN(*matar_src);
(*matar_dst) = static_cast<Material **>(MEM_dupallocN(*matar_src));
for (int a = 0; a < *materials_len_p_src; a++) {
id_us_plus((ID *)(*matar_dst)[a]);
@@ -531,7 +535,7 @@ void BKE_id_material_resize(Main *bmain, ID *id, short totcol, bool do_id_user)
Material ***matar = BKE_id_material_array_p(id);
short *totcolp = BKE_id_material_len_p(id);
if (matar == NULL) {
if (matar == nullptr) {
return;
}
@@ -545,11 +549,11 @@ void BKE_id_material_resize(Main *bmain, ID *id, short totcol, bool do_id_user)
if (totcol == 0) {
if (*totcolp) {
MEM_freeN(*matar);
*matar = NULL;
*matar = nullptr;
}
}
else {
*matar = MEM_recallocN(*matar, sizeof(void *) * totcol);
*matar = static_cast<Material **>(MEM_recallocN(*matar, sizeof(void *) * totcol));
}
*totcolp = totcol;
@@ -562,7 +566,7 @@ void BKE_id_material_append(Main *bmain, ID *id, Material *ma)
Material ***matar;
if ((matar = BKE_id_material_array_p(id))) {
short *totcol = BKE_id_material_len_p(id);
Material **mat = MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar");
Material **mat = MEM_cnew_array<Material *>((*totcol) + 1, "newmatar");
if (*totcol) {
memcpy(mat, *matar, sizeof(void *) * (*totcol));
}
@@ -584,7 +588,7 @@ void BKE_id_material_append(Main *bmain, ID *id, Material *ma)
Material *BKE_id_material_pop(Main *bmain, ID *id, int index_i)
{
short index = (short)index_i;
Material *ret = NULL;
Material *ret = nullptr;
Material ***matar;
if ((matar = BKE_id_material_array_p(id))) {
short *totcol = BKE_id_material_len_p(id);
@@ -595,7 +599,7 @@ Material *BKE_id_material_pop(Main *bmain, ID *id, int index_i)
if (*totcol <= 1) {
*totcol = 0;
MEM_freeN(*matar);
*matar = NULL;
*matar = nullptr;
}
else {
if (index + 1 != (*totcol)) {
@@ -605,7 +609,7 @@ Material *BKE_id_material_pop(Main *bmain, ID *id, int index_i)
}
(*totcol)--;
*matar = MEM_reallocN(*matar, sizeof(void *) * (*totcol));
*matar = static_cast<Material **>(MEM_reallocN(*matar, sizeof(void *) * (*totcol)));
BKE_objects_materials_test_all(bmain, id);
}
@@ -631,7 +635,7 @@ void BKE_id_material_clear(Main *bmain, ID *id)
*totcol = 0;
if (*matar) {
MEM_freeN(*matar);
*matar = NULL;
*matar = nullptr;
}
BKE_objects_materials_test_all(bmain, id);
@@ -647,14 +651,14 @@ Material **BKE_object_material_get_p(Object *ob, short act)
Material ***matarar, **ma_p;
const short *totcolp;
if (ob == NULL) {
return NULL;
if (ob == nullptr) {
return nullptr;
}
/* if object cannot have material, (totcolp == NULL) */
/* if object cannot have material, (totcolp == nullptr) */
totcolp = BKE_object_material_len_p(ob);
if (totcolp == NULL || *totcolp == 0) {
return NULL;
if (totcolp == nullptr || *totcolp == 0) {
return nullptr;
}
/* Clamp to number of slots if index is out of range, same convention as used for rendering. */
@@ -678,7 +682,7 @@ Material **BKE_object_material_get_p(Object *ob, short act)
ma_p = &(*matarar)[slot_index];
}
else {
ma_p = NULL;
ma_p = nullptr;
}
}
@@ -688,15 +692,15 @@ Material **BKE_object_material_get_p(Object *ob, short act)
Material *BKE_object_material_get(Object *ob, short act)
{
Material **ma_p = BKE_object_material_get_p(ob, act);
return ma_p ? *ma_p : NULL;
return ma_p ? *ma_p : nullptr;
}
static ID *get_evaluated_object_data_with_materials(Object *ob)
{
ID *data = ob->data;
ID *data = static_cast<ID *>(ob->data);
/* Meshes in edit mode need special handling. */
if (ob->type == OB_MESH && ob->mode == OB_MODE_EDIT) {
Mesh *mesh = ob->data;
Mesh *mesh = static_cast<Mesh *>(ob->data);
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
if (mesh->edit_mesh && editmesh_eval_final) {
data = &editmesh_eval_final->id;
@@ -714,7 +718,7 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
const int tot_slots_data = tot_slots_data_ptr ? *tot_slots_data_ptr : 0;
if (tot_slots_data == 0) {
return NULL;
return nullptr;
}
/* Clamp to number of slots if index is out of range, same convention as used for rendering. */
@@ -722,7 +726,7 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
const int tot_slots_object = ob->totcol;
Material ***materials_data_ptr = BKE_id_material_array_p(data);
Material **materials_data = materials_data_ptr ? *materials_data_ptr : NULL;
Material **materials_data = materials_data_ptr ? *materials_data_ptr : nullptr;
Material **materials_object = ob->mat;
/* Check if slot is overwritten by object. */
@@ -730,7 +734,7 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
if (ob->matbits) {
if (ob->matbits[slot_index]) {
Material *material = materials_object[slot_index];
if (material != NULL) {
if (material != nullptr) {
return material;
}
}
@@ -741,7 +745,7 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
Material *material = materials_data[slot_index];
return material;
}
return NULL;
return nullptr;
}
int BKE_object_material_count_eval(Object *ob)
@@ -757,7 +761,7 @@ void BKE_id_material_eval_assign(ID *id, int slot, Material *material)
BLI_assert(slot >= 1);
Material ***materials_ptr = BKE_id_material_array_p(id);
short *len_ptr = BKE_id_material_len_p(id);
if (ELEM(NULL, materials_ptr, len_ptr)) {
if (ELEM(nullptr, materials_ptr, len_ptr)) {
BLI_assert_unreachable();
return;
}
@@ -768,10 +772,11 @@ void BKE_id_material_eval_assign(ID *id, int slot, Material *material)
if (slot_index >= old_length) {
/* Need to grow slots array. */
const int new_length = slot_index + 1;
*materials_ptr = MEM_reallocN(*materials_ptr, sizeof(void *) * new_length);
*materials_ptr = static_cast<Material **>(
MEM_reallocN(*materials_ptr, sizeof(void *) * new_length));
*len_ptr = new_length;
for (int i = old_length; i < new_length; i++) {
(*materials_ptr)[i] = NULL;
(*materials_ptr)[i] = nullptr;
}
}
@@ -781,18 +786,18 @@ void BKE_id_material_eval_assign(ID *id, int slot, Material *material)
void BKE_id_material_eval_ensure_default_slot(ID *id)
{
short *len_ptr = BKE_id_material_len_p(id);
if (len_ptr == NULL) {
if (len_ptr == nullptr) {
return;
}
if (*len_ptr == 0) {
BKE_id_material_eval_assign(id, 1, NULL);
BKE_id_material_eval_assign(id, 1, nullptr);
}
}
Material *BKE_gpencil_material(Object *ob, short act)
{
Material *ma = BKE_object_material_get(ob, act);
if (ma != NULL) {
if (ma != nullptr) {
return ma;
}
@@ -802,8 +807,8 @@ Material *BKE_gpencil_material(Object *ob, short act)
MaterialGPencilStyle *BKE_gpencil_material_settings(Object *ob, short act)
{
Material *ma = BKE_object_material_get(ob, act);
if (ma != NULL) {
if (ma->gp_style == NULL) {
if (ma != nullptr) {
if (ma->gp_style == nullptr) {
BKE_gpencil_material_attr_init(ma);
}
@@ -828,13 +833,13 @@ void BKE_object_material_resize(Main *bmain, Object *ob, const short totcol, boo
if (ob->totcol) {
MEM_freeN(ob->mat);
MEM_freeN(ob->matbits);
ob->mat = NULL;
ob->matbits = NULL;
ob->mat = nullptr;
ob->matbits = nullptr;
}
}
else if (ob->totcol < totcol) {
newmatar = MEM_callocN(sizeof(void *) * totcol, "newmatar");
newmatbits = MEM_callocN(sizeof(char) * totcol, "newmatbits");
newmatar = MEM_cnew_array<Material *>(totcol, "newmatar");
newmatbits = MEM_cnew_array<char>(totcol, "newmatbits");
if (ob->totcol) {
memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol);
memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol);
@@ -863,7 +868,7 @@ void BKE_object_materials_test(Main *bmain, Object *ob, ID *id)
/* make the ob mat-array same size as 'ob->data' mat-array */
const short *totcol;
if (id == NULL || (totcol = BKE_id_material_len_p(id)) == NULL) {
if (id == nullptr || (totcol = BKE_id_material_len_p(id)) == nullptr) {
return;
}
@@ -886,13 +891,14 @@ void BKE_objects_materials_test_all(Main *bmain, ID *id)
Object *ob;
const short *totcol;
if (id == NULL || (totcol = BKE_id_material_len_p(id)) == NULL) {
if (id == nullptr || (totcol = BKE_id_material_len_p(id)) == nullptr) {
return;
}
BKE_main_lock(bmain);
int processed_objects = 0;
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
for (ob = static_cast<Object *>(bmain->objects.first); ob;
ob = static_cast<Object *>(ob->id.next)) {
if (ob->data == id) {
BKE_object_material_resize(bmain, ob, *totcol, false);
processed_objects++;
@@ -922,12 +928,12 @@ void BKE_id_material_assign(Main *bmain, ID *id, Material *ma, short act)
totcolp = BKE_id_material_len_p(id);
matarar = BKE_id_material_array_p(id);
if (totcolp == NULL || matarar == NULL) {
if (totcolp == nullptr || matarar == nullptr) {
return;
}
if (act > *totcolp) {
matar = MEM_callocN(sizeof(void *) * act, "matarray1");
matar = MEM_cnew_array<Material *>(act, "matarray1");
if (*totcolp) {
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
@@ -971,12 +977,12 @@ static void object_material_assign(
totcolp = BKE_object_material_len_p(ob);
matarar = BKE_object_material_array_p(ob);
if (totcolp == NULL || matarar == NULL) {
if (totcolp == nullptr || matarar == nullptr) {
return;
}
if (act > *totcolp) {
matar = MEM_callocN(sizeof(void *) * act, "matarray1");
matar = MEM_cnew_array<Material *>(act, "matarray1");
if (*totcolp) {
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
@@ -989,8 +995,10 @@ static void object_material_assign(
if (act > ob->totcol) {
/* Need more space in the material arrays */
ob->mat = MEM_recallocN_id(ob->mat, sizeof(void *) * act, "matarray2");
ob->matbits = MEM_recallocN_id(ob->matbits, sizeof(char) * act, "matbits1");
ob->mat = static_cast<Material **>(
MEM_recallocN_id(ob->mat, sizeof(void *) * act, "matarray2"));
ob->matbits = static_cast<char *>(
MEM_recallocN_id(ob->matbits, sizeof(char) * act, "matbits1"));
ob->totcol = act;
}
@@ -1028,7 +1036,7 @@ static void object_material_assign(
id_us_min(&mao->id);
}
ob->mat[act - 1] = ma;
BKE_object_materials_test(bmain, ob, ob->data);
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
}
else { /* in data */
mao = (*matarar)[act - 1];
@@ -1038,7 +1046,7 @@ static void object_material_assign(
(*matarar)[act - 1] = ma;
/* Data may be used by several objects. */
if (do_test_all) {
BKE_objects_materials_test_all(bmain, ob->data);
BKE_objects_materials_test_all(bmain, static_cast<ID *>(ob->data));
}
}
@@ -1076,17 +1084,17 @@ void BKE_object_material_remap(Object *ob, const uint *remap)
}
if (ob->type == OB_MESH) {
BKE_mesh_material_remap(ob->data, remap, ob->totcol);
BKE_mesh_material_remap(static_cast<Mesh *>(ob->data), remap, ob->totcol);
}
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF, OB_FONT)) {
BKE_curve_material_remap(ob->data, remap, ob->totcol);
BKE_curve_material_remap(static_cast<Curve *>(ob->data), remap, ob->totcol);
}
else if (ob->type == OB_GPENCIL) {
BKE_gpencil_material_remap(ob->data, remap, ob->totcol);
BKE_gpencil_material_remap(static_cast<bGPdata *>(ob->data), remap, ob->totcol);
}
else {
/* add support for this object data! */
BLI_assert(matar == NULL);
BLI_assert(matar == nullptr);
}
}
@@ -1100,7 +1108,7 @@ void BKE_object_material_remap_calc(Object *ob_dst, Object *ob_src, short *remap
for (int i = 0; i < ob_dst->totcol; i++) {
Material *ma_src = BKE_object_material_get(ob_dst, i + 1);
BLI_ghash_reinsert(gh_mat_map, ma_src, POINTER_FROM_INT(i), NULL, NULL);
BLI_ghash_reinsert(gh_mat_map, ma_src, POINTER_FROM_INT(i), nullptr, nullptr);
}
/* setup default mapping (when materials don't match) */
@@ -1135,12 +1143,12 @@ void BKE_object_material_remap_calc(Object *ob_dst, Object *ob_src, short *remap
}
}
BLI_ghash_free(gh_mat_map, NULL, NULL);
BLI_ghash_free(gh_mat_map, nullptr, nullptr);
}
void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *data_eval)
{
ID *data_orig = ob_orig->data;
ID *data_orig = static_cast<ID *>(ob_orig->data);
short *orig_totcol = BKE_id_material_len_p(data_orig);
Material ***orig_mat = BKE_id_material_array_p(data_orig);
@@ -1149,7 +1157,7 @@ void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *
const short *eval_totcol = BKE_id_material_len_p((ID *)data_eval);
Material ***eval_mat = BKE_id_material_array_p((ID *)data_eval);
if (ELEM(NULL, orig_totcol, orig_mat, eval_totcol, eval_mat)) {
if (ELEM(nullptr, orig_totcol, orig_mat, eval_totcol, eval_mat)) {
return;
}
@@ -1161,10 +1169,10 @@ void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *
/* Create new material slots based on materials on evaluated geometry. */
*orig_totcol = *eval_totcol;
*orig_mat = MEM_callocN(sizeof(void *) * (*eval_totcol), __func__);
*orig_mat = MEM_cnew_array<Material *>(*eval_totcol, __func__);
for (int i = 0; i < *eval_totcol; i++) {
Material *material_eval = (*eval_mat)[i];
if (material_eval != NULL) {
if (material_eval != nullptr) {
Material *material_orig = (Material *)DEG_get_original_id(&material_eval->id);
(*orig_mat)[i] = material_orig;
id_us_plus(&material_orig->id);
@@ -1210,14 +1218,14 @@ short BKE_object_material_slot_find_index(Object *ob, Material *ma)
Material ***matarar;
short a, *totcolp;
if (ma == NULL) {
if (ma == nullptr) {
return 0;
}
totcolp = BKE_object_material_len_p(ob);
matarar = BKE_object_material_array_p(ob);
if (totcolp == NULL || matarar == NULL) {
if (totcolp == nullptr || matarar == nullptr) {
return 0;
}
@@ -1234,14 +1242,14 @@ short BKE_object_material_slot_find_index(Object *ob, Material *ma)
bool BKE_object_material_slot_add(Main *bmain, Object *ob)
{
if (ob == NULL) {
if (ob == nullptr) {
return false;
}
if (ob->totcol >= MAXMAT) {
return false;
}
BKE_object_material_assign(bmain, ob, NULL, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF);
BKE_object_material_assign(bmain, ob, nullptr, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF);
ob->actcol = ob->totcol;
return true;
}
@@ -1253,7 +1261,7 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
Material *mao, ***matarar;
short *totcolp;
if (ob == NULL || ob->totcol == 0) {
if (ob == nullptr || ob->totcol == 0) {
return false;
}
@@ -1272,7 +1280,7 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
totcolp = BKE_object_material_len_p(ob);
matarar = BKE_object_material_array_p(ob);
if (ELEM(NULL, matarar, *matarar)) {
if (ELEM(nullptr, matarar, *matarar)) {
return false;
}
@@ -1294,12 +1302,13 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
if (*totcolp == 0) {
MEM_freeN(*matarar);
*matarar = NULL;
*matarar = nullptr;
}
const int actcol = ob->actcol;
for (Object *obt = bmain->objects.first; obt; obt = obt->id.next) {
for (Object *obt = static_cast<Object *>(bmain->objects.first); obt;
obt = static_cast<Object *>(obt->id.next)) {
if (obt->data == ob->data) {
/* Can happen when object material lists are used, see: T52953 */
if (actcol > obt->totcol) {
@@ -1323,8 +1332,8 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
if (obt->totcol == 0) {
MEM_freeN(obt->mat);
MEM_freeN(obt->matbits);
obt->mat = NULL;
obt->matbits = NULL;
obt->mat = nullptr;
obt->matbits = nullptr;
}
}
}
@@ -1349,7 +1358,7 @@ static bNode *nodetree_uv_node_recursive(bNode *node)
bNode *inode;
bNodeSocket *sock;
for (sock = node->inputs.first; sock; sock = sock->next) {
for (sock = static_cast<bNodeSocket *>(node->inputs.first); sock; sock = sock->next) {
if (sock->link) {
inode = sock->link->fromnode;
if (inode->typeinfo->nclass == NODE_CLASS_INPUT && inode->typeinfo->type == SH_NODE_UVMAP) {
@@ -1360,7 +1369,7 @@ static bNode *nodetree_uv_node_recursive(bNode *node)
}
}
return NULL;
return nullptr;
}
/** Bitwise filter for updating paint slots. */
@@ -1368,6 +1377,7 @@ typedef enum ePaintSlotFilter {
PAINT_SLOT_IMAGE = 1 << 0,
PAINT_SLOT_COLOR_ATTRIBUTE = 1 << 1,
} ePaintSlotFilter;
ENUM_OPERATORS(ePaintSlotFilter, PAINT_SLOT_COLOR_ATTRIBUTE)
typedef bool (*ForEachTexNodeCallback)(bNode *node, void *userdata);
static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree,
@@ -1424,7 +1434,7 @@ struct FillTexPaintSlotsData {
static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
{
struct FillTexPaintSlotsData *fill_data = userdata;
struct FillTexPaintSlotsData *fill_data = static_cast<FillTexPaintSlotsData *>(userdata);
Material *ma = fill_data->ma;
int index = fill_data->index;
@@ -1459,17 +1469,17 @@ static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
case SH_NODE_ATTRIBUTE: {
TexPaintSlot *slot = &ma->texpaintslot[index];
NodeShaderAttribute *storage = node->storage;
NodeShaderAttribute *storage = static_cast<NodeShaderAttribute *>(node->storage);
slot->attribute_name = storage->name;
if (storage->type == SHD_ATTRIBUTE_GEOMETRY) {
const Mesh *mesh = (const Mesh *)fill_data->ob->data;
const CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, storage->name);
slot->valid = layer != NULL;
slot->valid = layer != nullptr;
}
/* Do not show unsupported attributes. */
if (!slot->valid) {
slot->attribute_name = NULL;
slot->attribute_name = nullptr;
fill_data->index--;
}
@@ -1514,7 +1524,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const struct Ob
const int prev_paint_clone_slot = ma->paint_clone_slot;
const int prev_tot_slots = ma->tot_slots;
ma->texpaintslot = NULL;
ma->texpaintslot = nullptr;
ma->tot_slots = 0;
if (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_IMAGE) {
@@ -1533,7 +1543,8 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const struct Ob
ma->paint_clone_slot = 0;
}
else {
ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
ma->texpaintslot = static_cast<TexPaintSlot *>(
MEM_callocN(sizeof(TexPaintSlot) * count, "texpaint_slots"));
bNode *active_node = nodeGetActivePaintCanvas(ma->nodetree);
@@ -1579,7 +1590,7 @@ struct FindTexPaintNodeData {
static bool texpaint_slot_node_find_cb(bNode *node, void *userdata)
{
struct FindTexPaintNodeData *find_data = userdata;
struct FindTexPaintNodeData *find_data = static_cast<FindTexPaintNodeData *>(userdata);
if (find_data->slot->ima && node->type == SH_NODE_TEX_IMAGE) {
Image *node_ima = (Image *)node->id;
if (find_data->slot->ima == node_ima) {
@@ -1589,7 +1600,7 @@ static bool texpaint_slot_node_find_cb(bNode *node, void *userdata)
}
if (find_data->slot->attribute_name && node->type == SH_NODE_ATTRIBUTE) {
NodeShaderAttribute *storage = node->storage;
NodeShaderAttribute *storage = static_cast<NodeShaderAttribute *>(node->storage);
if (STREQLEN(find_data->slot->attribute_name, storage->name, sizeof(storage->name))) {
find_data->r_node = node;
return false;
@@ -1602,7 +1613,7 @@ static bool texpaint_slot_node_find_cb(bNode *node, void *userdata)
bNode *BKE_texpaint_slot_material_find_node(Material *ma, short texpaint_slot)
{
TexPaintSlot *slot = &ma->texpaintslot[texpaint_slot];
struct FindTexPaintNodeData find_data = {slot, NULL};
struct FindTexPaintNodeData find_data = {slot, nullptr};
ntree_foreach_texnode_recursive(ma->nodetree,
texpaint_slot_node_find_cb,
&find_data,
@@ -1873,7 +1884,7 @@ static short matcopied = 0;
void BKE_material_copybuf_clear(void)
{
memset(&matcopybuf, 0, sizeof(Material));
matcopybuf = blender::dna::shallow_zero_initialize();
matcopied = 0;
}
@@ -1883,7 +1894,7 @@ void BKE_material_copybuf_free(void)
ntreeFreeLocalTree(matcopybuf.nodetree);
BLI_assert(!matcopybuf.nodetree->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(matcopybuf.nodetree);
matcopybuf.nodetree = NULL;
matcopybuf.nodetree = nullptr;
}
matcopied = 0;
@@ -1895,15 +1906,15 @@ void BKE_material_copybuf_copy(Main *bmain, Material *ma)
BKE_material_copybuf_free();
}
memcpy(&matcopybuf, ma, sizeof(Material));
matcopybuf = blender::dna::shallow_copy(*ma);
if (ma->nodetree != NULL) {
if (ma->nodetree != nullptr) {
matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false);
}
matcopybuf.preview = NULL;
matcopybuf.preview = nullptr;
BLI_listbase_clear(&matcopybuf.gpumaterial);
/* TODO: Duplicate Engine Settings and set runtime to NULL. */
/* TODO: Duplicate Engine Settings and set runtime to nullptr. */
matcopied = 1;
}
@@ -1924,10 +1935,10 @@ void BKE_material_copybuf_paste(Main *bmain, Material *ma)
}
id = (ma->id);
memcpy(ma, &matcopybuf, sizeof(Material));
*ma = blender::dna::shallow_copy(matcopybuf);
(ma->id) = id;
if (matcopybuf.nodetree != NULL) {
if (matcopybuf.nodetree != nullptr) {
ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false);
}
}
@@ -1954,7 +1965,7 @@ static Material *default_materials[] = {&default_material_empty,
&default_material_surface,
&default_material_volume,
&default_material_gpencil,
NULL};
nullptr};
static void material_default_gpencil_init(Material *ma)
{
@@ -1968,14 +1979,14 @@ static void material_default_surface_init(Material *ma)
strcpy(ma->id.name, "MADefault Surface");
bNodeTree *ntree = ntreeAddTreeEmbedded(
NULL, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
nullptr, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
ma->use_nodes = true;
bNode *principled = nodeAddStaticNode(NULL, ntree, SH_NODE_BSDF_PRINCIPLED);
bNode *principled = nodeAddStaticNode(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED);
bNodeSocket *base_color = nodeFindSocket(principled, SOCK_IN, "Base Color");
copy_v3_v3(((bNodeSocketValueRGBA *)base_color->default_value)->value, &ma->r);
bNode *output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL);
bNode *output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL);
nodeAddLink(ntree,
principled,
@@ -1996,11 +2007,11 @@ static void material_default_volume_init(Material *ma)
strcpy(ma->id.name, "MADefault Volume");
bNodeTree *ntree = ntreeAddTreeEmbedded(
NULL, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
nullptr, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
ma->use_nodes = true;
bNode *principled = nodeAddStaticNode(NULL, ntree, SH_NODE_VOLUME_PRINCIPLED);
bNode *output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL);
bNode *principled = nodeAddStaticNode(nullptr, ntree, SH_NODE_VOLUME_PRINCIPLED);
bNode *output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL);
nodeAddLink(ntree,
principled,
@@ -2021,11 +2032,11 @@ static void material_default_holdout_init(Material *ma)
strcpy(ma->id.name, "MADefault Holdout");
bNodeTree *ntree = ntreeAddTreeEmbedded(
NULL, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
nullptr, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
ma->use_nodes = true;
bNode *holdout = nodeAddStaticNode(NULL, ntree, SH_NODE_HOLDOUT);
bNode *output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL);
bNode *holdout = nodeAddStaticNode(nullptr, ntree, SH_NODE_HOLDOUT);
bNode *output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL);
nodeAddLink(ntree,
holdout,

View File

@@ -78,11 +78,11 @@ static void texture_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const i
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
if (!BKE_texture_is_image_user(texture_src)) {
texture_dst->ima = NULL;
texture_dst->ima = nullptr;
}
if (texture_dst->coba) {
texture_dst->coba = MEM_dupallocN(texture_dst->coba);
texture_dst->coba = static_cast<ColorBand *>(MEM_dupallocN(texture_dst->coba));
}
if (texture_src->nodetree) {
if (texture_src->nodetree->execdata) {
@@ -103,7 +103,7 @@ static void texture_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const i
BKE_previewimg_id_copy(&texture_dst->id, &texture_src->id);
}
else {
texture_dst->preview = NULL;
texture_dst->preview = nullptr;
}
}
@@ -115,7 +115,7 @@ static void texture_free_data(ID *id)
if (texture->nodetree) {
ntreeFreeEmbeddedTree(texture->nodetree);
MEM_freeN(texture->nodetree);
texture->nodetree = NULL;
texture->nodetree = nullptr;
}
MEM_SAFE_FREE(texture->coba);
@@ -172,7 +172,7 @@ static void texture_blend_read_data(BlendDataReader *reader, ID *id)
BLO_read_data_address(reader, &tex->preview);
BKE_previewimg_blend_read(reader, tex->preview);
tex->iuser.scene = NULL;
tex->iuser.scene = nullptr;
}
static void texture_blend_read_lib(BlendLibReader *reader, ID *id)
@@ -190,33 +190,33 @@ static void texture_blend_read_expand(BlendExpander *expander, ID *id)
}
IDTypeInfo IDType_ID_TE = {
.id_code = ID_TE,
.id_filter = FILTER_ID_TE,
.main_listbase_index = INDEX_ID_TE,
.struct_size = sizeof(Tex),
.name = "Texture",
.name_plural = "textures",
.translation_context = BLT_I18NCONTEXT_ID_TEXTURE,
.flags = IDTYPE_FLAGS_APPEND_IS_REUSABLE,
.asset_type_info = NULL,
/* id_code */ ID_TE,
/* id_filter */ FILTER_ID_TE,
/* main_listbase_index */ INDEX_ID_TE,
/* struct_size */ sizeof(Tex),
/* name */ "Texture",
/* name_plural */ "textures",
/* translation_context */ BLT_I18NCONTEXT_ID_TEXTURE,
/* flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
/* asset_type_info */ nullptr,
.init_data = texture_init_data,
.copy_data = texture_copy_data,
.free_data = texture_free_data,
.make_local = NULL,
.foreach_id = texture_foreach_id,
.foreach_cache = NULL,
.foreach_path = NULL,
.owner_pointer_get = NULL,
/* init_data */ texture_init_data,
/* copy_data */ texture_copy_data,
/* free_data */ texture_free_data,
/* make_local */ nullptr,
/* foreach_id */ texture_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
/* owner_pointer_get */ nullptr,
.blend_write = texture_blend_write,
.blend_read_data = texture_blend_read_data,
.blend_read_lib = texture_blend_read_lib,
.blend_read_expand = texture_blend_read_expand,
/* blend_write */ texture_blend_write,
/* blend_read_data */ texture_blend_read_data,
/* blend_read_lib */ texture_blend_read_lib,
/* blend_read_expand */ texture_blend_read_expand,
.blend_read_undo_preserve = NULL,
/* blend_read_undo_preserve */ nullptr,
.lib_override_apply_post = NULL,
/* lib_override_apply_post */ nullptr,
};
void BKE_texture_mtex_foreach_id(LibraryForeachIDData *data, MTex *mtex)
@@ -229,7 +229,7 @@ void BKE_texture_mtex_foreach_id(LibraryForeachIDData *data, MTex *mtex)
TexMapping *BKE_texture_mapping_add(int type)
{
TexMapping *texmap = MEM_callocN(sizeof(TexMapping), "TexMapping");
TexMapping *texmap = MEM_cnew<TexMapping>("TexMapping");
BKE_texture_mapping_default(texmap, type);
@@ -331,7 +331,7 @@ void BKE_texture_mapping_init(TexMapping *texmap)
ColorMapping *BKE_texture_colormapping_add(void)
{
ColorMapping *colormap = MEM_callocN(sizeof(ColorMapping), "ColorMapping");
ColorMapping *colormap = MEM_cnew<ColorMapping>("ColorMapping");
BKE_texture_colormapping_default(colormap);
@@ -375,7 +375,7 @@ Tex *BKE_texture_add(Main *bmain, const char *name)
{
Tex *tex;
tex = BKE_id_new(bmain, ID_TE, name);
tex = static_cast<Tex *>(BKE_id_new(bmain, ID_TE, name));
return tex;
}
@@ -384,7 +384,7 @@ Tex *BKE_texture_add(Main *bmain, const char *name)
void BKE_texture_mtex_default(MTex *mtex)
{
memcpy(mtex, DNA_struct_default_get(MTex), sizeof(*mtex));
*mtex = blender::dna::shallow_copy(*DNA_struct_default_get(MTex));
}
/* ------------------------------------------------------------------------- */
@@ -393,7 +393,7 @@ MTex *BKE_texture_mtex_add(void)
{
MTex *mtex;
mtex = MEM_callocN(sizeof(MTex), "BKE_texture_mtex_add");
mtex = static_cast<MTex *>(MEM_callocN(sizeof(MTex), "BKE_texture_mtex_add"));
BKE_texture_mtex_default(mtex);
@@ -407,8 +407,8 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot)
give_active_mtex(id, &mtex_ar, &act);
if (mtex_ar == NULL) {
return NULL;
if (mtex_ar == nullptr) {
return nullptr;
}
if (slot == -1) {
@@ -421,20 +421,20 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot)
}
}
if (slot == -1) {
return NULL;
return nullptr;
}
}
else {
/* make sure slot is valid */
if (slot < 0 || slot >= MAX_MTEX) {
return NULL;
return nullptr;
}
}
if (mtex_ar[slot]) {
id_us_min((ID *)mtex_ar[slot]->tex);
MEM_freeN(mtex_ar[slot]);
mtex_ar[slot] = NULL;
mtex_ar[slot] = nullptr;
}
mtex_ar[slot] = BKE_texture_mtex_add();
@@ -446,8 +446,8 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot)
Tex *give_current_linestyle_texture(FreestyleLineStyle *linestyle)
{
MTex *mtex = NULL;
Tex *tex = NULL;
MTex *mtex = nullptr;
Tex *tex = nullptr;
if (linestyle) {
mtex = linestyle->mtex[(int)(linestyle->texact)];
@@ -497,7 +497,7 @@ bool give_active_mtex(ID *id, MTex ***mtex_ar, short *act)
}
break;
default:
*mtex_ar = NULL;
*mtex_ar = nullptr;
if (act) {
*act = 0;
}
@@ -547,11 +547,11 @@ void set_current_brush_texture(Brush *br, Tex *newtex)
Tex *give_current_particle_texture(ParticleSettings *part)
{
MTex *mtex = NULL;
Tex *tex = NULL;
MTex *mtex = nullptr;
Tex *tex = nullptr;
if (!part) {
return NULL;
return nullptr;
}
mtex = part->mtex[(int)(part->texact)];
@@ -594,8 +594,8 @@ void BKE_texture_pointdensity_init_data(PointDensity *pd)
pd->falloff_type = TEX_PD_FALLOFF_STD;
pd->falloff_softness = 2.0;
pd->source = TEX_PD_PSYS;
pd->point_tree = NULL;
pd->point_data = NULL;
pd->point_tree = nullptr;
pd->point_data = nullptr;
pd->noise_size = 0.5f;
pd->noise_depth = 1;
pd->noise_fac = 1.0f;
@@ -603,7 +603,7 @@ void BKE_texture_pointdensity_init_data(PointDensity *pd)
pd->coba = BKE_colorband_add(true);
pd->speed_scale = 1.0f;
pd->totpoints = 0;
pd->object = NULL;
pd->object = nullptr;
pd->psys = 0;
pd->psys_cache_space = TEX_PD_WORLDSPACE;
pd->falloff_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
@@ -619,7 +619,8 @@ void BKE_texture_pointdensity_init_data(PointDensity *pd)
PointDensity *BKE_texture_pointdensity_add(void)
{
PointDensity *pd = MEM_callocN(sizeof(PointDensity), "pointdensity");
PointDensity *pd = static_cast<PointDensity *>(
MEM_callocN(sizeof(PointDensity), "pointdensity"));
BKE_texture_pointdensity_init_data(pd);
return pd;
}
@@ -628,26 +629,26 @@ PointDensity *BKE_texture_pointdensity_copy(const PointDensity *pd, const int UN
{
PointDensity *pdn;
pdn = MEM_dupallocN(pd);
pdn->point_tree = NULL;
pdn->point_data = NULL;
pdn = static_cast<PointDensity *>(MEM_dupallocN(pd));
pdn->point_tree = nullptr;
pdn->point_data = nullptr;
if (pdn->coba) {
pdn->coba = MEM_dupallocN(pdn->coba);
pdn->coba = static_cast<ColorBand *>(MEM_dupallocN(pdn->coba));
}
pdn->falloff_curve = BKE_curvemapping_copy(pdn->falloff_curve); /* can be NULL */
pdn->falloff_curve = BKE_curvemapping_copy(pdn->falloff_curve); /* can be nullptr */
return pdn;
}
void BKE_texture_pointdensity_free_data(PointDensity *pd)
{
if (pd->point_tree) {
BLI_bvhtree_free(pd->point_tree);
pd->point_tree = NULL;
BLI_bvhtree_free(static_cast<BVHTree *>(pd->point_tree));
pd->point_tree = nullptr;
}
MEM_SAFE_FREE(pd->point_data);
MEM_SAFE_FREE(pd->coba);
BKE_curvemapping_free(pd->falloff_curve); /* can be NULL */
BKE_curvemapping_free(pd->falloff_curve); /* can be nullptr */
}
void BKE_texture_pointdensity_free(PointDensity *pd)
@@ -721,7 +722,7 @@ void BKE_texture_get_value(const Scene *scene,
TexResult *texres,
bool use_color_management)
{
BKE_texture_get_value_ex(scene, texture, tex_co, texres, NULL, use_color_management);
BKE_texture_get_value_ex(scene, texture, tex_co, texres, nullptr, use_color_management);
}
static void texture_nodes_fetch_images_for_pool(Tex *texture,
@@ -729,11 +730,11 @@ static void texture_nodes_fetch_images_for_pool(Tex *texture,
struct ImagePool *pool)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == SH_NODE_TEX_IMAGE && node->id != NULL) {
if (node->type == SH_NODE_TEX_IMAGE && node->id != nullptr) {
Image *image = (Image *)node->id;
BKE_image_pool_acquire_ibuf(image, &texture->iuser, pool);
}
else if (node->type == NODE_GROUP && node->id != NULL) {
else if (node->type == NODE_GROUP && node->id != nullptr) {
/* TODO(sergey): Do we need to control recursion here? */
bNodeTree *nested_tree = (bNodeTree *)node->id;
texture_nodes_fetch_images_for_pool(texture, nested_tree, pool);
@@ -743,12 +744,12 @@ static void texture_nodes_fetch_images_for_pool(Tex *texture,
void BKE_texture_fetch_images_for_pool(Tex *texture, struct ImagePool *pool)
{
if (texture->nodetree != NULL) {
if (texture->nodetree != nullptr) {
texture_nodes_fetch_images_for_pool(texture, texture->nodetree, pool);
}
else {
if (texture->type == TEX_IMAGE) {
if (texture->ima != NULL) {
if (texture->ima != nullptr) {
BKE_image_pool_acquire_ibuf(texture->ima, &texture->iuser, pool);
}
}

View File

@@ -130,7 +130,7 @@ set(SRC
engines/eevee/eevee_renderpasses.c
engines/eevee/eevee_sampling.c
engines/eevee/eevee_screen_raytrace.c
engines/eevee/eevee_shaders.c
engines/eevee/eevee_shaders.cc
engines/eevee/eevee_shaders_extra.cc
engines/eevee/eevee_shadows.c
engines/eevee/eevee_shadows_cascade.c
@@ -162,7 +162,7 @@ set(SRC
engines/workbench/workbench_effect_dof.c
engines/workbench/workbench_effect_outline.c
engines/workbench/workbench_engine.c
engines/workbench/workbench_materials.c
engines/workbench/workbench_materials.cc
engines/workbench/workbench_opaque.c
engines/workbench/workbench_render.c
engines/workbench/workbench_shader.cc
@@ -774,4 +774,3 @@ if(WITH_GTESTS)
blender_add_test_lib(bf_draw_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
endif()
endif()

View File

@@ -89,13 +89,13 @@ BLI_INLINE void workbench_material_get_image(
Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, eGPUSamplerState *r_sampler)
{
const bNode *node;
*r_sampler = 0;
*r_sampler = eGPUSamplerState(0);
ED_object_get_active_image(ob, mat_nr, r_image, r_iuser, &node, NULL);
if (node && *r_image) {
switch (node->type) {
case SH_NODE_TEX_IMAGE: {
const NodeTexImage *storage = node->storage;
const NodeTexImage *storage = static_cast<NodeTexImage *>(node->storage);
const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
const bool use_repeat = (storage->extension == SHD_IMAGE_EXTENSION_REPEAT);
const bool use_clip = (storage->extension == SHD_IMAGE_EXTENSION_CLIP);
@@ -105,7 +105,7 @@ BLI_INLINE void workbench_material_get_image(
break;
}
case SH_NODE_TEX_ENVIRONMENT: {
const NodeTexEnvironment *storage = node->storage;
const NodeTexEnvironment *storage = static_cast<NodeTexEnvironment *>(node->storage);
const bool use_filter = (storage->interpolation != SHD_INTERP_CLOSEST);
SET_FLAG_FROM_TEST(*r_sampler, use_filter, GPU_SAMPLER_FILTER);
break;
@@ -128,15 +128,18 @@ BLI_INLINE bool workbench_material_chunk_select(WORKBENCH_PrivateData *wpd,
/* We need to add a new chunk. */
while (chunk >= wpd->material_chunk_count) {
wpd->material_chunk_count++;
wpd->material_ubo_data_curr = BLI_memblock_alloc(wpd->material_ubo_data);
wpd->material_ubo_curr = workbench_material_ubo_alloc(wpd);
wpd->material_ubo_data_curr = static_cast<WORKBENCH_UBO_Material *>(
BLI_memblock_alloc(wpd->material_ubo_data));
wpd->material_ubo_curr = static_cast<GPUUniformBuf *>(workbench_material_ubo_alloc(wpd));
wpd->material_chunk_curr = chunk;
resource_changed = true;
}
/* We need to go back to a previous chunk. */
if (wpd->material_chunk_curr != chunk) {
wpd->material_ubo_data_curr = BLI_memblock_elem_get(wpd->material_ubo_data, 0, chunk);
wpd->material_ubo_curr = BLI_memblock_elem_get(wpd->material_ubo, 0, chunk);
wpd->material_ubo_data_curr = static_cast<WORKBENCH_UBO_Material *>(
BLI_memblock_elem_get(wpd->material_ubo_data, 0, chunk));
wpd->material_ubo_curr = static_cast<GPUUniformBuf *>(
BLI_memblock_elem_get(wpd->material_ubo, 0, chunk));
wpd->material_chunk_curr = chunk;
resource_changed = true;
}

View File

@@ -22,7 +22,7 @@ set(INC
set(SRC
buttons_context.c
buttons_ops.c
buttons_texture.c
buttons_texture.cc
space_buttons.c
buttons_intern.h

View File

@@ -11,6 +11,10 @@
#include "DNA_listBase.h"
#include "RNA_types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ARegionType;
struct ID;
struct SpaceProperties;
@@ -97,3 +101,7 @@ void BUTTONS_OT_file_browse(struct wmOperatorType *ot);
*/
void BUTTONS_OT_directory_browse(struct wmOperatorType *ot);
void BUTTONS_OT_context_menu(struct wmOperatorType *ot);
#ifdef __cplusplus
}
#endif

View File

@@ -71,7 +71,7 @@ static void buttons_texture_user_socket_property_add(ListBase *users,
int icon,
const char *name)
{
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser");
user->id = id;
user->ptr = ptr;
@@ -95,7 +95,7 @@ static void buttons_texture_user_property_add(ListBase *users,
int icon,
const char *name)
{
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser");
user->id = id;
user->ptr = ptr;
@@ -116,7 +116,7 @@ static void buttons_texture_user_node_add(ListBase *users,
int icon,
const char *name)
{
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser");
user->id = id;
user->ntree = ntree;
@@ -137,7 +137,7 @@ static void buttons_texture_users_find_nodetree(ListBase *users,
bNode *node;
if (ntree) {
for (node = ntree->nodes.first; node; node = node->next) {
for (node = static_cast<bNode *>(ntree->nodes.first); node; node = node->next) {
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
PointerRNA ptr;
// PropertyRNA *prop; /* UNUSED */
@@ -179,8 +179,8 @@ static void buttons_texture_modifier_geonodes_users_add(Object *ob,
prop = RNA_struct_find_property(&ptr, "default_value");
PointerRNA texptr = RNA_property_pointer_get(&ptr, prop);
Tex *tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? (Tex *)texptr.data : NULL;
if (tex != NULL) {
Tex *tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? (Tex *)texptr.data : nullptr;
if (tex != nullptr) {
buttons_texture_user_socket_property_add(users,
&ob->id,
ptr,
@@ -201,11 +201,11 @@ static void buttons_texture_modifier_foreach(void *userData,
ModifierData *md,
const char *propname)
{
ListBase *users = userData;
ListBase *users = static_cast<ListBase *>(userData);
if (md->type == eModifierType_Nodes) {
NodesModifierData *nmd = (NodesModifierData *)md;
if (nmd->node_group != NULL) {
if (nmd->node_group != nullptr) {
buttons_texture_modifier_geonodes_users_add(ob, nmd, nmd->node_group, users);
}
}
@@ -228,7 +228,7 @@ static void buttons_texture_modifier_gpencil_foreach(void *userData,
{
PointerRNA ptr;
PropertyRNA *prop;
ListBase *users = userData;
ListBase *users = static_cast<ListBase *>(userData);
RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr);
prop = RNA_struct_find_property(&ptr, propname);
@@ -246,10 +246,10 @@ static void buttons_texture_users_from_context(ListBase *users,
const bContext *C,
SpaceProperties *sbuts)
{
Scene *scene = NULL;
Object *ob = NULL;
FreestyleLineStyle *linestyle = NULL;
Brush *brush = NULL;
Scene *scene = nullptr;
Object *ob = nullptr;
FreestyleLineStyle *linestyle = nullptr;
Brush *brush = nullptr;
ID *pinid = sbuts->pinid;
bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0;
@@ -273,7 +273,7 @@ static void buttons_texture_users_from_context(ListBase *users,
scene = CTX_data_scene(C);
}
const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1;
const ID_Type id_type = ID_Type(pinid != nullptr ? GS(pinid->name) : -1);
if (!pinid || id_type == ID_SCE) {
wmWindow *win = CTX_wm_window(C);
ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) :
@@ -365,11 +365,11 @@ void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts)
{
/* gather available texture users in context. runs on every draw of
* properties editor, before the buttons are created. */
ButsContextTexture *ct = sbuts->texuser;
ButsContextTexture *ct = static_cast<ButsContextTexture *>(sbuts->texuser);
ID *pinid = sbuts->pinid;
if (!ct) {
ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture");
ct = MEM_cnew<ButsContextTexture>("ButsContextTexture");
sbuts->texuser = ct;
}
else {
@@ -379,7 +379,7 @@ void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts)
buttons_texture_users_from_context(&ct->users, C, sbuts);
if (pinid && GS(pinid->name) == ID_TE) {
ct->user = NULL;
ct->user = nullptr;
ct->texture = (Tex *)pinid;
}
else {
@@ -388,16 +388,16 @@ void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts)
ct->index = 0;
}
ct->user = BLI_findlink(&ct->users, ct->index);
ct->texture = NULL;
ct->user = static_cast<ButsTextureUser *>(BLI_findlink(&ct->users, ct->index));
ct->texture = nullptr;
if (ct->user) {
if (ct->user->node != NULL) {
if (ct->user->node != nullptr) {
/* Detect change of active texture node in same node tree, in that
* case we also automatically switch to the other node. */
if ((ct->user->node->flag & NODE_ACTIVE_TEXTURE) == 0) {
ButsTextureUser *user;
for (user = ct->users.first; user; user = user->next) {
for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) {
if (user->ntree == ct->user->ntree && user->node != ct->user->node) {
if (user->node->flag & NODE_ACTIVE_TEXTURE) {
ct->user = user;
@@ -414,7 +414,8 @@ void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts)
/* Get texture datablock pointer if it's a property. */
texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop);
tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? texptr.data : NULL;
tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? static_cast<Tex *>(texptr.data) :
nullptr;
ct->texture = tex;
}
@@ -426,7 +427,7 @@ static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)
{
/* callback when selecting a texture user in the menu */
SpaceProperties *sbuts = find_space_properties(C);
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr;
ButsTextureUser *user = (ButsTextureUser *)user_p;
PointerRNA texptr;
Tex *tex;
@@ -437,19 +438,19 @@ static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)
/* set user as active */
if (user->node) {
ED_node_set_active(CTX_data_main(C), NULL, user->ntree, user->node, NULL);
ct->texture = NULL;
ED_node_set_active(CTX_data_main(C), nullptr, user->ntree, user->node, nullptr);
ct->texture = nullptr;
/* Not totally sure if we should also change selection? */
LISTBASE_FOREACH (bNode *, node, &user->ntree->nodes) {
nodeSetSelected(node, false);
}
nodeSetSelected(user->node, true);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
}
if (user->ptr.data) {
texptr = RNA_property_pointer_get(&user->ptr, user->prop);
tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? texptr.data : NULL;
tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? static_cast<Tex *>(texptr.data) : nullptr;
ct->texture = tex;
@@ -479,26 +480,26 @@ static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUS
{
/* callback when opening texture user selection menu, to create buttons. */
SpaceProperties *sbuts = CTX_wm_space_properties(C);
ButsContextTexture *ct = sbuts->texuser;
ButsContextTexture *ct = static_cast<ButsContextTexture *>(sbuts->texuser);
ButsTextureUser *user;
uiBlock *block = uiLayoutGetBlock(layout);
const char *last_category = NULL;
const char *last_category = nullptr;
for (user = ct->users.first; user; user = user->next) {
for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) {
uiBut *but;
char name[UI_MAX_NAME_STR];
/* add label per category */
if (!last_category || !STREQ(last_category, user->category)) {
uiItemL(layout, IFACE_(user->category), ICON_NONE);
but = block->buttons.last;
but = static_cast<uiBut *>(block->buttons.last);
but->drawflag = UI_BUT_TEXT_LEFT;
}
/* create button */
if (user->prop) {
PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop);
Tex *tex = texptr.data;
Tex *tex = static_cast<Tex *>(texptr.data);
if (tex) {
BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2);
@@ -520,13 +521,13 @@ static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUS
0,
UI_UNIT_X * 4,
UI_UNIT_Y,
NULL,
nullptr,
0.0,
0.0,
0.0,
0.0,
"");
UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), NULL);
UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), nullptr);
last_category = user->category;
}
@@ -540,7 +541,7 @@ void uiTemplateTextureUser(uiLayout *layout, bContext *C)
* gathered before drawing in #ButsContextTexture, we merely need to
* display the current item. */
SpaceProperties *sbuts = CTX_wm_space_properties(C);
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr;
uiBlock *block = uiLayoutGetBlock(layout);
uiBut *but;
ButsTextureUser *user;
@@ -564,7 +565,7 @@ void uiTemplateTextureUser(uiLayout *layout, bContext *C)
if (user->icon) {
but = uiDefIconTextMenuBut(block,
template_texture_user_menu,
NULL,
nullptr,
user->icon,
name,
0,
@@ -575,7 +576,7 @@ void uiTemplateTextureUser(uiLayout *layout, bContext *C)
}
else {
but = uiDefMenuBut(
block, template_texture_user_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, "");
block, template_texture_user_menu, nullptr, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, "");
}
/* some cosmetic tweaks */
@@ -594,46 +595,46 @@ static ScrArea *find_area_properties(const bContext *C)
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
if (area->spacetype == SPACE_PROPERTIES) {
/* Only if unpinned, or if pinned object matches. */
SpaceProperties *sbuts = area->spacedata.first;
SpaceProperties *sbuts = static_cast<SpaceProperties *>(area->spacedata.first);
ID *pinid = sbuts->pinid;
if (pinid == NULL || ((GS(pinid->name) == ID_OB) && (Object *)pinid == ob)) {
if (pinid == nullptr || ((GS(pinid->name) == ID_OB) && (Object *)pinid == ob)) {
return area;
}
}
}
return NULL;
return nullptr;
}
static SpaceProperties *find_space_properties(const bContext *C)
{
ScrArea *area = find_area_properties(C);
if (area != NULL) {
return area->spacedata.first;
if (area != nullptr) {
return static_cast<SpaceProperties *>(area->spacedata.first);
}
return NULL;
return nullptr;
}
static void template_texture_show(bContext *C, void *data_p, void *prop_p)
{
if (data_p == NULL || prop_p == NULL) {
if (data_p == nullptr || prop_p == nullptr) {
return;
}
ScrArea *area = find_area_properties(C);
if (area == NULL) {
if (area == nullptr) {
return;
}
SpaceProperties *sbuts = (SpaceProperties *)area->spacedata.first;
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr;
if (!ct) {
return;
}
ButsTextureUser *user;
for (user = ct->users.first; user; user = user->next) {
for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) {
if (user->ptr.data == data_p && user->prop == prop_p) {
break;
}
@@ -641,7 +642,7 @@ static void template_texture_show(bContext *C, void *data_p, void *prop_p)
if (user) {
/* select texture */
template_texture_select(C, user, NULL);
template_texture_select(C, user, nullptr);
/* change context */
sbuts->mainb = BCONTEXT_TEXTURE;
@@ -656,25 +657,25 @@ static void template_texture_show(bContext *C, void *data_p, void *prop_p)
void uiTemplateTextureShow(uiLayout *layout, const bContext *C, PointerRNA *ptr, PropertyRNA *prop)
{
/* Only show the button if there is actually a texture assigned. */
Tex *texture = RNA_property_pointer_get(ptr, prop).data;
if (texture == NULL) {
Tex *texture = static_cast<Tex *>(RNA_property_pointer_get(ptr, prop).data);
if (texture == nullptr) {
return;
}
/* Only show the button if we are not in the Properties Editor's texture tab. */
SpaceProperties *sbuts_context = CTX_wm_space_properties(C);
if (sbuts_context != NULL && sbuts_context->mainb == BCONTEXT_TEXTURE) {
if (sbuts_context != nullptr && sbuts_context->mainb == BCONTEXT_TEXTURE) {
return;
}
SpaceProperties *sbuts = find_space_properties(C);
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr;
/* find corresponding texture user */
ButsTextureUser *user;
bool user_found = false;
if (ct != NULL) {
for (user = ct->users.first; user; user = user->next) {
if (ct != nullptr) {
for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) {
if (user->ptr.data == ptr->data && user->prop == prop) {
user_found = true;
break;
@@ -693,7 +694,7 @@ void uiTemplateTextureShow(uiLayout *layout, const bContext *C, PointerRNA *ptr,
0,
UI_UNIT_X,
UI_UNIT_Y,
NULL,
nullptr,
0.0,
0.0,
0.0,
@@ -701,9 +702,9 @@ void uiTemplateTextureShow(uiLayout *layout, const bContext *C, PointerRNA *ptr,
TIP_("Show texture in texture tab"));
UI_but_func_set(but,
template_texture_show,
user_found ? user->ptr.data : NULL,
user_found ? user->prop : NULL);
if (ct == NULL) {
user_found ? user->ptr.data : nullptr,
user_found ? user->prop : nullptr);
if (ct == nullptr) {
UI_but_disable(but, TIP_("No (unpinned) Properties Editor found to display texture in"));
}
else if (!user_found) {

View File

@@ -62,7 +62,7 @@ set(SRC
intern/gpu_init_exit.c
intern/gpu_material.c
intern/gpu_matrix.cc
intern/gpu_node_graph.c
intern/gpu_node_graph.cc
intern/gpu_platform.cc
intern/gpu_query.cc
intern/gpu_select.c

View File

@@ -29,7 +29,7 @@
static GPUNodeLink *gpu_node_link_create(void)
{
GPUNodeLink *link = MEM_callocN(sizeof(GPUNodeLink), "GPUNodeLink");
GPUNodeLink *link = MEM_cnew<GPUNodeLink>("GPUNodeLink");
link->users++;
return link;
@@ -55,7 +55,7 @@ static void gpu_node_link_free(GPUNodeLink *link)
static GPUNode *gpu_node_create(const char *name)
{
GPUNode *node = MEM_callocN(sizeof(GPUNode), "GPUNode");
GPUNode *node = MEM_cnew<GPUNode>("GPUNode");
node->name = name;
@@ -71,10 +71,10 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType
if (link->link_type == GPU_NODE_LINK_OUTPUT) {
outnode = link->output->node;
name = outnode->name;
input = outnode->inputs.first;
input = static_cast<GPUInput *>(outnode->inputs.first);
if (STR_ELEM(name, "set_value", "set_rgb", "set_rgba") && (input->type == type)) {
input = MEM_dupallocN(outnode->inputs.first);
input = static_cast<GPUInput *>(MEM_dupallocN(outnode->inputs.first));
switch (input->source) {
case GPU_SOURCE_ATTR:
@@ -103,7 +103,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType
}
}
input = MEM_callocN(sizeof(GPUInput), "GPUInput");
input = MEM_cnew<GPUInput>("GPUInput");
input->node = node;
input->type = type;
@@ -195,10 +195,10 @@ static GPUNodeLink *gpu_uniformbuffer_link(GPUMaterial *mat,
bNodeSocket *socket;
if (in_out == SOCK_IN) {
socket = BLI_findlink(&node->inputs, index);
socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, index));
}
else {
socket = BLI_findlink(&node->outputs, index);
socket = static_cast<bNodeSocket *>(BLI_findlink(&node->outputs, index));
}
BLI_assert(socket != NULL);
@@ -215,7 +215,10 @@ static GPUNodeLink *gpu_uniformbuffer_link(GPUMaterial *mat,
GPUNodeLink *link = GPU_uniform(stack->vec);
if (in_out == SOCK_IN) {
GPU_link(mat, gpu_uniform_set_function_from_type(socket->type), link, &stack->link);
GPU_link(mat,
gpu_uniform_set_function_from_type(eNodeSocketDatatype(socket->type)),
link,
&stack->link);
}
return link;
@@ -238,7 +241,7 @@ static void gpu_node_input_socket(
static void gpu_node_output(GPUNode *node, const eGPUType type, GPUNodeLink **link)
{
GPUOutput *output = MEM_callocN(sizeof(GPUOutput), "GPUOutput");
GPUOutput *output = MEM_cnew<GPUOutput>("GPUOutput");
output->type = type;
output->node = node;
@@ -260,7 +263,8 @@ static void gpu_node_output(GPUNode *node, const eGPUType type, GPUNodeLink **li
static int uniform_attr_sort_cmp(const void *a, const void *b)
{
const GPUUniformAttr *attr_a = a, *attr_b = b;
const GPUUniformAttr *attr_a = static_cast<const GPUUniformAttr *>(a),
*attr_b = static_cast<const GPUUniformAttr *>(b);
int cmps = strcmp(attr_a->name, attr_b->name);
if (cmps != 0) {
@@ -272,19 +276,21 @@ static int uniform_attr_sort_cmp(const void *a, const void *b)
static uint uniform_attr_list_hash(const void *key)
{
const GPUUniformAttrList *attrs = key;
const GPUUniformAttrList *attrs = static_cast<const GPUUniformAttrList *>(key);
return attrs->hash_code;
}
static bool uniform_attr_list_cmp(const void *a, const void *b)
{
const GPUUniformAttrList *set_a = a, *set_b = b;
const GPUUniformAttrList *set_a = static_cast<const GPUUniformAttrList *>(a),
*set_b = static_cast<const GPUUniformAttrList *>(b);
if (set_a->hash_code != set_b->hash_code || set_a->count != set_b->count) {
return true;
}
GPUUniformAttr *attr_a = set_a->list.first, *attr_b = set_b->list.first;
GPUUniformAttr *attr_a = static_cast<GPUUniformAttr *>(set_a->list.first),
*attr_b = static_cast<GPUUniformAttr *>(set_b->list.first);
for (; attr_a && attr_b; attr_a = attr_a->next, attr_b = attr_b->next) {
if (!STREQ(attr_a->name, attr_b->name) || attr_a->use_dupli != attr_b->use_dupli) {
@@ -377,7 +383,7 @@ static GPUMaterialAttribute *gpu_node_graph_add_attribute(GPUNodeGraph *graph,
{
/* Find existing attribute. */
int num_attributes = 0;
GPUMaterialAttribute *attr = graph->attributes.first;
GPUMaterialAttribute *attr = static_cast<GPUMaterialAttribute *>(graph->attributes.first);
for (; attr; attr = attr->next) {
if (attr->type == type && STREQ(attr->name, name) &&
attr->is_default_color == is_default_color) {
@@ -388,7 +394,7 @@ static GPUMaterialAttribute *gpu_node_graph_add_attribute(GPUNodeGraph *graph,
/* Add new requested attribute if it's within GPU limits. */
if (attr == NULL) {
attr = MEM_callocN(sizeof(*attr), __func__);
attr = MEM_cnew<GPUMaterialAttribute>(__func__);
attr->is_default_color = is_default_color;
attr->type = type;
STRNCPY(attr->name, name);
@@ -411,7 +417,7 @@ static GPUUniformAttr *gpu_node_graph_add_uniform_attribute(GPUNodeGraph *graph,
{
/* Find existing attribute. */
GPUUniformAttrList *attrs = &graph->uniform_attrs;
GPUUniformAttr *attr = attrs->list.first;
GPUUniformAttr *attr = static_cast<GPUUniformAttr *>(attrs->list.first);
for (; attr; attr = attr->next) {
if (STREQ(attr->name, name) && attr->use_dupli == use_dupli) {
@@ -421,7 +427,7 @@ static GPUUniformAttr *gpu_node_graph_add_uniform_attribute(GPUNodeGraph *graph,
/* Add new requested attribute if it's within GPU limits. */
if (attr == NULL && attrs->count < GPU_MAX_UNIFORM_ATTR) {
attr = MEM_callocN(sizeof(*attr), __func__);
attr = MEM_cnew<GPUUniformAttr>(__func__);
STRNCPY(attr->name, name);
attr->use_dupli = use_dupli;
attr->hash_code = BLI_ghashutil_strhash_p(attr->name) << 1 | (attr->use_dupli ? 0 : 1);
@@ -442,7 +448,7 @@ static GPULayerAttr *gpu_node_graph_add_layer_attribute(GPUNodeGraph *graph, con
{
/* Find existing attribute. */
ListBase *attrs = &graph->layer_attrs;
GPULayerAttr *attr = attrs->first;
GPULayerAttr *attr = static_cast<GPULayerAttr *>(attrs->first);
for (; attr; attr = attr->next) {
if (STREQ(attr->name, name)) {
@@ -452,7 +458,7 @@ static GPULayerAttr *gpu_node_graph_add_layer_attribute(GPUNodeGraph *graph, con
/* Add new requested attribute to the list. */
if (attr == NULL) {
attr = MEM_callocN(sizeof(*attr), __func__);
attr = MEM_cnew<GPULayerAttr>(__func__);
STRNCPY(attr->name, name);
attr->hash_code = BLI_ghashutil_strhash_p(attr->name);
BLI_addtail(attrs, attr);
@@ -475,7 +481,7 @@ static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph,
{
/* Find existing texture. */
int num_textures = 0;
GPUMaterialTexture *tex = graph->textures.first;
GPUMaterialTexture *tex = static_cast<GPUMaterialTexture *>(graph->textures.first);
for (; tex; tex = tex->next) {
if (tex->ima == ima && tex->colorband == colorband && tex->sky == sky &&
tex->sampler_state == sampler_state) {
@@ -486,7 +492,7 @@ static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph,
/* Add new requested texture. */
if (tex == NULL) {
tex = MEM_callocN(sizeof(*tex), __func__);
tex = MEM_cnew<GPUMaterialTexture>(__func__);
tex->ima = ima;
if (iuser != NULL) {
tex->iuser = *iuser;
@@ -812,7 +818,7 @@ static void gpu_inputs_free(ListBase *inputs)
{
GPUInput *input;
for (input = inputs->first; input; input = input->next) {
for (input = static_cast<GPUInput *>(inputs->first); input; input = input->next) {
switch (input->source) {
case GPU_SOURCE_ATTR:
input->attr->users--;
@@ -845,7 +851,7 @@ static void gpu_node_free(GPUNode *node)
gpu_inputs_free(&node->inputs);
for (output = node->outputs.first; output; output = output->next) {
for (output = static_cast<GPUOutput *>(node->outputs.first); output; output = output->next) {
if (output->link) {
output->link->output = NULL;
gpu_node_link_free(output->link);
@@ -860,7 +866,7 @@ void gpu_node_graph_free_nodes(GPUNodeGraph *graph)
{
GPUNode *node;
while ((node = BLI_pophead(&graph->nodes))) {
while ((node = static_cast<GPUNode *>(BLI_pophead(&graph->nodes)))) {
gpu_node_free(node);
}
@@ -932,7 +938,8 @@ void gpu_node_graph_prune_unused(GPUNodeGraph *graph)
gpu_nodes_tag(compositor_link->outlink, GPU_NODE_TAG_COMPOSITOR);
}
for (GPUNode *node = graph->nodes.first, *next = NULL; node; node = next) {
for (GPUNode *node = static_cast<GPUNode *>(graph->nodes.first), *next = NULL; node;
node = next) {
next = node->next;
if (node->tag == GPU_NODE_TAG_NONE) {
@@ -941,14 +948,20 @@ void gpu_node_graph_prune_unused(GPUNodeGraph *graph)
}
}
for (GPUMaterialAttribute *attr = graph->attributes.first, *next = NULL; attr; attr = next) {
for (GPUMaterialAttribute *attr = static_cast<GPUMaterialAttribute *>(graph->attributes.first),
*next = NULL;
attr;
attr = next) {
next = attr->next;
if (attr->users == 0) {
BLI_freelinkN(&graph->attributes, attr);
}
}
for (GPUMaterialTexture *tex = graph->textures.first, *next = NULL; tex; tex = next) {
for (GPUMaterialTexture *tex = static_cast<GPUMaterialTexture *>(graph->textures.first),
*next = NULL;
tex;
tex = next) {
next = tex->next;
if (tex->users == 0) {
BLI_freelinkN(&graph->textures, tex);