diff options
Diffstat (limited to 'source/blender/editors/render/render_internal.c')
-rw-r--r-- | source/blender/editors/render/render_internal.c | 192 |
1 files changed, 120 insertions, 72 deletions
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index d81b85f1414..e1e5c788b02 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -54,9 +54,9 @@ #include "BKE_camera.h" #include "BKE_context.h" #include "BKE_colortools.h" -#include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_layer.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" @@ -66,6 +66,9 @@ #include "BKE_screen.h" #include "BKE_scene.h" #include "BKE_undo_system.h" +#include "BKE_workspace.h" + +#include "DEG_depsgraph.h" #include "WM_api.h" #include "WM_types.h" @@ -83,6 +86,7 @@ #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" +#include "GPU_shader.h" #include "BIF_gl.h" #include "BIF_glutil.h" @@ -100,9 +104,13 @@ static int render_break(void *rjv); typedef struct RenderJob { Main *main; Scene *scene; + ViewLayer *view_layer; Scene *current_scene; + /* TODO(sergey): Should not be needed once engine will have own + * depsgraph and copy-on-write will be implemented. + */ + Depsgraph *depsgraph; Render *re; - SceneRenderLayer *srl; struct Object *camera_override; int lay_override; bool v3d_override; @@ -255,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_scene_layer_set(wmOperator *op, Main *mainp, Scene **scene, SceneRenderLayer **srl) +static void screen_render_view_layer_set(wmOperator *op, Main *mainp, Scene **scene, ViewLayer **view_layer) { /* single layer re-render */ if (RNA_struct_property_is_set(op->ptr, "scene")) { @@ -275,14 +283,14 @@ static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **s } if (RNA_struct_property_is_set(op->ptr, "layer")) { - SceneRenderLayer *rl; + ViewLayer *rl; char rl_name[RE_MAXNAME]; RNA_string_get(op->ptr, "layer", rl_name); - rl = (SceneRenderLayer *)BLI_findstring(&(*scene)->r.layers, rl_name, offsetof(SceneRenderLayer, name)); + rl = (ViewLayer *)BLI_findstring(&(*scene)->view_layers, rl_name, offsetof(ViewLayer, name)); if (rl) - *srl = rl; + *view_layer = rl; } } @@ -290,7 +298,8 @@ static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **s static int screen_render_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - SceneRenderLayer *srl = NULL; + RenderEngineType *re_type = RE_engines_find(scene->view_render.engine_id); + ViewLayer *view_layer = NULL; Render *re; Image *ima; View3D *v3d = CTX_wm_view3d(C); @@ -300,8 +309,13 @@ static int screen_render_exec(bContext *C, wmOperator *op) const bool is_write_still = RNA_boolean_get(op->ptr, "write_still"); struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL; + /* Cannot do render if there is not this function. */ + if (re_type->render_to_image == NULL) { + return OPERATOR_CANCELLED; + } + /* custom scene and single layer re-render */ - screen_render_scene_layer_set(op, mainp, &scene, &srl); + screen_render_view_layer_set(op, mainp, &scene, &view_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"); @@ -330,13 +344,13 @@ 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, srl, camera_override, lay_override, scene->r.cfra, is_write_still); + RE_BlenderFrame(re, mainp, scene, view_layer, camera_override, lay_override, scene->r.cfra, is_write_still); BLI_threaded_malloc_end(); RE_SetReports(re, NULL); // no redraw needed, we leave state as we entered it - ED_update_for_newframe(mainp, scene, 1); + ED_update_for_newframe(mainp, scene, view_layer, CTX_data_depsgraph(C)); WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene); @@ -492,8 +506,9 @@ static void render_image_update_pass_and_layer(RenderJob *rj, RenderResult *rr, for (wm = rj->main->wm.first; wm && matched_sa == NULL; wm = wm->id.next) { /* only 1 wm */ wmWindow *win; for (win = wm->windows.first; win && matched_sa == NULL; win = win->next) { - ScrArea *sa; - for (sa = win->screen->areabase.first; sa; sa = sa->next) { + const bScreen *screen = WM_window_get_active_screen(win); + + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { if (sa->spacetype == SPACE_IMAGE) { SpaceImage *sima = sa->spacedata.first; // sa->spacedata might be empty when toggling fullscreen mode. @@ -604,7 +619,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->srl, rj->camera_override, rj->lay_override, rj->scene->r.cfra, rj->write_still); + 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_SetReports(rj->re, NULL); } @@ -617,8 +632,9 @@ static void render_image_restore_layer(RenderJob *rj) for (wm = rj->main->wm.first; wm; wm = wm->id.next) { /* only 1 wm */ wmWindow *win; for (win = wm->windows.first; win; win = win->next) { - ScrArea *sa; - for (sa = win->screen->areabase.first; sa; sa = sa->next) { + const bScreen *screen = WM_window_get_active_screen(win); + + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { if (sa == rj->sa) { if (sa->spacetype == SPACE_IMAGE) { SpaceImage *sima = sa->spacedata.first; @@ -660,7 +676,7 @@ static void render_endjob(void *rjv) if (rj->anim && !(rj->scene->r.scemode & R_NO_FRAME_UPDATE)) { /* possible this fails of loading new file while rendering */ if (G.main->wm.first) { - ED_update_for_newframe(G.main, rj->scene, 1); + ED_update_for_newframe(G.main, rj->scene, rj->view_layer, rj->depsgraph); } } @@ -670,7 +686,7 @@ static void render_endjob(void *rjv) /* potentially set by caller */ rj->scene->r.scemode &= ~R_NO_FRAME_UPDATE; - if (rj->srl) { + if (rj->view_layer) { nodeUpdateID(rj->scene->nodetree, &rj->scene->id); WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene); } @@ -700,7 +716,7 @@ static void render_endjob(void *rjv) * engine API, so lets use simple and robust way for now * - sergey - */ - if (rj->scene->r.layers.first != rj->scene->r.layers.last || + if (rj->scene->view_layers.first != rj->scene->view_layers.last || rj->image_outdated) { void *lock; @@ -733,7 +749,7 @@ static void render_endjob(void *rjv) scene->lay_updated = 0; } - DAG_on_visible_update(G.main, false); + DEG_on_visible_update(G.main, false); } } @@ -797,33 +813,46 @@ static void screen_render_cancel(bContext *C, wmOperator *op) WM_jobs_kill_type(wm, scene, WM_JOB_TYPE_RENDER); } -static void clean_viewport_memory(Main *bmain, Scene *scene, int renderlay) +static void clean_viewport_memory_base(Base *base) { - Object *object; - Scene *sce_iter; - Base *base; + if ((base->flag & BASE_VISIBLED) == 0) { + return; + } - for (object = bmain->object.first; object; object = object->id.next) { - object->id.tag |= LIB_TAG_DOIT; + Object *object = base->object; + + if (object->id.tag & LIB_TAG_DOIT) { + return; } - for (SETLOOPER(scene, sce_iter, base)) { - if ((base->lay & renderlay) == 0) { - continue; - } - if (RE_allow_render_generic_object(base->object)) { - base->object->id.tag &= ~LIB_TAG_DOIT; - } + object->id.tag &= ~LIB_TAG_DOIT; + if (RE_allow_render_generic_object(object)) { + BKE_object_free_derived_caches(object); } +} - for (SETLOOPER(scene, sce_iter, base)) { - object = base->object; - if ((object->id.tag & LIB_TAG_DOIT) == 0) { - continue; +static void clean_viewport_memory(Main *bmain, Scene *scene) +{ + Scene *sce_iter; + Base *base; + + /* Tag all the available objects. */ + BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, true); + + /* Go over all the visible objects. */ + for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { + for (wmWindow *win = wm->windows.first; win; win = win->next) { + WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); + ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace); + + for (base = view_layer->object_bases.first; base; base = base->next) { + clean_viewport_memory_base(base); + } } - object->id.tag &= ~LIB_TAG_DOIT; + } - BKE_object_free_derived_caches(object); + for (SETLOOPER_SET_ONLY(scene, sce_iter, base)) { + clean_viewport_memory_base(base); } } @@ -832,8 +861,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even { /* new render clears all callbacks */ Main *mainp; + ViewLayer *view_layer = NULL; Scene *scene = CTX_data_scene(C); - SceneRenderLayer *srl = NULL; + RenderEngineType *re_type = RE_engines_find(scene->view_render.engine_id); Render *re; wmJob *wm_job; RenderJob *rj; @@ -846,7 +876,12 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL; const char *name; ScrArea *sa; - + + /* Cannot do render if there is not this function. */ + if (re_type->render_to_image == NULL) { + return OPERATOR_CANCELLED; + } + /* only one render job at a time */ if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER)) return OPERATOR_CANCELLED; @@ -901,7 +936,7 @@ 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_scene_layer_set(op, mainp, &scene, &srl); + screen_render_view_layer_set(op, mainp, &scene, &view_layer); if (RNA_struct_property_is_set(op->ptr, "layer")) jobflag |= WM_JOB_SUSPEND; @@ -911,7 +946,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even rj->main = mainp; rj->scene = scene; rj->current_scene = rj->scene; - rj->srl = srl; + rj->view_layer = view_layer; + /* TODO(sergey): Render engine should be using own depsgraph. */ + rj->depsgraph = CTX_data_depsgraph(C); rj->camera_override = camera_override; rj->lay_override = 0; rj->anim = is_animation; @@ -946,8 +983,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even /* Lock the user interface depending on render settings. */ if (scene->r.use_lock_interface) { - int renderlay = rj->lay_override ? rj->lay_override : scene->lay; - WM_set_locked_interface(CTX_wm_manager(C), true); /* Set flag interface need to be unlocked. @@ -961,7 +996,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even rj->interface_locked = true; /* Clean memory used by viewport? */ - clean_viewport_memory(rj->main, scene, renderlay); + clean_viewport_memory(rj->main, scene); } /* setup job */ @@ -1057,6 +1092,8 @@ typedef struct RenderPreview { wmJob *job; Scene *scene; + EvaluationContext *eval_ctx; + Depsgraph *depsgraph; ScrArea *sa; ARegion *ar; View3D *v3d; @@ -1071,7 +1108,8 @@ typedef struct RenderPreview { bool has_freestyle; } RenderPreview; -static int render_view3d_disprect(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rcti *disprect) +static int render_view3d_disprect(Scene *scene, const Depsgraph *depsgraph, + ARegion *ar, View3D *v3d, RegionView3D *rv3d, rcti *disprect) { /* copied code from view3d_draw.c */ rctf viewborder; @@ -1084,7 +1122,7 @@ static int render_view3d_disprect(Scene *scene, ARegion *ar, View3D *v3d, Region if (draw_border) { if (rv3d->persp == RV3D_CAMOB) { - ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, false); + ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false); disprect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder); disprect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder); @@ -1106,13 +1144,15 @@ static int render_view3d_disprect(Scene *scene, ARegion *ar, View3D *v3d, Region } /* returns true if OK */ -static bool render_view3d_get_rects(ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewplane, RenderEngine *engine, - float *r_clipsta, float *r_clipend, float *r_pixsize, bool *r_ortho) +static bool render_view3d_get_rects( + const Depsgraph *depsgraph, + ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewplane, RenderEngine *engine, + float *r_clipsta, float *r_clipend, float *r_pixsize, bool *r_ortho) { if (ar->winx < 4 || ar->winy < 4) return false; - *r_ortho = ED_view3d_viewplane_get(v3d, rv3d, ar->winx, ar->winy, viewplane, r_clipsta, r_clipend, r_pixsize); + *r_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, ar->winx, ar->winy, viewplane, r_clipsta, r_clipend, r_pixsize); engine->resolution_x = ar->winx; engine->resolution_y = ar->winy; @@ -1219,7 +1259,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda G.is_break = false; - if (false == render_view3d_get_rects(rp->ar, rp->v3d, rp->rv3d, &viewplane, rp->engine, &clipsta, &clipend, &pixsize, &orth)) + if (false == render_view3d_get_rects(rp->depsgraph, rp->ar, rp->v3d, rp->rv3d, &viewplane, rp->engine, &clipsta, &clipend, &pixsize, &orth)) return; rp->stop = stop; @@ -1252,8 +1292,9 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda } } - use_border = render_view3d_disprect(rp->scene, rp->ar, rp->v3d, - rp->rv3d, &cliprct); + use_border = render_view3d_disprect(rp->scene, rp->depsgraph, + rp->ar, rp->v3d, rp->rv3d, + &cliprct); if ((update_flag & (PR_UPDATE_RENDERSIZE | PR_UPDATE_DATABASE | PR_UPDATE_VIEW)) || rstats->convertdone == 0) { RenderData rdata; @@ -1270,10 +1311,10 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda /* initalize always */ if (use_border) { rdata.mode |= R_BORDER; - RE_InitState(re, NULL, &rdata, NULL, rp->ar->winx, rp->ar->winy, &cliprct); + RE_InitState(re, NULL, &rdata, &rp->scene->view_layers, rp->scene->active_view_layer, &rp->scene->view_render, NULL, rp->ar->winx, rp->ar->winy, &cliprct); } else - RE_InitState(re, NULL, &rdata, NULL, rp->ar->winx, rp->ar->winy, NULL); + RE_InitState(re, NULL, &rdata, &rp->scene->view_layers, rp->scene->active_view_layer, &rp->scene->view_render, NULL, rp->ar->winx, rp->ar->winy, NULL); } if (orth) @@ -1300,7 +1341,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda WM_job_main_thread_lock_release(rp->job); /* do preprocessing like building raytree, shadows, volumes, SSS */ - RE_Database_Preprocess(re); + RE_Database_Preprocess(rp->eval_ctx, re); /* conversion not completed, need to do it again */ if (!rstats->convertdone) { @@ -1366,6 +1407,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda static void render_view3d_free(void *customdata) { RenderPreview *rp = customdata; + DEG_evaluation_context_free(rp->eval_ctx); MEM_freeN(rp); } @@ -1376,6 +1418,7 @@ static bool render_view3d_flag_changed(RenderEngine *engine, const bContext *C) View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Render *re; rctf viewplane; rcti disprect; @@ -1407,8 +1450,10 @@ static bool render_view3d_flag_changed(RenderEngine *engine, const bContext *C) job_update_flag |= PR_UPDATE_DATABASE; /* load editmesh */ - if (scene->obedit) - ED_object_editmode_load(scene->obedit); + Object *obedit = CTX_data_edit_object(C); + if (obedit) { + ED_object_editmode_load(obedit); + } } engine->update_flag = 0; @@ -1425,14 +1470,14 @@ static bool render_view3d_flag_changed(RenderEngine *engine, const bContext *C) job_update_flag |= PR_UPDATE_VIEW; } - render_view3d_get_rects(ar, v3d, rv3d, &viewplane, engine, &clipsta, &clipend, NULL, &orth); + render_view3d_get_rects(depsgraph, ar, v3d, rv3d, &viewplane, engine, &clipsta, &clipend, NULL, &orth); if (BLI_rctf_compare(&viewplane, &engine->last_viewplane, 0.00001f) == 0) { engine->last_viewplane = viewplane; job_update_flag |= PR_UPDATE_VIEW; } - render_view3d_disprect(scene, ar, v3d, rv3d, &disprect); + render_view3d_disprect(scene, depsgraph, ar, v3d, rv3d, &disprect); if (BLI_rcti_compare(&disprect, &engine->last_disprect) == 0) { engine->last_disprect = disprect; job_update_flag |= PR_UPDATE_RENDERSIZE; @@ -1452,6 +1497,7 @@ static void render_view3d_do(RenderEngine *engine, const bContext *C) wmJob *wm_job; RenderPreview *rp; Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ARegion *ar = CTX_wm_region(C); int width = ar->winx, height = ar->winy; int divider = BKE_render_preview_pixel_size(&scene->r); @@ -1476,6 +1522,9 @@ static void render_view3d_do(RenderEngine *engine, const bContext *C) /* customdata for preview thread */ rp->scene = scene; + rp->depsgraph = depsgraph; + rp->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_PREVIEW); + CTX_data_eval_ctx(C, rp->eval_ctx); rp->engine = engine; rp->sa = CTX_wm_area(C); rp->ar = CTX_wm_region(C); @@ -1533,6 +1582,7 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) RegionView3D *rv3d = CTX_wm_region_view3d(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ARegion *ar = CTX_wm_region(C); bool force_fallback = false; bool need_fallback = true; @@ -1541,7 +1591,7 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) rcti clip_rect; int xof, yof; - if (render_view3d_disprect(scene, ar, v3d, rv3d, &clip_rect)) { + if (render_view3d_disprect(scene, depsgraph, ar, v3d, rv3d, &clip_rect)) { scale_x = (float) BLI_rcti_size_x(&clip_rect) / rres.rectx; scale_y = (float) BLI_rcti_size_y(&clip_rect) / rres.recty; xof = clip_rect.xmin; @@ -1561,11 +1611,10 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) if (force_fallback == false) { if (IMB_colormanagement_setup_glsl_draw(&scene->view_settings, &scene->display_settings, dither, true)) { glEnable(GL_BLEND); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glPixelZoom(scale_x, scale_y); - glaDrawPixelsTex(xof, yof, rres.rectx, rres.recty, - GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf); - glPixelZoom(1.0f, 1.0f); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + immDrawPixelsTex(&state, xof, yof, rres.rectx, rres.recty, + GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf, + scale_x, scale_y, NULL);; glDisable(GL_BLEND); IMB_colormanagement_finish_glsl_draw(); @@ -1582,12 +1631,11 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) 4, dither, &scene->view_settings, &scene->display_settings); glEnable(GL_BLEND); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glPixelZoom(scale_x, scale_y); - glaDrawPixelsAuto(xof, yof, rres.rectx, rres.recty, - GL_RGBA, GL_UNSIGNED_BYTE, - GL_NEAREST, display_buffer); - glPixelZoom(1.0f, 1.0f); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + immDrawPixelsTex(&state, xof, yof, rres.rectx, rres.recty, + GL_RGBA, GL_UNSIGNED_BYTE, + GL_NEAREST, display_buffer, + scale_x, scale_y, NULL); glDisable(GL_BLEND); MEM_freeN(display_buffer); |