void ED_render_scene_update(Main *bmain, Scene *scene, int updated) { /* viewport rendering update on data changes, happens after depsgraph * updates if there was any change. context is set to the 3d view */ bContext *C; bScreen *sc; ScrArea *sa; ARegion *ar; /* don't do this render engine update if we're updating the scene from * other threads doing e.g. rendering or baking jobs */ if (!BLI_thread_is_main()) return; C = CTX_create(); CTX_data_main_set(C, bmain); CTX_data_scene_set(C, scene); CTX_wm_manager_set(C, bmain->wm.first); for (sc = bmain->screen.first; sc; sc = sc->id.next) { for (sa = sc->areabase.first; sa; sa = sa->next) { if (sa->spacetype != SPACE_VIEW3D) continue; for (ar = sa->regionbase.first; ar; ar = ar->next) { RegionView3D *rv3d; RenderEngine *engine; if (ar->regiontype != RGN_TYPE_WINDOW) continue; rv3d = ar->regiondata; engine = rv3d->render_engine; if (engine && (updated || (engine->flag & RE_ENGINE_DO_UPDATE))) { CTX_wm_screen_set(C, sc); CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); engine->flag &= ~RE_ENGINE_DO_UPDATE; engine->type->view_update(engine, C); } } } } CTX_free(C); }
static int load_file(int UNUSED(argc), const char **argv, void *data) { bContext *C = data; /* Make the path absolute because its needed for relative linked blends to be found */ char filename[FILE_MAX]; /* note, we could skip these, but so far we always tried to load these files */ if (argv[0][0] == '-') { fprintf(stderr, "unknown argument, loading as file: %s\n", argv[0]); } BLI_strncpy(filename, argv[0], sizeof(filename)); BLI_path_cwd(filename); if (G.background) { int retval = BKE_read_file(C, filename, NULL); /* we successfully loaded a blend file, get sure that * pointcache works */ if (retval != BKE_READ_FILE_FAIL) { wmWindowManager *wm = CTX_wm_manager(C); /* special case, 2.4x files */ if (wm == NULL && CTX_data_main(C)->wm.first == NULL) { extern void wm_add_default(bContext *C); /* wm_add_default() needs the screen to be set. */ CTX_wm_screen_set(C, CTX_data_main(C)->screen.first); wm_add_default(C); } CTX_wm_manager_set(C, NULL); /* remove wm to force check */ WM_check(C); G.relbase_valid = 1; if (CTX_wm_manager(C) == NULL) CTX_wm_manager_set(C, wm); /* reset wm */ DAG_on_visible_update(CTX_data_main(C), TRUE); } else { /* failed to load file, stop processing arguments */ return -1; } /* WM_file_read() runs normally but since we're in background mode do here */ #ifdef WITH_PYTHON /* run any texts that were loaded in and flagged as modules */ BPY_python_reset(C); #endif /* happens for the UI on file reading too (huh? (ton))*/ // XXX BKE_reset_undo(); // BKE_write_undo("original"); /* save current state */ } else { /* we are not running in background mode here, but start blender in UI mode with * a file - this should do everything a 'load file' does */ ReportList reports; BKE_reports_init(&reports, RPT_PRINT); WM_file_autoexec_init(filename); WM_file_read(C, filename, &reports); BKE_reports_clear(&reports); } G.file_loaded = 1; return 0; }
static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath) { bScreen *curscreen = NULL; Scene *curscene = NULL; int recover; enum { LOAD_UI = 1, LOAD_UI_OFF, LOAD_UNDO, } mode; if (BLI_listbase_is_empty(&bfd->main->screen)) { mode = LOAD_UNDO; } else if (G.fileflags & G_FILE_NO_UI) { mode = LOAD_UI_OFF; } else { mode = LOAD_UI; } recover = (G.fileflags & G_FILE_RECOVER); /* Free all render results, without this stale data gets displayed after loading files */ if (mode != LOAD_UNDO) { RE_FreeAllRenderResults(); } /* Only make filepaths compatible when loading for real (not undo) */ if (mode != LOAD_UNDO) { clean_paths(bfd->main); } /* XXX here the complex windowmanager matching */ /* no load screens? */ if (mode != LOAD_UI) { /* Logic for 'track_undo_scene' is to keep using the scene which the active screen has, * as long as the scene associated with the undo operation is visible in one of the open windows. * * - 'curscreen->scene' - scene the user is currently looking at. * - 'bfd->curscene' - scene undo-step was created in. * * This means users can have 2+ windows open and undo in both without screens switching. * But if they close one of the screens, * undo will ensure that the scene being operated on will be activated * (otherwise we'd be undoing on an off-screen scene which isn't acceptable). * see: T43424 */ bool track_undo_scene; /* comes from readfile.c */ SWAP(ListBase, G.main->wm, bfd->main->wm); SWAP(ListBase, G.main->screen, bfd->main->screen); SWAP(ListBase, G.main->script, bfd->main->script); /* we re-use current screen */ curscreen = CTX_wm_screen(C); /* but use new Scene pointer */ curscene = bfd->curscene; track_undo_scene = (mode == LOAD_UNDO && curscreen && bfd->main->wm.first); if (curscene == NULL) curscene = bfd->main->scene.first; /* empty file, we add a scene to make Blender work */ if (curscene == NULL) curscene = BKE_scene_add(bfd->main, "Empty"); if (track_undo_scene) { /* keep the old (free'd) scene, let 'blo_lib_link_screen_restore' * replace it with 'curscene' if its needed */ } else { /* and we enforce curscene to be in current screen */ if (curscreen) { /* can run in bgmode */ curscreen->scene = curscene; } } /* clear_global will free G.main, here we can still restore pointers */ blo_lib_link_screen_restore(bfd->main, curscreen, curscene); curscene = curscreen->scene; if (track_undo_scene) { wmWindowManager *wm = bfd->main->wm.first; if (wm_scene_is_visible(wm, bfd->curscene) == false) { curscene = bfd->curscene; curscreen->scene = curscene; } } } /* free G.main Main database */ // CTX_wm_manager_set(C, NULL); clear_global(); /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); G.main = bfd->main; CTX_data_main_set(C, G.main); sound_init_main(G.main); if (bfd->user) { /* only here free userdef themes... */ BKE_userdef_free(); U = *bfd->user; /* Security issue: any blend file could include a USER block. * * Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE, * to load the preferences defined in the users home dir. * * This means we will never accidentally (or maliciously) * enable scripts auto-execution by loading a '.blend' file. */ U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE; MEM_freeN(bfd->user); } /* case G_FILE_NO_UI or no screens in file */ if (mode != LOAD_UI) { /* leave entire context further unaltered? */ CTX_data_scene_set(C, curscene); } else { G.fileflags = bfd->fileflags; CTX_wm_manager_set(C, G.main->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscene); CTX_wm_area_set(C, NULL); CTX_wm_region_set(C, NULL); CTX_wm_menu_set(C, NULL); curscene = bfd->curscene; } /* this can happen when active scene was lib-linked, and doesn't exist anymore */ if (CTX_data_scene(C) == NULL) { /* in case we don't even have a local scene, add one */ if (!G.main->scene.first) BKE_scene_add(G.main, "Scene"); CTX_data_scene_set(C, G.main->scene.first); CTX_wm_screen(C)->scene = CTX_data_scene(C); curscene = CTX_data_scene(C); } BLI_assert(curscene == CTX_data_scene(C)); /* special cases, override loaded flags: */ if (G.f != bfd->globalf) { const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF); bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep); } G.f = bfd->globalf; #ifdef WITH_PYTHON /* let python know about new main */ BPY_context_update(C); #endif if (!G.background) { //setscreen(G.curscreen); } /* FIXME: this version patching should really be part of the file-reading code, * but we still get too many unrelated data-corruption crashes otherwise... */ if (G.main->versionfile < 250) do_versions_ipos_to_animato(G.main); G.main->recovered = 0; /* startup.blend or recovered startup */ if (bfd->filename[0] == 0) { G.main->name[0] = 0; } else if (recover && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ filepath = bfd->filename; G.main->recovered = 1; /* these are the same at times, should never copy to the same location */ if (G.main->name != filepath) BLI_strncpy(G.main->name, filepath, FILE_MAX); } /* baseflags, groups, make depsgraph, etc */ /* first handle case if other windows have different scenes visible */ if (mode == LOAD_UI) { wmWindowManager *wm = G.main->wm.first; if (wm) { wmWindow *win; for (win = wm->windows.first; win; win = win->next) { if (win->screen && win->screen->scene) /* zealous check... */ if (win->screen->scene != curscene) BKE_scene_set_background(G.main, win->screen->scene); } } } BKE_scene_set_background(G.main, curscene); if (mode != LOAD_UNDO) { IMB_colormanagement_check_file_config(G.main); } MEM_freeN(bfd); }
void ED_render_scene_update(Main *bmain, Scene *scene, int updated) { /* viewport rendering update on data changes, happens after depsgraph * updates if there was any change. context is set to the 3d view */ bContext *C; wmWindowManager *wm; wmWindow *win; static bool recursive_check = false; /* don't do this render engine update if we're updating the scene from * other threads doing e.g. rendering or baking jobs */ if (!BLI_thread_is_main()) return; /* don't call this recursively for frame updates */ if (recursive_check) return; /* Do not call if no WM available, see T42688. */ if (BLI_listbase_is_empty(&bmain->wm)) return; recursive_check = true; C = CTX_create(); CTX_data_main_set(C, bmain); CTX_data_scene_set(C, scene); CTX_wm_manager_set(C, bmain->wm.first); wm = bmain->wm.first; for (win = wm->windows.first; win; win = win->next) { bScreen *sc = win->screen; ScrArea *sa; ARegion *ar; CTX_wm_window_set(C, win); for (sa = sc->areabase.first; sa; sa = sa->next) { if (sa->spacetype != SPACE_VIEW3D) continue; for (ar = sa->regionbase.first; ar; ar = ar->next) { RegionView3D *rv3d; RenderEngine *engine; if (ar->regiontype != RGN_TYPE_WINDOW) continue; rv3d = ar->regiondata; engine = rv3d->render_engine; /* call update if the scene changed, or if the render engine * tagged itself for update (e.g. because it was busy at the * time of the last update) */ if (engine && (updated || (engine->flag & RE_ENGINE_DO_UPDATE))) { CTX_wm_screen_set(C, sc); CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); engine->flag &= ~RE_ENGINE_DO_UPDATE; engine->type->view_update(engine, C); } } } } CTX_free(C); recursive_check = false; }
static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath) { bScreen *curscreen = NULL; Scene *curscene = NULL; int recover; char mode; /* 'u' = undo save, 'n' = no UI load */ if (bfd->main->screen.first == NULL) mode = 'u'; else if (G.fileflags & G_FILE_NO_UI) mode = 'n'; else mode = 0; recover = (G.fileflags & G_FILE_RECOVER); /* Free all render results, without this stale data gets displayed after loading files */ if (mode != 'u') { RE_FreeAllRenderResults(); } /* Only make filepaths compatible when loading for real (not undo) */ if (mode != 'u') { clean_paths(bfd->main); } /* XXX here the complex windowmanager matching */ /* no load screens? */ if (mode) { /* comes from readfile.c */ SWAP(ListBase, G.main->wm, bfd->main->wm); SWAP(ListBase, G.main->screen, bfd->main->screen); SWAP(ListBase, G.main->script, bfd->main->script); /* we re-use current screen */ curscreen = CTX_wm_screen(C); /* but use new Scene pointer */ curscene = bfd->curscene; if (curscene == NULL) curscene = bfd->main->scene.first; /* empty file, we add a scene to make Blender work */ if (curscene == NULL) curscene = BKE_scene_add(bfd->main, "Empty"); /* and we enforce curscene to be in current screen */ if (curscreen) curscreen->scene = curscene; /* can run in bgmode */ /* clear_global will free G.main, here we can still restore pointers */ blo_lib_link_screen_restore(bfd->main, curscreen, curscene); } /* free G.main Main database */ // CTX_wm_manager_set(C, NULL); clear_global(); /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); G.main = bfd->main; CTX_data_main_set(C, G.main); sound_init_main(G.main); if (bfd->user) { /* only here free userdef themes... */ BKE_userdef_free(); U = *bfd->user; MEM_freeN(bfd->user); } /* case G_FILE_NO_UI or no screens in file */ if (mode) { /* leave entire context further unaltered? */ CTX_data_scene_set(C, curscene); } else { G.winpos = bfd->winpos; G.displaymode = bfd->displaymode; G.fileflags = bfd->fileflags; CTX_wm_manager_set(C, G.main->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscene); CTX_wm_area_set(C, NULL); CTX_wm_region_set(C, NULL); CTX_wm_menu_set(C, NULL); } /* this can happen when active scene was lib-linked, and doesn't exist anymore */ if (CTX_data_scene(C) == NULL) { /* in case we don't even have a local scene, add one */ if (!G.main->scene.first) BKE_scene_add(G.main, "Scene"); CTX_data_scene_set(C, G.main->scene.first); CTX_wm_screen(C)->scene = CTX_data_scene(C); curscene = CTX_data_scene(C); } /* special cases, override loaded flags: */ if (G.f != bfd->globalf) { const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF); bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep); } G.f = bfd->globalf; #ifdef WITH_PYTHON /* let python know about new main */ BPY_context_update(C); #endif if (!G.background) { //setscreen(G.curscreen); } /* FIXME: this version patching should really be part of the file-reading code, * but we still get too many unrelated data-corruption crashes otherwise... */ if (G.main->versionfile < 250) do_versions_ipos_to_animato(G.main); G.main->recovered = 0; /* startup.blend or recovered startup */ if (bfd->filename[0] == 0) { G.main->name[0] = 0; } else if (recover && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ filepath = bfd->filename; G.main->recovered = 1; /* these are the same at times, should never copy to the same location */ if (G.main->name != filepath) BLI_strncpy(G.main->name, filepath, FILE_MAX); } /* baseflags, groups, make depsgraph, etc */ /* first handle case if other windows have different scenes visible */ if (mode == 0) { wmWindowManager *wm = G.main->wm.first; if (wm) { wmWindow *win; for (win = wm->windows.first; win; win = win->next) { if (win->screen && win->screen->scene) /* zealous check... */ if (win->screen->scene != CTX_data_scene(C)) BKE_scene_set_background(G.main, win->screen->scene); } } } BKE_scene_set_background(G.main, CTX_data_scene(C)); if (mode != 'u') { IMB_colormanagement_check_file_config(G.main); } MEM_freeN(bfd); }
static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath) { bScreen *curscreen= NULL; Scene *curscene= NULL; int recover; char mode; /* 'u' = undo save, 'n' = no UI load */ if(bfd->main->screen.first==NULL) mode= 'u'; else if(G.fileflags & G_FILE_NO_UI) mode= 'n'; else mode= 0; recover= (G.fileflags & G_FILE_RECOVER); /* Only make filepaths compatible when loading for real (not undo) */ if(mode != 'u') { clean_paths(bfd->main); } /* XXX here the complex windowmanager matching */ /* no load screens? */ if(mode) { /* comes from readfile.c */ extern void lib_link_screen_restore(Main *, bScreen *, Scene *); SWAP(ListBase, G.main->wm, bfd->main->wm); SWAP(ListBase, G.main->screen, bfd->main->screen); SWAP(ListBase, G.main->script, bfd->main->script); /* we re-use current screen */ curscreen= CTX_wm_screen(C); /* but use new Scene pointer */ curscene= bfd->curscene; if(curscene==NULL) curscene= bfd->main->scene.first; /* and we enforce curscene to be in current screen */ if(curscreen) curscreen->scene= curscene; /* can run in bgmode */ /* clear_global will free G.main, here we can still restore pointers */ lib_link_screen_restore(bfd->main, curscreen, curscene); } /* free G.main Main database */ // CTX_wm_manager_set(C, NULL); clear_global(); /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); G.main= bfd->main; CTX_data_main_set(C, G.main); sound_init_main(G.main); if (bfd->user) { /* only here free userdef themes... */ BKE_userdef_free(); U= *bfd->user; MEM_freeN(bfd->user); } /* case G_FILE_NO_UI or no screens in file */ if(mode) { /* leave entire context further unaltered? */ CTX_data_scene_set(C, curscene); } else { G.winpos= bfd->winpos; G.displaymode= bfd->displaymode; G.fileflags= bfd->fileflags; CTX_wm_manager_set(C, bfd->main->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscreen->scene); CTX_wm_area_set(C, NULL); CTX_wm_region_set(C, NULL); CTX_wm_menu_set(C, NULL); } /* this can happen when active scene was lib-linked, and doesnt exist anymore */ if(CTX_data_scene(C)==NULL) { CTX_data_scene_set(C, bfd->main->scene.first); CTX_wm_screen(C)->scene= CTX_data_scene(C); curscene= CTX_data_scene(C); } /* special cases, override loaded flags: */ if(G.f != bfd->globalf) { const int flags_keep= (G_DEBUG | G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF); bfd->globalf= (bfd->globalf & ~flags_keep) | (G.f & flags_keep); } G.f= bfd->globalf; if (!G.background) { //setscreen(G.curscreen); } // FIXME: this version patching should really be part of the file-reading code, // but we still get too many unrelated data-corruption crashes otherwise... if (G.main->versionfile < 250) do_versions_ipos_to_animato(G.main); if(recover && bfd->filename[0] && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ filepath= bfd->filename; } #if 0 else if (!G.relbase_valid) { /* otherwise, use an empty string as filename, rather than <memory2> */ filepath=""; } #endif /* these are the same at times, should never copy to the same location */ if(G.main->name != filepath) BLI_strncpy(G.main->name, filepath, FILE_MAX); /* baseflags, groups, make depsgraph, etc */ set_scene_bg(G.main, CTX_data_scene(C)); MEM_freeN(bfd); (void)curscene; /* quiet warning */ }