Blender  V3.3
Classes
render_preview.cc File Reference
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <list>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "PIL_time.h"
#include "BLO_readfile.h"
#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.h"
#include "BKE_armature.h"
#include "BKE_brush.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_light.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_texture.h"
#include "BKE_world.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_thumbs.h"
#include "BIF_glutil.h"
#include "GPU_shader.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "RE_texture.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_armature.h"
#include "ED_datafiles.h"
#include "ED_render.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "ED_view3d_offscreen.h"
#include "UI_interface_icons.h"
#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, ViewLayer *view_layer, Object *preview_object)
 
static Sceneobject_preview_scene_create (const struct 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 struct PoseBackupaction_preview_render_prepare (IconPreview *preview)
 
static void action_preview_render_cleanup (IconPreview *preview, struct 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 *UNUSED(rr), struct rcti *UNUSED(rect))
 
static int shader_preview_break (void *spv)
 
static void shader_preview_updatejob (void *UNUSED(spv))
 
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, short *stop, short *do_update)
 
static void preview_id_copy_free (ID *id)
 
static void shader_preview_free (void *customdata)
 

Preview for Buttons

static MainG_pr_main = nullptr
 
static MainG_pr_main_grease_pencil = nullptr
 
static Mainload_main_from_memory (const void *blend, int blend_size)
 
void ED_preview_ensure_dbase ()
 
static bool check_engine_supports_preview (Scene *scene)
 
static bool preview_method_is_render (const ePreviewRenderMethod pr_method)
 
void ED_preview_free_dbase ()
 
static Scenepreview_get_scene (Main *pr_main)
 
static const char * 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 *me, 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)
 
static void set_preview_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)
 
static Worldpreview_prepare_world (Main *pr_main, const Scene *sce, 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 (ScrArea *area, int split, int first, rcti *rect, rcti *newrect)
 
void ED_preview_draw (const bContext *C, void *idp, void *parentp, void *slotp, rcti *rect)
 

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, short *stop, short *do_update)
 
static void common_preview_startjob (void *customdata, short *stop, short *do_update, float *UNUSED(progress))
 
static void other_id_types_preview_render (IconPreview *ip, IconPreviewSize *cur_size, const ePreviewRenderMethod pr_method, short *stop, short *do_update, float *progress)
 
static int icon_previewimg_size_index_get (const IconPreviewSize *icon_size, const PreviewImage *preview_image)
 
static void icon_preview_startjob_all_sizes (void *customdata, short *stop, short *do_update, float *progress)
 
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)
 
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 *UNUSED(bmain))
 
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()

static void action_preview_render ( IconPreview preview,
IconPreviewSize preview_sized 
)
static

◆ action_preview_render_cleanup()

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

◆ action_preview_render_prepare()

static struct PoseBackup* action_preview_render_prepare ( IconPreview preview)
static

◆ check_engine_supports_preview()

static bool check_engine_supports_preview ( Scene scene)
static

◆ 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 909 of file render_preview.cc.

References Collection::children, COLLECTION_HIDE_RENDER, Collection::gobject, LISTBASE_FOREACH, OB_HIDE_RENDER, and OB_TYPE_IS_GEOMETRY.

Referenced by ED_preview_id_is_supported(), and icon_preview_startjob_all_sizes().

◆ common_preview_startjob()

static void common_preview_startjob ( void customdata,
short *  stop,
short *  do_update,
float UNUSEDprogress 
)
static

◆ duplicate_ids()

static ID* duplicate_ids ( ID id,
const bool  allow_failure 
)
static

◆ ED_preview_draw()

void ED_preview_draw ( const bContext C,
void idp,
void parentp,
void slotp,
rcti rect 
)

◆ ed_preview_draw_rect()

static bool ed_preview_draw_rect ( ScrArea area,
int  split,
int  first,
rcti rect,
rcti newrect 
)
static

◆ ED_preview_ensure_dbase()

void ED_preview_ensure_dbase ( void  )

◆ ED_preview_free_dbase()

void ED_preview_free_dbase ( void  )

Definition at line 206 of file render_preview.cc.

References BKE_main_free(), G_pr_main, and G_pr_main_grease_pencil.

Referenced by WM_exit_ex().

◆ ED_preview_icon_job()

void ED_preview_icon_job ( const bContext C,
PreviewImage prv_img,
ID id,
eIconSizes  icon_size,
const bool  delay 
)

◆ ED_preview_icon_render()

void ED_preview_icon_render ( const bContext C,
Scene scene,
PreviewImage prv_img,
ID id,
eIconSizes  icon_size 
)

◆ ED_preview_id_is_supported()

bool ED_preview_id_is_supported ( const ID id)

◆ ED_preview_kill_jobs()

void ED_preview_kill_jobs ( wmWindowManager wm,
Main UNUSEDbmain 
)

◆ 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 ( void  )

Definition at line 2135 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()

void ED_preview_restart_queue_work ( const bContext C)

