Blender V4.3
render_preview.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <list>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BLO_readfile.hh"
#include "DNA_brush_types.h"
#include "DNA_camera_types.h"
#include "DNA_collection_types.h"
#include "DNA_light_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_world_types.h"
#include "BKE_animsys.h"
#include "BKE_appdir.hh"
#include "BKE_armature.hh"
#include "BKE_brush.hh"
#include "BKE_colortools.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_icons.h"
#include "BKE_idprop.hh"
#include "BKE_image.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_light.h"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_node.hh"
#include "BKE_object.hh"
#include "BKE_pose_backup.h"
#include "BKE_preview_image.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "BKE_texture.h"
#include "BKE_world.h"
#include "BLI_math_vector.h"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_build.hh"
#include "DEG_depsgraph_query.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "IMB_thumbs.hh"
#include "BIF_glutil.hh"
#include "GPU_shader.hh"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "RE_texture.h"
#include "WM_api.hh"
#include "WM_types.hh"
#include "ED_datafiles.h"
#include "ED_render.hh"
#include "ED_screen.hh"
#include "ED_view3d.hh"
#include "ED_view3d_offscreen.hh"
#include "UI_interface_icons.hh"
#include "ANIM_action.hh"
#include "ANIM_pose.hh"
#include "BLI_threads.h"

Go to the source code of this file.

Classes

struct  ShaderPreview
 
struct  IconPreviewSize
 
struct  IconPreview
 
struct  ObjectPreviewData
 
class  PreviewLoadJob
 
struct  PreviewRestartQueueEntry
 

Functions

Object Preview
static bool object_preview_is_type_supported (const Object *ob)
 
static Objectobject_preview_camera_create (Main *preview_main, Scene *scene, ViewLayer *view_layer, Object *preview_object)
 
static Sceneobject_preview_scene_create (const ObjectPreviewData *preview_data, Depsgraph **r_depsgraph)
 
static void object_preview_render (IconPreview *preview, IconPreviewSize *preview_sized)
 
Collection Preview

For the most part this reuses the object preview code by creating an instance collection empty object and rendering that.

static bool collection_preview_contains_geometry_recursive (const Collection *collection)
 
Action Preview
static PoseBackupaction_preview_render_prepare (IconPreview *preview)
 
static void action_preview_render_cleanup (IconPreview *preview, PoseBackup *pose_backup)
 
static void action_preview_render (IconPreview *preview, IconPreviewSize *preview_sized)
 
New Shader Preview System
static void shader_preview_update (void *spv, RenderResult *, rcti *)
 
static bool shader_preview_break (void *spv)
 
static void shader_preview_updatejob (void *)
 
static void shader_preview_texture (ShaderPreview *sp, Tex *tex, Scene *sce, Render *re)
 
static void shader_preview_render (ShaderPreview *sp, ID *id, int split, int first)
 
static void shader_preview_startjob (void *customdata, bool *stop, bool *do_update)
 
static void preview_id_copy_free (ID *id)
 
static void shader_preview_free (void *customdata)
 

Preview for Buttons

static MainG_pr_main_grease_pencil = nullptr
 
static Mainload_main_from_memory (const void *blend, int blend_size)
 
void ED_preview_ensure_dbase (const bool with_gpencil)
 
bool ED_check_engine_supports_preview (const Scene *scene)
 
static bool preview_method_is_render (const ePreviewRenderMethod pr_method)
 
void ED_preview_free_dbase ()
 
static Scenepreview_get_scene (Main *pr_main)
 
const char * ED_preview_collection_name (const ePreviewType pr_type)
 
static bool render_engine_supports_ray_visibility (const Scene *sce)
 
static void switch_preview_collection_visibility (ViewLayer *view_layer, const ePreviewType pr_type)
 
static const char * preview_floor_material_name (const Scene *scene, const ePreviewRenderMethod pr_method)
 
static void switch_preview_floor_material (Main *pr_main, Mesh *mesh, const Scene *scene, const ePreviewRenderMethod pr_method)
 
