Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_preview.c
| Show First 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static bool check_engine_supports_preview(Scene *scene) | static bool check_engine_supports_preview(Scene *scene) | ||||
| { | { | ||||
| RenderEngineType *type = RE_engines_find(scene->r.engine); | RenderEngineType *type = RE_engines_find(scene->r.engine); | ||||
| return (type->flag & RE_USE_PREVIEW) != 0; | return (type->flag & RE_USE_PREVIEW) != 0; | ||||
| } | } | ||||
| static bool preview_method_is_render(int pr_method) | |||||
| { | |||||
| return ELEM(pr_method, PR_ICON_RENDER, PR_BUTS_RENDER, PR_NODE_RENDER); | |||||
| } | |||||
| 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_grease_pencil) { | if (G_pr_main_grease_pencil) { | ||||
| BKE_main_free(G_pr_main_grease_pencil); | BKE_main_free(G_pr_main_grease_pencil); | ||||
| ▲ Show 20 Lines • Show All 1,136 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** | /** | ||||
| * Some ID types already have their own, more focused rendering (only objects right now). This is | * Some ID types already have their own, more focused rendering (only objects right now). This is | ||||
| * for the other ones, which all share #ShaderPreview and some functions. | * for the other ones, which all share #ShaderPreview and some functions. | ||||
| */ | */ | ||||
| static void other_id_types_preview_render(IconPreview *ip, | static void other_id_types_preview_render(IconPreview *ip, | ||||
| IconPreviewSize *cur_size, | IconPreviewSize *cur_size, | ||||
| const bool is_deferred, | const int pr_method, | ||||
| short *stop, | short *stop, | ||||
| short *do_update, | short *do_update, | ||||
| float *progress) | float *progress) | ||||
| { | { | ||||
| ShaderPreview *sp = MEM_callocN(sizeof(ShaderPreview), "Icon ShaderPreview"); | ShaderPreview *sp = MEM_callocN(sizeof(ShaderPreview), "Icon ShaderPreview"); | ||||
| const bool is_render = !is_deferred; | |||||
| /* These types don't use the ShaderPreview mess, they have their own types and functions. */ | /* These types don't use the ShaderPreview mess, they have their own types and functions. */ | ||||
| BLI_assert(!ip->id || !ELEM(GS(ip->id->name), ID_OB)); | BLI_assert(!ip->id || !ELEM(GS(ip->id->name), ID_OB)); | ||||
| /* construct shader preview from image size and previewcustomdata */ | /* construct shader preview from image size and previewcustomdata */ | ||||
| sp->scene = ip->scene; | sp->scene = ip->scene; | ||||
| sp->owner = ip->owner; | sp->owner = ip->owner; | ||||
| 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 = pr_method; | ||||
| 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; | Material *ma = NULL; | ||||
| if (is_render) { | if (sp->pr_method == PR_ICON_RENDER) { | ||||
| BLI_assert(ip->id); | BLI_assert(ip->id); | ||||
| /* grease pencil use its own preview file */ | /* grease pencil use its own preview file */ | ||||
| if (GS(ip->id->name) == ID_MA) { | if (GS(ip->id->name) == ID_MA) { | ||||
| ma = (Material *)ip->id; | ma = (Material *)ip->id; | ||||
| } | } | ||||
| if ((ma == NULL) || (ma->gp_style == NULL)) { | if ((ma == NULL) || (ma->gp_style == NULL)) { | ||||
| Show All 31 Lines | static void icon_preview_startjob_all_sizes(void *customdata, | ||||
| short *do_update, | short *do_update, | ||||
| float *progress) | float *progress) | ||||
| { | { | ||||
| IconPreview *ip = (IconPreview *)customdata; | IconPreview *ip = (IconPreview *)customdata; | ||||
| IconPreviewSize *cur_size; | IconPreviewSize *cur_size; | ||||
| for (cur_size = ip->sizes.first; cur_size; cur_size = cur_size->next) { | for (cur_size = ip->sizes.first; cur_size; cur_size = cur_size->next) { | ||||
| PreviewImage *prv = ip->owner; | PreviewImage *prv = ip->owner; | ||||
| /* Is this a render job or a deferred loading job? */ | |||||
| const int pr_method = (prv->tag & PRV_TAG_DEFFERED) ? PR_ICON_DEFERRED : PR_ICON_RENDER; | |||||
| if (*stop) { | if (*stop) { | ||||
| break; | break; | ||||
| } | } | ||||
| if (prv->tag & PRV_TAG_DEFFERED_DELETE) { | if (prv->tag & PRV_TAG_DEFFERED_DELETE) { | ||||
| /* Non-thread-protected reading is not an issue here. */ | /* Non-thread-protected reading is not an issue here. */ | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!check_engine_supports_preview(ip->scene)) { | if (preview_method_is_render(pr_method) && !check_engine_supports_preview(ip->scene)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| { | { | ||||
| int size_index = icon_previewimg_size_index_get(cur_size, prv); | int size_index = icon_previewimg_size_index_get(cur_size, prv); | ||||
| BLI_assert(!BKE_previewimg_is_finished(prv, size_index)); | BLI_assert(!BKE_previewimg_is_finished(prv, size_index)); | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (ip->id && ELEM(GS(ip->id->name), ID_OB)) { | if (ip->id && ELEM(GS(ip->id->name), ID_OB)) { | ||||
| /* Much simpler than the ShaderPreview mess used for other ID types. */ | /* Much simpler than the ShaderPreview mess used for other ID types. */ | ||||
| object_preview_render(ip, cur_size); | object_preview_render(ip, cur_size); | ||||
| } | } | ||||
| else { | else { | ||||
| other_id_types_preview_render( | other_id_types_preview_render(ip, cur_size, pr_method, stop, do_update, progress); | ||||
| ip, cur_size, (prv->tag & PRV_TAG_DEFFERED), stop, do_update, progress); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void icon_preview_add_size(IconPreview *ip, uint *rect, int sizex, int sizey) | static void icon_preview_add_size(IconPreview *ip, uint *rect, int sizex, int sizey) | ||||
| { | { | ||||
| IconPreviewSize *cur_size = ip->sizes.first, *new_size; | IconPreviewSize *cur_size = ip->sizes.first, *new_size; | ||||
| ▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | void ED_preview_shader_job(const bContext *C, | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| short id_type = GS(id->name); | short id_type = GS(id->name); | ||||
| BLI_assert(BKE_previewimg_id_supports_jobs(id)); | BLI_assert(BKE_previewimg_id_supports_jobs(id)); | ||||
| /* Use workspace render only for buttons Window, | /* Use workspace render only for buttons Window, | ||||
| * since the other previews are related to the datablock. */ | * since the other previews are related to the datablock. */ | ||||
| if (!check_engine_supports_preview(scene)) { | if (preview_method_is_render(method) && !check_engine_supports_preview(scene)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Only texture node preview is supported with Cycles. */ | /* Only texture node preview is supported with Cycles. */ | ||||
| if (method == PR_NODE_RENDER && id_type != ID_TE) { | if (method == PR_NODE_RENDER && id_type != ID_TE) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||