1 // Copyright (c) 2012 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 "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"
21 enum CopyType
{ TexImage
, TexSubImage
};
22 const CopyType kCopyTypes
[] = {
28 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension.
29 class GLCopyTextureCHROMIUMTest
30 : public testing::Test
,
31 public ::testing::WithParamInterface
<CopyType
> {
33 void SetUp() override
{
34 gl_
.Initialize(GLManager::Options());
36 glGenTextures(2, textures_
);
37 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
39 // Some drivers (NVidia/SGX) require texture settings to be a certain way or
40 // they won't report FRAMEBUFFER_COMPLETE.
41 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
42 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
43 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
44 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
46 glGenFramebuffers(1, &framebuffer_id_
);
47 glBindFramebuffer(GL_FRAMEBUFFER
, framebuffer_id_
);
48 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
,
52 void TearDown() override
{
53 glDeleteTextures(2, textures_
);
54 glDeleteFramebuffers(1, &framebuffer_id_
);
60 GLuint framebuffer_id_
;
63 INSTANTIATE_TEST_CASE_P(CopyType
,
64 GLCopyTextureCHROMIUMTest
,
65 ::testing::ValuesIn(kCopyTypes
));
67 // Test to ensure that the basic functionality of the extension works.
68 TEST_P(GLCopyTextureCHROMIUMTest
, Basic
) {
69 CopyType copy_type
= GetParam();
70 uint8 pixels
[1 * 4] = { 255u, 0u, 0u, 255u };
72 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
73 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
76 if (copy_type
== TexImage
) {
77 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
80 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
81 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
84 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
87 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
89 // Check the FB is still bound.
91 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &value
);
93 EXPECT_EQ(framebuffer_id_
, fb_id
);
95 // Check that FB is complete.
96 EXPECT_EQ(static_cast<GLenum
>(GL_FRAMEBUFFER_COMPLETE
),
97 glCheckFramebufferStatus(GL_FRAMEBUFFER
));
99 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels
);
100 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
103 TEST_P(GLCopyTextureCHROMIUMTest
, ImmutableTexture
) {
104 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) {
105 LOG(INFO
) << "GL_EXT_texture_storage not supported. Skipping test...";
108 CopyType copy_type
= GetParam();
110 uint8 pixels
[1 * 4] = {255u, 0u, 0u, 255u};
112 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
113 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 1, 1);
114 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
117 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
118 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 1, 1);
119 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
,
121 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
123 if (copy_type
== TexImage
) {
124 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
126 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION
);
128 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
130 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
132 // Check the FB is still bound.
134 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &value
);
135 GLuint fb_id
= value
;
136 EXPECT_EQ(framebuffer_id_
, fb_id
);
138 // Check that FB is complete.
139 EXPECT_EQ(static_cast<GLenum
>(GL_FRAMEBUFFER_COMPLETE
),
140 glCheckFramebufferStatus(GL_FRAMEBUFFER
));
142 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels
);
143 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
147 TEST_P(GLCopyTextureCHROMIUMTest
, InternalFormat
) {
148 CopyType copy_type
= GetParam();
149 GLint src_formats
[] = {GL_ALPHA
, GL_RGB
, GL_RGBA
,
150 GL_LUMINANCE
, GL_LUMINANCE_ALPHA
, GL_BGRA_EXT
};
151 GLint dest_formats
[] = {GL_RGB
, GL_RGBA
};
153 for (size_t src_index
= 0; src_index
< arraysize(src_formats
); src_index
++) {
154 for (size_t dest_index
= 0; dest_index
< arraysize(dest_formats
);
156 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
157 glTexImage2D(GL_TEXTURE_2D
, 0, src_formats
[src_index
], 1, 1, 0,
158 src_formats
[src_index
], GL_UNSIGNED_BYTE
, nullptr);
159 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
161 if (copy_type
== TexImage
) {
162 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
163 dest_formats
[dest_index
], GL_UNSIGNED_BYTE
);
165 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
166 glTexImage2D(GL_TEXTURE_2D
, 0, dest_formats
[dest_index
], 1, 1, 0,
167 dest_formats
[dest_index
], GL_UNSIGNED_BYTE
, nullptr);
168 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
170 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0,
174 EXPECT_TRUE(GL_NO_ERROR
== glGetError()) << "src_index:" << src_index
175 << " dest_index:" << dest_index
;
180 TEST_P(GLCopyTextureCHROMIUMTest
, InternalFormatNotSupported
) {
181 CopyType copy_type
= GetParam();
182 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
183 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
185 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
187 // Check unsupported format reports error.
188 GLint unsupported_dest_formats
[] = {GL_ALPHA
, GL_LUMINANCE
,
190 for (size_t dest_index
= 0; dest_index
< arraysize(unsupported_dest_formats
);
192 if (copy_type
== TexImage
) {
193 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1],
194 unsupported_dest_formats
[dest_index
],
197 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
198 glTexImage2D(GL_TEXTURE_2D
, 0, unsupported_dest_formats
[dest_index
], 1, 1,
199 0, unsupported_dest_formats
[dest_index
], GL_UNSIGNED_BYTE
,
201 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0,
204 EXPECT_TRUE(GL_INVALID_OPERATION
== glGetError())
205 << "dest_index:" << dest_index
;
209 // Test to ensure that the destination texture is redefined if the properties
211 TEST_F(GLCopyTextureCHROMIUMTest
, RedefineDestinationTexture
) {
212 uint8 pixels
[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u,
213 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u};
215 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
217 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
219 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
220 glTexImage2D(GL_TEXTURE_2D
,
229 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
231 // GL_INVALID_OPERATION due to "intrinsic format" != "internal format".
233 GL_TEXTURE_2D
, 0, 0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
234 EXPECT_TRUE(GL_INVALID_OPERATION
== glGetError());
235 // GL_INVALID_VALUE due to bad dimensions.
237 GL_TEXTURE_2D
, 0, 1, 1, 1, 1, GL_BGRA_EXT
, GL_UNSIGNED_BYTE
, pixels
);
238 EXPECT_TRUE(GL_INVALID_VALUE
== glGetError());
240 // If the dest texture has different properties, glCopyTextureCHROMIUM()
242 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
244 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
246 // glTexSubImage2D() succeeds because textures_[1] is redefined into 2x2
247 // dimension and GL_RGBA format.
248 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
250 GL_TEXTURE_2D
, 0, 1, 1, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
251 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
253 // Check the FB is still bound.
255 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &value
);
256 GLuint fb_id
= value
;
257 EXPECT_EQ(framebuffer_id_
, fb_id
);
259 // Check that FB is complete.
260 EXPECT_EQ(static_cast<GLenum
>(GL_FRAMEBUFFER_COMPLETE
),
261 glCheckFramebufferStatus(GL_FRAMEBUFFER
));
263 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, &pixels
[12]);
264 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
267 // Test that the extension respects the flip-y pixel storage setting.
268 TEST_P(GLCopyTextureCHROMIUMTest
, FlipY
) {
269 CopyType copy_type
= GetParam();
270 uint8 pixels
[2][2][4];
271 for (int x
= 0; x
< 2; ++x
) {
272 for (int y
= 0; y
< 2; ++y
) {
273 pixels
[y
][x
][0] = x
+ y
;
274 pixels
[y
][x
][1] = x
+ y
;
275 pixels
[y
][x
][2] = x
+ y
;
276 pixels
[y
][x
][3] = 255u;
280 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
281 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
284 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM
, GL_TRUE
);
286 if (copy_type
== TexImage
) {
287 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
290 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
291 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
293 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
296 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
298 uint8 copied_pixels
[2][2][4] = {{{0}}};
299 glReadPixels(0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, copied_pixels
);
300 for (int x
= 0; x
< 2; ++x
) {
301 for (int y
= 0; y
< 2; ++y
) {
302 EXPECT_EQ(pixels
[1-y
][x
][0], copied_pixels
[y
][x
][0]);
303 EXPECT_EQ(pixels
[1-y
][x
][1], copied_pixels
[y
][x
][1]);
304 EXPECT_EQ(pixels
[1-y
][x
][2], copied_pixels
[y
][x
][2]);
305 EXPECT_EQ(pixels
[1-y
][x
][3], copied_pixels
[y
][x
][3]);
309 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
312 // Test that the extension respects the GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM
314 TEST_P(GLCopyTextureCHROMIUMTest
, PremultiplyAlpha
) {
315 CopyType copy_type
= GetParam();
316 uint8 pixels
[1 * 4] = { 2, 2, 2, 128 };
318 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
319 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
322 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM
, GL_TRUE
);
323 if (copy_type
== TexImage
) {
324 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
327 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
328 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
330 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
333 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
335 uint8 copied_pixels
[1 * 4] = {0};
336 glReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, copied_pixels
);
337 EXPECT_EQ(1u, copied_pixels
[0]);
338 EXPECT_EQ(1u, copied_pixels
[1]);
339 EXPECT_EQ(1u, copied_pixels
[2]);
340 EXPECT_EQ(128u, copied_pixels
[3]);
342 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
345 // Test that the extension respects the GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM
347 TEST_P(GLCopyTextureCHROMIUMTest
, UnpremultiplyAlpha
) {
348 CopyType copy_type
= GetParam();
349 uint8 pixels
[1 * 4] = { 16, 16, 16, 128 };
351 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
352 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
355 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM
, GL_TRUE
);
356 if (copy_type
== TexImage
) {
357 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
360 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
361 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
363 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
366 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
368 uint8 copied_pixels
[1 * 4] = {0};
369 glReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, copied_pixels
);
370 EXPECT_EQ(32u, copied_pixels
[0]);
371 EXPECT_EQ(32u, copied_pixels
[1]);
372 EXPECT_EQ(32u, copied_pixels
[2]);
373 EXPECT_EQ(128u, copied_pixels
[3]);
375 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
378 TEST_P(GLCopyTextureCHROMIUMTest
, FlipYAndPremultiplyAlpha
) {
379 CopyType copy_type
= GetParam();
380 uint8 pixels
[2][2][4];
381 for (int x
= 0; x
< 2; ++x
) {
382 for (int y
= 0; y
< 2; ++y
) {
383 uint8 color
= 16 * x
+ 16 * y
;
384 pixels
[y
][x
][0] = color
;
385 pixels
[y
][x
][1] = color
;
386 pixels
[y
][x
][2] = color
;
387 pixels
[y
][x
][3] = 128u;
391 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
392 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
395 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM
, GL_TRUE
);
396 glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM
, GL_TRUE
);
397 if (copy_type
== TexImage
) {
398 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
401 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
402 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
404 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
407 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
409 uint8 copied_pixels
[2][2][4] = {{{0}}};
410 glReadPixels(0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, copied_pixels
);
411 for (int x
= 0; x
< 2; ++x
) {
412 for (int y
= 0; y
< 2; ++y
) {
413 EXPECT_EQ(pixels
[1-y
][x
][0] / 2, copied_pixels
[y
][x
][0]);
414 EXPECT_EQ(pixels
[1-y
][x
][1] / 2, copied_pixels
[y
][x
][1]);
415 EXPECT_EQ(pixels
[1-y
][x
][2] / 2, copied_pixels
[y
][x
][2]);
416 EXPECT_EQ(pixels
[1-y
][x
][3], copied_pixels
[y
][x
][3]);
420 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
423 TEST_P(GLCopyTextureCHROMIUMTest
, FlipYAndUnpremultiplyAlpha
) {
424 CopyType copy_type
= GetParam();
425 uint8 pixels
[2][2][4];
426 for (int x
= 0; x
< 2; ++x
) {
427 for (int y
= 0; y
< 2; ++y
) {
428 uint8 color
= 16 * x
+ 16 * y
;
429 pixels
[y
][x
][0] = color
;
430 pixels
[y
][x
][1] = color
;
431 pixels
[y
][x
][2] = color
;
432 pixels
[y
][x
][3] = 128u;
436 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
437 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
440 glPixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM
, GL_TRUE
);
441 glPixelStorei(GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM
, GL_TRUE
);
442 if (copy_type
== TexImage
) {
443 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
446 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
447 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
449 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
452 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
454 uint8 copied_pixels
[2][2][4] = {{{0}}};
455 glReadPixels(0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, copied_pixels
);
456 for (int x
= 0; x
< 2; ++x
) {
457 for (int y
= 0; y
< 2; ++y
) {
458 EXPECT_EQ(pixels
[1-y
][x
][0] * 2, copied_pixels
[y
][x
][0]);
459 EXPECT_EQ(pixels
[1-y
][x
][1] * 2, copied_pixels
[y
][x
][1]);
460 EXPECT_EQ(pixels
[1-y
][x
][2] * 2, copied_pixels
[y
][x
][2]);
461 EXPECT_EQ(pixels
[1-y
][x
][3], copied_pixels
[y
][x
][3]);
465 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
470 void glEnableDisable(GLint param
, GLboolean value
) {
477 } // unnamed namespace
479 // Validate that some basic GL state is not touched upon execution of
481 TEST_P(GLCopyTextureCHROMIUMTest
, BasicStatePreservation
) {
482 CopyType copy_type
= GetParam();
483 uint8 pixels
[1 * 4] = { 255u, 0u, 0u, 255u };
485 glBindFramebuffer(GL_FRAMEBUFFER
, 0);
487 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
488 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
491 if (copy_type
== TexSubImage
) {
492 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
493 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
497 GLboolean reference_settings
[2] = { GL_TRUE
, GL_FALSE
};
498 for (int x
= 0; x
< 2; ++x
) {
499 GLboolean setting
= reference_settings
[x
];
500 glEnableDisable(GL_DEPTH_TEST
, setting
);
501 glEnableDisable(GL_SCISSOR_TEST
, setting
);
502 glEnableDisable(GL_STENCIL_TEST
, setting
);
503 glEnableDisable(GL_CULL_FACE
, setting
);
504 glEnableDisable(GL_BLEND
, setting
);
505 glColorMask(setting
, setting
, setting
, setting
);
506 glDepthMask(setting
);
508 glActiveTexture(GL_TEXTURE1
+ x
);
510 if (copy_type
== TexImage
) {
511 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
514 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0,
517 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
519 EXPECT_EQ(setting
, glIsEnabled(GL_DEPTH_TEST
));
520 EXPECT_EQ(setting
, glIsEnabled(GL_SCISSOR_TEST
));
521 EXPECT_EQ(setting
, glIsEnabled(GL_STENCIL_TEST
));
522 EXPECT_EQ(setting
, glIsEnabled(GL_CULL_FACE
));
523 EXPECT_EQ(setting
, glIsEnabled(GL_BLEND
));
525 GLboolean bool_array
[4] = { GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
};
526 glGetBooleanv(GL_DEPTH_WRITEMASK
, bool_array
);
527 EXPECT_EQ(setting
, bool_array
[0]);
529 bool_array
[0] = GL_FALSE
;
530 glGetBooleanv(GL_COLOR_WRITEMASK
, bool_array
);
531 EXPECT_EQ(setting
, bool_array
[0]);
532 EXPECT_EQ(setting
, bool_array
[1]);
533 EXPECT_EQ(setting
, bool_array
[2]);
534 EXPECT_EQ(setting
, bool_array
[3]);
536 GLint active_texture
= 0;
537 glGetIntegerv(GL_ACTIVE_TEXTURE
, &active_texture
);
538 EXPECT_EQ(GL_TEXTURE1
+ x
, active_texture
);
541 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
544 // Verify that invocation of the extension does not modify the bound
546 TEST_P(GLCopyTextureCHROMIUMTest
, TextureStatePreserved
) {
547 CopyType copy_type
= GetParam();
548 // Setup the texture used for the extension invocation.
549 uint8 pixels
[1 * 4] = { 255u, 0u, 0u, 255u };
550 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
551 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
554 if (copy_type
== TexSubImage
) {
555 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
556 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
560 GLuint texture_ids
[2];
561 glGenTextures(2, texture_ids
);
563 glActiveTexture(GL_TEXTURE0
);
564 glBindTexture(GL_TEXTURE_2D
, texture_ids
[0]);
566 glActiveTexture(GL_TEXTURE1
);
567 glBindTexture(GL_TEXTURE_2D
, texture_ids
[1]);
569 if (copy_type
== TexImage
) {
570 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
573 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
576 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
578 GLint active_texture
= 0;
579 glGetIntegerv(GL_ACTIVE_TEXTURE
, &active_texture
);
580 EXPECT_EQ(GL_TEXTURE1
, active_texture
);
582 GLint bound_texture
= 0;
583 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &bound_texture
);
584 EXPECT_EQ(texture_ids
[1], static_cast<GLuint
>(bound_texture
));
585 glBindTexture(GL_TEXTURE_2D
, 0);
588 glActiveTexture(GL_TEXTURE0
);
589 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &bound_texture
);
590 EXPECT_EQ(texture_ids
[0], static_cast<GLuint
>(bound_texture
));
591 glBindTexture(GL_TEXTURE_2D
, 0);
593 glDeleteTextures(2, texture_ids
);
595 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
598 // Verify that invocation of the extension does not perturb the currently
600 TEST_P(GLCopyTextureCHROMIUMTest
, FBOStatePreserved
) {
601 CopyType copy_type
= GetParam();
602 // Setup the texture used for the extension invocation.
603 uint8 pixels
[1 * 4] = { 255u, 0u, 0u, 255u };
604 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
605 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
608 if (copy_type
== TexSubImage
) {
609 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
610 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
615 glGenTextures(1, &texture_id
);
616 glBindTexture(GL_TEXTURE_2D
, texture_id
);
617 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
620 GLuint renderbuffer_id
;
621 glGenRenderbuffers(1, &renderbuffer_id
);
622 glBindRenderbuffer(GL_RENDERBUFFER
, renderbuffer_id
);
623 glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH_COMPONENT16
, 1, 1);
625 GLuint framebuffer_id
;
626 glGenFramebuffers(1, &framebuffer_id
);
627 glBindFramebuffer(GL_FRAMEBUFFER
, framebuffer_id
);
628 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
,
630 glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
,
631 GL_RENDERBUFFER
, renderbuffer_id
);
633 GL_FRAMEBUFFER_COMPLETE
== glCheckFramebufferStatus(GL_FRAMEBUFFER
));
635 // Test that we can write to the bound framebuffer
636 uint8 expected_color
[4] = { 255u, 255u, 0, 255u };
637 glClearColor(1.0, 1.0, 0, 1.0);
638 glClear(GL_COLOR_BUFFER_BIT
);
639 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color
);
641 if (copy_type
== TexImage
) {
642 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
645 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
648 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
650 EXPECT_TRUE(glIsFramebuffer(framebuffer_id
));
652 // Ensure that reading from the framebuffer produces correct pixels.
653 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color
);
655 uint8 expected_color2
[4] = { 255u, 0, 255u, 255u };
656 glClearColor(1.0, 0, 1.0, 1.0);
657 glClear(GL_COLOR_BUFFER_BIT
);
658 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected_color2
);
661 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &bound_fbo
);
662 EXPECT_EQ(framebuffer_id
, static_cast<GLuint
>(bound_fbo
));
664 GLint fbo_params
= 0;
665 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
666 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
,
668 EXPECT_EQ(GL_TEXTURE
, fbo_params
);
671 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
672 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
,
674 EXPECT_EQ(texture_id
, static_cast<GLuint
>(fbo_params
));
677 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
,
678 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
,
680 EXPECT_EQ(GL_RENDERBUFFER
, fbo_params
);
683 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
,
684 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
,
686 EXPECT_EQ(renderbuffer_id
, static_cast<GLuint
>(fbo_params
));
688 glDeleteRenderbuffers(1, &renderbuffer_id
);
689 glDeleteTextures(1, &texture_id
);
690 glDeleteFramebuffers(1, &framebuffer_id
);
692 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
695 TEST_P(GLCopyTextureCHROMIUMTest
, ProgramStatePreservation
) {
696 CopyType copy_type
= GetParam();
697 // unbind the one created in setup.
698 glBindFramebuffer(GL_FRAMEBUFFER
, 0);
699 glBindTexture(GL_TEXTURE_2D
, 0);
702 GLManager::Options options
;
703 options
.size
= gfx::Size(16, 16);
704 options
.share_group_manager
= &gl_
;
705 gl2
.Initialize(options
);
708 static const char* v_shader_str
=
709 "attribute vec4 g_Position;\n"
712 " gl_Position = g_Position;\n"
714 static const char* f_shader_str
=
715 "precision mediump float;\n"
718 " gl_FragColor = vec4(0,1,0,1);\n"
721 GLuint program
= GLTestHelper::LoadProgram(v_shader_str
, f_shader_str
);
722 glUseProgram(program
);
723 GLuint position_loc
= glGetAttribLocation(program
, "g_Position");
726 // Delete program from other context.
728 glDeleteProgram(program
);
729 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
732 // Program should still be usable on this context.
735 GLTestHelper::SetupUnitQuad(position_loc
);
737 // test using program before
738 uint8 expected
[] = { 0, 255, 0, 255, };
739 uint8 zero
[] = { 0, 0, 0, 0, };
740 glClear(GL_COLOR_BUFFER_BIT
);
741 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero
));
742 glDrawArrays(GL_TRIANGLES
, 0, 6);
743 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected
));
745 // Call copyTextureCHROMIUM
746 uint8 pixels
[1 * 4] = { 255u, 0u, 0u, 255u };
747 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
748 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
750 if (copy_type
== TexImage
) {
751 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
754 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
755 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
757 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
761 // test using program after
762 glClear(GL_COLOR_BUFFER_BIT
);
763 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, zero
));
764 glDrawArrays(GL_TRIANGLES
, 0, 6);
765 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expected
));
767 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
774 // Test that glCopyTextureCHROMIUM doesn't leak uninitialized textures.
775 TEST_P(GLCopyTextureCHROMIUMTest
, UninitializedSource
) {
776 CopyType copy_type
= GetParam();
777 const GLsizei kWidth
= 64, kHeight
= 64;
778 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
779 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, kWidth
, kHeight
, 0, GL_RGBA
,
780 GL_UNSIGNED_BYTE
, nullptr);
782 if (copy_type
== TexImage
) {
783 glCopyTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], GL_RGBA
,
786 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
787 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, kWidth
, kHeight
, 0, GL_RGBA
,
788 GL_UNSIGNED_BYTE
, nullptr);
789 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 0,
792 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
794 uint8 pixels
[kHeight
][kWidth
][4] = {{{1}}};
795 glReadPixels(0, 0, kWidth
, kHeight
, GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
796 for (int x
= 0; x
< kWidth
; ++x
) {
797 for (int y
= 0; y
< kHeight
; ++y
) {
798 EXPECT_EQ(0, pixels
[y
][x
][0]);
799 EXPECT_EQ(0, pixels
[y
][x
][1]);
800 EXPECT_EQ(0, pixels
[y
][x
][2]);
801 EXPECT_EQ(0, pixels
[y
][x
][3]);
805 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
808 TEST_F(GLCopyTextureCHROMIUMTest
, CopySubTextureDimension
) {
809 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
810 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
813 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
814 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 3, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
817 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 1, 1, 0,
819 EXPECT_TRUE(GL_NO_ERROR
== glGetError());
822 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], -1, 1, 0,
824 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
827 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 1, 1, -1,
829 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
831 // xoffset + width > dest_width
832 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 2, 2, 0,
834 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
836 // x + width > source_width
837 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 0, 1,
839 EXPECT_TRUE(glGetError() == GL_INVALID_VALUE
);
842 TEST_F(GLCopyTextureCHROMIUMTest
, CopySubTextureOffset
) {
843 uint8 rgba_pixels
[4 * 4] = {255u,
859 glBindTexture(GL_TEXTURE_2D
, textures_
[0]);
860 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
863 uint8 transparent_pixels
[4 * 4] = {
864 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
865 glBindTexture(GL_TEXTURE_2D
, textures_
[1]);
866 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,
869 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 1, 1, 0,
871 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
872 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 1, 0, 1,
874 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
875 glCopySubTextureCHROMIUM(GL_TEXTURE_2D
, textures_
[0], textures_
[1], 0, 1, 0,
877 EXPECT_TRUE(glGetError() == GL_NO_ERROR
);
879 // Check the FB is still bound.
881 glGetIntegerv(GL_FRAMEBUFFER_BINDING
, &value
);
882 GLuint fb_id
= value
;
883 EXPECT_EQ(framebuffer_id_
, fb_id
);
885 // Check that FB is complete.
886 EXPECT_EQ(static_cast<GLenum
>(GL_FRAMEBUFFER_COMPLETE
),
887 glCheckFramebufferStatus(GL_FRAMEBUFFER
));
889 uint8 transparent
[1 * 4] = {0u, 0u, 0u, 0u};
890 uint8 red
[1 * 4] = {255u, 0u, 0u, 255u};
891 uint8 green
[1 * 4] = {0u, 255u, 0u, 255u};
892 uint8 blue
[1 * 4] = {0u, 0u, 255u, 255u};
893 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent
);
894 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red
);
895 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green
);
896 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue
);
897 EXPECT_TRUE(GL_NO_ERROR
== glGetError());