diff options
Diffstat (limited to 'source')
36 files changed, 260 insertions, 322 deletions
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index 79b61b7c965..27e3d32a510 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -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); diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h index 3ba4fbe0338..376a324d25c 100644 --- a/source/blender/blenkernel/BKE_linestyle.h +++ b/source/blender/blenkernel/BKE_linestyle.h @@ -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); diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index bdbed9ab6aa..44aa1b04569 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -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) diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 74e6c996329..34079d778f7 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -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) { diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 41bdc3bb9ef..215826454a9 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -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; diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index dd1315fe3fa..5757ae7480b 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -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) diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 91ff3c15502..758db5178de 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -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) { diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 974c2faeadf..a282f535df6 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -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; diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index ebd4c04e8ce..3314e8d01b6 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -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) diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index ef6c05ff59f..7d473230a4e 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -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; } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc index 750b0054ee5..ac3970ed3ab 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc @@ -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); } } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc index c97fa3b3a5a..99295a733fc 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc @@ -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); } } diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 60533e382e8..b49a58b3766 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -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"); diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 89dbd3da16d..4e44c9b1185 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -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; diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 1c6938cbdb3..bf6aa9c9675 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -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); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 9a179ce3b47..03742b489a1 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -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; diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index c5787a1d46c..e792de01e2c 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -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"); diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c index 58a58ef8172..b6608ce600f 100644 --- a/source/blender/editors/scene/scene_edit.c +++ b/source/blender/editors/scene/scene_edit.c @@ -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); diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index e8faf794bb8..6793f0a0195 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -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 { diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index df06eee3fd5..078ab540ace 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -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); } diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 340184845b8..d91c330c853 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -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; diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 765c77e4906..fad35060d72 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -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); diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 800f36d35a0..a3dbab1b3fd 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -43,13 +43,14 @@ #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; diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 60473853e18..2a5151a16ad 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -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)) { diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 5c4d2b98055..557a0723cb4 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -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; } diff --git a/source/blender/editors/space_topbar/space_topbar.c b/source/blender/editors/space_topbar/space_topbar.c index fa39d89091c..a8555e9e269 100644 --- a/source/blender/editors/space_topbar/space_topbar.c +++ b/source/blender/editors/space_topbar/space_topbar.c @@ -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) diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 58a9a748cfd..03f3f80f807 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -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 */ diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c index b74cdb5f0a5..93df67306e3 100644 --- a/source/blender/makesrna/intern/rna_layer.c +++ b/source/blender/makesrna/intern/rna_layer.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 822ab119854..faecae7ab65 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -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) */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 5d430e5d7b9..4683031d2da 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -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} }; diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index f4e084929cc..bad80450f80 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -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; diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index 5e57338dc57..cd7a3f6d9c2 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -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); diff --git a/source/blender/render/extern/include/RE_bake.h b/source/blender/render/extern/include/RE_bake.h index d827a3507d9..76228d93e66 100644 --- a/source/blender/render/extern/include/RE_bake.h +++ b/source/blender/render/extern/include/RE_bake.h @@ -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 */ diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 022f2a31826..056e236f60e 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -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); diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 03be96a20bc..c75574cd09d 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -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, diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index dd2042d3220..afceb8bd700 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -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); |