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