static void switch_preview_floor_visibility (Main *pr_main, const Scene *scene, ViewLayer *view_layer, const ePreviewRenderMethod pr_method)
 
void ED_preview_set_visibility (Main *pr_main, Scene *scene, ViewLayer *view_layer, const ePreviewType pr_type, const ePreviewRenderMethod pr_method)
 
static Worldpreview_get_localized_world (ShaderPreview *sp, World *world)
 
static IDduplicate_ids (ID *id, const bool allow_failure)
 
static const char * preview_world_name (const Scene *sce, const ID_Type id_type, const ePreviewRenderMethod pr_method)
 
static Worldpreview_get_world (Main *pr_main, const Scene *sce, const ID_Type id_type, const ePreviewRenderMethod pr_method)
 
static void preview_sync_exposure (World *dst, const World *src)
 
WorldED_preview_prepare_world (Main *pr_main, const Scene *scene, const World *world, const ID_Type id_type, const ePreviewRenderMethod pr_method)
 
static Scenepreview_prepare_scene (Main *bmain, Scene *scene, ID *id, int id_type, ShaderPreview *sp)
 
static bool ed_preview_draw_rect (Scene *scene, ScrArea *area, int split, int first, const rcti *rect, rcti *newrect)
 
void ED_preview_draw (const bContext *C, void *idp, void *parentp, void *slotp, uiPreview *ui_preview, rcti *rect)
 
void ED_previews_tag_dirty_by_id (const Main &bmain, const ID &id)
 

Icon Preview

static ListBase G_restart_previews_queue
 
static void icon_copy_rect (ImBuf *ibuf, uint w, uint h, uint *rect)
 
static ImBuficon_preview_imbuf_from_brush (Brush *brush)
 
static void set_alpha (char *cp, int sizex, int sizey, char alpha)
 
static void icon_preview_startjob (void *customdata, bool *stop, bool *do_update)
 
static void common_preview_startjob (void *customdata, wmJobWorkerStatus *worker_status)
 
static void other_id_types_preview_render (IconPreview *ip, IconPreviewSize *cur_size, const ePreviewRenderMethod pr_method, wmJobWorkerStatus *worker_status)
 
static int icon_previewimg_size_index_get (const IconPreviewSize *icon_size, const PreviewImage *preview_image)
 
static void icon_preview_startjob_all_sizes (void *customdata, wmJobWorkerStatus *worker_status)
 
static void icon_preview_add_size (IconPreview *ip, uint *rect, int sizex, int sizey)
 
static void icon_preview_endjob (void *customdata)
 
static void icon_preview_free (void *customdata)
 
bool ED_preview_id_is_supported (const ID *id, const char **r_disabled_hint)
 
void ED_preview_icon_render (const bContext *C, Scene *scene, PreviewImage *prv_img, ID *id, eIconSizes icon_size)
 
void ED_preview_icon_job (const bContext *C, PreviewImage *prv_img, ID *id, eIconSizes icon_size, const bool delay)
 
void ED_preview_shader_job (const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey, ePreviewRenderMethod method)
 
void ED_preview_kill_jobs (wmWindowManager *wm, Main *)
 
void ED_preview_restart_queue_free ()
 
void ED_preview_restart_queue_add (ID *id, enum eIconSizes size)
 
void ED_preview_restart_queue_work (const bContext *C)
 

Function Documentation

◆ action_preview_render()

◆ action_preview_render_cleanup()

static void action_preview_render_cleanup ( IconPreview * preview,
PoseBackup * pose_backup )
static

◆ action_preview_render_prepare()

◆ collection_preview_contains_geometry_recursive()

static bool collection_preview_contains_geometry_recursive ( const Collection * collection)
static

Check if the collection contains any geometry that can be rendered. Otherwise there's nothing to display in the preview, so don't generate one. Objects and sub-collections hidden in the render will be skipped.

Definition at line 936 of file render_preview.cc.

References COLLECTION_HIDE_RENDER, collection_preview_contains_geometry_recursive(), LISTBASE_FOREACH, OB_HIDE_RENDER, and OB_TYPE_IS_GEOMETRY.

