Simplify GenerateMipmap validation now that sized format info is tracked.
The previous validation used some workarounds because it didn't know if
the texture format was sized or not. Now that the InternalFormat struct
tracks this, the validation can work correctly for floating point
formats.
BUG=angleproject:2149
Change-Id: I583db4a36137a57dd1b7fc81cd4e3b6d5972fc67
Reviewed-on: https://chromium-review.googlesource.com/665163
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES2.cpp b/src/libANGLE/validationES2.cpp
index e7390fe..a254961 100644
--- a/src/libANGLE/validationES2.cpp
+++ b/src/libANGLE/validationES2.cpp
@@ -6059,37 +6059,40 @@
}
GLenum baseTarget = (target == GL_TEXTURE_CUBE_MAP) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target;
- const auto &format = texture->getFormat(baseTarget, effectiveBaseLevel);
- const TextureCaps &formatCaps = context->getTextureCaps().get(format.info->sizedInternalFormat);
-
- if (format.info->compressed)
+ const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info);
+ if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 ||
+ format.stencilBits > 0)
{
ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed);
return false;
}
- // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
- // unsized formats or that are color renderable and filterable. Since we do not track if
- // the texture was created with sized or unsized format (only sized formats are stored),
- // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
- // be able to) because they aren't color renderable. Simply do a special case for LUMA
- // textures since they're the only texture format that can be created with unsized formats
- // that is not color renderable. New unsized formats are unlikely to be added, since ES2
- // was the last version to use add them.
- if (format.info->depthBits > 0 || format.info->stencilBits > 0 || !formatCaps.filterable ||
- (!formatCaps.renderable && !format.info->isLUMA()))
+ // GenerateMipmap accepts formats that are unsized or both color renderable and filterable.
+ bool formatUnsized = !format.sized;
+ bool formatColorRenderableAndFilterable =
+ format.filterSupport(context->getClientVersion(), context->getExtensions()) &&
+ format.renderSupport(context->getClientVersion(), context->getExtensions());
+ if (!formatUnsized && !formatColorRenderableAndFilterable)
{
- context->handleError(InvalidOperation());
+ ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed);
return false;
}
- // ES3 and WebGL grant mipmap generation for sRGB textures but GL_EXT_sRGB does not.
+ // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap
+ // generation
+ if (format.colorEncoding == GL_SRGB && format.format == GL_RGB)
+ {
+ ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed);
+ return false;
+ }
+
+ // ES3 and WebGL grant mipmap generation for sRGBA (with alpha) textures but GL_EXT_sRGB does
+ // not.
bool supportsSRGBMipmapGeneration =
context->getClientVersion() >= ES_3_0 || context->getExtensions().webglCompatibility;
- if (!supportsSRGBMipmapGeneration && format.info->colorEncoding == GL_SRGB)
+ if (!supportsSRGBMipmapGeneration && format.colorEncoding == GL_SRGB)
{
- context->handleError(InvalidOperation()
- << "Mipmap generation of sRGB textures is not allowed.");
+ ANGLE_VALIDATION_ERR(context, InvalidOperation(), GenerateMipmapNotAllowed);
return false;
}