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