Skip to content

Commit

Permalink
[wip] the null fields/mappings are a PAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Dec 7, 2021
1 parent c34e03d commit 2ad3abd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Magnum/Trade/Implementation/sceneTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ inline SceneData sceneConvertToSingleFunctionObjects(const SceneData& scene, Con
- fields that don't actually get their object mapping touched
during the process (and then all fields that share object
mapping with them) */
#warning removing implicit mapping from here will mean the null will get treated as a placeholder by copy(), not wanted
#warning it needs to restore the field instead
} else fields[i] = SceneFieldData{field.name(), field.mappingType(), field.mappingData(), field.fieldType(), field.fieldData(), field.fieldArraySize(), field.flags() & ~SceneFieldFlag::ImplicitMapping};
}

Expand Down
48 changes: 47 additions & 1 deletion src/Magnum/Trade/Test/SceneToolsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct SceneToolsTest: TestSuite::Tester {
void combineObjectsShared();
void combineObjectsPlaceholderFieldPlaceholder();
void combineObjectSharedFieldPlaceholder();
void combineImplicitNullMapping();
void combineTrivialNullParent();

void convertToSingleFunctionObjects();
void convertToSingleFunctionObjectsFieldsToCopy();
Expand Down Expand Up @@ -80,7 +82,10 @@ SceneToolsTest::SceneToolsTest() {
addTests({&SceneToolsTest::combineAlignment,
&SceneToolsTest::combineObjectsShared,
&SceneToolsTest::combineObjectsPlaceholderFieldPlaceholder,
&SceneToolsTest::combineObjectSharedFieldPlaceholder});
&SceneToolsTest::combineObjectSharedFieldPlaceholder,

&SceneToolsTest::combineImplicitNullMapping,
&SceneToolsTest::combineTrivialNullParent});

addInstancedTests({&SceneToolsTest::convertToSingleFunctionObjects},
Containers::arraySize(ConvertToSingleFunctionObjectsData));
Expand Down Expand Up @@ -349,6 +354,47 @@ void SceneToolsTest::combineObjectSharedFieldPlaceholder() {
CORRADE_COMPARE(scene.field(SceneField::MeshMaterial).stride()[0], 4);
}

void SceneToolsTest::combineImplicitNullMapping() {
const Short parentFieldData[]{-1, 0, 0};
const UnsignedByte meshFieldData[]{3, 5};

SceneData scene = Implementation::sceneCombine(SceneMappingType::UnsignedShort, 167, Containers::arrayView({
/* If the field has any flags, it shouldn't be treated as a
placeholder */
#warning or maybe it should be preserved? yeah
SceneFieldData{SceneField::Mesh, Containers::ArrayView<UnsignedByte>{nullptr, Containers::arraySize(meshFieldData)}, Containers::arrayView(meshFieldData), SceneFieldFlag::ImplicitMapping},
SceneFieldData{SceneField::Parent, Containers::ArrayView<UnsignedShort>{nullptr, Containers::arraySize(parentFieldData)}, Containers::arrayView(parentFieldData), SceneFieldFlag::ImplicitMapping}
}));

CORRADE_COMPARE(scene.mappingBound(), 167);
CORRADE_COMPARE(scene.fieldCount(), 2);

CORRADE_COMPARE(scene.fieldName(0), SceneField::Mesh);
CORRADE_COMPARE(scene.fieldFlags(0), SceneFieldFlag::ImplicitMapping);
CORRADE_COMPARE(scene.fieldType(0), SceneFieldType::UnsignedByte);
CORRADE_COMPARE(scene.fieldArraySize(0), 0);
CORRADE_COMPARE_AS(scene.mapping<UnsignedShort>(0), Containers::arrayView<UnsignedShort>({
0, 1, 2
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(scene.field<UnsignedByte>(0),
Containers::arrayView(meshFieldData),
TestSuite::Compare::Container);

CORRADE_COMPARE(scene.fieldName(1), SceneField::Parent);
CORRADE_COMPARE(scene.fieldFlags(1), SceneFieldFlag::ImplicitMapping);
CORRADE_COMPARE(scene.fieldType(1), SceneFieldType::Short);
CORRADE_COMPARE(scene.fieldArraySize(1), 0);
CORRADE_COMPARE_AS(scene.mapping<UnsignedShort>(1), Containers::arrayView<UnsignedShort>({
0, 1
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(scene.field<UnsignedByte>(1),
Containers::arrayView(meshFieldData),
TestSuite::Compare::Container);
}

void SceneToolsTest::combineTrivialNullParent() {
}

void SceneToolsTest::convertToSingleFunctionObjects() {
auto&& data = ConvertToSingleFunctionObjectsData[testCaseInstanceId()];
setTestCaseDescription(data.name);
Expand Down

0 comments on commit 2ad3abd

Please sign in to comment.