Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_image.c
| Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static struct GPUTexture *image_camera_background_texture_get(CameraBGImage *bgpic, | static struct GPUTexture *image_camera_background_texture_get(CameraBGImage *bgpic, | ||||
| const DRWContextState *draw_ctx, | const DRWContextState *draw_ctx, | ||||
| OVERLAY_PrivateData *pd, | OVERLAY_PrivateData *pd, | ||||
| float *r_aspect, | float *r_aspect, | ||||
| bool *r_use_alpha_premult) | bool *r_use_alpha_premult) | ||||
| { | { | ||||
| void *lock; | |||||
| Image *image = bgpic->ima; | Image *image = bgpic->ima; | ||||
| ImageUser *iuser = &bgpic->iuser; | ImageUser *iuser = &bgpic->iuser; | ||||
| MovieClip *clip = NULL; | MovieClip *clip = NULL; | ||||
| GPUTexture *tex = NULL; | GPUTexture *tex = NULL; | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| float aspect_x, aspect_y; | float aspect_x, aspect_y; | ||||
| int width, height; | int width, height; | ||||
| int ctime = (int)DEG_get_ctime(draw_ctx->depsgraph); | int ctime = (int)DEG_get_ctime(draw_ctx->depsgraph); | ||||
| *r_use_alpha_premult = false; | *r_use_alpha_premult = false; | ||||
brecht: Move this code to right above `BKE_image_acquire_ibuf`, now there are cases where it's not… | |||||
| switch (bgpic->source) { | switch (bgpic->source) { | ||||
| case CAM_BGIMG_SOURCE_IMAGE: | case CAM_BGIMG_SOURCE_IMAGE: | ||||
| if (image == NULL) { | if (image == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| *r_use_alpha_premult = (image->alpha_mode == IMA_ALPHA_PREMUL); | *r_use_alpha_premult = (image->alpha_mode == IMA_ALPHA_PREMUL); | ||||
| BKE_image_user_frame_calc(image, iuser, ctime); | BKE_image_user_frame_calc(image, iuser, ctime); | ||||
| if (image->source == IMA_SRC_SEQUENCE && !(iuser->flag & IMA_USER_FRAME_IN_RANGE)) { | if (image->source == IMA_SRC_SEQUENCE && !(iuser->flag & IMA_USER_FRAME_IN_RANGE)) { | ||||
| /* Frame is out of range, dont show. */ | /* Frame is out of range, dont show. */ | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| camera_background_images_stereo_setup(scene, draw_ctx->v3d, image, iuser); | camera_background_images_stereo_setup(scene, draw_ctx->v3d, image, iuser); | ||||
| } | } | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(image, iuser, NULL); | iuser->scene = draw_ctx->scene; | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(image, iuser, &lock); | |||||
| if (ibuf == NULL) { | if (ibuf == NULL) { | ||||
| BKE_image_release_ibuf(image, ibuf, lock); | |||||
| iuser->scene = NULL; | |||||
| return NULL; | return NULL; | ||||
Done Inline ActionsYou still have to call BKE_image_release_ibuf if the image buffer returned is NULL. brecht: You still have to call `BKE_image_release_ibuf` if the image buffer returned is `NULL`. | |||||
| } | } | ||||
| width = ibuf->x; | |||||
| height = ibuf->y; | |||||
| tex = GPU_texture_from_blender(image, iuser, ibuf, GL_TEXTURE_2D); | |||||
| BKE_image_release_ibuf(image, ibuf, lock); | |||||
| iuser->scene = NULL; | |||||
| tex = GPU_texture_from_blender(image, iuser, GL_TEXTURE_2D); | |||||
| if (tex == NULL) { | if (tex == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| aspect_x = bgpic->ima->aspx; | aspect_x = bgpic->ima->aspx; | ||||
| aspect_y = bgpic->ima->aspy; | aspect_y = bgpic->ima->aspy; | ||||
| width = ibuf->x; | |||||
| height = ibuf->y; | |||||
| BKE_image_release_ibuf(image, ibuf, NULL); | |||||
| break; | break; | ||||
| case CAM_BGIMG_SOURCE_MOVIE: | case CAM_BGIMG_SOURCE_MOVIE: | ||||
| if (bgpic->flag & CAM_BGIMG_FLAG_CAMERACLIP) { | if (bgpic->flag & CAM_BGIMG_FLAG_CAMERACLIP) { | ||||
| if (scene->camera) { | if (scene->camera) { | ||||
| clip = BKE_object_movieclip_get(scene, scene->camera, true); | clip = BKE_object_movieclip_get(scene, scene->camera, true); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | if (!show_frame) { | ||||
| return; | return; | ||||
| } | } | ||||
| { | { | ||||
| /* Calling 'BKE_image_get_size' may free the texture. Get the size from 'tex' instead, | /* Calling 'BKE_image_get_size' may free the texture. Get the size from 'tex' instead, | ||||
| * see: T59347 */ | * see: T59347 */ | ||||
| int size[2] = {0}; | int size[2] = {0}; | ||||
| if (ima != NULL) { | if (ima != NULL) { | ||||
| tex = GPU_texture_from_blender(ima, ob->iuser, GL_TEXTURE_2D); | tex = GPU_texture_from_blender(ima, ob->iuser, NULL, GL_TEXTURE_2D); | ||||
| if (tex) { | if (tex) { | ||||
| size[0] = GPU_texture_orig_width(tex); | size[0] = GPU_texture_orig_width(tex); | ||||
| size[1] = GPU_texture_orig_height(tex); | size[1] = GPU_texture_orig_height(tex); | ||||
| } | } | ||||
| } | } | ||||
| CLAMP_MIN(size[0], 1); | CLAMP_MIN(size[0], 1); | ||||
| CLAMP_MIN(size[1], 1); | CLAMP_MIN(size[1], 1); | ||||
| ▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines | |||||
Move this code to right above BKE_image_acquire_ibuf, now there are cases where it's not cleared.