Referenced by collection_preview_contains_geometry_recursive(), ED_preview_id_is_supported(), and icon_preview_startjob_all_sizes().

◆ common_preview_startjob()

static void common_preview_startjob ( void * customdata,
wmJobWorkerStatus * worker_status )
static

◆ duplicate_ids()

◆ ED_check_engine_supports_preview()

bool ED_check_engine_supports_preview ( const Scene * scene)

◆ ED_preview_collection_name()

const char * ED_preview_collection_name ( const ePreviewType pr_type)

◆ ED_preview_draw()

◆ ed_preview_draw_rect()

◆ ED_preview_ensure_dbase()

◆ ED_preview_free_dbase()

void ED_preview_free_dbase ( )

Definition at line 222 of file render_preview.cc.

References BKE_main_free(), G, and G_pr_main_grease_pencil.

Referenced by WM_exit_ex().

◆ ED_preview_icon_job()

◆ ED_preview_icon_render()

◆ ED_preview_id_is_supported()

bool ED_preview_id_is_supported ( const ID * id,
const char ** r_disabled_hint = nullptr )

Check if id is supported by the automatic preview render.

Definition at line 1919 of file render_preview.cc.

References BKE_previewimg_id_get_p(), collection_preview_contains_geometry_recursive(), GS, ID_GR, ID_NT, ID_OB, object_preview_is_type_supported(), result, and RPT_.

Referenced by lib_id_generate_preview_poll(), and UI_icon_render_id().

◆ ED_preview_kill_jobs()

void ED_preview_kill_jobs ( wmWindowManager * wm,
Main * bmain )

Definition at line 2136 of file render_preview.cc.

References WM_JOB_TYPE_RENDER_PREVIEW, and WM_jobs_kill_type().

Referenced by blender::ed::space_node::add_node_group_asset(), blender::ed::space_node::add_reroute_exec(), blender::ed::space_node::cut_links_exec(), blender::ed::space_node::detach_links_exec(), ED_render_engine_changed(), image_open_exec(), image_reload_exec(), image_replace_exec(), image_unpack_exec(), lib_id_generate_preview_exec(), lib_id_generate_preview_from_object_exec(), memfile_undosys_step_decode(), blender::ed::space_node::mute_links_exec(), blender::ed::space_node::node_active_link_viewer_exec(), blender::ed::space_node::node_add_collection_exec(), blender::ed::space_node::node_add_file_exec(), blender::ed::space_node::node_add_group_exec(), blender::ed::space_node::node_add_mask_exec(), blender::ed::space_node::node_add_material_exec(), blender::ed::space_node::node_add_object_exec(), blender::ed::space_node::node_clipboard_paste_exec(), blender::ed::space_node::node_delete_exec(), blender::ed::space_node::node_delete_reconnect_exec(), blender::ed::space_node::node_duplicate_exec(), blender::ed::space_node::node_group_edit_exec(), blender::ed::space_node::node_group_insert_exec(), blender::ed::space_node::node_group_make_exec(), blender::ed::space_node::node_group_separate_exec(), blender::ed::space_node::node_group_ungroup_exec(), blender::ed::space_node::node_link_invoke(), blender::ed::space_node::node_make_link_exec(), blender::ed::space_node::node_mute_exec(), blender::ed::space_node::node_read_viewlayers_exec(), blender::ed::space_node::node_socket_toggle_exec(), and blender::ed::space_node::viewer_border_exec().

◆ ED_preview_prepare_world()

World * ED_preview_prepare_world ( Main * pr_main,
const Scene * scene,
const World * world,
const ID_Type id_type,
const ePreviewRenderMethod pr_method )

◆ ED_preview_restart_queue_add()

void ED_preview_restart_queue_add ( ID * id,
enum eIconSizes size )

◆ ED_preview_restart_queue_free()

void ED_preview_restart_queue_free ( )

Definition at line 2154 of file render_preview.cc.

References BLI_freelistN(), and G_restart_previews_queue.

Referenced by WM_exit_ex(), and wm_file_read_pre().

