Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-03-07 21:39:50 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-03-07 21:41:05 +0300
commita261d6f2d3feb80efb51b27aa7cae56ea6c4c57d (patch)
tree9d80597e6436f0e5f8f4eaa97cfe1eb22d8f4e8f
parent8ca43a0c7b140fd40185b27e52884e5b79d79346 (diff)
Fix T62328, T62209: revert recent fix for texture slots updates (T60366).
This causes other issues, revert for now until a better fix is found. Reverts commit da1323d1c95095feff98e8aa054d73fd323c363d.
-rw-r--r--source/blender/blenkernel/BKE_material.h4
-rw-r--r--source/blender/blenkernel/intern/material.c83
-rw-r--r--source/blender/blenloader/intern/readfile.c1
-rw-r--r--source/blender/editors/render/render_update.c4
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c6
-rw-r--r--source/blender/editors/util/ed_util.c2
-rw-r--r--source/blender/makesrna/intern/rna_sculpt_paint.c2
8 files changed, 61 insertions, 43 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 84760a522f3..1c171ef6e7c 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -83,8 +83,8 @@ bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob);
struct MaterialGPencilStyle *BKE_material_gpencil_settings_get(struct Object *ob, short act);
-void BKE_texpaint_slot_refresh_cache(struct Material *ma);
-void BKE_texpaint_slots_refresh_object(struct Object *ob);
+void BKE_texpaint_slot_refresh_cache(struct Scene *scene, struct Material *ma);
+void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob);
/* rna api */
void BKE_material_resize_id(struct Main *bmain, struct ID *id, short totcol, bool do_id_user);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 05be84c14e6..5bc65bcda48 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -229,7 +229,6 @@ Material *BKE_material_localize(Material *ma)
Material *man = BKE_libblock_copy_for_localize(&ma->id);
man->texpaintslot = NULL;
- man->tot_slots = 0;
man->preview = NULL;
if (ma->nodetree != NULL) {
@@ -1048,7 +1047,7 @@ static int count_texture_nodes_recursive(bNodeTree *nodetree)
return tex_nodes;
}
-static void fill_texpaint_slots_recursive(bNodeTree *nodetree, bNode *active_node, Material *ma, TexPaintSlot *slots, int *index)
+static void fill_texpaint_slots_recursive(bNodeTree *nodetree, bNode *active_node, Material *ma, int *index)
{
for (bNode *node = nodetree->nodes.first; node; node = node->next) {
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
@@ -1056,77 +1055,99 @@ static void fill_texpaint_slots_recursive(bNodeTree *nodetree, bNode *active_nod
ma->paint_active_slot = *index;
}
- slots[*index].ima = (Image *)node->id;
- slots[*index].interp = ((NodeTexImage *)node->storage)->interpolation;
+ ma->texpaintslot[*index].ima = (Image *)node->id;
+ ma->texpaintslot[*index].interp = ((NodeTexImage *)node->storage)->interpolation;
/* for new renderer, we need to traverse the treeback in search of a UV node */
bNode *uvnode = nodetree_uv_node_recursive(node);
if (uvnode) {
NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage;
- slots[*index].uvname = storage->uv_map;
+ ma->texpaintslot[*index].uvname = storage->uv_map;
/* set a value to index so UI knows that we have a valid pointer for the mesh */
- slots[*index].valid = true;
+ ma->texpaintslot[*index].valid = true;
}
else {
/* just invalidate the index here so UV map does not get displayed on the UI */
- slots[*index].valid = false;
+ ma->texpaintslot[*index].valid = false;
}
(*index)++;
}
else if (node->type == NODE_GROUP && node->id) {
/* recurse into the node group and see if it contains any textures */
- fill_texpaint_slots_recursive((bNodeTree *)node->id, active_node, ma, slots, index);
+ fill_texpaint_slots_recursive((bNodeTree *)node->id, active_node, ma, index);
}
}
}
-void BKE_texpaint_slot_refresh_cache(Material *ma)
+void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma)
{
- if (ma == NULL) {
+ int count = 0;
+ int index = 0;
+
+ if (!ma)
return;
- }
- /* Compute texture paint slots. */
- TexPaintSlot *texpaintslot = NULL;
- int tot_slots = (ma->nodetree) ? count_texture_nodes_recursive(ma->nodetree) : 0;
+ /* COW needed when adding texture slot on an object with no materials. */
+ DEG_id_tag_update(&ma->id, ID_RECALC_SHADING | ID_RECALC_COPY_ON_WRITE);
- if (tot_slots) {
- texpaintslot = MEM_callocN(sizeof(*texpaintslot) * tot_slots, "texpaint_slots");
+ if (ma->texpaintslot) {
+ MEM_freeN(ma->texpaintslot);
+ ma->tot_slots = 0;
+ ma->texpaintslot = NULL;
+ }
- bNode *active_node = nodeGetActiveTexture(ma->nodetree);
- int index = 0;
- fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, texpaintslot, &index);
+ if (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_IMAGE) {
+ ma->paint_active_slot = 0;
+ ma->paint_clone_slot = 0;
+ return;
}
- /* Keep active slots within range. */
- if (ma->paint_active_slot >= tot_slots) {
- ma->paint_active_slot = MAX2(tot_slots - 1, 0);
+ if (!(ma->nodetree)) {
+ ma->paint_active_slot = 0;
+ ma->paint_clone_slot = 0;
+ return;
}
- if (ma->paint_clone_slot >= tot_slots) {
- ma->paint_clone_slot = MAX2(tot_slots - 1, 0);
+ count = count_texture_nodes_recursive(ma->nodetree);
+
+ if (count == 0) {
+ ma->paint_active_slot = 0;
+ ma->paint_clone_slot = 0;
+ return;
}
- /* Replace slots. */
- if (ma->texpaintslot) {
- MEM_freeN(ma->texpaintslot);
+ ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
+
+ bNode *active_node = nodeGetActiveTexture(ma->nodetree);
+
+ fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, &index);
+
+ ma->tot_slots = count;
+
+
+ if (ma->paint_active_slot >= count) {
+ ma->paint_active_slot = count - 1;
+ }
+
+ if (ma->paint_clone_slot >= count) {
+ ma->paint_clone_slot = count - 1;
}
- ma->texpaintslot = texpaintslot;
- ma->tot_slots = tot_slots;
+ return;
}
-void BKE_texpaint_slots_refresh_object(struct Object *ob)
+void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob)
{
int i;
for (i = 1; i < ob->totcol + 1; i++) {
Material *ma = give_current_material(ob, i);
- BKE_texpaint_slot_refresh_cache(ma);
+ BKE_texpaint_slot_refresh_cache(scene, ma);
}
}
+
/* r_col = current value, col = new value, (fac == 0) is no change */
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
{
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index e34382dc752..de997e7002d 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4513,7 +4513,6 @@ static void direct_link_material(FileData *fd, Material *ma)
direct_link_animdata(fd, ma->adt);
ma->texpaintslot = NULL;
- ma->tot_slots = 0;
ma->nodetree = newdataadr(fd, ma->nodetree);
if (ma->nodetree) {
diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c
index 6e6154e638a..462fd997fc5 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -206,8 +206,6 @@ void ED_render_engine_changed(Main *bmain)
static void material_changed(Main *UNUSED(bmain), Material *ma)
{
- BKE_texpaint_slot_refresh_cache(ma);
-
/* icons */
BKE_icon_changed(BKE_icon_id_ensure(&ma->id));
}
@@ -268,7 +266,7 @@ static void scene_changed(Main *bmain, Scene *scene)
/* glsl */
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (ob->mode & OB_MODE_TEXTURE_PAINT) {
- BKE_texpaint_slots_refresh_object(ob);
+ BKE_texpaint_slots_refresh_object(scene, ob);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 711571497e5..510f9827736 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1095,7 +1095,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
/* This has to stay here to regenerate the texture paint
* cache in case we are loading a file */
- BKE_texpaint_slots_refresh_object(ob);
+ BKE_texpaint_slots_refresh_object(scene, ob);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 7e767a6161f..e26d9b1ef9d 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5991,7 +5991,7 @@ bool BKE_paint_proj_mesh_data_check(Scene *scene, Object *ob, bool *uvs, bool *m
hasmat = true;
if (!ma->texpaintslot) {
/* refresh here just in case */
- BKE_texpaint_slot_refresh_cache(ma);
+ BKE_texpaint_slot_refresh_cache(scene, ma);
/* if still no slots, we have to add */
if (ma->texpaintslot) {
@@ -6251,13 +6251,13 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
nodePositionPropagate(out_node);
if (ima) {
- BKE_texpaint_slot_refresh_cache(ma);
+ BKE_texpaint_slot_refresh_cache(scene, ma);
BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
}
DEG_id_tag_update(&ntree->id, 0);
- DEG_id_tag_update(&ma->id, ID_RECALC_SHADING | ID_RECALC_COPY_ON_WRITE);
+ DEG_id_tag_update(&ma->id, ID_RECALC_SHADING);
ED_area_tag_redraw(CTX_wm_area(C));
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index ea99dd9996e..6f0c8594446 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -90,7 +90,7 @@ void ED_editors_init_for_undo(Main *bmain)
if (ob->mode & OB_MODE_TEXTURE_PAINT) {
Scene *scene = WM_window_get_active_scene(win);
- BKE_texpaint_slots_refresh_object(ob);
+ BKE_texpaint_slots_refresh_object(scene, ob);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
}
}
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index b849b0719e3..00d42fc408b 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -451,7 +451,7 @@ static void rna_ImaPaint_mode_update(bContext *C, PointerRNA *UNUSED(ptr))
if (ob && ob->type == OB_MESH) {
/* of course we need to invalidate here */
- BKE_texpaint_slots_refresh_object(ob);
+ BKE_texpaint_slots_refresh_object(scene, ob);
/* we assume that changing the current mode will invalidate the uv layers so we need to refresh display */
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);