Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
| 6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| 11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
| 12 #include <GLES3/gl3.h> | |
| 12 #include <stddef.h> | 13 #include <stddef.h> |
| 13 #include <stdint.h> | 14 #include <stdint.h> |
| 14 | 15 |
| 15 #include "gpu/command_buffer/tests/gl_manager.h" | 16 #include "gpu/command_buffer/tests/gl_manager.h" |
| 16 #include "gpu/command_buffer/tests/gl_test_utils.h" | 17 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/gl/gl_version_info.h" | |
| 19 | 21 |
| 20 namespace gpu { | 22 namespace gpu { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 25 | |
| 23 enum CopyType { TexImage, TexSubImage }; | 26 enum CopyType { TexImage, TexSubImage }; |
| 24 const CopyType kCopyTypes[] = { | 27 const CopyType kCopyTypes[] = { |
| 25 TexImage, | 28 TexImage, |
| 26 TexSubImage, | 29 TexSubImage, |
| 27 }; | 30 }; |
| 31 | |
| 32 static const char* kSimpleVertexShaderES3 = | |
| 33 "#version 300 es\n" | |
| 34 "in vec2 a_position;\n" | |
| 35 "out vec2 v_texCoord;\n" | |
| 36 "void main() {\n" | |
| 37 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" | |
| 38 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" | |
| 39 "}\n"; | |
| 40 | |
| 41 std::string GetFragmentShaderSource(GLenum format) { | |
| 42 std::string source; | |
| 43 source += std::string( | |
| 44 "#version 300 es\n" | |
| 45 "precision mediump float;\n"); | |
| 46 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) { | |
| 47 source += std::string("#define SamplerType isampler2D\n"); | |
| 48 source += std::string("#define TextureType ivec4\n"); | |
| 49 source += std::string("#define ScaleValue 255.0\n"); | |
| 50 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) { | |
| 51 source += std::string("#define SamplerType usampler2D\n"); | |
| 52 source += std::string("#define TextureType uvec4\n"); | |
| 53 source += std::string("#define ScaleValue 255.0\n"); | |
| 54 } else { | |
| 55 source += std::string("#define SamplerType sampler2D\n"); | |
| 56 source += std::string("#define TextureType vec4\n"); | |
| 57 source += std::string("#define ScaleValue 1.0\n"); | |
| 58 } | |
| 59 | |
| 60 source += std::string( | |
| 61 "uniform mediump SamplerType u_texture;\n" | |
| 62 "in vec2 v_texCoord;\n" | |
| 63 "out vec4 fragData;\n" | |
| 64 "void main() {\n" | |
| 65 " TextureType color = texture(u_texture, v_texCoord);\n" | |
| 66 " fragData = vec4(color) / ScaleValue;\n" | |
| 67 "}\n"); | |
| 68 return source; | |
| 28 } | 69 } |
| 29 | 70 |
| 71 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) { | |
| 72 color[0] = r; | |
| 73 color[1] = g; | |
| 74 color[2] = b; | |
| 75 color[3] = a; | |
| 76 } | |
| 77 | |
| 78 void getExpectedColor(GLenum src_internal_format, | |
| 79 GLenum dest_internal_format, | |
| 80 uint8_t* color, | |
| 81 uint8_t* expected_color, | |
| 82 uint8_t* mask) { | |
| 83 uint8_t adjust_color[4]; | |
| 84 switch (src_internal_format) { | |
| 85 case GL_ALPHA: | |
| 86 setColor(0, 0, 0, color[0], adjust_color); | |
| 87 break; | |
| 88 case GL_R8: | |
| 89 setColor(color[0], 0, 0, 255, adjust_color); | |
| 90 break; | |
| 91 case GL_LUMINANCE: | |
| 92 setColor(color[0], color[0], color[0], 255, adjust_color); | |
| 93 break; | |
| 94 case GL_LUMINANCE_ALPHA: | |
| 95 setColor(color[0], color[0], color[0], color[1], adjust_color); | |
| 96 break; | |
| 97 case GL_RGB: | |
| 98 case GL_RGB8: | |
| 99 case GL_RGB_YCBCR_420V_CHROMIUM: | |
| 100 case GL_RGB_YCBCR_422_CHROMIUM: | |
| 101 setColor(color[0], color[1], color[2], 255, adjust_color); | |
| 102 break; | |
| 103 case GL_RGBA: | |
| 104 case GL_RGBA8: | |
| 105 setColor(color[0], color[1], color[2], color[3], adjust_color); | |
| 106 break; | |
| 107 case GL_BGRA_EXT: | |
| 108 case GL_BGRA8_EXT: | |
| 109 setColor(color[2], color[1], color[0], color[3], adjust_color); | |
| 110 break; | |
| 111 default: | |
| 112 NOTREACHED(); | |
| 113 break; | |
| 114 } | |
| 115 | |
| 116 switch (dest_internal_format) { | |
| 117 case GL_ALPHA: | |
| 118 setColor(0, 0, 0, adjust_color[3], expected_color); | |
| 119 setColor(0, 0, 0, 1, mask); | |
| 120 break; | |
| 121 case GL_R8: | |
| 122 case GL_R16F: | |
| 123 case GL_R32F: | |
| 124 case GL_R8UI: | |
| 125 setColor(adjust_color[0], 0, 0, 0, expected_color); | |
| 126 setColor(1, 0, 0, 0, mask); | |
| 127 break; | |
| 128 case GL_LUMINANCE: | |
| 129 setColor(adjust_color[0], 0, 0, 0, expected_color); | |
| 130 setColor(1, 0, 0, 0, mask); | |
| 131 break; | |
| 132 case GL_LUMINANCE_ALPHA: | |
| 133 setColor(adjust_color[0], 0, 0, adjust_color[3], expected_color); | |
| 134 setColor(1, 0, 0, 1, mask); | |
| 135 break; | |
| 136 case GL_RG8: | |
| 137 case GL_RG16F: | |
| 138 case GL_RG32F: | |
| 139 case GL_RG8UI: | |
| 140 setColor(adjust_color[0], adjust_color[1], 0, 0, expected_color); | |
| 141 setColor(1, 1, 0, 0, mask); | |
| 142 break; | |
| 143 case GL_RGB: | |
| 144 case GL_RGB8: | |
| 145 case GL_SRGB_EXT: | |
| 146 case GL_SRGB8: | |
| 147 case GL_RGB565: | |
| 148 case GL_R11F_G11F_B10F: | |
| 149 case GL_RGB9_E5: | |
| 150 case GL_RGB16F: | |
| 151 case GL_RGB32F: | |
| 152 case GL_RGB8UI: | |
| 153 setColor(adjust_color[0], adjust_color[1], adjust_color[2], 0, | |
| 154 expected_color); | |
| 155 setColor(1, 1, 1, 0, mask); | |
| 156 break; | |
| 157 case GL_RGBA: | |
| 158 case GL_RGBA8: | |
| 159 case GL_BGRA_EXT: | |
| 160 case GL_BGRA8_EXT: | |
| 161 case GL_SRGB_ALPHA_EXT: | |
| 162 case GL_SRGB8_ALPHA8: | |
| 163 case GL_RGBA4: | |
| 164 case GL_RGBA16F: | |
| 165 case GL_RGBA32F: | |
| 166 case GL_RGBA8UI: | |
| 167 setColor(adjust_color[0], adjust_color[1], adjust_color[2], | |
| 168 adjust_color[3], expected_color); | |
| 169 setColor(1, 1, 1, 1, mask); | |
| 170 break; | |
| 171 case GL_RGB5_A1: | |
| 172 setColor(adjust_color[0], adjust_color[1], adjust_color[2], | |
| 173 (adjust_color[3] >> 7) ? 0xFF : 0x0, expected_color); | |
| 174 // TODO(qiankun.miao@intel.com): On some Windows platforms, the alpha | |
| 175 // channel of expected color is the source alpha value other than 255. | |
| 176 // This should be wrong. Skip the alpha channel check and revisit this in | |
| 177 // future. | |
| 178 setColor(1, 1, 1, 0, mask); | |
| 179 break; | |
| 180 default: | |
| 181 NOTREACHED(); | |
| 182 break; | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 } // namespace | |
| 187 | |
| 30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 188 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
| 31 class GLCopyTextureCHROMIUMTest | 189 class GLCopyTextureCHROMIUMTest |
| 32 : public testing::Test, | 190 : public testing::Test, |
| 33 public ::testing::WithParamInterface<CopyType> { | 191 public ::testing::WithParamInterface<CopyType> { |
| 34 protected: | 192 protected: |
| 35 | 193 |
| 36 void CreateAndBindDestinationTextureAndFBO(GLenum target) { | 194 void CreateAndBindDestinationTextureAndFBO(GLenum target) { |
| 37 glGenTextures(2, textures_); | 195 glGenTextures(2, textures_); |
| 38 glBindTexture(target, textures_[1]); | 196 glBindTexture(target, textures_[1]); |
| 39 | 197 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 NOTREACHED(); | 243 NOTREACHED(); |
| 86 return GL_NONE; | 244 return GL_NONE; |
| 87 } | 245 } |
| 88 } | 246 } |
| 89 | 247 |
| 90 GLManager gl_; | 248 GLManager gl_; |
| 91 GLuint textures_[2]; | 249 GLuint textures_[2]; |
| 92 GLuint framebuffer_id_; | 250 GLuint framebuffer_id_; |
| 93 }; | 251 }; |
| 94 | 252 |
| 253 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest { | |
| 254 protected: | |
| 255 void SetUp() override { | |
| 256 GLManager::Options options; | |
| 257 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; | |
| 258 options.size = gfx::Size(64, 64); | |
| 259 gl_.Initialize(options); | |
| 260 | |
| 261 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); | |
| 262 } | |
| 263 | |
| 264 // If a driver isn't capable of supporting ES3 context, creating | |
| 265 // ContextGroup will fail. Just skip the test. | |
| 266 bool ShouldSkipTest() const { | |
| 267 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup()); | |
| 268 } | |
| 269 | |
| 270 // RGB9_E5 isn't accepted by glCopyTexImage2D if underneath context is ES. | |
|
Zhenyao Mo
2016/12/01 01:34:02
This I don't understand. If it's not accepted in
qiankun
2016/12/02 16:53:46
I am afraid we cannot make RGB9_E5 work since it's
Zhenyao Mo
2016/12/03 00:39:20
So in ValidateCopyTextureCHROMIUMInternalFormats()
qiankun
2016/12/10 00:12:40
Disable RGB9_E5 format for ES context before the r
| |
| 271 bool ShouldSkipRGB9_E5() const { | |
| 272 DCHECK(!ShouldSkipTest()); | |
| 273 const gl::GLVersionInfo& gl_version_info = | |
| 274 gl_.decoder()->GetFeatureInfo()->gl_version_info(); | |
| 275 return gl_version_info.is_es; | |
| 276 } | |
| 277 | |
| 278 // If EXT_color_buffer_float isn't available, float format isn't supported. | |
| 279 bool ShouldSkipFloatFormat() const { | |
| 280 DCHECK(!ShouldSkipTest()); | |
| 281 return !gl_.decoder()->GetFeatureInfo()->ext_color_buffer_float_available(); | |
| 282 } | |
| 283 | |
| 284 bool ShouldSkipBGRA() const { | |
| 285 DCHECK(!ShouldSkipTest()); | |
| 286 return !gl_.decoder() | |
| 287 ->GetFeatureInfo() | |
| 288 ->feature_flags() | |
| 289 .ext_texture_format_bgra8888; | |
| 290 } | |
| 291 | |
| 292 bool ShouldSkipSRGBEXT() const { | |
| 293 DCHECK(!ShouldSkipTest()); | |
| 294 return !gl_.decoder()->GetFeatureInfo()->feature_flags().ext_srgb; | |
| 295 } | |
| 296 }; | |
| 297 | |
| 95 INSTANTIATE_TEST_CASE_P(CopyType, | 298 INSTANTIATE_TEST_CASE_P(CopyType, |
| 96 GLCopyTextureCHROMIUMTest, | 299 GLCopyTextureCHROMIUMTest, |
| 97 ::testing::ValuesIn(kCopyTypes)); | 300 ::testing::ValuesIn(kCopyTypes)); |
| 98 | 301 |
| 302 INSTANTIATE_TEST_CASE_P(CopyType, | |
| 303 GLCopyTextureCHROMIUMES3Test, | |
| 304 ::testing::ValuesIn(kCopyTypes)); | |
| 305 | |
| 99 // Test to ensure that the basic functionality of the extension works. | 306 // Test to ensure that the basic functionality of the extension works. |
| 100 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { | 307 TEST_P(GLCopyTextureCHROMIUMTest, Basic) { |
| 101 CopyType copy_type = GetParam(); | 308 CopyType copy_type = GetParam(); |
| 102 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; | 309 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; |
| 103 | 310 |
| 104 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 311 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 312 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 106 pixels); | 313 pixels); |
| 107 | 314 |
| 108 if (copy_type == TexImage) { | 315 if (copy_type == TexImage) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 125 EXPECT_EQ(framebuffer_id_, fb_id); | 332 EXPECT_EQ(framebuffer_id_, fb_id); |
| 126 | 333 |
| 127 // Check that FB is complete. | 334 // Check that FB is complete. |
| 128 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 335 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 129 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 336 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 130 | 337 |
| 131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 338 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
| 132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 339 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 133 } | 340 } |
| 134 | 341 |
| 342 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) { | |
| 343 if (ShouldSkipTest()) | |
| 344 return; | |
| 345 CopyType copy_type = GetParam(); | |
| 346 | |
| 347 struct FormatType { | |
| 348 GLenum internal_format; | |
| 349 GLenum format; | |
| 350 GLenum type; | |
| 351 }; | |
| 352 | |
| 353 FormatType src_format_types[] = { | |
| 354 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | |
| 355 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | |
| 356 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 357 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 358 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 359 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 360 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
| 361 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
| 362 }; | |
| 363 | |
| 364 FormatType dest_format_types[] = { | |
| 365 // TODO(qiankun.miao@intel.com): ALPHA and LUMINANCE formats have bug on | |
| 366 // GL core profile. See crbug.com/577144. Enable these formats after | |
| 367 // using workaround in gles2_cmd_copy_tex_image.cc. | |
| 368 // {GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE}, | |
| 369 // {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | |
| 370 // {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | |
| 371 | |
| 372 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 373 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 374 {GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE}, | |
| 375 {GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE}, | |
| 376 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
| 377 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
| 378 {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, | |
| 379 {GL_R16F, GL_RED, GL_HALF_FLOAT}, | |
| 380 {GL_R16F, GL_RED, GL_FLOAT}, | |
| 381 {GL_R32F, GL_RED, GL_FLOAT}, | |
| 382 {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, | |
| 383 {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, | |
| 384 {GL_RG16F, GL_RG, GL_HALF_FLOAT}, | |
| 385 {GL_RG16F, GL_RG, GL_FLOAT}, | |
| 386 {GL_RG32F, GL_RG, GL_FLOAT}, | |
| 387 {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE}, | |
| 388 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 389 {GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 390 {GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 391 {GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT}, | |
| 392 {GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT}, | |
| 393 {GL_RGB9_E5, GL_RGB, GL_FLOAT}, | |
| 394 {GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, | |
| 395 {GL_RGB16F, GL_RGB, GL_FLOAT}, | |
| 396 {GL_RGB32F, GL_RGB, GL_FLOAT}, | |
| 397 {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, | |
| 398 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 399 {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 400 {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 401 {GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 402 {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, | |
| 403 {GL_RGBA16F, GL_RGBA, GL_FLOAT}, | |
| 404 {GL_RGBA32F, GL_RGBA, GL_FLOAT}, | |
| 405 {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, | |
| 406 }; | |
| 407 | |
| 408 for (auto src_format_type : src_format_types) { | |
| 409 for (auto dest_format_type : dest_format_types) { | |
| 410 if (dest_format_type.internal_format == GL_RGB9_E5 && ShouldSkipRGB9_E5()) | |
| 411 continue; | |
| 412 if ((src_format_type.internal_format == GL_BGRA_EXT || | |
| 413 src_format_type.internal_format == GL_BGRA8_EXT || | |
| 414 dest_format_type.internal_format == GL_BGRA_EXT || | |
| 415 dest_format_type.internal_format == GL_BGRA8_EXT) && | |
| 416 ShouldSkipBGRA()) | |
| 417 continue; | |
|
Zhenyao Mo
2016/12/01 01:34:02
Again, use {} here and below.
qiankun
2016/12/02 16:53:46
Done.
| |
| 418 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && | |
| 419 ShouldSkipFloatFormat()) | |
| 420 continue; | |
| 421 if ((dest_format_type.internal_format == GL_SRGB_EXT || | |
| 422 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && | |
| 423 ShouldSkipSRGBEXT()) | |
| 424 continue; | |
| 425 | |
| 426 const GLsizei kWidth = 8, kHeight = 8; | |
| 427 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( | |
| 428 src_format_type.format, src_format_type.type); | |
| 429 uint8_t color[4] = {1, 63, 127, 255}; | |
| 430 uint8_t pixels[8 * 8 * 4]; | |
| 431 for (int i = 0; i < kWidth * kHeight * src_channel_count; | |
| 432 i += src_channel_count) | |
| 433 for (int j = 0; j < src_channel_count; ++j) | |
| 434 pixels[i + j] = color[j]; | |
| 435 uint8_t expected_color[4]; | |
| 436 uint8_t mask[4]; | |
| 437 getExpectedColor(src_format_type.internal_format, | |
| 438 dest_format_type.internal_format, color, expected_color, | |
| 439 mask); | |
| 440 | |
| 441 glDeleteTextures(2, textures_); | |
| 442 glDeleteFramebuffers(1, &framebuffer_id_); | |
|
Zhenyao Mo
2016/12/01 01:34:02
This is hard to understand. Can we not do it in t
qiankun
2016/12/02 16:53:46
Done.
| |
| 443 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); | |
| 444 | |
| 445 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
| 446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 448 glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth, | |
| 449 kHeight, 0, src_format_type.format, src_format_type.type, | |
| 450 pixels); | |
| 451 | |
| 452 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
| 453 if (copy_type == TexImage) { | |
| 454 glCopyTextureCHROMIUM(textures_[0], textures_[1], | |
| 455 dest_format_type.internal_format, | |
| 456 dest_format_type.type, false, false, false); | |
| 457 } else { | |
| 458 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
| 459 glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth, | |
| 460 kHeight, 0, dest_format_type.format, dest_format_type.type, | |
| 461 nullptr); | |
| 462 | |
| 463 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth, | |
| 464 kHeight, false, false, false); | |
| 465 } | |
| 466 EXPECT_TRUE(glGetError() == GL_NO_ERROR) | |
| 467 << " src_internal_format: " | |
| 468 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format) | |
| 469 << " dest_internal_format: " | |
| 470 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format); | |
| 471 | |
| 472 // Draw destination texture to a fbo with attachment in RGBA format. | |
| 473 glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| 474 GLuint framebuffer = 0; | |
| 475 glGenFramebuffers(1, &framebuffer); | |
| 476 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
| 477 GLuint texture = 0; | |
| 478 glGenTextures(1, &texture); | |
| 479 glBindTexture(GL_TEXTURE_2D, texture); | |
| 480 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 482 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight); | |
| 483 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 484 GL_TEXTURE_2D, texture, 0); | |
| 485 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
| 486 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
| 487 glViewport(0, 0, kWidth, kHeight); | |
| 488 | |
| 489 std::string fragment_shader_source = | |
| 490 GetFragmentShaderSource(dest_format_type.internal_format); | |
| 491 GLuint program = GLTestHelper::LoadProgram( | |
| 492 kSimpleVertexShaderES3, fragment_shader_source.c_str()); | |
| 493 EXPECT_NE(program, 0u); | |
| 494 GLint position_loc = glGetAttribLocation(program, "a_position"); | |
| 495 GLint texture_loc = glGetUniformLocation(program, "u_texture"); | |
| 496 ASSERT_NE(position_loc, -1); | |
| 497 ASSERT_NE(texture_loc, -1); | |
| 498 glUseProgram(program); | |
| 499 | |
| 500 GLuint vbo = GLTestHelper::SetupUnitQuad(position_loc); | |
| 501 ASSERT_NE(vbo, 0u); | |
| 502 | |
| 503 glActiveTexture(GL_TEXTURE0); | |
| 504 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
| 505 | |
| 506 glDrawArrays(GL_TRIANGLES, 0, 6); | |
| 507 | |
| 508 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
| 509 | |
| 510 GLsizei size = kWidth * kHeight * 4; | |
| 511 std::unique_ptr<uint8_t[]> result(new uint8_t[size]); | |
| 512 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, | |
|
Zhenyao Mo
2016/12/01 01:34:02
This is wrong. You can't do this with certain for
qiankun
2016/12/02 16:53:46
The destination texture is drawn to a RGBA texture
| |
| 513 result.get()); | |
| 514 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7; | |
| 515 for (GLint yy = 0; yy < kHeight; ++yy) { | |
| 516 for (GLint xx = 0; xx < kWidth; ++xx) { | |
| 517 int offset = yy * kWidth * 4 + xx * 4; | |
| 518 for (int jj = 0; jj < 4; ++jj) { | |
| 519 uint8_t actual = result[offset + jj]; | |
| 520 uint8_t expected = expected_color[jj]; | |
| 521 int diff = actual - expected; | |
| 522 diff = diff < 0 ? -diff : diff; | |
| 523 if (mask[jj] && diff > tolerance) { | |
| 524 EXPECT_EQ(expected, actual) | |
| 525 << " at " << xx << ", " << yy << " channel " << jj | |
| 526 << " src_internal_format: " | |
| 527 << gles2::GLES2Util::GetStringEnum( | |
| 528 src_format_type.internal_format) | |
| 529 << " dest_internal_format: " | |
| 530 << gles2::GLES2Util::GetStringEnum( | |
| 531 dest_format_type.internal_format); | |
| 532 } | |
| 533 } | |
| 534 } | |
| 535 } | |
| 536 | |
| 537 glDeleteTextures(1, &texture); | |
| 538 glDeleteFramebuffers(1, &framebuffer); | |
| 539 } | |
| 540 } | |
| 541 } | |
| 542 | |
| 135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { | 543 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
| 136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | 544 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { |
| 137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | 545 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; |
| 138 return; | 546 return; |
| 139 } | 547 } |
| 140 CopyType copy_type = GetParam(); | 548 CopyType copy_type = GetParam(); |
| 141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; | 549 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
| 142 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; | 550 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
| 143 | 551 |
| 144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; | 552 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 } | 631 } |
| 224 | 632 |
| 225 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { | 633 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
| 226 CopyType copy_type = GetParam(); | 634 CopyType copy_type = GetParam(); |
| 227 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 635 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 636 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 229 nullptr); | 637 nullptr); |
| 230 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 638 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 231 | 639 |
| 232 // Check unsupported format reports error. | 640 // Check unsupported format reports error. |
| 233 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, | 641 GLint unsupported_dest_formats[] = {GL_RED, GL_RG}; |
| 234 GL_LUMINANCE_ALPHA}; | |
| 235 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); | 642 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); |
| 236 dest_index++) { | 643 dest_index++) { |
| 237 if (copy_type == TexImage) { | 644 if (copy_type == TexImage) { |
| 238 glCopyTextureCHROMIUM(textures_[0], textures_[1], | 645 glCopyTextureCHROMIUM(textures_[0], textures_[1], |
| 239 unsupported_dest_formats[dest_index], | 646 unsupported_dest_formats[dest_index], |
| 240 GL_UNSIGNED_BYTE, false, false, false); | 647 GL_UNSIGNED_BYTE, false, false, false); |
| 241 } else { | 648 } else { |
| 242 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 649 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 243 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, | 650 glTexImage2D(GL_TEXTURE_2D, 0, unsupported_dest_formats[dest_index], 1, 1, |
| 244 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, | 651 0, unsupported_dest_formats[dest_index], GL_UNSIGNED_BYTE, |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 expected_color = y < copy_region_y + 1 ? blue : white; | 1301 expected_color = y < copy_region_y + 1 ? blue : white; |
| 895 } | 1302 } |
| 896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); | 1303 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); |
| 897 } | 1304 } |
| 898 } | 1305 } |
| 899 } | 1306 } |
| 900 } | 1307 } |
| 901 } | 1308 } |
| 902 | 1309 |
| 903 } // namespace gpu | 1310 } // namespace gpu |
| OLD | NEW |