◆ ED_preview_restart_queue_work()

◆ ED_preview_set_visibility()

void ED_preview_set_visibility ( Main * pr_main,
Scene * scene,
ViewLayer * view_layer,
const ePreviewType pr_type,
const ePreviewRenderMethod pr_method )

◆ ED_preview_shader_job()

◆ ED_previews_tag_dirty_by_id()

void ED_previews_tag_dirty_by_id ( const Main & bmain,
const ID & id )

For UI previews (i.e. uiPreview, not PreviewImage): Tag all previews for id as dirty, so the next redraw triggers a re-render in ED_preview_draw().

Definition at line 763 of file render_preview.cc.

References LISTBASE_FOREACH, Main::screens, and UI_PREVIEW_TAG_DIRTY.

Referenced by image_changed(), lamp_changed(), material_changed(), texture_changed(), and world_changed().

◆ icon_copy_rect()

◆ icon_preview_add_size()

static void icon_preview_add_size ( IconPreview * ip,
uint * rect,
int sizex,
int sizey )
static

◆ icon_preview_endjob()

◆ icon_preview_free()

static void icon_preview_free ( void * customdata)
static

◆ icon_preview_imbuf_from_brush()

◆ icon_preview_startjob()

◆ icon_preview_startjob_all_sizes()

◆ icon_previewimg_size_index_get()

static int icon_previewimg_size_index_get ( const IconPreviewSize * icon_size,
const PreviewImage * preview_image )
static

Find the index to map icon_size to data in preview_image.

Definition at line 1565 of file render_preview.cc.

References BLI_assert_msg, PreviewImage::h, NUM_ICON_SIZES, IconPreviewSize::sizex, IconPreviewSize::sizey, and PreviewImage::w.

Referenced by icon_preview_endjob(), and icon_preview_startjob_all_sizes().

◆ load_main_from_memory()

static Main * load_main_from_memory ( const void * blend,
int blend_size )
static

◆ object_preview_camera_create()

static Object * object_preview_camera_create ( Main * preview_main,
Scene * scene,
ViewLayer * view_layer,
Object * preview_object )
static

◆ object_preview_is_type_supported()

static bool object_preview_is_type_supported ( const Object * ob)
static

◆ object_preview_render()

◆ object_preview_scene_create()

◆ other_id_types_preview_render()

◆ preview_floor_material_name()

static const char * preview_floor_material_name ( const Scene * scene,
const ePreviewRenderMethod pr_method )
static

◆ preview_get_localized_world()

static World * preview_get_localized_world ( ShaderPreview * sp,
World * world )
static

◆ preview_get_scene()

static Scene * preview_get_scene ( Main * pr_main)
static

Definition at line 233 of file render_preview.cc.

References ListBase::first, and Main::scenes.

Referenced by preview_prepare_scene(), and shader_preview_render().

◆ preview_get_world()

static World * preview_get_world ( Main * pr_main,
const Scene * sce,
const ID_Type id_type,
const ePreviewRenderMethod pr_method )
static

◆ preview_id_copy_free()

static void preview_id_copy_free ( ID * id)
static

◆ preview_method_is_render()

static bool preview_method_is_render ( const ePreviewRenderMethod pr_method)
static

Definition at line 217 of file render_preview.cc.

References ELEM, PR_BUTS_RENDER, and PR_ICON_RENDER.

Referenced by ED_preview_shader_job(), and icon_preview_startjob_all_sizes().

◆ preview_prepare_scene()

static Scene * preview_prepare_scene ( Main * bmain,
Scene * scene,
ID * id,
int id_type,
ShaderPreview * sp )
static

Definition at line 476 of file render_preview.cc.

