Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/external/external_engine.c
| Show First 20 Lines • Show All 290 Lines • ▼ Show 20 Lines | static void external_draw_scene_do_v3d(void *vedata) | ||||
| if (rv3d->render_engine->text[0] != '\0') { | if (rv3d->render_engine->text[0] != '\0') { | ||||
| BLI_strncpy(data->info, rv3d->render_engine->text, sizeof(data->info)); | BLI_strncpy(data->info, rv3d->render_engine->text, sizeof(data->info)); | ||||
| } | } | ||||
| else { | else { | ||||
| data->info[0] = '\0'; | data->info[0] = '\0'; | ||||
| } | } | ||||
| } | } | ||||
| /* Get render engine of the current scene. | |||||
| * | |||||
| * Note that existence of the engine does not correlate with the rendering scene of the scene: | |||||
| * the engine could be non-NULL if the scene used persistent data. Or, if the scene is just | |||||
| * beginning to render the engine might not be existing yet. */ | |||||
| static RenderEngine *external_engine_get(void) | |||||
| { | |||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| Scene *scene = draw_ctx->scene; | |||||
| Render *re = RE_GetSceneRender(scene); | |||||
| if (re == NULL) { | |||||
| return NULL; | |||||
| } | |||||
| return RE_engine_get(re); | |||||
| } | |||||
| /* Configure current matrix stack so that the external engine can use the same drawing code for | /* Configure current matrix stack so that the external engine can use the same drawing code for | ||||
| * both viewport and image editor drawing. | * both viewport and image editor drawing. | ||||
| * | * | ||||
| * The engine draws result in the pixel space, and is applying render offset. For image editor we | * The engine draws result in the pixel space, and is applying render offset. For image editor we | ||||
| * need to switch from normalized space to pixel space, and "un-apply" offset. */ | * need to switch from normalized space to pixel space, and "un-apply" offset. */ | ||||
| static void external_image_space_matrix_set(const RenderEngine *engine) | static void external_image_space_matrix_set(const RenderEngine *engine) | ||||
| { | { | ||||
| BLI_assert(engine != NULL); | BLI_assert(engine != NULL); | ||||
| Show All 32 Lines | /* Un-apply render offset. */ | ||||
| RE_GetViewPlane(render, &view_rect, &render_rect); | RE_GetViewPlane(render, &view_rect, &render_rect); | ||||
| GPU_matrix_translate_2f(-render_rect.xmin, -render_rect.ymin); | GPU_matrix_translate_2f(-render_rect.xmin, -render_rect.ymin); | ||||
| } | } | ||||
| } | } | ||||
| static void external_draw_scene_do_image(void *UNUSED(vedata)) | static void external_draw_scene_do_image(void *UNUSED(vedata)) | ||||
| { | { | ||||
| RenderEngine *engine = external_engine_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| if (engine == NULL) { | Scene *scene = draw_ctx->scene; | ||||
| return; | Render *re = RE_GetSceneRender(scene); | ||||
| } | RenderEngine *engine = RE_engine_get(re); | ||||
| /* Is tested before enabling the drawing engine. */ | |||||
| BLI_assert(re != NULL); | |||||
| BLI_assert(engine != NULL); | |||||
| const DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | const DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); | ||||
| /* Clear the depth buffer to the value used by the background overlay so that the overlay is not | /* Clear the depth buffer to the value used by the background overlay so that the overlay is not | ||||
| * happening outside of the drawn image. | * happening outside of the drawn image. | ||||
| * | * | ||||
| * NOTE: The external engine only draws color. The depth is taken care of using the depth pass | * NOTE: The external engine only draws color. The depth is taken care of using the depth pass | ||||
| * which initialized the depth to the values expected by the background overlay. */ | * which initialized the depth to the values expected by the background overlay. */ | ||||
| GPU_framebuffer_clear_depth(dfbl->default_fb, 1.0f); | GPU_framebuffer_clear_depth(dfbl->default_fb, 1.0f); | ||||
| GPU_matrix_push_projection(); | GPU_matrix_push_projection(); | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| external_image_space_matrix_set(engine); | external_image_space_matrix_set(engine); | ||||
| GPU_debug_group_begin("External Engine"); | GPU_debug_group_begin("External Engine"); | ||||
| const RenderEngineType *engine_type = engine->type; | const RenderEngineType *engine_type = engine->type; | ||||
| BLI_assert(engine_type != NULL); | BLI_assert(engine_type != NULL); | ||||
| BLI_assert(engine_type->draw != NULL); | BLI_assert(engine_type->draw != NULL); | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| engine_type->draw(engine, draw_ctx->evil_C, draw_ctx->depsgraph); | engine_type->draw(engine, draw_ctx->evil_C, draw_ctx->depsgraph); | ||||
| GPU_debug_group_end(); | GPU_debug_group_end(); | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| GPU_matrix_pop_projection(); | GPU_matrix_pop_projection(); | ||||
| DRW_state_reset(); | DRW_state_reset(); | ||||
| GPU_bgl_end(); | GPU_bgl_end(); | ||||
| RE_engine_draw_release(re); | |||||
| } | } | ||||
| static void external_draw_scene_do(void *vedata) | static void external_draw_scene_do(void *vedata) | ||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| if (draw_ctx->v3d != NULL) { | if (draw_ctx->v3d != NULL) { | ||||
| external_draw_scene_do_v3d(vedata); | external_draw_scene_do_v3d(vedata); | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | RenderEngineType DRW_engine_viewport_external_type = { | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| &draw_engine_external_type, | &draw_engine_external_type, | ||||
| {NULL, NULL, NULL}, | {NULL, NULL, NULL}, | ||||
| }; | }; | ||||
| bool DRW_engine_external_use_for_image_editor(void) | bool DRW_engine_external_acquire_for_image_editor(void) | ||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| const SpaceLink *space_data = draw_ctx->space_data; | const SpaceLink *space_data = draw_ctx->space_data; | ||||
| Scene *scene = draw_ctx->scene; | |||||
| if (space_data == NULL) { | if (space_data == NULL) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const eSpace_Type space_type = draw_ctx->space_data->spacetype; | const eSpace_Type space_type = draw_ctx->space_data->spacetype; | ||||
| if (space_type != SPACE_IMAGE) { | if (space_type != SPACE_IMAGE) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| struct SpaceImage *space_image = (struct SpaceImage *)space_data; | struct SpaceImage *space_image = (struct SpaceImage *)space_data; | ||||
| const Image *image = ED_space_image(space_image); | const Image *image = ED_space_image(space_image); | ||||
| if (image == NULL || image->type != IMA_TYPE_R_RESULT) { | if (image == NULL || image->type != IMA_TYPE_R_RESULT) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (image->render_slot != image->last_render_slot) { | if (image->render_slot != image->last_render_slot) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| RenderEngine *engine = external_engine_get(); | /* Render is allocated on main thread, so it is safe to access it from here. */ | ||||
| if (engine == NULL) { | Render *re = RE_GetSceneRender(scene); | ||||
| return false; | |||||
| } | |||||
| if (!RE_engine_is_rendering(engine->re)) { | |||||
| return false; | |||||
| } | |||||
| const RenderEngineType *engine_type = engine->type; | |||||
| BLI_assert(engine_type != NULL); | |||||
| if (engine_type->draw == NULL) { | |||||
| return false; | |||||
| } | |||||
| return true; | return RE_engine_draw_acquire(re); | ||||
brecht: I suggest `return RE_engine_draw_acquire(re);` | |||||
| } | } | ||||
| #undef EXTERNAL_ENGINE | #undef EXTERNAL_ENGINE | ||||
I suggest return RE_engine_draw_acquire(re);