diff options
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/CMakeLists.txt | 8 | ||||
-rw-r--r-- | source/blender/render/RE_engine.h | 5 | ||||
-rw-r--r-- | source/blender/render/intern/bake.c | 1 | ||||
-rw-r--r-- | source/blender/render/intern/engine.cc (renamed from source/blender/render/intern/engine.c) | 122 | ||||
-rw-r--r-- | source/blender/render/intern/initrender.cc (renamed from source/blender/render/intern/initrender.c) | 0 | ||||
-rw-r--r-- | source/blender/render/intern/pipeline.cc (renamed from source/blender/render/intern/pipeline.c) | 328 | ||||
-rw-r--r-- | source/blender/render/intern/render_result.cc (renamed from source/blender/render/intern/render_result.c) | 267 | ||||
-rw-r--r-- | source/blender/render/intern/render_result.h | 3 | ||||
-rw-r--r-- | source/blender/render/intern/render_types.h | 4 | ||||
-rw-r--r-- | source/blender/render/intern/texture_image.c | 1 | ||||
-rw-r--r-- | source/blender/render/intern/texture_pointdensity.c | 2 | ||||
-rw-r--r-- | source/blender/render/intern/texture_procedural.c | 1 |
12 files changed, 342 insertions, 400 deletions
diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt index db406ae96f2..5e876e5d6f2 100644 --- a/source/blender/render/CMakeLists.txt +++ b/source/blender/render/CMakeLists.txt @@ -26,11 +26,11 @@ set(INC set(SRC intern/bake.c - intern/engine.c - intern/initrender.c + intern/engine.cc + intern/initrender.cc intern/multires_bake.c - intern/pipeline.c - intern/render_result.c + intern/pipeline.cc + intern/render_result.cc intern/texture_image.c intern/texture_margin.cc intern/texture_pointdensity.c diff --git a/source/blender/render/RE_engine.h b/source/blender/render/RE_engine.h index d7815ef3f3c..b79ae310636 100644 --- a/source/blender/render/RE_engine.h +++ b/source/blender/render/RE_engine.h @@ -154,11 +154,6 @@ typedef struct RenderEngine { ThreadMutex update_render_passes_mutex; update_render_passes_cb_t update_render_passes_cb; void *update_render_passes_data; - - rctf last_viewplane; - rcti last_disprect; - float last_viewmat[4][4]; - int last_winx, last_winy; } RenderEngine; RenderEngine *RE_engine_create(RenderEngineType *type); diff --git a/source/blender/render/intern/bake.c b/source/blender/render/intern/bake.c index 54497a6572f..74e9662d5db 100644 --- a/source/blender/render/intern/bake.c +++ b/source/blender/render/intern/bake.c @@ -72,7 +72,6 @@ #include "RE_texture_margin.h" /* local include */ -#include "render_types.h" #include "zbuf.h" typedef struct BakeDataZSpan { diff --git a/source/blender/render/intern/engine.c b/source/blender/render/intern/engine.cc index 266e66092b8..e80e66a7b25 100644 --- a/source/blender/render/intern/engine.c +++ b/source/blender/render/intern/engine.cc @@ -54,7 +54,7 @@ /* Render Engine Types */ -ListBase R_engines = {NULL, NULL}; +ListBase R_engines = {nullptr, nullptr}; void RE_engines_init(void) { @@ -72,7 +72,7 @@ void RE_engines_exit(void) DRW_engines_free(); - for (type = R_engines.first; type; type = next) { + for (type = static_cast<RenderEngineType *>(R_engines.first); type; type = next) { next = type->next; BLI_remlink(&R_engines, type); @@ -97,11 +97,11 @@ void RE_engines_register(RenderEngineType *render_type) RenderEngineType *RE_engines_find(const char *idname) { - RenderEngineType *type; - - type = BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname)); + RenderEngineType *type = static_cast<RenderEngineType *>( + BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname))); if (!type) { - type = BLI_findstring(&R_engines, "BLENDER_EEVEE", offsetof(RenderEngineType, idname)); + type = static_cast<RenderEngineType *>( + BLI_findstring(&R_engines, "BLENDER_EEVEE", offsetof(RenderEngineType, idname))); } return type; @@ -115,7 +115,8 @@ bool RE_engine_is_external(const Render *re) bool RE_engine_is_opengl(RenderEngineType *render_type) { /* TODO: refine? Can we have ogl render engine without ogl render pipeline? */ - return (render_type->draw_engine != NULL) && DRW_engine_render_support(render_type->draw_engine); + return (render_type->draw_engine != nullptr) && + DRW_engine_render_support(render_type->draw_engine); } bool RE_engine_supports_alembic_procedural(const RenderEngineType *render_type, Scene *scene) @@ -135,7 +136,7 @@ bool RE_engine_supports_alembic_procedural(const RenderEngineType *render_type, RenderEngine *RE_engine_create(RenderEngineType *type) { - RenderEngine *engine = MEM_callocN(sizeof(RenderEngine), "RenderEngine"); + RenderEngine *engine = MEM_cnew<RenderEngine>("RenderEngine"); engine->type = type; BLI_mutex_init(&engine->update_render_passes_mutex); @@ -153,7 +154,7 @@ static void engine_depsgraph_free(RenderEngine *engine) } DEG_graph_free(engine->depsgraph); - engine->depsgraph = NULL; + engine->depsgraph = nullptr; if (use_gpu_context) { DRW_render_context_disable(engine->re); @@ -181,7 +182,7 @@ void RE_engine_free(RenderEngine *engine) static RenderResult *render_result_from_bake(RenderEngine *engine, int x, int y, int w, int h) { /* Create render result with specified size. */ - RenderResult *rr = MEM_callocN(sizeof(RenderResult), __func__); + RenderResult *rr = MEM_cnew<RenderResult>(__func__); rr->rectx = w; rr->recty = h; @@ -191,7 +192,7 @@ static RenderResult *render_result_from_bake(RenderEngine *engine, int x, int y, rr->tilerect.ymax = y + h; /* Add single baking render layer. */ - RenderLayer *rl = MEM_callocN(sizeof(RenderLayer), "bake render layer"); + RenderLayer *rl = MEM_cnew<RenderLayer>("bake render layer"); rl->rectx = w; rl->recty = h; BLI_addtail(&rr->layers, rl); @@ -240,7 +241,8 @@ static RenderResult *render_result_from_bake(RenderEngine *engine, int x, int y, static void render_result_to_bake(RenderEngine *engine, RenderResult *rr) { - RenderPass *rpass = RE_pass_find_by_name(rr->layers.first, RE_PASSNAME_COMBINED, ""); + RenderPass *rpass = RE_pass_find_by_name( + static_cast<RenderLayer *>(rr->layers.first), RE_PASSNAME_COMBINED, ""); if (!rpass) { return; @@ -296,7 +298,7 @@ static void engine_tile_highlight_set(RenderEngine *engine, BLI_mutex_lock(&re->highlighted_tiles_mutex); - if (re->highlighted_tiles == NULL) { + if (re->highlighted_tiles == nullptr) { re->highlighted_tiles = BLI_gset_new( BLI_ghashutil_inthash_v4_p, BLI_ghashutil_inthash_v4_cmp, "highlighted tiles"); } @@ -304,7 +306,7 @@ static void engine_tile_highlight_set(RenderEngine *engine, if (highlight) { HighlightedTile **tile_in_set; if (!BLI_gset_ensure_p_ex(re->highlighted_tiles, tile, (void ***)&tile_in_set)) { - *tile_in_set = MEM_mallocN(sizeof(HighlightedTile), __func__); + *tile_in_set = MEM_cnew<HighlightedTile>(__func__); **tile_in_set = *tile; } } @@ -351,7 +353,7 @@ RenderResult *RE_engine_begin_result( /* TODO: make this thread safe. */ - /* can be NULL if we CLAMP the width or height to 0 */ + /* can be nullptr if we CLAMP the width or height to 0 */ if (result) { render_result_clone_passes(re, result, viewname); render_result_passes_allocated_ensure(result); @@ -390,8 +392,9 @@ void RE_engine_update_result(RenderEngine *engine, RenderResult *result) if (result) { re_ensure_passes_allocated_thread_safe(re); render_result_merge(re->result, result); - result->renlay = result->layers.first; /* weak, draws first layer always */ - re->display_update(re->duh, result, NULL); + result->renlay = static_cast<RenderLayer *>( + result->layers.first); /* weak, draws first layer always */ + re->display_update(re->duh, result, nullptr); } } @@ -407,7 +410,7 @@ void RE_engine_add_pass(RenderEngine *engine, return; } - RE_create_render_pass(re->result, name, channels, chan_id, layername, NULL, false); + RE_create_render_pass(re->result, name, channels, chan_id, layername, nullptr, false); } void RE_engine_end_result( @@ -440,8 +443,9 @@ void RE_engine_end_result( /* draw */ if (!re->test_break(re->tbh)) { - result->renlay = result->layers.first; /* weak, draws first layer always */ - re->display_update(re->duh, result, NULL); + result->renlay = static_cast<RenderLayer *>( + result->layers.first); /* weak, draws first layer always */ + re->display_update(re->duh, result, nullptr); } } @@ -479,8 +483,8 @@ void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char re->i.statstr = stats; re->i.infostr = info; re->stats_draw(re->sdh, &re->i); - re->i.infostr = NULL; - re->i.statstr = NULL; + re->i.infostr = nullptr; + re->i.statstr = nullptr; } /* set engine text */ @@ -522,20 +526,20 @@ void RE_engine_report(RenderEngine *engine, int type, const char *msg) Render *re = engine->re; if (re) { - BKE_report(engine->re->reports, type, msg); + BKE_report(engine->re->reports, (eReportType)type, msg); } else if (engine->reports) { - BKE_report(engine->reports, type, msg); + BKE_report(engine->reports, (eReportType)type, msg); } } void RE_engine_set_error_message(RenderEngine *engine, const char *msg) { Render *re = engine->re; - if (re != NULL) { + if (re != nullptr) { RenderResult *rr = RE_AcquireResultRead(re); if (rr) { - if (rr->error != NULL) { + if (rr->error != nullptr) { MEM_freeN(rr->error); } rr->error = BLI_strdup(msg); @@ -547,17 +551,17 @@ void RE_engine_set_error_message(RenderEngine *engine, const char *msg) RenderPass *RE_engine_pass_by_index_get(RenderEngine *engine, const char *layer_name, int index) { Render *re = engine->re; - if (re == NULL) { - return NULL; + if (re == nullptr) { + return nullptr; } - RenderPass *pass = NULL; + RenderPass *pass = nullptr; RenderResult *rr = RE_AcquireResultRead(re); - if (rr != NULL) { + if (rr != nullptr) { const RenderLayer *layer = RE_GetRenderLayer(rr, layer_name); - if (layer != NULL) { - pass = BLI_findlink(&layer->passes, index); + if (layer != nullptr) { + pass = static_cast<RenderPass *>(BLI_findlink(&layer->passes, index)); } } RE_ReleaseResult(re); @@ -582,8 +586,8 @@ float RE_engine_get_camera_shift_x(RenderEngine *engine, Object *camera, bool us /* When using spherical stereo, get camera shift without multiview, * leaving stereo to be handled by the engine. */ Render *re = engine->re; - if (use_spherical_stereo || re == NULL) { - return BKE_camera_multiview_shift_x(NULL, camera, NULL); + if (use_spherical_stereo || re == nullptr) { + return BKE_camera_multiview_shift_x(nullptr, camera, nullptr); } return BKE_camera_multiview_shift_x(&re->r, camera, re->viewname); @@ -597,8 +601,8 @@ void RE_engine_get_camera_model_matrix(RenderEngine *engine, /* When using spherical stereo, get model matrix without multiview, * leaving stereo to be handled by the engine. */ Render *re = engine->re; - if (use_spherical_stereo || re == NULL) { - BKE_camera_multiview_model_matrix(NULL, camera, NULL, (float(*)[4])r_modelmat); + if (use_spherical_stereo || re == nullptr) { + BKE_camera_multiview_model_matrix(nullptr, camera, nullptr, (float(*)[4])r_modelmat); } else { BKE_camera_multiview_model_matrix(&re->r, camera, re->viewname, (float(*)[4])r_modelmat); @@ -608,7 +612,7 @@ void RE_engine_get_camera_model_matrix(RenderEngine *engine, bool RE_engine_get_spherical_stereo(RenderEngine *engine, Object *camera) { Render *re = engine->re; - return BKE_camera_multiview_spherical_stereo(re ? &re->r : NULL, camera) ? 1 : 0; + return BKE_camera_multiview_spherical_stereo(re ? &re->r : nullptr, camera) ? 1 : 0; } rcti *RE_engine_get_current_tiles(Render *re, int *r_total_tiles, bool *r_needs_free) @@ -623,10 +627,10 @@ rcti *RE_engine_get_current_tiles(Render *re, int *r_total_tiles, bool *r_needs_ *r_needs_free = false; - if (re->highlighted_tiles == NULL) { + if (re->highlighted_tiles == nullptr) { *r_total_tiles = 0; BLI_mutex_unlock(&re->highlighted_tiles_mutex); - return NULL; + return nullptr; } GSET_FOREACH_BEGIN (HighlightedTile *, tile, re->highlighted_tiles) { @@ -639,10 +643,10 @@ rcti *RE_engine_get_current_tiles(Render *re, int *r_total_tiles, bool *r_needs_ /* Can not realloc yet, tiles are pointing to a * stack memory. */ - tiles = MEM_mallocN(allocation_size * sizeof(rcti), "current engine tiles"); + tiles = MEM_cnew_array<rcti>(allocation_size, "current engine tiles"); } else { - tiles = MEM_reallocN(tiles, allocation_size * sizeof(rcti)); + tiles = static_cast<rcti *>(MEM_reallocN(tiles, allocation_size * sizeof(rcti))); } *r_needs_free = true; } @@ -707,7 +711,7 @@ static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer) if (!engine->depsgraph) { /* Ensure we only use persistent data for one scene / view layer at a time, * to avoid excessive memory usage. */ - RE_FreePersistentData(NULL); + RE_FreePersistentData(nullptr); /* Create new depsgraph if not cached with persistent data. */ engine->depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER); @@ -785,7 +789,7 @@ void RE_bake_engine_set_engine_parameters(Render *re, Main *bmain, Scene *scene) bool RE_bake_has_engine(const Render *re) { const RenderEngineType *type = RE_engines_find(re->r.engine); - return (type->bake != NULL); + return (type->bake != nullptr); } bool RE_bake_engine(Render *re, @@ -845,7 +849,7 @@ bool RE_bake_engine(Render *re, memset(&engine->bake, 0, sizeof(engine->bake)); } - engine->depsgraph = NULL; + engine->depsgraph = nullptr; } engine->flag &= ~RE_ENGINE_RENDERING; @@ -853,7 +857,7 @@ bool RE_bake_engine(Render *re, engine_depsgraph_free(engine); RE_engine_free(engine); - re->engine = NULL; + re->engine = nullptr; if (BKE_reports_contain(re->reports, RPT_ERROR)) { G.is_break = true; @@ -876,8 +880,8 @@ static void engine_render_view_layer(Render *re, } /* Create depsgraph with scene evaluated at render resolution. */ - ViewLayer *view_layer = BLI_findstring( - &re->scene->view_layers, view_layer_iter->name, offsetof(ViewLayer, name)); + ViewLayer *view_layer = static_cast<ViewLayer *>( + BLI_findstring(&re->scene->view_layers, view_layer_iter->name, offsetof(ViewLayer, name))); engine_depsgraph_init(engine, view_layer); /* Sync data to engine, within draw lock so scene data can be accessed safely. */ @@ -920,7 +924,7 @@ static void engine_render_view_layer(Render *re, /* NOTE: External engine might have been requested to free its * dependency graph, which is only allowed if there is no grease * pencil (pipeline is taking care of that). */ - if (!RE_engine_test_break(engine) && engine->depsgraph != NULL) { + if (!RE_engine_test_break(engine) && engine->depsgraph != nullptr) { DRW_render_gpencil(engine, engine->depsgraph); } } @@ -970,7 +974,7 @@ bool RE_engine_render(Render *re, bool do_all) /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - if (re->result == NULL || !(re->r.scemode & R_BUTS_PREVIEW)) { + if (re->result == nullptr || !(re->r.scemode & R_BUTS_PREVIEW)) { if (re->result) { render_result_free(re->result); } @@ -979,7 +983,7 @@ bool RE_engine_render(Render *re, bool do_all) } BLI_rw_mutex_unlock(&re->resultmutex); - if (re->result == NULL) { + if (re->result == nullptr) { /* Clear UI drawing locks. */ if (re->draw_lock) { re->draw_lock(re->dlh, false); @@ -1062,14 +1066,15 @@ bool RE_engine_render(Render *re, bool do_all) /* Clear tile data */ engine->flag &= ~RE_ENGINE_RENDERING; - render_result_free_list(&engine->fullresult, engine->fullresult.first); + render_result_free_list(&engine->fullresult, + static_cast<RenderResult *>(engine->fullresult.first)); /* re->engine becomes zero if user changed active render engine during render */ if (!engine_keep_depsgraph(engine) || !re->engine) { engine_depsgraph_free(engine); RE_engine_free(engine); - re->engine = NULL; + re->engine = nullptr; } if (re->r.scemode & R_EXR_CACHE_FILE) { @@ -1106,8 +1111,8 @@ void RE_engine_update_render_passes(struct RenderEngine *engine, engine->update_render_passes_cb = callback; engine->update_render_passes_data = callback_data; engine->type->update_render_passes(engine, scene, view_layer); - engine->update_render_passes_cb = NULL; - engine->update_render_passes_data = NULL; + engine->update_render_passes_cb = nullptr; + engine->update_render_passes_data = nullptr; BLI_mutex_unlock(&engine->update_render_passes_mutex); } @@ -1151,7 +1156,8 @@ bool RE_engine_draw_acquire(Render *re) RenderEngine *engine = re->engine; - if (engine == NULL || engine->type->draw == NULL || (engine->flag & RE_ENGINE_CAN_DRAW) == 0) { + if (engine == nullptr || engine->type->draw == nullptr || + (engine->flag & RE_ENGINE_CAN_DRAW) == 0) { BLI_mutex_unlock(&re->engine_draw_mutex); return false; } @@ -1183,7 +1189,7 @@ void RE_engine_tile_highlight_clear_all(RenderEngine *engine) BLI_mutex_lock(&re->highlighted_tiles_mutex); - if (re->highlighted_tiles != NULL) { + if (re->highlighted_tiles != nullptr) { BLI_gset_clear(re->highlighted_tiles, MEM_freeN); } @@ -1199,11 +1205,11 @@ void RE_engine_tile_highlight_clear_all(RenderEngine *engine) bool RE_engine_has_render_context(RenderEngine *engine) { - if (engine->re == NULL) { + if (engine->re == nullptr) { return false; } - return RE_gl_context_get(engine->re) != NULL; + return RE_gl_context_get(engine->re) != nullptr; } void RE_engine_render_context_enable(RenderEngine *engine) diff --git a/source/blender/render/intern/initrender.c b/source/blender/render/intern/initrender.cc index a2a6a5815a0..a2a6a5815a0 100644 --- a/source/blender/render/intern/initrender.c +++ b/source/blender/render/intern/initrender.cc diff --git a/source/blender/render/intern/pipeline.c b/source/blender/render/intern/pipeline.cc index 30e8cfa5c17..c3365a7b3ed 100644 --- a/source/blender/render/intern/pipeline.c +++ b/source/blender/render/intern/pipeline.cc @@ -33,6 +33,7 @@ #include "BLI_string.h" #include "BLI_threads.h" #include "BLI_timecode.h" +#include "BLI_vector.hh" #include "BLT_translation.h" @@ -41,7 +42,6 @@ #include "BKE_callbacks.h" #include "BKE_camera.h" #include "BKE_colortools.h" -#include "BKE_context.h" /* XXX needed by wm_window.h */ #include "BKE_global.h" #include "BKE_image.h" #include "BKE_image_format.h" @@ -49,6 +49,7 @@ #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_lib_remap.h" +#include "BKE_main.h" #include "BKE_mask.h" #include "BKE_modifier.h" #include "BKE_node.h" @@ -123,7 +124,7 @@ /* here we store all renders */ static struct { ListBase renderlist; -} RenderGlobal = {{NULL, NULL}}; +} RenderGlobal = {{nullptr, nullptr}}; /** \} */ @@ -185,7 +186,7 @@ static int default_break(void *UNUSED(arg)) static void stats_background(void *UNUSED(arg), RenderStats *rs) { - if (rs->infostr == NULL) { + if (rs->infostr == nullptr) { return; } @@ -221,7 +222,7 @@ static void stats_background(void *UNUSED(arg), RenderStats *rs) fflush(stdout); /* NOTE: using G_MAIN seems valid here??? - * Not sure it's actually even used anyway, we could as well pass NULL? */ + * Not sure it's actually even used anyway, we could as well pass nullptr? */ BKE_callback_exec_null(G_MAIN, BKE_CB_EVT_RENDER_STATS); fputc('\n', stdout); @@ -238,16 +239,17 @@ void RE_FreeRenderResult(RenderResult *rr) float *RE_RenderLayerGetPass(RenderLayer *rl, const char *name, const char *viewname) { RenderPass *rpass = RE_pass_find_by_name(rl, name, viewname); - return rpass ? rpass->rect : NULL; + return rpass ? rpass->rect : nullptr; } RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name) { - if (rr == NULL) { - return NULL; + if (rr == nullptr) { + return nullptr; } - return BLI_findstring(&rr->layers, name, offsetof(RenderLayer, name)); + return static_cast<RenderLayer *>( + BLI_findstring(&rr->layers, name, offsetof(RenderLayer, name))); } bool RE_HasSingleLayer(Render *re) @@ -263,17 +265,18 @@ RenderResult *RE_MultilayerConvert( RenderLayer *render_get_active_layer(Render *re, RenderResult *rr) { - ViewLayer *view_layer = BLI_findlink(&re->view_layers, re->active_view_layer); + ViewLayer *view_layer = static_cast<ViewLayer *>( + BLI_findlink(&re->view_layers, re->active_view_layer)); if (view_layer) { - RenderLayer *rl = BLI_findstring(&rr->layers, view_layer->name, offsetof(RenderLayer, name)); + RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name); if (rl) { return rl; } } - return rr->layers.first; + return static_cast<RenderLayer *>(rr->layers.first); } static bool render_scene_has_layers_to_render(Scene *scene, ViewLayer *single_layer) @@ -282,8 +285,7 @@ static bool render_scene_has_layers_to_render(Scene *scene, ViewLayer *single_la return true; } - ViewLayer *view_layer; - for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (view_layer->flag & VIEW_LAYER_RENDER) { return true; } @@ -299,16 +301,14 @@ static bool render_scene_has_layers_to_render(Scene *scene, ViewLayer *single_la Render *RE_GetRender(const char *name) { - Render *re; - /* search for existing renders */ - for (re = RenderGlobal.renderlist.first; re; re = re->next) { + LISTBASE_FOREACH (Render *, re, &RenderGlobal.renderlist) { if (STREQLEN(re->name, name, RE_MAXNAME)) { - break; + return re; } } - return re; + return nullptr; } RenderResult *RE_AcquireResultRead(Render *re) @@ -318,7 +318,7 @@ RenderResult *RE_AcquireResultRead(Render *re) return re->result; } - return NULL; + return nullptr; } RenderResult *RE_AcquireResultWrite(Render *re) @@ -329,14 +329,14 @@ RenderResult *RE_AcquireResultWrite(Render *re) return re->result; } - return NULL; + return nullptr; } void RE_ClearResult(Render *re) { if (re) { render_result_free(re->result); - re->result = NULL; + re->result = nullptr; } } @@ -360,7 +360,7 @@ Scene *RE_GetScene(Render *re) if (re) { return re->scene; } - return NULL; + return nullptr; } void RE_SetScene(Render *re, Scene *sce) @@ -378,30 +378,27 @@ void RE_AcquireResultImageViews(Render *re, RenderResult *rr) BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_READ); if (re->result) { - RenderLayer *rl; - RenderView *rv, *rview; - rr->rectx = re->result->rectx; rr->recty = re->result->recty; /* creates a temporary duplication of views */ render_result_views_shallowcopy(rr, re->result); - rv = rr->views.first; - rr->have_combined = (rv->rectf != NULL); + RenderView *rv = static_cast<RenderView *>(rr->views.first); + rr->have_combined = (rv->rectf != nullptr); /* active layer */ - rl = render_get_active_layer(re, re->result); + RenderLayer *rl = render_get_active_layer(re, re->result); if (rl) { - if (rv->rectf == NULL) { - for (rview = (RenderView *)rr->views.first; rview; rview = rview->next) { + if (rv->rectf == nullptr) { + LISTBASE_FOREACH (RenderView *, rview, &rr->views) { rview->rectf = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, rview->name); } } - if (rv->rectz == NULL) { - for (rview = (RenderView *)rr->views.first; rview; rview = rview->next) { + if (rv->rectz == nullptr) { + LISTBASE_FOREACH (RenderView *, rview, &rr->views) { rview->rectz = RE_RenderLayerGetPass(rl, RE_PASSNAME_Z, rview->name); } } @@ -441,7 +438,7 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr, const int view_id) /* actview view */ rv = RE_RenderViewGetById(re->result, view_id); - rr->have_combined = (rv->rectf != NULL); + rr->have_combined = (rv->rectf != nullptr); rr->rectf = rv->rectf; rr->rectz = rv->rectz; @@ -451,11 +448,11 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr, const int view_id) rl = render_get_active_layer(re, re->result); if (rl) { - if (rv->rectf == NULL) { + if (rv->rectf == nullptr) { rr->rectf = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, rv->name); } - if (rv->rectz == NULL) { + if (rv->rectz == nullptr) { rr->rectz = RE_RenderLayerGetPass(rl, RE_PASSNAME_Z, rv->name); } } @@ -519,10 +516,10 @@ Render *RE_NewRender(const char *name) /* only one render per name exists */ re = RE_GetRender(name); - if (re == NULL) { + if (re == nullptr) { /* new render data struct */ - re = MEM_callocN(sizeof(Render), "new render"); + re = MEM_cnew<Render>("new render"); BLI_addtail(&RenderGlobal.renderlist, re); BLI_strncpy(re->name, name, RE_MAXNAME); BLI_rw_mutex_init(&re->resultmutex); @@ -578,7 +575,7 @@ void RE_InitRenderCB(Render *re) re->stats_draw = stats_nothing; } /* clear callback handles */ - re->dih = re->dch = re->duh = re->sdh = re->prh = re->tbh = NULL; + re->dih = re->dch = re->duh = re->sdh = re->prh = re->tbh = nullptr; } void RE_FreeRender(Render *re) @@ -596,13 +593,13 @@ void RE_FreeRender(Render *re) BKE_curvemapping_free_data(&re->r.mblur_shutter_curve); - if (re->highlighted_tiles != NULL) { + if (re->highlighted_tiles != nullptr) { BLI_gset_free(re->highlighted_tiles, MEM_freeN); } /* main dbase can already be invalid now, some database-free code checks it */ - re->main = NULL; - re->scene = NULL; + re->main = nullptr; + re->scene = nullptr; render_result_free(re->result); render_result_free(re->pushedresult); @@ -614,7 +611,7 @@ void RE_FreeRender(Render *re) void RE_FreeAllRender(void) { while (RenderGlobal.renderlist.first) { - RE_FreeRender(RenderGlobal.renderlist.first); + RE_FreeRender(static_cast<Render *>(RenderGlobal.renderlist.first)); } #ifdef WITH_FREESTYLE @@ -625,25 +622,22 @@ void RE_FreeAllRender(void) void RE_FreeAllRenderResults(void) { - Render *re; - - for (re = RenderGlobal.renderlist.first; re; re = re->next) { + LISTBASE_FOREACH (Render *, re, &RenderGlobal.renderlist) { render_result_free(re->result); render_result_free(re->pushedresult); - re->result = NULL; - re->pushedresult = NULL; + re->result = nullptr; + re->pushedresult = nullptr; } } void RE_FreeAllPersistentData(void) { - Render *re; - for (re = RenderGlobal.renderlist.first; re != NULL; re = re->next) { - if (re->engine != NULL) { + LISTBASE_FOREACH (Render *, re, &RenderGlobal.renderlist) { + if (re->engine != nullptr) { BLI_assert(!(re->engine->flag & RE_ENGINE_RENDERING)); RE_engine_free(re->engine); - re->engine = NULL; + re->engine = nullptr; } } } @@ -653,7 +647,7 @@ static void re_free_persistent_data(Render *re) /* If engine is currently rendering, just wait for it to be freed when it finishes rendering. */ if (re->engine && !(re->engine->flag & RE_ENGINE_RENDERING)) { RE_engine_free(re->engine); - re->engine = NULL; + re->engine = nullptr; } } @@ -667,7 +661,7 @@ void RE_FreePersistentData(const Scene *scene) } } else { - for (Render *re = RenderGlobal.renderlist.first; re; re = re->next) { + LISTBASE_FOREACH (Render *, re, &RenderGlobal.renderlist) { re_free_persistent_data(re); } } @@ -719,7 +713,7 @@ void render_copy_renderdata(RenderData *to, RenderData *from) BLI_freelistN(&to->views); BKE_curvemapping_free_data(&to->mblur_shutter_curve); - *to = *from; + memcpy(to, from, sizeof(*to)); BLI_duplicatelist(&to->views, &from->views); BKE_curvemapping_copy_data(&to->mblur_shutter_curve, &from->mblur_shutter_curve); @@ -787,14 +781,14 @@ void RE_InitState(Render *re, if (had_freestyle || (re->r.mode & R_EDGE_FRS)) { /* freestyle manipulates render layers so always have to free */ render_result_free(re->result); - re->result = NULL; + re->result = nullptr; } else if (re->result) { - ViewLayer *active_render_layer = BLI_findlink(&re->view_layers, re->active_view_layer); - RenderLayer *rl; + ViewLayer *active_render_layer = static_cast<ViewLayer *>( + BLI_findlink(&re->view_layers, re->active_view_layer)); bool have_layer = false; - for (rl = re->result->layers.first; rl; rl = rl->next) { + LISTBASE_FOREACH (RenderLayer *, rl, &re->result->layers) { if (STREQ(rl->name, active_render_layer->name)) { have_layer = true; } @@ -807,7 +801,7 @@ void RE_InitState(Render *re, else { /* free because resolution changed */ render_result_free(re->result); - re->result = NULL; + re->result = nullptr; } } } @@ -815,7 +809,7 @@ void RE_InitState(Render *re, /* make empty render result, so display callbacks can initialize */ render_result_free(re->result); - re->result = MEM_callocN(sizeof(RenderResult), "new render result"); + re->result = MEM_cnew<RenderResult>("new render result"); re->result->rectx = re->rectx; re->result->recty = re->recty; render_result_view_new(re->result, ""); @@ -914,13 +908,13 @@ void RE_gl_context_destroy(Render *re) if (re->gl_context) { if (re->gpu_context) { WM_opengl_context_activate(re->gl_context); - GPU_context_active_set(re->gpu_context); - GPU_context_discard(re->gpu_context); - re->gpu_context = NULL; + GPU_context_active_set(static_cast<GPUContext *>(re->gpu_context)); + GPU_context_discard(static_cast<GPUContext *>(re->gpu_context)); + re->gpu_context = nullptr; } WM_opengl_context_dispose(re->gl_context); - re->gl_context = NULL; + re->gl_context = nullptr; } } @@ -931,8 +925,8 @@ void *RE_gl_context_get(Render *re) void *RE_gpu_context_get(Render *re) { - if (re->gpu_context == NULL) { - re->gpu_context = GPU_context_create(NULL); + if (re->gpu_context == nullptr) { + re->gpu_context = GPU_context_create(nullptr); } return re->gpu_context; } @@ -982,7 +976,7 @@ static void render_result_uncrop(Render *re) rres = render_result_new(re, &re->disprect, RR_ALL_LAYERS, RR_ALL_VIEWS); rres->stamp_data = BKE_stamp_data_copy(re->result->stamp_data); - render_result_clone_passes(re, rres, NULL); + render_result_clone_passes(re, rres, nullptr); render_result_passes_allocated_ensure(rres); render_result_merge(rres, re->result); @@ -995,7 +989,7 @@ static void render_result_uncrop(Render *re) BLI_rw_mutex_unlock(&re->resultmutex); re->display_init(re->dih, re->result); - re->display_update(re->duh, re->result, NULL); + re->display_update(re->duh, re->result, nullptr); /* restore the disprect from border */ re->disprect = orig_disprect; @@ -1015,7 +1009,7 @@ static void do_render_engine(Render *re) { Object *camera = RE_GetCamera(re); /* also check for camera here */ - if (camera == NULL) { + if (camera == nullptr) { BKE_report(re->reports, RPT_ERROR, "Cannot render, no camera"); G.is_break = true; return; @@ -1048,7 +1042,7 @@ static void do_render_compositor_scene(Render *re, Scene *sce, int cfra) } /* initial setup */ - RE_InitState(resc, re, &sce->r, &sce->view_layers, NULL, winx, winy, &re->disprect); + RE_InitState(resc, re, &sce->r, &sce->view_layers, nullptr, 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); @@ -1075,9 +1069,8 @@ static void do_render_compositor_scene(Render *re, Scene *sce, int cfra) static int compositor_needs_render(Scene *sce, int this_scene) { bNodeTree *ntree = sce->nodetree; - bNode *node; - if (ntree == NULL) { + if (ntree == nullptr) { return 1; } if (sce->use_nodes == false) { @@ -1087,9 +1080,9 @@ static int compositor_needs_render(Scene *sce, int this_scene) return 1; } - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { - if (this_scene == 0 || node->id == NULL || node->id == &sce->id) { + if (this_scene == 0 || node->id == nullptr || node->id == &sce->id) { return 1; } } @@ -1100,11 +1093,10 @@ static int compositor_needs_render(Scene *sce, int this_scene) /* Render all scenes within a compositor node tree. */ static void do_render_compositor_scenes(Render *re) { - bNode *node; int cfra = re->scene->r.cfra; Scene *restore_scene = re->scene; - if (re->scene->nodetree == NULL) { + if (re->scene->nodetree == nullptr) { return; } @@ -1113,12 +1105,12 @@ static void do_render_compositor_scenes(Render *re) /* now foreach render-result node we do a full render */ /* results are stored in a way compositor will find it */ GSet *scenes_rendered = BLI_gset_ptr_new(__func__); - for (node = re->scene->nodetree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &re->scene->nodetree->nodes) { if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { if (node->id && node->id != (ID *)re->scene) { Scene *scene = (Scene *)node->id; if (!BLI_gset_haskey(scenes_rendered, scene) && - render_scene_has_layers_to_render(scene, false)) { + render_scene_has_layers_to_render(scene, nullptr)) { do_render_compositor_scene(re, scene, cfra); BLI_gset_add(scenes_rendered, scene); node->typeinfo->updatefunc(restore_scene->nodetree, node); @@ -1130,7 +1122,7 @@ static void do_render_compositor_scenes(Render *re) } } } - BLI_gset_free(scenes_rendered, NULL); + BLI_gset_free(scenes_rendered, nullptr); if (changed_scene) { /* If rendered another scene, switch back to the current scene with compositing nodes. */ @@ -1215,64 +1207,59 @@ static void do_render_compositor(Render *re) /* If we have consistent depsgraph now would be a time to update them. */ } - RenderView *rv; - for (rv = re->result->views.first; rv; rv = rv->next) { + LISTBASE_FOREACH (RenderView *, rv, &re->result->views) { ntreeCompositExecTree( re->pipeline_scene_eval, ntree, &re->r, true, G.background == 0, rv->name); } - ntree->stats_draw = NULL; - ntree->test_break = NULL; - ntree->progress = NULL; - ntree->tbh = ntree->sdh = ntree->prh = NULL; + ntree->stats_draw = nullptr; + ntree->test_break = nullptr; + ntree->progress = nullptr; + ntree->tbh = ntree->sdh = ntree->prh = nullptr; } } } /* Weak: the display callback wants an active render-layer pointer. */ - if (re->result != NULL) { + if (re->result != nullptr) { re->result->renlay = render_get_active_layer(re, re->result); - re->display_update(re->duh, re->result, NULL); + re->display_update(re->duh, re->result, nullptr); } } static void renderresult_stampinfo(Render *re) { RenderResult rres; - RenderView *rv; - int nr; + int nr = 0; /* this is the basic trick to get the displayed float or char rect from render result */ - nr = 0; - for (rv = re->result->views.first; rv; rv = rv->next, nr++) { + LISTBASE_FOREACH (RenderView *, rv, &re->result->views) { RE_SetActiveRenderView(re, rv->name); RE_AcquireResultImage(re, &rres, nr); Object *ob_camera_eval = DEG_get_evaluated_object(re->pipeline_depsgraph, RE_GetCamera(re)); BKE_image_stamp_buf(re->scene, ob_camera_eval, - (re->r.stamp & R_STAMP_STRIPMETA) ? rres.stamp_data : NULL, + (re->r.stamp & R_STAMP_STRIPMETA) ? rres.stamp_data : nullptr, (unsigned char *)rres.rect32, rres.rectf, rres.rectx, rres.recty, 4); RE_ReleaseResultImage(re); + nr++; } } int RE_seq_render_active(Scene *scene, RenderData *rd) { - Editing *ed; - Sequence *seq; - - ed = scene->ed; + Editing *ed = scene->ed; if (!(rd->scemode & R_DOSEQ) || !ed || !ed->seqbase.first) { return 0; } - for (seq = ed->seqbase.first; seq; seq = seq->next) { + LISTBASE_FOREACH (Sequence *, seq, &ed->seqbase) { if (seq->type != SEQ_TYPE_SOUND_RAM) { return 1; } @@ -1290,7 +1277,6 @@ static void do_render_sequencer(Render *re) int cfra = re->r.cfra; SeqRenderData context; int view_id, tot_views; - struct ImBuf **ibuf_arr; int re_x, re_y; re->i.cfra = cfra; @@ -1309,7 +1295,7 @@ static void do_render_sequencer(Render *re) } tot_views = BKE_scene_multiview_num_views_get(&re->r); - ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * tot_views, "Sequencer Views ImBufs"); + blender::Vector<ImBuf *> ibuf_arr(tot_views); SEQ_render_new_render_data(re->main, re->pipeline_depsgraph, @@ -1334,7 +1320,7 @@ static void do_render_sequencer(Render *re) SEQ_render_imbuf_from_sequencer_space(re->pipeline_scene_eval, ibuf_arr[view_id]); } else { - ibuf_arr[view_id] = NULL; + ibuf_arr[view_id] = nullptr; } } @@ -1354,7 +1340,7 @@ static void do_render_sequencer(Render *re) if (ibuf_arr[view_id]->metadata && (re->r.stamp & R_STAMP_STRIPMETA)) { /* ensure render stamp info first */ - BKE_render_result_stamp_info(NULL, NULL, rr, true); + BKE_render_result_stamp_info(nullptr, nullptr, rr, true); BKE_stamp_info_from_imbuf(rr, ibuf_arr[view_id]); } @@ -1375,11 +1361,9 @@ static void do_render_sequencer(Render *re) /* would mark display buffers as invalid */ RE_SetActiveRenderView(re, rv->name); - re->display_update(re->duh, re->result, NULL); + re->display_update(re->duh, re->result, nullptr); } - MEM_freeN(ibuf_arr); - recurs_depth--; /* just in case this flag went missing at some point */ @@ -1422,7 +1406,7 @@ static void do_render_full_pipeline(Render *re) } re->stats_draw(re->sdh, &re->i); - re->display_update(re->duh, re->result, NULL); + re->display_update(re->duh, re->result, nullptr); } else { do_render_compositor(re); @@ -1433,7 +1417,7 @@ static void do_render_full_pipeline(Render *re) re->stats_draw(re->sdh, &re->i); /* save render result stamp if needed */ - if (re->result != NULL) { + if (re->result != nullptr) { /* sequence rendering should have taken care of that already */ if (!(render_seq && (re->r.stamp & R_STAMP_STRIPMETA))) { Object *ob_camera_eval = DEG_get_evaluated_object(re->pipeline_depsgraph, RE_GetCamera(re)); @@ -1443,7 +1427,7 @@ static void do_render_full_pipeline(Render *re) /* stamp image info here */ if ((re->r.stamp & R_STAMP_ALL) && (re->r.stamp & R_STAMP_DRAW)) { renderresult_stampinfo(re); - re->display_update(re->duh, re->result, NULL); + re->display_update(re->duh, re->result, nullptr); } } } @@ -1451,38 +1435,34 @@ static void do_render_full_pipeline(Render *re) static bool check_valid_compositing_camera(Scene *scene, Object *camera_override) { if (scene->r.scemode & R_DOCOMP && scene->use_nodes) { - bNode *node = scene->nodetree->nodes.first; - - while (node) { + LISTBASE_FOREACH (bNode *, node, &scene->nodetree->nodes) { if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { Scene *sce = node->id ? (Scene *)node->id : scene; - if (sce->camera == NULL) { + if (sce->camera == nullptr) { sce->camera = BKE_view_layer_camera_find(BKE_view_layer_default_render(sce)); } - if (sce->camera == NULL) { + if (sce->camera == nullptr) { /* all render layers nodes need camera */ return false; } } - node = node->next; } return true; } - return (camera_override != NULL || scene->camera != NULL); + return (camera_override != nullptr || scene->camera != nullptr); } static bool check_valid_camera_multiview(Scene *scene, Object *camera, ReportList *reports) { - SceneRenderView *srv; bool active_view = false; - if (camera == NULL || (scene->r.scemode & R_MULTIVIEW) == 0) { + if (camera == nullptr || (scene->r.scemode & R_MULTIVIEW) == 0) { return true; } - for (srv = scene->r.views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) { if (BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { active_view = true; @@ -1516,7 +1496,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) { + if (camera_override == nullptr && scene->camera == nullptr) { scene->camera = BKE_view_layer_camera_find(BKE_view_layer_default_render(scene)); } @@ -1526,16 +1506,14 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList if (RE_seq_render_active(scene, &scene->r)) { if (scene->ed) { - Sequence *seq = scene->ed->seqbase.first; - - while (seq) { + LISTBASE_FOREACH (Sequence *, seq, &scene->ed->seqbase) { if ((seq->type == SEQ_TYPE_SCENE) && ((seq->flag & SEQ_SCENE_STRIPS) == 0) && - (seq->scene != NULL)) { + (seq->scene != nullptr)) { if (!seq->scene_camera) { if (!seq->scene->camera && !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; + Object *override = (seq->scene == scene) ? camera_override : nullptr; if (!check_valid_compositing_camera(seq->scene, override)) { BKE_reportf(reports, RPT_ERROR, err_msg, seq->scene->id.name + 2); @@ -1547,8 +1525,6 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList return false; } } - - seq = seq->next; } } } @@ -1562,9 +1538,7 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList static bool node_tree_has_compositor_output(bNodeTree *ntree) { - bNode *node; - - for (node = ntree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) { return true; } @@ -1728,7 +1702,7 @@ static int render_init_from_main(Render *re, BLI_rw_mutex_unlock(&re->resultmutex); } - RE_InitState(re, NULL, &scene->r, &scene->view_layers, single_layer, winx, winy, &disprect); + RE_InitState(re, nullptr, &scene->r, &scene->view_layers, single_layer, winx, winy, &disprect); if (!re->ok) { /* if an error was printed, abort */ return 0; } @@ -1776,19 +1750,19 @@ static void render_pipeline_free(Render *re) { if (re->engine && !RE_engine_use_persistent_data(re->engine)) { RE_engine_free(re->engine); - re->engine = NULL; + re->engine = nullptr; } - if (re->pipeline_depsgraph != NULL) { + if (re->pipeline_depsgraph != nullptr) { DEG_graph_free(re->pipeline_depsgraph); - re->pipeline_depsgraph = NULL; - re->pipeline_scene_eval = NULL; + re->pipeline_depsgraph = nullptr; + re->pipeline_scene_eval = nullptr; } /* Destroy the opengl context in the correct thread. */ RE_gl_context_destroy(re); /* In the case the engine did not mark tiles as finished (un-highlight, which could happen in the * case of cancelled render) ensure the storage is empty. */ - if (re->highlighted_tiles != NULL) { + if (re->highlighted_tiles != nullptr) { BLI_mutex_lock(&re->highlighted_tiles_mutex); /* Rendering is supposed to be finished here, so no new tiles are expected to be written. @@ -1796,7 +1770,7 @@ static void render_pipeline_free(Render *re) BLI_assert(re->highlighted_tiles); BLI_gset_free(re->highlighted_tiles, MEM_freeN); - re->highlighted_tiles = NULL; + re->highlighted_tiles = nullptr; BLI_mutex_unlock(&re->highlighted_tiles_mutex); } @@ -1821,7 +1795,8 @@ void RE_RenderFrame(Render *re, scene->r.subframe = subframe; if (render_init_from_main(re, &scene->r, bmain, scene, single_layer, camera_override, 0, 0)) { - const RenderData rd = scene->r; + RenderData rd; + memcpy(&rd, &scene->r, sizeof(rd)); MEM_reset_peak_memory(); render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_PRE); @@ -1844,10 +1819,10 @@ void RE_RenderFrame(Render *re, &rd.im_format, (rd.scemode & R_EXTENSION) != 0, false, - NULL); + nullptr); /* reports only used for Movie */ - do_write_image_or_movie(re, bmain, scene, NULL, 0, name); + do_write_image_or_movie(re, bmain, scene, nullptr, 0, name); } } @@ -1877,7 +1852,7 @@ static void change_renderdata_engine(Render *re, const char *new_engine) if (!STREQ(re->r.engine, new_engine)) { if (re->engine) { RE_engine_free(re->engine); - re->engine = NULL; + re->engine = nullptr; } BLI_strncpy(re->r.engine, new_engine, sizeof(re->r.engine)); } @@ -1892,7 +1867,7 @@ static bool use_eevee_for_freestyle_render(Render *re) void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene, int render) { re->result_ok = 0; - if (render_init_from_main(re, &scene->r, bmain, scene, NULL, NULL, 0, 0)) { + if (render_init_from_main(re, &scene->r, bmain, scene, nullptr, nullptr, 0, 0)) { if (render) { char scene_engine[32]; BLI_strncpy(scene_engine, re->r.engine, sizeof(scene_engine)); @@ -1919,7 +1894,8 @@ void RE_RenderFreestyleExternal(Render *re) LISTBASE_FOREACH (RenderView *, rv, &re->result->views) { RE_SetActiveRenderView(re, rv->name); - ViewLayer *active_view_layer = BLI_findlink(&re->view_layers, re->active_view_layer); + ViewLayer *active_view_layer = static_cast<ViewLayer *>( + BLI_findlink(&re->view_layers, re->active_view_layer)); FRS_begin_stroke_rendering(re); LISTBASE_FOREACH (ViewLayer *, view_layer, &re->view_layers) { @@ -1959,7 +1935,7 @@ bool RE_WriteRenderViewsMovie(ReportList *reports, } ImageFormatData image_format; - BKE_image_format_init_for_write(&image_format, scene, NULL); + BKE_image_format_init_for_write(&image_format, scene, nullptr); const bool is_mono = BLI_listbase_count_at_most(&rr->views, 2) < 2; const float dither = scene->r.dither_intensity; @@ -1989,7 +1965,7 @@ bool RE_WriteRenderViewsMovie(ReportList *reports, } else { /* R_IMF_VIEWS_STEREO_3D */ const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - ImBuf *ibuf_arr[3] = {NULL}; + ImBuf *ibuf_arr[3] = {nullptr}; int i; BLI_assert((totvideos == 1) && (image_format.views_format == R_IMF_VIEWS_STEREO_3D)); @@ -2061,7 +2037,7 @@ static bool do_write_image_or_movie(Render *re, &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, true, - NULL); + nullptr); } /* write images as individual images or stereo */ @@ -2081,7 +2057,7 @@ static bool do_write_image_or_movie(Render *re, fflush(stdout); /* NOTE: using G_MAIN seems valid here??? - * Not sure it's actually even used anyway, we could as well pass NULL? */ + * Not sure it's actually even used anyway, we could as well pass nullptr? */ render_callback_exec_null(re, G_MAIN, BKE_CB_EVT_RENDER_STATS); if (do_write_file) { @@ -2144,8 +2120,9 @@ void RE_RenderAnim(Render *re, * copying (e.g. alter the output path). */ render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_INIT); - const RenderData rd = scene->r; - bMovieHandle *mh = NULL; + RenderData rd; + memcpy(&rd, &scene->r, sizeof(rd)); + bMovieHandle *mh = nullptr; const int cfra_old = rd.cfra; const float subframe_old = rd.subframe; int nfra, totrendered = 0, totskipped = 0; @@ -2175,12 +2152,12 @@ void RE_RenderAnim(Render *re, get_videos_dimensions(re, &rd, &width, &height); mh = BKE_movie_handle_get(rd.im_format.imtype); - if (mh == NULL) { + if (mh == nullptr) { BKE_report(re->reports, RPT_ERROR, "Movie format unsupported"); return; } - re->movie_ctx_arr = MEM_mallocN(sizeof(void *) * totvideos, "Movies' Context"); + re->movie_ctx_arr = MEM_cnew_array<void *>(totvideos, "Movies' Context"); for (i = 0; i < totvideos; i++) { const char *suffix = BKE_scene_multiview_view_id_suffix_get(&re->r, i); @@ -2260,7 +2237,7 @@ void RE_RenderAnim(Render *re, &rd.im_format, (rd.scemode & R_EXTENSION) != 0, true, - NULL); + nullptr); } if (rd.mode & R_NO_OVERWRITE) { @@ -2272,11 +2249,10 @@ void RE_RenderAnim(Render *re, } } else { - SceneRenderView *srv; bool is_skip = false; char filepath[FILE_MAX]; - for (srv = scene->r.views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) { if (!BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { continue; } @@ -2304,10 +2280,9 @@ void RE_RenderAnim(Render *re, } } else { - SceneRenderView *srv; char filepath[FILE_MAX]; - for (srv = scene->r.views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) { if (!BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { continue; } @@ -2334,7 +2309,7 @@ void RE_RenderAnim(Render *re, if (re->test_break(re->tbh) == 0) { if (!G.is_break) { - if (!do_write_image_or_movie(re, bmain, scene, mh, totvideos, NULL)) { + if (!do_write_image_or_movie(re, bmain, scene, mh, totvideos, nullptr)) { G.is_break = true; } } @@ -2354,10 +2329,9 @@ void RE_RenderAnim(Render *re, } } else { - SceneRenderView *srv; char filepath[FILE_MAX]; - for (srv = scene->r.views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) { if (!BKE_scene_multiview_is_render_view_active(&scene->r, srv)) { continue; } @@ -2417,7 +2391,7 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce) BKE_render_resolution(&sce->r, false, &winx, &winy); - RE_InitState(re, NULL, &sce->r, &sce->view_layers, NULL, winx, winy, NULL); + RE_InitState(re, nullptr, &sce->r, &sce->view_layers, nullptr, winx, winy, nullptr); re->main = bmain; re->scene = sce; @@ -2430,7 +2404,7 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce) /* No persistent data for preview render. */ if (re->engine) { RE_engine_free(re->engine); - re->engine = NULL; + re->engine = nullptr; } } @@ -2466,10 +2440,10 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode) /* get render: it can be called from UI with draw callbacks */ re = RE_GetSceneRender(scene); - if (re == NULL) { + if (re == nullptr) { re = RE_NewSceneRender(scene); } - RE_InitState(re, NULL, &scene->r, &scene->view_layers, NULL, winx, winy, &disprect); + RE_InitState(re, nullptr, &scene->r, &scene->view_layers, nullptr, winx, winy, &disprect); re->scene = scene; BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); @@ -2485,17 +2459,17 @@ void RE_layer_load_from_file( RenderLayer *layer, ReportList *reports, const char *filepath, int x, int y) { /* OCIO_TODO: assume layer was saved in default color space */ - ImBuf *ibuf = IMB_loadiffname(filepath, IB_rect, NULL); - RenderPass *rpass = NULL; + ImBuf *ibuf = IMB_loadiffname(filepath, IB_rect, nullptr); + RenderPass *rpass = nullptr; /* multiview: since the API takes no 'view', we use the first combined pass found */ - for (rpass = layer->passes.first; rpass; rpass = rpass->next) { + for (rpass = static_cast<RenderPass *>(layer->passes.first); rpass; rpass = rpass->next) { if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) { break; } } - if (rpass == NULL) { + if (rpass == nullptr) { BKE_reportf(reports, RPT_ERROR, "%s: no Combined pass found in the render layer '%s'", @@ -2505,7 +2479,7 @@ void RE_layer_load_from_file( if (ibuf && (ibuf->rect || ibuf->rect_float)) { if (ibuf->x == layer->rectx && ibuf->y == layer->recty) { - if (ibuf->rect_float == NULL) { + if (ibuf->rect_float == nullptr) { IMB_float_from_rect(ibuf); } @@ -2515,7 +2489,7 @@ void RE_layer_load_from_file( if ((ibuf->x - x >= layer->rectx) && (ibuf->y - y >= layer->recty)) { ImBuf *ibuf_clip; - if (ibuf->rect_float == NULL) { + if (ibuf->rect_float == nullptr) { IMB_float_from_rect(ibuf); } @@ -2550,7 +2524,7 @@ void RE_layer_load_from_file( void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filepath) { - if (!render_result_exr_file_read_path(result, NULL, filepath)) { + if (!render_result_exr_file_read_path(result, nullptr, filepath)) { BKE_reportf(reports, RPT_ERROR, "%s: failed to load '%s'", __func__, filepath); return; } @@ -2582,19 +2556,17 @@ bool RE_passes_have_name(struct RenderLayer *rl) RenderPass *RE_pass_find_by_name(RenderLayer *rl, const char *name, const char *viewname) { - RenderPass *rp = NULL; - - for (rp = rl->passes.last; rp; rp = rp->prev) { + LISTBASE_FOREACH_BACKWARD (RenderPass *, rp, &rl->passes) { if (STREQ(rp->name, name)) { - if (viewname == NULL || viewname[0] == '\0') { - break; + if (viewname == nullptr || viewname[0] == '\0') { + return rp; } if (STREQ(rp->view, viewname)) { - break; + return rp; } } } - return rp; + return nullptr; } RenderPass *RE_pass_find_by_type(RenderLayer *rl, int passtype, const char *viewname) @@ -2632,15 +2604,15 @@ RenderPass *RE_pass_find_by_type(RenderLayer *rl, int passtype, const char *view #undef CHECK_PASS - return NULL; + return nullptr; } RenderPass *RE_create_gp_pass(RenderResult *rr, const char *layername, const char *viewname) { - RenderLayer *rl = BLI_findstring(&rr->layers, layername, offsetof(RenderLayer, name)); + RenderLayer *rl = RE_GetRenderLayer(rr, layername); /* only create render layer if not exist */ if (!rl) { - rl = MEM_callocN(sizeof(RenderLayer), layername); + rl = MEM_cnew<RenderLayer>(layername); BLI_addtail(&rr->layers, rl); BLI_strncpy(rl->name, layername, sizeof(rl->name)); rl->layflag = SCE_LAY_SOLID; diff --git a/source/blender/render/intern/render_result.c b/source/blender/render/intern/render_result.cc index 4cd31fa3bc1..8edd91e0953 100644 --- a/source/blender/render/intern/render_result.c +++ b/source/blender/render/intern/render_result.cc @@ -28,6 +28,7 @@ #include "BKE_image.h" #include "BKE_image_format.h" #include "BKE_image_save.h" +#include "BKE_main.h" #include "BKE_report.h" #include "BKE_scene.h" @@ -46,7 +47,7 @@ static void render_result_views_free(RenderResult *rr) { while (rr->views.first) { - RenderView *rv = rr->views.first; + RenderView *rv = static_cast<RenderView *>(rr->views.first); BLI_remlink(&rr->views, rv); if (rv->rect32) { @@ -69,15 +70,15 @@ static void render_result_views_free(RenderResult *rr) void render_result_free(RenderResult *rr) { - if (rr == NULL) { + if (rr == nullptr) { return; } while (rr->layers.first) { - RenderLayer *rl = rr->layers.first; + RenderLayer *rl = static_cast<RenderLayer *>(rr->layers.first); while (rl->passes.first) { - RenderPass *rpass = rl->passes.first; + RenderPass *rpass = static_cast<RenderPass *>(rl->passes.first); if (rpass->rect) { MEM_freeN(rpass->rect); } @@ -130,16 +131,14 @@ void render_result_free_list(ListBase *lb, RenderResult *rr) void render_result_views_shallowcopy(RenderResult *dst, RenderResult *src) { - RenderView *rview; - - if (dst == NULL || src == NULL) { + if (dst == nullptr || src == nullptr) { return; } - for (rview = src->views.first; rview; rview = rview->next) { + LISTBASE_FOREACH (RenderView *, rview, &src->views) { RenderView *rv; - rv = MEM_mallocN(sizeof(RenderView), "new render view"); + rv = MEM_cnew<RenderView>("new render view"); BLI_addtail(&dst->views, rv); BLI_strncpy(rv->name, rview->name, sizeof(rv->name)); @@ -151,12 +150,12 @@ void render_result_views_shallowcopy(RenderResult *dst, RenderResult *src) void render_result_views_shallowdelete(RenderResult *rr) { - if (rr == NULL) { + if (rr == nullptr) { return; } while (rr->views.first) { - RenderView *rv = rr->views.first; + RenderView *rv = static_cast<RenderView *>(rr->views.first); BLI_remlink(&rr->views, rv); MEM_freeN(rv); } @@ -166,12 +165,12 @@ void render_result_views_shallowdelete(RenderResult *rr) static void render_layer_allocate_pass(RenderResult *rr, RenderPass *rp) { - if (rp->rect != NULL) { + if (rp->rect != nullptr) { return; } const size_t rectsize = ((size_t)rr->rectx) * rr->recty * rp->channels; - rp->rect = MEM_callocN(sizeof(float) * rectsize, rp->name); + rp->rect = MEM_cnew_array<float>(rectsize, rp->name); if (STREQ(rp->name, RE_PASSNAME_VECTOR)) { /* initialize to max speed */ @@ -197,7 +196,7 @@ RenderPass *render_layer_add_pass(RenderResult *rr, const bool allocate) { const int view_id = BLI_findstringindex(&rr->views, viewname, offsetof(RenderView, name)); - RenderPass *rpass = MEM_callocN(sizeof(RenderPass), name); + RenderPass *rpass = MEM_cnew<RenderPass>(name); rpass->channels = channels; rpass->rectx = rl->rectx; @@ -208,14 +207,15 @@ RenderPass *render_layer_add_pass(RenderResult *rr, BLI_strncpy(rpass->chan_id, chan_id, sizeof(rpass->chan_id)); BLI_strncpy(rpass->view, viewname, sizeof(rpass->view)); RE_render_result_full_channel_name( - rpass->fullname, NULL, rpass->name, rpass->view, rpass->chan_id, -1); + rpass->fullname, nullptr, rpass->name, rpass->view, rpass->chan_id, -1); if (rl->exrhandle) { int a; for (a = 0; a < channels; a++) { char passname[EXR_PASS_MAXNAME]; - RE_render_result_full_channel_name(passname, NULL, rpass->name, NULL, rpass->chan_id, a); - IMB_exr_add_channel(rl->exrhandle, rl->name, passname, viewname, 0, 0, NULL, false); + RE_render_result_full_channel_name( + passname, nullptr, rpass->name, nullptr, rpass->chan_id, a); + IMB_exr_add_channel(rl->exrhandle, rl->name, passname, viewname, 0, 0, nullptr, false); } } @@ -239,17 +239,16 @@ RenderResult *render_result_new(Render *re, { RenderResult *rr; RenderLayer *rl; - RenderView *rv; int rectx, recty; rectx = BLI_rcti_size_x(partrct); recty = BLI_rcti_size_y(partrct); if (rectx <= 0 || recty <= 0) { - return NULL; + return nullptr; } - rr = MEM_callocN(sizeof(RenderResult), "new render result"); + rr = MEM_cnew<RenderResult>("new render result"); rr->rectx = rectx; rr->recty = recty; rr->renrect.xmin = 0; @@ -273,7 +272,7 @@ RenderResult *render_result_new(Render *re, } } - rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); + rl = MEM_cnew<RenderLayer>("new render layer"); BLI_addtail(&rr->layers, rl); BLI_strncpy(rl->name, view_layer->name, sizeof(rl->name)); @@ -284,7 +283,7 @@ RenderResult *render_result_new(Render *re, rl->rectx = rectx; rl->recty = recty; - for (rv = rr->views.first; rv; rv = rv->next) { + LISTBASE_FOREACH (RenderView *, rv, &rr->views) { const char *view = rv->name; if (viewname && viewname[0]) { @@ -295,9 +294,9 @@ RenderResult *render_result_new(Render *re, #define RENDER_LAYER_ADD_PASS_SAFE(rr, rl, channels, name, viewname, chan_id) \ do { \ - if (render_layer_add_pass(rr, rl, channels, name, viewname, chan_id, false) == NULL) { \ + if (render_layer_add_pass(rr, rl, channels, name, viewname, chan_id, false) == nullptr) { \ render_result_free(rr); \ - return NULL; \ + return nullptr; \ } \ } while (false) @@ -383,13 +382,13 @@ RenderResult *render_result_new(Render *re, /* Preview-render doesn't do layers, so we make a default one. */ if (BLI_listbase_is_empty(&rr->layers) && !(layername && layername[0])) { - rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); + rl = MEM_cnew<RenderLayer>("new render layer"); BLI_addtail(&rr->layers, rl); rl->rectx = rectx; rl->recty = recty; - for (rv = rr->views.first; rv; rv = rv->next) { + LISTBASE_FOREACH (RenderView *, rv, &rr->views) { const char *view = rv->name; if (viewname && viewname[0]) { @@ -424,7 +423,7 @@ RenderResult *render_result_new(Render *re, void render_result_passes_allocated_ensure(RenderResult *rr) { - if (rr == NULL) { + if (rr == nullptr) { /* Happens when the result was not yet allocated for the current scene or slot configuration. */ return; @@ -432,7 +431,7 @@ void render_result_passes_allocated_ensure(RenderResult *rr) LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { LISTBASE_FOREACH (RenderPass *, rp, &rl->passes) { - if (rl->exrhandle != NULL && !STREQ(rp->name, RE_PASSNAME_COMBINED)) { + if (rl->exrhandle != nullptr && !STREQ(rp->name, RE_PASSNAME_COMBINED)) { continue; } @@ -445,24 +444,20 @@ void render_result_passes_allocated_ensure(RenderResult *rr) void render_result_clone_passes(Render *re, RenderResult *rr, const char *viewname) { - RenderLayer *rl; - RenderPass *main_rp; - - for (rl = rr->layers.first; rl; rl = rl->next) { - RenderLayer *main_rl = BLI_findstring( - &re->result->layers, rl->name, offsetof(RenderLayer, name)); + LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { + RenderLayer *main_rl = RE_GetRenderLayer(re->result, rl->name); if (!main_rl) { continue; } - for (main_rp = main_rl->passes.first; main_rp; main_rp = main_rp->next) { + LISTBASE_FOREACH (RenderPass *, main_rp, &main_rl->passes) { if (viewname && viewname[0] && !STREQ(main_rp->view, viewname)) { continue; } /* Compare fullname to make sure that the view also is equal. */ - RenderPass *rp = BLI_findstring( - &rl->passes, main_rp->fullname, offsetof(RenderPass, fullname)); + RenderPass *rp = static_cast<RenderPass *>( + BLI_findstring(&rl->passes, main_rp->fullname, offsetof(RenderPass, fullname))); if (!rp) { render_layer_add_pass( rr, rl, main_rp->channels, main_rp->name, main_rp->view, main_rp->chan_id, false); @@ -479,16 +474,12 @@ void RE_create_render_pass(RenderResult *rr, const char *viewname, const bool allocate) { - RenderLayer *rl; - RenderPass *rp; - RenderView *rv; - - for (rl = rr->layers.first; rl; rl = rl->next) { + LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { if (layername && layername[0] && !STREQ(rl->name, layername)) { continue; } - for (rv = rr->views.first; rv; rv = rv->next) { + LISTBASE_FOREACH (RenderView *, rv, &rr->views) { const char *view = rv->name; if (viewname && viewname[0] && !STREQ(view, viewname)) { @@ -496,17 +487,15 @@ void RE_create_render_pass(RenderResult *rr, } /* Ensure that the pass doesn't exist yet. */ - for (rp = rl->passes.first; rp; rp = rp->next) { - if (!STREQ(rp->name, name)) { - continue; - } - if (!STREQ(rp->view, view)) { - continue; + bool pass_exists = false; + LISTBASE_FOREACH (RenderPass *, rp, &rl->passes) { + if (STREQ(rp->name, name) && STREQ(rp->view, view)) { + pass_exists = true; + break; } - break; } - if (!rp) { + if (!pass_exists) { render_layer_add_pass(rr, rl, channels, name, view, chan_id, allocate); } } @@ -587,10 +576,9 @@ static int passtype_from_name(const char *name) /* callbacks for render_result_new_from_exr */ static void *ml_addlayer_cb(void *base, const char *str) { - RenderResult *rr = base; - RenderLayer *rl; + RenderResult *rr = static_cast<RenderResult *>(base); - rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); + RenderLayer *rl = MEM_cnew<RenderLayer>("new render layer"); BLI_addtail(&rr->layers, rl); BLI_strncpy(rl->name, str, EXR_LAY_MAXNAME); @@ -605,9 +593,9 @@ static void ml_addpass_cb(void *base, const char *chan_id, const char *view) { - RenderResult *rr = base; - RenderLayer *rl = lay; - RenderPass *rpass = MEM_callocN(sizeof(RenderPass), "loaded pass"); + RenderResult *rr = static_cast<RenderResult *>(base); + RenderLayer *rl = static_cast<RenderLayer *>(lay); + RenderPass *rpass = MEM_cnew<RenderPass>("loaded pass"); BLI_addtail(&rl->passes, rpass); rpass->channels = totchan; @@ -619,7 +607,7 @@ static void ml_addpass_cb(void *base, rpass->rect = rect; BLI_strncpy(rpass->name, name, EXR_PASS_MAXNAME); BLI_strncpy(rpass->view, view, sizeof(rpass->view)); - RE_render_result_full_channel_name(rpass->fullname, NULL, name, view, rpass->chan_id, -1); + RE_render_result_full_channel_name(rpass->fullname, nullptr, name, view, rpass->chan_id, -1); if (view[0] != '\0') { rpass->view_id = BLI_findstringindex(&rr->views, view, offsetof(RenderView, name)); @@ -631,10 +619,9 @@ static void ml_addpass_cb(void *base, static void *ml_addview_cb(void *base, const char *str) { - RenderResult *rr = base; - RenderView *rv; + RenderResult *rr = static_cast<RenderResult *>(base); - rv = MEM_callocN(sizeof(RenderView), "new render view"); + RenderView *rv = MEM_cnew<RenderView>("new render view"); BLI_strncpy(rv->name, str, EXR_VIEW_MAXNAME); /* For stereo drawing we need to ensure: @@ -645,9 +632,10 @@ static void *ml_addview_cb(void *base, const char *str) BLI_addhead(&rr->views, rv); } else if (STREQ(str, STEREO_RIGHT_NAME)) { - RenderView *left_rv = BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name)); + RenderView *left_rv = static_cast<RenderView *>( + BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name))); - if (left_rv == NULL) { + if (left_rv == nullptr) { BLI_addhead(&rr->views, rv); } else { @@ -719,9 +707,7 @@ static int order_render_passes(const void *a, const void *b) RenderResult *render_result_new_from_exr( void *exrhandle, const char *colorspace, bool predivide, int rectx, int recty) { - RenderResult *rr = MEM_callocN(sizeof(RenderResult), __func__); - RenderLayer *rl; - RenderPass *rpass; + RenderResult *rr = MEM_cnew<RenderResult>(__func__); const char *to_colorspace = IMB_colormanagement_role_colorspace_name_get( COLOR_ROLE_SCENE_LINEAR); @@ -730,13 +716,13 @@ RenderResult *render_result_new_from_exr( IMB_exr_multilayer_convert(exrhandle, rr, ml_addview_cb, ml_addlayer_cb, ml_addpass_cb); - for (rl = rr->layers.first; rl; rl = rl->next) { + LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { rl->rectx = rectx; rl->recty = recty; BLI_listbase_sort(&rl->passes, order_render_passes); - for (rpass = rl->passes.first; rpass; rpass = rpass->next) { + LISTBASE_FOREACH (RenderPass *, rpass, &rl->passes) { rpass->rectx = rectx; rpass->recty = recty; @@ -757,21 +743,19 @@ RenderResult *render_result_new_from_exr( void render_result_view_new(RenderResult *rr, const char *viewname) { - RenderView *rv = MEM_callocN(sizeof(RenderView), "new render view"); + RenderView *rv = MEM_cnew<RenderView>("new render view"); BLI_addtail(&rr->views, rv); BLI_strncpy(rv->name, viewname, sizeof(rv->name)); } void render_result_views_new(RenderResult *rr, const RenderData *rd) { - SceneRenderView *srv; - /* clear previously existing views - for sequencer */ render_result_views_free(rr); /* check renderdata for amount of views */ if (rd->scemode & R_MULTIVIEW) { - for (srv = rd->views.first; srv; srv = srv->next) { + LISTBASE_FOREACH (SceneRenderView *, srv, &rd->views) { if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) { continue; } @@ -812,17 +796,17 @@ static void do_merge_tile( void render_result_merge(RenderResult *rr, RenderResult *rrpart) { - RenderLayer *rl, *rlp; - RenderPass *rpass, *rpassp; + LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { + RenderLayer *rlp = RE_GetRenderLayer(rrpart, rl->name); - for (rl = rr->layers.first; rl; rl = rl->next) { - rlp = RE_GetRenderLayer(rrpart, rl->name); if (rlp) { /* Passes are allocated in sync. */ - for (rpass = rl->passes.first, rpassp = rlp->passes.first; rpass && rpassp; + for (RenderPass *rpass = static_cast<RenderPass *>(rl->passes.first), + *rpassp = static_cast<RenderPass *>(rlp->passes.first); + rpass && rpassp; rpass = rpass->next) { /* For save buffers, skip any passes that are only saved to disk. */ - if (rpass->rect == NULL || rpassp->rect == NULL) { + if (rpass->rect == nullptr || rpassp->rect == nullptr) { continue; } /* Render-result have all passes, render-part only the active view's passes. */ @@ -845,21 +829,16 @@ void render_result_single_layer_begin(Render *re) { /* all layers except the active one get temporally pushed away */ - /* officially pushed result should be NULL... error can happen with do_seq */ + /* officially pushed result should be nullptr... error can happen with do_seq */ RE_FreeRenderResult(re->pushedresult); re->pushedresult = re->result; - re->result = NULL; + re->result = nullptr; } void render_result_single_layer_end(Render *re) { - ViewLayer *view_layer; - RenderLayer *rlpush; - RenderLayer *rl; - int nr; - - if (re->result == NULL) { + if (re->result == nullptr) { printf("pop render result error; no current result!\n"); return; } @@ -871,37 +850,36 @@ void render_result_single_layer_end(Render *re) if (re->pushedresult->rectx == re->result->rectx && re->pushedresult->recty == re->result->recty) { /* find which layer in re->pushedresult should be replaced */ - rl = re->result->layers.first; + RenderLayer *rl = static_cast<RenderLayer *>(re->result->layers.first); /* render result should be empty after this */ BLI_remlink(&re->result->layers, rl); /* reconstruct render result layers */ - for (nr = 0, view_layer = re->view_layers.first; view_layer; - view_layer = view_layer->next, nr++) { + int nr = 0; + LISTBASE_FOREACH (ViewLayer *, view_layer, &re->view_layers) { if (nr == re->active_view_layer) { BLI_addtail(&re->result->layers, rl); } else { - rlpush = RE_GetRenderLayer(re->pushedresult, view_layer->name); + RenderLayer *rlpush = RE_GetRenderLayer(re->pushedresult, view_layer->name); if (rlpush) { BLI_remlink(&re->pushedresult->layers, rlpush); BLI_addtail(&re->result->layers, rlpush); } } + nr++; } } RE_FreeRenderResult(re->pushedresult); - re->pushedresult = NULL; + re->pushedresult = nullptr; } int render_result_exr_file_read_path(RenderResult *rr, RenderLayer *rl_single, const char *filepath) { - RenderLayer *rl; - RenderPass *rpass; void *exrhandle = IMB_exr_get_handle(); int rectx, recty; @@ -911,37 +889,37 @@ int render_result_exr_file_read_path(RenderResult *rr, return 0; } - if (rr == NULL || rectx != rr->rectx || recty != rr->recty) { + if (rr == nullptr || rectx != rr->rectx || recty != rr->recty) { if (rr) { printf("error in reading render result: dimensions don't match\n"); } else { - printf("error in reading render result: NULL result pointer\n"); + printf("error in reading render result: nullptr result pointer\n"); } IMB_exr_close(exrhandle); return 0; } - for (rl = rr->layers.first; rl; rl = rl->next) { + LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { if (rl_single && rl_single != rl) { continue; } /* passes are allocated in sync */ - for (rpass = rl->passes.first; rpass; rpass = rpass->next) { + LISTBASE_FOREACH (RenderPass *, rpass, &rl->passes) { const int xstride = rpass->channels; int a; char fullname[EXR_PASS_MAXNAME]; for (a = 0; a < xstride; a++) { RE_render_result_full_channel_name( - fullname, NULL, rpass->name, rpass->view, rpass->chan_id, a); + fullname, nullptr, rpass->name, rpass->view, rpass->chan_id, a); IMB_exr_set_channel( exrhandle, rl->name, fullname, xstride, xstride * rectx, rpass->rect + a); } RE_render_result_full_channel_name( - rpass->fullname, NULL, rpass->name, rpass->view, rpass->chan_id, -1); + rpass->fullname, nullptr, rpass->name, rpass->view, rpass->chan_id, -1); } } @@ -995,7 +973,7 @@ void render_result_exr_file_cache_write(Render *re) render_result_exr_file_cache_path(re->scene, root, str); printf("Caching exr file, %dx%d, %s\n", rr->rectx, rr->recty, str); - BKE_image_render_write_exr(NULL, rr, str, NULL, true, NULL, -1); + BKE_image_render_write_exr(nullptr, rr, str, nullptr, true, nullptr, -1); } bool render_result_exr_file_cache_read(Render *re) @@ -1055,7 +1033,7 @@ ImBuf *RE_render_result_rect_to_ibuf(RenderResult *rr, (R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_24 | R_IMF_CHAN_DEPTH_32)) { if (imf->depth == R_IMF_CHAN_DEPTH_8) { /* Higher depth bits are supported but not needed for current file output. */ - ibuf->rect_float = NULL; + ibuf->rect_float = nullptr; } else { IMB_float_from_rect(ibuf); @@ -1063,7 +1041,7 @@ ImBuf *RE_render_result_rect_to_ibuf(RenderResult *rr, } else { /* ensure no float buffer remained from previous frame */ - ibuf->rect_float = NULL; + ibuf->rect_float = nullptr; } } @@ -1087,7 +1065,7 @@ void RE_render_result_rect_from_ibuf(RenderResult *rr, const ImBuf *ibuf, const rr->have_combined = true; if (!rv->rectf) { - rv->rectf = MEM_mallocN(sizeof(float[4]) * rr->rectx * rr->recty, "render_seq rectf"); + rv->rectf = MEM_cnew_array<float>(4 * rr->rectx * rr->recty, "render_seq rectf"); } memcpy(rv->rectf, ibuf->rect_float, sizeof(float[4]) * rr->rectx * rr->recty); @@ -1100,10 +1078,10 @@ void RE_render_result_rect_from_ibuf(RenderResult *rr, const ImBuf *ibuf, const rr->have_combined = true; if (!rv->rect32) { - rv->rect32 = MEM_mallocN(sizeof(int) * rr->rectx * rr->recty, "render_seq rect"); + rv->rect32 = MEM_cnew_array<int>(rr->rectx * rr->recty, "render_seq rect"); } - memcpy(rv->rect32, ibuf->rect, 4 * rr->rectx * rr->recty); + memcpy(rv->rect32, ibuf->rect, sizeof(int) * rr->rectx * rr->recty); /* Same things as above, old rectf can hang around from previous render. */ MEM_SAFE_FREE(rv->rectf); @@ -1121,7 +1099,7 @@ void render_result_rect_fill_zero(RenderResult *rr, const int view_id) memset(rv->rect32, 0, 4 * rr->rectx * rr->recty); } else { - rv->rect32 = MEM_callocN(sizeof(int) * rr->rectx * rr->recty, "render_seq rect"); + rv->rect32 = MEM_cnew_array<int>(rr->rectx * rr->recty, "render_seq rect"); } } @@ -1158,12 +1136,12 @@ void render_result_rect_get_pixels(RenderResult *rr, bool RE_HasCombinedLayer(const RenderResult *rr) { - if (rr == NULL) { + if (rr == nullptr) { return false; } - const RenderView *rv = rr->views.first; - if (rv == NULL) { + const RenderView *rv = static_cast<RenderView *>(rr->views.first); + if (rv == nullptr) { return false; } @@ -1172,7 +1150,7 @@ bool RE_HasCombinedLayer(const RenderResult *rr) bool RE_HasFloatPixels(const RenderResult *rr) { - for (const RenderView *rview = rr->views.first; rview; rview = rview->next) { + LISTBASE_FOREACH (const RenderView *, rview, &rr->views) { if (rview->rect32 && !rview->rectf) { return false; } @@ -1196,37 +1174,36 @@ bool RE_RenderResult_is_stereo(const RenderResult *rr) RenderView *RE_RenderViewGetById(RenderResult *rr, const int view_id) { - RenderView *rv = BLI_findlink(&rr->views, view_id); + RenderView *rv = static_cast<RenderView *>(BLI_findlink(&rr->views, view_id)); BLI_assert(rr->views.first); - return rv ? rv : rr->views.first; + return rv ? rv : static_cast<RenderView *>(rr->views.first); } RenderView *RE_RenderViewGetByName(RenderResult *rr, const char *viewname) { - RenderView *rv = BLI_findstring(&rr->views, viewname, offsetof(RenderView, name)); + RenderView *rv = static_cast<RenderView *>( + BLI_findstring(&rr->views, viewname, offsetof(RenderView, name))); BLI_assert(rr->views.first); - return rv ? rv : rr->views.first; + return rv ? rv : static_cast<RenderView *>(rr->views.first); } static RenderPass *duplicate_render_pass(RenderPass *rpass) { - RenderPass *new_rpass = MEM_mallocN(sizeof(RenderPass), "new render pass"); - *new_rpass = *rpass; - new_rpass->next = new_rpass->prev = NULL; - if (new_rpass->rect != NULL) { - new_rpass->rect = MEM_dupallocN(new_rpass->rect); + RenderPass *new_rpass = MEM_cnew("new render pass", *rpass); + new_rpass->next = new_rpass->prev = nullptr; + if (new_rpass->rect != nullptr) { + new_rpass->rect = static_cast<float *>(MEM_dupallocN(new_rpass->rect)); } return new_rpass; } static RenderLayer *duplicate_render_layer(RenderLayer *rl) { - RenderLayer *new_rl = MEM_mallocN(sizeof(RenderLayer), "new render layer"); - *new_rl = *rl; - new_rl->next = new_rl->prev = NULL; - new_rl->passes.first = new_rl->passes.last = NULL; - new_rl->exrhandle = NULL; - for (RenderPass *rpass = rl->passes.first; rpass != NULL; rpass = rpass->next) { + RenderLayer *new_rl = MEM_cnew("new render layer", *rl); + new_rl->next = new_rl->prev = nullptr; + new_rl->passes.first = new_rl->passes.last = nullptr; + new_rl->exrhandle = nullptr; + LISTBASE_FOREACH (RenderPass *, rpass, &rl->passes) { RenderPass *new_rpass = duplicate_render_pass(rpass); BLI_addtail(&new_rl->passes, new_rpass); } @@ -1235,43 +1212,41 @@ static RenderLayer *duplicate_render_layer(RenderLayer *rl) static RenderView *duplicate_render_view(RenderView *rview) { - RenderView *new_rview = MEM_mallocN(sizeof(RenderView), "new render view"); - *new_rview = *rview; - if (new_rview->rectf != NULL) { - new_rview->rectf = MEM_dupallocN(new_rview->rectf); + RenderView *new_rview = MEM_cnew("new render view", *rview); + if (new_rview->rectf != nullptr) { + new_rview->rectf = static_cast<float *>(MEM_dupallocN(new_rview->rectf)); } - if (new_rview->rectz != NULL) { - new_rview->rectz = MEM_dupallocN(new_rview->rectz); + if (new_rview->rectz != nullptr) { + new_rview->rectz = static_cast<float *>(MEM_dupallocN(new_rview->rectz)); } - if (new_rview->rect32 != NULL) { - new_rview->rect32 = MEM_dupallocN(new_rview->rect32); + if (new_rview->rect32 != nullptr) { + new_rview->rect32 = static_cast<int *>(MEM_dupallocN(new_rview->rect32)); } return new_rview; } RenderResult *RE_DuplicateRenderResult(RenderResult *rr) { - RenderResult *new_rr = MEM_mallocN(sizeof(RenderResult), "new duplicated render result"); - *new_rr = *rr; - new_rr->next = new_rr->prev = NULL; - new_rr->layers.first = new_rr->layers.last = NULL; - new_rr->views.first = new_rr->views.last = NULL; - for (RenderLayer *rl = rr->layers.first; rl != NULL; rl = rl->next) { + RenderResult *new_rr = MEM_cnew("new duplicated render result", *rr); + new_rr->next = new_rr->prev = nullptr; + new_rr->layers.first = new_rr->layers.last = nullptr; + new_rr->views.first = new_rr->views.last = nullptr; + LISTBASE_FOREACH (RenderLayer *, rl, &rr->layers) { RenderLayer *new_rl = duplicate_render_layer(rl); BLI_addtail(&new_rr->layers, new_rl); } - for (RenderView *rview = rr->views.first; rview != NULL; rview = rview->next) { + LISTBASE_FOREACH (RenderView *, rview, &rr->views) { RenderView *new_rview = duplicate_render_view(rview); BLI_addtail(&new_rr->views, new_rview); } - if (new_rr->rect32 != NULL) { - new_rr->rect32 = MEM_dupallocN(new_rr->rect32); + if (new_rr->rectf != nullptr) { + new_rr->rectf = static_cast<float *>(MEM_dupallocN(new_rr->rectf)); } - if (new_rr->rectf != NULL) { - new_rr->rectf = MEM_dupallocN(new_rr->rectf); + if (new_rr->rectz != nullptr) { + new_rr->rectz = static_cast<float *>(MEM_dupallocN(new_rr->rectz)); } - if (new_rr->rectz != NULL) { - new_rr->rectz = MEM_dupallocN(new_rr->rectz); + if (new_rr->rect32 != nullptr) { + new_rr->rect32 = static_cast<int *>(MEM_dupallocN(new_rr->rect32)); } new_rr->stamp_data = BKE_stamp_data_copy(new_rr->stamp_data); return new_rr; diff --git a/source/blender/render/intern/render_result.h b/source/blender/render/intern/render_result.h index c84e0a04018..2e76efba8a3 100644 --- a/source/blender/render/intern/render_result.h +++ b/source/blender/render/intern/render_result.h @@ -136,7 +136,8 @@ void render_result_views_shallowdelete(struct RenderResult *rr); { \ int nr_; \ ViewLayer *iter_; \ - for (nr_ = 0, iter_ = (re_)->view_layers.first; iter_ != NULL; iter_ = iter_->next, nr_++) { \ + for (nr_ = 0, iter_ = static_cast<ViewLayer *>((re_)->view_layers.first); iter_ != NULL; \ + iter_ = iter_->next, nr_++) { \ if (!G.background && (re_)->r.scemode & R_SINGLE_LAYER) { \ if (nr_ != re->active_view_layer) { \ continue; \ diff --git a/source/blender/render/intern/render_types.h b/source/blender/render/intern/render_types.h index 58a15e3f013..d1ffa1ba705 100644 --- a/source/blender/render/intern/render_types.h +++ b/source/blender/render/intern/render_types.h @@ -11,16 +11,12 @@ /* exposed internal in render module only! */ /* ------------------------------------------------------------------------- */ -#include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BLI_threads.h" -#include "BKE_main.h" - #include "RE_pipeline.h" -struct GHash; struct GSet; struct Main; struct Object; diff --git a/source/blender/render/intern/texture_image.c b/source/blender/render/intern/texture_image.c index 3c12742f52c..38a569877c0 100644 --- a/source/blender/render/intern/texture_image.c +++ b/source/blender/render/intern/texture_image.c @@ -32,7 +32,6 @@ #include "RE_texture.h" -#include "render_types.h" #include "texture_common.h" static void boxsample(ImBuf *ibuf, diff --git a/source/blender/render/intern/texture_pointdensity.c b/source/blender/render/intern/texture_pointdensity.c index 6e0bae700dc..af49c301302 100644 --- a/source/blender/render/intern/texture_pointdensity.c +++ b/source/blender/render/intern/texture_pointdensity.c @@ -24,6 +24,7 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_particle_types.h" +#include "DNA_scene_types.h" #include "DNA_texture_types.h" #include "BKE_colorband.h" @@ -39,7 +40,6 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" -#include "render_types.h" #include "texture_common.h" #include "RE_texture.h" diff --git a/source/blender/render/intern/texture_procedural.c b/source/blender/render/intern/texture_procedural.c index 37605236738..13207543fd7 100644 --- a/source/blender/render/intern/texture_procedural.c +++ b/source/blender/render/intern/texture_procedural.c @@ -38,7 +38,6 @@ #include "MEM_guardedalloc.h" -#include "render_types.h" #include "texture_common.h" #include "RE_texture.h" |