Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: gpu/command_buffer/tests/gl_copy_compressed_texture_CHROMIUM_unittest.cc

Issue 1119723003: Add glCopyCompressedTextureCHROMIUM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments in tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
7 #endif
8
9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h>
12
13 #include "gpu/command_buffer/tests/gl_manager.h"
14 #include "gpu/command_buffer/tests/gl_test_utils.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 #define SHADER(src) #src
19
20 namespace gpu {
21
22 namespace {
23
24 const uint8 kCompressedImageColor[4] = { 255u, 0u, 0u, 255u };
25
26 // Single compressed ATC block of source pixels all set to:
27 // kCompressedImageColor.
28 const uint8 kCompressedImageATC[8] = {
29 0x0, 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 };
30
31 // Single compressed ATCIA block of source pixels all set to:
32 // kCompressedImageColor.
33 const uint8 kCompressedImageATCIA[16] = {
34 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
35 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 };
36
37 // Single compressed DXT1 block of source pixels all set to:
38 // kCompressedImageColor.
39 const uint8 kCompressedImageDXT1[8] = {
40 0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa };
41
42 // Single compressed DXT5 block of source pixels all set to:
43 // kCompressedImageColor.
44 const uint8 kCompressedImageDXT5[16] = {
45 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
46 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa };
47
48 // Single compressed DXT1 block of source pixels all set to:
49 // kCompressedImageColor.
50 const uint8 kCompressedImageETC1[8] = {
51 0x0, 0x0, 0xf8, 0x2, 0xff, 0xff, 0x0, 0x0 };
52
53 void glEnableDisable(GLint param, GLboolean value) {
54 if (value)
55 glEnable(param);
56 else
57 glDisable(param);
58 }
59
60 } // unnamed namespace
61
62 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
63 class GLCopyCompressedTextureCHROMIUMTest
64 : public testing::Test {
65 protected:
66 void SetUp() override {
67 gl_.Initialize(GLManager::Options());
68
69 glGenTextures(2, textures_);
70 }
71
72 void TearDown() override {
73 glDeleteTextures(2, textures_);
74 gl_.Destroy();
75 }
76
77 GLuint LoadProgram() {
78 const char* v_shader_src = SHADER(
79 attribute vec2 a_position;
80 varying vec2 v_texcoord;
81 void main() {
82 gl_Position = vec4(a_position, 0.0, 1.0);
83 v_texcoord = (a_position + 1.0) * 0.5;
84 }
85 );
86 const char* f_shader_src = SHADER(
87 precision mediump float;
88 uniform sampler2D u_texture;
89 varying vec2 v_texcoord;
90 void main() {
91 gl_FragColor = texture2D(u_texture, v_texcoord);
92 }
93 );
94 return GLTestHelper::LoadProgram(v_shader_src, f_shader_src);
95 }
96
97 GLManager gl_;
98 GLuint textures_[2];
99 GLuint framebuffer_id_;
100 };
101
102 // Test to ensure that the basic functionality of the extension works.
103 TEST_F(GLCopyCompressedTextureCHROMIUMTest, Basic) {
104 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
105 LOG(INFO) <<
106 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
107 return;
108 }
109
110 glBindTexture(GL_TEXTURE_2D, textures_[0]);
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
115 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
116 4, 4, 0,
117 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
118 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
119
120 glBindTexture(GL_TEXTURE_2D, textures_[1]);
121 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
122 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
125 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
126 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
127 GL_UNSIGNED_BYTE,
128 sizeof(kCompressedImageDXT1));
129 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
130
131 // Load shader program.
132 GLuint program = LoadProgram();
133 ASSERT_NE(program, 0u);
134 GLint position_loc = glGetAttribLocation(program, "a_position");
135 GLint texture_loc = glGetUniformLocation(program, "u_texture");
136 ASSERT_NE(position_loc, -1);
137 ASSERT_NE(texture_loc, -1);
138 glUseProgram(program);
139
140 // Load geometry.
141 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
142 ASSERT_NE(vbo, 0u);
143
144 // Load texture.
145 glActiveTexture(GL_TEXTURE0);
146 glBindTexture(GL_TEXTURE_2D, textures_[1]);
147 glUniform1i(texture_loc, 0);
148
149 // Draw.
150 glDrawArrays(GL_TRIANGLES, 0, 6);
151 glFlush();
152
153 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor);
154 EXPECT_TRUE(GL_NO_ERROR == glGetError());
155 }
156
157 TEST_F(GLCopyCompressedTextureCHROMIUMTest, InternalFormat) {
158 struct Image {
159 const GLint format;
160 const uint8* data;
161 const GLsizei data_size;
162 };
163 std::vector<Image> supported_formats;
164
165 if (GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") ||
166 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) {
167 supported_formats.push_back({
168 GL_ATC_RGB_AMD,
169 kCompressedImageATC,
170 sizeof(kCompressedImageATC)});
171 supported_formats.push_back({
172 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD,
173 kCompressedImageATCIA,
174 sizeof(kCompressedImageATCIA)});
175 }
176 if (GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
177 supported_formats.push_back({
178 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
179 kCompressedImageDXT1,
180 sizeof(kCompressedImageDXT1)});
181 }
182 if (GLTestHelper::HasExtension("GL_ANGLE_texture_compression_dxt5") ||
183 GLTestHelper::HasExtension("GL_EXT_texture_compression_s3tc")) {
184 supported_formats.push_back({
185 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
186 kCompressedImageDXT5,
187 sizeof(kCompressedImageDXT5)});
188 }
189 if (GLTestHelper::HasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
190 supported_formats.push_back({
191 GL_ETC1_RGB8_OES,
192 kCompressedImageETC1,
193 sizeof(kCompressedImageETC1)});
194 }
195
196 for (const Image& image : supported_formats) {
197 glBindTexture(GL_TEXTURE_2D, textures_[0]);
198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
199 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
200 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
202 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image.format,
203 4, 4, 0, image.data_size, image.data);
204 EXPECT_TRUE(GL_NO_ERROR == glGetError());
205
206 glBindTexture(GL_TEXTURE_2D, textures_[1]);
207 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
208 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
210 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
211 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
212 image.format, GL_UNSIGNED_BYTE,
213 image.data_size);
214 EXPECT_TRUE(GL_NO_ERROR == glGetError());
215 }
216 }
217
218 TEST_F(GLCopyCompressedTextureCHROMIUMTest, InternalFormatNotSupportedX) {
219 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
220 LOG(INFO) <<
221 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
222 return;
223 }
224
225 glBindTexture(GL_TEXTURE_2D, textures_[0]);
226 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
229 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
230 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
231 4, 4, 0,
232 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
233 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
234
235 glBindTexture(GL_TEXTURE_2D, textures_[1]);
236 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
237 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
240
241 // Check unsupported format reports error.
242 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_BGRA_EXT, GL_LUMINANCE,
243 GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA};
244 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats);
245 dest_index++) {
246 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
247 unsupported_dest_formats[dest_index],
248 GL_UNSIGNED_BYTE,
249 sizeof(kCompressedImageDXT1));
250 EXPECT_TRUE(GL_INVALID_ENUM == glGetError()) <<
251 "dest_index:" << dest_index;
252 }
253 }
254
255 // Validate that some basic GL state is not touched upon execution of
256 // the extension.
257 TEST_F(GLCopyCompressedTextureCHROMIUMTest, BasicStatePreservation) {
258 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
259 LOG(INFO) <<
260 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
261 return;
262 }
263
264 glBindTexture(GL_TEXTURE_2D, textures_[0]);
265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
266 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
269 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
270 4, 4, 0,
271 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
272 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
273
274 glBindTexture(GL_TEXTURE_2D, textures_[1]);
275 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
276 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
279
280 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE };
281 for (int x = 0; x < 2; ++x) {
282 GLboolean setting = reference_settings[x];
283 glEnableDisable(GL_DEPTH_TEST, setting);
284 glEnableDisable(GL_SCISSOR_TEST, setting);
285 glEnableDisable(GL_STENCIL_TEST, setting);
286 glEnableDisable(GL_CULL_FACE, setting);
287 glEnableDisable(GL_BLEND, setting);
288 glColorMask(setting, setting, setting, setting);
289 glDepthMask(setting);
290
291 glActiveTexture(GL_TEXTURE1 + x);
292
293 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
294 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
295 GL_UNSIGNED_BYTE,
296 sizeof(kCompressedImageDXT1));
297 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
298
299 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST));
300 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST));
301 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST));
302 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE));
303 EXPECT_EQ(setting, glIsEnabled(GL_BLEND));
304
305 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
306 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array);
307 EXPECT_EQ(setting, bool_array[0]);
308
309 bool_array[0] = GL_FALSE;
310 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array);
311 EXPECT_EQ(setting, bool_array[0]);
312 EXPECT_EQ(setting, bool_array[1]);
313 EXPECT_EQ(setting, bool_array[2]);
314 EXPECT_EQ(setting, bool_array[3]);
315
316 GLint active_texture = 0;
317 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
318 EXPECT_EQ(GL_TEXTURE1 + x, active_texture);
319 }
320
321 EXPECT_TRUE(GL_NO_ERROR == glGetError());
322 };
323
324 // Verify that invocation of the extension does not modify the bound
325 // texture state.
326 TEST_F(GLCopyCompressedTextureCHROMIUMTest, TextureStatePreserved) {
327 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
328 LOG(INFO) <<
329 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
330 return;
331 }
332
333 glBindTexture(GL_TEXTURE_2D, textures_[0]);
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
338 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
339 4, 4, 0,
340 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
341 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
342
343 glBindTexture(GL_TEXTURE_2D, textures_[1]);
344 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
345 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
348
349 GLuint texture_ids[2];
350 glGenTextures(2, texture_ids);
351
352 glActiveTexture(GL_TEXTURE0);
353 glBindTexture(GL_TEXTURE_2D, texture_ids[0]);
354
355 glActiveTexture(GL_TEXTURE1);
356 glBindTexture(GL_TEXTURE_2D, texture_ids[1]);
357
358 glCopyCompressedTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1],
359 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
360 GL_UNSIGNED_BYTE,
361 sizeof(kCompressedImageDXT1));
362 EXPECT_TRUE(GL_NO_ERROR == glGetError());
363
364 GLint active_texture = 0;
365 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
366 EXPECT_EQ(GL_TEXTURE1, active_texture);
367
368 GLint bound_texture = 0;
369 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
370 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture));
371 glBindTexture(GL_TEXTURE_2D, 0);
372
373 bound_texture = 0;
374 glActiveTexture(GL_TEXTURE0);
375 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
376 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture));
377 glBindTexture(GL_TEXTURE_2D, 0);
378
379 glDeleteTextures(2, texture_ids);
380
381 EXPECT_TRUE(GL_NO_ERROR == glGetError());
382 }
383
384 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698