diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-07-20 14:49:56 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-07-24 12:10:45 +0200 |
commit | c0efad5de22e50a2f2d541a62a07b0786cde0202 (patch) | |
tree | f6a3e63ded1ffd317c2af6d5f4a47b4ae623218d /test/gl/bucket.test.cpp | |
parent | 4dff51719b27988fe4672bd4022d305b6e7d9816 (diff) | |
download | qtlocation-mapboxgl-c0efad5de22e50a2f2d541a62a07b0786cde0202.tar.gz |
[core] generate masks for raster tiles to avoid painting over children
Diffstat (limited to 'test/gl/bucket.test.cpp')
-rw-r--r-- | test/gl/bucket.test.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/test/gl/bucket.test.cpp b/test/gl/bucket.test.cpp index 7ff67f40d0..afdbd2a29b 100644 --- a/test/gl/bucket.test.cpp +++ b/test/gl/bucket.test.cpp @@ -12,6 +12,26 @@ #include <mbgl/map/mode.hpp> +namespace mbgl { + +template <class Attributes> +bool operator==(const Segment<Attributes>& lhs, const Segment<Attributes>& rhs) { + return std::tie(lhs.vertexOffset, lhs.indexOffset, lhs.vertexLength, lhs.indexLength) == + std::tie(rhs.vertexOffset, rhs.indexOffset, rhs.vertexLength, rhs.indexLength); +} + +namespace gl { +namespace detail { + +template <class A1, class A2> +bool operator==(const Vertex<A1, A2>& lhs, const Vertex<A1, A2>& rhs) { + return std::tie(lhs.a1, lhs.a2) == std::tie(rhs.a1, rhs.a2); +} + +} // namespace detail +} // namespace gl +} // namespace mbgl + using namespace mbgl; namespace { @@ -114,3 +134,142 @@ TEST(Buckets, RasterBucket) { bucket.clear(); ASSERT_TRUE(bucket.needsUpload()); } + +TEST(Buckets, RasterBucketMaskEmpty) { + RasterBucket bucket{ nullptr }; + bucket.setMask({}); + EXPECT_EQ((std::vector<RasterLayoutVertex>{}), bucket.vertices.vector()); + EXPECT_EQ((std::vector<uint16_t>{}), bucket.indices.vector()); + SegmentVector<RasterAttributes> expectedSegments; + expectedSegments.emplace_back(0, 0, 0, 0); + EXPECT_EQ(expectedSegments, bucket.segments); +} + +TEST(Buckets, RasterBucketMaskNoChildren) { + RasterBucket bucket{ nullptr }; + bucket.setMask({ CanonicalTileID{ 0, 0, 0 } }); + + // A mask of 0/0/0 doesn't produce buffers since we're instead using the global shared buffers. + EXPECT_EQ((std::vector<RasterLayoutVertex>{}), bucket.vertices.vector()); + EXPECT_EQ((std::vector<uint16_t>{}), bucket.indices.vector()); + EXPECT_EQ((SegmentVector<RasterAttributes>{}), bucket.segments); +} + + TEST(Buckets, RasterBucketMaskTwoChildren) { + RasterBucket bucket{ nullptr }; + bucket.setMask( + { CanonicalTileID{ 1, 0, 0 }, CanonicalTileID{ 1, 1, 1 } }); + + EXPECT_EQ( + (std::vector<RasterLayoutVertex>{ + // 1/0/1 + RasterProgram::layoutVertex({ 0, 0 }, { 0, 0 }), + RasterProgram::layoutVertex({ 4096, 0 }, { 16384, 0 }), + RasterProgram::layoutVertex({ 0, 4096 }, { 0, 16384 }), + RasterProgram::layoutVertex({ 4096, 4096 }, { 16384, 16384 }), + + // 1/1/1 + RasterProgram::layoutVertex({ 4096, 4096 }, { 16384, 16384 }), + RasterProgram::layoutVertex({ 8192, 4096 }, { 32768, 16384 }), + RasterProgram::layoutVertex({ 4096, 8192 }, { 16384, 32768 }), + RasterProgram::layoutVertex({ 8192, 8192 }, { 32768, 32768 }), + }), + bucket.vertices.vector()); + + EXPECT_EQ( + (std::vector<uint16_t>{ + // 1/0/1 + 0, 1, 2, + 1, 2, 3, + + // 1/1/1 + 4, 5, 6, + 5, 6, 7, + }), + bucket.indices.vector()); + + + SegmentVector<RasterAttributes> expectedSegments; + expectedSegments.emplace_back(0, 0, 8, 12); + EXPECT_EQ(expectedSegments, bucket.segments); + } + + TEST(Buckets, RasterBucketMaskComplex) { + RasterBucket bucket{ nullptr }; + bucket.setMask( + { CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, CanonicalTileID{ 2, 2, 3 }, + CanonicalTileID{ 2, 3, 2 }, CanonicalTileID{ 3, 6, 7 }, CanonicalTileID{ 3, 7, 6 } }); + + EXPECT_EQ( + (std::vector<RasterLayoutVertex>{ + // 1/0/1 + RasterProgram::layoutVertex({ 0, 4096 }, { 0, 16384 }), + RasterProgram::layoutVertex({ 4096, 4096 }, { 16384, 16384 }), + RasterProgram::layoutVertex({ 0, 8192 }, { 0, 32768 }), + RasterProgram::layoutVertex({ 4096, 8192 }, { 16384, 32768 }), + + // 1/1/0 + RasterProgram::layoutVertex({ 4096, 0 }, { 16384, 0 }), + RasterProgram::layoutVertex({ 8192, 0 }, { 32768, 0 }), + RasterProgram::layoutVertex({ 4096, 4096 }, { 16384, 16384 }), + RasterProgram::layoutVertex({ 8192, 4096 }, { 32768, 16384 }), + + // 2/2/3 + RasterProgram::layoutVertex({ 4096, 6144 }, { 16384, 24576 }), + RasterProgram::layoutVertex({ 6144, 6144 }, { 24576, 24576 }), + RasterProgram::layoutVertex({ 4096, 8192 }, { 16384, 32768 }), + RasterProgram::layoutVertex({ 6144, 8192 }, { 24576, 32768 }), + + // 2/3/2 + RasterProgram::layoutVertex({ 6144, 4096 }, { 24576, 16384 }), + RasterProgram::layoutVertex({ 8192, 4096 }, { 32768, 16384 }), + RasterProgram::layoutVertex({ 6144, 6144 }, { 24576, 24576 }), + RasterProgram::layoutVertex({ 8192, 6144 }, { 32768, 24576 }), + + // 3/6/7 + RasterProgram::layoutVertex({ 6144, 7168 }, { 24576, 28672 }), + RasterProgram::layoutVertex({ 7168, 7168 }, { 28672, 28672 }), + RasterProgram::layoutVertex({ 6144, 8192 }, { 24576, 32768 }), + RasterProgram::layoutVertex({ 7168, 8192 }, { 28672, 32768 }), + + // 3/7/6 + RasterProgram::layoutVertex({ 7168, 6144 }, { 28672, 24576 }), + RasterProgram::layoutVertex({ 8192, 6144 }, { 32768, 24576 }), + RasterProgram::layoutVertex({ 7168, 7168 }, { 28672, 28672 }), + RasterProgram::layoutVertex({ 8192, 7168 }, { 32768, 28672 }), + }), + bucket.vertices.vector()); + + EXPECT_EQ( + (std::vector<uint16_t>{ + // 1/0/1 + 0, 1, 2, + 1, 2, 3, + + // 1/1/0 + 4, 5, 6, + 5, 6, 7, + + // 2/2/3 + 8, 9, 10, + 9, 10, 11, + + // 2/3/2 + 12, 13, 14, + 13, 14, 15, + + // 3/6/7 + 16, 17, 18, + 17, 18, 19, + + // 3/7/6 + 20, 21, 22, + 21, 22, 23, + }), + bucket.indices.vector()); + + + SegmentVector<RasterAttributes> expectedSegments; + expectedSegments.emplace_back(0, 0, 24, 36); + EXPECT_EQ(expectedSegments, bucket.segments); + } |