diff --git a/source/blender/compositor/COM_context.hh b/source/blender/compositor/COM_context.hh index 7ea31839214..6f03db938c2 100644 --- a/source/blender/compositor/COM_context.hh +++ b/source/blender/compositor/COM_context.hh @@ -6,11 +6,11 @@ #include +#include "BLI_bounds_types.hh" #include "BLI_math_vector_types.hh" #include "BLI_string_ref.hh" #include "DNA_scene_types.h" -#include "DNA_vec_types.h" #include "GPU_shader.hh" @@ -66,7 +66,7 @@ class Context { * render region. In other cases, the compositing region might be a subset of the render region. * Callers should check the validity of the region through is_valid_compositing_region(), since * the region can be zero sized. */ - virtual rcti get_compositing_region() const = 0; + virtual Bounds get_compositing_region() const = 0; /* Get the result where the result of the compositor should be written. */ virtual Result get_output() = 0; diff --git a/source/blender/compositor/intern/context.cc b/source/blender/compositor/intern/context.cc index 71db4f77d0b..aba67d6579a 100644 --- a/source/blender/compositor/intern/context.cc +++ b/source/blender/compositor/intern/context.cc @@ -2,11 +2,10 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ +#include "BLI_bounds.hh" #include "BLI_math_vector.hh" -#include "BLI_rect.h" #include "DNA_node_types.h" -#include "DNA_vec_types.h" #include "GPU_shader.hh" @@ -70,18 +69,12 @@ void Context::reset() int2 Context::get_compositing_region_size() const { - const rcti compositing_region = get_compositing_region(); - const int x = BLI_rcti_size_x(&compositing_region); - const int y = BLI_rcti_size_y(&compositing_region); - return math::max(int2(1), int2(x, y)); + return math::max(int2(1), this->get_compositing_region().size()); } bool Context::is_valid_compositing_region() const { - const rcti compositing_region = get_compositing_region(); - const int x = BLI_rcti_size_x(&compositing_region); - const int y = BLI_rcti_size_y(&compositing_region); - return x != 0 && y != 0; + return !this->get_compositing_region().is_empty(); } float Context::get_render_percentage() const diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc index 85cb9dfed7c..129fa9990d1 100644 --- a/source/blender/draw/engines/compositor/compositor_engine.cc +++ b/source/blender/draw/engines/compositor/compositor_engine.cc @@ -2,9 +2,9 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ +#include "BLI_bounds.hh" #include "BLI_listbase.h" #include "BLI_math_vector_types.hh" -#include "BLI_rect.h" #include "BLI_string_ref.hh" #include "BLI_utildefines.h" @@ -88,11 +88,11 @@ class Context : public compositor::Context { /* We limit the compositing region to the camera region if in camera view, while we use the * entire viewport otherwise. We also use the entire viewport when doing viewport rendering since * the viewport is already the camera region in that case. */ - rcti get_compositing_region() const override + Bounds get_compositing_region() const override { const DRWContext *draw_ctx = DRW_context_get(); const int2 viewport_size = int2(draw_ctx->viewport_size_get()); - const rcti render_region = rcti{0, viewport_size.x, 0, viewport_size.y}; + const Bounds render_region = Bounds(int2(0), viewport_size); if (draw_ctx->rv3d->persp != RV3D_CAMOB || draw_ctx->is_viewport_image_render()) { return render_region; @@ -107,13 +107,12 @@ class Context : public compositor::Context { false, &camera_border); - rcti camera_region; - BLI_rcti_rctf_copy_floor(&camera_region, &camera_border); + const Bounds camera_region = Bounds( + int2(int(camera_border.xmin), int(camera_border.ymin)), + int2(int(camera_border.xmax), int(camera_border.ymax))); - rcti visible_camera_region; - BLI_rcti_isect(&render_region, &camera_region, &visible_camera_region); - - return visible_camera_region; + return blender::bounds::intersect(render_region, camera_region) + .value_or(Bounds(int2(0))); } compositor::Result get_output() override diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc index 18eab542a54..5d503edaf54 100644 --- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc @@ -836,8 +836,7 @@ class CryptoMatteOperation : public BaseCryptoMatteOperation { { switch (get_source()) { case CMP_NODE_CRYPTOMATTE_SOURCE_RENDER: { - const rcti compositing_region = this->context().get_compositing_region(); - return int2(compositing_region.xmin, compositing_region.ymin); + return this->context().get_compositing_region().min; } case CMP_NODE_CRYPTOMATTE_SOURCE_IMAGE: return int2(0); diff --git a/source/blender/nodes/composite/nodes/node_composite_group_input.cc b/source/blender/nodes/composite/nodes/node_composite_group_input.cc index eb75bf7625b..98a1747b6a8 100644 --- a/source/blender/nodes/composite/nodes/node_composite_group_input.cc +++ b/source/blender/nodes/composite/nodes/node_composite_group_input.cc @@ -73,8 +73,7 @@ class GroupInputOperation : public NodeOperation { /* The compositing space might be limited to a subset of the pass texture, so only read that * compositing region into an appropriately sized result. */ - const rcti compositing_region = this->context().get_compositing_region(); - const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin); + const int2 lower_bound = this->context().get_compositing_region().min; GPU_shader_uniform_2iv(shader, "lower_bound", lower_bound); pass.bind_as_texture(shader, "input_tx"); @@ -119,8 +118,7 @@ class GroupInputOperation : public NodeOperation { { /* The compositing space might be limited to a subset of the pass texture, so only read that * compositing region into an appropriately sized result. */ - const rcti compositing_region = this->context().get_compositing_region(); - const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin); + const int2 lower_bound = this->context().get_compositing_region().min; result.allocate_texture(Domain(this->context().get_compositing_region_size())); diff --git a/source/blender/nodes/composite/nodes/node_composite_group_output.cc b/source/blender/nodes/composite/nodes/node_composite_group_output.cc index 1b2467a8ddf..82bd7710789 100644 --- a/source/blender/nodes/composite/nodes/node_composite_group_output.cc +++ b/source/blender/nodes/composite/nodes/node_composite_group_output.cc @@ -95,7 +95,7 @@ class GroupOutputOperation : public NodeOperation { GPUShader *shader = this->context().get_shader("compositor_write_output", output.precision()); GPU_shader_bind(shader); - const Bounds bounds = this->get_output_bounds(); + const Bounds bounds = this->context().get_compositing_region(); GPU_shader_uniform_2iv(shader, "lower_bound", bounds.min); GPU_shader_uniform_2iv(shader, "upper_bound", bounds.max); @@ -115,7 +115,7 @@ class GroupOutputOperation : public NodeOperation { const Domain domain = this->compute_domain(); Result output = this->context().get_output(); - const Bounds bounds = this->get_output_bounds(); + const Bounds bounds = this->context().get_compositing_region(); parallel_for(domain.size, [&](const int2 texel) { const int2 output_texel = texel + bounds.min; if (output_texel.x > bounds.max.x || output_texel.y > bounds.max.y) { @@ -125,15 +125,6 @@ class GroupOutputOperation : public NodeOperation { }); } - /* Returns the bounds of the area of the compositing region. Only write into the compositing - * region, which might be limited to a smaller region of the output result. */ - Bounds get_output_bounds() - { - const rcti compositing_region = this->context().get_compositing_region(); - return Bounds(int2(compositing_region.xmin, compositing_region.ymin), - int2(compositing_region.xmax, compositing_region.ymax)); - } - /* The operation domain has the same size as the compositing region without any transformations * applied. */ Domain compute_domain() override diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc index c77f8b49d6f..aaad2f62243 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.cc +++ b/source/blender/nodes/composite/nodes/node_composite_image.cc @@ -755,8 +755,7 @@ class RenderLayerOperation : public NodeOperation { /* The compositing space might be limited to a subset of the pass texture, so only read that * compositing region into an appropriately sized result. */ - const rcti compositing_region = this->context().get_compositing_region(); - const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin); + const int2 lower_bound = this->context().get_compositing_region().min; GPU_shader_uniform_2iv(shader, "lower_bound", lower_bound); pass.bind_as_texture(shader, "input_tx"); @@ -806,8 +805,7 @@ class RenderLayerOperation : public NodeOperation { { /* The compositing space might be limited to a subset of the pass texture, so only read that * compositing region into an appropriately sized result. */ - const rcti compositing_region = this->context().get_compositing_region(); - const int2 lower_bound = int2(compositing_region.xmin, compositing_region.ymin); + const int2 lower_bound = this->context().get_compositing_region().min; result.allocate_texture(Domain(this->context().get_compositing_region_size())); diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.cc b/source/blender/nodes/composite/nodes/node_composite_viewer.cc index ddb2b80bc69..309fa48df9b 100644 --- a/source/blender/nodes/composite/nodes/node_composite_viewer.cc +++ b/source/blender/nodes/composite/nodes/node_composite_viewer.cc @@ -143,14 +143,12 @@ class ViewerOperation : public NodeOperation { { /* Viewers are treated as composite outputs that should be in the bounds of the compositing * region. */ - if (context().treat_viewer_as_compositor_output()) { - const rcti compositing_region = context().get_compositing_region(); - return Bounds(int2(compositing_region.xmin, compositing_region.ymin), - int2(compositing_region.xmax, compositing_region.ymax)); + if (this->context().treat_viewer_as_compositor_output()) { + return this->context().get_compositing_region(); } /* Otherwise, use the bounds of the input as is. */ - return Bounds(int2(0), compute_domain().size); + return Bounds(int2(0), this->compute_domain().size); } Domain compute_domain() override diff --git a/source/blender/render/intern/compositor.cc b/source/blender/render/intern/compositor.cc index df7c2dcbc05..2adfb3b6112 100644 --- a/source/blender/render/intern/compositor.cc +++ b/source/blender/render/intern/compositor.cc @@ -165,12 +165,9 @@ class Context : public compositor::Context { return size; } - rcti get_compositing_region() const override + Bounds get_compositing_region() const override { - const int2 render_size = get_render_size(); - const rcti render_region = rcti{0, render_size.x, 0, render_size.y}; - - return render_region; + return Bounds(int2(0), this->get_render_size()); } compositor::Result get_output() override