Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // CopyTextureTest.cpp: Tests of the GL_CHROMIUM_copy_texture extension |
| 8 | |
| 9 | #include "test_utils/ANGLETest.h" |
| 10 | |
| 11 | namespace angle |
| 12 | { |
| 13 | |
| 14 | class CopyTextureTest : public ANGLETest |
| 15 | { |
| 16 | protected: |
| 17 | CopyTextureTest() |
| 18 | { |
| 19 | setWindowWidth(256); |
| 20 | setWindowHeight(256); |
| 21 | setConfigRedBits(8); |
| 22 | setConfigGreenBits(8); |
| 23 | setConfigBlueBits(8); |
| 24 | setConfigAlphaBits(8); |
| 25 | } |
| 26 | |
| 27 | void SetUp() override |
| 28 | { |
| 29 | ANGLETest::SetUp(); |
| 30 | |
| 31 | glGenTextures(2, mTextures); |
| 32 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 33 | |
| 34 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 35 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 36 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 38 | |
| 39 | glGenFramebuffers(1, &mFramebuffer); |
| 40 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 41 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], |
| 42 | 0); |
| 43 | |
| 44 | if (extensionEnabled("GL_CHROMIUM_copy_texture")) |
| 45 | { |
| 46 | glCopyTextureCHROMIUM = reinterpret_cast<PFNGLCOPYTEXTURECHROMIUMPROC>( |
| 47 | eglGetProcAddress("glCopyTextureCHROMIUM")); |
| 48 | glCopySubTextureCHROMIUM = reinterpret_cast<PFNGLCOPYSUBTEXTURECHROMIUMPROC>( |
| 49 | eglGetProcAddress("glCopySubTextureCHROMIUM")); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void TearDown() override |
| 54 | { |
| 55 | glDeleteTextures(2, mTextures); |
| 56 | glDeleteFramebuffers(1, &mFramebuffer); |
| 57 | |
| 58 | ANGLETest::TearDown(); |
| 59 | } |
| 60 | |
| 61 | bool checkExtensions() const |
| 62 | { |
| 63 | if (!extensionEnabled("GL_CHROMIUM_copy_texture")) |
| 64 | { |
| 65 | std::cout << "Test skipped because GL_CHROMIUM_copy_texture is not available." |
| 66 | << std::endl; |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | EXPECT_NE(nullptr, glCopyTextureCHROMIUM); |
| 71 | EXPECT_NE(nullptr, glCopySubTextureCHROMIUM); |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | GLuint mTextures[2] = { |
| 76 | 0, 0, |
| 77 | }; |
| 78 | GLuint mFramebuffer = 0; |
| 79 | |
| 80 | PFNGLCOPYTEXTURECHROMIUMPROC glCopyTextureCHROMIUM = nullptr; |
| 81 | PFNGLCOPYSUBTEXTURECHROMIUMPROC glCopySubTextureCHROMIUM = nullptr; |
| 82 | }; |
| 83 | |
| 84 | // Test to ensure that the basic functionality of the extension works. |
| 85 | TEST_P(CopyTextureTest, BasicCopyTexture) |
| 86 | { |
| 87 | if (!checkExtensions()) |
| 88 | { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | GLColor pixels = GLColor::red; |
| 93 | |
| 94 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 95 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 96 | |
| 97 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, |
| 98 | false); |
| 99 | |
| 100 | EXPECT_GL_NO_ERROR(); |
| 101 | |
| 102 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 103 | } |
| 104 | |
| 105 | // Test to ensure that the basic functionality of the extension works. |
| 106 | TEST_P(CopyTextureTest, BasicCopySubTexture) |
| 107 | { |
| 108 | if (!checkExtensions()) |
| 109 | { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | GLColor pixels = GLColor::red; |
| 114 | |
| 115 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 116 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 117 | |
| 118 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 119 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 120 | |
| 121 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); |
| 122 | |
| 123 | EXPECT_GL_NO_ERROR(); |
| 124 | |
| 125 | // Check that FB is complete. |
| 126 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 127 | |
| 128 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 129 | |
| 130 | EXPECT_GL_NO_ERROR(); |
| 131 | } |
| 132 | |
| 133 | // Test that CopyTexture cannot redefine an immutable texture and CopySubTexture can copy data to |
| 134 | // immutable textures |
| 135 | TEST_P(CopyTextureTest, ImmutableTexture) |
| 136 | { |
| 137 | if (!checkExtensions()) |
| 138 | { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | if (getClientMajorVersion() < 3 && |
| 143 | (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8"))) |
| 144 | { |
| 145 | std::cout |
| 146 | << "Test skipped due to missing ES3 or GL_EXT_texture_storage or GL_OES_rgb8_rgba8" |
| 147 | << std::endl; |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | GLColor pixels = GLColor::red; |
| 152 | |
| 153 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 154 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); |
| 155 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 156 | |
| 157 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 158 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); |
| 159 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], 0); |
| 160 | EXPECT_GL_NO_ERROR(); |
| 161 | |
| 162 | // Should generate an error when the texture is redefined |
| 163 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, |
| 164 | false); |
| 165 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 166 | |
| 167 | // Should succeed when using CopySubTexture |
| 168 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); |
| 169 | EXPECT_GL_NO_ERROR(); |
| 170 | |
| 171 | // Check that FB is complete. |
| 172 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 173 | |
| 174 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 175 | |
| 176 | EXPECT_GL_NO_ERROR(); |
| 177 | } |
| 178 | |
| 179 | // Test validation of internal formats in CopyTexture and CopySubTexture |
| 180 | TEST_P(CopyTextureTest, InternalFormat) |
| 181 | { |
| 182 | if (!checkExtensions()) |
| 183 | { |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | std::vector<GLint> sourceFormats; |
| 188 | sourceFormats.push_back(GL_ALPHA); |
| 189 | sourceFormats.push_back(GL_RGB); |
| 190 | sourceFormats.push_back(GL_RGBA); |
| 191 | sourceFormats.push_back(GL_LUMINANCE); |
| 192 | sourceFormats.push_back(GL_LUMINANCE_ALPHA); |
| 193 | |
| 194 | std::vector<GLint> destFormats; |
| 195 | destFormats.push_back(GL_RGB); |
| 196 | destFormats.push_back(GL_RGBA); |
| 197 | |
| 198 | if (extensionEnabled("GL_EXT_texture_format_BGRA8888")) |
| 199 | { |
| 200 | sourceFormats.push_back(GL_BGRA_EXT); |
| 201 | destFormats.push_back(GL_BGRA_EXT); |
| 202 | } |
| 203 | |
| 204 | // Test with glCopyTexture |
| 205 | for (GLint sourceFormat : sourceFormats) |
| 206 | { |
| 207 | for (GLint destFormat : destFormats) |
| 208 | { |
| 209 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 210 | glTexImage2D(GL_TEXTURE_2D, 0, sourceFormat, 1, 1, 0, sourceFormat, GL_UNSIGNED_BYTE, |
| 211 | nullptr); |
| 212 | EXPECT_GL_NO_ERROR(); |
| 213 | |
| 214 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], destFormat, GL_UNSIGNED_BYTE, false, |
| 215 | false, false); |
| 216 | |
| 217 | EXPECT_GL_NO_ERROR(); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Test with glCopySubTexture |
| 222 | for (GLint sourceFormat : sourceFormats) |
| 223 | { |
| 224 | for (GLint destFormat : destFormats) |
| 225 | { |
| 226 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 227 | glTexImage2D(GL_TEXTURE_2D, 0, sourceFormat, 1, 1, 0, sourceFormat, GL_UNSIGNED_BYTE, |
| 228 | nullptr); |
| 229 | EXPECT_GL_NO_ERROR(); |
| 230 | |
| 231 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 232 | glTexImage2D(GL_TEXTURE_2D, 0, destFormat, 1, 1, 0, destFormat, GL_UNSIGNED_BYTE, |
| 233 | nullptr); |
| 234 | EXPECT_GL_NO_ERROR(); |
| 235 | |
| 236 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, |
| 237 | false); |
| 238 | |
| 239 | EXPECT_GL_NO_ERROR(); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // Check that invalid internal formats return errors. |
| 245 | TEST_P(CopyTextureTest, InternalFormatNotSupported) |
| 246 | { |
| 247 | if (!checkExtensions()) |
| 248 | { |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 253 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 254 | EXPECT_GL_NO_ERROR(); |
| 255 | |
| 256 | std::vector<GLint> unsupportedDestFormats; |
| 257 | unsupportedDestFormats.push_back(GL_ALPHA); |
| 258 | unsupportedDestFormats.push_back(GL_LUMINANCE); |
| 259 | unsupportedDestFormats.push_back(GL_LUMINANCE_ALPHA); |
| 260 | |
| 261 | if (!extensionEnabled("GL_EXT_texture_format_BGRA8888")) |
| 262 | { |
| 263 | unsupportedDestFormats.push_back(GL_BGRA_EXT); |
| 264 | } |
| 265 | |
| 266 | // Check unsupported format reports an error. |
| 267 | for (GLint unsupportedDestFormat : unsupportedDestFormats) |
| 268 | { |
| 269 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], unsupportedDestFormat, GL_UNSIGNED_BYTE, |
| 270 | false, false, false); |
| 271 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 272 | } |
| 273 | |
| 274 | for (GLint unsupportedDestFormat : unsupportedDestFormats) |
| 275 | { |
| 276 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 277 | glTexImage2D(GL_TEXTURE_2D, 0, unsupportedDestFormat, 1, 1, 0, unsupportedDestFormat, |
| 278 | GL_UNSIGNED_BYTE, nullptr); |
| 279 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); |
| 280 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // Test to ensure that the destination texture is redefined if the properties are different. |
| 285 | TEST_P(CopyTextureTest, RedefineDestinationTexture) |
| 286 | { |
| 287 | if (!checkExtensions()) |
| 288 | { |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | GLColor pixels[4] = {GLColor::red, GLColor::red, GLColor::red, GLColor::red}; |
| 293 | |
| 294 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 295 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 296 | |
| 297 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 298 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, 1, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); |
| 299 | EXPECT_GL_NO_ERROR(); |
| 300 | |
| 301 | // GL_INVALID_OPERATION due to "intrinsic format" != "internal format". |
| 302 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 303 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 304 | // GL_INVALID_VALUE due to bad dimensions. |
| 305 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); |
| 306 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 307 | |
| 308 | // If the dest texture has different properties, glCopyTextureCHROMIUM() |
| 309 | // redefines them. |
| 310 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, |
| 311 | false); |
| 312 | EXPECT_GL_NO_ERROR(); |
| 313 | |
| 314 | // glTexSubImage2D() succeeds because mTextures[1] is redefined into 2x2 |
| 315 | // dimension and GL_RGBA format. |
| 316 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 317 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 318 | EXPECT_GL_NO_ERROR(); |
| 319 | |
| 320 | // Check that FB is complete. |
| 321 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 322 | |
| 323 | EXPECT_PIXEL_COLOR_EQ(1, 1, pixels[3]); |
| 324 | EXPECT_GL_NO_ERROR(); |
| 325 | } |
| 326 | |
| 327 | // Test that invalid dimensions in CopySubTexture are validated |
| 328 | TEST_P(CopyTextureTest, CopySubTextureDimension) |
| 329 | { |
| 330 | if (!checkExtensions()) |
| 331 | { |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 336 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 337 | |
| 338 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 339 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 340 | |
| 341 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); |
| 342 | EXPECT_GL_NO_ERROR(); |
| 343 | |
| 344 | // xoffset < 0 |
| 345 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], -1, 1, 0, 0, 1, 1, false, false, false); |
| 346 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 347 | |
| 348 | // x < 0 |
| 349 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, -1, 0, 1, 1, false, false, false); |
| 350 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 351 | |
| 352 | // xoffset + width > dest_width |
| 353 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 2, 2, 0, 0, 2, 2, false, false, false); |
| 354 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 355 | |
| 356 | // x + width > source_width |
| 357 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 1, 1, 2, 2, false, false, false); |
| 358 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 359 | } |
| 360 | |
| 361 | // Test that invalid IDs in CopyTexture are validated |
| 362 | TEST_P(CopyTextureTest, CopyTextureInvalidTextureIds) |
| 363 | { |
| 364 | if (!checkExtensions()) |
| 365 | { |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 370 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 371 | |
| 372 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 373 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 374 | |
| 375 | glCopyTextureCHROMIUM(mTextures[0], 99993, GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); |
| 376 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 377 | |
| 378 | glCopyTextureCHROMIUM(99994, mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); |
| 379 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 380 | |
| 381 | glCopyTextureCHROMIUM(99995, 99996, GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); |
| 382 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 383 | |
| 384 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, |
| 385 | false); |
| 386 | EXPECT_GL_NO_ERROR(); |
| 387 | } |
| 388 | |
| 389 | // Test that invalid IDs in CopySubTexture are validated |
| 390 | TEST_P(CopyTextureTest, CopySubTextureInvalidTextureIds) |
| 391 | { |
| 392 | if (!checkExtensions()) |
| 393 | { |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 398 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 399 | |
| 400 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 401 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 402 | |
| 403 | glCopySubTextureCHROMIUM(mTextures[0], 99993, 1, 1, 0, 0, 1, 1, false, false, false); |
| 404 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 405 | |
| 406 | glCopySubTextureCHROMIUM(99994, mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); |
| 407 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 408 | |
| 409 | glCopySubTextureCHROMIUM(99995, 99996, 1, 1, 0, 0, 1, 1, false, false, false); |
| 410 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 411 | |
| 412 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); |
| 413 | EXPECT_GL_NO_ERROR(); |
| 414 | } |
| 415 | |
| 416 | // Test that using an offset in CopySubTexture works correctly |
| 417 | TEST_P(CopyTextureTest, CopySubTextureOffset) |
| 418 | { |
| 419 | if (!checkExtensions()) |
| 420 | { |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | GLColor rgbaPixels[4 * 4] = {GLColor::red, GLColor::green, GLColor::blue, GLColor::black}; |
| 425 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 426 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 427 | |
| 428 | GLColor transparentPixels[4 * 4] = {GLColor::transparentBlack, GLColor::transparentBlack, |
| 429 | GLColor::transparentBlack, GLColor::transparentBlack}; |
| 430 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 431 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, transparentPixels); |
| 432 | |
| 433 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); |
| 434 | EXPECT_GL_NO_ERROR(); |
| 435 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 0, 1, 0, 1, 1, false, false, false); |
| 436 | EXPECT_GL_NO_ERROR(); |
| 437 | glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 1, 0, 1, 1, 1, false, false, false); |
| 438 | EXPECT_GL_NO_ERROR(); |
| 439 | |
| 440 | // Check that FB is complete. |
| 441 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 442 | |
| 443 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack); |
| 444 | EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red); |
| 445 | EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::green); |
| 446 | EXPECT_PIXEL_COLOR_EQ(0, 1, GLColor::blue); |
| 447 | EXPECT_GL_NO_ERROR(); |
| 448 | } |
| 449 | |
| 450 | // Test that flipping the Y component works correctly |
| 451 | TEST_P(CopyTextureTest, FlipY) |
| 452 | { |
| 453 | if (!checkExtensions()) |
| 454 | { |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), |
| 459 | GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 460 | |
| 461 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 462 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 463 | |
| 464 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, GL_TRUE, GL_FALSE, |
| 465 | GL_FALSE); |
| 466 | EXPECT_GL_NO_ERROR(); |
| 467 | |
| 468 | // Check that FB is complete. |
| 469 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 470 | |
| 471 | EXPECT_PIXEL_COLOR_EQ(0, 0, rgbaPixels[2]); |
| 472 | EXPECT_PIXEL_COLOR_EQ(1, 0, rgbaPixels[3]); |
| 473 | EXPECT_PIXEL_COLOR_EQ(0, 1, rgbaPixels[0]); |
| 474 | EXPECT_PIXEL_COLOR_EQ(1, 1, rgbaPixels[1]); |
| 475 | EXPECT_GL_NO_ERROR(); |
| 476 | } |
| 477 | |
| 478 | // Test that premultipying the alpha on copy works correctly |
| 479 | TEST_P(CopyTextureTest, PremultiplyAlpha) |
| 480 | { |
| 481 | if (!checkExtensions()) |
| 482 | { |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(255u, 255u, 255u, 127u), |
| 487 | GLColor(127u, 127u, 127u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 488 | |
| 489 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 490 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 491 | |
| 492 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE, GL_TRUE, |
| 493 | GL_FALSE); |
| 494 | EXPECT_GL_NO_ERROR(); |
| 495 | |
| 496 | // Check that FB is complete. |
| 497 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 498 | |
| 499 | EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); |
| 500 | EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(127, 127, 127, 127), 1.0); |
| 501 | EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(63, 63, 63, 127), 1.0); |
| 502 | EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(0, 0, 0, 0), 1.0); |
| 503 | EXPECT_GL_NO_ERROR(); |
| 504 | } |
| 505 | |
| 506 | // Test that unmultipying the alpha on copy works correctly |
| 507 | TEST_P(CopyTextureTest, UnmultiplyAlpha) |
| 508 | { |
| 509 | if (!checkExtensions()) |
| 510 | { |
| 511 | return; |
| 512 | } |
| 513 | |
| 514 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), |
| 515 | GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 516 | |
| 517 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 518 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 519 | |
| 520 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE, GL_FALSE, |
| 521 | GL_TRUE); |
| 522 | EXPECT_GL_NO_ERROR(); |
| 523 | |
| 524 | // Check that FB is complete. |
| 525 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 526 | |
| 527 | EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); |
| 528 | EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(255, 255, 255, 127), 1.0); |
| 529 | EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(127, 127, 127, 127), 1.0); |
| 530 | EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(255, 255, 255, 0), 1.0); |
| 531 | EXPECT_GL_NO_ERROR(); |
| 532 | } |
| 533 | |
| 534 | // Test that unmultipying and premultiplying the alpha is the same as doing neither |
| 535 | TEST_P(CopyTextureTest, UnmultiplyAndPremultplyAlpha) |
| 536 | { |
| 537 | if (!checkExtensions()) |
| 538 | { |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), |
| 543 | GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 544 | |
| 545 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 546 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 547 | |
| 548 | glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE, GL_TRUE, |
| 549 | GL_TRUE); |
| 550 | EXPECT_GL_NO_ERROR(); |
| 551 | |
| 552 | // Check that FB is complete. |
| 553 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 554 | |
| 555 | EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); |
| 556 | EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(127, 127, 127, 127), 1.0); |
| 557 | EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(63, 63, 63, 127), 1.0); |
| 558 | EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(255, 255, 255, 0), 1.0); |
| 559 | EXPECT_GL_NO_ERROR(); |
| 560 | } |
| 561 | |
| 562 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 563 | // tests should be run against. |
| 564 | ANGLE_INSTANTIATE_TEST(CopyTextureTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES()); |
| 565 | |
| 566 | } // namespace angle |