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); |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 36 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), nextIndex.target); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 37 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 38 | EXPECT_FALSE(nextIndex.hasLayer()); |
| 39 | |
| 40 | // Also test current |
| 41 | EXPECT_EQ(current.type, nextIndex.type); |
| 42 | EXPECT_EQ(current.mipIndex, nextIndex.mipIndex); |
| 43 | EXPECT_EQ(current.layerIndex, nextIndex.layerIndex); |
| 44 | } |
Jamie Madill | 96f4f45 | 2016-09-02 16:20:11 -0400 | [diff] [blame] | 45 | |
| 46 | EXPECT_FALSE(iter.hasNext()); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | TEST(ImageIndexTest, IteratorCube) |
| 50 | { |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 51 | ImageIndexIterator iter = ImageIndexIterator::MakeCube(minMip, maxMip); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 52 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 53 | ASSERT_GE(0, minMip); |
| 54 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 55 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 56 | { |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 57 | for (GLenum target = FirstCubeMapTextureTarget; target <= LastCubeMapTextureTarget; |
| 58 | target++) |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 59 | { |
| 60 | EXPECT_TRUE(iter.hasNext()); |
| 61 | ImageIndex nextIndex = iter.next(); |
| 62 | |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 63 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP), nextIndex.type); |
| 64 | EXPECT_EQ(target, nextIndex.target); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 65 | EXPECT_EQ(mip, nextIndex.mipIndex); |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 66 | EXPECT_FALSE(nextIndex.hasLayer()); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 67 | } |
| 68 | } |
Jamie Madill | 96f4f45 | 2016-09-02 16:20:11 -0400 | [diff] [blame] | 69 | |
| 70 | EXPECT_FALSE(iter.hasNext()); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | TEST(ImageIndexTest, Iterator3D) |
| 74 | { |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 75 | ImageIndexIterator iter = ImageIndexIterator::Make3D(minMip, maxMip, minLayer, maxLayer); |
| 76 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 77 | ASSERT_GE(0, minMip); |
| 78 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 79 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 80 | { |
| 81 | for (GLint layer = minLayer; layer < maxLayer; layer++) |
| 82 | { |
| 83 | EXPECT_TRUE(iter.hasNext()); |
| 84 | ImageIndex nextIndex = iter.next(); |
| 85 | |
Kenneth Russell | e0a2d1c | 2014-10-06 17:45:59 -0700 | [diff] [blame] | 86 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_3D), nextIndex.type); |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 87 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_3D), nextIndex.target); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 88 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 89 | EXPECT_EQ(layer, nextIndex.layerIndex); |
| 90 | EXPECT_TRUE(nextIndex.hasLayer()); |
| 91 | } |
| 92 | } |
Jamie Madill | 96f4f45 | 2016-09-02 16:20:11 -0400 | [diff] [blame] | 93 | |
| 94 | EXPECT_FALSE(iter.hasNext()); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | TEST(ImageIndexTest, Iterator2DArray) |
| 98 | { |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 99 | GLsizei layerCounts[] = { 1, 3, 5, 2 }; |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 100 | |
| 101 | ImageIndexIterator iter = ImageIndexIterator::Make2DArray(minMip, maxMip, layerCounts); |
| 102 | |
Jamie Madill | 1ea5350 | 2014-10-06 12:54:10 -0400 | [diff] [blame] | 103 | ASSERT_GE(0, minMip); |
| 104 | ASSERT_EQ(ArraySize(layerCounts), static_cast<size_t>(maxMip)); |
| 105 | |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 106 | for (GLint mip = minMip; mip < maxMip; mip++) |
| 107 | { |
| 108 | for (GLint layer = 0; layer < layerCounts[mip]; layer++) |
| 109 | { |
| 110 | EXPECT_TRUE(iter.hasNext()); |
| 111 | ImageIndex nextIndex = iter.next(); |
| 112 | |
Kenneth Russell | e0a2d1c | 2014-10-06 17:45:59 -0700 | [diff] [blame] | 113 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D_ARRAY), nextIndex.type); |
Geoff Lang | b52fac0 | 2018-02-21 15:45:35 -0500 | [diff] [blame] | 114 | EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D_ARRAY), nextIndex.target); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 115 | EXPECT_EQ(mip, nextIndex.mipIndex); |
| 116 | EXPECT_EQ(layer, nextIndex.layerIndex); |
| 117 | EXPECT_TRUE(nextIndex.hasLayer()); |
| 118 | } |
| 119 | } |
Jamie Madill | 96f4f45 | 2016-09-02 16:20:11 -0400 | [diff] [blame] | 120 | |
| 121 | EXPECT_FALSE(iter.hasNext()); |
Jamie Madill | ef4ac5b | 2014-09-29 10:46:11 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | } // namespace |