Commit: d5cc07e2c742956028a4567b2e965541c0d0d0df
Author: Antony Riakiotakis
Date:   Tue Jun 24 17:44:52 2014 +0300
https://developer.blender.org/rBd5cc07e2c742956028a4567b2e965541c0d0d0df

Refresh texture paint caches of materials on changing render engine.

This is not perfect yet - it would help a lot if we could restore the
node mode of a material when changing the render engine too, but this
is maybe for later.

Also did some naming cleanups - we have texture paint slots now for
materials, not images.

===================================================================

M       source/blender/blenkernel/BKE_material.h
M       source/blender/blenkernel/intern/depsgraph.c
M       source/blender/blenkernel/intern/material.c
M       source/blender/editors/render/render_update.c
M       source/blender/editors/sculpt_paint/paint_image.c
M       source/blender/editors/sculpt_paint/paint_image_proj.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_material.h 
b/source/blender/blenkernel/BKE_material.h
index 723bae2..4a91763 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -88,10 +88,10 @@ short find_material_index(struct Object *ob, struct 
Material *ma);
 bool object_add_material_slot(struct Object *ob);
 bool object_remove_material_slot(struct Object *ob);
 
-bool get_mtex_slot_valid_texpaint(struct MTex *);
-void refresh_texpaint_image_cache(struct Material *ma, bool use_nodes);
+void refresh_texpaint_slot_cache(struct Material *ma, bool use_nodes);
 struct MTex *give_current_texpaint_slot(struct Material *ma);
-void refresh_object_texpaint_images(struct Object *ob, bool use_nodes);
+void refresh_object_texpaint_slots(struct Object *ob, bool use_nodes);
+void clear_texpaint_slots(struct Material *ma);
 
 /* rna api */
 void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user);
diff --git a/source/blender/blenkernel/intern/depsgraph.c 
b/source/blender/blenkernel/intern/depsgraph.c
index 4c8d1a3..4b2b0a6 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -2477,7 +2477,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, 
ID *id)
                        for (obt = bmain->object.first; obt; obt = 
obt->id.next) {
                                if (obt->mode & OB_MODE_TEXTURE_PAINT) {
                                        obt->recalc |= OB_RECALC_DATA;
-                                       refresh_object_texpaint_images(obt, 
new_shading_nodes);
+                                       refresh_object_texpaint_slots(obt, 
new_shading_nodes);
                                        lib_id_recalc_data_tag(bmain, &obt->id);
                                }
                        }
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index 5b32c01..f42aae5 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1306,15 +1306,27 @@ bool object_remove_material_slot(Object *ob)
        return true;
 }
 
-bool get_mtex_slot_valid_texpaint(struct MTex *mtex)
+void clear_texpaint_slots(struct Material *ma)
+{
+
+       if (ma->texpaintslot) {
+               MEM_freeN(ma->texpaintslot);
+               ma->texpaintslot = NULL;
+       }
+       ma->tot_slots = 0;
+       ma->paint_active_slot = 0;
+       ma->paint_clone_slot = 0;
+}
+
+
+static bool get_mtex_slot_valid_texpaint(struct MTex *mtex)
 {
        return (mtex && (mtex->texco == TEXCO_UV) &&
                mtex->tex && (mtex->tex->type == TEX_IMAGE) &&
                mtex->tex->ima);
 }
 
-
-void refresh_texpaint_image_cache(Material *ma, bool use_nodes)
+void refresh_texpaint_slot_cache(Material *ma, bool use_nodes)
 {
        MTex **mtex;
        short count = 0;
@@ -1393,7 +1405,7 @@ void refresh_texpaint_image_cache(Material *ma, bool 
use_nodes)
        return;
 }
 
-void refresh_object_texpaint_images(struct Object *ob, bool use_nodes)
+void refresh_object_texpaint_slots(struct Object *ob, bool use_nodes)
 {
        int i;
 
@@ -1402,7 +1414,7 @@ void refresh_object_texpaint_images(struct Object *ob, 
bool use_nodes)
 
        for (i = 1; i < ob->totcol + 1; i++) {
                Material *ma = give_current_material(ob, i);
-               refresh_texpaint_image_cache(ma, use_nodes);
+               refresh_texpaint_slot_cache(ma, use_nodes);
        }
 }
 
diff --git a/source/blender/editors/render/render_update.c 
b/source/blender/editors/render/render_update.c
index 94d8d78..a77747d 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -165,6 +165,7 @@ void ED_render_engine_changed(Main *bmain)
        bScreen *sc;
        ScrArea *sa;
        Scene *scene;
+       Material *ma;
 
        for (sc = bmain->screen.first; sc; sc = sc->id.next)
                for (sa = sc->areabase.first; sa; sa = sa->next)
@@ -174,6 +175,11 @@ void ED_render_engine_changed(Main *bmain)
 
        for (scene = bmain->scene.first; scene; scene = scene->id.next)
                ED_render_id_flush_update(bmain, &scene->id);
+
+       /* reset texture painting */
+       for (ma = bmain->mat.first; ma; ma = ma->id.next) {
+               clear_texpaint_slots(ma);
+       }
 }
 
 /***************************** Updates ***********************************
diff --git a/source/blender/editors/sculpt_paint/paint_image.c 
b/source/blender/editors/sculpt_paint/paint_image.c
index a725729..74a5dcd 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1440,7 +1440,7 @@ static int texture_paint_toggle_exec(bContext *C, 
wmOperator *op)
                bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
                /* This has to stay here to regenerate the texture paint
                 * cache in case we are loading a file */
-               refresh_object_texpaint_images(ob, use_nodes);
+               refresh_object_texpaint_slots(ob, use_nodes);
 
                paint_proj_mesh_data_ensure(C, ob, op);
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 1b21eaa..5fa6480 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4870,7 +4870,7 @@ bool proj_paint_add_slot(bContext *C, int type, Material 
*ma)
                                        ima = mtex->tex->ima = 
BKE_image_add_generated(bmain, width, height, imagename, 32, use_float,
                                                                                
       IMA_GENTYPE_BLANK, color);
 
-                                       refresh_texpaint_image_cache(ma, false);
+                                       refresh_texpaint_slot_cache(ma, false);
                                        BKE_image_signal(ima, NULL, 
IMA_SIGNAL_USER_NEW_IMAGE);
                                        WM_event_add_notifier(C, NC_TEXTURE | 
NA_ADDED, mtex->tex);
                                        WM_event_add_notifier(C, NC_IMAGE | 
NA_ADDED, ima);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to