diff --git a/include/platform/FeaturesGL.h b/include/platform/FeaturesGL.h index b3c760e60..0c0c70ecc 100644 --- a/include/platform/FeaturesGL.h +++ b/include/platform/FeaturesGL.h @@ -338,6 +338,12 @@ struct FeaturesGL : FeatureSetBase "clip_src_region_for_blitframebuffer", FeatureCategory::OpenGLWorkarounds, "Mac has issues with blitFramebuffer when the parameters don't match the framebuffer size.", &members, "http://crbug.com/830046"}; + + // Calling glTexImage2D with zero size on a rectangle texture generates GL errors + Feature resettingRectangleTexturesGeneratesErrors = { + "reset_rectangle_texture_generates_errors", FeatureCategory::OpenGLWorkarounds, + "Calling glTexImage2D with zero size on a rectangle texture generates errors.", &members, + "http://anglebug.com/3859"}; }; inline FeaturesGL::FeaturesGL() = default; diff --git a/src/libANGLE/renderer/gl/TextureGL.cpp b/src/libANGLE/renderer/gl/TextureGL.cpp index ffa4c6c05..eab9e5df3 100644 --- a/src/libANGLE/renderer/gl/TextureGL.cpp +++ b/src/libANGLE/renderer/gl/TextureGL.cpp @@ -1191,16 +1191,22 @@ angle::Result TextureGL::bindTexImage(const gl::Context *context, egl::Surface * angle::Result TextureGL::releaseTexImage(const gl::Context *context) { - // Not all Surface implementations reset the size of mip 0 when releasing, do it manually ASSERT(getType() == gl::TextureType::_2D || getType() == gl::TextureType::Rectangle); - const FunctionsGL *functions = GetFunctionsGL(context); - StateManagerGL *stateManager = GetStateManagerGL(context); + const angle::FeaturesGL &features = GetFeaturesGL(context); + if (getType() != gl::TextureType::Rectangle && + !features.resettingRectangleTexturesGeneratesErrors.enabled) + { + // Not all Surface implementations reset the size of mip 0 when releasing, do it manually + const FunctionsGL *functions = GetFunctionsGL(context); + StateManagerGL *stateManager = GetStateManagerGL(context); + + stateManager->bindTexture(getType(), mTextureID); + ASSERT(nativegl::UseTexImage2D(getType())); + functions->texImage2D(ToGLenum(getType()), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, + nullptr); + } - stateManager->bindTexture(getType(), mTextureID); - ASSERT(nativegl::UseTexImage2D(getType())); - functions->texImage2D(ToGLenum(getType()), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, - nullptr); return angle::Result::Continue; } diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp index 32f3a417a..8dd99c551 100644 --- a/src/libANGLE/renderer/gl/renderergl_utils.cpp +++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp @@ -1545,6 +1545,8 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature IsLinux() || (IsAndroid() && IsNvidia(vendor)) || (IsWindows() && IsNvidia(vendor)); features->clipSrcRegionBlitFramebuffer.enabled = IsApple(); + + features->resettingRectangleTexturesGeneratesErrors.enabled = IsApple(); } void InitializeFrontendFeatures(const FunctionsGL *functions, angle::FrontendFeatures *features)