@ -29,7 +29,7 @@
# include <Corrade/Utility/DebugStl.h>
# include "Magnum/Math/Color.h"
# include "Magnum/MeshTools/Reference .h"
# include "Magnum/MeshTools/Copy .h"
# include "Magnum/Primitives/Cube.h"
# include "Magnum/Primitives/Gradient.h"
# include "Magnum/Primitives/Grid.h"
@ -38,8 +38,17 @@
namespace Magnum { namespace MeshTools { namespace Test { namespace {
struct ReferenceTest : TestSuite : : Tester {
explicit ReferenceTest ( ) ;
struct CopyTest : TestSuite : : Tester {
explicit CopyTest ( ) ;
void copy ( ) ;
void copyNoIndexData ( ) ;
void copyNoAttributeVertexData ( ) ;
void copyStridedIndices ( ) ;
void copyArrayAttribute ( ) ;
void copyImplementationSpecificVertexFormat ( ) ;
void copyRvaluePassthrough ( ) ;
void copyRvaluePartialPassthrough ( ) ;
void reference ( ) ;
void referenceNoIndexData ( ) ;
@ -51,15 +60,6 @@ struct ReferenceTest: TestSuite::Tester {
void mutableReferenceImplementationSpecificIndexType ( ) ;
void mutableReferenceNoIndexVertexAttributeData ( ) ;
void mutableReferenceNotMutable ( ) ;
void owned ( ) ;
void ownedNoIndexData ( ) ;
void ownedNoAttributeVertexData ( ) ;
void ownedStridedIndices ( ) ;
void ownedArrayAttribute ( ) ;
void ownedImplementationSpecificVertexFormat ( ) ;
void ownedRvaluePassthrough ( ) ;
void ownedRvaluePartialPassthrough ( ) ;
} ;
struct {
@ -70,32 +70,205 @@ struct {
{ " implementation-specific index format " , meshIndexTypeWrap ( 0xcaca ) }
} ;
ReferenceTest : : ReferenceTest ( ) {
addTests ( { & ReferenceTest : : reference ,
& ReferenceTest : : referenceNoIndexData ,
& ReferenceTest : : referenceImplementationSpecificIndexType ,
& ReferenceTest : : referenceNoIndexVertexAttributeData ,
CopyTest : : CopyTest ( ) {
addTests ( { & CopyTest : : copy ,
& CopyTest : : copyNoIndexData ,
& CopyTest : : copyNoAttributeVertexData } ) ;
& ReferenceTest : : mutableReference ,
& ReferenceTest : : mutableReferenceNoIndexData ,
& ReferenceTest : : mutableReferenceImplementationSpecificIndexType ,
& ReferenceTest : : mutableReferenceNoIndexVertexAttributeData ,
& ReferenceTest : : mutableReferenceNotMutable ,
addInstancedTests ( { & CopyTest : : copyStridedIndices } ,
Containers : : arraySize ( StridedIndicesData ) ) ;
& ReferenceTest : : owned ,
& ReferenceTest : : ownedNoIndexData ,
& ReferenceTest : : ownedNoAttributeVertexData } ) ;
addTests ( { & CopyTest : : copyArrayAttribute ,
& CopyTest : : copyImplementationSpecificVertexFormat ,
& CopyTest : : copyRvaluePassthrough ,
& CopyTest : : copyRvaluePartialPassthrough ,
& CopyTest : : reference ,
& CopyTest : : referenceNoIndexData ,
& CopyTest : : referenceImplementationSpecificIndexType ,
& CopyTest : : referenceNoIndexVertexAttributeData ,
& CopyTest : : mutableReference ,
& CopyTest : : mutableReferenceNoIndexData ,
& CopyTest : : mutableReferenceImplementationSpecificIndexType ,
& CopyTest : : mutableReferenceNoIndexVertexAttributeData ,
& CopyTest : : mutableReferenceNotMutable } ) ;
}
addInstancedTests ( { & ReferenceTest : : ownedStridedIndices } ,
Containers : : arraySize ( StridedIndicesData ) ) ;
void CopyTest : : copy ( ) {
Trade : : MeshData cube = Primitives : : cubeSolid ( ) ;
CORRADE_COMPARE ( cube . indexDataFlags ( ) , Trade : : DataFlag : : Global ) ;
CORRADE_COMPARE ( cube . vertexDataFlags ( ) , Trade : : DataFlag : : Global ) ;
Trade : : MeshData copy = MeshTools : : copy ( cube ) ;
CORRADE_VERIFY ( copy . isIndexed ( ) ) ;
CORRADE_COMPARE ( copy . primitive ( ) , cube . primitive ( ) ) ;
CORRADE_COMPARE ( copy . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . indexCount ( ) , cube . indexCount ( ) ) ;
CORRADE_COMPARE ( copy . indexType ( ) , cube . indexType ( ) ) ;
CORRADE_COMPARE ( copy . indexOffset ( ) , cube . indexOffset ( ) ) ;
CORRADE_COMPARE ( copy . indexStride ( ) , cube . indexStride ( ) ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , cube . vertexCount ( ) ) ;
CORRADE_COMPARE ( copy . attributeCount ( ) , cube . attributeCount ( ) ) ;
for ( std : : size_t i = 0 ; i ! = cube . attributeCount ( ) ; + + i ) {
CORRADE_ITERATION ( i ) ;
CORRADE_COMPARE ( copy . attributeName ( i ) , cube . attributeName ( i ) ) ;
CORRADE_COMPARE ( copy . attributeFormat ( i ) , cube . attributeFormat ( i ) ) ;
CORRADE_COMPARE ( copy . attributeOffset ( i ) , cube . attributeOffset ( i ) ) ;
CORRADE_COMPARE ( copy . attributeStride ( i ) , cube . attributeStride ( i ) ) ;
CORRADE_COMPARE ( copy . attributeArraySize ( i ) , cube . attributeArraySize ( i ) ) ;
}
CORRADE_COMPARE_AS ( copy . indexData ( ) , cube . indexData ( ) , TestSuite : : Compare : : Container ) ;
CORRADE_COMPARE_AS ( copy . vertexData ( ) , cube . vertexData ( ) , TestSuite : : Compare : : Container ) ;
}
void CopyTest : : copyNoIndexData ( ) {
Trade : : MeshData cube = Primitives : : cubeSolidStrip ( ) ;
CORRADE_VERIFY ( ! cube . isIndexed ( ) ) ;
CORRADE_COMPARE ( cube . vertexDataFlags ( ) , Trade : : DataFlag : : Global ) ;
Trade : : MeshData copy = MeshTools : : copy ( cube ) ;
CORRADE_VERIFY ( ! copy . isIndexed ( ) ) ;
CORRADE_COMPARE ( copy . primitive ( ) , cube . primitive ( ) ) ;
CORRADE_COMPARE ( copy . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , cube . vertexCount ( ) ) ;
CORRADE_COMPARE ( copy . attributeCount ( ) , cube . attributeCount ( ) ) ;
}
void CopyTest : : copyNoAttributeVertexData ( ) {
UnsignedShort indexData [ ] { 0 , 41 , 2 } ;
Trade : : MeshData indexedFourtytwo { MeshPrimitive : : Edges ,
{ } , indexData , Trade : : MeshIndexData { indexData } ,
42 } ;
Trade : : MeshData copy = MeshTools : : copy ( indexedFourtytwo ) ;
CORRADE_VERIFY ( copy . isIndexed ( ) ) ;
CORRADE_COMPARE ( copy . primitive ( ) , MeshPrimitive : : Edges ) ;
CORRADE_COMPARE ( copy . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . indexCount ( ) , 3 ) ;
CORRADE_COMPARE ( copy . indexType ( ) , MeshIndexType : : UnsignedShort ) ;
CORRADE_COMPARE ( copy . indexOffset ( ) , 0 ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , 42 ) ;
CORRADE_COMPARE ( copy . attributeCount ( ) , 0 ) ;
CORRADE_COMPARE_AS ( copy . indexData ( ) , indexedFourtytwo . indexData ( ) , TestSuite : : Compare : : Container ) ;
CORRADE_VERIFY ( ! static_cast < const void * > ( copy . vertexData ( ) . data ( ) ) ) ;
CORRADE_VERIFY ( ! static_cast < const void * > ( copy . attributeData ( ) . data ( ) ) ) ;
}
void CopyTest : : copyStridedIndices ( ) {
auto & & data = StridedIndicesData [ testCaseInstanceId ( ) ] ;
setTestCaseDescription ( data . name ) ;
const UnsignedShort indices [ 7 ] { 0 , 3 , 0 , 7 , 0 , 15 , 0 } ;
Trade : : MeshData stuff { MeshPrimitive : : Points ,
{ } , indices , Trade : : MeshIndexData { data . type , Containers : : stridedArrayView ( indices ) . exceptPrefix ( 1 ) . every ( 2 ) } ,
16 } ;
/* The full index data layout including whatever format should be
preserved */
Trade : : MeshData copy = MeshTools : : copy ( stuff ) ;
CORRADE_VERIFY ( copy . isIndexed ( ) ) ;
CORRADE_COMPARE ( copy . primitive ( ) , MeshPrimitive : : Points ) ;
CORRADE_COMPARE ( copy . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . indexCount ( ) , 3 ) ;
CORRADE_COMPARE ( copy . indexType ( ) , data . type ) ;
CORRADE_COMPARE ( copy . indexOffset ( ) , 2 ) ;
CORRADE_COMPARE ( copy . indexStride ( ) , 4 ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , 16 ) ;
CORRADE_COMPARE ( copy . attributeCount ( ) , 0 ) ;
/* Has to do a prefix() because for an implementation-specific index type
the returned size is equal to stride */
CORRADE_COMPARE_AS ( ( Containers : : arrayCast < 1 , const UnsignedShort > ( copy . indices ( ) . prefix ( { copy . indexCount ( ) , 2 } ) ) ) ,
Containers : : arrayView < UnsignedShort > ( { 3 , 7 , 15 } ) ,
TestSuite : : Compare : : Container ) ;
CORRADE_COMPARE_AS ( copy . indexData ( ) , stuff . indexData ( ) ,
TestSuite : : Compare : : Container ) ;
}
void CopyTest : : copyArrayAttribute ( ) {
const Vector3us vertexData [ 13 ] { } ;
/* Verify that array attributes are propagated correctly */
Trade : : MeshData weirdThing { MeshPrimitive : : Faces ,
{ } , vertexData ,
{ Trade : : MeshAttributeData { Trade : : meshAttributeCustom ( 42 ) , VertexFormat : : Half , Containers : : arrayView ( vertexData ) , 3 } } } ;
Trade : : MeshData copy = MeshTools : : copy ( weirdThing ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , 13 ) ;
CORRADE_COMPARE ( copy . attributeCount ( ) , 1 ) ;
CORRADE_COMPARE ( copy . attributeArraySize ( 0 ) , 3 ) ;
}
void CopyTest : : copyImplementationSpecificVertexFormat ( ) {
const Int vertexData [ 13 ] { } ;
/* Verify that custom vertex formats are propagated without a problem */
Trade : : MeshData weirdThing { MeshPrimitive : : Faces ,
{ } , vertexData ,
{ Trade : : MeshAttributeData { Trade : : meshAttributeCustom ( 42 ) , vertexFormatWrap ( 0xcaca ) , Containers : : arrayView ( vertexData ) } } } ;
Trade : : MeshData copy = MeshTools : : copy ( weirdThing ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , 13 ) ;
CORRADE_COMPARE ( copy . attributeCount ( ) , 1 ) ;
CORRADE_COMPARE ( copy . attributeArraySize ( 0 ) , 0 ) ;
CORRADE_COMPARE ( copy . attributeFormat ( 0 ) , vertexFormatWrap ( 0xcaca ) ) ;
CORRADE_COMPARE_AS ( ( Containers : : arrayCast < 1 , const Int > ( copy . attribute ( 0 ) ) ) ,
Containers : : arrayView ( vertexData ) ,
TestSuite : : Compare : : Container ) ;
}
void CopyTest : : copyRvaluePassthrough ( ) {
Trade : : MeshData grid = Primitives : : grid3DSolid ( { 15 , 3 } , Primitives : : GridFlag : : Tangents ) ;
CORRADE_COMPARE ( grid . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( grid . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
UnsignedInt indexCount = grid . indexCount ( ) ;
MeshIndexType indexType = grid . indexType ( ) ;
std : : size_t indexOffset = grid . indexOffset ( ) ;
Int indexStride = grid . indexStride ( ) ;
UnsignedInt vertexCount = grid . vertexCount ( ) ;
const void * indexData = grid . indexData ( ) ;
const void * vertexData = grid . vertexData ( ) ;
const void * attributeData = grid . attributeData ( ) ;
Trade : : MeshData copy = MeshTools : : copy ( std : : move ( grid ) ) ;
CORRADE_VERIFY ( copy . isIndexed ( ) ) ;
CORRADE_COMPARE ( copy . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . indexCount ( ) , indexCount ) ;
CORRADE_COMPARE ( copy . indexType ( ) , indexType ) ;
CORRADE_COMPARE ( copy . indexOffset ( ) , indexOffset ) ;
CORRADE_COMPARE ( copy . indexStride ( ) , indexStride ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , vertexCount ) ;
CORRADE_COMPARE ( copy . indexData ( ) , indexData ) ;
CORRADE_COMPARE ( copy . vertexData ( ) , vertexData ) ;
CORRADE_COMPARE ( copy . attributeData ( ) , attributeData ) ;
}
void CopyTest : : copyRvaluePartialPassthrough ( ) {
Trade : : MeshData gradient = Primitives : : gradient3DHorizontal ( { } , { } ) ;
CORRADE_COMPARE ( gradient . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
UnsignedInt vertexCount = gradient . vertexCount ( ) ;
const void * vertexData = gradient . vertexData ( ) ;
const void * attributeData = gradient . attributeData ( ) ;
addTests ( { & ReferenceTest : : ownedArrayAttribute ,
& ReferenceTest : : ownedImplementationSpecificVertexFormat ,
& ReferenceTest : : ownedRvaluePassthrough ,
& ReferenceTest : : ownedRvaluePartialPassthrough } ) ;
Trade : : MeshData copy = MeshTools : : copy ( std : : move ( gradient ) ) ;
CORRADE_VERIFY ( ! copy . isIndexed ( ) ) ;
CORRADE_COMPARE ( copy . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( copy . vertexCount ( ) , vertexCount ) ;
CORRADE_COMPARE ( copy . vertexData ( ) , vertexData ) ;
/* Attribute data is constant in the original, so this gets copied */
CORRADE_VERIFY ( copy . attributeData ( ) ! = attributeData ) ;
}
void ReferenceTest : : reference ( ) {
void Copy Test: : reference ( ) {
const Trade : : MeshData grid = Primitives : : grid3DSolid ( { 15 , 3 } , Primitives : : GridFlag : : Tangents ) ;
CORRADE_VERIFY ( grid . isIndexed ( ) ) ;
@ -114,7 +287,7 @@ void ReferenceTest::reference() {
CORRADE_COMPARE ( static_cast < const void * > ( reference . attributeData ( ) . data ( ) ) , grid . attributeData ( ) . data ( ) ) ;
}
void Reference Test: : referenceNoIndexData ( ) {
void Copy Test: : referenceNoIndexData ( ) {
const Trade : : MeshData circle = Primitives : : circle3DSolid ( 5 ) ;
CORRADE_VERIFY ( ! circle . isIndexed ( ) ) ;
@ -129,7 +302,7 @@ void ReferenceTest::referenceNoIndexData() {
CORRADE_COMPARE ( static_cast < const void * > ( reference . attributeData ( ) . data ( ) ) , circle . attributeData ( ) . data ( ) ) ;
}
void Reference Test: : referenceImplementationSpecificIndexType ( ) {
void Copy Test: : referenceImplementationSpecificIndexType ( ) {
const UnsignedShort indices [ 7 ] { 0 , 3 , 0 , 7 , 0 , 15 , 0 } ;
Trade : : MeshData stuff { MeshPrimitive : : Points ,
{ } , indices , Trade : : MeshIndexData { meshIndexTypeWrap ( 0xcaca ) , Containers : : stridedArrayView ( indices ) } ,
@ -140,7 +313,7 @@ void ReferenceTest::referenceImplementationSpecificIndexType() {
CORRADE_COMPARE ( reference . indexType ( ) , meshIndexTypeWrap ( 0xcaca ) ) ;
}
void Reference Test: : referenceNoIndexVertexAttributeData ( ) {
void Copy Test: : referenceNoIndexVertexAttributeData ( ) {
Trade : : MeshData fourtytwo { MeshPrimitive : : Edges , 42 } ;
Trade : : MeshData reference = MeshTools : : reference ( fourtytwo ) ;
@ -153,7 +326,7 @@ void ReferenceTest::referenceNoIndexVertexAttributeData() {
CORRADE_VERIFY ( ! static_cast < const void * > ( reference . attributeData ( ) . data ( ) ) ) ;
}
void Reference Test: : mutableReference ( ) {
void Copy Test: : mutableReference ( ) {
Trade : : MeshData grid = Primitives : : grid3DSolid ( { 15 , 3 } , Primitives : : GridFlag : : Tangents ) ;
CORRADE_VERIFY ( grid . isIndexed ( ) ) ;
@ -172,7 +345,7 @@ void ReferenceTest::mutableReference() {
CORRADE_COMPARE ( static_cast < const void * > ( reference . attributeData ( ) . data ( ) ) , grid . attributeData ( ) . data ( ) ) ;
}
void Reference Test: : mutableReferenceNoIndexData ( ) {
void Copy Test: : mutableReferenceNoIndexData ( ) {
Trade : : MeshData circle = Primitives : : circle3DSolid ( 5 ) ;
CORRADE_VERIFY ( ! circle . isIndexed ( ) ) ;
@ -187,7 +360,7 @@ void ReferenceTest::mutableReferenceNoIndexData() {
CORRADE_COMPARE ( static_cast < const void * > ( reference . attributeData ( ) . data ( ) ) , circle . attributeData ( ) . data ( ) ) ;
}
void Reference Test: : mutableReferenceImplementationSpecificIndexType ( ) {
void Copy Test: : mutableReferenceImplementationSpecificIndexType ( ) {
UnsignedShort indices [ 7 ] { 0 , 3 , 0 , 7 , 0 , 15 , 0 } ;
Trade : : MeshData stuff { MeshPrimitive : : Points ,
Trade : : DataFlag : : Mutable , indices , Trade : : MeshIndexData { meshIndexTypeWrap ( 0xcaca ) , Containers : : stridedArrayView ( indices ) } ,
@ -198,7 +371,7 @@ void ReferenceTest::mutableReferenceImplementationSpecificIndexType() {
CORRADE_COMPARE ( reference . indexType ( ) , meshIndexTypeWrap ( 0xcaca ) ) ;
}
void Reference Test: : mutableReferenceNoIndexVertexAttributeData ( ) {
void Copy Test: : mutableReferenceNoIndexVertexAttributeData ( ) {
Trade : : MeshData fourtytwo { MeshPrimitive : : Edges , 42 } ;
Trade : : MeshData reference = MeshTools : : mutableReference ( fourtytwo ) ;
@ -211,7 +384,7 @@ void ReferenceTest::mutableReferenceNoIndexVertexAttributeData() {
CORRADE_VERIFY ( ! static_cast < const void * > ( reference . attributeData ( ) . data ( ) ) ) ;
}
void Reference Test: : mutableReferenceNotMutable ( ) {
void Copy Test: : mutableReferenceNotMutable ( ) {
CORRADE_SKIP_IF_NO_ASSERT ( ) ;
Trade : : MeshData cube = Primitives : : cubeSolid ( ) ;
@ -224,179 +397,6 @@ void ReferenceTest::mutableReferenceNotMutable() {
CORRADE_COMPARE ( out . str ( ) , " MeshTools::mutableReference(): data not mutable \n " ) ;
}
void ReferenceTest : : owned ( ) {
Trade : : MeshData cube = Primitives : : cubeSolid ( ) ;
CORRADE_COMPARE ( cube . indexDataFlags ( ) , Trade : : DataFlag : : Global ) ;
CORRADE_COMPARE ( cube . vertexDataFlags ( ) , Trade : : DataFlag : : Global ) ;
Trade : : MeshData owned = MeshTools : : owned ( cube ) ;
CORRADE_VERIFY ( owned . isIndexed ( ) ) ;
CORRADE_COMPARE ( owned . primitive ( ) , cube . primitive ( ) ) ;
CORRADE_COMPARE ( owned . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . indexCount ( ) , cube . indexCount ( ) ) ;
CORRADE_COMPARE ( owned . indexType ( ) , cube . indexType ( ) ) ;
CORRADE_COMPARE ( owned . indexOffset ( ) , cube . indexOffset ( ) ) ;
CORRADE_COMPARE ( owned . indexStride ( ) , cube . indexStride ( ) ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , cube . vertexCount ( ) ) ;
CORRADE_COMPARE ( owned . attributeCount ( ) , cube . attributeCount ( ) ) ;
for ( std : : size_t i = 0 ; i ! = cube . attributeCount ( ) ; + + i ) {
CORRADE_ITERATION ( i ) ;
CORRADE_COMPARE ( owned . attributeName ( i ) , cube . attributeName ( i ) ) ;
CORRADE_COMPARE ( owned . attributeFormat ( i ) , cube . attributeFormat ( i ) ) ;
CORRADE_COMPARE ( owned . attributeOffset ( i ) , cube . attributeOffset ( i ) ) ;
CORRADE_COMPARE ( owned . attributeStride ( i ) , cube . attributeStride ( i ) ) ;
CORRADE_COMPARE ( owned . attributeArraySize ( i ) , cube . attributeArraySize ( i ) ) ;
}
CORRADE_COMPARE_AS ( owned . indexData ( ) , cube . indexData ( ) , TestSuite : : Compare : : Container ) ;
CORRADE_COMPARE_AS ( owned . vertexData ( ) , cube . vertexData ( ) , TestSuite : : Compare : : Container ) ;
}
void ReferenceTest : : ownedNoIndexData ( ) {
Trade : : MeshData cube = Primitives : : cubeSolidStrip ( ) ;
CORRADE_VERIFY ( ! cube . isIndexed ( ) ) ;
CORRADE_COMPARE ( cube . vertexDataFlags ( ) , Trade : : DataFlag : : Global ) ;
Trade : : MeshData owned = MeshTools : : owned ( cube ) ;
CORRADE_VERIFY ( ! owned . isIndexed ( ) ) ;
CORRADE_COMPARE ( owned . primitive ( ) , cube . primitive ( ) ) ;
CORRADE_COMPARE ( owned . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , cube . vertexCount ( ) ) ;
CORRADE_COMPARE ( owned . attributeCount ( ) , cube . attributeCount ( ) ) ;
}
void ReferenceTest : : ownedNoAttributeVertexData ( ) {
UnsignedShort indexData [ ] { 0 , 41 , 2 } ;
Trade : : MeshData indexedFourtytwo { MeshPrimitive : : Edges ,
{ } , indexData , Trade : : MeshIndexData { indexData } ,
42 } ;
Trade : : MeshData owned = MeshTools : : owned ( indexedFourtytwo ) ;
CORRADE_VERIFY ( owned . isIndexed ( ) ) ;
CORRADE_COMPARE ( owned . primitive ( ) , MeshPrimitive : : Edges ) ;
CORRADE_COMPARE ( owned . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . indexCount ( ) , 3 ) ;
CORRADE_COMPARE ( owned . indexType ( ) , MeshIndexType : : UnsignedShort ) ;
CORRADE_COMPARE ( owned . indexOffset ( ) , 0 ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , 42 ) ;
CORRADE_COMPARE ( owned . attributeCount ( ) , 0 ) ;
CORRADE_COMPARE_AS ( owned . indexData ( ) , indexedFourtytwo . indexData ( ) , TestSuite : : Compare : : Container ) ;
CORRADE_VERIFY ( ! static_cast < const void * > ( owned . vertexData ( ) . data ( ) ) ) ;
CORRADE_VERIFY ( ! static_cast < const void * > ( owned . attributeData ( ) . data ( ) ) ) ;
}
void ReferenceTest : : ownedStridedIndices ( ) {
auto & & data = StridedIndicesData [ testCaseInstanceId ( ) ] ;
setTestCaseDescription ( data . name ) ;
const UnsignedShort indices [ 7 ] { 0 , 3 , 0 , 7 , 0 , 15 , 0 } ;
Trade : : MeshData stuff { MeshPrimitive : : Points ,
{ } , indices , Trade : : MeshIndexData { data . type , Containers : : stridedArrayView ( indices ) . exceptPrefix ( 1 ) . every ( 2 ) } ,
16 } ;
/* The full index data layout including whatever format should be
preserved */
Trade : : MeshData owned = MeshTools : : owned ( stuff ) ;
CORRADE_VERIFY ( owned . isIndexed ( ) ) ;
CORRADE_COMPARE ( owned . primitive ( ) , MeshPrimitive : : Points ) ;
CORRADE_COMPARE ( owned . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . indexCount ( ) , 3 ) ;
CORRADE_COMPARE ( owned . indexType ( ) , data . type ) ;
CORRADE_COMPARE ( owned . indexOffset ( ) , 2 ) ;
CORRADE_COMPARE ( owned . indexStride ( ) , 4 ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , 16 ) ;
CORRADE_COMPARE ( owned . attributeCount ( ) , 0 ) ;
/* Has to do a prefix() because for an implementation-specific index type
the returned size is equal to stride */
CORRADE_COMPARE_AS ( ( Containers : : arrayCast < 1 , const UnsignedShort > ( owned . indices ( ) . prefix ( { owned . indexCount ( ) , 2 } ) ) ) ,
Containers : : arrayView < UnsignedShort > ( { 3 , 7 , 15 } ) ,
TestSuite : : Compare : : Container ) ;
CORRADE_COMPARE_AS ( owned . indexData ( ) , stuff . indexData ( ) ,
TestSuite : : Compare : : Container ) ;
}
void ReferenceTest : : ownedArrayAttribute ( ) {
const Vector3us vertexData [ 13 ] { } ;
/* Verify that array attributes are propagated correctly */
Trade : : MeshData weirdThing { MeshPrimitive : : Faces ,
{ } , vertexData ,
{ Trade : : MeshAttributeData { Trade : : meshAttributeCustom ( 42 ) , VertexFormat : : Half , Containers : : arrayView ( vertexData ) , 3 } } } ;
Trade : : MeshData owned = MeshTools : : owned ( weirdThing ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , 13 ) ;
CORRADE_COMPARE ( owned . attributeCount ( ) , 1 ) ;
CORRADE_COMPARE ( owned . attributeArraySize ( 0 ) , 3 ) ;
}
void ReferenceTest : : ownedImplementationSpecificVertexFormat ( ) {
const Int vertexData [ 13 ] { } ;
/* Verify that custom vertex formats are propagated without a problem */
Trade : : MeshData weirdThing { MeshPrimitive : : Faces ,
{ } , vertexData ,
{ Trade : : MeshAttributeData { Trade : : meshAttributeCustom ( 42 ) , vertexFormatWrap ( 0xcaca ) , Containers : : arrayView ( vertexData ) } } } ;
Trade : : MeshData owned = MeshTools : : owned ( weirdThing ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , 13 ) ;
CORRADE_COMPARE ( owned . attributeCount ( ) , 1 ) ;
CORRADE_COMPARE ( owned . attributeArraySize ( 0 ) , 0 ) ;
CORRADE_COMPARE ( owned . attributeFormat ( 0 ) , vertexFormatWrap ( 0xcaca ) ) ;
CORRADE_COMPARE_AS ( ( Containers : : arrayCast < 1 , const Int > ( owned . attribute ( 0 ) ) ) ,
Containers : : arrayView ( vertexData ) ,
TestSuite : : Compare : : Container ) ;
}
void ReferenceTest : : ownedRvaluePassthrough ( ) {
Trade : : MeshData grid = Primitives : : grid3DSolid ( { 15 , 3 } , Primitives : : GridFlag : : Tangents ) ;
CORRADE_COMPARE ( grid . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( grid . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
UnsignedInt indexCount = grid . indexCount ( ) ;
MeshIndexType indexType = grid . indexType ( ) ;
std : : size_t indexOffset = grid . indexOffset ( ) ;
Int indexStride = grid . indexStride ( ) ;
UnsignedInt vertexCount = grid . vertexCount ( ) ;
const void * indexData = grid . indexData ( ) ;
const void * vertexData = grid . vertexData ( ) ;
const void * attributeData = grid . attributeData ( ) ;
Trade : : MeshData owned = MeshTools : : owned ( std : : move ( grid ) ) ;
CORRADE_VERIFY ( owned . isIndexed ( ) ) ;
CORRADE_COMPARE ( owned . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . indexCount ( ) , indexCount ) ;
CORRADE_COMPARE ( owned . indexType ( ) , indexType ) ;
CORRADE_COMPARE ( owned . indexOffset ( ) , indexOffset ) ;
CORRADE_COMPARE ( owned . indexStride ( ) , indexStride ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , vertexCount ) ;
CORRADE_COMPARE ( owned . indexData ( ) , indexData ) ;
CORRADE_COMPARE ( owned . vertexData ( ) , vertexData ) ;
CORRADE_COMPARE ( owned . attributeData ( ) , attributeData ) ;
}
void ReferenceTest : : ownedRvaluePartialPassthrough ( ) {
Trade : : MeshData gradient = Primitives : : gradient3DHorizontal ( { } , { } ) ;
CORRADE_COMPARE ( gradient . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
UnsignedInt vertexCount = gradient . vertexCount ( ) ;
const void * vertexData = gradient . vertexData ( ) ;
const void * attributeData = gradient . attributeData ( ) ;
Trade : : MeshData owned = MeshTools : : owned ( std : : move ( gradient ) ) ;
CORRADE_VERIFY ( ! owned . isIndexed ( ) ) ;
CORRADE_COMPARE ( owned . indexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexDataFlags ( ) , Trade : : DataFlag : : Mutable | Trade : : DataFlag : : Owned ) ;
CORRADE_COMPARE ( owned . vertexCount ( ) , vertexCount ) ;
CORRADE_COMPARE ( owned . vertexData ( ) , vertexData ) ;
/* Attribute data is constant in the original, so this gets copied */
CORRADE_VERIFY ( owned . attributeData ( ) ! = attributeData ) ;
}
} } } }
CORRADE_TEST_MAIN ( Magnum : : MeshTools : : Test : : Reference Test)
CORRADE_TEST_MAIN ( Magnum : : MeshTools : : Test : : CopyTest )