Workspaces: active view layer now always comes from workspace, not scene.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 24 Apr 2018 13:20:17 +0000 (15:20 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 26 Apr 2018 15:06:14 +0000 (17:06 +0200)
Both the scene and workspace had an active view layer, and it was confusing
which settings were being used or displayed where. Now we always have one,
so there is no mismatch.

The "View Layers" tab in the properties editor is now "View Layer", no longer
showing a list of layers. Instead view layers can be added and removed with
the workspace view layer selector. They are also listed and selectable in the
outliner.

Single layer rendering uses the active view layer from the workspace.

This fixes bugs where the wrong active view layer was used, but more places
remain that are wrong and are now using the first view layer in the scene.
These are all marked with BKE_view_layer_context_active_PLACEHOLDER.

59 files changed:
intern/cycles/blender/addon/properties.py
intern/cycles/blender/addon/ui.py
release/scripts/startup/bl_operators/freestyle.py
release/scripts/startup/bl_ui/properties_freestyle.py
release/scripts/startup/bl_ui/properties_view_layer.py
release/scripts/startup/bl_ui/space_node.py
release/scripts/startup/bl_ui/space_topbar.py
source/blender/blenkernel/BKE_layer.h
source/blender/blenkernel/BKE_linestyle.h
source/blender/blenkernel/BKE_scene.h
source/blender/blenkernel/intern/blendfile.c
source/blender/blenkernel/intern/layer.c
source/blender/blenkernel/intern/linestyle.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/tracking.c
source/blender/blenloader/intern/versioning_280.c
source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
source/blender/editors/object/object_bake_api.c
source/blender/editors/render/render_internal.c
source/blender/editors/render/render_opengl.c
source/blender/editors/render/render_preview.c
source/blender/editors/render/render_shading.c
source/blender/editors/scene/scene_edit.c
source/blender/editors/space_buttons/buttons_context.c
source/blender/editors/space_buttons/buttons_texture.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_outliner/outliner_select.c
source/blender/editors/space_outliner/outliner_tree.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/editors/space_topbar/space_topbar.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_layer.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/nodes/shader/node_shader_tree.c
source/blender/nodes/texture/node_texture_tree.c
source/blender/render/extern/include/RE_bake.h
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/external_engine.c
source/blender/render/intern/source/pipeline.c
tests/python/view_layer/test_evaluation_selectability_a.py
tests/python/view_layer/test_evaluation_selectability_b.py
tests/python/view_layer/test_evaluation_selectability_c.py
tests/python/view_layer/test_evaluation_selectability_d.py
tests/python/view_layer/test_evaluation_selectability_e.py
tests/python/view_layer/test_evaluation_selectability_f.py
tests/python/view_layer/test_evaluation_visibility_a.py
tests/python/view_layer/test_evaluation_visibility_b.py
tests/python/view_layer/test_evaluation_visibility_c.py
tests/python/view_layer/test_evaluation_visibility_d.py
tests/python/view_layer/test_evaluation_visibility_e.py
tests/python/view_layer/test_evaluation_visibility_f.py
tests/python/view_layer/test_object_copy.py
tests/python/view_layer/test_object_link_b.py
tests/python/view_layer/test_operator_context.py
tests/python/view_layer/view_layer_common.py

index 0e88ed0b6ea79c84dd16f2651939cabf0f63f772..f3403602beaccc85015acb409a3b71b1b3a10139 100644 (file)
@@ -1195,7 +1195,7 @@ class CyclesCurveRenderSettings(bpy.types.PropertyGroup):
 def update_render_passes(self, context):
     scene = context.scene
     rd = scene.render
-    view_layer = scene.view_layers.active
+    view_layer = context.view_layer
     view_layer.update_render_passes()
 
 class CyclesRenderLayerSettings(bpy.types.PropertyGroup):
index 37c040e2362a60622a8f8daf8a0c13d79683f551..98619b4f1636f066e65bf8e7d42f37a80d78c9db 100644 (file)
@@ -436,8 +436,8 @@ class CYCLES_RENDER_PT_performance(CyclesButtonsPanel, Panel):
         split.prop(cscene, "preview_start_resolution")
 
 
-class CYCLES_RENDER_PT_layer_options(CyclesButtonsPanel, Panel):
-    bl_label = "Layer"
+class CYCLES_RENDER_PT_filter(CyclesButtonsPanel, Panel):
+    bl_label = "Filter"
     bl_context = "view_layer"
 
     def draw(self, context):
@@ -446,7 +446,7 @@ class CYCLES_RENDER_PT_layer_options(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         rd = scene.render
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
 
         col = layout.column()
         col.prop(view_layer, "use_sky", "Use Environment")
@@ -471,7 +471,7 @@ class CYCLES_RENDER_PT_layer_passes(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         rd = scene.render
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         cycles_view_layer = view_layer.cycles
 
         split = layout.split()
@@ -545,7 +545,7 @@ class CYCLES_RENDER_PT_denoising(CyclesButtonsPanel, Panel):
 
     def draw_header(self, context):
         scene = context.scene
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         cycles_view_layer = view_layer.cycles
         cscene = scene.cycles
         layout = self.layout
@@ -557,7 +557,7 @@ class CYCLES_RENDER_PT_denoising(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         cscene = scene.cycles
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         cycles_view_layer = view_layer.cycles
 
         layout.active = cycles_view_layer.use_denoising
@@ -1545,7 +1545,7 @@ def get_panels():
         'DATA_PT_spot',
         'MATERIAL_PT_context_material',
         'MATERIAL_PT_preview',
-        'VIEWLAYER_PT_layer_options',
+        'VIEWLAYER_PT_filter',
         'VIEWLAYER_PT_layer_passes',
         'RENDER_PT_post_processing',
         'SCENE_PT_simplify',
@@ -1569,7 +1569,7 @@ classes = (
     CYCLES_RENDER_PT_motion_blur,
     CYCLES_RENDER_PT_film,
     CYCLES_RENDER_PT_performance,
-    CYCLES_RENDER_PT_layer_options,
+    CYCLES_RENDER_PT_filter,
     CYCLES_RENDER_PT_layer_passes,
     CYCLES_RENDER_PT_denoising,
     CYCLES_PT_post_processing,
index 0cfe78879db569ae42fc67d1ad7fb3d05833e3bc..d3023f8e582a696f77232fa3560b8b05fb03d349 100644 (file)
@@ -47,14 +47,14 @@ class SCENE_OT_freestyle_fill_range_by_selection(bpy.types.Operator):
 
     @classmethod
     def poll(cls, context):
-        view_layer = context.scene.view_layers.active
+        view_layer = context.view_layer
         return view_layer and view_layer.freestyle_settings.linesets.active
 
     def execute(self, context):
         import sys
 
         scene = context.scene
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         lineset = view_layer.freestyle_settings.linesets.active
         linestyle = lineset.linestyle
         # Find the modifier to work on
@@ -207,7 +207,7 @@ class SCENE_OT_freestyle_module_open(bpy.types.Operator):
 
     @classmethod
     def poll(cls, context):
-        view_layer = context.scene.view_layers.active
+        view_layer = context.view_layer
         return view_layer and view_layer.freestyle_settings.mode == 'SCRIPT'
 
     def invoke(self, context, event):
index 84ebb21c7033f013955c859ea5d98e8b58da9146..a9c9d512335b13d02c1707e19345503e7a428da0 100644 (file)
@@ -71,11 +71,11 @@ class ViewLayerFreestyleButtonsPanel:
     @classmethod
     def poll(cls, context):
         scene = context.scene
-        rd = context.scene.render
+        rd = scene.render
         with_freestyle = bpy.app.build_options.freestyle
 
         return (scene and with_freestyle and rd.use_freestyle and
-                scene.view_layers.active and(context.engine in cls.COMPAT_ENGINES))
+                (context.engine in cls.COMPAT_ENGINES))
 
 
 class ViewLayerFreestyleEditorButtonsPanel(ViewLayerFreestyleButtonsPanel):
@@ -85,7 +85,7 @@ class ViewLayerFreestyleEditorButtonsPanel(ViewLayerFreestyleButtonsPanel):
     def poll(cls, context):
         if not super().poll(context):
             return False
-        view_layer = context.scene.view_layers.active
+        view_layer = context.view_layer
         return view_layer and view_layer.freestyle_settings.mode == 'EDITOR'
 
 
@@ -117,7 +117,7 @@ class VIEWLAYER_PT_freestyle(ViewLayerFreestyleButtonsPanel, Panel):
         layout = self.layout
 
         scene = context.scene
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         freestyle = view_layer.freestyle_settings
 
         layout.active = view_layer.use_freestyle
@@ -186,7 +186,7 @@ class VIEWLAYER_PT_freestyle_lineset(ViewLayerFreestyleEditorButtonsPanel, Panel
         scene = context.scene
         rd = scene.render
 
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         freestyle = view_layer.freestyle_settings
         lineset = freestyle.linesets.active
 
@@ -378,7 +378,7 @@ class VIEWLAYER_PT_freestyle_linestyle(ViewLayerFreestyleEditorButtonsPanel, Pan
                 row = box.row(align=True)
                 row.prop(modifier, "curvature_min")
                 row.prop(modifier, "curvature_max")
-                freestyle = context.scene.view_layers.active.freestyle_settings
+                freestyle = context.view_layer.freestyle_settings
                 if not freestyle.use_smoothness:
                     message = "Enable Face Smoothness to use this modifier"
                     self.draw_modifier_box_error(col.box(), modifier, message)
@@ -433,7 +433,7 @@ class VIEWLAYER_PT_freestyle_linestyle(ViewLayerFreestyleEditorButtonsPanel, Pan
                 row = box.row(align=True)
                 row.prop(modifier, "curvature_min")
                 row.prop(modifier, "curvature_max")
-                freestyle = context.scene.view_layers.active.freestyle_settings
+                freestyle = context.view_layer.freestyle_settings
                 if not freestyle.use_smoothness:
                     message = "Enable Face Smoothness to use this modifier"
                     self.draw_modifier_box_error(col.box(), modifier, message)
@@ -505,7 +505,7 @@ class VIEWLAYER_PT_freestyle_linestyle(ViewLayerFreestyleEditorButtonsPanel, Pan
                 row = box.row(align=True)
                 row.prop(modifier, "curvature_min")
                 row.prop(modifier, "curvature_max")
-                freestyle = context.scene.view_layers.active.freestyle_settings
+                freestyle = context.view_layer.freestyle_settings
                 if not freestyle.use_smoothness:
                     message = "Enable Face Smoothness to use this modifier"
                     self.draw_modifier_box_error(col.box(), modifier, message)
@@ -614,7 +614,7 @@ class VIEWLAYER_PT_freestyle_linestyle(ViewLayerFreestyleEditorButtonsPanel, Pan
         layout = self.layout
 
         scene = context.scene
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
         lineset = view_layer.freestyle_settings.linesets.active
 
         layout.active = view_layer.use_freestyle
index 28fd5bf666f6da9cebdf2a22ec11722f453d3518..842a3f36fa23d0c73c9d8e5ad95d0384210ba458 100644 (file)
@@ -32,21 +32,8 @@ class ViewLayerButtonsPanel:
         return (context.engine in cls.COMPAT_ENGINES)
 
 
-class VIEWLAYER_UL_viewlayers(UIList):
-    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
-        # assert(isinstance(item, bpy.types.SceneLayer)
-        layer = item
-        if self.layout_type in {'DEFAULT', 'COMPACT'}:
-            layout.prop(layer, "name", text="", icon_value=icon, emboss=False)
-            layout.prop(layer, "use", text="", index=index)
-        elif self.layout_type == 'GRID':
-            layout.alignment = 'CENTER'
-            layout.label("", icon_value=icon)
-
-
-class VIEWLAYER_PT_layers(ViewLayerButtonsPanel, Panel):
-    bl_label = "Layer List"
-    bl_options = {'HIDE_HEADER'}
+class VIEWLAYER_PT_layer(ViewLayerButtonsPanel, Panel):
+    bl_label = "View Layer"
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_CLAY', 'BLENDER_EEVEE'}
 
     def draw(self, context):
@@ -54,16 +41,10 @@ class VIEWLAYER_PT_layers(ViewLayerButtonsPanel, Panel):
 
         scene = context.scene
         rd = scene.render
+        layer = bpy.context.view_layer
 
-        row = layout.row()
-        col = row.column()
-        col.template_list("VIEWLAYER_UL_viewlayers", "", scene, "view_layers", scene.view_layers, "active_index", rows=2)
-
-        col = row.column()
-        sub = col.column(align=True)
-        sub.operator("scene.view_layer_add", icon='ZOOMIN', text="")
-        sub.operator("scene.view_layer_remove", icon='ZOOMOUT', text="")
-        col.prop(rd, "use_single_layer", icon_only=True)
+        layout.prop(layer, "use", text="Use for Rendering");
+        layout.prop(rd, "use_single_layer", text="Render Single Layer")
 
 
 class VIEWLAYER_PT_clay_settings(ViewLayerButtonsPanel, Panel):
@@ -385,7 +366,7 @@ class VIEWLAYER_PT_eevee_layer_passes(ViewLayerButtonsPanel, Panel):
 
         scene = context.scene
         rd = scene.render
-        view_layer = scene.view_layers.active
+        view_layer = context.view_layer
 
         split = layout.split()
 
@@ -405,8 +386,7 @@ class VIEWLAYER_PT_eevee_layer_passes(ViewLayerButtonsPanel, Panel):
 
 
 classes = (
-    VIEWLAYER_UL_viewlayers,
-    VIEWLAYER_PT_layers,
+    VIEWLAYER_PT_layer,
     VIEWLAYER_PT_clay_settings,
     VIEWLAYER_PT_eevee_sampling,
     VIEWLAYER_PT_eevee_shadows,
index f97c88be0ad2b82548023947af66f1043b94318a..23d822bbf1fdc837ab72fe4204d6f3a4b1e9a973 100644 (file)
@@ -79,7 +79,7 @@ class NODE_HT_header(Header):
                     row.prop(snode_id, "use_nodes")
 
             if snode.shader_type == 'LINESTYLE':
-                view_layer = context.scene.view_layers.active
+                view_layer = context.view_layer
                 lineset = view_layer.freestyle_settings.linesets.active
                 if lineset is not None:
                     row = layout.row()
index 3eded5e0b466bfd807f6cadc38b01a114355cbfa..b6d88dc5a6ee0865bf9cd1c6e56c62b053414a88 100644 (file)
@@ -85,7 +85,13 @@ class TOPBAR_HT_upper_bar(Header):
 
         # Active workspace view-layer is retrieved through window, not through workspace.
         layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
-        layout.template_search(window, "view_layer", scene, "view_layers")
+
+        row = layout.row(align=True)
+        row.template_search(
+            window, "view_layer",
+            scene, "view_layers",
+            new="scene.view_layer_add",
+            unlink="scene.view_layer_remove")
 
 
 class TOPBAR_HT_lower_bar(Header):
index 79b61b7c965ce396f6b5c191ecca326bcb1c32c8..27e3d32a51093e5d1759ace29a6c898ab560137a 100644 (file)
@@ -58,7 +58,8 @@ struct WorkSpace;
 
 void BKE_layer_exit(void);
 
-struct ViewLayer *BKE_view_layer_from_scene_get(const struct Scene *scene);
+struct ViewLayer *BKE_view_layer_default_view(const struct Scene *scene);
+struct ViewLayer *BKE_view_layer_default_render(const struct Scene *scene);
 struct ViewLayer *BKE_view_layer_from_workspace_get(const struct Scene *scene, const struct WorkSpace *workspace);
 struct ViewLayer *BKE_view_layer_add(struct Scene *scene, const char *name);
 struct ViewLayer *BKE_view_layer_group_add(struct Group *group);
index 3ba4fbe03385dc01e3704c710d58a2feafc3b0e7..376a324d25c0e227f7cd7794be3393a8a4efb77e 100644 (file)
@@ -48,6 +48,7 @@ struct Main;
 struct Object;
 struct ColorBand;
 struct bContext;
+struct ViewLayer;
 
 void BKE_linestyle_init(struct FreestyleLineStyle *linestyle);
 FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name);
@@ -59,7 +60,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineSt
 
 void BKE_linestyle_make_local(struct Main *bmain, struct FreestyleLineStyle *linestyle, const bool lib_local);
 
-FreestyleLineStyle *BKE_linestyle_active_from_scene(struct Scene *scene);
+FreestyleLineStyle *BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer);
 
 LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type);
 LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type);
index bdbed9ab6aa38d90102538d4cf9614dd668927a8..44aa1b04569d14d61240f3651b9ee7542910f1d4 100644 (file)
@@ -60,7 +60,7 @@ typedef enum eSceneCopyMethod {
 
 /* Use as the contents of a 'for' loop: for (SETLOOPER(...)) { ... */
 #define SETLOOPER(_sce_basis, _sce_iter, _base)                               \
-       _sce_iter = _sce_basis, _base = _setlooper_base_step(&_sce_iter, BKE_view_layer_from_scene_get(_sce_basis), NULL); \
+       _sce_iter = _sce_basis, _base = _setlooper_base_step(&_sce_iter, BKE_view_layer_context_active_PLACEHOLDER(_sce_basis), NULL); \
        _base;                                                                    \
        _base = _setlooper_base_step(&_sce_iter, NULL, _base)
 
index 74e6c996329a299baab2ad8c34ec0e0673c283d7..34079d778f72e6e78109e8f6f3f40e2252b511c6 100644 (file)
@@ -194,7 +194,7 @@ static void setup_app_data(
                }
                if (cur_view_layer == NULL) {
                        /* fallback to scene layer */
-                       cur_view_layer = BKE_view_layer_from_scene_get(curscene);
+                       cur_view_layer = BKE_view_layer_default_view(curscene);
                }
 
                if (track_undo_scene) {
index 41bdc3bb9ef3c2c544d9ad36c76b32c65ed3e92a..215826454a9222e1408125f115e0b45f71399b90 100644 (file)
@@ -75,15 +75,37 @@ static void object_bases_iterator_next(BLI_Iterator *iter, const int flag);
 
 /* RenderLayer */
 
-/**
- * Returns the ViewLayer to be used for rendering
- * Most of the time BKE_view_layer_from_workspace_get should be used instead
- */
-ViewLayer *BKE_view_layer_from_scene_get(const Scene *scene)
+/* Returns the default view layer to view in workspaces if there is
+ * none linked to the workspace yet. */
+ViewLayer *BKE_view_layer_default_view(const Scene *scene)
 {
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
-       BLI_assert(view_layer);
-       return view_layer;
+       /* TODO: it makes more sense to have the Viewport layer as the default,
+        * but this breaks view layer tests so change it later. */
+#if 0
+       for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+               if (!(view_layer->flag & VIEW_LAYER_RENDER)) {
+                       return view_layer;
+               }
+       }
+
+       BLI_assert(scene->view_layers.first);
+       return scene->view_layers.first;
+#else
+       return BKE_view_layer_default_render(scene);
+#endif
+}
+
+/* Returns the default view layer to render if we need to render just one. */
+ViewLayer *BKE_view_layer_default_render(const Scene *scene)
+{
+       for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+               if (view_layer->flag & VIEW_LAYER_RENDER) {
+                       return view_layer;
+               }
+       }
+
+       BLI_assert(scene->view_layers.first);
+       return scene->view_layers.first;
 }
 
 /**
@@ -100,7 +122,8 @@ ViewLayer *BKE_view_layer_from_workspace_get(const struct Scene *scene, const st
  */
 ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene)
 {
-       return BKE_view_layer_from_scene_get(scene);
+       BLI_assert(scene->view_layers.first);
+       return scene->view_layers.first;
 }
 
 static ViewLayer *view_layer_add(const char *name, SceneCollection *master_scene_collection)
@@ -2253,7 +2276,7 @@ void BKE_view_layer_renderable_objects_iterator_next(BLI_Iterator *iter)
 
        /* Look for an object in the next set. */
        while ((data->iter.set = data->iter.set->set)) {
-               ViewLayer *view_layer = BKE_view_layer_from_scene_get(data->iter.set);
+               ViewLayer *view_layer = BKE_view_layer_default_render(data->iter.set);
                data->base_temp.next = view_layer->object_bases.first;
                data->iter.base = &data->base_temp;
                return;
index dd1315fe3fa75364585d813ec989309fb9d641f4..5757ae7480b1a0c1d31e52320a0a2981a444e3c3 100644 (file)
@@ -212,17 +212,11 @@ void BKE_linestyle_make_local(struct Main *bmain, FreestyleLineStyle *linestyle,
        BKE_id_make_local_generic(bmain, &linestyle->id, true, lib_local);
 }
 
-FreestyleLineStyle *BKE_linestyle_active_from_scene(Scene *scene)
+FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer)
 {
-       ViewLayer *active_render_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
-       if (active_render_layer) {
-               FreestyleConfig *config = &active_render_layer->freestyle_config;
-               FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
-               if (lineset) {
-                       return lineset->linestyle;
-               }
-       }
-       return NULL;
+       FreestyleConfig *config = &view_layer->freestyle_config;
+       FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
+       return (lineset) ? lineset->linestyle : NULL;
 }
 
 static LineStyleModifier *new_modifier(const char *name, int type, size_t size)
index 91ff3c155020e6663037c2c6e4cd329b75208b18..758db5178de453ab3b4898972505f4a811cf69c9 100644 (file)
@@ -346,7 +346,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
                rv = sce_copy->r.views;
                curvemapping_free_data(&sce_copy->r.mblur_shutter_curve);
                sce_copy->r = sce->r;
-               sce_copy->active_view_layer = 0;
                sce_copy->r.views = rv;
                sce_copy->unit = sce->unit;
                sce_copy->physics_settings = sce->physics_settings;
@@ -934,7 +933,7 @@ int BKE_scene_base_iter_next(
                        if (iter->phase == F_START) {
                                ViewLayer *view_layer = (depsgraph) ?
                                        DEG_get_evaluated_view_layer(depsgraph) :
-                                       BKE_view_layer_from_scene_get(*scene);
+                                       BKE_view_layer_context_active_PLACEHOLDER(*scene);
                                *base = view_layer->object_bases.first;
                                if (*base) {
                                        *ob = (*base)->object;
@@ -944,7 +943,7 @@ int BKE_scene_base_iter_next(
                                        /* exception: empty scene layer */
                                        while ((*scene)->set) {
                                                (*scene) = (*scene)->set;
-                                               ViewLayer *view_layer_set = BKE_view_layer_from_scene_get((*scene));
+                                               ViewLayer *view_layer_set = BKE_view_layer_default_render((*scene));
                                                if (view_layer_set->object_bases.first) {
                                                        *base = view_layer_set->object_bases.first;
                                                        *ob = (*base)->object;
@@ -965,7 +964,7 @@ int BKE_scene_base_iter_next(
                                                        /* (*scene) is finished, now do the set */
                                                        while ((*scene)->set) {
                                                                (*scene) = (*scene)->set;
-                                                               ViewLayer *view_layer_set = BKE_view_layer_from_scene_get((*scene));
+                                                               ViewLayer *view_layer_set = BKE_view_layer_default_render((*scene));
                                                                if (view_layer_set->object_bases.first) {
                                                                        *base = view_layer_set->object_bases.first;
                                                                        *ob = (*base)->object;
@@ -1465,7 +1464,7 @@ Base *_setlooper_base_step(Scene **sce_iter, ViewLayer *view_layer, Base *base)
 next_set:
                /* Reached the end, get the next base in the set. */
                while ((*sce_iter = (*sce_iter)->set)) {
-                       ViewLayer *view_layer_set = BKE_view_layer_from_scene_get((*sce_iter));
+                       ViewLayer *view_layer_set = BKE_view_layer_default_render((*sce_iter));
                        base = (Base *)view_layer_set->object_bases.first;
 
                        if (base) {
index 974c2faeadf299e9e2d25a5b5d1976e39c9d6597..a282f535df66e4db621887d866d644d8a3af2427 100644 (file)
@@ -3269,7 +3269,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
        have_comp = (scene->r.scemode & R_DOCOMP) && scene->use_nodes && scene->nodetree;
 
        /* Get view layer for the strip. */
-       ViewLayer *view_layer = BKE_view_layer_from_scene_get(scene);
+       ViewLayer *view_layer = BKE_view_layer_default_render(scene);
        /* Depsgraph will be NULL when doing rendering. */
        Depsgraph *depsgraph = NULL;
 
index ebd4c04e8ce9334c11d1dd1a06e370ec4bc44c3b..3314e8d01b661f24ff0df1249e13d60f2189f620 100644 (file)
@@ -401,7 +401,7 @@ void BKE_tracking_get_camera_object_matrix(Scene *scene, Object *ob, float mat[4
                if (scene->camera)
                        ob = scene->camera;
                else
-                       ob = BKE_view_layer_camera_find(BKE_view_layer_from_scene_get(scene));
+                       ob = BKE_view_layer_camera_find(BKE_view_layer_context_active_PLACEHOLDER(scene));
        }
 
        if (ob)
index ef6c05ff59f410d42de7dd764c74e49da3687e1e..7d473230a4e43ee1c05d63e1da5b0c74faf7d059 100644 (file)
@@ -96,7 +96,10 @@ static void do_version_workspaces_create_from_screens(Main *bmain)
                const bScreen *screen_parent = screen_parent_find(screen);
                Scene *scene = screen->scene;
                WorkSpace *workspace;
-               ViewLayer *layer = BKE_view_layer_from_scene_get(scene);
+               ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
+               if (!layer) {
+                       layer = BKE_view_layer_default_view(scene);
+               }
 
                if (screen_parent) {
                        /* fullscreen with "Back to Previous" option, don't create
@@ -330,8 +333,6 @@ void do_versions_after_linking_280(Main *main)
                                }
                                BLI_assert(scene_collection_parent == NULL);
 
-                               scene->active_view_layer = 0;
-
                                /* Handle legacy render layers. */
                                {
                                        for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
@@ -433,10 +434,6 @@ void do_versions_after_linking_280(Main *main)
                                                        }
                                                }
                                        }
-
-                                       if (BLI_findlink(&scene->view_layers, scene->r.actlay)) {
-                                               scene->active_view_layer = scene->r.actlay;
-                                       }
                                }
                                BLI_freelistN(&scene->r.layers);
 
@@ -483,7 +480,7 @@ void do_versions_after_linking_280(Main *main)
                                }
 
                                /* convert selected bases */
-                               for (Base *base = scene->base.first; base; base = base->next) {
+                               for (Base *base = view_layer->object_bases.first; base; base = base->next) {
                                        if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
                                                base->flag |= BASE_SELECTED;
                                        }
index 750b0054ee528ca96fea0e0148ea2c103b5ed75d..ac3970ed3abd5ed26eef53e202777b3ae7c897b1 100644 (file)
@@ -151,7 +151,7 @@ void DepsgraphNodeBuilder::build_view_layer(
                           "Scene Eval");
        /* Build all set scenes. */
        if (scene->set != NULL) {
-               ViewLayer *set_view_layer = BKE_view_layer_from_scene_get(scene->set);
+               ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
                build_view_layer(scene->set, set_view_layer, DEG_ID_LINKED_VIA_SET);
        }
 }
index c97fa3b3a5af3cd000508b006f4958e2982369a1..99295a733fca92b99223ac3c2456695b8a623a98 100644 (file)
@@ -123,7 +123,7 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la
        }
        /* Build all set scenes. */
        if (scene->set != NULL) {
-               ViewLayer *set_view_layer = BKE_view_layer_from_scene_get(scene->set);
+               ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
                build_view_layer(scene->set, set_view_layer);
        }
 }
index 60533e382e8240a05842f3bb81038e4e766bd64d..b49a58b3766cba152de9c20a8f8e051abc646368 100644 (file)
@@ -893,7 +893,7 @@ static int bake(
 
                /* the baking itself */
                for (i = 0; i < tot_highpoly; i++) {
-                       ok = RE_bake_engine(re, highpoly[i].ob, i, pixel_array_high,
+                       ok = RE_bake_engine(re, view_layer, highpoly[i].ob, i, pixel_array_high,
                                            num_pixels, depth, pass_type, pass_filter, result);
                        if (!ok) {
                                BKE_reportf(reports, RPT_ERROR, "Error baking from object \"%s\"", highpoly[i].ob->id.name + 2);
@@ -920,7 +920,7 @@ cage_cleanup:
                ob_low->restrictflag &= ~OB_RESTRICT_RENDER;
 
                if (RE_bake_has_engine(re)) {
-                       ok = RE_bake_engine(re, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, pass_filter, result);
+                       ok = RE_bake_engine(re, view_layer, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, pass_filter, result);
                }
                else {
                        BKE_report(reports, RPT_ERROR, "Current render engine does not support baking");
index 89dbd3da16d106b02f77e27c8ac49accda453f43..4e44c9b118515b1d5adcf1daeb28ade5fafb6505 100644 (file)
@@ -104,7 +104,7 @@ static int render_break(void *rjv);
 typedef struct RenderJob {
        Main *main;
        Scene *scene;
-       ViewLayer *view_layer;
+       ViewLayer *single_layer;
        Scene *current_scene;
        /* TODO(sergey): Should not be needed once engine will have own
         * depsgraph and copy-on-write will be implemented.
@@ -263,7 +263,7 @@ static void image_buffer_rect_update(RenderJob *rj, RenderResult *rr, ImBuf *ibu
 /* set callbacks, exported to sequence render too.
  * Only call in foreground (UI) renders. */
 
-static void screen_render_view_layer_set(wmOperator *op, Main *mainp, Scene **scene, ViewLayer **view_layer)
+static void screen_render_single_layer_set(wmOperator *op, Main *mainp, WorkSpace *workspace, Scene **scene, ViewLayer **single_layer)
 {
        /* single layer re-render */
        if (RNA_struct_property_is_set(op->ptr, "scene")) {
@@ -290,7 +290,10 @@ static void screen_render_view_layer_set(wmOperator *op, Main *mainp, Scene **sc
                rl = (ViewLayer *)BLI_findstring(&(*scene)->view_layers, rl_name, offsetof(ViewLayer, name));
                
                if (rl)
-                       *view_layer = rl;
+                       *single_layer = rl;
+       }
+       else if (((*scene)->r.scemode & R_SINGLE_LAYER) && workspace) {
+               *single_layer = BKE_view_layer_from_workspace_get(*scene, workspace);
        }
 }
 
@@ -299,11 +302,12 @@ static int screen_render_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        RenderEngineType *re_type = RE_engines_find(scene->r.engine);
-       ViewLayer *view_layer = NULL;
+       ViewLayer *single_layer = NULL;
        Render *re;
        Image *ima;
        View3D *v3d = CTX_wm_view3d(C);
        Main *mainp = CTX_data_main(C);
+       WorkSpace *workspace = CTX_wm_workspace(C);
        unsigned int lay_override;
        const bool is_animation = RNA_boolean_get(op->ptr, "animation");
        const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
@@ -315,7 +319,7 @@ static int screen_render_exec(bContext *C, wmOperator *op)
        }
 
        /* custom scene and single layer re-render */
-       screen_render_view_layer_set(op, mainp, &scene, &view_layer);
+       screen_render_single_layer_set(op, mainp, workspace, &scene, &single_layer);
 
        if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
                BKE_report(op->reports, RPT_ERROR, "Cannot write a single file with an animation format selected");
@@ -344,7 +348,7 @@ static int screen_render_exec(bContext *C, wmOperator *op)
        if (is_animation)
                RE_BlenderAnim(re, mainp, scene, camera_override, lay_override, scene->r.sfra, scene->r.efra, scene->r.frame_step);
        else
-               RE_BlenderFrame(re, mainp, scene, view_layer, camera_override, lay_override, scene->r.cfra, is_write_still);
+               RE_BlenderFrame(re, mainp, scene, single_layer, camera_override, lay_override, scene->r.cfra, is_write_still);
        BLI_threaded_malloc_end();
 
        RE_SetReports(re, NULL);
@@ -619,7 +623,7 @@ static void render_startjob(void *rjv, short *stop, short *do_update, float *pro
        if (rj->anim)
                RE_BlenderAnim(rj->re, rj->main, rj->scene, rj->camera_override, rj->lay_override, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step);
        else
-               RE_BlenderFrame(rj->re, rj->main, rj->scene, rj->view_layer, rj->camera_override, rj->lay_override, rj->scene->r.cfra, rj->write_still);
+               RE_BlenderFrame(rj->re, rj->main, rj->scene, rj->single_layer, rj->camera_override, rj->lay_override, rj->scene->r.cfra, rj->write_still);
 
        RE_SetReports(rj->re, NULL);
 }
@@ -686,7 +690,7 @@ static void render_endjob(void *rjv)
        /* potentially set by caller */
        rj->scene->r.scemode &= ~R_NO_FRAME_UPDATE;
        
-       if (rj->view_layer) {
+       if (rj->single_layer) {
                nodeUpdateID(rj->scene->nodetree, &rj->scene->id);
                WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene);
        }
@@ -860,8 +864,8 @@ static void clean_viewport_memory(Main *bmain, Scene *scene)
 static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
        /* new render clears all callbacks */
-       Main *mainp;
-       ViewLayer *view_layer = NULL;
+       Main *bmain = CTX_data_main(C);
+       ViewLayer *single_layer = NULL;
        Scene *scene = CTX_data_scene(C);
        RenderEngineType *re_type = RE_engines_find(scene->r.engine);
        Render *re;
@@ -873,6 +877,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
        const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
        const bool use_viewport = RNA_boolean_get(op->ptr, "use_viewport");
        View3D *v3d = use_viewport ? CTX_wm_view3d(C) : NULL;
+       WorkSpace *workspace = CTX_wm_workspace(C);
        struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
        const char *name;
        ScrArea *sa;
@@ -882,14 +887,14 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
                return OPERATOR_CANCELLED;
        }
 
+       /* custom scene and single layer re-render */
+       screen_render_single_layer_set(op, bmain, workspace, &scene, &single_layer);
+
        /* only one render job at a time */
        if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER))
                return OPERATOR_CANCELLED;
 
-       if (RE_force_single_renderlayer(scene))
-               WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
-       if (!RE_is_rendering_allowed(scene, camera_override, op->reports)) {
+       if (!RE_is_rendering_allowed(scene, single_layer, camera_override, op->reports)) {
                return OPERATOR_CANCELLED;
        }
 
@@ -901,15 +906,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
        /* stop all running jobs, except screen one. currently previews frustrate Render */
        WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));
 
-       /* get main */
-       if (G.debug_value == 101) {
-               /* thread-safety experiment, copy main from the undo buffer */
-               struct MemFile *memfile = ED_undosys_stack_memfile_get_active(CTX_wm_manager(C)->undo_stack);
-               mainp = BLO_memfile_main_get(memfile, CTX_data_main(C), &scene);
-       }
-       else
-               mainp = CTX_data_main(C);
-
        /* cancel animation playback */
        if (ED_screen_animation_playing(CTX_wm_manager(C)))
                ED_screen_animation_play(C, 0, 0);
@@ -935,18 +931,15 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
 
        jobflag = WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS;
        
-       /* custom scene and single layer re-render */
-       screen_render_view_layer_set(op, mainp, &scene, &view_layer);
-
        if (RNA_struct_property_is_set(op->ptr, "layer"))
                jobflag |= WM_JOB_SUSPEND;
 
        /* job custom data */
        rj = MEM_callocN(sizeof(RenderJob), "render job");
-       rj->main = mainp;
+       rj->main = bmain;
        rj->scene = scene;
        rj->current_scene = rj->scene;
-       rj->view_layer = view_layer;
+       rj->single_layer = single_layer;
        /* TODO(sergey): Render engine should be using own depsgraph. */
        rj->depsgraph = CTX_data_depsgraph(C);
        rj->camera_override = camera_override;
index 1c6938cbdb37a1a07c0b6527fb65c94add6ae096..bf6aa9c9675b01d2b974abc61bee661965284b3f 100644 (file)
@@ -713,7 +713,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
        oglrender->iuser.ok = 1;
 
        /* create render result */
-       RE_InitState(oglrender->re, NULL, &scene->r, &scene->view_layers, scene->active_view_layer, NULL, sizex, sizey, NULL);
+       RE_InitState(oglrender->re, NULL, &scene->r, &scene->view_layers, NULL, sizex, sizey, NULL);
 
        /* create render views */
        screen_opengl_views_setup(oglrender);
index 9a179ce3b47c4da37d19f020cda83ab0edf1e4a1..03742b489a1ff81d24e99b15bdc62acce83ea44d 100644 (file)
@@ -317,7 +317,7 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
 
        sce = preview_get_scene(pr_main);
        if (sce) {
-               ViewLayer *view_layer = BKE_view_layer_from_scene_get(sce);
+               ViewLayer *view_layer = sce->view_layers.first;
 
                /* this flag tells render to not execute depsgraph or ipos etc */
                sce->r.scemode |= R_BUTS_PREVIEW;
index c5787a1d46cc6a8f92304a645f8b3510a470e054..e792de01e2c7ef15f016dcb821c5170a24f3b7f4 100644 (file)
@@ -62,6 +62,7 @@
 #include "BKE_report.h"
 #include "BKE_scene.h"
 #include "BKE_texture.h"
+#include "BKE_workspace.h"
 #include "BKE_world.h"
 #include "BKE_editmesh.h"
 
@@ -611,10 +612,13 @@ void WORLD_OT_new(wmOperatorType *ot)
 
 static int view_layer_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
+       WorkSpace *workspace = CTX_wm_workspace(C);
        Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = BKE_view_layer_add(scene, NULL);
 
-       BKE_view_layer_add(scene, NULL);
-       scene->active_view_layer = BLI_listbase_count(&scene->view_layers) - 1;
+       if (workspace) {
+               BKE_workspace_view_layer_set(workspace, view_layer, scene);
+       }
 
        DEG_id_tag_update(&scene->id, 0);
        DEG_relations_tag_update(CTX_data_main(C));
@@ -641,7 +645,7 @@ static int view_layer_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BKE_view_layer_from_scene_get(scene);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        if (!ED_scene_view_layer_delete(bmain, scene, view_layer, NULL)) {
                return OPERATOR_CANCELLED;
@@ -757,7 +761,7 @@ static int freestyle_active_module_poll(bContext *C)
 static int freestyle_module_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        BKE_freestyle_module_add(&view_layer->freestyle_config);
 
@@ -783,7 +787,7 @@ void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
 static int freestyle_module_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
        FreestyleModuleConfig *module = ptr.data;
 
@@ -813,7 +817,7 @@ void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
 static int freestyle_module_move_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
        FreestyleModuleConfig *module = ptr.data;
        int dir = RNA_enum_get(op->ptr, "direction");
@@ -855,7 +859,7 @@ static int freestyle_lineset_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        BKE_freestyle_lineset_add(bmain, &view_layer->freestyle_config, NULL);
 
@@ -881,8 +885,7 @@ void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot)
 
 static int freestyle_active_lineset_poll(bContext *C)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        if (!view_layer) {
                return false;
@@ -893,8 +896,7 @@ static int freestyle_active_lineset_poll(bContext *C)
 
 static int freestyle_lineset_copy_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        FRS_copy_active_lineset(&view_layer->freestyle_config);
 
@@ -919,7 +921,7 @@ void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot)
 static int freestyle_lineset_paste_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        FRS_paste_active_lineset(&view_layer->freestyle_config);
 
@@ -947,7 +949,7 @@ void SCENE_OT_freestyle_lineset_paste(wmOperatorType *ot)
 static int freestyle_lineset_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        FRS_delete_active_lineset(&view_layer->freestyle_config);
 
@@ -975,7 +977,7 @@ void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot)
 static int freestyle_lineset_move_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        int dir = RNA_enum_get(op->ptr, "direction");
 
        if (FRS_move_active_lineset(&view_layer->freestyle_config, dir)) {
@@ -1014,8 +1016,7 @@ void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
 static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
 
        if (!lineset) {
@@ -1052,8 +1053,7 @@ void SCENE_OT_freestyle_linestyle_new(wmOperatorType *ot)
 
 static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        int type = RNA_enum_get(op->ptr, "type");
 
@@ -1092,8 +1092,7 @@ void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot)
 
 static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        int type = RNA_enum_get(op->ptr, "type");
 
@@ -1132,8 +1131,7 @@ void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot)
 
 static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        int type = RNA_enum_get(op->ptr, "type");
 
@@ -1172,8 +1170,7 @@ void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot)
 
 static int freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        int type = RNA_enum_get(op->ptr, "type");
 
@@ -1225,8 +1222,7 @@ static int freestyle_get_modifier_type(PointerRNA *ptr)
 
 static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
        LineStyleModifier *modifier = ptr.data;
@@ -1275,8 +1271,7 @@ void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot)
 
 static int freestyle_modifier_copy_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
        LineStyleModifier *modifier = ptr.data;
@@ -1325,8 +1320,7 @@ void SCENE_OT_freestyle_modifier_copy(wmOperatorType *ot)
 
 static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
        PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
        LineStyleModifier *modifier = ptr.data;
@@ -1391,8 +1385,8 @@ void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
 static int freestyle_stroke_material_create_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
-       Scene *scene = CTX_data_scene(C);
-       FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer);
 
        if (!linestyle) {
                BKE_report(op->reports, RPT_ERROR, "No active line style in the current scene");
index 58a58ef8172686232462b4619ede250735dd6871..b6608ce600f747f4da33aefd191eb70f82c5beba 100644 (file)
@@ -117,7 +117,7 @@ bool ED_scene_delete(bContext *C, Main *bmain, wmWindow *win, Scene *scene)
 static ViewLayer *scene_change_get_new_view_layer(const WorkSpace *workspace, const Scene *scene_new)
 {
        ViewLayer *layer_new = BKE_workspace_view_layer_get(workspace, scene_new);
-       return layer_new ? layer_new : BKE_view_layer_from_scene_get(scene_new);
+       return layer_new ? layer_new : BKE_view_layer_default_view(scene_new);
 }
 
 void ED_scene_change_update(
@@ -200,7 +200,6 @@ bool ED_scene_view_layer_delete(
 
        BLI_remlink(&scene->view_layers, layer);
        BLI_assert(BLI_listbase_is_empty(&scene->view_layers) == false);
-       scene->active_view_layer = 0;
 
        ED_workspace_view_layer_unset(bmain, scene, layer, scene->view_layers.first);
        BKE_workspace_view_layer_remove_references(bmain, layer);
index e8faf794bb8bc4cb60bfef651fc7e2fadd872686..6793f0a01956882e2922da2b78dc7b58c1be3618 100644 (file)
@@ -114,6 +114,20 @@ static int buttons_context_path_scene(ButsContextPath *path)
        return RNA_struct_is_a(ptr->type, &RNA_Scene);
 }
 
+static int buttons_context_path_view_layer(ButsContextPath *path, WorkSpace *workspace)
+{
+       if (buttons_context_path_scene(path)) {
+               Scene *scene = path->ptr[path->len - 1].data;
+               ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
+
+               RNA_pointer_create(&scene->id, &RNA_ViewLayer, view_layer, &path->ptr[path->len]);
+               path->len++;
+               return 1;
+       }
+
+       return 0;
+}
+
 /* note: this function can return 1 without adding a world to the path
  * so the buttons stay visible, but be sure to check the ID type if a ID_WO */
 static int buttons_context_path_world(ButsContextPath *path)
@@ -145,9 +159,8 @@ static int buttons_context_path_world(ButsContextPath *path)
        return 0;
 }
 
-static int buttons_context_path_linestyle(ButsContextPath *path)
+static int buttons_context_path_linestyle(ButsContextPath *path, WorkSpace *workspace)
 {
-       Scene *scene;
        FreestyleLineStyle *linestyle;
        PointerRNA *ptr = &path->ptr[path->len - 1];
 
@@ -155,10 +168,10 @@ static int buttons_context_path_linestyle(ButsContextPath *path)
        if (RNA_struct_is_a(ptr->type, &RNA_FreestyleLineStyle)) {
                return 1;
        }
-       /* if we have a scene, use the lineset's linestyle */
-       else if (buttons_context_path_scene(path)) {
-               scene = path->ptr[path->len - 1].data;
-               linestyle = BKE_linestyle_active_from_scene(scene);
+       /* if we have a view layer, use the lineset's linestyle */
+       else if (buttons_context_path_view_layer(path, workspace)) {
+               ViewLayer *view_layer = path->ptr[path->len - 1].data;
+               linestyle = BKE_linestyle_active_from_view_layer(view_layer);
                if (linestyle) {
                        RNA_id_pointer_create(&linestyle->id, &path->ptr[path->len]);
                        path->len++;
@@ -186,25 +199,26 @@ static int buttons_context_path_collection(ButsContextPath *path, eSpaceButtons_
        if (RNA_struct_is_a(ptr->type, &RNA_LayerCollection)) {
                return 1;
        }
+       else if (RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) {
+               ViewLayer *view_layer = ptr->data;
 
-       ViewLayer *view_layer = ptr->data;
-
-       if (collection_context == SB_COLLECTION_CTX_GROUP) {
-               Object *ob = OBACT(view_layer);
-               if (ob && ob->dup_group) {
-                       view_layer = ob->dup_group->view_layer;
+               if (collection_context == SB_COLLECTION_CTX_GROUP) {
+                       Object *ob = OBACT(view_layer);
+                       if (ob && ob->dup_group) {
+                               view_layer = ob->dup_group->view_layer;
 
-                       /* Replace the view layer by the group in the context path. */
-                       RNA_pointer_create(NULL, &RNA_Group, ob->dup_group, &path->ptr[path->len - 1]);
+                               /* Replace the view layer by the group in the context path. */
+                               RNA_pointer_create(NULL, &RNA_Group, ob->dup_group, &path->ptr[path->len - 1]);
+                       }
                }
-       }
 
-       LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
+               LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
 
-       if (layer_collection) {
-               RNA_pointer_create(NULL, &RNA_LayerCollection, layer_collection, &path->ptr[path->len]);
-               path->len++;
-               return 1;
+               if (layer_collection) {
+                       RNA_pointer_create(NULL, &RNA_LayerCollection, layer_collection, &path->ptr[path->len]);
+                       path->len++;
+                       return 1;
+               }
        }
 
        /* no path to a collection possible */
@@ -452,7 +466,7 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
                else if (GS(id->name) == ID_OB)
                        buttons_context_path_object(path);
                else if (GS(id->name) == ID_LS)
-                       buttons_context_path_linestyle(path);
+                       buttons_context_path_linestyle(path, CTX_wm_workspace(C));
        }
 
        if (ct->texture) {
@@ -464,10 +478,9 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
 }
 
 #ifdef WITH_FREESTYLE
-static bool buttons_context_linestyle_pinnable(const bContext *C)
+static bool buttons_context_linestyle_pinnable(const bContext *C, ViewLayer *view_layer)
 {
        Scene *scene = CTX_data_scene(C);
-       ViewLayer *active_view_layer;
        FreestyleConfig *config;
        SpaceButs *sbuts;
 
@@ -476,8 +489,7 @@ static bool buttons_context_linestyle_pinnable(const bContext *C)
                return false;
        }
        /* if Freestyle is not in the Parameter Editor mode */
-       active_view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
-       config = &active_view_layer->freestyle_config;
+       config = &view_layer->freestyle_config;
        if (config->mode != FREESTYLE_CONTROL_EDITOR_MODE) {
                return false;
        }
@@ -495,6 +507,7 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
        SpaceButs *sbuts = CTX_wm_space_buts(C);
        Scene *scene = CTX_data_scene(C);
        WorkSpace *workspace = CTX_wm_workspace(C);
+       ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
        ID *id;
        int found;
 
@@ -508,24 +521,21 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
                RNA_id_pointer_create(id, &path->ptr[0]);
                path->len++;
        }
-       /* No pinned root, use scene or workspace as initial root. */
+       /* No pinned root, use scene as initial root. */
        else {
-               if ((mainb != BCONTEXT_WORKSPACE) &&
-                   ELEM(mainb, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD))
-               {
-                       RNA_id_pointer_create(&scene->id, &path->ptr[0]);
+               if (mainb == BCONTEXT_WORKSPACE) {
+                       RNA_id_pointer_create(&workspace->id, &path->ptr[0]);
                        path->len++;
                }
                else {
-                       RNA_id_pointer_create(&workspace->id, &path->ptr[0]);
+                       RNA_id_pointer_create(&scene->id, &path->ptr[0]);
                        path->len++;
-               }
-       }
 
-       if (!ELEM(mainb, BCONTEXT_WORKSPACE, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD)) {
-               ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
-               RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]);
-               path->len++;
+                       if (!ELEM(mainb, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD)) {
+                               RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]);
+                               path->len++;
+                       }
+               }
        }
 
        /* now for each buttons context type, we try to construct a path,
@@ -537,14 +547,14 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
                        break;
                case BCONTEXT_VIEW_LAYER:
 #ifdef WITH_FREESTYLE
-                       if (buttons_context_linestyle_pinnable(C)) {
-                               found = buttons_context_path_linestyle(path);
+                       if (buttons_context_linestyle_pinnable(C, view_layer)) {
+                               found = buttons_context_path_linestyle(path, workspace);
                                if (found) {
                                        break;
                                }
                        }
 #endif
-                       found = buttons_context_path_scene(path);
+                       found = buttons_context_path_view_layer(path, workspace);
                        break;
                case BCONTEXT_WORLD:
                        found = buttons_context_path_world(path);
@@ -700,7 +710,7 @@ const char *buttons_context_dir[] = {
        "texture", "texture_user", "texture_user_property", "bone", "edit_bone",
        "pose_bone", "particle_system", "particle_system_editable", "particle_settings",
        "cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint",
-       "line_style", "collection", "workspace", NULL
+       "line_style", "collection", NULL
 };
 
 int buttons_context(const bContext *C, const char *member, bContextDataResult *result)
@@ -729,10 +739,6 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
                set_pointer_type(path, result, &RNA_World);
                return 1;
        }
-       else if (CTX_data_equals(member, "workspace")) {
-               /* Do not return one here if scene not found in path, in this case we want to get default context scene! */
-               return set_pointer_type(path, result, &RNA_WorkSpace);
-       }
        else if (CTX_data_equals(member, "object")) {
                set_pointer_type(path, result, &RNA_Object);
                return 1;
@@ -1037,9 +1043,10 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
                        name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL);
 
                        if (name) {
-                               if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER) && ptr->type == &RNA_Scene) ||
-                                   (!ELEM(sbuts->mainb, BCONTEXT_WORKSPACE) && ptr->type == &RNA_WorkSpace))
-                               {
+                               if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER) && ptr->type == &RNA_Scene)) {
+                                       uiItemLDrag(row, ptr, "", icon);  /* save some space */
+                               }
+                               else if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER) && ptr->type == &RNA_ViewLayer)) {
                                        uiItemLDrag(row, ptr, "", icon);  /* save some space */
                                }
                                else {
index df06eee3fd59ba29e2821848437adb5363eb918c..078ab540ace6939fe227acb9ef744918f15c408c 100644 (file)
@@ -58,6 +58,7 @@
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_scene.h"
+#include "BKE_workspace.h"
 #ifdef WITH_FREESTYLE
 #  include "BKE_freestyle.h"
 #endif
@@ -152,7 +153,6 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
 {
        Scene *scene = NULL;
        Object *ob = NULL;
-       WorkSpace *workspace = NULL;
        FreestyleLineStyle *linestyle = NULL;
        Brush *brush = NULL;
        ID *pinid = sbuts->pinid;
@@ -168,8 +168,6 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
                        brush = (Brush *)pinid;
                else if (GS(pinid->name) == ID_LS)
                        linestyle = (FreestyleLineStyle *)pinid;
-               else if (GS(pinid->name) == ID_WS)
-                       workspace = (WorkSpace *)workspace;
        }
 
        if (!scene) {
@@ -177,15 +175,12 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
        }
 
        const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1;
-       if (!pinid || ELEM(id_type, ID_SCE, ID_WS)) {
-               brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
-
-               if (workspace == NULL) {
-                       linestyle = BKE_linestyle_active_from_scene(scene);
-                       workspace = CTX_wm_workspace(C);
-               }
+       if (!pinid || id_type == ID_SCE) {
+               WorkSpace *workspace = CTX_wm_workspace(C);
+               ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
 
-               ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
+               brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
+               linestyle = BKE_linestyle_active_from_view_layer(view_layer);
                ob = OBACT(view_layer);
        }
 
index 340184845b832476df9a406a45d800ae6e052980..d91c330c853216335b4c1d92c855a91e68a2fe07 100644 (file)
@@ -675,22 +675,6 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
                                /* addnode() doesnt link this yet... */
                                node->id = (ID *)BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
                        }
-                       else if (node->type == CMP_NODE_R_LAYERS) {
-                               Scene *scene;
-
-                               for (scene = bmain->scene.first; scene; scene = scene->id.next) {
-                                       if (scene->nodetree && scene->use_nodes && ntreeHasTree(scene->nodetree, ntree)) {
-                                               if (node->id == NULL || node->id == (ID *)scene) {
-                                                       int num_layers = BLI_listbase_count(&scene->view_layers);
-                                                       scene->active_view_layer = node->custom1;
-                                                       /* Clamp the value, because it might have come from a different
-                                                        * scene which could have more render layers than new one.
-                                                        */
-                                                       scene->active_view_layer = min_ff(scene->active_view_layer, num_layers - 1);
-                                               }
-                                       }
-                               }
-                       }
                        else if (node->type == CMP_NODE_COMPOSITE) {
                                if (was_output == 0) {
                                        bNode *tnode;
index 765c77e49064de7632160cf24b1bddf359e274ef..fad35060d7283105a8deef86667778e8bd6b537b 100644 (file)
@@ -442,11 +442,13 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
                        if (tselem->type == TSE_R_LAYER && (soops->outlinevis == SO_SCENES)) {
                                /* View layer render toggle. */
+                               ViewLayer *view_layer = te->directdata;
+
                                UI_block_emboss_set(block, UI_EMBOSS_NONE);
                                
-                               bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE_N, VIEW_LAYER_RENDER, 0, ICON_RESTRICT_RENDER_OFF,
+                               bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, VIEW_LAYER_RENDER, 0, ICON_RESTRICT_RENDER_OFF,
                                                      (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
-                                                     UI_UNIT_Y, te->directdata, 0, 0, 0, 0, TIP_("Use view layer for rendering"));
+                                                     UI_UNIT_Y, &view_layer->flag, 0, 0, 0, 0, TIP_("Use view layer for rendering"));
                                UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
                                
@@ -1045,7 +1047,7 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
                                ICON_DRAW(ICON_OUTLINER_OB_GROUP_INSTANCE);
                                break;
                        case TSE_R_LAYER:
-                               ICON_DRAW(ICON_RENDERLAYERS);
+                               ICON_DRAW(ICON_RENDER_RESULT);
                                break;
                        case TSE_LINKED_LAMP:
                                ICON_DRAW(ICON_LAMP_DATA);
index 800f36d35a053701102dbda38782388b7ee2399a..a3dbab1b3fdc162e25091c88494f0d26f381df8e 100644 (file)
 #include "BLI_utildefines.h"
 #include "BLI_listbase.h"
 
+#include "BKE_armature.h"
 #include "BKE_context.h"
 #include "BKE_group.h"
-#include "BKE_object.h"
 #include "BKE_layer.h"
+#include "BKE_object.h"
 #include "BKE_scene.h"
 #include "BKE_sequencer.h"
-#include "BKE_armature.h"
+#include "BKE_workspace.h"
 
 #include "DEG_depsgraph.h"
 
@@ -75,7 +76,7 @@
 /* ****************************************************** */
 /* Outliner Element Selection/Activation on Click */
 
-static eOLDrawState tree_element_active_renderlayer(
+static eOLDrawState active_viewlayer(
         bContext *C, Scene *UNUSED(scene), ViewLayer *UNUSED(sl), TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
 {
        Scene *sce;
@@ -85,12 +86,15 @@ static eOLDrawState tree_element_active_renderlayer(
                return OL_DRAWSEL_NONE;
        sce = (Scene *)tselem->id;
        
+       WorkSpace *workspace = CTX_wm_workspace(C);
+       ViewLayer *view_layer = te->directdata;
+
        if (set != OL_SETSEL_NONE) {
-               sce->active_view_layer = tselem->nr;
-               WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, sce);
+               BKE_workspace_view_layer_set(workspace, view_layer, sce);
+               WM_event_add_notifier(C, NC_SCREEN | ND_LAYER, NULL);
        }
        else {
-               return sce->active_view_layer == tselem->nr;
+               return BKE_workspace_view_layer_get(workspace, sce) == view_layer;
        }
        return OL_DRAWSEL_NONE;
 }
@@ -782,7 +786,7 @@ eOLDrawState tree_element_type_active(
                        return tree_element_active_constraint(C, scene, view_layer, te, tselem, set);
                case TSE_R_LAYER:
                        if (soops->outlinevis == SO_SCENES) {
-                               return tree_element_active_renderlayer(C, scene, view_layer, te, tselem, set);
+                               return active_viewlayer(C, scene, view_layer, te, tselem, set);
                        }
                        else {
                                return OL_DRAWSEL_NONE;
index 60473853e18c8a6b6f19aacaa7d716a30d98b5b7..2a5151a16adffc44c04916ac75a08b673d063f4b 100644 (file)
@@ -297,11 +297,10 @@ static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *s
        tenla->name = IFACE_("View Layers");
 
        ViewLayer *view_layer;
-       int a;
-       for (a = 0, view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next, a++) {
-               TreeElement *tenlay = outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
+       for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+               TreeElement *tenlay = outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, 0);
                tenlay->name = view_layer->name;
-               tenlay->directdata = &view_layer->flag;
+               tenlay->directdata = view_layer;
        }
 
        /* Collections */
@@ -2198,10 +2197,9 @@ void outliner_build_tree(Main *mainvar, Scene *scene, ViewLayer *view_layer, Spa
                outliner_add_orphaned_datablocks(mainvar, soops);
        }
        else if (soops->outlinevis == SO_COLLECTIONS) {
-               int a = BLI_findindex(&scene->view_layers, view_layer);
-               TreeElement *tenlay = outliner_add_element(soops, &soops->tree, scene, te, TSE_R_LAYER, a);
+               TreeElement *tenlay = outliner_add_element(soops, &soops->tree, scene, te, TSE_R_LAYER, 0);
                tenlay->name = view_layer->name;
-               tenlay->directdata = &view_layer->flag;
+               tenlay->directdata = view_layer;
                TREESTORE(tenlay)->flag &= ~TSE_CLOSED;
 
                if ((soops->filter & SO_FILTER_ENABLE) && (soops->filter & SO_FILTER_NO_COLLECTION)) {
index 5c4d2b9805513d7ea28d0be8cbee903555fc04b9..557a0723cb498db066caf7b58238e9e29ca493d8 100644 (file)
@@ -332,6 +332,7 @@ static void outliner_main_region_listener(
                                case ND_LAYER:
                                case ND_LAYER_CONTENT:
                                case ND_WORLD:
+                               case ND_SCENEBROWSE:
                                        ED_region_tag_redraw(ar);
                                        break;
                        }
index fa39d89091c66196c4f45fed75001fb2334a28e6..a8555e9e269dcd3057e67eb29236e01b9931e2b9 100644 (file)
@@ -178,16 +178,20 @@ static void topbar_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa)
        }
 }
 
-static void topbar_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
-                                   wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
+static void topbar_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+                                   wmNotifier *wmn, const Scene *UNUSED(scene))
 {
        /* context changes */
-#if 0
        switch (wmn->category) {
-               default:
+               case NC_SCREEN:
+                       if (wmn->data == ND_LAYER)
+                               ED_region_tag_redraw(ar);
+                       break;
+               case NC_SCENE:
+                       if (wmn->data == ND_SCENEBROWSE)
+                               ED_region_tag_redraw(ar);
                        break;
        }
-#endif
 }
 
 static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu)
index 58a9a748cfdb1329ece43a2597d68a502fd0b885..03f3f80f8072fa10157fdb5e9d8951623c64ebac 100644 (file)
@@ -1440,8 +1440,6 @@ typedef struct Scene {
 
        ListBase view_layers;
        struct SceneCollection *collection;
-       int active_view_layer;
-       int pad4;
 
        IDProperty *collection_properties;  /* settings to be overriden by layer collections */
        IDProperty *layer_properties;  /* settings to be override by workspaces */
index b74cdb5f0a541d8509c9f0ceaf78bde26a74cf52..93df67306e3aed4903c37d3944e92bf5f8c64110 100644 (file)
@@ -864,6 +864,15 @@ static void rna_LayerObjects_active_object_set(PointerRNA *ptr, PointerRNA value
                view_layer->basact = NULL;
 }
 
+static char *rna_ViewLayer_path(PointerRNA *ptr)
+{
+       ViewLayer *srl = (ViewLayer *)ptr->data;
+       char name_esc[sizeof(srl->name) * 2];
+
+       BLI_strescape(name_esc, srl->name, sizeof(name_esc));
+       return BLI_sprintfN("view_layers[\"%s\"]", name_esc);
+}
+
 static IDProperty *rna_ViewLayer_idprops(PointerRNA *ptr, bool create)
 {
        ViewLayer *view_layer = (ViewLayer *)ptr->data;
@@ -1017,6 +1026,7 @@ static void rna_def_scene_collection(BlenderRNA *brna)
 
        srna = RNA_def_struct(brna, "SceneCollection", NULL);
        RNA_def_struct_ui_text(srna, "Scene Collection", "Collection");
+       RNA_def_struct_ui_icon(srna, ICON_COLLAPSEMENU);
        RNA_def_struct_refine_func(srna, "rna_SceneCollection_refine");
 
        prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
@@ -2020,6 +2030,7 @@ static void rna_def_layer_collection(BlenderRNA *brna)
 
        srna = RNA_def_struct(brna, "LayerCollection", NULL);
        RNA_def_struct_ui_text(srna, "Layer Collection", "Layer collection");
+       RNA_def_struct_ui_icon(srna, ICON_COLLAPSEMENU);
 
        prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
        RNA_def_property_string_funcs(prop, "rna_LayerCollection_name_get", "rna_LayerCollection_name_length", "rna_LayerCollection_name_set");
@@ -2217,7 +2228,8 @@ void RNA_def_view_layer(BlenderRNA *brna)
 
        srna = RNA_def_struct(brna, "ViewLayer", NULL);
        RNA_def_struct_ui_text(srna, "Render Layer", "Render layer");
-       RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
+       RNA_def_struct_ui_icon(srna, ICON_RENDER_RESULT);
+       RNA_def_struct_path_func(srna, "rna_ViewLayer_path");
        RNA_def_struct_idprops_func(srna, "rna_ViewLayer_idprops");
 
        rna_def_view_layer_common(srna, 1);
index 822ab119854f7860ca66f486ef520ceaef4ca2c2..faecae7ab6562f6e9bf047424e041616fed58977 100644 (file)
@@ -1534,19 +1534,23 @@ static void rna_Physics_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointe
 
 static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const int *value)
 {
-       Scene *scene = (Scene *)ptr->id.data;
-       ViewLayer *view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene);
        ToolSettings *ts = (ToolSettings *)ptr->data;
        int flag = (value[0] ? SCE_SELECT_VERTEX : 0) | (value[1] ? SCE_SELECT_EDGE : 0) | (value[2] ? SCE_SELECT_FACE : 0);
 
        if (flag) {
                ts->selectmode = flag;
 
-               if (view_layer->basact) {
-                       Mesh *me = BKE_mesh_from_object(view_layer->basact->object);
-                       if (me && me->edit_btmesh && me->edit_btmesh->selectmode != flag) {
-                               me->edit_btmesh->selectmode = flag;
-                               EDBM_selectmode_set(me->edit_btmesh);
+               /* Update select mode in all the workspaces in mesh edit mode. */
+               wmWindowManager *wm = G.main->wm.first;
+               for (wmWindow *win = wm->windows.first; win; win = win->next) {
+                       ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+
+                       if (view_layer && view_layer->basact) {
+                               Mesh *me = BKE_mesh_from_object(view_layer->basact->object);
+                               if (me && me->edit_btmesh && me->edit_btmesh->selectmode != flag) {
+                                       me->edit_btmesh->selectmode = flag;
+                                       EDBM_selectmode_set(me->edit_btmesh);
+                               }
                        }
                }
        }
@@ -2009,44 +2013,6 @@ static int rna_gpu_is_hq_supported_get(PointerRNA *UNUSED(ptr))
        return true;
 }
 
-static int rna_ViewLayer_active_view_layer_index_get(PointerRNA *ptr)
-{
-       Scene *scene = (Scene *)ptr->data;
-       return scene->active_view_layer;
-}
-
-static void rna_ViewLayer_active_view_layer_index_set(PointerRNA *ptr, int value)
-{
-       Scene *scene = (Scene *)ptr->data;
-       int num_layers = BLI_listbase_count(&scene->view_layers);
-       scene->active_view_layer = min_ff(value, num_layers - 1);
-}
-
-static void rna_ViewLayer_active_view_layer_index_range(
-        PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
-{
-       Scene *scene = (Scene *)ptr->data;
-
-       *min = 0;
-       *max = max_ii(0, BLI_listbase_count(&scene->view_layers) - 1);
-}
-
-static PointerRNA rna_ViewLayer_active_view_layer_get(PointerRNA *ptr)
-{
-       Scene *scene = (Scene *)ptr->data;
-       ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
-
-       return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer);
-}
-
-static void rna_ViewLayer_active_view_layer_set(PointerRNA *ptr, PointerRNA value)
-{
-       Scene *scene = (Scene *)ptr->data;
-       ViewLayer *view_layer = (ViewLayer *)value.data;
-       const int index = BLI_findindex(&scene->view_layers, view_layer);
-       if (index != -1) scene->active_view_layer = index;
-}
-
 static ViewLayer *rna_ViewLayer_new(
         ID *id, Scene *UNUSED(sce), Main *bmain, const char *name)
 {
@@ -4069,7 +4035,6 @@ static void rna_def_gpu_dof_fx(BlenderRNA *brna)
 
        srna = RNA_def_struct(brna, "GPUDOFSettings", NULL);
        RNA_def_struct_ui_text(srna, "GPU DOF", "Settings for GPU based depth of field");
-       RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
        RNA_def_struct_path_func(srna, "rna_GPUDOF_path");
 
        prop = RNA_def_property(srna, "focus_distance", PROP_FLOAT, PROP_DISTANCE);
@@ -4134,7 +4099,6 @@ static void rna_def_gpu_ssao_fx(BlenderRNA *brna)
 
        srna = RNA_def_struct(brna, "GPUSSAOSettings", NULL);
        RNA_def_struct_ui_text(srna, "GPU SSAO", "Settings for GPU based screen space ambient occlusion");
-       RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
 
        prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_NONE);
        RNA_def_property_ui_text(prop, "Strength", "Strength of the SSAO effect");
@@ -4175,7 +4139,6 @@ static void rna_def_gpu_fx(BlenderRNA *brna)
 
        srna = RNA_def_struct(brna, "GPUFXSettings", NULL);
        RNA_def_struct_ui_text(srna, "GPU FX Settings", "Settings for GPU based compositing");
-       RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
 
        prop = RNA_def_property(srna, "dof", PROP_POINTER, PROP_NONE);
        RNA_def_property_flag(prop, PROP_NEVER_NULL);
@@ -4205,29 +4168,12 @@ static void rna_def_view_layers(BlenderRNA *brna, PropertyRNA *cprop)
        StructRNA *srna;
        FunctionRNA *func;
        PropertyRNA *parm;
-       PropertyRNA *prop;
 
        RNA_def_property_srna(cprop, "ViewLayers");
        srna = RNA_def_struct(brna, "ViewLayers", NULL);
        RNA_def_struct_sdna(srna, "Scene");
        RNA_def_struct_ui_text(srna, "Render Layers", "Collection of render layers");
 
-       prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
-       RNA_def_property_int_sdna(prop, NULL, "active_view_layer");
-       RNA_def_property_int_funcs(prop, "rna_ViewLayer_active_view_layer_index_get",
-                                  "rna_ViewLayer_active_view_layer_index_set",
-                                  "rna_ViewLayer_active_view_layer_index_range");
-       RNA_def_property_ui_text(prop, "Active View Layer Index", "Active index in view layer array");
-       RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
-
-       prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
-       RNA_def_property_struct_type(prop, "ViewLayer");
-       RNA_def_property_pointer_funcs(prop, "rna_ViewLayer_active_view_layer_get",
-                                      "rna_ViewLayer_active_view_layer_set", NULL, NULL);
-       RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
-       RNA_def_property_ui_text(prop, "Active View Layer", "Active View Layer");
-       RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
-
        func = RNA_def_function(srna, "new", "rna_ViewLayer_new");
        RNA_def_function_ui_description(func, "Add a view layer to scene");
        RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
@@ -5408,8 +5354,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
 
        prop = RNA_def_property(srna, "use_single_layer", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_SINGLE_LAYER);
-       RNA_def_property_ui_text(prop, "Single Layer", "Only render the active layer");
-       RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
+       RNA_def_property_ui_text(prop, "Render Single Layer", "Only render the active layer");
        RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
 
        /* views (stereoscopy et al) */
index 5d430e5d7b954e16b98145077521bf67c20549fc..4683031d2daf90edb4cbff3cc64bf4709b227e02 100644 (file)
@@ -201,7 +201,8 @@ const EnumPropertyItem rna_enum_clip_editor_mode_items[] = {
 static const EnumPropertyItem buttons_context_items[] = {
        {BCONTEXT_SCENE, "SCENE", ICON_SCENE_DATA, "Scene", "Scene"},
        {BCONTEXT_RENDER, "RENDER", ICON_SCENE, "Render", "Render"},
-       {BCONTEXT_VIEW_LAYER, "VIEW_LAYER", ICON_RENDERLAYERS, "View Layers", "View layers"},
+       {BCONTEXT_VIEW_LAYER, "VIEW_LAYER", ICON_RENDER_RESULT, "View Layer", "View layer"},
+       {BCONTEXT_COLLECTION, "COLLECTION", ICON_COLLAPSEMENU, "Collection", "Collection"},
        {BCONTEXT_WORLD, "WORLD", ICON_WORLD, "World", "World"},
        {BCONTEXT_OBJECT, "OBJECT", ICON_OBJECT_DATA, "Object", "Object"},
        {BCONTEXT_CONSTRAINT, "CONSTRAINT", ICON_CONSTRAINT, "Constraints", "Object constraints"},
@@ -213,13 +214,12 @@ static const EnumPropertyItem buttons_context_items[] = {
        {BCONTEXT_TEXTURE, "TEXTURE", ICON_TEXTURE, "Texture", "Texture"},
        {BCONTEXT_PARTICLE, "PARTICLES", ICON_PARTICLES, "Particles", "Particle"},
        {BCONTEXT_PHYSICS, "PHYSICS", ICON_PHYSICS, "Physics", "Physics"},
-       {BCONTEXT_COLLECTION, "COLLECTION", ICON_COLLAPSEMENU, "Collection", "Collection"},
        {BCONTEXT_WORKSPACE, "WORKSPACE", ICON_SPLITSCREEN, "Workspace", "Workspace"},
        {0, NULL, 0, NULL, NULL}
 };
 
 static const EnumPropertyItem buttons_collection_context_items[] = {
-       {SB_COLLECTION_CTX_VIEW_LAYER, "VIEW_LAYER", ICON_RENDERLAYERS, "", "Show material textures"},
+       {SB_COLLECTION_CTX_VIEW_LAYER, "VIEW_LAYER", ICON_RENDER_RESULT, "", "Show material textures"},
        {SB_COLLECTION_CTX_GROUP, "GROUP", ICON_GROUP, "", "Show world textures"},
        {0, NULL, 0, NULL, NULL}
 };
index f4e084929ccf95b29567b82445af1315ecf16e41..bad80450f802755bc94d3860c766d31f4837aec6 100644 (file)
@@ -101,7 +101,7 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre
        }
 #ifdef WITH_FREESTYLE
        else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) {
-               FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
+               FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer);
                if (linestyle) {
                        *r_from = NULL;
                        *r_id = &linestyle->id;
index 5e57338dc57b9dbc8948a2f686af127ec453ab11..cd7a3f6d9c2381caa5c01c49418df3b965ada9c0 100644 (file)
@@ -86,7 +86,7 @@ static void texture_get_from_context(
                }
        }
        else if (snode->texfrom == SNODE_TEX_LINESTYLE) {
-               FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
+               FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer);
                if (linestyle) {
                        *r_from = (ID *)linestyle;
                        tx = give_current_linestyle_texture(linestyle);
index d827a3507d9d8b96bd682885930e67000542a704..76228d93e6670f767e92ed7cd08fc3639e11f856 100644 (file)
@@ -35,6 +35,7 @@
 struct ImBuf;
 struct Render;
 struct Mesh;
+struct ViewLayer;
 
 typedef struct BakeImage {
        struct Image *image;
@@ -71,7 +72,7 @@ typedef struct BakeHighPolyData {
 bool RE_bake_has_engine(struct Render *re);
 
 bool RE_bake_engine(
-        struct Render *re, struct Object *object, const int object_id, const BakePixel pixel_array[],
+        struct Render *re, struct ViewLayer *view_layer, struct Object *object, const int object_id, const BakePixel pixel_array[],
         const size_t num_pixels, const int depth, const eScenePassType pass_type, const int pass_filter, float result[]);
 
 /* bake.c */
index 022f2a31826fd5a8ca6d12844ec7179c43ffc0de..056e236f60e56cc61a69b7eec458adf93f32d772 100644 (file)
@@ -240,8 +240,7 @@ struct RenderPass *RE_create_gp_pass(struct RenderResult *rr, const char *layern
 
 /* obligatory initialize call, disprect is optional */
 void RE_InitState(struct Render *re, struct Render *source, struct RenderData *rd,
-                  struct ListBase *render_layers, const int active_layer,
-                  struct ViewLayer *view_layer,
+                  struct ListBase *render_layers, struct ViewLayer *single_layer,
                   int winx, int winy, rcti *disprect);
 void RE_ChangeResolution(struct Render *re, int winx, int winy, rcti *disprect);
 void RE_ChangeModeFlag(struct Render *re, int flag, bool clear);
@@ -277,7 +276,7 @@ bool RE_WriteRenderViewsMovie(
 
 /* only RE_NewRender() needed, main Blender render calls */
 void RE_BlenderFrame(struct Render *re, struct Main *bmain, struct Scene *scene,
-                     struct ViewLayer *view_layer, struct Object *camera_override,
+                     struct ViewLayer *single_layer, struct Object *camera_override,
                      unsigned int lay_override, int frame, const bool write_still);
 void RE_BlenderAnim(struct Render *re, struct Main *bmain, struct Scene *scene, struct Object *camera_override,
                     unsigned int lay_override, int sfra, int efra, int tfra);
@@ -332,8 +331,7 @@ void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, flo
 void RE_GetCameraModelMatrix(struct Render *re, struct Object *camera, float r_mat[4][4]);
 struct Scene *RE_GetScene(struct Render *re);
 
-bool RE_force_single_renderlayer(struct Scene *scene);
-bool RE_is_rendering_allowed(struct Scene *scene, struct Object *camera_override, struct ReportList *reports);
+bool RE_is_rendering_allowed(struct Scene *scene, struct ViewLayer *single_layer, struct Object *camera_override, struct ReportList *reports);
 
 bool RE_allow_render_generic_object(struct Object *ob);
 
index 03be96a20bc08da5a071805957ee7bb23d2a287c..c75574cd09de614465f85f90872f70b26dfe5441 100644 (file)
@@ -555,7 +555,7 @@ bool RE_bake_has_engine(Render *re)
 }
 
 bool RE_bake_engine(
-        Render *re, Object *object,
+        Render *re, ViewLayer *view_layer, Object *object,
         const int object_id, const BakePixel pixel_array[],
         const size_t num_pixels, const int depth,
         const eScenePassType pass_type, const int pass_filter,
@@ -595,7 +595,6 @@ bool RE_bake_engine(
                type->update(engine, re->main, re->scene);
 
        if (type->bake) {
-               ViewLayer *view_layer = BLI_findlink(&re->scene->view_layers, re->scene->active_view_layer);
                engine_depsgraph_init(engine, view_layer);
 
                type->bake(engine,
index dd2042d32200fb41291bb8f7c34fe1810d8231ca..afceb8bd7002a29f98bc41c1a8d9bf5fc631c0ec 100644 (file)
@@ -277,8 +277,12 @@ RenderLayer *render_get_active_layer(Render *re, RenderResult *rr)
        return rr->layers.first;
 }
 
-static bool render_scene_has_layers_to_render(Scene *scene)
+static bool render_scene_has_layers_to_render(Scene *scene, ViewLayer *single_layer)
 {
+       if (single_layer) {
+               return true;
+       }
+
        ViewLayer *view_layer;
        for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
                if (view_layer->flag & VIEW_LAYER_RENDER) {
@@ -705,8 +709,7 @@ void render_copy_renderdata(RenderData *to, RenderData *from)
 /* what doesn't change during entire render sequence */
 /* disprect is optional, if NULL it assumes full window render */
 void RE_InitState(Render *re, Render *source, RenderData *rd,
-                  ListBase *render_layers, const int active_layer,
-                  ViewLayer *view_layer,
+                  ListBase *render_layers, ViewLayer *single_layer,
                   int winx, int winy, rcti *disprect)
 {
        bool had_freestyle = (re->r.mode & R_EDGE_FRS) != 0;
@@ -719,7 +722,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd,
        render_copy_renderdata(&re->r, rd);
        BLI_freelistN(&re->view_layers);
        BLI_duplicatelist(&re->view_layers, render_layers);
-       re->active_view_layer = active_layer;
+       re->active_view_layer = 0;
 
        if (source) {
                /* reuse border flags from source renderer */
@@ -751,8 +754,8 @@ void RE_InitState(Render *re, Render *source, RenderData *rd,
 
        re->r.scemode = check_mode_full_sample(&re->r);
        
-       if (view_layer) {
-               int index = BLI_findindex(render_layers, view_layer);
+       if (single_layer) {
+               int index = BLI_findindex(render_layers, single_layer);
                if (index != -1) {
                        re->active_view_layer = index;
                        re->r.scemode |= R_SINGLE_LAYER;
@@ -1145,7 +1148,7 @@ static void render_scene(Render *re, Scene *sce, int cfra)
        }
        
        /* initial setup */
-       RE_InitState(resc, re, &sce->r, &sce->view_layers, sce->active_view_layer, NULL, winx, winy, &re->disprect);
+       RE_InitState(resc, re, &sce->r, &sce->view_layers, NULL, winx, winy, &re->disprect);
 
        /* We still want to use 'rendercache' setting from org (main) scene... */
        resc->r.scemode = (resc->r.scemode & ~R_EXR_CACHE_FILE) | (re->r.scemode & R_EXR_CACHE_FILE);
@@ -1382,7 +1385,7 @@ static void tag_scenes_for_render(Render *re)
                                if (node->id != (ID *)re->scene) {
                                        if ((node->id->tag & LIB_TAG_DOIT) == 0) {
                                                Scene *scene = (Scene *) node->id;
-                                               if (render_scene_has_layers_to_render(scene)) {
+                                               if (render_scene_has_layers_to_render(scene, NULL)) {
                                                        node->flag |= NODE_TEST;
                                                        node->id->tag |= LIB_TAG_DOIT;
 #ifdef DEPSGRAPH_WORKAROUND_HACK
@@ -1824,20 +1827,6 @@ static void do_render_all_options(Render *re)
        }
 }
 
-bool RE_force_single_renderlayer(Scene *scene)
-{
-       int scemode = check_mode_full_sample(&scene->r);
-       if (scemode & R_SINGLE_LAYER) {
-               ViewLayer *view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
-               /* force layer to be enabled */
-               if ((view_layer->flag & VIEW_LAYER_RENDER) == 0) {
-                       view_layer->flag |= VIEW_LAYER_RENDER;
-                       return true;
-               }
-       }
-       return false;
-}
-
 static bool check_valid_compositing_camera(Scene *scene, Object *camera_override)
 {
        if (scene->r.scemode & R_DOCOMP && scene->use_nodes) {
@@ -1847,7 +1836,7 @@ static bool check_valid_compositing_camera(Scene *scene, Object *camera_override
                        if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) {
                                Scene *sce = node->id ? (Scene *)node->id : scene;
                                if (sce->camera == NULL) {
-                                       sce->camera = BKE_view_layer_camera_find(BKE_view_layer_from_scene_get(sce));
+                                       sce->camera = BKE_view_layer_camera_find(BKE_view_layer_default_render(sce));
                                }
                                if (sce->camera == NULL) {
                                        /* all render layers nodes need camera */
@@ -1905,7 +1894,7 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList
        const char *err_msg = "No camera found in scene \"%s\"";
 
        if (camera_override == NULL && scene->camera == NULL)
-               scene->camera = BKE_view_layer_camera_find(BKE_view_layer_from_scene_get(scene));
+               scene->camera = BKE_view_layer_camera_find(BKE_view_layer_default_render(scene));
 
        if (!check_valid_camera_multiview(scene, scene->camera, reports))
                return false;
@@ -1921,7 +1910,7 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList
                                {
                                        if (!seq->scene_camera) {
                                                if (!seq->scene->camera &&
-                                                   !BKE_view_layer_camera_find(BKE_view_layer_from_scene_get(seq->scene)))
+                                                   !BKE_view_layer_camera_find(BKE_view_layer_default_render(seq->scene)))
                                                {
                                                        /* camera could be unneeded due to composite nodes */
                                                        Object *override = (seq->scene == scene) ? camera_override : NULL;
@@ -1973,7 +1962,7 @@ static int check_composite_output(Scene *scene)
        return node_tree_has_composite_output(scene->nodetree);
 }
 
-bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *reports)
+bool RE_is_rendering_allowed(Scene *scene, ViewLayer *single_layer, Object *camera_override, ReportList *reports)
 {
        int scemode = check_mode_full_sample(&scene->r);
        
@@ -2049,7 +2038,7 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *
        }
 
        /* layer flag tests */
-       if (!render_scene_has_layers_to_render(scene)) {
+       if (!render_scene_has_layers_to_render(scene, single_layer)) {
                BKE_report(reports, RPT_ERROR, "All render layers are disabled");
                return 0;
        }
@@ -2094,7 +2083,7 @@ const char *RE_GetActiveRenderView(Render *re)
 
 /* evaluating scene options for general Blender render */
 static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, Scene *scene,
-                                       ViewLayer *view_layer, Object *camera_override, unsigned int lay_override,
+                                       ViewLayer *single_layer, Object *camera_override, unsigned int lay_override,
                                        int anim, int anim_init)
 {
        int winx, winy;
@@ -2151,17 +2140,17 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain,
         */
        if (0) {
                /* make sure dynamics are up to date */
-               view_layer = BKE_view_layer_from_scene_get(scene);
+               ViewLayer *view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene);
                update_physics_cache(re, scene, view_layer, anim_init);
        }
        
-       if (view_layer || scene->r.scemode & R_SINGLE_LAYER) {
+       if (single_layer || scene->r.scemode & R_SINGLE_LAYER) {
                BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
                render_result_single_layer_begin(re);
                BLI_rw_mutex_unlock(&re->resultmutex);
        }
        
-       RE_InitState(re, NULL, &scene->r, &scene->view_layers, scene->active_view_layer, view_layer, winx, winy, &disprect);
+       RE_InitState(re, NULL, &scene->r, &scene->view_layers, single_layer, winx, winy, &disprect);
        if (!re->ok)  /* if an error was printed, abort */
                return 0;
        
@@ -2182,7 +2171,7 @@ void RE_SetReports(Render *re, ReportList *reports)
 }
 
 /* general Blender frame render call */
-void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, ViewLayer *view_layer, Object *camera_override,
+void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, ViewLayer *single_layer, Object *camera_override,
                      unsigned int lay_override, int frame, const bool write_still)
 {
        BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_INIT);
@@ -2192,7 +2181,7 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, ViewLayer *view_laye
        
        scene->r.cfra = frame;
        
-       if (render_initialize_from_main(re, &scene->r, bmain, scene, view_layer,
+       if (render_initialize_from_main(re, &scene->r, bmain, scene, single_layer,
                                        camera_override, lay_override, 0, 0))
        {
                MEM_reset_peak_memory();
@@ -2796,7 +2785,7 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
        winx = (sce->r.size * sce->r.xsch) / 100;
        winy = (sce->r.size * sce->r.ysch) / 100;
 
-       RE_InitState(re, NULL, &sce->r, &sce->view_layers, sce->active_view_layer, NULL, winx, winy, NULL);
+       RE_InitState(re, NULL, &sce->r, &sce->view_layers, NULL, winx, winy, NULL);
 
        re->main = bmain;
        re->scene = sce;
@@ -2843,7 +2832,7 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode)
        re = RE_GetSceneRender(scene);
        if (re == NULL)
                re = RE_NewSceneRender(scene);
-       RE_InitState(re, NULL, &scene->r, &scene->view_layers, scene->active_view_layer, NULL, winx, winy, &disprect);
+       RE_InitState(re, NULL, &scene->r, &scene->view_layers, NULL, winx, winy, &disprect);
        re->scene = scene;
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
index bd80f638ef4d594b63caa55a79ab8b463b83760b..f862ca55c86616f324981da79f0fc3c3663eaa0c 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Selectability Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index a220d89445ebc69c526d67944c83e7126630f09a..91f5dc3de2be52f7888d0f26b7dde2f221f03121 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Selectability Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index e551310cbbe0a9eba16b68d9e6aba8ff93f78a06..c1ce5dba81571b1c84cfaf6c22bc5a67091843e2 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Selectability Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index 76adf12c6669b1356f3cea7254e6afeed1b3b4af..1af8a0dbd592426496cdfb28418d1b30f3427d01 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Selectability Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index 970c1cdd9d253ba701b64dfc0d3b4c341b35a789..54df1e9b59b7a374ef709118f16346b6a124b2d2 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Selectability Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index 54a070e4ae92a8ea8c17f3d573a4fc4f961092fa..fbc4a49fc113a9d3ddd02dbb72ae3f9aca411886 100644 (file)
@@ -17,10 +17,11 @@ class UnitTesting(ViewLayerTesting):
     def test_selectability(self):
         import bpy
         scene = bpy.context.scene
+        view_layer = bpy.context.view_layer
 
         cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh'))
         scene_collection = scene.master_collection.collections.new('collection')
-        layer_collection = scene.view_layers.active.collections.link(scene_collection)
+        layer_collection = view_layer.collections.link(scene_collection)
 
         bpy.context.scene.update()  # update depsgraph
 
index c1e6a427210ee1345418bfae8643a63ae01f1ef1..666513fa85a6592f676bf3414003133df4021531 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index a6859ba31ec30dbbed9820ce77de5a9bcbcea82a..c24b7a73dabd67ed6e531eb5dac4c44b26d7a975 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index 8c88a045c99f1f1013f124a5cab3186bf2e93fe3..5a8c6386265d6527a563ef18a943e881d89911f3 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index 1836fae98027c19322020c2b4b705dedeb2fbc1a..6a5f660edde40c8f3a910c17a7b92dbe11663230 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index f05d797ecdc89f04398b609247cba6bfcbbc598e..16e08cfaba729a860e831f93936436ed9173b45d 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index 9034d0ce6f821aa9f9837f606bde3aecaf54efef..cf886786c5e73c9397bac30203af38b87138059f 100644 (file)
@@ -26,7 +26,6 @@ class UnitTesting(ViewLayerTesting):
 
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
         window.view_layer = layer
 
         scene_collection_mom = scene.master_collection.collections.new("Mom")
index a15b9e2c941a6109bf15022ae04b0a277fb07eb3..15d863f31385bf531fd6b69f49670ca5cbc0adc5 100644 (file)
@@ -41,7 +41,6 @@ class UnitTesting(ViewLayerTesting):
             layer = scene.view_layers.new('Fresh new Layer')
             layer.collections.link(subzero)
 
-            scene.view_layers.active_index = len(scene.view_layers) - 1
             bpy.context.window.view_layer = bpy.context.scene.view_layers['Fresh new Layer']
 
             if mode == 'DUPLICATE':
index 361ea7fc3a5b07cce58ea1525fc527b777c4bd9c..8a78251a167b0ae5829f619677c5243a4e7e7e6f 100644 (file)
@@ -19,7 +19,6 @@ class UnitTesting(ViewLayerTesting):
         See if we can link objects via bpy.context.scene_collection
         """
         import bpy
-        bpy.context.scene.view_layers.active_index = len(bpy.context.scene.view_layers) - 1
         bpy.context.window.view_layer = bpy.context.scene.view_layers['Viewport']
         master_collection = bpy.context.scene_collection
         self.do_object_link(master_collection)
index 34f46c963bb0ae97dcfedabe8fe3813c39cdbfad..38379aa2a75c35c299a44c6040fd2cb500cdfb42 100644 (file)
@@ -90,8 +90,6 @@ class UnitTesting(ViewLayerTesting):
 
         # Change active scene layer (do it for window too just to don't get mangled in window bugs)
         scene = bpy.context.scene
-        scene.view_layers.active_index = len(scene.view_layers) - 2
-        self.assertEqual(scene.view_layers.active.name, "Viewport")
         bpy.context.window.view_layer = bpy.context.scene.view_layers['Viewport']
 
         # old layer
index df47e72c3270d44c99e728bfeec2b53388058019..8dcc094a1c62f8d1f20ec4e2b0fa1472751b8767 100644 (file)
@@ -452,7 +452,6 @@ class ViewLayerTesting(unittest.TestCase):
         # real test
         layer = scene.view_layers.new('Visibility Test')
         layer.collections.unlink(layer.collections[0])
-        scene.view_layers.active = layer
 
         scene_collection = scene.master_collection.collections.new("Collection")
         layer.collections.link(scene_collection)
@@ -770,7 +769,6 @@ class Clay:
 
         layer = self._scene.view_layers.new('Evaluation Test')
         layer.collections.unlink(layer.collections[0])
-        self._scene.view_layers.active = layer
         bpy.context.window.view_layer = layer
 
         # remove all other layers