Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_preview.c
| Show First 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | typedef struct IconPreview { | ||||
| ID *id, *id_copy; | ID *id, *id_copy; | ||||
| ListBase sizes; | ListBase sizes; | ||||
| } IconPreview; | } IconPreview; | ||||
| /* *************************** Preview for buttons *********************** */ | /* *************************** Preview for buttons *********************** */ | ||||
| static Main *G_pr_main = NULL; | static Main *G_pr_main = NULL; | ||||
| static Main *G_pr_main_cycles = NULL; | static Main *G_pr_main_cycles = NULL; | ||||
| static Main *G_pr_main_grease_pencil = NULL; | |||||
| #ifndef WITH_HEADLESS | #ifndef WITH_HEADLESS | ||||
| static Main *load_main_from_memory(const void *blend, int blend_size) | static Main *load_main_from_memory(const void *blend, int blend_size) | ||||
| { | { | ||||
| const int fileflags = G.fileflags; | const int fileflags = G.fileflags; | ||||
| Main *bmain = NULL; | Main *bmain = NULL; | ||||
| BlendFileData *bfd; | BlendFileData *bfd; | ||||
| Show All 13 Lines | |||||
| void ED_preview_ensure_dbase(void) | void ED_preview_ensure_dbase(void) | ||||
| { | { | ||||
| #ifndef WITH_HEADLESS | #ifndef WITH_HEADLESS | ||||
| static bool base_initialized = false; | static bool base_initialized = false; | ||||
| BLI_assert(BLI_thread_is_main()); | BLI_assert(BLI_thread_is_main()); | ||||
| if (!base_initialized) { | if (!base_initialized) { | ||||
| G_pr_main = load_main_from_memory(datatoc_preview_blend, datatoc_preview_blend_size); | G_pr_main = load_main_from_memory(datatoc_preview_blend, datatoc_preview_blend_size); | ||||
| G_pr_main_cycles = load_main_from_memory(datatoc_preview_cycles_blend, datatoc_preview_cycles_blend_size); | G_pr_main_cycles = load_main_from_memory(datatoc_preview_cycles_blend, datatoc_preview_cycles_blend_size); | ||||
| G_pr_main_grease_pencil = load_main_from_memory(datatoc_preview_grease_pencil_blend, datatoc_preview_grease_pencil_blend_size); | |||||
| base_initialized = true; | base_initialized = true; | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| static bool check_engine_supports_textures(Scene *scene) | static bool check_engine_supports_textures(Scene *scene) | ||||
| { | { | ||||
| RenderEngineType *type = RE_engines_find(scene->r.engine); | RenderEngineType *type = RE_engines_find(scene->r.engine); | ||||
| return type->flag & RE_USE_TEXTURE_PREVIEW; | return type->flag & RE_USE_TEXTURE_PREVIEW; | ||||
| } | } | ||||
| void ED_preview_free_dbase(void) | void ED_preview_free_dbase(void) | ||||
| { | { | ||||
| if (G_pr_main) | if (G_pr_main) | ||||
| BKE_main_free(G_pr_main); | BKE_main_free(G_pr_main); | ||||
| if (G_pr_main_cycles) | if (G_pr_main_cycles) | ||||
| BKE_main_free(G_pr_main_cycles); | BKE_main_free(G_pr_main_cycles); | ||||
| if (G_pr_main_grease_pencil) | |||||
| BKE_main_free(G_pr_main_grease_pencil); | |||||
| } | } | ||||
| static Scene *preview_get_scene(Main *pr_main) | static Scene *preview_get_scene(Main *pr_main) | ||||
| { | { | ||||
| if (pr_main == NULL) return NULL; | if (pr_main == NULL) return NULL; | ||||
| return pr_main->scene.first; | return pr_main->scene.first; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 841 Lines • ▼ Show 20 Lines | for (cur_size = ip->sizes.first; cur_size; cur_size = cur_size->next) { | ||||
| sp->sizex = cur_size->sizex; | sp->sizex = cur_size->sizex; | ||||
| sp->sizey = cur_size->sizey; | sp->sizey = cur_size->sizey; | ||||
| sp->pr_method = is_render ? PR_ICON_RENDER : PR_ICON_DEFERRED; | sp->pr_method = is_render ? PR_ICON_RENDER : PR_ICON_DEFERRED; | ||||
| sp->pr_rect = cur_size->rect; | sp->pr_rect = cur_size->rect; | ||||
| sp->id = ip->id; | sp->id = ip->id; | ||||
| sp->id_copy = ip->id_copy; | sp->id_copy = ip->id_copy; | ||||
| sp->bmain = ip->bmain; | sp->bmain = ip->bmain; | ||||
| sp->own_id_copy = false; | sp->own_id_copy = false; | ||||
| Material *ma = NULL; | |||||
| if (is_render) { | if (is_render) { | ||||
| BLI_assert(ip->id); | BLI_assert(ip->id); | ||||
| /* texture icon rendering is hardcoded to use the BI scene, | /* texture icon rendering is hardcoded to use the BI scene, | ||||
| * so don't even think of using cycle's bmain for | * so don't even think of using cycle's bmain for | ||||
| * texture icons | * texture icons | ||||
| */ | */ | ||||
| if (GS(ip->id->name) != ID_TE) | if (GS(ip->id->name) != ID_TE) { | ||||
| /* grease pencil use its own preview file */ | |||||
| if (GS(ip->id->name) == ID_MA) { | |||||
| ma = (Material *)ip->id; | |||||
| } | |||||
| if ((ma == NULL) || (ma->gp_style == NULL)) { | |||||
| sp->pr_main = G_pr_main_cycles; | sp->pr_main = G_pr_main_cycles; | ||||
| else | } | ||||
| else { | |||||
| sp->pr_main = G_pr_main_grease_pencil; | |||||
| } | |||||
| } | |||||
| else { | |||||
| sp->pr_main = G_pr_main; | sp->pr_main = G_pr_main; | ||||
| } | } | ||||
| } | |||||
| common_preview_startjob(sp, stop, do_update, progress); | common_preview_startjob(sp, stop, do_update, progress); | ||||
| shader_preview_free(sp); | shader_preview_free(sp); | ||||
| } | } | ||||
| } | } | ||||
| static void icon_preview_endjob(void *customdata) | static void icon_preview_endjob(void *customdata) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey, int method) | ||||
| sp->sizey = sizey; | sp->sizey = sizey; | ||||
| sp->pr_method = method; | sp->pr_method = method; | ||||
| sp->id = id; | sp->id = id; | ||||
| sp->id_copy = duplicate_ids(id, sp->depsgraph); | sp->id_copy = duplicate_ids(id, sp->depsgraph); | ||||
| sp->own_id_copy = true; | sp->own_id_copy = true; | ||||
| sp->parent = parent; | sp->parent = parent; | ||||
| sp->slot = slot; | sp->slot = slot; | ||||
| sp->bmain = CTX_data_main(C); | sp->bmain = CTX_data_main(C); | ||||
| Material *ma = NULL; | |||||
| /* hardcoded preview .blend for Eevee + Cycles, this should be solved | /* hardcoded preview .blend for Eevee + Cycles, this should be solved | ||||
| * once with custom preview .blend path for external engines */ | * once with custom preview .blend path for external engines */ | ||||
| if ((method != PR_NODE_RENDER) && id_type != ID_TE) { | if ((method != PR_NODE_RENDER) && id_type != ID_TE) { | ||||
| /* grease pencil use its own preview file */ | |||||
| if (GS(id->name) == ID_MA) { | |||||
| ma = (Material *)id; | |||||
| } | |||||
| if ((ma == NULL) || (ma->gp_style == NULL)) { | |||||
| sp->pr_main = G_pr_main_cycles; | sp->pr_main = G_pr_main_cycles; | ||||
| } | } | ||||
| else { | else { | ||||
| sp->pr_main = G_pr_main_grease_pencil; | |||||
| } | |||||
| } | |||||
| else { | |||||
| sp->pr_main = G_pr_main; | sp->pr_main = G_pr_main; | ||||
| } | } | ||||
| if (ob && ob->totcol) copy_v4_v4(sp->col, ob->col); | if (ob && ob->totcol) copy_v4_v4(sp->col, ob->col); | ||||
| else sp->col[0] = sp->col[1] = sp->col[2] = sp->col[3] = 1.0f; | else sp->col[0] = sp->col[1] = sp->col[2] = sp->col[3] = 1.0f; | ||||
| /* setup job */ | /* setup job */ | ||||
| WM_jobs_customdata_set(wm_job, sp, shader_preview_free); | WM_jobs_customdata_set(wm_job, sp, shader_preview_free); | ||||
| Show All 11 Lines | |||||