Refactor: Use Bounds for compositing region
This patch uses the new C++ Bounds structure for the composition region returned by the compositor context. Pull Request: https://projects.blender.org/blender/blender/pulls/143199
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#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<int2> get_compositing_region() const = 0;
|
||||
|
||||
/* Get the result where the result of the compositor should be written. */
|
||||
virtual Result get_output() = 0;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int2> 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<int2> render_region = Bounds<int2>(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<int2> camera_region = Bounds<int2>(
|
||||
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>(int2(0)));
|
||||
}
|
||||
|
||||
compositor::Result get_output() override
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()));
|
||||
|
||||
|
||||
@@ -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<int2> bounds = this->get_output_bounds();
|
||||
const Bounds<int2> 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<int2> bounds = this->get_output_bounds();
|
||||
const Bounds<int2> 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<int2> get_output_bounds()
|
||||
{
|
||||
const rcti compositing_region = this->context().get_compositing_region();
|
||||
return Bounds<int2>(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
|
||||
|
||||
@@ -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()));
|
||||
|
||||
|
||||
@@ -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>(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>(int2(0), compute_domain().size);
|
||||
return Bounds<int2>(int2(0), this->compute_domain().size);
|
||||
}
|
||||
|
||||
Domain compute_domain() override
|
||||
|
||||
@@ -165,12 +165,9 @@ class Context : public compositor::Context {
|
||||
return size;
|
||||
}
|
||||
|
||||
rcti get_compositing_region() const override
|
||||
Bounds<int2> 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>(int2(0), this->get_render_size());
|
||||
}
|
||||
|
||||
compositor::Result get_output() override
|
||||
|
||||
Reference in New Issue
Block a user