diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index d99dcf8dfa5..b770952b735 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -133,6 +133,9 @@ static void image_runtime_reset_on_copy(Image *image) image->runtime.partial_update_register = nullptr; image->runtime.partial_update_user = nullptr; + + image->runtime.backdrop_offset[0] = 0.0f; + image->runtime.backdrop_offset[1] = 0.0f; } static void image_runtime_free_data(Image *image) diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cc b/source/blender/compositor/operations/COM_ViewerOperation.cc index e0f34c527cd..ef4b6056f7b 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.cc +++ b/source/blender/compositor/operations/COM_ViewerOperation.cc @@ -110,8 +110,8 @@ void ViewerOperation::update_image(const rcti *rect) return; } - image_->offset_x = canvas_.xmin; - image_->offset_y = canvas_.ymin; + image_->runtime.backdrop_offset[0] = canvas_.xmin; + image_->runtime.backdrop_offset[1] = canvas_.ymin; float *buffer = output_buffer_; IMB_partial_display_buffer_update(ibuf_, buffer, diff --git a/source/blender/draw/engines/image/image_engine.cc b/source/blender/draw/engines/image/image_engine.cc index e1401ef7b24..f9019dbb1c2 100644 --- a/source/blender/draw/engines/image/image_engine.cc +++ b/source/blender/draw/engines/image/image_engine.cc @@ -100,10 +100,10 @@ class ImageEngine { /* Setup the matrix to go from screen UV coordinates to UV texture space coordinates. */ float image_resolution[2] = {image_buffer ? image_buffer->x : 1024.0f, image_buffer ? image_buffer->y : 1024.0f}; - float image_offset[2] = {float(instance_data->image->offset_x), - float(instance_data->image->offset_y)}; - space->init_ss_to_texture_matrix( - draw_ctx->region, image_offset, image_resolution, instance_data->ss_to_texture); + space->init_ss_to_texture_matrix(draw_ctx->region, + instance_data->image->runtime.backdrop_offset, + image_resolution, + instance_data->ss_to_texture); const Scene *scene = DRW_context_state_get()->scene; instance_data->sh_params.update(space.get(), scene, instance_data->image, image_buffer); diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 8078fac9fa8..63b72f39c9a 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1673,8 +1673,8 @@ void draw_nodespace_back_pix(const bContext &C, if (ibuf) { /* somehow the offset has to be calculated inverse */ wmOrtho2_region_pixelspace(®ion); - const float offset_x = snode.xof + ima->offset_x * snode.zoom; - const float offset_y = snode.yof + ima->offset_y * snode.zoom; + const float offset_x = snode.xof + ima->runtime.backdrop_offset[0] * snode.zoom; + const float offset_y = snode.yof + ima->runtime.backdrop_offset[1] * snode.zoom; const float x = (region.winx - snode.zoom * ibuf->x) / 2 + offset_x; const float y = (region.winy - snode.zoom * ibuf->y) / 2 + offset_y; diff --git a/source/blender/editors/space_node/node_gizmo.cc b/source/blender/editors/space_node/node_gizmo.cc index 0a33af4984c..9378cf0154a 100644 --- a/source/blender/editors/space_node/node_gizmo.cc +++ b/source/blender/editors/space_node/node_gizmo.cc @@ -468,7 +468,7 @@ static void WIDGETGROUP_node_sbeam_refresh(const bContext *C, wmGizmoGroup *gzgr if (ibuf) { sbeam_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; sbeam_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; - sbeam_group->state.offset = {float(ima->offset_x), float(ima->offset_y)}; + copy_v2_v2(sbeam_group->state.offset, ima->runtime.backdrop_offset); SpaceNode *snode = CTX_wm_space_node(C); bNode *node = nodeGetActive(snode->edittree); @@ -582,7 +582,7 @@ static void WIDGETGROUP_node_corner_pin_refresh(const bContext *C, wmGizmoGroup if (ibuf) { cpin_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; cpin_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; - cpin_group->state.offset = {float(ima->offset_x), float(ima->offset_y)}; + copy_v2_v2(cpin_group->state.offset, ima->runtime.backdrop_offset); SpaceNode *snode = CTX_wm_space_node(C); bNode *node = nodeGetActive(snode->edittree); diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h index 9d5c0af59f7..0dc877fd85f 100644 --- a/source/blender/makesdna/DNA_image_types.h +++ b/source/blender/makesdna/DNA_image_types.h @@ -132,6 +132,9 @@ typedef struct Image_Runtime { /** \brief Partial update user for GPUTextures stored inside the Image. */ struct PartialUpdateUser *partial_update_user; + /* Compositor viewer might be translated, and that translation will be stored in this runtime + * vector by the compositor so that the editor draw code can draw the image translated. */ + float backdrop_offset[2]; } Image_Runtime; typedef struct Image { @@ -201,9 +204,6 @@ typedef struct Image { char eye; char views_format; - /** Offset caused by translation. Used in compositor backdrop for viewer nodes in image space. */ - int offset_x, offset_y; - /* ImageTile list for UDIMs. */ int active_tile_index; ListBase tiles; diff --git a/source/blender/render/intern/compositor.cc b/source/blender/render/intern/compositor.cc index 13cf34617f3..117d3940acb 100644 --- a/source/blender/render/intern/compositor.cc +++ b/source/blender/render/intern/compositor.cc @@ -272,8 +272,8 @@ class Context : public realtime_compositor::Context { Image *image = BKE_image_ensure_viewer(G.main, IMA_TYPE_COMPOSITE, "Viewer Node"); const float2 translation = domain.transformation.location(); - image->offset_x = int(translation.x); - image->offset_y = int(translation.y); + image->runtime.backdrop_offset[0] = translation.x; + image->runtime.backdrop_offset[1] = translation.y; return viewer_output_texture_; }