Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | #include "gmock/gmock.h" |
| 8 | #include "gtest/gtest.h" |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 9 | |
| 10 | #include "common/utilities.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/ImageIndex.h" |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 12 | |
| 13 | using namespace gl; |
| 14 | |
| 15 | namespace |
| 16 | { |
| 17 | |
| 18 | static const GLint minMip = 0; |
| 19 | static const GLint maxMip = 4; |
| 20 | static const GLint minLayer = 1; |
| 21 | static const GLint maxLayer = 3; |
| 22 | |
| 23 | TEST(ImageIndexTest, Iterator2D) |
| 24 | { |
| 25 | ImageIndexIterator iter = ImageIndexIterator::Make2D(minMip, maxMip); |
| 26 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 27 | ASSERT_GE(0, minMip); |
| 28 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 29 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 30 | { |
| 31 | EXPECT_TRUE(iter.hasNext()); |
| 32 | ImageIndex current = iter.current(); |
| 33 | ImageIndex nextIndex = iter.next(); |
| 34 | |
Kenneth Russell | e0a2d1c | 2014-10-06 17:45:59 -0700 | [diff] [blame] | 35 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), nextIndex.type); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 36 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 37 | EXPECT_FALSE(nextIndex.hasLayer()); |
| 38 | |
| 39 | // Also test current |
| 40 | EXPECT_EQ(current.type, nextIndex.type); |
| 41 | EXPECT_EQ(current.mipIndex, nextIndex.mipIndex); |
| 42 | EXPECT_EQ(current.layerIndex, nextIndex.layerIndex); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | TEST(ImageIndexTest, IteratorCube) |
| 47 | { |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 48 | ImageIndexIterator iter = ImageIndexIterator::MakeCube(0, 4); |
| 49 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 50 | ASSERT_GE(0, minMip); |
| 51 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 52 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 53 | { |
| 54 | for (GLint layer = 0; layer < 6; layer++) |
| 55 | { |
| 56 | EXPECT_TRUE(iter.hasNext()); |
| 57 | ImageIndex nextIndex = iter.next(); |
| 58 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 59 | GLenum cubeTarget = LayerIndexToCubeMapTextureTarget(layer); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 60 | |
| 61 | EXPECT_EQ(cubeTarget, nextIndex.type); |
| 62 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 63 | EXPECT_EQ(layer, nextIndex.layerIndex); |
| 64 | EXPECT_TRUE(nextIndex.hasLayer()); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | TEST(ImageIndexTest, Iterator3D) |
| 70 | { |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 71 | ImageIndexIterator iter = ImageIndexIterator::Make3D(minMip, maxMip, minLayer, maxLayer); |
| 72 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 73 | ASSERT_GE(0, minMip); |
| 74 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 75 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 76 | { |
| 77 | for (GLint layer = minLayer; layer < maxLayer; layer++) |
| 78 | { |
| 79 | EXPECT_TRUE(iter.hasNext()); |
| 80 | ImageIndex nextIndex = iter.next(); |
| 81 | |
Kenneth Russell | e0a2d1c | 2014-10-06 17:45:59 -0700 | [diff] [blame] | 82 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_3D), nextIndex.type); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 83 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 84 | EXPECT_EQ(layer, nextIndex.layerIndex); |
| 85 | EXPECT_TRUE(nextIndex.hasLayer()); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | TEST(ImageIndexTest, Iterator2DArray) |
| 91 | { |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 92 | GLsizei layerCounts[] = { 1, 3, 5, 2 }; |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 93 | |
| 94 | ImageIndexIterator iter = ImageIndexIterator::Make2DArray(minMip, maxMip, layerCounts); |
| 95 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 96 | ASSERT_GE(0, minMip); |
| 97 | ASSERT_EQ(ArraySize(layerCounts), static_cast<size_t>(maxMip)); |
| 98 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 99 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 100 | { |
| 101 | for (GLint layer = 0; layer < layerCounts[mip]; layer++) |
| 102 | { |
| 103 | EXPECT_TRUE(iter.hasNext()); |
| 104 | ImageIndex nextIndex = iter.next(); |
| 105 | |
Kenneth Russell | e0a2d1c | 2014-10-06 17:45:59 -0700 | [diff] [blame] | 106 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D_ARRAY), nextIndex.type); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 107 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 108 | EXPECT_EQ(layer, nextIndex.layerIndex); |
| 109 | EXPECT_TRUE(nextIndex.hasLayer()); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | } // namespace |