Fix T53971: single layer render showing the wrong render layer in image editor.
authorCheryl Chen <chnchryl>
Thu, 15 Mar 2018 22:36:15 +0000 (23:36 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 15 Mar 2018 23:58:10 +0000 (00:58 +0100)
Original patch Cheryl Chen, extra fixes by Brecht.

Differential Revision: https://developer.blender.org/D3098

source/blender/editors/render/render_internal.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/pipeline.c

index 58b4c0f..c27570a 100644 (file)
@@ -521,10 +521,8 @@ static void render_image_update_pass_and_layer(RenderJob *rj, RenderResult *rr,
                        int layer = BLI_findstringindex(&main_rr->layers,
                                                        (char *)rr->renlay->name,
                                                        offsetof(RenderLayer, name));
-                       if (layer != rj->last_layer) {
-                               sima->iuser.layer = layer;
-                               rj->last_layer = layer;
-                       }
+                       sima->iuser.layer = layer;
+                       rj->last_layer = layer;
                }
 
                iuser->pass = sima->iuser.pass;
@@ -621,7 +619,21 @@ static void render_image_restore_layer(RenderJob *rj)
                                if (sa == rj->sa) {
                                        if (sa->spacetype == SPACE_IMAGE) {
                                                SpaceImage *sima = sa->spacedata.first;
-                                               sima->iuser.layer = rj->orig_layer;
+
+                                               if (RE_HasSingleLayer(rj->re)) {
+                                                       /* For single layer renders keep the active layer
+                                                        * visible, or show the compositing result. */
+                                                       RenderResult *rr = RE_AcquireResultRead(rj->re);
+                                                       if(RE_HasCombinedLayer(rr)) {
+                                                               sima->iuser.layer = 0;
+                                                       }
+                                                       RE_ReleaseResult(rj->re);
+                                               }
+                                               else {
+                                                       /* For multiple layer render, set back the layer
+                                                        * that was set at the start of rendering. */
+                                                       sima->iuser.layer = rj->orig_layer;
+                                               }
                                        }
                                        return;
                                }
index bb05667..de71b8d 100644 (file)
@@ -236,6 +236,8 @@ void RE_render_result_rect_from_ibuf(
 struct RenderLayer *RE_GetRenderLayer(struct RenderResult *rr, const char *name);
 float *RE_RenderLayerGetPass(volatile struct RenderLayer *rl, const char *name, const char *viewname);
 
+bool RE_HasSingleLayer(struct Render *re);
+
 /* add passes for grease pencil */
 struct RenderPass *RE_create_gp_pass(struct RenderResult *rr, const char *layername, const char *viewname);
 
index 7cab5f4..e17a503 100644 (file)
@@ -257,6 +257,11 @@ RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name)
        }
 }
 
+bool RE_HasSingleLayer(Render *re)
+{
+       return (re->r.scemode & R_SINGLE_LAYER);
+}
+
 RenderResult *RE_MultilayerConvert(void *exrhandle, const char *colorspace, bool predivide, int rectx, int recty)
 {
        return render_result_new_from_exr(exrhandle, colorspace, predivide, rectx, recty);
@@ -264,12 +269,19 @@ RenderResult *RE_MultilayerConvert(void *exrhandle, const char *colorspace, bool
 
 RenderLayer *render_get_active_layer(Render *re, RenderResult *rr)
 {
-       RenderLayer *rl = BLI_findlink(&rr->layers, re->r.actlay);
-       
-       if (rl)
-               return rl;
-       else 
-               return rr->layers.first;
+       SceneRenderLayer *srl = BLI_findlink(&re->r.layers, re->r.actlay);
+
+       if (srl) {
+               RenderLayer *rl = BLI_findstring(&rr->layers,
+                                                srl->name,
+                                                offsetof(RenderLayer, name));
+
+               if (rl) {
+                       return rl;
+               }
+       }
+
+       return rr->layers.first;
 }
 
 static int render_scene_needs_vector(Render *re)