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