Compositor: Refactor backdrop offset
This patch refactors the backdrop offset to be stored as a float instead of an int and to be stored in the image runtime structure instead of the image itself. Pull Request: https://projects.blender.org/blender/blender/pulls/119877
This commit is contained in:
parent
3b3a6ccecd
commit
6d7b4e049e
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue