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

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

Issue 1119723003: Add glCopyCompressedTextureCHROMIUM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address issues 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 GLCompressedCopyTextureCHROMIUMTest
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(GLCompressedCopyTextureCHROMIUMTest, 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 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
126 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
127
128 // Load shader program.
129 GLuint program = LoadProgram();
130 ASSERT_NE(program, 0u);
131 GLint position_loc = glGetAttribLocation(program, "a_position");
132 GLint texture_loc = glGetUniformLocation(program, "u_texture");
133 ASSERT_NE(position_loc, -1);
134 ASSERT_NE(texture_loc, -1);
135 glUseProgram(program);
136
137 // Load geometry.
138 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc);
139 ASSERT_NE(vbo, 0u);
140
141 // Load texture.
142 glActiveTexture(GL_TEXTURE0);
143 glBindTexture(GL_TEXTURE_2D, textures_[1]);
144 glUniform1i(texture_loc, 0);
145
146 // Draw.
147 glDrawArrays(GL_TRIANGLES, 0, 6);
148 glFlush();
149
150 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor);
151 EXPECT_TRUE(GL_NO_ERROR == glGetError());
152 }
153
154 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InternalFormat) {
155 struct Image {
156 const GLint format;
157 const uint8* data;
158 const GLsizei data_size;
159 };
160 std::vector<Image> supported_formats;
161
162 if (GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") ||
163 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) {
164 supported_formats.push_back({
165 GL_ATC_RGB_AMD,
166 kCompressedImageATC,
167 sizeof(kCompressedImageATC)});
168 supported_formats.push_back({
169 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD,
170 kCompressedImageATCIA,
171 sizeof(kCompressedImageATCIA)});
172 }
173 if (GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
174 supported_formats.push_back({
175 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
176 kCompressedImageDXT1,
177 sizeof(kCompressedImageDXT1)});
178 }
179 if (GLTestHelper::HasExtension("GL_ANGLE_texture_compression_dxt5") ||
180 GLTestHelper::HasExtension("GL_EXT_texture_compression_s3tc")) {
181 supported_formats.push_back({
182 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
183 kCompressedImageDXT5,
184 sizeof(kCompressedImageDXT5)});
185 }
186 if (GLTestHelper::HasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
187 supported_formats.push_back({
188 GL_ETC1_RGB8_OES,
189 kCompressedImageETC1,
190 sizeof(kCompressedImageETC1)});
191 }
192
193 for (const Image& image : supported_formats) {
194 glBindTexture(GL_TEXTURE_2D, textures_[0]);
195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
198 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
199 glCompressedTexImage2D(GL_TEXTURE_2D, 0, image.format,
200 4, 4, 0, image.data_size, image.data);
201 EXPECT_TRUE(GL_NO_ERROR == glGetError());
202
203 glBindTexture(GL_TEXTURE_2D, textures_[1]);
204 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
205 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
208 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
209 EXPECT_TRUE(GL_NO_ERROR == glGetError());
210 }
211 }
212
213 TEST_F(GLCompressedCopyTextureCHROMIUMTest, InternalFormatNotSupported) {
214 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
215 LOG(INFO) <<
216 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
217 return;
218 }
219
220 const uint8 kUncompressedPixels[1 * 4] = { 255u, 0u, 0u, 255u };
221
222 glBindTexture(GL_TEXTURE_2D, textures_[0]);
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
226 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
227 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
228 kUncompressedPixels);
229 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
230
231 glBindTexture(GL_TEXTURE_2D, textures_[1]);
232 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
233 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
235 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
236
237 // Check that the GL_RGBA format reports an error.
238 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
239 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError());
240 }
241
242 // Validate that some basic GL state is not touched upon execution of
243 // the extension.
244 TEST_F(GLCompressedCopyTextureCHROMIUMTest, BasicStatePreservation) {
245 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
246 LOG(INFO) <<
247 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
248 return;
249 }
250
251 glBindTexture(GL_TEXTURE_2D, textures_[0]);
252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
255 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
256 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
257 4, 4, 0,
258 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
259 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
260
261 glBindTexture(GL_TEXTURE_2D, textures_[1]);
262 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
263 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
265 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
266
267 GLboolean reference_settings[2] = { GL_TRUE, GL_FALSE };
268 for (int x = 0; x < 2; ++x) {
269 GLboolean setting = reference_settings[x];
270 glEnableDisable(GL_DEPTH_TEST, setting);
271 glEnableDisable(GL_SCISSOR_TEST, setting);
272 glEnableDisable(GL_STENCIL_TEST, setting);
273 glEnableDisable(GL_CULL_FACE, setting);
274 glEnableDisable(GL_BLEND, setting);
275 glColorMask(setting, setting, setting, setting);
276 glDepthMask(setting);
277
278 glActiveTexture(GL_TEXTURE1 + x);
279
280 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
281 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
282
283 EXPECT_EQ(setting, glIsEnabled(GL_DEPTH_TEST));
284 EXPECT_EQ(setting, glIsEnabled(GL_SCISSOR_TEST));
285 EXPECT_EQ(setting, glIsEnabled(GL_STENCIL_TEST));
286 EXPECT_EQ(setting, glIsEnabled(GL_CULL_FACE));
287 EXPECT_EQ(setting, glIsEnabled(GL_BLEND));
288
289 GLboolean bool_array[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
290 glGetBooleanv(GL_DEPTH_WRITEMASK, bool_array);
291 EXPECT_EQ(setting, bool_array[0]);
292
293 bool_array[0] = GL_FALSE;
294 glGetBooleanv(GL_COLOR_WRITEMASK, bool_array);
295 EXPECT_EQ(setting, bool_array[0]);
296 EXPECT_EQ(setting, bool_array[1]);
297 EXPECT_EQ(setting, bool_array[2]);
298 EXPECT_EQ(setting, bool_array[3]);
299
300 GLint active_texture = 0;
301 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
302 EXPECT_EQ(GL_TEXTURE1 + x, active_texture);
303 }
304
305 EXPECT_TRUE(GL_NO_ERROR == glGetError());
306 };
307
308 // Verify that invocation of the extension does not modify the bound
309 // texture state.
310 TEST_F(GLCompressedCopyTextureCHROMIUMTest, TextureStatePreserved) {
311 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
312 LOG(INFO) <<
313 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
314 return;
315 }
316
317 glBindTexture(GL_TEXTURE_2D, textures_[0]);
318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
322 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
323 4, 4, 0,
324 sizeof(kCompressedImageDXT1), kCompressedImageDXT1);
325 EXPECT_TRUE(glGetError() == GL_NO_ERROR);
326
327 glBindTexture(GL_TEXTURE_2D, textures_[1]);
328 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
329 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
332
333 GLuint texture_ids[2];
334 glGenTextures(2, texture_ids);
335
336 glActiveTexture(GL_TEXTURE0);
337 glBindTexture(GL_TEXTURE_2D, texture_ids[0]);
338
339 glActiveTexture(GL_TEXTURE1);
340 glBindTexture(GL_TEXTURE_2D, texture_ids[1]);
341
342 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D, textures_[0], textures_[1]);
343 EXPECT_TRUE(GL_NO_ERROR == glGetError());
344
345 GLint active_texture = 0;
346 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
347 EXPECT_EQ(GL_TEXTURE1, active_texture);
348
349 GLint bound_texture = 0;
350 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
351 EXPECT_EQ(texture_ids[1], static_cast<GLuint>(bound_texture));
352 glBindTexture(GL_TEXTURE_2D, 0);
353
354 bound_texture = 0;
355 glActiveTexture(GL_TEXTURE0);
356 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture);
357 EXPECT_EQ(texture_ids[0], static_cast<GLuint>(bound_texture));
358 glBindTexture(GL_TEXTURE_2D, 0);
359
360 glDeleteTextures(2, texture_ids);
361
362 EXPECT_TRUE(GL_NO_ERROR == glGetError());
363 }
364
365 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698