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 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 11 | #include "test_utils/gl_raii.h" |
| 12 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 13 | namespace angle |
| 14 | { |
| 15 | |
| 16 | class CopyTextureTest : public ANGLETest |
| 17 | { |
| 18 | protected: |
| 19 | CopyTextureTest() |
| 20 | { |
| 21 | setWindowWidth(256); |
| 22 | setWindowHeight(256); |
| 23 | setConfigRedBits(8); |
| 24 | setConfigGreenBits(8); |
| 25 | setConfigBlueBits(8); |
| 26 | setConfigAlphaBits(8); |
| 27 | } |
| 28 | |
| 29 | void SetUp() override |
| 30 | { |
| 31 | ANGLETest::SetUp(); |
| 32 | |
| 33 | glGenTextures(2, mTextures); |
| 34 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 35 | |
| 36 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 37 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 38 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 39 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 40 | |
| 41 | glGenFramebuffers(1, &mFramebuffer); |
| 42 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 43 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], |
| 44 | 0); |
| 45 | |
| 46 | if (extensionEnabled("GL_CHROMIUM_copy_texture")) |
| 47 | { |
| 48 | glCopyTextureCHROMIUM = reinterpret_cast<PFNGLCOPYTEXTURECHROMIUMPROC>( |
| 49 | eglGetProcAddress("glCopyTextureCHROMIUM")); |
| 50 | glCopySubTextureCHROMIUM = reinterpret_cast<PFNGLCOPYSUBTEXTURECHROMIUMPROC>( |
| 51 | eglGetProcAddress("glCopySubTextureCHROMIUM")); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void TearDown() override |
| 56 | { |
| 57 | glDeleteTextures(2, mTextures); |
| 58 | glDeleteFramebuffers(1, &mFramebuffer); |
| 59 | |
| 60 | ANGLETest::TearDown(); |
| 61 | } |
| 62 | |
| 63 | bool checkExtensions() const |
| 64 | { |
| 65 | if (!extensionEnabled("GL_CHROMIUM_copy_texture")) |
| 66 | { |
| 67 | std::cout << "Test skipped because GL_CHROMIUM_copy_texture is not available." |
| 68 | << std::endl; |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | EXPECT_NE(nullptr, glCopyTextureCHROMIUM); |
| 73 | EXPECT_NE(nullptr, glCopySubTextureCHROMIUM); |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | GLuint mTextures[2] = { |
| 78 | 0, 0, |
| 79 | }; |
| 80 | GLuint mFramebuffer = 0; |
| 81 | |
| 82 | PFNGLCOPYTEXTURECHROMIUMPROC glCopyTextureCHROMIUM = nullptr; |
| 83 | PFNGLCOPYSUBTEXTURECHROMIUMPROC glCopySubTextureCHROMIUM = nullptr; |
| 84 | }; |
| 85 | |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 86 | class CopyTextureTestDest : public CopyTextureTest |
| 87 | { |
| 88 | }; |
| 89 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 90 | class CopyTextureTestES3 : public CopyTextureTest |
| 91 | { |
| 92 | }; |
| 93 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 94 | // Test to ensure that the basic functionality of the extension works. |
| 95 | TEST_P(CopyTextureTest, BasicCopyTexture) |
| 96 | { |
| 97 | if (!checkExtensions()) |
| 98 | { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | GLColor pixels = GLColor::red; |
| 103 | |
| 104 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 105 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 106 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 107 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 108 | GL_UNSIGNED_BYTE, false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 109 | |
| 110 | EXPECT_GL_NO_ERROR(); |
| 111 | |
| 112 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 113 | } |
| 114 | |
| 115 | // Test to ensure that the basic functionality of the extension works. |
| 116 | TEST_P(CopyTextureTest, BasicCopySubTexture) |
| 117 | { |
| 118 | if (!checkExtensions()) |
| 119 | { |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | GLColor pixels = GLColor::red; |
| 124 | |
| 125 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 126 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 127 | |
| 128 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 129 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 130 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 131 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 0, 0, 0, 0, 1, 1, |
| 132 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 133 | |
| 134 | EXPECT_GL_NO_ERROR(); |
| 135 | |
| 136 | // Check that FB is complete. |
| 137 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 138 | |
| 139 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 140 | |
| 141 | EXPECT_GL_NO_ERROR(); |
| 142 | } |
| 143 | |
| 144 | // Test that CopyTexture cannot redefine an immutable texture and CopySubTexture can copy data to |
| 145 | // immutable textures |
| 146 | TEST_P(CopyTextureTest, ImmutableTexture) |
| 147 | { |
| 148 | if (!checkExtensions()) |
| 149 | { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | if (getClientMajorVersion() < 3 && |
| 154 | (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8"))) |
| 155 | { |
| 156 | std::cout |
| 157 | << "Test skipped due to missing ES3 or GL_EXT_texture_storage or GL_OES_rgb8_rgba8" |
| 158 | << std::endl; |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | GLColor pixels = GLColor::red; |
| 163 | |
| 164 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 165 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); |
| 166 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 167 | |
| 168 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 169 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); |
| 170 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], 0); |
| 171 | EXPECT_GL_NO_ERROR(); |
| 172 | |
| 173 | // Should generate an error when the texture is redefined |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 174 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 175 | GL_UNSIGNED_BYTE, false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 176 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 177 | |
| 178 | // Should succeed when using CopySubTexture |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 179 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 0, 0, 0, 0, 1, 1, |
| 180 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 181 | EXPECT_GL_NO_ERROR(); |
| 182 | |
| 183 | // Check that FB is complete. |
| 184 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 185 | |
| 186 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 187 | |
| 188 | EXPECT_GL_NO_ERROR(); |
| 189 | } |
| 190 | |
| 191 | // Test validation of internal formats in CopyTexture and CopySubTexture |
| 192 | TEST_P(CopyTextureTest, InternalFormat) |
| 193 | { |
| 194 | if (!checkExtensions()) |
| 195 | { |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | std::vector<GLint> sourceFormats; |
| 200 | sourceFormats.push_back(GL_ALPHA); |
| 201 | sourceFormats.push_back(GL_RGB); |
| 202 | sourceFormats.push_back(GL_RGBA); |
| 203 | sourceFormats.push_back(GL_LUMINANCE); |
| 204 | sourceFormats.push_back(GL_LUMINANCE_ALPHA); |
| 205 | |
| 206 | std::vector<GLint> destFormats; |
| 207 | destFormats.push_back(GL_RGB); |
| 208 | destFormats.push_back(GL_RGBA); |
| 209 | |
| 210 | if (extensionEnabled("GL_EXT_texture_format_BGRA8888")) |
| 211 | { |
| 212 | sourceFormats.push_back(GL_BGRA_EXT); |
| 213 | destFormats.push_back(GL_BGRA_EXT); |
| 214 | } |
| 215 | |
| 216 | // Test with glCopyTexture |
| 217 | for (GLint sourceFormat : sourceFormats) |
| 218 | { |
| 219 | for (GLint destFormat : destFormats) |
| 220 | { |
| 221 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 222 | glTexImage2D(GL_TEXTURE_2D, 0, sourceFormat, 1, 1, 0, sourceFormat, GL_UNSIGNED_BYTE, |
| 223 | nullptr); |
| 224 | EXPECT_GL_NO_ERROR(); |
| 225 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 226 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, destFormat, |
| 227 | GL_UNSIGNED_BYTE, false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 228 | |
| 229 | EXPECT_GL_NO_ERROR(); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Test with glCopySubTexture |
| 234 | for (GLint sourceFormat : sourceFormats) |
| 235 | { |
| 236 | for (GLint destFormat : destFormats) |
| 237 | { |
| 238 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 239 | glTexImage2D(GL_TEXTURE_2D, 0, sourceFormat, 1, 1, 0, sourceFormat, GL_UNSIGNED_BYTE, |
| 240 | nullptr); |
| 241 | EXPECT_GL_NO_ERROR(); |
| 242 | |
| 243 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 244 | glTexImage2D(GL_TEXTURE_2D, 0, destFormat, 1, 1, 0, destFormat, GL_UNSIGNED_BYTE, |
| 245 | nullptr); |
| 246 | EXPECT_GL_NO_ERROR(); |
| 247 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 248 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 0, 0, 0, 0, 1, |
| 249 | 1, false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 250 | |
| 251 | EXPECT_GL_NO_ERROR(); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 256 | // Test to ensure that the destination texture is redefined if the properties are different. |
| 257 | TEST_P(CopyTextureTest, RedefineDestinationTexture) |
| 258 | { |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 259 | ANGLE_SKIP_TEST_IF(!checkExtensions()); |
| 260 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_format_BGRA8888")); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 261 | |
| 262 | GLColor pixels[4] = {GLColor::red, GLColor::red, GLColor::red, GLColor::red}; |
| 263 | |
| 264 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 265 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 266 | |
| 267 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 268 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, 1, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); |
| 269 | EXPECT_GL_NO_ERROR(); |
| 270 | |
| 271 | // GL_INVALID_OPERATION due to "intrinsic format" != "internal format". |
| 272 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 273 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 274 | // GL_INVALID_VALUE due to bad dimensions. |
| 275 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); |
| 276 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 277 | |
| 278 | // If the dest texture has different properties, glCopyTextureCHROMIUM() |
| 279 | // redefines them. |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 280 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 281 | GL_UNSIGNED_BYTE, false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 282 | EXPECT_GL_NO_ERROR(); |
| 283 | |
| 284 | // glTexSubImage2D() succeeds because mTextures[1] is redefined into 2x2 |
| 285 | // dimension and GL_RGBA format. |
| 286 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 287 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 288 | EXPECT_GL_NO_ERROR(); |
| 289 | |
| 290 | // Check that FB is complete. |
| 291 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 292 | |
| 293 | EXPECT_PIXEL_COLOR_EQ(1, 1, pixels[3]); |
| 294 | EXPECT_GL_NO_ERROR(); |
| 295 | } |
| 296 | |
| 297 | // Test that invalid dimensions in CopySubTexture are validated |
| 298 | TEST_P(CopyTextureTest, CopySubTextureDimension) |
| 299 | { |
| 300 | if (!checkExtensions()) |
| 301 | { |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 306 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 307 | |
| 308 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 309 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 310 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 311 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 1, 1, 0, 0, 1, 1, |
| 312 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 313 | EXPECT_GL_NO_ERROR(); |
| 314 | |
| 315 | // xoffset < 0 |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 316 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, -1, 1, 0, 0, 1, 1, |
| 317 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 318 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 319 | |
| 320 | // x < 0 |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 321 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 1, 1, -1, 0, 1, 1, |
| 322 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 323 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 324 | |
| 325 | // xoffset + width > dest_width |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 326 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 2, 2, 0, 0, 2, 2, |
| 327 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 328 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 329 | |
| 330 | // x + width > source_width |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 331 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 0, 0, 1, 1, 2, 2, |
| 332 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 333 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 334 | } |
| 335 | |
| 336 | // Test that invalid IDs in CopyTexture are validated |
| 337 | TEST_P(CopyTextureTest, CopyTextureInvalidTextureIds) |
| 338 | { |
| 339 | if (!checkExtensions()) |
| 340 | { |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 345 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 346 | |
| 347 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 348 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 349 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 350 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, 99993, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 351 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 352 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 353 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 354 | glCopyTextureCHROMIUM(99994, 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 355 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 356 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 357 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 358 | glCopyTextureCHROMIUM(99995, 0, GL_TEXTURE_2D, 99996, 0, GL_RGBA, GL_UNSIGNED_BYTE, false, |
| 359 | false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 360 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 361 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 362 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 363 | GL_UNSIGNED_BYTE, false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 364 | EXPECT_GL_NO_ERROR(); |
| 365 | } |
| 366 | |
| 367 | // Test that invalid IDs in CopySubTexture are validated |
| 368 | TEST_P(CopyTextureTest, CopySubTextureInvalidTextureIds) |
| 369 | { |
| 370 | if (!checkExtensions()) |
| 371 | { |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 376 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 377 | |
| 378 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 379 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 380 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 381 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, 99993, 0, 1, 1, 0, 0, 1, 1, false, |
| 382 | false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 383 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 384 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 385 | glCopySubTextureCHROMIUM(99994, 0, GL_TEXTURE_2D, mTextures[1], 0, 1, 1, 0, 0, 1, 1, false, |
| 386 | false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 387 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 388 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 389 | glCopySubTextureCHROMIUM(99995, 0, GL_TEXTURE_2D, 99996, 0, 1, 1, 0, 0, 1, 1, false, false, |
| 390 | false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 391 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 392 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 393 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 1, 1, 0, 0, 1, 1, |
| 394 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 395 | EXPECT_GL_NO_ERROR(); |
| 396 | } |
| 397 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 398 | TEST_P(CopyTextureTest, InvalidTarget) |
| 399 | { |
| 400 | ANGLE_SKIP_TEST_IF(!checkExtensions()); |
| 401 | |
| 402 | GLTexture textures[2]; |
| 403 | |
| 404 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 405 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 406 | |
| 407 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 408 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 409 | |
| 410 | // Invalid enum for a completely invalid target |
| 411 | glCopySubTextureCHROMIUM(textures[0], 0, GL_INVALID_VALUE, textures[1], 0, 1, 1, 0, 0, 1, 1, |
| 412 | false, false, false); |
| 413 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 414 | |
| 415 | // Invalid value for a valid target enum but is not valid for the destination texture |
| 416 | glCopySubTextureCHROMIUM(textures[0], 0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, textures[1], 0, 1, 1, |
| 417 | 0, 0, 1, 1, false, false, false); |
| 418 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 419 | } |
| 420 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 421 | // Test that using an offset in CopySubTexture works correctly |
| 422 | TEST_P(CopyTextureTest, CopySubTextureOffset) |
| 423 | { |
| 424 | if (!checkExtensions()) |
| 425 | { |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | GLColor rgbaPixels[4 * 4] = {GLColor::red, GLColor::green, GLColor::blue, GLColor::black}; |
| 430 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 431 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 432 | |
| 433 | GLColor transparentPixels[4 * 4] = {GLColor::transparentBlack, GLColor::transparentBlack, |
| 434 | GLColor::transparentBlack, GLColor::transparentBlack}; |
| 435 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 436 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, transparentPixels); |
| 437 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 438 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 1, 1, 0, 0, 1, 1, |
| 439 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 440 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 441 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 1, 0, 1, 0, 1, 1, |
| 442 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 443 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 444 | glCopySubTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, 0, 1, 0, 1, 1, 1, |
| 445 | false, false, false); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 446 | EXPECT_GL_NO_ERROR(); |
| 447 | |
| 448 | // Check that FB is complete. |
| 449 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 450 | |
| 451 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack); |
| 452 | EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red); |
| 453 | EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::green); |
| 454 | EXPECT_PIXEL_COLOR_EQ(0, 1, GLColor::blue); |
| 455 | EXPECT_GL_NO_ERROR(); |
| 456 | } |
| 457 | |
| 458 | // Test that flipping the Y component works correctly |
| 459 | TEST_P(CopyTextureTest, FlipY) |
| 460 | { |
| 461 | if (!checkExtensions()) |
| 462 | { |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), |
| 467 | GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 468 | |
| 469 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 470 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 471 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 472 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 473 | GL_UNSIGNED_BYTE, GL_TRUE, GL_FALSE, GL_FALSE); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 474 | EXPECT_GL_NO_ERROR(); |
| 475 | |
| 476 | // Check that FB is complete. |
| 477 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 478 | |
| 479 | EXPECT_PIXEL_COLOR_EQ(0, 0, rgbaPixels[2]); |
| 480 | EXPECT_PIXEL_COLOR_EQ(1, 0, rgbaPixels[3]); |
| 481 | EXPECT_PIXEL_COLOR_EQ(0, 1, rgbaPixels[0]); |
| 482 | EXPECT_PIXEL_COLOR_EQ(1, 1, rgbaPixels[1]); |
| 483 | EXPECT_GL_NO_ERROR(); |
| 484 | } |
| 485 | |
| 486 | // Test that premultipying the alpha on copy works correctly |
| 487 | TEST_P(CopyTextureTest, PremultiplyAlpha) |
| 488 | { |
| 489 | if (!checkExtensions()) |
| 490 | { |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(255u, 255u, 255u, 127u), |
| 495 | GLColor(127u, 127u, 127u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 496 | |
| 497 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 498 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 499 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 500 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 501 | GL_UNSIGNED_BYTE, GL_FALSE, GL_TRUE, GL_FALSE); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 502 | EXPECT_GL_NO_ERROR(); |
| 503 | |
| 504 | // Check that FB is complete. |
| 505 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 506 | |
| 507 | EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); |
| 508 | EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(127, 127, 127, 127), 1.0); |
| 509 | EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(63, 63, 63, 127), 1.0); |
| 510 | EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(0, 0, 0, 0), 1.0); |
| 511 | EXPECT_GL_NO_ERROR(); |
| 512 | } |
| 513 | |
| 514 | // Test that unmultipying the alpha on copy works correctly |
| 515 | TEST_P(CopyTextureTest, UnmultiplyAlpha) |
| 516 | { |
| 517 | if (!checkExtensions()) |
| 518 | { |
| 519 | return; |
| 520 | } |
| 521 | |
| 522 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), |
| 523 | GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 524 | |
| 525 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 526 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 527 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 528 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 529 | GL_UNSIGNED_BYTE, GL_FALSE, GL_FALSE, GL_TRUE); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 530 | EXPECT_GL_NO_ERROR(); |
| 531 | |
| 532 | // Check that FB is complete. |
| 533 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 534 | |
| 535 | EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); |
| 536 | EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(255, 255, 255, 127), 1.0); |
| 537 | EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(127, 127, 127, 127), 1.0); |
| 538 | EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(255, 255, 255, 0), 1.0); |
| 539 | EXPECT_GL_NO_ERROR(); |
| 540 | } |
| 541 | |
| 542 | // Test that unmultipying and premultiplying the alpha is the same as doing neither |
Corentin Wallez | 133a2ec | 2016-11-17 16:28:03 -0500 | [diff] [blame] | 543 | TEST_P(CopyTextureTest, UnmultiplyAndPremultiplyAlpha) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 544 | { |
| 545 | if (!checkExtensions()) |
| 546 | { |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), |
| 551 | GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; |
| 552 | |
| 553 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 554 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); |
| 555 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 556 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 557 | GL_UNSIGNED_BYTE, GL_FALSE, GL_TRUE, GL_TRUE); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 558 | EXPECT_GL_NO_ERROR(); |
| 559 | |
| 560 | // Check that FB is complete. |
| 561 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 562 | |
| 563 | EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); |
| 564 | EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(127, 127, 127, 127), 1.0); |
| 565 | EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(63, 63, 63, 127), 1.0); |
| 566 | EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(255, 255, 255, 0), 1.0); |
| 567 | EXPECT_GL_NO_ERROR(); |
| 568 | } |
| 569 | |
Corentin Wallez | 133a2ec | 2016-11-17 16:28:03 -0500 | [diff] [blame] | 570 | // Test to ensure that CopyTexture works with LUMINANCE_ALPHA texture |
| 571 | TEST_P(CopyTextureTest, LuminanceAlpha) |
| 572 | { |
| 573 | if (!checkExtensions()) |
| 574 | { |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | uint8_t originalPixels[] = {163u, 67u}; |
| 579 | GLColor expectedPixels(163u, 163u, 163u, 67u); |
| 580 | |
| 581 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 582 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA, |
| 583 | GL_UNSIGNED_BYTE, &originalPixels); |
| 584 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 585 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 586 | GL_UNSIGNED_BYTE, false, false, false); |
Corentin Wallez | 133a2ec | 2016-11-17 16:28:03 -0500 | [diff] [blame] | 587 | |
| 588 | EXPECT_GL_NO_ERROR(); |
| 589 | |
| 590 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 591 | } |
| 592 | |
| 593 | // Test to ensure that CopyTexture works with LUMINANCE texture |
| 594 | TEST_P(CopyTextureTest, Luminance) |
| 595 | { |
| 596 | if (!checkExtensions()) |
| 597 | { |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | uint8_t originalPixels[] = {57u}; |
| 602 | GLColor expectedPixels(57u, 57u, 57u, 255u); |
| 603 | |
| 604 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 605 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, |
| 606 | &originalPixels); |
| 607 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 608 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 609 | GL_UNSIGNED_BYTE, false, false, false); |
Corentin Wallez | 133a2ec | 2016-11-17 16:28:03 -0500 | [diff] [blame] | 610 | |
| 611 | EXPECT_GL_NO_ERROR(); |
| 612 | |
| 613 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 614 | } |
| 615 | |
| 616 | // Test to ensure that CopyTexture works with ALPHA texture |
| 617 | TEST_P(CopyTextureTest, Alpha) |
| 618 | { |
| 619 | if (!checkExtensions()) |
| 620 | { |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | uint8_t originalPixels[] = {77u}; |
| 625 | GLColor expectedPixels(0u, 0u, 0u, 77u); |
| 626 | |
| 627 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 628 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &originalPixels); |
| 629 | |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 630 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 631 | GL_UNSIGNED_BYTE, false, false, false); |
Corentin Wallez | 133a2ec | 2016-11-17 16:28:03 -0500 | [diff] [blame] | 632 | |
| 633 | EXPECT_GL_NO_ERROR(); |
| 634 | |
| 635 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 636 | } |
| 637 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 638 | // Test that copying to cube maps works |
| 639 | TEST_P(CopyTextureTest, CubeMapTarget) |
| 640 | { |
| 641 | if (!checkExtensions()) |
| 642 | { |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | GLColor pixels = GLColor::red; |
| 647 | |
| 648 | GLTexture textures[2]; |
| 649 | |
| 650 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 651 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); |
| 652 | |
| 653 | glBindTexture(GL_TEXTURE_CUBE_MAP, textures[1]); |
| 654 | for (GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; |
| 655 | face++) |
| 656 | { |
| 657 | glTexImage2D(face, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 658 | } |
| 659 | |
| 660 | glCopySubTextureCHROMIUM(textures[0], 0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, textures[1], 0, 0, 0, |
| 661 | 0, 0, 1, 1, false, false, false); |
| 662 | |
| 663 | EXPECT_GL_NO_ERROR(); |
| 664 | |
| 665 | GLFramebuffer fbo; |
| 666 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 667 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 668 | textures[1], 0); |
| 669 | |
| 670 | // Check that FB is complete. |
| 671 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 672 | |
| 673 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); |
| 674 | |
| 675 | EXPECT_GL_NO_ERROR(); |
| 676 | } |
| 677 | |
| 678 | // Test that copying to non-zero mipmaps works |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 679 | TEST_P(CopyTextureTest, CopyToMipmap) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 680 | { |
| 681 | if (!checkExtensions()) |
| 682 | { |
| 683 | return; |
| 684 | } |
| 685 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 686 | if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_fbo_render_mipmap")) |
| 687 | { |
| 688 | std::cout << "Test skipped because ES3 or GL_OES_fbo_render_mipmap is missing." |
| 689 | << std::endl; |
| 690 | return; |
| 691 | } |
| 692 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 693 | if (IsOSX() && IsIntel()) |
| 694 | { |
| 695 | std::cout << "Test skipped on Mac Intel." << std::endl; |
| 696 | return; |
| 697 | } |
| 698 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 699 | GLColor pixels[] = {GLColor::red, GLColor::red, GLColor::red, GLColor::red}; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 700 | |
| 701 | GLTexture textures[2]; |
| 702 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 703 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 704 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 705 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 706 | |
| 707 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 708 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 709 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 710 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 711 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 712 | std::vector<std::pair<GLint, GLint>> soureDestPairs; |
| 713 | soureDestPairs.push_back(std::make_pair(0, 1)); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 714 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 715 | // ES3 allows copying from non-zero mips |
| 716 | if (getClientMajorVersion() >= 3) |
| 717 | { |
| 718 | soureDestPairs.push_back(std::make_pair(1, 2)); |
| 719 | } |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 720 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 721 | for (const auto &sourceDestPair : soureDestPairs) |
| 722 | { |
| 723 | const GLint sourceLevel = sourceDestPair.first; |
| 724 | const GLint destLevel = sourceDestPair.second; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 725 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 726 | glCopyTextureCHROMIUM(textures[0], sourceLevel, GL_TEXTURE_2D, textures[1], destLevel, |
| 727 | GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 728 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 729 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 730 | |
Geoff Lang | 165dcf1 | 2017-06-07 15:05:14 -0400 | [diff] [blame] | 731 | GLFramebuffer fbo; |
| 732 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 733 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], |
| 734 | destLevel); |
| 735 | |
| 736 | // Check that FB is complete. |
| 737 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 738 | |
| 739 | EXPECT_PIXEL_COLOR_EQ(0, 0, pixels[0]); |
| 740 | |
| 741 | EXPECT_GL_NO_ERROR(); |
| 742 | } |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 743 | } |
| 744 | |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 745 | // Test to ensure that CopyTexture works with LUMINANCE texture as a destination |
| 746 | TEST_P(CopyTextureTestDest, Luminance) |
| 747 | { |
| 748 | if (!checkExtensions()) |
| 749 | { |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | GLColor originalPixels(50u, 100u, 150u, 200u); |
| 754 | GLColor expectedPixels(50u, 50u, 50u, 255u); |
| 755 | |
| 756 | // ReadPixels doesn't work with LUMINANCE (non-renderable), so we copy again back to an RGBA |
| 757 | // texture to verify contents. |
| 758 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 759 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 760 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 761 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr); |
| 762 | |
| 763 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_LUMINANCE, |
| 764 | GL_UNSIGNED_BYTE, false, false, false); |
| 765 | |
| 766 | EXPECT_GL_NO_ERROR(); |
| 767 | |
| 768 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 769 | GL_UNSIGNED_BYTE, false, false, false); |
| 770 | |
| 771 | EXPECT_GL_NO_ERROR(); |
| 772 | |
| 773 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 774 | } |
| 775 | |
| 776 | // Test to ensure that CopyTexture works with LUMINANCE texture as a destination with |
| 777 | // UnpackPremultiply parameter |
| 778 | TEST_P(CopyTextureTestDest, LuminanceMultiply) |
| 779 | { |
| 780 | if (!checkExtensions()) |
| 781 | { |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | GLColor originalPixels(50u, 100u, 150u, 200u); |
| 786 | GLColor expectedPixels(39u, 39u, 39u, 255u); |
| 787 | |
| 788 | // ReadPixels doesn't work with LUMINANCE (non-renderable), so we copy again back to an RGBA |
| 789 | // texture to verify contents. |
| 790 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 791 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 792 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 793 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr); |
| 794 | |
| 795 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_LUMINANCE, |
| 796 | GL_UNSIGNED_BYTE, false, true, false); |
| 797 | |
| 798 | EXPECT_GL_NO_ERROR(); |
| 799 | |
| 800 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 801 | GL_UNSIGNED_BYTE, false, false, false); |
| 802 | |
| 803 | EXPECT_GL_NO_ERROR(); |
| 804 | |
| 805 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 806 | } |
| 807 | |
| 808 | // Test to ensure that CopyTexture works with LUMINANCE texture as a destination with |
| 809 | // UnpackUnmultiply parameter |
| 810 | TEST_P(CopyTextureTestDest, LuminanceUnmultiply) |
| 811 | { |
| 812 | if (!checkExtensions()) |
| 813 | { |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | GLColor originalPixels(50u, 100u, 150u, 200u); |
| 818 | GLColor expectedPixels(64u, 64u, 64u, 255u); |
| 819 | |
| 820 | // ReadPixels doesn't work with LUMINANCE (non-renderable), so we copy again back to an RGBA |
| 821 | // texture to verify contents. |
| 822 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 823 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 824 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 825 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr); |
| 826 | |
| 827 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_LUMINANCE, |
| 828 | GL_UNSIGNED_BYTE, false, false, true); |
| 829 | |
| 830 | EXPECT_GL_NO_ERROR(); |
| 831 | |
| 832 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 833 | GL_UNSIGNED_BYTE, false, false, false); |
| 834 | |
| 835 | EXPECT_GL_NO_ERROR(); |
| 836 | |
| 837 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 838 | } |
| 839 | |
| 840 | // Test to ensure that CopyTexture works with LUMINANCE_ALPHA texture as a destination |
| 841 | TEST_P(CopyTextureTestDest, LuminanceAlpha) |
| 842 | { |
| 843 | if (!checkExtensions()) |
| 844 | { |
| 845 | return; |
| 846 | } |
| 847 | |
| 848 | GLColor originalPixels(50u, 100u, 150u, 200u); |
| 849 | GLColor expectedPixels(50u, 50u, 50u, 200u); |
| 850 | |
| 851 | // ReadPixels doesn't work with LUMINANCE_ALPHA (non-renderable), so we copy again back to an |
| 852 | // RGBA texture to verify contents. |
| 853 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 854 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 855 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 856 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA, |
| 857 | GL_UNSIGNED_BYTE, nullptr); |
| 858 | |
| 859 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_LUMINANCE_ALPHA, |
| 860 | GL_UNSIGNED_BYTE, false, false, false); |
| 861 | |
| 862 | EXPECT_GL_NO_ERROR(); |
| 863 | |
| 864 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 865 | GL_UNSIGNED_BYTE, false, false, false); |
| 866 | |
| 867 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 868 | } |
| 869 | |
| 870 | // Test to ensure that CopyTexture works with LUMINANCE_ALPHA texture as a destination with |
| 871 | // UnpackPremultiply parameter |
| 872 | TEST_P(CopyTextureTestDest, LuminanceAlphaMultiply) |
| 873 | { |
| 874 | if (!checkExtensions()) |
| 875 | { |
| 876 | return; |
| 877 | } |
| 878 | |
| 879 | GLColor originalPixels(50u, 100u, 150u, 200u); |
| 880 | GLColor expectedPixels(39u, 39u, 39u, 200u); |
| 881 | |
| 882 | // ReadPixels doesn't work with LUMINANCE_ALPHA (non-renderable), so we copy again back to an |
| 883 | // RGBA texture to verify contents. |
| 884 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 885 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 886 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 887 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA, |
| 888 | GL_UNSIGNED_BYTE, nullptr); |
| 889 | |
| 890 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_LUMINANCE_ALPHA, |
| 891 | GL_UNSIGNED_BYTE, false, true, false); |
| 892 | |
| 893 | EXPECT_GL_NO_ERROR(); |
| 894 | |
| 895 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 896 | GL_UNSIGNED_BYTE, false, false, false); |
| 897 | |
| 898 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 899 | } |
| 900 | |
| 901 | // Test to ensure that CopyTexture works with LUMINANCE_ALPHA texture as a destination with |
| 902 | // UnpackUnmultiplyAlpha parameter |
| 903 | TEST_P(CopyTextureTestDest, LuminanceAlphaUnmultiply) |
| 904 | { |
| 905 | if (!checkExtensions()) |
| 906 | { |
| 907 | return; |
| 908 | } |
| 909 | |
| 910 | GLColor originalPixels(50u, 100u, 150u, 200u); |
| 911 | GLColor expectedPixels(64u, 64u, 64u, 200u); |
| 912 | |
| 913 | // ReadPixels doesn't work with LUMINANCE_ALPHA (non-renderable), so we copy again back to an |
| 914 | // RGBA texture to verify contents. |
| 915 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 916 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 917 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 918 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA, |
| 919 | GL_UNSIGNED_BYTE, nullptr); |
| 920 | |
| 921 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_LUMINANCE_ALPHA, |
| 922 | GL_UNSIGNED_BYTE, false, false, true); |
| 923 | |
| 924 | EXPECT_GL_NO_ERROR(); |
| 925 | |
| 926 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 927 | GL_UNSIGNED_BYTE, false, false, false); |
| 928 | |
| 929 | EXPECT_GL_NO_ERROR(); |
| 930 | |
| 931 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 932 | } |
| 933 | |
| 934 | // Test to ensure that CopyTexture works with ALPHA texture as a destination |
| 935 | TEST_P(CopyTextureTestDest, Alpha) |
| 936 | { |
| 937 | if (!checkExtensions()) |
| 938 | { |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | GLColor originalPixels(50u, 100u, 150u, 155u); |
| 943 | GLColor expectedPixels(0u, 0u, 0u, 155u); |
| 944 | |
| 945 | // ReadPixels doesn't work with ALPHA (non-renderable), so we copy again back to an RGBA |
| 946 | // texture to verify contents. |
| 947 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 948 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 949 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 950 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, nullptr); |
| 951 | |
| 952 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_ALPHA, |
| 953 | GL_UNSIGNED_BYTE, false, false, false); |
| 954 | |
| 955 | EXPECT_GL_NO_ERROR(); |
| 956 | |
| 957 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 958 | GL_UNSIGNED_BYTE, false, false, false); |
| 959 | |
| 960 | EXPECT_GL_NO_ERROR(); |
| 961 | |
| 962 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 963 | } |
| 964 | |
| 965 | // Test to ensure that CopyTexture works with ALPHA texture as a destination with |
| 966 | // UnpackPremultiplyAlpha parameter |
| 967 | TEST_P(CopyTextureTestDest, AlphaMultiply) |
| 968 | { |
| 969 | if (!checkExtensions()) |
| 970 | { |
| 971 | return; |
| 972 | } |
| 973 | |
| 974 | GLColor originalPixels(50u, 100u, 150u, 155u); |
| 975 | GLColor expectedPixels(0u, 0u, 0u, 155u); |
| 976 | |
| 977 | // ReadPixels doesn't work with ALPHA (non-renderable), so we copy again back to an RGBA |
| 978 | // texture to verify contents. |
| 979 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 980 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 981 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 982 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, nullptr); |
| 983 | |
| 984 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_ALPHA, |
| 985 | GL_UNSIGNED_BYTE, false, true, false); |
| 986 | |
| 987 | EXPECT_GL_NO_ERROR(); |
| 988 | |
| 989 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 990 | GL_UNSIGNED_BYTE, false, false, false); |
| 991 | |
| 992 | EXPECT_GL_NO_ERROR(); |
| 993 | |
| 994 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 995 | } |
| 996 | |
| 997 | // Test to ensure that CopyTexture works with ALPHA texture as a destination with |
| 998 | // UnpackUnmultiplyAlpha parameter |
| 999 | TEST_P(CopyTextureTestDest, AlphaUnmultiply) |
| 1000 | { |
| 1001 | if (!checkExtensions()) |
| 1002 | { |
| 1003 | return; |
| 1004 | } |
| 1005 | |
| 1006 | GLColor originalPixels(50u, 100u, 150u, 155u); |
| 1007 | GLColor expectedPixels(0u, 0u, 0u, 155u); |
| 1008 | |
| 1009 | // ReadPixels doesn't work with ALPHA (non-renderable), so we copy again back to an RGBA |
| 1010 | // texture to verify contents. |
| 1011 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 1012 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 1013 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 1014 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_UNSIGNED_BYTE, nullptr); |
| 1015 | |
| 1016 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_ALPHA, |
| 1017 | GL_UNSIGNED_BYTE, false, false, true); |
| 1018 | |
| 1019 | EXPECT_GL_NO_ERROR(); |
| 1020 | |
| 1021 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 1022 | GL_UNSIGNED_BYTE, false, false, false); |
| 1023 | |
| 1024 | EXPECT_GL_NO_ERROR(); |
| 1025 | |
| 1026 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 1027 | } |
| 1028 | |
Brandon Jones | 92a1459 | 2017-11-16 10:01:08 -0800 | [diff] [blame] | 1029 | // Test to ensure that CopyTexture uses the correct ALPHA passthrough shader to ensure RGB channels |
| 1030 | // are set to 0. |
| 1031 | TEST_P(CopyTextureTestDest, AlphaCopyWithRGB) |
| 1032 | { |
| 1033 | ANGLE_SKIP_TEST_IF(!checkExtensions()); |
| 1034 | |
| 1035 | GLColor originalPixels(50u, 100u, 150u, 155u); |
| 1036 | GLColor expectedPixels(0u, 0u, 0u, 155u); |
| 1037 | |
| 1038 | // ReadPixels doesn't work with ALPHA (non-renderable), so we copy again back to an RGBA |
| 1039 | // texture to verify contents. |
| 1040 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 1041 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &originalPixels); |
| 1042 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 1043 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 1, 1, 0, GL_ALPHA, GL_HALF_FLOAT_OES, nullptr); |
| 1044 | |
| 1045 | glCopyTextureCHROMIUM(mTextures[1], 0, GL_TEXTURE_2D, mTextures[0], 0, GL_ALPHA, |
| 1046 | GL_HALF_FLOAT_OES, false, false, false); |
| 1047 | |
| 1048 | EXPECT_GL_NO_ERROR(); |
| 1049 | |
| 1050 | glCopyTextureCHROMIUM(mTextures[0], 0, GL_TEXTURE_2D, mTextures[1], 0, GL_RGBA, |
| 1051 | GL_UNSIGNED_BYTE, false, false, false); |
| 1052 | |
| 1053 | EXPECT_GL_NO_ERROR(); |
| 1054 | |
| 1055 | EXPECT_PIXEL_COLOR_EQ(0, 0, expectedPixels); |
| 1056 | } |
| 1057 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1058 | // Test the newly added ES3 unorm formats |
| 1059 | TEST_P(CopyTextureTestES3, ES3UnormFormats) |
| 1060 | { |
| 1061 | if (!checkExtensions()) |
| 1062 | { |
| 1063 | return; |
| 1064 | } |
| 1065 | |
| 1066 | auto testOutput = [this](GLuint texture, const GLColor &expectedColor) { |
| 1067 | const std::string vs = |
| 1068 | "#version 300 es\n" |
| 1069 | "in vec4 position;\n" |
| 1070 | "out vec2 texcoord;\n" |
| 1071 | "void main()\n" |
| 1072 | "{\n" |
| 1073 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 1074 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 1075 | "}\n"; |
| 1076 | |
| 1077 | const std::string fs = |
| 1078 | "#version 300 es\n" |
| 1079 | "precision mediump float;\n" |
| 1080 | "uniform sampler2D tex;\n" |
| 1081 | "in vec2 texcoord;\n" |
| 1082 | "out vec4 color;\n" |
| 1083 | "void main()\n" |
| 1084 | "{\n" |
| 1085 | " color = texture(tex, texcoord);\n" |
| 1086 | "}\n"; |
| 1087 | |
| 1088 | ANGLE_GL_PROGRAM(program, vs, fs); |
| 1089 | glUseProgram(program); |
| 1090 | |
| 1091 | GLRenderbuffer rbo; |
| 1092 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 1093 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 1094 | |
| 1095 | GLFramebuffer fbo; |
| 1096 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1097 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 1098 | |
| 1099 | glActiveTexture(GL_TEXTURE0); |
| 1100 | glBindTexture(GL_TEXTURE_2D, texture); |
| 1101 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1102 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1103 | glUniform1i(glGetUniformLocation(program.get(), "tex"), 0); |
| 1104 | |
| 1105 | drawQuad(program, "position", 0.5f, 1.0f, true); |
| 1106 | |
| 1107 | EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedColor, 1.0); |
| 1108 | }; |
| 1109 | |
| 1110 | auto testCopyCombination = [this, testOutput](GLenum sourceInternalFormat, GLenum sourceFormat, |
| 1111 | GLenum sourceType, const GLColor &sourceColor, |
| 1112 | GLenum destInternalFormat, GLenum destType, |
| 1113 | bool flipY, bool premultiplyAlpha, |
| 1114 | bool unmultiplyAlpha, |
| 1115 | const GLColor &expectedColor) { |
| 1116 | |
| 1117 | GLTexture sourceTexture; |
| 1118 | glBindTexture(GL_TEXTURE_2D, sourceTexture); |
| 1119 | glTexImage2D(GL_TEXTURE_2D, 0, sourceInternalFormat, 1, 1, 0, sourceFormat, sourceType, |
| 1120 | &sourceColor); |
| 1121 | |
| 1122 | GLTexture destTexture; |
| 1123 | glBindTexture(GL_TEXTURE_2D, destTexture); |
| 1124 | |
| 1125 | glCopyTextureCHROMIUM(sourceTexture, 0, GL_TEXTURE_2D, destTexture, 0, destInternalFormat, |
| 1126 | destType, flipY, premultiplyAlpha, unmultiplyAlpha); |
| 1127 | ASSERT_GL_NO_ERROR(); |
| 1128 | |
| 1129 | testOutput(destTexture, expectedColor); |
| 1130 | }; |
| 1131 | |
| 1132 | // New LUMA source formats |
| 1133 | testCopyCombination(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, GLColor(128, 0, 0, 0), GL_RGB, |
| 1134 | GL_UNSIGNED_BYTE, false, false, false, GLColor(128, 128, 128, 255)); |
| 1135 | testCopyCombination(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, |
| 1136 | GLColor(128, 64, 0, 0), GL_RGB, GL_UNSIGNED_BYTE, false, false, false, |
| 1137 | GLColor(128, 128, 128, 255)); |
| 1138 | testCopyCombination(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, |
| 1139 | GLColor(128, 64, 0, 0), GL_RGB, GL_UNSIGNED_BYTE, false, true, false, |
| 1140 | GLColor(32, 32, 32, 255)); |
| 1141 | testCopyCombination(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, |
| 1142 | GLColor(128, 128, 0, 0), GL_RGB, GL_UNSIGNED_BYTE, false, false, true, |
| 1143 | GLColor(255, 255, 255, 255)); |
| 1144 | testCopyCombination(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, GLColor(128, 0, 0, 0), GL_RGBA, |
| 1145 | GL_UNSIGNED_BYTE, false, false, false, GLColor(0, 0, 0, 128)); |
| 1146 | testCopyCombination(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, GLColor(128, 0, 0, 0), GL_RGBA, |
| 1147 | GL_UNSIGNED_BYTE, false, false, true, GLColor(0, 0, 0, 128)); |
| 1148 | testCopyCombination(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, GLColor(128, 0, 0, 0), GL_RGBA, |
| 1149 | GL_UNSIGNED_BYTE, false, true, false, GLColor(0, 0, 0, 128)); |
| 1150 | |
| 1151 | // New sRGB dest formats |
Geoff Lang | aadc8f3 | 2017-08-11 17:34:44 -0400 | [diff] [blame] | 1152 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_SRGB, |
| 1153 | GL_UNSIGNED_BYTE, false, false, false, GLColor(55, 13, 4, 255)); |
| 1154 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_SRGB, |
| 1155 | GL_UNSIGNED_BYTE, false, true, false, GLColor(13, 4, 1, 255)); |
| 1156 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), |
| 1157 | GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, false, false, false, |
| 1158 | GLColor(55, 13, 4, 128)); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | // Test the newly added ES3 float formats |
| 1162 | TEST_P(CopyTextureTestES3, ES3FloatFormats) |
| 1163 | { |
Jamie Madill | e59000c | 2017-08-16 11:13:49 -0400 | [diff] [blame] | 1164 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL()); |
| 1165 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1166 | if (!checkExtensions()) |
| 1167 | { |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | if (!extensionEnabled("GL_EXT_color_buffer_float")) |
| 1172 | { |
| 1173 | std::cout << "Test skipped due to missing GL_EXT_color_buffer_float." << std::endl; |
| 1174 | return; |
| 1175 | } |
| 1176 | |
| 1177 | auto testOutput = [this](GLuint texture, const GLColor32F &expectedColor) { |
| 1178 | const std::string vs = |
| 1179 | "#version 300 es\n" |
| 1180 | "in vec4 position;\n" |
| 1181 | "out vec2 texcoord;\n" |
| 1182 | "void main()\n" |
| 1183 | "{\n" |
| 1184 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 1185 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 1186 | "}\n"; |
| 1187 | |
| 1188 | const std::string fs = |
| 1189 | "#version 300 es\n" |
| 1190 | "precision mediump float;\n" |
| 1191 | "uniform sampler2D tex;\n" |
| 1192 | "in vec2 texcoord;\n" |
| 1193 | "out vec4 color;\n" |
| 1194 | "void main()\n" |
| 1195 | "{\n" |
| 1196 | " color = texture(tex, texcoord);\n" |
| 1197 | "}\n"; |
| 1198 | |
| 1199 | ANGLE_GL_PROGRAM(program, vs, fs); |
| 1200 | glUseProgram(program); |
| 1201 | |
| 1202 | GLRenderbuffer rbo; |
| 1203 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 1204 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32F, 1, 1); |
| 1205 | |
| 1206 | GLFramebuffer fbo; |
| 1207 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1208 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 1209 | |
| 1210 | glActiveTexture(GL_TEXTURE0); |
| 1211 | glBindTexture(GL_TEXTURE_2D, texture); |
| 1212 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1213 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1214 | glUniform1i(glGetUniformLocation(program.get(), "tex"), 0); |
| 1215 | |
| 1216 | drawQuad(program, "position", 0.5f, 1.0f, true); |
| 1217 | |
| 1218 | EXPECT_PIXEL_COLOR32F_NEAR(0, 0, expectedColor, 0.05); |
| 1219 | }; |
| 1220 | |
| 1221 | auto testCopyCombination = [this, testOutput](GLenum sourceInternalFormat, GLenum sourceFormat, |
| 1222 | GLenum sourceType, const GLColor &sourceColor, |
| 1223 | GLenum destInternalFormat, GLenum destType, |
| 1224 | bool flipY, bool premultiplyAlpha, |
| 1225 | bool unmultiplyAlpha, |
| 1226 | const GLColor32F &expectedColor) { |
| 1227 | |
| 1228 | GLTexture sourceTexture; |
| 1229 | glBindTexture(GL_TEXTURE_2D, sourceTexture); |
| 1230 | glTexImage2D(GL_TEXTURE_2D, 0, sourceInternalFormat, 1, 1, 0, sourceFormat, sourceType, |
| 1231 | &sourceColor); |
| 1232 | |
| 1233 | GLTexture destTexture; |
| 1234 | glBindTexture(GL_TEXTURE_2D, destTexture); |
| 1235 | |
| 1236 | glCopyTextureCHROMIUM(sourceTexture, 0, GL_TEXTURE_2D, destTexture, 0, destInternalFormat, |
| 1237 | destType, flipY, premultiplyAlpha, unmultiplyAlpha); |
| 1238 | ASSERT_GL_NO_ERROR(); |
| 1239 | |
| 1240 | testOutput(destTexture, expectedColor); |
| 1241 | }; |
| 1242 | |
| 1243 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGBA32F, |
| 1244 | GL_FLOAT, false, false, false, GLColor32F(0.5f, 0.25f, 0.125f, 0.5f)); |
| 1245 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGBA32F, |
| 1246 | GL_FLOAT, false, true, false, GLColor32F(0.25f, 0.125f, 0.0625f, 0.5f)); |
| 1247 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGBA32F, |
| 1248 | GL_FLOAT, false, false, true, GLColor32F(1.0f, 0.5f, 0.25f, 0.5f)); |
| 1249 | |
| 1250 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_R16F, |
| 1251 | GL_FLOAT, false, false, false, GLColor32F(0.5f, 0.0f, 0.0f, 1.0f)); |
| 1252 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_R16F, |
| 1253 | GL_FLOAT, false, true, false, GLColor32F(0.25f, 0.0f, 0.0f, 1.0f)); |
| 1254 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_R16F, |
| 1255 | GL_FLOAT, false, false, true, GLColor32F(1.0f, 0.0f, 0.0f, 1.0f)); |
| 1256 | |
| 1257 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RG16F, |
| 1258 | GL_FLOAT, false, false, false, GLColor32F(0.5f, 0.25f, 0.0f, 1.0f)); |
| 1259 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RG16F, |
| 1260 | GL_FLOAT, false, true, false, GLColor32F(0.25f, 0.125f, 0.0f, 1.0f)); |
| 1261 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RG16F, |
| 1262 | GL_FLOAT, false, false, true, GLColor32F(1.0f, 0.5f, 0.0f, 1.0f)); |
| 1263 | |
| 1264 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB16F, |
| 1265 | GL_FLOAT, false, false, false, GLColor32F(0.5f, 0.25f, 0.125f, 1.0f)); |
| 1266 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB16F, |
| 1267 | GL_FLOAT, false, true, false, GLColor32F(0.25f, 0.125f, 0.0625f, 1.0f)); |
| 1268 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB16F, |
| 1269 | GL_FLOAT, false, false, true, GLColor32F(1.0f, 0.5f, 0.25f, 1.0f)); |
| 1270 | |
| 1271 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), |
| 1272 | GL_R11F_G11F_B10F, GL_FLOAT, false, false, false, |
| 1273 | GLColor32F(0.5f, 0.25f, 0.125f, 1.0f)); |
| 1274 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), |
| 1275 | GL_R11F_G11F_B10F, GL_FLOAT, false, true, false, |
| 1276 | GLColor32F(0.25f, 0.125f, 0.0625f, 1.0f)); |
| 1277 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), |
| 1278 | GL_R11F_G11F_B10F, GL_FLOAT, false, false, true, |
| 1279 | GLColor32F(1.0f, 0.5f, 0.25f, 1.0f)); |
| 1280 | |
Geoff Lang | aadc8f3 | 2017-08-11 17:34:44 -0400 | [diff] [blame] | 1281 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB9_E5, |
| 1282 | GL_FLOAT, false, false, false, GLColor32F(0.5f, 0.25f, 0.125f, 1.0f)); |
| 1283 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB9_E5, |
| 1284 | GL_FLOAT, false, true, false, GLColor32F(0.25f, 0.125f, 0.0625f, 1.0f)); |
| 1285 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB9_E5, |
| 1286 | GL_FLOAT, false, false, true, GLColor32F(1.0f, 0.5f, 0.25f, 1.0f)); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | // Test the newly added ES3 unsigned integer formats |
| 1290 | TEST_P(CopyTextureTestES3, ES3UintFormats) |
| 1291 | { |
Jamie Madill | 3dfaf26 | 2017-08-18 12:32:14 -0400 | [diff] [blame] | 1292 | ANGLE_SKIP_TEST_IF(IsLinux() && IsOpenGL() && IsIntel()); |
| 1293 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1294 | if (!checkExtensions()) |
| 1295 | { |
| 1296 | return; |
| 1297 | } |
| 1298 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1299 | using GLColor32U = std::tuple<GLuint, GLuint, GLuint, GLuint>; |
| 1300 | |
| 1301 | auto testOutput = [this](GLuint texture, const GLColor32U &expectedColor) { |
| 1302 | const std::string vs = |
| 1303 | "#version 300 es\n" |
| 1304 | "in vec4 position;\n" |
| 1305 | "out vec2 texcoord;\n" |
| 1306 | "void main()\n" |
| 1307 | "{\n" |
| 1308 | " gl_Position = vec4(position.xy, 0.0, 1.0);\n" |
| 1309 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 1310 | "}\n"; |
| 1311 | |
| 1312 | std::string fs = |
| 1313 | "#version 300 es\n" |
| 1314 | "precision mediump float;\n" |
| 1315 | "precision mediump usampler2D;\n" |
| 1316 | "in vec2 texcoord;\n" |
| 1317 | "uniform usampler2D tex;\n" |
| 1318 | "out uvec4 color;\n" |
| 1319 | "void main()\n" |
| 1320 | "{\n" |
| 1321 | " color = texture(tex, texcoord);\n" |
| 1322 | "}\n"; |
| 1323 | |
| 1324 | ANGLE_GL_PROGRAM(program, vs, fs); |
| 1325 | glUseProgram(program); |
| 1326 | |
| 1327 | GLRenderbuffer rbo; |
| 1328 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 1329 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1); |
| 1330 | |
| 1331 | GLFramebuffer fbo; |
| 1332 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1333 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 1334 | |
| 1335 | glActiveTexture(GL_TEXTURE0); |
| 1336 | glBindTexture(GL_TEXTURE_2D, texture); |
| 1337 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1338 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1339 | glUniform1i(glGetUniformLocation(program.get(), "tex"), 0); |
| 1340 | |
| 1341 | drawQuad(program, "position", 0.5f, 1.0f, true); |
| 1342 | ASSERT_GL_NO_ERROR(); |
| 1343 | |
| 1344 | GLuint pixel[4] = {0}; |
| 1345 | glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_UNSIGNED_INT, pixel); |
| 1346 | ASSERT_GL_NO_ERROR(); |
| 1347 | EXPECT_NEAR(std::get<0>(expectedColor), pixel[0], 1); |
| 1348 | EXPECT_NEAR(std::get<1>(expectedColor), pixel[1], 1); |
| 1349 | EXPECT_NEAR(std::get<2>(expectedColor), pixel[2], 1); |
| 1350 | EXPECT_NEAR(std::get<3>(expectedColor), pixel[3], 1); |
| 1351 | }; |
| 1352 | |
| 1353 | auto testCopyCombination = [this, testOutput](GLenum sourceInternalFormat, GLenum sourceFormat, |
| 1354 | GLenum sourceType, const GLColor &sourceColor, |
| 1355 | GLenum destInternalFormat, GLenum destType, |
| 1356 | bool flipY, bool premultiplyAlpha, |
| 1357 | bool unmultiplyAlpha, |
| 1358 | const GLColor32U &expectedColor) { |
| 1359 | |
| 1360 | GLTexture sourceTexture; |
| 1361 | glBindTexture(GL_TEXTURE_2D, sourceTexture); |
| 1362 | glTexImage2D(GL_TEXTURE_2D, 0, sourceInternalFormat, 1, 1, 0, sourceFormat, sourceType, |
| 1363 | &sourceColor); |
| 1364 | |
| 1365 | GLTexture destTexture; |
| 1366 | glBindTexture(GL_TEXTURE_2D, destTexture); |
| 1367 | |
| 1368 | glCopyTextureCHROMIUM(sourceTexture, 0, GL_TEXTURE_2D, destTexture, 0, destInternalFormat, |
| 1369 | destType, flipY, premultiplyAlpha, unmultiplyAlpha); |
| 1370 | ASSERT_GL_NO_ERROR(); |
| 1371 | |
| 1372 | testOutput(destTexture, expectedColor); |
| 1373 | }; |
| 1374 | |
| 1375 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGBA8UI, |
| 1376 | GL_UNSIGNED_BYTE, false, false, false, GLColor32U(128, 64, 32, 128)); |
| 1377 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGBA8UI, |
| 1378 | GL_UNSIGNED_BYTE, false, true, false, GLColor32U(64, 32, 16, 128)); |
| 1379 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGBA8UI, |
| 1380 | GL_UNSIGNED_BYTE, false, false, true, GLColor32U(255, 128, 64, 128)); |
| 1381 | |
Geoff Lang | aadc8f3 | 2017-08-11 17:34:44 -0400 | [diff] [blame] | 1382 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB8UI, |
| 1383 | GL_UNSIGNED_BYTE, false, false, false, GLColor32U(128, 64, 32, 1)); |
| 1384 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB8UI, |
| 1385 | GL_UNSIGNED_BYTE, false, true, false, GLColor32U(64, 32, 16, 1)); |
| 1386 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RGB8UI, |
| 1387 | GL_UNSIGNED_BYTE, false, false, true, GLColor32U(255, 128, 64, 1)); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1388 | |
| 1389 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RG8UI, |
| 1390 | GL_UNSIGNED_BYTE, false, false, false, GLColor32U(128, 64, 0, 1)); |
| 1391 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RG8UI, |
| 1392 | GL_UNSIGNED_BYTE, false, true, false, GLColor32U(64, 32, 0, 1)); |
| 1393 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_RG8UI, |
| 1394 | GL_UNSIGNED_BYTE, false, false, true, GLColor32U(255, 128, 0, 1)); |
| 1395 | |
| 1396 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_R8UI, |
| 1397 | GL_UNSIGNED_BYTE, false, false, false, GLColor32U(128, 0, 0, 1)); |
| 1398 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_R8UI, |
| 1399 | GL_UNSIGNED_BYTE, false, true, false, GLColor32U(64, 0, 0, 1)); |
| 1400 | testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(120, 64, 32, 128), GL_R8UI, |
| 1401 | GL_UNSIGNED_BYTE, false, false, true, GLColor32U(240, 0, 0, 1)); |
| 1402 | } |
| 1403 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 1404 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 1405 | // tests should be run against. |
| 1406 | ANGLE_INSTANTIATE_TEST(CopyTextureTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES()); |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 1407 | ANGLE_INSTANTIATE_TEST(CopyTextureTestDest, ES2_D3D11()); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 1408 | ANGLE_INSTANTIATE_TEST(CopyTextureTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 1409 | |
| 1410 | } // namespace angle |