Files
test2/source/blender/blenkernel/intern/layer_test.cc
Jacques Lucke b5c89822ac RNA: return PointerRNA from rna create functions
There are a couple of functions that create rna pointers. For example
`RNA_main_pointer_create` and `RNA_pointer_create`. Currently, those
take an output parameter `r_ptr` as last argument. This patch changes
it so that the functions actually return a` PointerRNA` instead of using
the output parameters.

This has a few benefits:
* Output parameters should only be used when there is an actual benefit.
  Otherwise, one should default to returning the value.
* It's simpler to use the API in the large majority of cases (note that this
  patch reduces the number of lines of code).
* It allows the `PointerRNA` to be const on the call-site, if that is desired.

No performance regression has been measured in production files.
If one of these functions happened to be called in a hot loop where
there is a regression, the solution should be to use an inline function
there which allows the compiler to optimize it even better.

Pull Request: https://projects.blender.org/blender/blender/pulls/111976
2023-09-06 00:48:50 +02:00

169 lines
5.8 KiB
C++

/* SPDX-FileCopyrightText: 2020 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "testing/testing.h"
#include "MEM_guardedalloc.h"
#include "BKE_appdir.h"
#include "BKE_idtype.h"
#include "BKE_layer.h"
#include "BLI_string.h"
#include "RE_engine.h"
#include "IMB_imbuf.h"
#include "CLG_log.h"
#include "RNA_access.hh"
#include "RNA_prototypes.h"
#include "GHOST_Path-api.hh"
namespace blender::bke::tests {
TEST(view_layer, aov_unique_names)
{
/* Set Up */
CLG_init();
BKE_idtype_init();
BKE_appdir_init();
IMB_init();
RE_engines_init();
Scene scene = {{nullptr}};
IDType_ID_SCE.init_data(&scene.id);
ViewLayer *view_layer = static_cast<ViewLayer *>(scene.view_layers.first);
RenderEngineType *engine_type = RE_engines_find(scene.r.engine);
RenderEngine *engine = RE_engine_create(engine_type);
EXPECT_FALSE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_EQ(view_layer->active_aov, nullptr);
/* Add an AOV */
ViewLayerAOV *aov1 = BKE_view_layer_add_aov(view_layer);
BKE_view_layer_verify_aov(engine, &scene, view_layer);
EXPECT_EQ(view_layer->active_aov, aov1);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov1->flag & AOV_CONFLICT) != 0);
/* Add a second AOV */
ViewLayerAOV *aov2 = BKE_view_layer_add_aov(view_layer);
BKE_view_layer_verify_aov(engine, &scene, view_layer);
EXPECT_EQ(view_layer->active_aov, aov2);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov1->flag & AOV_CONFLICT) != 0);
EXPECT_FALSE((aov2->flag & AOV_CONFLICT) != 0);
EXPECT_TRUE(STREQ(aov1->name, "AOV"));
EXPECT_TRUE(STREQ(aov2->name, "AOV_001"));
/* Revert previous resolution */
STRNCPY(aov2->name, "AOV");
BKE_view_layer_verify_aov(engine, &scene, view_layer);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov1->flag & AOV_CONFLICT) != 0);
EXPECT_FALSE((aov2->flag & AOV_CONFLICT) != 0);
EXPECT_TRUE(STREQ(aov1->name, "AOV"));
EXPECT_TRUE(STREQ(aov2->name, "AOV_001"));
/* Resolve by removing AOV resolution */
BKE_view_layer_remove_aov(view_layer, aov2);
aov2 = nullptr;
BKE_view_layer_verify_aov(engine, &scene, view_layer);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov1->flag & AOV_CONFLICT) != 0);
/* Tear down */
RE_engine_free(engine);
RE_engines_exit();
IDType_ID_SCE.free_data(&scene.id);
IMB_exit();
BKE_appdir_exit();
CLG_exit();
GHOST_DisposeSystemPaths();
}
static void test_render_pass_conflict(Scene *scene,
RenderEngine *engine,
ViewLayer *view_layer,
ViewLayerAOV *aov,
const char *render_pass_name,
const char *rna_prop_name)
{
PointerRNA ptr = RNA_pointer_create(&scene->id, &RNA_ViewLayer, view_layer);
RNA_boolean_set(&ptr, rna_prop_name, false);
/* Rename to Conflicting name */
STRNCPY(aov->name, render_pass_name);
BKE_view_layer_verify_aov(engine, scene, view_layer);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov->flag & AOV_CONFLICT) != 0);
EXPECT_TRUE(STREQ(aov->name, render_pass_name));
/* Activate render pass */
RNA_boolean_set(&ptr, rna_prop_name, true);
BKE_view_layer_verify_aov(engine, scene, view_layer);
EXPECT_FALSE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_TRUE((aov->flag & AOV_CONFLICT) != 0);
EXPECT_TRUE(STREQ(aov->name, render_pass_name));
/* Deactivate render pass */
RNA_boolean_set(&ptr, rna_prop_name, false);
BKE_view_layer_verify_aov(engine, scene, view_layer);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov->flag & AOV_CONFLICT) != 0);
EXPECT_TRUE(STREQ(aov->name, render_pass_name));
}
TEST(view_layer, aov_conflict)
{
/* Set Up */
CLG_init();
BKE_appdir_init();
IMB_init();
RE_engines_init();
Scene scene = {{nullptr}};
IDType_ID_SCE.init_data(&scene.id);
ViewLayer *view_layer = static_cast<ViewLayer *>(scene.view_layers.first);
RenderEngineType *engine_type = RE_engines_find(scene.r.engine);
RenderEngine *engine = RE_engine_create(engine_type);
EXPECT_FALSE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_EQ(view_layer->active_aov, nullptr);
/* Add an AOV */
ViewLayerAOV *aov = BKE_view_layer_add_aov(view_layer);
BKE_view_layer_verify_aov(engine, &scene, view_layer);
EXPECT_EQ(view_layer->active_aov, aov);
EXPECT_TRUE(BKE_view_layer_has_valid_aov(view_layer));
EXPECT_FALSE((aov->flag & AOV_CONFLICT) != 0);
test_render_pass_conflict(&scene, engine, view_layer, aov, "Depth", "use_pass_z");
test_render_pass_conflict(&scene, engine, view_layer, aov, "Normal", "use_pass_normal");
test_render_pass_conflict(&scene, engine, view_layer, aov, "Mist", "use_pass_mist");
test_render_pass_conflict(&scene, engine, view_layer, aov, "Shadow", "use_pass_shadow");
test_render_pass_conflict(&scene, engine, view_layer, aov, "AO", "use_pass_ambient_occlusion");
test_render_pass_conflict(&scene, engine, view_layer, aov, "Emit", "use_pass_emit");
test_render_pass_conflict(&scene, engine, view_layer, aov, "Env", "use_pass_environment");
test_render_pass_conflict(&scene, engine, view_layer, aov, "DiffDir", "use_pass_diffuse_direct");
test_render_pass_conflict(&scene, engine, view_layer, aov, "DiffCol", "use_pass_diffuse_color");
test_render_pass_conflict(&scene, engine, view_layer, aov, "GlossDir", "use_pass_glossy_direct");
test_render_pass_conflict(&scene, engine, view_layer, aov, "GlossCol", "use_pass_glossy_color");
/* Tear down */
RE_engine_free(engine);
RE_engines_exit();
IDType_ID_SCE.free_data(&scene.id);
IMB_exit();
BKE_appdir_exit();
CLG_exit();
GHOST_DisposeSystemPaths();
}
} // namespace blender::bke::tests