svn merge ^/trunk/blender -r42053:42069
[blender.git] / source / blender / editors / sculpt_paint / paint_image.c
index 7625633ea6c049d34768e9b79a55869b9b2bb09c..3bca2f46efe1bca38b68da9f5bea138544660d07 100644 (file)
@@ -300,6 +300,7 @@ typedef struct ProjPaintState {
        short do_occlude;                       /* Use raytraced occlusion? - ortherwise will paint right through to the back*/
        short do_backfacecull;  /* ignore faces with normals pointing away, skips a lot of raycasts if your normals are correctly flipped */
        short do_mask_normal;                   /* mask out pixels based on their normals */
+       short do_new_shading_nodes;     /* cache scene_use_new_shading_nodes value */
        float normal_angle;                             /* what angle to mask at*/
        float normal_angle_inner;
        float normal_angle_range;               /* difference between normal_angle and normal_angle_inner, for easy access */
@@ -518,17 +519,16 @@ static Image *imapaint_face_image(const ImagePaintState *s, int face_index)
        return ima;
 }
 
-static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
+static Image *project_paint_face_image(const ProjPaintState *ps, MTFace *dm_mtface, int face_index)
 {
        Image *ima;
 
-       if(scene_use_new_shading_nodes(ps->scene)) {
+       if(ps->do_new_shading_nodes) { /* cached scene_use_new_shading_nodes result */
                MFace *mf = ps->dm_mface+face_index;
                ED_object_get_active_image(ps->ob, mf->mat_nr, &ima, NULL, NULL);
        }
        else {
-               MTFace *tf = ps->dm_mtface+face_index;
-               ima = tf->tpage;
+               ima = dm_mtface[face_index].tpage;
        }
 
        return ima;
@@ -725,7 +725,7 @@ static int project_paint_PickColor(const ProjPaintState *ps, float pt[2], float
                interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
        }
 
-       ima = project_paint_face_image(ps, face_index);
+       ima = project_paint_face_image(ps, ps->dm_mtface, face_index);
        ibuf = ima->ibufs.first; /* we must have got the imbuf before getting here */
        if (!ibuf) return 0;
        
@@ -1091,8 +1091,8 @@ static int check_seam(const ProjPaintState *ps, const int orig_face, const int o
                        
                        /* Only need to check if 'i2_fidx' is valid because we know i1_fidx is the same vert on both faces */
                        if (i2_fidx != -1) {
-                               Image *tpage = project_paint_face_image(ps, face_index);
-                               Image *orig_tpage = project_paint_face_image(ps, orig_face);
+                               Image *tpage = project_paint_face_image(ps, ps->dm_mtface, face_index);
+                               Image *orig_tpage = project_paint_face_image(ps, ps->dm_mtface, orig_face);
 
                                /* This IS an adjacent face!, now lets check if the UVs are ok */
                                tf = ps->dm_mtface + face_index;
@@ -1349,7 +1349,7 @@ static float project_paint_uvpixel_mask(
        if (ps->do_layer_stencil) {
                /* another UV layers image is masking this one's */
                ImBuf *ibuf_other;
-               Image *other_tpage = project_paint_face_image(ps, face_index);
+               Image *other_tpage = project_paint_face_image(ps, ps->dm_mtface_stencil, face_index);
                const MTFace *tf_other = ps->dm_mtface_stencil + face_index;
                
                if (other_tpage && (ibuf_other = BKE_image_get_ibuf(other_tpage, NULL))) {
@@ -1506,7 +1506,7 @@ static ProjPixel *project_paint_uvpixel_init(
        if (ps->tool==PAINT_TOOL_CLONE) {
                if (ps->dm_mtface_clone) {
                        ImBuf *ibuf_other;
-                       Image *other_tpage = project_paint_face_image(ps, face_index);
+                       Image *other_tpage = project_paint_face_image(ps, ps->dm_mtface_clone, face_index);
                        const MTFace *tf_other = ps->dm_mtface_clone + face_index;
                        
                        if (other_tpage && (ibuf_other = BKE_image_get_ibuf(other_tpage, NULL))) {
@@ -2746,7 +2746,7 @@ static void project_bucket_init(const ProjPaintState *ps, const int thread_index
                        face_index = GET_INT_FROM_POINTER(node->link);
                                
                        /* Image context switching */
-                       tpage = project_paint_face_image(ps, face_index);
+                       tpage = project_paint_face_image(ps, ps->dm_mtface, face_index);
                        if (tpage_last != tpage) {
                                tpage_last = tpage;
 
@@ -3252,7 +3252,7 @@ static void project_paint_begin(ProjPaintState *ps)
                }
 #endif
                
-               tpage = project_paint_face_image(ps, face_index);
+               tpage = project_paint_face_image(ps, ps->dm_mtface, face_index);
 
                if (tpage && ((((Mesh *)ps->ob->data)->editflag & ME_EDIT_PAINT_MASK)==0 || mf->flag & ME_FACE_SEL)) {
                        
@@ -4718,6 +4718,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps)
        ps->do_backfacecull = (settings->imapaint.flag & IMAGEPAINT_PROJECT_BACKFACE) ? 0 : 1;
        ps->do_occlude = (settings->imapaint.flag & IMAGEPAINT_PROJECT_XRAY) ? 0 : 1;
        ps->do_mask_normal = (settings->imapaint.flag & IMAGEPAINT_PROJECT_FLAT) ? 0 : 1;
+       ps->do_new_shading_nodes = scene_use_new_shading_nodes(scene); /* only cache the value */
 
        if (ps->tool == PAINT_TOOL_CLONE)
                ps->do_layer_clone = (settings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE);