Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_manager.c
| Show All 21 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include "BLI_alloca.h" | #include "BLI_alloca.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_memblock.h" | #include "BLI_memblock.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_task.h" | |||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_duplilist.h" | #include "BKE_duplilist.h" | ||||
| ▲ Show 20 Lines • Show All 1,381 Lines • ▼ Show 20 Lines | DST.draw_ctx = (DRWContextState){ | ||||
| .view_layer = view_layer, | .view_layer = view_layer, | ||||
| .obact = OBACT(view_layer), | .obact = OBACT(view_layer), | ||||
| .engine_type = engine_type, | .engine_type = engine_type, | ||||
| .depsgraph = depsgraph, | .depsgraph = depsgraph, | ||||
| /* reuse if caller sets */ | /* reuse if caller sets */ | ||||
| .evil_C = DST.draw_ctx.evil_C, | .evil_C = DST.draw_ctx.evil_C, | ||||
| }; | }; | ||||
| BLI_assert(DST.task_graph == NULL); | |||||
| DST.task_graph = BLI_task_graph_create(); | |||||
| drw_context_state_init(); | drw_context_state_init(); | ||||
| drw_viewport_var_init(); | drw_viewport_var_init(); | ||||
| drw_viewport_colormanagement_set(); | drw_viewport_colormanagement_set(); | ||||
| const int object_type_exclude_viewport = v3d->object_type_exclude_viewport; | const int object_type_exclude_viewport = v3d->object_type_exclude_viewport; | ||||
| /* Check if scene needs to perform the populate loop */ | /* Check if scene needs to perform the populate loop */ | ||||
| const bool internal_engine = (engine_type->flag & RE_INTERNAL) != 0; | const bool internal_engine = (engine_type->flag & RE_INTERNAL) != 0; | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | /* Cache filling */ | ||||
| DRW_render_instance_buffer_finish(); | DRW_render_instance_buffer_finish(); | ||||
| #ifdef USE_PROFILE | #ifdef USE_PROFILE | ||||
| double *cache_time = GPU_viewport_cache_time_get(DST.viewport); | double *cache_time = GPU_viewport_cache_time_get(DST.viewport); | ||||
| PROFILE_END_UPDATE(*cache_time, stime); | PROFILE_END_UPDATE(*cache_time, stime); | ||||
| #endif | #endif | ||||
| } | } | ||||
| BLI_task_graph_work_and_wait(DST.task_graph); | |||||
| BLI_task_graph_free(DST.task_graph); | |||||
| DST.task_graph = NULL; | |||||
| DRW_stats_begin(); | DRW_stats_begin(); | ||||
| GPU_framebuffer_bind(DST.default_framebuffer); | GPU_framebuffer_bind(DST.default_framebuffer); | ||||
| /* Start Drawing */ | /* Start Drawing */ | ||||
| DRW_state_reset(); | DRW_state_reset(); | ||||
| GPU_framebuffer_bind(DST.default_framebuffer); | GPU_framebuffer_bind(DST.default_framebuffer); | ||||
| ▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph) | ||||
| * This shall remain in effect until immediate mode supports | * This shall remain in effect until immediate mode supports | ||||
| * multiple threads. */ | * multiple threads. */ | ||||
| /* Reset before using it. */ | /* Reset before using it. */ | ||||
| drw_state_prepare_clean_for_draw(&DST); | drw_state_prepare_clean_for_draw(&DST); | ||||
| DST.options.is_image_render = true; | DST.options.is_image_render = true; | ||||
| DST.options.is_scene_render = true; | DST.options.is_scene_render = true; | ||||
| DST.options.draw_background = scene->r.alphamode == R_ADDSKY; | DST.options.draw_background = scene->r.alphamode == R_ADDSKY; | ||||
| DST.draw_ctx = (DRWContextState){ | DST.draw_ctx = (DRWContextState){ | ||||
| .scene = scene, | .scene = scene, | ||||
| .view_layer = view_layer, | .view_layer = view_layer, | ||||
| .engine_type = engine_type, | .engine_type = engine_type, | ||||
| .depsgraph = depsgraph, | .depsgraph = depsgraph, | ||||
| .object_mode = OB_MODE_OBJECT, | .object_mode = OB_MODE_OBJECT, | ||||
| }; | }; | ||||
| drw_context_state_init(); | drw_context_state_init(); | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| void DRW_render_object_iter( | void DRW_render_object_iter( | ||||
| void *vedata, | void *vedata, | ||||
| RenderEngine *engine, | RenderEngine *engine, | ||||
| struct Depsgraph *depsgraph, | struct Depsgraph *depsgraph, | ||||
| void (*callback)(void *vedata, Object *ob, RenderEngine *engine, struct Depsgraph *depsgraph)) | void (*callback)(void *vedata, Object *ob, RenderEngine *engine, struct Depsgraph *depsgraph)) | ||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| DRW_hair_init(); | DRW_hair_init(); | ||||
| BLI_assert(DST.task_graph == NULL); | |||||
| DST.task_graph = BLI_task_graph_create(); | |||||
| const int object_type_exclude_viewport = draw_ctx->v3d ? | const int object_type_exclude_viewport = draw_ctx->v3d ? | ||||
| draw_ctx->v3d->object_type_exclude_viewport : | draw_ctx->v3d->object_type_exclude_viewport : | ||||
| 0; | 0; | ||||
| DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN (depsgraph, ob) { | DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN (depsgraph, ob) { | ||||
| if ((object_type_exclude_viewport & (1 << ob->type)) == 0) { | if ((object_type_exclude_viewport & (1 << ob->type)) == 0) { | ||||
| DST.dupli_parent = data_.dupli_parent; | DST.dupli_parent = data_.dupli_parent; | ||||
| DST.dupli_source = data_.dupli_object_current; | DST.dupli_source = data_.dupli_object_current; | ||||
| DST.ob_handle = 0; | DST.ob_handle = 0; | ||||
| drw_duplidata_load(DST.dupli_source); | drw_duplidata_load(DST.dupli_source); | ||||
| if (!DST.dupli_source) { | if (!DST.dupli_source) { | ||||
| drw_batch_cache_validate(ob); | drw_batch_cache_validate(ob); | ||||
| } | } | ||||
| callback(vedata, ob, engine, depsgraph); | callback(vedata, ob, engine, depsgraph); | ||||
| if (!DST.dupli_source) { | if (!DST.dupli_source) { | ||||
| drw_batch_cache_generate_requested(ob); | drw_batch_cache_generate_requested(ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; | DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; | ||||
| drw_duplidata_free(); | drw_duplidata_free(); | ||||
| BLI_task_graph_work_and_wait(DST.task_graph); | |||||
| BLI_task_graph_free(DST.task_graph); | |||||
| DST.task_graph = NULL; | |||||
| } | } | ||||
| /* Assume a valid gl context is bound (and that the gl_context_mutex has been acquired). | /* Assume a valid gl context is bound (and that the gl_context_mutex has been acquired). | ||||
| * This function only setup DST and execute the given function. | * This function only setup DST and execute the given function. | ||||
| * Warning: similar to DRW_render_to_image you cannot use default lists (dfbl & dtxl). */ | * Warning: similar to DRW_render_to_image you cannot use default lists (dfbl & dtxl). */ | ||||
| void DRW_custom_pipeline(DrawEngineType *draw_engine_type, | void DRW_custom_pipeline(DrawEngineType *draw_engine_type, | ||||
| struct Depsgraph *depsgraph, | struct Depsgraph *depsgraph, | ||||
| void (*callback)(void *vedata, void *user_data), | void (*callback)(void *vedata, void *user_data), | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | #else | ||||
| } | } | ||||
| int viewport_size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)}; | int viewport_size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)}; | ||||
| struct GPUViewport *viewport = GPU_viewport_create(); | struct GPUViewport *viewport = GPU_viewport_create(); | ||||
| GPU_viewport_size_set(viewport, viewport_size); | GPU_viewport_size_set(viewport, viewport_size); | ||||
| DST.viewport = viewport; | DST.viewport = viewport; | ||||
| DST.options.is_select = true; | DST.options.is_select = true; | ||||
| BLI_assert(DST.task_graph == NULL); | |||||
| DST.task_graph = BLI_task_graph_create(); | |||||
| /* Get list of enabled engines */ | /* Get list of enabled engines */ | ||||
| if (use_obedit) { | if (use_obedit) { | ||||
| drw_engines_enable_overlays(); | drw_engines_enable_overlays(); | ||||
| } | } | ||||
| else if (!draw_surface) { | else if (!draw_surface) { | ||||
| /* grease pencil selection */ | /* grease pencil selection */ | ||||
| if (drw_gpencil_engine_needed(depsgraph, v3d)) { | if (drw_gpencil_engine_needed(depsgraph, v3d)) { | ||||
| use_drw_engine(&draw_engine_gpencil_type); | use_drw_engine(&draw_engine_gpencil_type); | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | else { | ||||
| drw_duplidata_load(DST.dupli_source); | drw_duplidata_load(DST.dupli_source); | ||||
| drw_engines_cache_populate(ob); | drw_engines_cache_populate(ob); | ||||
| } | } | ||||
| } | } | ||||
| DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; | DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; | ||||
| } | } | ||||
| drw_duplidata_free(); | drw_duplidata_free(); | ||||
| BLI_task_graph_work_and_wait(DST.task_graph); | |||||
| BLI_task_graph_free(DST.task_graph); | |||||
| DST.task_graph = NULL; | |||||
| drw_engines_cache_finish(); | drw_engines_cache_finish(); | ||||
| DRW_render_instance_buffer_finish(); | DRW_render_instance_buffer_finish(); | ||||
| } | } | ||||
| /* Setup framebuffer */ | /* Setup framebuffer */ | ||||
| draw_select_framebuffer_depth_only_setup(viewport_size); | draw_select_framebuffer_depth_only_setup(viewport_size); | ||||
| GPU_framebuffer_bind(g_select_buffer.framebuffer_depth_only); | GPU_framebuffer_bind(g_select_buffer.framebuffer_depth_only); | ||||
| ▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | case OB_MESH: { | ||||
| Mesh *me = object->data; | Mesh *me = object->data; | ||||
| if (object->mode & OB_MODE_EDIT) { | if (object->mode & OB_MODE_EDIT) { | ||||
| batch = DRW_mesh_batch_cache_get_edit_triangles(me); | batch = DRW_mesh_batch_cache_get_edit_triangles(me); | ||||
| } | } | ||||
| else { | else { | ||||
| batch = DRW_mesh_batch_cache_get_surface(me); | batch = DRW_mesh_batch_cache_get_surface(me); | ||||
| } | } | ||||
| struct TaskGraph *task_graph = BLI_task_graph_create(); | |||||
| DRW_mesh_batch_cache_create_requested(object, me, scene, false, true); | DRW_mesh_batch_cache_create_requested(task_graph, object, me, scene, false, true); | ||||
| BLI_task_graph_work_and_wait(task_graph); | |||||
| BLI_task_graph_free(task_graph); | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | ||||
| GPU_SHADER_CFG_DEFAULT; | GPU_SHADER_CFG_DEFAULT; | ||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg); | GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg); | ||||
| if (world_clip_planes != NULL) { | if (world_clip_planes != NULL) { | ||||
| draw_world_clip_planes_from_rv3d(batch, world_clip_planes); | draw_world_clip_planes_from_rv3d(batch, world_clip_planes); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 410 Lines • Show Last 20 Lines | |||||