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> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 namespace gpu { | 22 namespace gpu { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 enum CopyType { TexImage, TexSubImage }; | 26 enum CopyType { TexImage, TexSubImage }; |
| 27 const CopyType kCopyTypes[] = { | 27 const CopyType kCopyTypes[] = { |
| 28 TexImage, | 28 TexImage, |
| 29 TexSubImage, | 29 TexSubImage, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 struct FormatType { | |
| 33 GLenum internal_format; | |
| 34 GLenum format; | |
| 35 GLenum type; | |
| 36 }; | |
| 37 | |
| 38 static const char* kSimpleVertexShaderES2 = | |
| 39 "attribute vec2 a_position;\n" | |
| 40 "varying vec2 v_texCoord;\n" | |
| 41 "void main() {\n" | |
| 42 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" | |
| 43 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" | |
| 44 "}\n"; | |
| 45 | |
| 32 static const char* kSimpleVertexShaderES3 = | 46 static const char* kSimpleVertexShaderES3 = |
| 33 "#version 300 es\n" | 47 "#version 300 es\n" |
| 34 "in vec2 a_position;\n" | 48 "in vec2 a_position;\n" |
| 35 "out vec2 v_texCoord;\n" | 49 "out vec2 v_texCoord;\n" |
| 36 "void main() {\n" | 50 "void main() {\n" |
| 37 " gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);\n" | 51 " 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" | 52 " v_texCoord = (a_position + vec2(1.0, 1.0)) * 0.5;\n" |
| 39 "}\n"; | 53 "}\n"; |
| 40 | 54 |
| 41 std::string GetFragmentShaderSource(GLenum format) { | 55 std::string GetFragmentShaderSource(GLenum format, bool is_es3) { |
| 42 std::string source; | 56 std::string source; |
| 43 source += std::string( | 57 if (is_es3) { |
| 44 "#version 300 es\n" | 58 source += |
| 45 "precision mediump float;\n"); | 59 "#version 300 es\n" |
| 60 "#define VARYING in\n" | |
| 61 "#define FRAGCOLOR frag_color\n" | |
| 62 "#define TextureLookup texture\n"; | |
| 63 } else { | |
| 64 source += | |
| 65 "#define VARYING varying\n" | |
| 66 "#define FRAGCOLOR gl_FragColor\n" | |
| 67 "#define TextureLookup texture2D\n"; | |
| 68 } | |
| 69 source += "precision mediump float;\n"; | |
| 70 | |
| 46 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) { | 71 if (gles2::GLES2Util::IsSignedIntegerFormat(format)) { |
| 47 source += std::string("#define SamplerType isampler2D\n"); | 72 source += std::string("#define SamplerType isampler2D\n"); |
| 48 source += std::string("#define TextureType ivec4\n"); | 73 source += std::string("#define TextureType ivec4\n"); |
| 49 source += std::string("#define ScaleValue 255.0\n"); | 74 source += std::string("#define ScaleValue 255.0\n"); |
| 50 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) { | 75 } else if (gles2::GLES2Util::IsUnsignedIntegerFormat(format)) { |
| 51 source += std::string("#define SamplerType usampler2D\n"); | 76 source += std::string("#define SamplerType usampler2D\n"); |
| 52 source += std::string("#define TextureType uvec4\n"); | 77 source += std::string("#define TextureType uvec4\n"); |
| 53 source += std::string("#define ScaleValue 255.0\n"); | 78 source += std::string("#define ScaleValue 255.0\n"); |
| 54 } else { | 79 } else { |
| 55 source += std::string("#define SamplerType sampler2D\n"); | 80 source += std::string("#define SamplerType sampler2D\n"); |
| 56 source += std::string("#define TextureType vec4\n"); | 81 source += std::string("#define TextureType vec4\n"); |
| 57 source += std::string("#define ScaleValue 1.0\n"); | 82 source += std::string("#define ScaleValue 1.0\n"); |
| 58 } | 83 } |
| 59 | 84 |
| 85 if (is_es3) | |
| 86 source += "out vec4 frag_color;\n"; | |
| 87 | |
| 60 source += std::string( | 88 source += std::string( |
| 61 "uniform mediump SamplerType u_texture;\n" | 89 "uniform mediump SamplerType u_texture;\n" |
| 62 "in vec2 v_texCoord;\n" | 90 "VARYING vec2 v_texCoord;\n" |
| 63 "out vec4 fragData;\n" | |
| 64 "void main() {\n" | 91 "void main() {\n" |
| 65 " TextureType color = texture(u_texture, v_texCoord);\n" | 92 " TextureType color = TextureLookup(u_texture, v_texCoord);\n" |
| 66 " fragData = vec4(color) / ScaleValue;\n" | 93 " FRAGCOLOR = vec4(color) / ScaleValue;\n" |
| 67 "}\n"); | 94 "}\n"); |
| 68 return source; | 95 return source; |
| 69 } | 96 } |
| 70 | 97 |
| 71 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) { | 98 void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t* color) { |
| 72 color[0] = r; | 99 color[0] = r; |
| 73 color[1] = g; | 100 color[1] = g; |
| 74 color[2] = b; | 101 color[2] = b; |
| 75 color[3] = a; | 102 color[3] = a; |
| 76 } | 103 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 } | 210 } |
| 184 } | 211 } |
| 185 | 212 |
| 186 } // namespace | 213 } // namespace |
| 187 | 214 |
| 188 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 215 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
| 189 class GLCopyTextureCHROMIUMTest | 216 class GLCopyTextureCHROMIUMTest |
| 190 : public testing::Test, | 217 : public testing::Test, |
| 191 public ::testing::WithParamInterface<CopyType> { | 218 public ::testing::WithParamInterface<CopyType> { |
| 192 protected: | 219 protected: |
| 193 | |
| 194 void CreateAndBindDestinationTextureAndFBO(GLenum target) { | 220 void CreateAndBindDestinationTextureAndFBO(GLenum target) { |
| 195 glGenTextures(2, textures_); | 221 glGenTextures(2, textures_); |
| 196 glBindTexture(target, textures_[1]); | 222 glBindTexture(target, textures_[1]); |
| 197 | 223 |
| 198 // Some drivers (NVidia/SGX) require texture settings to be a certain way or | 224 // Some drivers (NVidia/SGX) require texture settings to be a certain way or |
| 199 // they won't report FRAMEBUFFER_COMPLETE. | 225 // they won't report FRAMEBUFFER_COMPLETE. |
| 200 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 226 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 201 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 227 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 202 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 228 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 203 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 229 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 204 | 230 |
| 205 glGenFramebuffers(1, &framebuffer_id_); | 231 glGenFramebuffers(1, &framebuffer_id_); |
| 206 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); | 232 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 207 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, | 233 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, |
| 208 textures_[1], 0); | 234 textures_[1], 0); |
| 209 } | 235 } |
| 210 | 236 |
| 211 void SetUp() override { | 237 void SetUp() override { |
| 212 gl_.Initialize(GLManager::Options()); | 238 GLManager::Options options; |
| 239 options.size = gfx::Size(64, 64); | |
| 240 gl_.Initialize(options); | |
| 241 | |
| 242 width_ = 8; | |
| 243 height_ = 8; | |
| 213 } | 244 } |
| 214 | 245 |
| 215 void TearDown() override { gl_.Destroy(); } | 246 void TearDown() override { gl_.Destroy(); } |
| 216 | 247 |
| 217 void CreateBackingForTexture(GLenum target, GLsizei width, GLsizei height) { | 248 void CreateBackingForTexture(GLenum target, GLsizei width, GLsizei height) { |
| 218 if (target == GL_TEXTURE_RECTANGLE_ARB) { | 249 if (target == GL_TEXTURE_RECTANGLE_ARB) { |
| 219 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM( | 250 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM( |
| 220 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM); | 251 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM); |
| 221 glBindTexImage2DCHROMIUM(target, image_id); | 252 glBindTexImage2DCHROMIUM(target, image_id); |
| 222 } else { | 253 } else { |
| 223 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, | 254 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, |
| 224 GL_UNSIGNED_BYTE, nullptr); | 255 GL_UNSIGNED_BYTE, nullptr); |
| 225 } | 256 } |
| 226 } | 257 } |
| 227 | 258 |
| 259 GLuint CreateDrawingTexture(GLenum target, GLsizei width, GLsizei height) { | |
| 260 GLuint texture = 0; | |
| 261 glGenTextures(1, &texture); | |
| 262 glBindTexture(target, texture); | |
| 263 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 264 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 265 CreateBackingForTexture(GL_TEXTURE_2D, width, height); | |
| 266 return texture; | |
| 267 } | |
| 268 | |
| 269 GLuint CreateDrawingFBO(GLenum target, GLuint texture) { | |
| 270 GLuint framebuffer = 0; | |
| 271 glGenFramebuffers(1, &framebuffer); | |
| 272 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
| 273 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, | |
| 274 texture, 0); | |
| 275 return framebuffer; | |
| 276 } | |
| 277 | |
| 228 GLenum ExtractFormatFrom(GLenum internalformat) { | 278 GLenum ExtractFormatFrom(GLenum internalformat) { |
| 229 switch (internalformat) { | 279 switch (internalformat) { |
| 230 case GL_RGBA8_OES: | 280 case GL_RGBA8_OES: |
| 231 return GL_RGBA; | 281 return GL_RGBA; |
| 232 case GL_RGB8_OES: | 282 case GL_RGB8_OES: |
| 233 return GL_RGB; | 283 return GL_RGB; |
| 234 case GL_BGRA8_EXT: | 284 case GL_BGRA8_EXT: |
| 235 return GL_BGRA_EXT; | 285 return GL_BGRA_EXT; |
| 236 default: | 286 default: |
| 237 NOTREACHED(); | 287 NOTREACHED(); |
| 238 return GL_NONE; | 288 return GL_NONE; |
| 239 } | 289 } |
| 240 } | 290 } |
| 241 | 291 |
| 292 void RunCopyTexture(GLenum target, | |
| 293 CopyType copy_type, | |
| 294 FormatType src_format_type, | |
| 295 GLint source_level, | |
| 296 FormatType dest_format_type, | |
| 297 GLint dest_level, | |
| 298 bool is_es3) { | |
| 299 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( | |
| 300 src_format_type.format, src_format_type.type); | |
| 301 uint8_t color[4] = {1u, 63u, 127u, 255u}; | |
| 302 std::unique_ptr<uint8_t[]> pixels(new uint8_t[width_ * height_ * 4]); | |
| 303 for (int i = 0; i < width_ * height_ * src_channel_count; | |
| 304 i += src_channel_count) | |
| 305 for (int j = 0; j < src_channel_count; ++j) | |
| 306 pixels[i + j] = color[j]; | |
| 307 uint8_t expected_color[4]; | |
| 308 uint8_t mask[4]; | |
| 309 getExpectedColor(src_format_type.internal_format, | |
| 310 dest_format_type.internal_format, color, expected_color, | |
| 311 mask); | |
| 312 | |
| 313 glGenTextures(2, textures_); | |
| 314 glBindTexture(target, textures_[0]); | |
| 315 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 316 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 317 glTexImage2D(target, source_level, src_format_type.internal_format, width_, | |
| 318 height_, 0, src_format_type.format, src_format_type.type, | |
| 319 pixels.get()); | |
| 320 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
| 321 glBindTexture(target, textures_[1]); | |
| 322 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 323 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 324 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 325 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
| 326 | |
| 327 if (copy_type == TexImage) { | |
| 328 glCopyTextureCHROMIUM(textures_[0], textures_[1], | |
|
Zhenyao Mo
2017/01/04 18:51:21
Could you please add a comment here that this func
qiankun
2017/01/05 03:07:45
Done.
| |
| 329 dest_format_type.internal_format, | |
| 330 dest_format_type.type, false, false, false); | |
| 331 } else { | |
| 332 glBindTexture(target, textures_[1]); | |
| 333 glTexImage2D(target, dest_level, dest_format_type.internal_format, width_, | |
| 334 height_, 0, dest_format_type.format, dest_format_type.type, | |
| 335 nullptr); | |
| 336 | |
| 337 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, width_, | |
|
Zhenyao Mo
2017/01/04 18:51:21
Same here.
qiankun
2017/01/05 03:07:45
Done.
| |
| 338 height_, false, false, false); | |
| 339 } | |
| 340 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
| 341 | |
| 342 // Draw destination texture to a fbo with a texture attachment in RGBA | |
| 343 // format. | |
| 344 GLuint texture = CreateDrawingTexture(target, width_, height_); | |
| 345 GLuint framebuffer = CreateDrawingFBO(target, texture); | |
| 346 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
| 347 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
| 348 glViewport(0, 0, width_, height_); | |
| 349 | |
| 350 glBindTexture(target, textures_[1]); | |
| 351 std::string fragment_shader_source = | |
| 352 GetFragmentShaderSource(dest_format_type.internal_format, is_es3); | |
| 353 GLTestHelper::DrawTextureQuad( | |
|
Zhenyao Mo
2017/01/04 18:51:21
Again, the tex level information isn't reflected h
qiankun
2017/01/05 03:07:45
Done.
| |
| 354 is_es3 ? kSimpleVertexShaderES3 : kSimpleVertexShaderES2, | |
| 355 fragment_shader_source.c_str(), "a_position", "u_texture"); | |
| 356 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
| 357 | |
| 358 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7; | |
| 359 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, width_, height_, tolerance, | |
| 360 expected_color, mask)) | |
| 361 << " src_internal_format: " | |
| 362 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format) | |
| 363 << " source_level: " << source_level | |
| 364 << " dest_internal_format: " | |
| 365 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format) | |
| 366 << " dest_level: " << dest_level; | |
| 367 | |
| 368 glDeleteTextures(1, &texture); | |
| 369 glDeleteFramebuffers(1, &framebuffer); | |
| 370 glDeleteTextures(2, textures_); | |
| 371 } | |
| 372 | |
| 242 GLManager gl_; | 373 GLManager gl_; |
| 243 GLuint textures_[2]; | 374 GLuint textures_[2]; |
| 375 GLsizei width_; | |
| 376 GLsizei height_; | |
| 244 GLuint framebuffer_id_; | 377 GLuint framebuffer_id_; |
| 245 }; | 378 }; |
| 246 | 379 |
| 247 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest { | 380 class GLCopyTextureCHROMIUMES3Test : public GLCopyTextureCHROMIUMTest { |
| 248 protected: | 381 protected: |
| 249 void SetUp() override { | 382 void SetUp() override { |
| 250 GLManager::Options options; | 383 GLManager::Options options; |
| 251 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; | 384 options.context_type = gles2::CONTEXT_TYPE_OPENGLES3; |
| 252 options.size = gfx::Size(64, 64); | 385 options.size = gfx::Size(64, 64); |
| 253 gl_.Initialize(options); | 386 gl_.Initialize(options); |
| 387 | |
| 388 width_ = 8; | |
| 389 height_ = 8; | |
| 254 } | 390 } |
| 255 | 391 |
| 256 // If a driver isn't capable of supporting ES3 context, creating | 392 // If a driver isn't capable of supporting ES3 context, creating |
| 257 // ContextGroup will fail. Just skip the test. | 393 // ContextGroup will fail. Just skip the test. |
| 258 bool ShouldSkipTest() const { | 394 bool ShouldSkipTest() const { |
| 259 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup()); | 395 return (!gl_.decoder() || !gl_.decoder()->GetContextGroup()); |
| 260 } | 396 } |
| 261 | 397 |
| 262 // RGB9_E5 isn't accepted by glCopyTexImage2D if underlying context is ES. | 398 // RGB9_E5 isn't accepted by glCopyTexImage2D if underlying context is ES. |
| 263 // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context. | 399 // TODO(qiankun.miao@intel.com): we should support RGB9_E5 in ES context. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 | 474 |
| 339 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels, nullptr); | 475 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels, nullptr); |
| 340 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 476 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 341 } | 477 } |
| 342 | 478 |
| 343 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) { | 479 TEST_P(GLCopyTextureCHROMIUMES3Test, FormatCombinations) { |
| 344 if (ShouldSkipTest()) | 480 if (ShouldSkipTest()) |
| 345 return; | 481 return; |
| 346 CopyType copy_type = GetParam(); | 482 CopyType copy_type = GetParam(); |
| 347 | 483 |
| 348 struct FormatType { | |
| 349 GLenum internal_format; | |
| 350 GLenum format; | |
| 351 GLenum type; | |
| 352 }; | |
| 353 | |
| 354 FormatType src_format_types[] = { | 484 FormatType src_format_types[] = { |
| 355 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, | 485 {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE}, |
| 356 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, | 486 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, |
| 357 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | 487 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, |
| 358 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, | 488 {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, |
| 359 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | 489 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, |
| 360 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | 490 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, |
| 361 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | 491 {GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, |
| 362 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | 492 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, |
| 363 }; | 493 }; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && | 550 if (gles2::GLES2Util::IsFloatFormat(dest_format_type.internal_format) && |
| 421 ShouldSkipFloatFormat()) | 551 ShouldSkipFloatFormat()) |
| 422 continue; | 552 continue; |
| 423 if ((dest_format_type.internal_format == GL_SRGB_EXT || | 553 if ((dest_format_type.internal_format == GL_SRGB_EXT || |
| 424 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && | 554 dest_format_type.internal_format == GL_SRGB_ALPHA_EXT) && |
| 425 ShouldSkipSRGBEXT()) | 555 ShouldSkipSRGBEXT()) |
| 426 continue; | 556 continue; |
| 427 if (dest_format_type.internal_format == GL_RGB5_A1 && ShouldSkipRGB5_A1()) | 557 if (dest_format_type.internal_format == GL_RGB5_A1 && ShouldSkipRGB5_A1()) |
| 428 continue; | 558 continue; |
| 429 | 559 |
| 430 const GLsizei kWidth = 8, kHeight = 8; | 560 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, 0, |
| 431 const int src_channel_count = gles2::GLES2Util::ElementsPerGroup( | 561 dest_format_type, 0, true); |
| 432 src_format_type.format, src_format_type.type); | |
| 433 uint8_t color[4] = {1, 63, 127, 255}; | |
| 434 uint8_t pixels[8 * 8 * 4]; | |
| 435 for (int i = 0; i < kWidth * kHeight * src_channel_count; | |
| 436 i += src_channel_count) | |
| 437 for (int j = 0; j < src_channel_count; ++j) | |
| 438 pixels[i + j] = color[j]; | |
| 439 uint8_t expected_color[4]; | |
| 440 uint8_t mask[4]; | |
| 441 getExpectedColor(src_format_type.internal_format, | |
| 442 dest_format_type.internal_format, color, expected_color, | |
| 443 mask); | |
| 444 | |
| 445 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); | |
| 446 glBindTexture(GL_TEXTURE_2D, textures_[0]); | |
| 447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 449 glTexImage2D(GL_TEXTURE_2D, 0, src_format_type.internal_format, kWidth, | |
| 450 kHeight, 0, src_format_type.format, src_format_type.type, | |
| 451 pixels); | |
| 452 | |
| 453 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
| 454 if (copy_type == TexImage) { | |
| 455 glCopyTextureCHROMIUM(textures_[0], textures_[1], | |
| 456 dest_format_type.internal_format, | |
| 457 dest_format_type.type, false, false, false); | |
| 458 } else { | |
| 459 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
| 460 glTexImage2D(GL_TEXTURE_2D, 0, dest_format_type.internal_format, kWidth, | |
| 461 kHeight, 0, dest_format_type.format, dest_format_type.type, | |
| 462 nullptr); | |
| 463 | |
| 464 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, kWidth, | |
| 465 kHeight, false, false, false); | |
| 466 } | |
| 467 EXPECT_TRUE(glGetError() == GL_NO_ERROR) | |
| 468 << " src_internal_format: " | |
| 469 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format) | |
| 470 << " dest_internal_format: " | |
| 471 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format); | |
| 472 | |
| 473 // Draw destination texture to a fbo with attachment in RGBA format. | |
| 474 glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| 475 GLuint framebuffer = 0; | |
| 476 glGenFramebuffers(1, &framebuffer); | |
| 477 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
| 478 GLuint texture = 0; | |
| 479 glGenTextures(1, &texture); | |
| 480 glBindTexture(GL_TEXTURE_2D, texture); | |
| 481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 483 CreateBackingForTexture(GL_TEXTURE_2D, kWidth, kHeight); | |
| 484 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 485 GL_TEXTURE_2D, texture, 0); | |
| 486 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
| 487 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
| 488 glViewport(0, 0, kWidth, kHeight); | |
| 489 | |
| 490 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
| 491 std::string fragment_shader_source = | |
| 492 GetFragmentShaderSource(dest_format_type.internal_format); | |
| 493 GLTestHelper::DrawTextureQuad(kSimpleVertexShaderES3, | |
| 494 fragment_shader_source.c_str(), | |
| 495 "a_position", "u_texture"); | |
| 496 | |
| 497 uint8_t tolerance = dest_format_type.internal_format == GL_RGBA4 ? 20 : 7; | |
| 498 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kWidth, kHeight, tolerance, | |
| 499 expected_color, mask)) | |
| 500 << " src_internal_format: " | |
| 501 << gles2::GLES2Util::GetStringEnum(src_format_type.internal_format) | |
| 502 << " dest_internal_format: " | |
| 503 << gles2::GLES2Util::GetStringEnum(dest_format_type.internal_format); | |
| 504 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
| 505 | |
| 506 glDeleteTextures(1, &texture); | |
| 507 glDeleteFramebuffers(1, &framebuffer); | |
| 508 glDeleteTextures(2, textures_); | |
| 509 glDeleteFramebuffers(1, &framebuffer_id_); | |
| 510 } | 562 } |
| 511 } | 563 } |
| 512 } | 564 } |
| 513 | 565 |
| 514 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { | 566 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
| 515 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | 567 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { |
| 516 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | 568 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; |
| 517 return; | 569 return; |
| 518 } | 570 } |
| 519 CopyType copy_type = GetParam(); | 571 CopyType copy_type = GetParam(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 glCopyTextureCHROMIUM( | 705 glCopyTextureCHROMIUM( |
| 654 textures_[0], textures_[1], unsupported_format_types[dest_index].format, | 706 textures_[0], textures_[1], unsupported_format_types[dest_index].format, |
| 655 unsupported_format_types[dest_index].type, false, false, false); | 707 unsupported_format_types[dest_index].type, false, false, false); |
| 656 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) | 708 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) |
| 657 << "dest_index:" << dest_index; | 709 << "dest_index:" << dest_index; |
| 658 } | 710 } |
| 659 glDeleteTextures(2, textures_); | 711 glDeleteTextures(2, textures_); |
| 660 glDeleteFramebuffers(1, &framebuffer_id_); | 712 glDeleteFramebuffers(1, &framebuffer_id_); |
| 661 } | 713 } |
| 662 | 714 |
| 715 TEST_P(GLCopyTextureCHROMIUMTest, CopyTextureLevel) { | |
| 716 CopyType copy_type = GetParam(); | |
| 717 | |
| 718 // Copy from RGB source texture to dest texture. | |
| 719 FormatType src_format_type = {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}; | |
| 720 FormatType dest_format_types[] = { | |
| 721 {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}, | |
| 722 {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 723 }; | |
| 724 // Source level must be 0 in ES2 context. | |
|
Zhenyao Mo
2017/01/04 18:51:22
Even this can be lifted if you sample the source t
qiankun
2017/01/05 03:07:45
We cannot do this if the source texture is not com
| |
| 725 GLint source_level = 0; | |
| 726 | |
| 727 // TODO(qiankun.miao@intel.com): Support level > 0. | |
| 728 for (GLint dest_level = 0; dest_level < 1; dest_level++) { | |
| 729 for (auto dest_format_type : dest_format_types) { | |
| 730 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, source_level, | |
| 731 dest_format_type, dest_level, false); | |
| 732 } | |
| 733 } | |
| 734 } | |
| 735 | |
| 736 TEST_P(GLCopyTextureCHROMIUMES3Test, CopyTextureLevel) { | |
| 737 if (ShouldSkipTest()) | |
| 738 return; | |
| 739 CopyType copy_type = GetParam(); | |
| 740 | |
| 741 // Copy from RGBA source texture to dest texture. | |
| 742 FormatType src_format_type = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}; | |
| 743 FormatType dest_format_types[] = { | |
| 744 {GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, | |
| 745 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, | |
| 746 {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, | |
| 747 }; | |
| 748 | |
| 749 // TODO(qiankun.miao@intel.com): Support level > 0. | |
| 750 for (GLint source_level = 0; source_level < 1; source_level++) { | |
| 751 for (GLint dest_level = 0; dest_level < 1; dest_level++) { | |
| 752 for (auto dest_format_type : dest_format_types) { | |
| 753 RunCopyTexture(GL_TEXTURE_2D, copy_type, src_format_type, source_level, | |
| 754 dest_format_type, dest_level, true); | |
| 755 } | |
| 756 } | |
| 757 } | |
| 758 } | |
| 759 | |
| 663 // Test to ensure that the destination texture is redefined if the properties | 760 // Test to ensure that the destination texture is redefined if the properties |
| 664 // are different. | 761 // are different. |
| 665 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { | 762 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { |
| 666 uint8_t pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, | 763 uint8_t pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, |
| 667 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; | 764 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; |
| 668 | 765 |
| 669 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); | 766 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); |
| 670 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 767 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 671 glTexImage2D( | 768 glTexImage2D( |
| 672 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 769 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 } | 1413 } |
| 1317 } | 1414 } |
| 1318 | 1415 |
| 1319 glDeleteTextures(2, textures_); | 1416 glDeleteTextures(2, textures_); |
| 1320 glDeleteFramebuffers(1, &framebuffer_id_); | 1417 glDeleteFramebuffers(1, &framebuffer_id_); |
| 1321 } | 1418 } |
| 1322 } | 1419 } |
| 1323 } | 1420 } |
| 1324 | 1421 |
| 1325 } // namespace gpu | 1422 } // namespace gpu |
| OLD | NEW |