◆ ED_preview_shader_job()

void ED_preview_shader_job ( const bContext C,
void owner,
ID id,
ID parent,
MTex slot,
int  sizex,
int  sizey,
ePreviewRenderMethod  method 
)

◆ icon_copy_rect()

static void icon_copy_rect ( ImBuf ibuf,
uint  w,
uint  h,
uint rect 
)
static

◆ icon_preview_add_size()

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

◆ icon_preview_endjob()

static void icon_preview_endjob ( void customdata)
static

◆ icon_preview_free()

static void icon_preview_free ( void customdata)
static

◆ icon_preview_imbuf_from_brush()

static ImBuf* icon_preview_imbuf_from_brush ( Brush brush)
static

◆ icon_preview_startjob()

static void icon_preview_startjob ( void customdata,
short *  stop,
short *  do_update 
)
static

◆ icon_preview_startjob_all_sizes()

static void icon_preview_startjob_all_sizes ( void customdata,
short *  stop,
short *  do_update,
float progress 
)
static

◆ 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 1563 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,
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()

static void object_preview_render ( IconPreview preview,
IconPreviewSize preview_sized 
)
static

◆ object_preview_scene_create()

static Scene* object_preview_scene_create ( const struct ObjectPreviewData preview_data,
Depsgraph **  r_depsgraph 
)
static

◆ other_id_types_preview_render()

static void other_id_types_preview_render ( IconPreview ip,
IconPreviewSize cur_size,
const ePreviewRenderMethod  pr_method,
short *  stop,
short *  do_update,
float progress 
)
static

◆ preview_collection_name()

static const char* preview_collection_name ( const ePreviewType  pr_type)
static

◆ 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 217 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 201 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 458 of file render_preview.cc.

References Object::actcol, RenderData::alphamode, BASE_VISIBLE_DEPSGRAPH, 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(), BLI_addtail(), BLI_assert, BLI_strncpy(), RenderData::cfra, ShaderPreview::color, RenderData::color_mgt_flag, copy_v4_v4(), Scene::display, Scene::display_settings, 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, MA_SPHERE_A, Object::mat, ShaderPreview::matcopy, Main::materials, max_ii(), OB_LAMP, OB_TYPE_SUPPORT_MATERIAL, ViewLayer::object_bases, 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(), preview_prepare_world(), Scene::r, R_ADDSKY, R_ALPHAPREMUL, R_BUTS_PREVIEW, RE_engine_id_BLENDER_EEVEE, SceneDisplay::render_aa, ViewLayerEEVEE::render_passes, SCE_DISPLAY_AA_OFF, SCE_PASS_COMBINED, RenderData::scemode, scene, set_preview_visibility(), 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_prepare_world()

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

Definition at line 443 of file render_preview.cc.

References preview_get_world(), preview_sync_exposure(), result, and world.

Referenced by preview_prepare_scene().

◆ preview_sync_exposure()

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

Definition at line 435 of file render_preview.cc.

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

Referenced by 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 398 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 1406 of file render_preview.cc.

References Freestyle::a, and size().

Referenced by icon_preview_startjob().

◆ set_preview_visibility()

static void set_preview_visibility ( Main pr_main,
Scene scene,
ViewLayer view_layer,
const ePreviewType  pr_type,
const ePreviewRenderMethod  pr_method 
)
static

◆ shader_preview_break()

static int shader_preview_break ( void spv)
static

Definition at line 1046 of file render_preview.cc.

References ShaderPreview::stop.

Referenced by shader_preview_render(), and shader_preview_texture().

◆ shader_preview_free()

static void shader_preview_free ( void customdata)
static

◆ shader_preview_render()

static void shader_preview_render ( ShaderPreview sp,
ID id,
int  split,
int  first 
)
static

◆ shader_preview_startjob()

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

◆ shader_preview_texture()

static void shader_preview_texture ( ShaderPreview sp,
Tex tex,
Scene sce,
Render re 
)
static

◆ shader_preview_update()

static void shader_preview_update ( void spv,
RenderResult UNUSEDrr,
struct rcti UNUSEDrect 
)
static

Definition at line 1038 of file render_preview.cc.

References ShaderPreview::do_update.

Referenced by shader_preview_render().

◆ shader_preview_updatejob()

static void shader_preview_updatejob ( void UNUSEDspv)
static

Definition at line 1053 of file render_preview.cc.

Referenced by ED_preview_shader_job().

◆ switch_preview_collection_visibility()

static void switch_preview_collection_visibility ( ViewLayer view_layer,
const ePreviewType  pr_type 
)
static

◆ switch_preview_floor_material()

static void switch_preview_floor_material ( Main pr_main,
Mesh me,
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

Main* G_pr_main = nullptr
static

◆ G_pr_main_grease_pencil

Main* G_pr_main_grease_pencil = nullptr
static

◆ G_restart_previews_queue

ListBase G_restart_previews_queue
static