Commit 03589986 by Nicolas Capens Committed by Nicolas Capens

Refactor compressed texture format validation.

We were generating GL_INVALID_OPERATION when a non-compressed format is used where a compressed one is expected or a compressed one is used where a non-compressed one is expected. Instead we can generate GL_INVALID_ENUM since these enums are never valid for these calls (GL_INVALID_OPERATION is for when the enum is valid in some situations but it's currently used incorrectly). Change-Id: I9ee92a92cda0574284e709a5a745d5bb8b825a31 Reviewed-on: https://swiftshader-review.googlesource.com/16888Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 17e2e2f2
......@@ -56,10 +56,9 @@ static bool validImageSize(GLint level, GLsizei width, GLsizei height)
static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFormat)
{
GLenum validationError = ValidateCompressedFormat(textureFormat, egl::getClientVersion(), false);
if(validationError != GL_NONE)
if(IsCompressed(textureFormat, egl::getClientVersion()))
{
return error(validationError, false);
return error(GL_INVALID_OPERATION, false);
}
// [OpenGL ES 2.0.24] table 3.9
......@@ -803,23 +802,9 @@ void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLs
return error(GL_INVALID_VALUE);
}
switch(internalformat)
if(!IsCompressed(internalformat, egl::getClientVersion()))
{
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32_OES:
case GL_DEPTH_STENCIL_OES:
case GL_DEPTH24_STENCIL8_OES:
return error(GL_INVALID_OPERATION);
default:
{
GLenum validationError = ValidateCompressedFormat(internalformat, egl::getClientVersion(), true);
if(validationError != GL_NONE)
{
return error(validationError);
}
}
break;
return error(GL_INVALID_ENUM);
}
if(border != 0)
......@@ -5042,13 +5027,7 @@ void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width,
}
}
GLenum validationError = ValidateCompressedFormat(format, clientVersion, false);
if(validationError != GL_NONE)
{
return error(validationError);
}
validationError = ValidateTextureFormatType(format, type, internalformat, context->getClientVersion());
GLenum validationError = ValidateTextureFormatType(format, type, internalformat, context->getClientVersion());
if(validationError != GL_NONE)
{
return error(validationError);
......@@ -6466,22 +6445,9 @@ void CompressedTexImage3DOES(GLenum target, GLint level, GLenum internalformat,
return error(GL_INVALID_VALUE);
}
switch(internalformat)
if(!IsCompressed(internalformat, egl::getClientVersion()))
{
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32_OES:
case GL_DEPTH_STENCIL_OES:
case GL_DEPTH24_STENCIL8_OES:
return error(GL_INVALID_OPERATION);
default:
{
GLenum validationError = ValidateCompressedFormat(internalformat, egl::getClientVersion(), true);
if(validationError != GL_NONE)
{
return error(validationError);
}
}
return error(GL_INVALID_ENUM);
}
if(imageSize != egl::ComputeCompressedSize(width, height, internalformat) * depth)
......@@ -6536,10 +6502,9 @@ void CompressedTexSubImage3DOES(GLenum target, GLint level, GLint xoffset, GLint
return error(GL_INVALID_VALUE);
}
GLenum validationError = ValidateCompressedFormat(format, egl::getClientVersion(), true);
if(validationError != GL_NONE)
if(!IsCompressed(format, egl::getClientVersion()))
{
return error(validationError);
return error(GL_INVALID_ENUM);
}
if(imageSize != egl::ComputeCompressedSize(width, height, format) * depth)
......
......@@ -55,10 +55,9 @@ static bool validImageSize(GLint level, GLsizei width, GLsizei height)
static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFormat)
{
GLenum validationError = ValidateCompressedFormat(textureFormat, egl::getClientVersion(), false);
if(validationError != GL_NONE)
if(IsCompressed(textureFormat, egl::getClientVersion()))
{
return error(validationError, false);
return error(GL_INVALID_OPERATION, false);
}
switch(textureFormat)
......@@ -834,22 +833,9 @@ GL_APICALL void GL_APIENTRY glCompressedTexImage3D(GLenum target, GLint level, G
return error(GL_INVALID_VALUE);
}
switch(internalformat)
if(!IsCompressed(internalformat, egl::getClientVersion()))
{
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32_OES:
case GL_DEPTH_STENCIL:
case GL_DEPTH24_STENCIL8:
return error(GL_INVALID_OPERATION);
default:
{
GLenum validationError = ValidateCompressedFormat(internalformat, egl::getClientVersion(), true);
if(validationError != GL_NONE)
{
return error(validationError);
}
}
return error(GL_INVALID_ENUM);
}
if(imageSize != egl::ComputeCompressedSize(width, height, internalformat) * depth)
......@@ -904,10 +890,9 @@ GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D(GLenum target, GLint level
return error(GL_INVALID_VALUE);
}
GLenum validationError = ValidateCompressedFormat(format, egl::getClientVersion(), true);
if(validationError != GL_NONE)
if(!IsCompressed(format, egl::getClientVersion()))
{
return error(validationError);
return error(GL_INVALID_ENUM);
}
if(imageSize != egl::ComputeCompressedSize(width, height, format) * depth)
......
......@@ -469,20 +469,14 @@ namespace es2
bool IsCompressed(GLenum format, GLint clientVersion)
{
return ValidateCompressedFormat(format, clientVersion, true) == GL_NONE;
}
GLenum ValidateCompressedFormat(GLenum format, GLint clientVersion, bool expectCompressedFormats)
{
switch(format)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
return expectCompressedFormats ? GL_NONE : GL_INVALID_OPERATION;
case GL_ETC1_RGB8_OES:
return expectCompressedFormats ? GL_NONE : GL_INVALID_OPERATION;
return true;
case GL_COMPRESSED_R11_EAC:
case GL_COMPRESSED_SIGNED_R11_EAC:
case GL_COMPRESSED_RG11_EAC:
......@@ -493,7 +487,7 @@ namespace es2
case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
case GL_COMPRESSED_RGBA8_ETC2_EAC:
case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
return (clientVersion >= 3) ? (expectCompressedFormats ? GL_NONE : GL_INVALID_OPERATION) : GL_INVALID_ENUM;
return (clientVersion >= 3);
case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
......@@ -522,13 +516,9 @@ namespace es2
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
#if(ASTC_SUPPORT)
return ((clientVersion >= 3) && ()) ? (expectCompressedFormats ? GL_NONE : GL_INVALID_OPERATION) : GL_INVALID_ENUM;
#else
return GL_INVALID_ENUM;
#endif
return ASTC_SUPPORT && (clientVersion >= 3);
default:
return expectCompressedFormats ? GL_INVALID_ENUM : GL_NONE; // Not compressed format
return false;
}
}
......
......@@ -44,7 +44,6 @@ namespace es2
bool IsCompressed(GLenum format, GLint clientVersion);
GLint GetSizedInternalFormat(GLint internalFormat, GLenum type);
GLenum ValidateCompressedFormat(GLenum format, GLint clientVersion, bool expectCompressedFormats);
GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height, GLenum format, GLenum type, Texture *texture, GLint clientVersion);
GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment