1 //
2 // Copyright 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"
9
10 #include "common/utilities.h"
11 #include "libANGLE/ImageIndex.h"
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
TEST(ImageIndexTest,Iterator2D)23 TEST(ImageIndexTest, Iterator2D)
24 {
25 ImageIndexIterator iter = ImageIndexIterator::Make2D(minMip, maxMip);
26
27 ASSERT_GE(0, minMip);
28
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
35 EXPECT_EQ(TextureType::_2D, nextIndex.getType());
36 EXPECT_EQ(TextureTarget::_2D, nextIndex.getTarget());
37 EXPECT_EQ(mip, nextIndex.getLevelIndex());
38 EXPECT_FALSE(nextIndex.hasLayer());
39 EXPECT_FALSE(nextIndex.has3DLayer());
40
41 // Also test current
42 EXPECT_EQ(current.getType(), nextIndex.getType());
43 EXPECT_EQ(current.getLevelIndex(), nextIndex.getLevelIndex());
44 EXPECT_EQ(current.getLayerIndex(), nextIndex.getLayerIndex());
45 }
46
47 EXPECT_FALSE(iter.hasNext());
48 }
49
TEST(ImageIndexTest,IteratorCube)50 TEST(ImageIndexTest, IteratorCube)
51 {
52 ImageIndexIterator iter = ImageIndexIterator::MakeCube(minMip, maxMip);
53
54 ASSERT_GE(0, minMip);
55
56 for (GLint mip = minMip; mip < maxMip; mip++)
57 {
58 for (TextureTarget target : AllCubeFaceTextureTargets())
59 {
60 EXPECT_TRUE(iter.hasNext());
61 ImageIndex nextIndex = iter.next();
62
63 EXPECT_EQ(TextureType::CubeMap, nextIndex.getType());
64 EXPECT_EQ(target, nextIndex.getTarget());
65 EXPECT_EQ(mip, nextIndex.getLevelIndex());
66 EXPECT_TRUE(nextIndex.hasLayer());
67 EXPECT_FALSE(nextIndex.has3DLayer());
68 }
69 }
70
71 EXPECT_FALSE(iter.hasNext());
72 }
73
TEST(ImageIndexTest,Iterator3D)74 TEST(ImageIndexTest, Iterator3D)
75 {
76 ImageIndexIterator iter = ImageIndexIterator::Make3D(minMip, maxMip, minLayer, maxLayer);
77
78 ASSERT_GE(0, minMip);
79
80 for (GLint mip = minMip; mip < maxMip; mip++)
81 {
82 for (GLint layer = minLayer; layer < maxLayer; layer++)
83 {
84 EXPECT_TRUE(iter.hasNext());
85 ImageIndex nextIndex = iter.next();
86
87 EXPECT_EQ(TextureType::_3D, nextIndex.getType());
88 EXPECT_EQ(TextureTarget::_3D, nextIndex.getTarget());
89 EXPECT_EQ(mip, nextIndex.getLevelIndex());
90 EXPECT_EQ(layer, nextIndex.getLayerIndex());
91 EXPECT_TRUE(nextIndex.hasLayer());
92 EXPECT_TRUE(nextIndex.has3DLayer());
93 }
94 }
95
96 EXPECT_FALSE(iter.hasNext());
97 }
98
TEST(ImageIndexTest,Iterator2DArray)99 TEST(ImageIndexTest, Iterator2DArray)
100 {
101 GLsizei layerCounts[] = {1, 3, 5, 2};
102
103 ImageIndexIterator iter = ImageIndexIterator::Make2DArray(minMip, maxMip, layerCounts);
104
105 ASSERT_GE(0, minMip);
106 ASSERT_EQ(ArraySize(layerCounts), static_cast<size_t>(maxMip));
107
108 for (GLint mip = minMip; mip < maxMip; mip++)
109 {
110 for (GLint layer = 0; layer < layerCounts[mip]; layer++)
111 {
112 EXPECT_TRUE(iter.hasNext());
113 ImageIndex nextIndex = iter.next();
114
115 EXPECT_EQ(TextureType::_2DArray, nextIndex.getType());
116 EXPECT_EQ(TextureTarget::_2DArray, nextIndex.getTarget());
117 EXPECT_EQ(mip, nextIndex.getLevelIndex());
118 EXPECT_EQ(layer, nextIndex.getLayerIndex());
119 EXPECT_TRUE(nextIndex.hasLayer());
120 EXPECT_TRUE(nextIndex.has3DLayer());
121 }
122 }
123
124 EXPECT_FALSE(iter.hasNext());
125 }
126
TEST(ImageIndexTest,LayerIterator2DArray)127 TEST(ImageIndexTest, LayerIterator2DArray)
128 {
129 GLsizei layerCounts[] = {1, 3, 5, 2};
130
131 ASSERT_GE(0, minMip);
132 ASSERT_EQ(ArraySize(layerCounts), static_cast<size_t>(maxMip));
133
134 for (GLint mip = minMip; mip < maxMip; mip++)
135 {
136 // Make a layer iterator.
137 ImageIndex mipImageIndex = ImageIndex::Make2DArray(mip, ImageIndex::kEntireLevel);
138 ImageIndexIterator iter = mipImageIndex.getLayerIterator(layerCounts[mip]);
139
140 for (GLint layer = 0; layer < layerCounts[mip]; layer++)
141 {
142 EXPECT_TRUE(iter.hasNext());
143 ImageIndex nextIndex = iter.next();
144
145 EXPECT_EQ(TextureType::_2DArray, nextIndex.getType());
146 EXPECT_EQ(TextureTarget::_2DArray, nextIndex.getTarget());
147 EXPECT_EQ(mip, nextIndex.getLevelIndex());
148 EXPECT_EQ(layer, nextIndex.getLayerIndex());
149 EXPECT_TRUE(nextIndex.hasLayer());
150 EXPECT_TRUE(nextIndex.has3DLayer());
151 EXPECT_LT(nextIndex.getLayerIndex(), layerCounts[mip]);
152 }
153
154 EXPECT_FALSE(iter.hasNext());
155 }
156 }
157
158 } // namespace
159