int RE_engine_render(Render *re, int do_all) { RenderEngineType *type= RE_engines_find(re->r.engine); RenderEngine *engine; /* verify if we can render */ if (!type->render) return 0; if ((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW)) return 0; if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) { if (re->result) render_result_free(re->result); re->result= render_result_new(re, &re->disprect, 0, 0); } BLI_rw_mutex_unlock(&re->resultmutex); if (re->result==NULL) return 1; /* set render info */ re->i.cfra= re->scene->r.cfra; BLI_strncpy(re->i.scenename, re->scene->id.name+2, sizeof(re->i.scenename)); re->i.totface=re->i.totvert=re->i.totstrand=re->i.totlamp=re->i.tothalo= 0; /* render */ engine = RE_engine_create(type); engine->re= re; if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; if (re->r.scemode & R_PREVIEWBUTS) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) scene_update_for_newframe(re->main, re->scene, re->lay); if (type->update) type->update(engine, re->main, re->scene); if (type->render) type->render(engine, re->scene); render_result_free_list(&engine->fullresult, engine->fullresult.first); RE_engine_free(engine); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.afbreek = 1; return 1; }
int RE_engine_render(Render *re, int do_all) { RenderEngineType *type = RE_engines_find(re->r.engine); RenderEngine *engine; bool persistent_data = (re->r.mode & R_PERSISTENT_DATA) != 0; /* verify if we can render */ if (!type->render) return 0; if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW)) return 0; if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* Lock drawing in UI during data phase. */ if (re->draw_lock) { re->draw_lock(re->dlh, 1); } /* update animation here so any render layer animation is applied before * creating the render result */ if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_BUTS_PREVIEW)) == 0) { unsigned int lay = re->lay; /* don't update layers excluded on all render layers */ if (type->flag & RE_USE_EXCLUDE_LAYERS) { SceneRenderLayer *srl; unsigned int non_excluded_lay = 0; if (re->r.scemode & R_SINGLE_LAYER) { srl = BLI_findlink(&re->r.layers, re->r.actlay); if (srl) { non_excluded_lay |= ~srl->lay_exclude; /* in this case we must update all because animation for * the scene has not been updated yet, and so may not be * up to date until after BKE_scene_update_for_newframe */ if (render_layer_exclude_animated(re->scene, srl)) non_excluded_lay |= ~0; } } else { for (srl = re->r.layers.first; srl; srl = srl->next) { if (!(srl->layflag & SCE_LAY_DISABLE)) { non_excluded_lay |= ~srl->lay_exclude; if (render_layer_exclude_animated(re->scene, srl)) non_excluded_lay |= ~0; } } } lay &= non_excluded_lay; } BKE_scene_update_for_newframe_ex(re->eval_ctx, re->main, re->scene, lay, true); render_update_anim_renderdata(re, &re->scene->r); } /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result == NULL || !(re->r.scemode & R_BUTS_PREVIEW)) { int savebuffers = RR_USE_MEM; if (re->result) render_result_free(re->result); if ((type->flag & RE_USE_SAVE_BUFFERS) && (re->r.scemode & R_EXR_TILE_FILE)) savebuffers = RR_USE_EXR; re->result = render_result_new(re, &re->disprect, 0, savebuffers, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); if (re->result == NULL) { /* Clear UI drawing locks. */ if (re->draw_lock) { re->draw_lock(re->dlh, 0); } return 1; } /* set render info */ re->i.cfra = re->scene->r.cfra; BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name)); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ engine = re->engine; if (!engine) { engine = RE_engine_create(type); re->engine = engine; } engine->flag |= RE_ENGINE_RENDERING; /* TODO: actually link to a parent which shouldn't happen */ engine->re = re; if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; if (re->r.scemode & R_BUTS_PREVIEW) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; engine->layer_override = re->layer_override; engine->resolution_x = re->winx; engine->resolution_y = re->winy; RE_parts_init(re, false); engine->tile_x = re->partx; engine->tile_y = re->party; if (re->result->do_exr_tile) render_result_exr_file_begin(re); if (type->update) type->update(engine, re->main, re->scene); /* Clear UI drawing locks. */ if (re->draw_lock) { re->draw_lock(re->dlh, 0); } if (type->render) type->render(engine, re->scene); engine->tile_x = 0; engine->tile_y = 0; engine->flag &= ~RE_ENGINE_RENDERING; render_result_free_list(&engine->fullresult, engine->fullresult.first); BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_WRITE); /* re->engine becomes zero if user changed active render engine during render */ if (!persistent_data || !re->engine) { RE_engine_free(engine); re->engine = NULL; } if (re->result->do_exr_tile) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); } if (re->r.scemode & R_EXR_CACHE_FILE) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_cache_write(re); BLI_rw_mutex_unlock(&re->resultmutex); } RE_parts_free(re); BLI_rw_mutex_unlock(&re->partsmutex); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = true; #ifdef WITH_FREESTYLE if (re->r.mode & R_EDGE_FRS) RE_RenderFreestyleExternal(re); #endif return 1; }
bool RE_bake_engine( Render *re, Object *object, const BakePixel pixel_array[], const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]) { RenderEngineType *type = RE_engines_find(re->r.engine); RenderEngine *engine; bool persistent_data = (re->r.mode & R_PERSISTENT_DATA) != 0; /* set render info */ re->i.cfra = re->scene->r.cfra; BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name) - 2); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ engine = re->engine; if (!engine) { engine = RE_engine_create(type); re->engine = engine; } engine->flag |= RE_ENGINE_RENDERING; /* TODO: actually link to a parent which shouldn't happen */ engine->re = re; engine->resolution_x = re->winx; engine->resolution_y = re->winy; RE_parts_init(re, false); engine->tile_x = re->r.tilex; engine->tile_y = re->r.tiley; /* update is only called so we create the engine.session */ if (type->update) type->update(engine, re->main, re->scene); if (type->bake) type->bake(engine, re->scene, object, pass_type, pixel_array, num_pixels, depth, result); engine->tile_x = 0; engine->tile_y = 0; engine->flag &= ~RE_ENGINE_RENDERING; BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_WRITE); /* re->engine becomes zero if user changed active render engine during render */ if (!persistent_data || !re->engine) { RE_engine_free(engine); re->engine = NULL; } RE_parts_free(re); BLI_rw_mutex_unlock(&re->partsmutex); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = true; return true; }
int RE_engine_render(Render *re, int do_all) { RenderEngineType *type = RE_engines_find(re->r.engine); RenderEngine *engine; int persistent_data = re->r.mode & R_PERSISTENT_DATA; /* verify if we can render */ if (!type->render) return 0; if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW)) return 0; if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* update animation here so any render layer animation is applied before * creating the render result */ if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_BUTS_PREVIEW)) == 0) { unsigned int lay = re->lay; /* don't update layers excluded on all render layers */ if (type->flag & RE_USE_EXCLUDE_LAYERS) { SceneRenderLayer *srl; unsigned int non_excluded_lay = 0; if (re->r.scemode & R_SINGLE_LAYER) { srl = BLI_findlink(&re->r.layers, re->r.actlay); if (srl) non_excluded_lay |= ~srl->lay_exclude; } else { for (srl = re->r.layers.first; srl; srl = srl->next) if (!(srl->layflag & SCE_LAY_DISABLE)) non_excluded_lay |= ~srl->lay_exclude; } lay &= non_excluded_lay; } BKE_scene_update_for_newframe(re->main, re->scene, lay); } /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result == NULL || !(re->r.scemode & R_BUTS_PREVIEW)) { int savebuffers = RR_USE_MEM; if (re->result) render_result_free(re->result); if ((type->flag & RE_USE_SAVE_BUFFERS) && (re->r.scemode & R_EXR_TILE_FILE)) savebuffers = RR_USE_EXR; re->result = render_result_new(re, &re->disprect, 0, savebuffers, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); if (re->result == NULL) return 1; /* set render info */ re->i.cfra = re->scene->r.cfra; BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name)); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ engine = re->engine; if (!engine) { engine = RE_engine_create(type); re->engine = engine; } engine->flag |= RE_ENGINE_RENDERING; /* TODO: actually link to a parent which shouldn't happen */ engine->re = re; if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; if (re->r.scemode & R_BUTS_PREVIEW) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; engine->resolution_x = re->winx; engine->resolution_y = re->winy; RE_parts_init(re, FALSE); engine->tile_x = re->partx; engine->tile_y = re->party; if (re->result->do_exr_tile) render_result_exr_file_begin(re); if (type->update) type->update(engine, re->main, re->scene); if (type->render) type->render(engine, re->scene); engine->tile_x = 0; engine->tile_y = 0; engine->flag &= ~RE_ENGINE_RENDERING; render_result_free_list(&engine->fullresult, engine->fullresult.first); /* re->engine becomes zero if user changed active render engine during render */ if (!persistent_data || !re->engine) { RE_engine_free(engine); re->engine = NULL; } if (re->result->do_exr_tile) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); } RE_parts_free(re); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = TRUE; return 1; }