References RenderData::alphamode, BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT, BKE_color_managed_display_settings_copy(), BKE_color_managed_view_settings_copy(), BKE_color_managed_view_settings_free(), BKE_main_blendfile_path(), BKE_object_material_array_p(), BKE_view_layer_object_bases_get(), BKE_view_layer_synced_ensure(), BLI_addtail(), BLI_assert, RenderData::cfra, ShaderPreview::color, RenderData::color_mgt_flag, copy_v4_v4(), Scene::display, Scene::display_settings, ED_preview_prepare_world(), ED_preview_set_visibility(), ViewLayer::eevee, RenderData::engine, Main::filepath, ListBase::first, Material::flag, G_pr_main_grease_pencil, World::horb, World::horg, World::horr, ShaderPreview::id_copy, ID_LA, ID_MA, ID_TE, ID_WO, ShaderPreview::lampcopy, Main::lights, LISTBASE_FOREACH, MA_LAMP, MA_PREVIEW_WORLD, MA_SKY, ShaderPreview::matcopy, Main::materials, max_ii(), OB_LAMP, OB_TYPE_SUPPORT_MATERIAL, ViewLayer::passflag, PR_BUTS_RENDER, Material::pr_flag, PR_ICON_RENDER, ShaderPreview::pr_main, ShaderPreview::pr_method, Material::pr_type, preview_get_localized_world(), preview_get_scene(), Scene::r, R_ADDSKY, R_ALPHAPREMUL, R_BUTS_PREVIEW, RE_engine_id_BLENDER_EEVEE_NEXT, SceneDisplay::render_aa, ViewLayerEEVEE::render_passes, SCE_DISPLAY_AA_OFF, SCE_PASS_COMBINED, RenderData::scemode, STRNCPY, tex, ShaderPreview::texcopy, Main::textures, World::use_nodes, Scene::view_layers, Scene::view_settings, Scene::world, ShaderPreview::worldcopy, and Main::worlds.

Referenced by shader_preview_render().

◆ preview_sync_exposure()

static void preview_sync_exposure ( World * dst,
const World * src )
static

Definition at line 453 of file render_preview.cc.

References BLI_assert, World::exp, and World::range.

Referenced by ED_preview_prepare_world().

◆ preview_world_name()

static const char * preview_world_name ( const Scene * sce,
const ID_Type id_type,
const ePreviewRenderMethod pr_method )
static

Definition at line 415 of file render_preview.cc.

References ID_MA, PR_ICON_RENDER, and render_engine_supports_ray_visibility().

Referenced by preview_get_world().

◆ render_engine_supports_ray_visibility()

static bool render_engine_supports_ray_visibility ( const Scene * sce)
static

◆ set_alpha()

static void set_alpha ( char * cp,
int sizex,
int sizey,
char alpha )
static

Definition at line 1417 of file render_preview.cc.

References size().

Referenced by icon_preview_startjob().

◆ shader_preview_break()

static bool shader_preview_break ( void * spv)
static

Definition at line 1076 of file render_preview.cc.

References ShaderPreview::stop.

Referenced by shader_preview_render(), and shader_preview_texture().

◆ shader_preview_free()

◆ shader_preview_render()

◆ shader_preview_startjob()

static void shader_preview_startjob ( void * customdata,
bool * stop,
bool * do_update )
static

◆ shader_preview_texture()

◆ shader_preview_update()

static void shader_preview_update ( void * spv,
RenderResult * ,
rcti *  )
static

Definition at line 1068 of file render_preview.cc.

References ShaderPreview::do_update.

Referenced by shader_preview_render().

◆ shader_preview_updatejob()

static void shader_preview_updatejob ( void * )
static

Definition at line 1083 of file render_preview.cc.

Referenced by ED_preview_shader_job().

◆ switch_preview_collection_visibility()

◆ switch_preview_floor_material()

static void switch_preview_floor_material ( Main * pr_main,
Mesh * mesh,
const Scene * scene,
const ePreviewRenderMethod pr_method )
static

◆ switch_preview_floor_visibility()

static void switch_preview_floor_visibility ( Main * pr_main,
const Scene * scene,
ViewLayer * view_layer,
const ePreviewRenderMethod pr_method )
static

Variable Documentation

◆ G_pr_main_grease_pencil

Main* G_pr_main_grease_pencil = nullptr
static

◆ G_restart_previews_queue

ListBase G_restart_previews_queue
static