From 9ecb8b5b8d29b400b39c371f1631f5e75108b2eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Apr 2013 19:21:01 +0200 Subject: [PATCH] SceneGraph: fully test also Object::setClean() for list of objects. The test fails (it doesn't clean parent objects). --- src/SceneGraph/Test/ObjectTest.cpp | 62 ++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 51f1187f2..a54acdd43 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -42,7 +42,8 @@ class ObjectTest: public Corrade::TestSuite::Tester { void transformationsOrphan(); void transformationsDuplicate(); void setClean(); - void bulkSetClean(); + void setCleanListHierarchy(); + void setCleanListBulk(); }; typedef SceneGraph::Object> Object3D; @@ -71,7 +72,8 @@ ObjectTest::ObjectTest() { &ObjectTest::transformationsOrphan, &ObjectTest::transformationsDuplicate, &ObjectTest::setClean, - &ObjectTest::bulkSetClean}); + &ObjectTest::setCleanListHierarchy, + &ObjectTest::setCleanListBulk}); } void ObjectTest::parenting() { @@ -305,10 +307,13 @@ void ObjectTest::setClean() { /* If the object itself is already clean, it shouldn't clean it again */ childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero); + CORRADE_VERIFY(!childOne->isDirty()); childOne->setClean(); CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); /* If any object in the hierarchy is already clean, it shouldn't clean it again */ + CORRADE_VERIFY(!childOne->isDirty()); + CORRADE_VERIFY(childTwo->isDirty()); childTwo->setClean(); CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); @@ -332,7 +337,58 @@ void ObjectTest::setClean() { CORRADE_VERIFY(childThree->isDirty()); } -void ObjectTest::bulkSetClean() { +void ObjectTest::setCleanListHierarchy() { + Scene3D scene; + + class CachingFeature: public AbstractFeature<3> { + public: + CachingFeature(AbstractObject<3>* object): AbstractFeature<3>(object) { + setCachedTransformations(CachedTransformation::Absolute); + } + + Matrix4 cleanedAbsoluteTransformation; + + void clean(const Matrix4& absoluteTransformation) override { + cleanedAbsoluteTransformation = absoluteTransformation; + } + }; + + CachingObject* childOne = new CachingObject(&scene); + childOne->scale(Vector3(2.0f)); + + CachingObject* childTwo = new CachingObject(childOne); + childTwo->translate(Vector3::xAxis(1.0f)); + CachingFeature* childTwoFeature = new CachingFeature(childTwo); + + CachingObject* childThree = new CachingObject(childTwo); + childThree->rotate(Deg(90.0f), Vector3::yAxis()); + + /* Clean the object and all its dirty parents (but not children) */ + Scene3D::setClean(std::vector{childTwo}); + CORRADE_VERIFY(!scene.isDirty()); + CORRADE_VERIFY(!childOne->isDirty()); + CORRADE_VERIFY(!childTwo->isDirty()); + CORRADE_VERIFY(childThree->isDirty()); + + /* Verify the right matrices were passed */ + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, childOne->absoluteTransformationMatrix()); + CORRADE_COMPARE(childTwo->cleanedAbsoluteTransformation, childTwo->absoluteTransformationMatrix()); + CORRADE_COMPARE(childTwoFeature->cleanedAbsoluteTransformation, childTwo->absoluteTransformationMatrix()); + + /* If the object itself is already clean, it shouldn't clean it again */ + childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero); + CORRADE_VERIFY(!childOne->isDirty()); + Scene3D::setClean(std::vector{childOne}); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); + + /* If any object in the hierarchy is already clean, it shouldn't clean it again */ + CORRADE_VERIFY(!childOne->isDirty()); + childTwo->setDirty(); + Scene3D::setClean(std::vector{childTwo}); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero)); +} + +void ObjectTest::setCleanListBulk() { /* Verify it doesn't crash when passed empty list */ Object3D::setClean(std::vector());