1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/service/texture_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gpu {
namespace gles2 {
class TextureManagerTest : public testing::Test {
public:
static const GLint kMaxTextureSize = 16;
static const GLint kMaxCubeMapTextureSize = 8;
static const GLint kMax2dLevels = 5;
static const GLint kMaxCubeMapLevels = 4;
TextureManagerTest()
: manager_(kMaxTextureSize, kMaxCubeMapTextureSize) {
}
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
TextureManager manager_;
};
// GCC requires these declarations, but MSVC requires they not be present
#ifndef COMPILER_MSVC
const GLint TextureManagerTest::kMaxTextureSize;
const GLint TextureManagerTest::kMaxCubeMapTextureSize;
const GLint TextureManagerTest::kMax2dLevels;
const GLint TextureManagerTest::kMaxCubeMapLevels;
#endif
TEST_F(TextureManagerTest, Basic) {
const GLuint kClient1Id = 1;
const GLuint kService1Id = 11;
const GLuint kClient2Id = 2;
// Check we can create texture.
manager_.CreateTextureInfo(kClient1Id, kService1Id);
// Check texture got created.
TextureManager::TextureInfo* info1 = manager_.GetTextureInfo(kClient1Id);
ASSERT_TRUE(info1 != NULL);
EXPECT_EQ(kService1Id, info1->service_id());
GLuint client_id = 0;
EXPECT_TRUE(manager_.GetClientId(info1->service_id(), &client_id));
EXPECT_EQ(kClient1Id, client_id);
// Check we get nothing for a non-existent texture.
EXPECT_TRUE(manager_.GetTextureInfo(kClient2Id) == NULL);
// Check trying to a remove non-existent textures does not crash.
manager_.RemoveTextureInfo(kClient2Id);
// Check we can't get the texture after we remove it.
manager_.RemoveTextureInfo(kClient1Id);
EXPECT_TRUE(manager_.GetTextureInfo(kClient1Id) == NULL);
}
TEST_F(TextureManagerTest, MaxValues) {
// Check we get the right values for the max sizes.
EXPECT_EQ(kMax2dLevels, manager_.MaxLevelsForTarget(GL_TEXTURE_2D));
EXPECT_EQ(kMaxCubeMapLevels,
manager_.MaxLevelsForTarget(GL_TEXTURE_CUBE_MAP));
EXPECT_EQ(kMaxTextureSize, manager_.MaxSizeForTarget(GL_TEXTURE_2D));
EXPECT_EQ(kMaxCubeMapTextureSize,
manager_.MaxSizeForTarget(GL_TEXTURE_CUBE_MAP));
}
TEST_F(TextureManagerTest, ValidForTexture) {
// check 2d
EXPECT_TRUE(manager_.ValidForTarget(
GL_TEXTURE_2D, 0,
kMaxTextureSize, kMaxTextureSize, 1));
EXPECT_TRUE(manager_.ValidForTarget(
GL_TEXTURE_2D, kMax2dLevels - 1,
kMaxTextureSize, kMaxTextureSize, 1));
EXPECT_TRUE(manager_.ValidForTarget(
GL_TEXTURE_2D, kMax2dLevels - 1,
1, kMaxTextureSize, 1));
EXPECT_TRUE(manager_.ValidForTarget(
GL_TEXTURE_2D, kMax2dLevels - 1,
kMaxTextureSize, 1, 1));
// check level out of range.
EXPECT_FALSE(manager_.ValidForTarget(
GL_TEXTURE_2D, kMax2dLevels,
kMaxTextureSize, 1, 1));
// check has depth.
EXPECT_FALSE(manager_.ValidForTarget(
GL_TEXTURE_2D, kMax2dLevels,
kMaxTextureSize, 1, 2));
// check cube
EXPECT_TRUE(manager_.ValidForTarget(
GL_TEXTURE_CUBE_MAP, 0,
kMaxCubeMapTextureSize, kMaxCubeMapTextureSize, 1));
EXPECT_TRUE(manager_.ValidForTarget(
GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels - 1,
kMaxCubeMapTextureSize, kMaxCubeMapTextureSize, 1));
// check level out of range.
EXPECT_FALSE(manager_.ValidForTarget(
GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels,
kMaxCubeMapTextureSize, 1, 1));
// check not square.
EXPECT_FALSE(manager_.ValidForTarget(
GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels,
kMaxCubeMapTextureSize, 1, 1));
// check has depth.
EXPECT_FALSE(manager_.ValidForTarget(
GL_TEXTURE_CUBE_MAP, kMaxCubeMapLevels,
kMaxCubeMapTextureSize, 1, 2));
}
class TextureInfoTest : public testing::Test {
public:
static const GLint kMaxTextureSize = 16;
static const GLint kMaxCubeMapTextureSize = 8;
static const GLint kMax2dLevels = 5;
static const GLint kMaxCubeMapLevels = 4;
static const GLuint kClient1Id = 1;
static const GLuint kService1Id = 11;
TextureInfoTest()
: manager_(kMaxTextureSize, kMaxCubeMapTextureSize) {
}
protected:
virtual void SetUp() {
manager_.CreateTextureInfo(kClient1Id, kService1Id);
info_ = manager_.GetTextureInfo(kClient1Id);
ASSERT_TRUE(info_ != NULL);
}
virtual void TearDown() {
}
TextureManager manager_;
TextureManager::TextureInfo* info_;
};
TEST_F(TextureInfoTest, Basic) {
EXPECT_EQ(0u, info_->target());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->cube_complete());
EXPECT_FALSE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->CanRender());
}
TEST_F(TextureInfoTest, POT2D) {
manager_.SetInfoTarget(info_, GL_TEXTURE_2D);
EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), info_->target());
// Check Setting level 0 to POT
info_->SetLevelInfo(
GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->CanRender());
// Set filters to something that will work with a single mip.
info_->SetParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
EXPECT_TRUE(info_->CanRender());
// Set them back.
info_->SetParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
EXPECT_TRUE(info_->CanGenerateMipmaps());
// Make mips.
EXPECT_TRUE(info_->MarkMipmapsGenerated());
EXPECT_TRUE(info_->texture_complete());
EXPECT_TRUE(info_->CanRender());
// Change a mip.
info_->SetLevelInfo(
GL_TEXTURE_2D, 1, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_TRUE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
// Set a level past the number of mips that would get generated.
info_->SetLevelInfo(
GL_TEXTURE_2D, 3, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_TRUE(info_->CanGenerateMipmaps());
// Make mips.
EXPECT_TRUE(info_->MarkMipmapsGenerated());
EXPECT_FALSE(info_->CanRender());
EXPECT_FALSE(info_->texture_complete());
}
TEST_F(TextureInfoTest, NPOT2D) {
manager_.SetInfoTarget(info_, GL_TEXTURE_2D);
EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), info_->target());
// Check Setting level 0 to NPOT
info_->SetLevelInfo(
GL_TEXTURE_2D, 0, GL_RGBA, 4, 5, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_TRUE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
info_->SetParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
EXPECT_FALSE(info_->CanRender());
info_->SetParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
EXPECT_FALSE(info_->CanRender());
info_->SetParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
EXPECT_TRUE(info_->CanRender());
// Change it to POT.
info_->SetLevelInfo(
GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_TRUE(info_->CanGenerateMipmaps());
}
TEST_F(TextureInfoTest, POTCubeMap) {
manager_.SetInfoTarget(info_, GL_TEXTURE_CUBE_MAP);
EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP), info_->target());
// Check Setting level 0 each face to POT
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->cube_complete());
EXPECT_FALSE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->cube_complete());
EXPECT_FALSE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->cube_complete());
EXPECT_FALSE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->cube_complete());
EXPECT_FALSE(info_->CanRender());
EXPECT_FALSE(info_->CanGenerateMipmaps());
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_FALSE(info_->cube_complete());
EXPECT_FALSE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
0, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_TRUE(info_->cube_complete());
EXPECT_TRUE(info_->CanGenerateMipmaps());
EXPECT_FALSE(info_->CanRender());
// Make mips.
EXPECT_TRUE(info_->MarkMipmapsGenerated());
EXPECT_TRUE(info_->texture_complete());
EXPECT_TRUE(info_->cube_complete());
// Change a mip.
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
1, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_FALSE(info_->npot());
EXPECT_FALSE(info_->texture_complete());
EXPECT_TRUE(info_->cube_complete());
EXPECT_TRUE(info_->CanGenerateMipmaps());
// Set a level past the number of mips that would get generated.
info_->SetLevelInfo(
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
3, GL_RGBA, 4, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
EXPECT_TRUE(info_->CanGenerateMipmaps());
// Make mips.
EXPECT_TRUE(info_->MarkMipmapsGenerated());
EXPECT_FALSE(info_->texture_complete());
EXPECT_TRUE(info_->cube_complete());
}
TEST_F(TextureInfoTest, GetLevelSize) {
manager_.SetInfoTarget(info_, GL_TEXTURE_2D);
info_->SetLevelInfo(
GL_TEXTURE_2D, 1, GL_RGBA, 4, 5, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE);
GLsizei width = -1;
GLsizei height = -1;
EXPECT_FALSE(info_->GetLevelSize(GL_TEXTURE_2D, -1, &width, &height));
EXPECT_FALSE(info_->GetLevelSize(GL_TEXTURE_2D, 1000, &width, &height));
EXPECT_TRUE(info_->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
EXPECT_EQ(0, width);
EXPECT_EQ(0, height);
EXPECT_TRUE(info_->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
EXPECT_EQ(4, width);
EXPECT_EQ(5, height);
manager_.RemoveTextureInfo(kClient1Id);
EXPECT_FALSE(info_->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
}
} // namespace gles2
} // namespace gpu
|