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.
5 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h>
13 #include "base/memory/scoped_vector.h"
14 #include "gpu/command_buffer/tests/gl_manager.h"
15 #include "gpu/command_buffer/tests/gl_test_utils.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 #define SHADER(src) #src
25 enum CopyType
{ TexImage
, TexSubImage
};
26 const CopyType kCopyTypes
[] = {
31 const uint8 kCompressedImageColor
[4] = { 255u, 0u, 0u, 255u };
33 // Single compressed ATC block of source pixels all set to:
34 // kCompressedImageColor.
35 const uint8 kCompressedImageATC
[8] = {
36 0x0, 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 };
38 // Single compressed ATCIA block of source pixels all set to:
39 // kCompressedImageColor.
40 const uint8 kCompressedImageATCIA
[16] = {
41 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
42 0x7c, 0x0, 0xf8, 0x55, 0x55, 0x55, 0x55 };
44 // Single compressed DXT1 block of source pixels all set to:
45 // kCompressedImageColor.
46 const uint8 kCompressedImageDXT1
[8] = {
47 0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa };
49 // Four compressed DXT1 blocks solidly colored in red, green, blue and black:
52 const uint8 kCompressedImageDXT1RGB
[32] = {
53 0x0, 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa,
54 0xe0, 0x7, 0xe0, 0x7, 0xaa, 0xaa, 0xaa, 0xaa,
55 0x1f, 0x0, 0x1f, 0x0, 0xaa, 0xaa, 0xaa, 0xaa,
56 0x0, 0x0, 0x0, 0x0, 0xaa, 0xaa, 0xaa, 0xaa };
58 // Single compressed DXT5 block of source pixels all set to:
59 // kCompressedImageColor.
60 const uint8 kCompressedImageDXT5
[16] = {
61 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
62 0xf8, 0x0, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa };
64 // Single compressed DXT1 block of source pixels all set to:
65 // kCompressedImageColor.
66 const uint8 kCompressedImageETC1
[8] = {
67 0x0, 0x0, 0xf8, 0x2, 0xff, 0xff, 0x0, 0x0 };
69 // Single block of zeroes, used for texture pre-allocation.
70 const uint8 kInvalidCompressedImage
[8] = {
71 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
73 // Four blocks of zeroes, used for texture pre-allocation.
74 const uint8 kInvalidCompressedImageLarge
[32] = {
75 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
76 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
77 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
78 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
80 void glEnableDisable(GLint param
, GLboolean value
) {
87 } // unnamed namespace
89 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
90 class GLCompressedCopyTextureCHROMIUMTest
91 : public testing::Test
,
92 public ::testing::WithParamInterface
<CopyType
> {
94 void SetUp() override
{
95 gl_
.Initialize(GLManager::Options());
97 glGenTextures(2, textures_
);
100 void TearDown() override
{
101 glDeleteTextures(2, textures_
);
105 GLuint
LoadProgram() {
106 const char* v_shader_src
= SHADER(
107 attribute vec2 a_position
;
108 varying vec2 v_texcoord
;
110 gl_Position
= vec4(a_position
, 0.0, 1.0);
111 v_texcoord
= (a_position
+ 1.0) * 0.5;
114 const char* f_shader_src
= SHADER(
115 precision mediump
float;
116 uniform sampler2D u_texture
;
117 varying vec2 v_texcoord
;
119 gl_FragColor
= texture2D(u_texture
, v_texcoord
);
122 return GLTestHelper::LoadProgram(v_shader_src
, f_shader_src
);
127 GLuint framebuffer_id_
;
130 INSTANTIATE_TEST_CASE_P(CopyType
,
131 GLCompressedCopyTextureCHROMIUMTest
,
132 ::testing::ValuesIn(kCopyTypes
));
134 // Test to ensure that the basic functionality of the extension works.
135 TEST_P(GLCompressedCopyTextureCHROMIUMTest
, Basic
) {
136 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
138 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
142 CopyType copy_type
= GetParam();
144 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
145 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
146 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
147 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
148 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
149 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
151 sizeof(kCompressedImageDXT1
), kCompressedImageDXT1
);
152 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
154 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
155 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
156 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
157 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
158 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
159 if (copy_type
== TexImage
) {
160 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1]);
162 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
164 sizeof(kInvalidCompressedImage
),
165 kInvalidCompressedImage
);
167 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
168 textures_
[1], 0, 0, 0, 0, 4, 4);
170 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
172 // Load shader program.
173 GLuint program
= LoadProgram();
174 ASSERT_NE(program
, 0u);
175 GLint position_loc
= glGetAttribLocation(program
, "a_position");
176 GLint texture_loc
= glGetUniformLocation(program
, "u_texture");
177 ASSERT_NE(position_loc
, -1);
178 ASSERT_NE(texture_loc
, -1);
179 glUseProgram(program
);
182 GLuint vbo
= GLTestHelper::SetupUnitQuad(position_loc
);
186 glActiveTexture(GL_TEXTURE0
);
187 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
188 glUniform1i(texture_loc
, 0);
191 glDrawArrays(GL_TRIANGLES
, 0, 6);
194 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, kCompressedImageColor
);
195 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
198 TEST_P(GLCompressedCopyTextureCHROMIUMTest
, InternalFormat
) {
199 CopyType copy_type
= GetParam();
204 const GLsizei data_size
;
206 Image(const GLint format
, const uint8
* data
, const GLsizei data_size
) :
207 format(format
), data(data
), data_size(data_size
) {}
209 ScopedVector
<Image
> supported_formats
;
211 if ((GLTestHelper::HasExtension("GL_AMD_compressed_ATC_texture") ||
212 GLTestHelper::HasExtension("GL_ATI_texture_compression_atitc")) &&
213 copy_type
!= TexSubImage
) {
214 supported_formats
.push_back(new Image(
217 sizeof(kCompressedImageATC
)));
218 supported_formats
.push_back(new Image(
219 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
,
220 kCompressedImageATCIA
,
221 sizeof(kCompressedImageATCIA
)));
223 if (GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
224 supported_formats
.push_back(new Image(
225 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
226 kCompressedImageDXT1
,
227 sizeof(kCompressedImageDXT1
)));
229 if (GLTestHelper::HasExtension("GL_ANGLE_texture_compression_dxt5") ||
230 GLTestHelper::HasExtension("GL_EXT_texture_compression_s3tc")) {
231 supported_formats
.push_back(new Image(
232 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
233 kCompressedImageDXT5
,
234 sizeof(kCompressedImageDXT5
)));
236 if (GLTestHelper::HasExtension("GL_OES_compressed_ETC1_RGB8_texture") &&
237 copy_type
!= TexSubImage
) {
238 supported_formats
.push_back(new Image(
240 kCompressedImageETC1
,
241 sizeof(kCompressedImageETC1
)));
244 for (const Image
* image
: supported_formats
) {
245 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
246 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
247 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
248 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
249 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
250 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, image
->format
,
251 4, 4, 0, image
->data_size
, image
->data
);
252 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
254 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
255 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
256 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
257 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
258 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
259 if (copy_type
== TexImage
) {
260 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
263 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, image
->format
, 4, 4, 0,
264 sizeof(kInvalidCompressedImage
),
265 kInvalidCompressedImage
);
267 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
268 textures_
[1], 0, 0, 0, 0, 4, 4);
270 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
274 TEST_P(GLCompressedCopyTextureCHROMIUMTest
, InternalFormatNotSupported
) {
275 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
277 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
281 CopyType copy_type
= GetParam();
283 const uint8 kUncompressedPixels
[1 * 4] = { 255u, 0u, 0u, 255u };
285 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
286 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
287 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
288 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
289 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
290 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
291 kUncompressedPixels
);
292 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
294 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
295 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
296 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
297 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
298 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
300 // Check that the GL_RGBA format reports an error.
301 if (copy_type
== TexImage
) {
302 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1]);
304 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
305 kUncompressedPixels
);
307 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
308 textures_
[1], 0, 0, 0, 0, 1, 1);
310 EXPECT_TRUE(GL_INVALID_OPERATION
== glGetError());
313 // Validate that some basic GL state is not touched upon execution of
315 TEST_P(GLCompressedCopyTextureCHROMIUMTest
, BasicStatePreservation
) {
316 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
318 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
322 CopyType copy_type
= GetParam();
324 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
325 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
326 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
327 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
328 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
329 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
331 sizeof(kCompressedImageDXT1
), kCompressedImageDXT1
);
332 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
334 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
335 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
336 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
337 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
338 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
340 if (copy_type
== TexSubImage
) {
341 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
343 sizeof(kInvalidCompressedImage
),
344 kInvalidCompressedImage
);
347 GLboolean reference_settings
[2] = { GL_TRUE
, GL_FALSE
};
348 for (int x
= 0; x
< 2; ++x
) {
349 GLboolean setting
= reference_settings
[x
];
350 glEnableDisable(GL_DEPTH_TEST
, setting
);
351 glEnableDisable(GL_SCISSOR_TEST
, setting
);
352 glEnableDisable(GL_STENCIL_TEST
, setting
);
353 glEnableDisable(GL_CULL_FACE
, setting
);
354 glEnableDisable(GL_BLEND
, setting
);
355 glColorMask(setting
, setting
, setting
, setting
);
356 glDepthMask(setting
);
358 glActiveTexture(GL_TEXTURE1
+ x
);
360 if (copy_type
== TexImage
) {
361 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
364 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
365 textures_
[1], 0, 0, 0, 0, 4, 4);
367 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
369 EXPECT_EQ(setting
, glIsEnabled(GL_DEPTH_TEST
));
370 EXPECT_EQ(setting
, glIsEnabled(GL_SCISSOR_TEST
));
371 EXPECT_EQ(setting
, glIsEnabled(GL_STENCIL_TEST
));
372 EXPECT_EQ(setting
, glIsEnabled(GL_CULL_FACE
));
373 EXPECT_EQ(setting
, glIsEnabled(GL_BLEND
));
375 GLboolean bool_array
[4] = { GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
};
376 glGetBooleanv(GL_DEPTH_WRITEMASK
, bool_array
);
377 EXPECT_EQ(setting
, bool_array
[0]);
379 bool_array
[0] = GL_FALSE
;
380 glGetBooleanv(GL_COLOR_WRITEMASK
, bool_array
);
381 EXPECT_EQ(setting
, bool_array
[0]);
382 EXPECT_EQ(setting
, bool_array
[1]);
383 EXPECT_EQ(setting
, bool_array
[2]);
384 EXPECT_EQ(setting
, bool_array
[3]);
386 GLint active_texture
= 0;
387 glGetIntegerv(GL_ACTIVE_TEXTURE
, &active_texture
);
388 EXPECT_EQ(GL_TEXTURE1
+ x
, active_texture
);
391 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
394 // Verify that invocation of the extension does not modify the bound
396 TEST_P(GLCompressedCopyTextureCHROMIUMTest
, TextureStatePreserved
) {
397 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
399 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
403 CopyType copy_type
= GetParam();
405 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
406 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
407 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
408 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
409 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
410 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
412 sizeof(kCompressedImageDXT1
), kCompressedImageDXT1
);
413 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
415 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
416 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
417 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
418 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
419 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
421 if (copy_type
== TexSubImage
) {
422 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
424 sizeof(kInvalidCompressedImage
),
425 kInvalidCompressedImage
);
428 GLuint texture_ids
[2];
429 glGenTextures(2, texture_ids
);
431 glActiveTexture(GL_TEXTURE0
);
432 glBindTexture(GL_TEXTURE_2D
, texture_ids
[0]);
434 glActiveTexture(GL_TEXTURE1
);
435 glBindTexture(GL_TEXTURE_2D
, texture_ids
[1]);
437 if (copy_type
== TexImage
) {
438 glCompressedCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1]);
440 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
441 textures_
[1], 0, 0, 0, 0, 4, 4);
443 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
445 GLint active_texture
= 0;
446 glGetIntegerv(GL_ACTIVE_TEXTURE
, &active_texture
);
447 EXPECT_EQ(GL_TEXTURE1
, active_texture
);
449 GLint bound_texture
= 0;
450 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &bound_texture
);
451 EXPECT_EQ(texture_ids
[1], static_cast<GLuint
>(bound_texture
));
452 glBindTexture(GL_TEXTURE_2D
, 0);
455 glActiveTexture(GL_TEXTURE0
);
456 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &bound_texture
);
457 EXPECT_EQ(texture_ids
[0], static_cast<GLuint
>(bound_texture
));
458 glBindTexture(GL_TEXTURE_2D
, 0);
460 glDeleteTextures(2, texture_ids
);
462 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
465 TEST_F(GLCompressedCopyTextureCHROMIUMTest
, CopySubTextureDimension
) {
466 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
468 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
472 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
473 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
474 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
475 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
476 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
477 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
479 sizeof(kCompressedImageDXT1RGB
),
480 kCompressedImageDXT1RGB
);
481 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
483 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
484 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
485 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
486 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
487 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
488 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
490 sizeof(kInvalidCompressedImageLarge
),
491 kInvalidCompressedImageLarge
);
493 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
494 textures_
[1], 4, 4, 0, 0, 4, 4);
495 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
497 // Reset the destination texture as it might have been converted to RGBA.
498 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
500 sizeof(kInvalidCompressedImageLarge
),
501 kInvalidCompressedImageLarge
);
504 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
506 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
509 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
511 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
513 // xoffset + width > dest_width
514 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
516 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
518 // x + width > source_width
519 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
521 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
523 // xoffset not within block-boundary
524 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
526 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION
);
528 // x not within block-boundary
529 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
531 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION
);
534 TEST_F(GLCompressedCopyTextureCHROMIUMTest
, CopySubTextureOffset
) {
535 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
537 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
541 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
542 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
543 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
544 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
545 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
546 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
548 sizeof(kCompressedImageDXT1RGB
),
549 kCompressedImageDXT1RGB
);
550 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
552 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
553 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
554 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
555 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
556 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
557 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
559 sizeof(kInvalidCompressedImageLarge
),
560 kInvalidCompressedImageLarge
);
562 // Load shader program.
563 GLuint program
= LoadProgram();
564 ASSERT_NE(program
, 0u);
565 GLint position_loc
= glGetAttribLocation(program
, "a_position");
566 GLint texture_loc
= glGetUniformLocation(program
, "u_texture");
567 ASSERT_NE(position_loc
, -1);
568 ASSERT_NE(texture_loc
, -1);
569 glUseProgram(program
);
572 GLuint vbo
= GLTestHelper::SetupUnitQuad(position_loc
);
576 glActiveTexture(GL_TEXTURE0
);
577 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
578 glUniform1i(texture_loc
, 0);
580 const uint8 kBlack
[1 * 4] = {0u, 0u, 0u, 255u};
581 const uint8 kRed
[1 * 4] = {255u, 0u, 0u, 255u};
582 const uint8 kGreen
[1 * 4] = {0u, 255u, 0u, 255u};
583 const uint8 kBlue
[1 * 4] = {0u, 0u, 255u, 255u};
585 // Copy each block one by one in a clockwise fashion. Note that we reset the
586 // destination texture after each copy operation. That's because on some
587 // platforms we might fallback into replacing the compressed destination
588 // texture with an uncompressed one.
590 // Move blue block up.
591 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
592 textures_
[1], 0, 0, 0, 4, 4, 4);
593 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
595 glDrawArrays(GL_TRIANGLES
, 0, 6);
597 GLTestHelper::CheckPixels(0, 0, 2, 2, 0, kBlue
);
599 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
600 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
602 sizeof(kInvalidCompressedImageLarge
),
603 kInvalidCompressedImageLarge
);
605 // Move red block right.
606 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
607 textures_
[1], 4, 0, 0, 0, 4, 4);
608 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
610 glDrawArrays(GL_TRIANGLES
, 0, 6);
612 GLTestHelper::CheckPixels(2, 0, 2, 2, 0, kRed
);
614 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
616 sizeof(kInvalidCompressedImageLarge
),
617 kInvalidCompressedImageLarge
);
619 // Move green block down.
620 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
621 textures_
[1], 4, 4, 4, 0, 4, 4);
622 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
624 glDrawArrays(GL_TRIANGLES
, 0, 6);
626 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kGreen
);
628 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
630 sizeof(kInvalidCompressedImageLarge
),
631 kInvalidCompressedImageLarge
);
633 // Move black block left.
634 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
635 textures_
[1], 0, 4, 4, 4, 4, 4);
636 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
638 glDrawArrays(GL_TRIANGLES
, 0, 6);
640 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlack
);
642 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
645 TEST_F(GLCompressedCopyTextureCHROMIUMTest
, CopySubTexturePreservation
) {
646 if (!GLTestHelper::HasExtension("GL_EXT_texture_compression_dxt1")) {
648 "GL_EXT_texture_compression_dxt1 not supported. Skipping test...";
652 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
653 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
654 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
655 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
656 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
657 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
659 sizeof(kCompressedImageDXT1
),
660 kCompressedImageDXT1
);
661 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
663 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
664 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
665 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
666 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
667 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
668 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
670 sizeof(kCompressedImageDXT1RGB
),
671 kCompressedImageDXT1RGB
);
673 // Copy entire first texture into the second, replacing the green block:
676 glCompressedCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0],
677 textures_
[1], 4, 0, 0, 0, 4, 4);
678 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
680 // Load shader program.
681 GLuint program
= LoadProgram();
682 ASSERT_NE(program
, 0u);
683 GLint position_loc
= glGetAttribLocation(program
, "a_position");
684 GLint texture_loc
= glGetUniformLocation(program
, "u_texture");
685 ASSERT_NE(position_loc
, -1);
686 ASSERT_NE(texture_loc
, -1);
687 glUseProgram(program
);
690 GLuint vbo
= GLTestHelper::SetupUnitQuad(position_loc
);
694 glActiveTexture(GL_TEXTURE0
);
695 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
696 glUniform1i(texture_loc
, 0);
699 glDrawArrays(GL_TRIANGLES
, 0, 6);
702 const uint8 kBlack
[1 * 4] = {0u, 0u, 0u, 255u};
703 const uint8 kRed
[1 * 4] = {255u, 0u, 0u, 255u};
704 const uint8 kBlue
[1 * 4] = {0u, 0u, 255u, 255u};
706 // Note that while destination texture is 8 x 8 pixels the viewport is only
708 GLTestHelper::CheckPixels(0, 0, 4, 2, 0, kRed
);
709 GLTestHelper::CheckPixels(0, 2, 2, 2, 0, kBlue
);
710 GLTestHelper::CheckPixels(2, 2, 2, 2, 0, kBlack
);
711 EXPECT_TRUE(GL_NO_ERROR
== glGetError());