Commit f15fd5a1 by Nicolas Capens Committed by Nicolas Capens

Validate unsized internal formats.

If the format and internalformat parameters are the same, only the combinations in Table 3.3 of the OpenGL ES 3.0 specification are valid. GL_RGB10_A2 and GL_RGB10_A2UI have GL_UNSIGNED_INT_2_10_10_10_REV type. GL_OES_vertex_type_10_10_10_2 is a vertex attribute type, part of the GL_OES_vertex_type_10_10_10_2 extension. GL_RGB10_A2 internal format is valid for glReadPixels with a combination of format GL_RGBA and type GL_UNSIGNED_INT_2_10_10_10_REV. Change-Id: I590b43fcf9f1dc4beee9a64b45fe94fd74388b7a Reviewed-on: https://swiftshader-review.googlesource.com/14788Tested-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 3be576c0
...@@ -598,7 +598,7 @@ GLenum Framebuffer::getImplementationColorReadType() const ...@@ -598,7 +598,7 @@ GLenum Framebuffer::getImplementationColorReadType() const
case GL_R16UI: return GL_UNSIGNED_INT; case GL_R16UI: return GL_UNSIGNED_INT;
case GL_RG16UI: return GL_UNSIGNED_INT; case GL_RG16UI: return GL_UNSIGNED_INT;
case GL_RGB16UI: return GL_UNSIGNED_INT; case GL_RGB16UI: return GL_UNSIGNED_INT;
case GL_RGB10_A2UI: return GL_UNSIGNED_INT_10_10_10_2_OES; case GL_RGB10_A2UI: return GL_UNSIGNED_INT_2_10_10_10_REV;
case GL_RGBA16UI: return GL_UNSIGNED_INT; case GL_RGBA16UI: return GL_UNSIGNED_INT;
case GL_R32I: return GL_INT; case GL_R32I: return GL_INT;
case GL_RG32I: return GL_INT; case GL_RG32I: return GL_INT;
...@@ -617,7 +617,7 @@ GLenum Framebuffer::getImplementationColorReadType() const ...@@ -617,7 +617,7 @@ GLenum Framebuffer::getImplementationColorReadType() const
case GL_RG32F: return GL_FLOAT; case GL_RG32F: return GL_FLOAT;
case GL_RGB32F: return GL_FLOAT; case GL_RGB32F: return GL_FLOAT;
case GL_RGBA32F: return GL_FLOAT; case GL_RGBA32F: return GL_FLOAT;
case GL_RGB10_A2: return GL_UNSIGNED_INT_10_10_10_2_OES; case GL_RGB10_A2: return GL_UNSIGNED_INT_2_10_10_10_REV;
case GL_SRGB8: return GL_UNSIGNED_BYTE; case GL_SRGB8: return GL_UNSIGNED_BYTE;
case GL_SRGB8_ALPHA8: return GL_UNSIGNED_BYTE; case GL_SRGB8_ALPHA8: return GL_UNSIGNED_BYTE;
default: default:
......
...@@ -716,7 +716,7 @@ namespace es2 ...@@ -716,7 +716,7 @@ namespace es2
} }
// Additional third combination accepted by OpenGL ES 3.0. // Additional third combination accepted by OpenGL ES 3.0.
if(internalformat == sw::FORMAT_A2B10G10R10) if(internalformat == GL_RGB10_A2)
{ {
ASSERT(clientVersion >= 3); ASSERT(clientVersion >= 3);
...@@ -922,6 +922,94 @@ namespace es2 ...@@ -922,6 +922,94 @@ namespace es2
} }
} }
if((GLenum)internalformat == format)
{
// Validate format, type, and unsized internalformat combinations [OpenGL ES 3.0 Table 3.3]
switch(format)
{
case GL_RGBA:
switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_FLOAT: // GL_OES_texture_float
case GL_HALF_FLOAT_OES: // GL_OES_texture_half_float
break;
default:
return GL_INVALID_OPERATION;
}
break;
case GL_RGB:
switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_FLOAT: // GL_OES_texture_float
case GL_HALF_FLOAT_OES: // GL_OES_texture_half_float
break;
default:
return GL_INVALID_OPERATION;
}
break;
case GL_LUMINANCE_ALPHA:
case GL_LUMINANCE:
case GL_ALPHA:
switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_FLOAT: // GL_OES_texture_float
case GL_HALF_FLOAT_OES: // GL_OES_texture_half_float
break;
default:
return GL_INVALID_OPERATION;
}
break;
case GL_DEPTH_COMPONENT:
switch(type)
{
case GL_UNSIGNED_SHORT: // GL_OES_depth_texture
case GL_UNSIGNED_INT: // GL_OES_depth_texture
break;
default:
return GL_INVALID_OPERATION;
}
break;
case GL_DEPTH_STENCIL_OES:
switch(type)
{
case GL_UNSIGNED_INT_24_8_OES: // GL_OES_packed_depth_stencil
break;
default:
return GL_INVALID_OPERATION;
}
break;
case GL_RED_EXT:
case GL_RG_EXT:
switch(type)
{
case GL_UNSIGNED_BYTE: // GL_EXT_texture_rg
case GL_FLOAT: // GL_EXT_texture_rg + GL_OES_texture_float
case GL_HALF_FLOAT_OES: // GL_EXT_texture_rg + GL_OES_texture_half_float
break;
default:
return GL_INVALID_OPERATION;
}
break;
// case GL_BGRA_EXT:
// if(type != GL_UNSIGNED_BYTE) // GL_APPLE_texture_format_BGRA8888
// {
// return GL_INVALID_OPERATION;
// }
// break;
default:
UNREACHABLE(format);
return GL_INVALID_ENUM;
}
return GL_NONE;
}
// Validate format, type, and sized internalformat combinations [OpenGL ES 3.0 Table 3.2] // Validate format, type, and sized internalformat combinations [OpenGL ES 3.0 Table 3.2]
bool validSizedInternalformat = false; bool validSizedInternalformat = false;
#define VALIDATE_INTERNALFORMAT(...) { GLint validInternalformats[] = {__VA_ARGS__}; for(GLint v : validInternalformats) {if(internalformat == v) validSizedInternalformat = true;} } break; #define VALIDATE_INTERNALFORMAT(...) { GLint validInternalformats[] = {__VA_ARGS__}; for(GLint v : validInternalformats) {if(internalformat == v) validSizedInternalformat = true;} } break;
...@@ -1090,7 +1178,7 @@ namespace es2 ...@@ -1090,7 +1178,7 @@ namespace es2
#undef VALIDATE_INTERNALFORMAT #undef VALIDATE_INTERNALFORMAT
if((GLenum)internalformat != format && !validSizedInternalformat) if(!validSizedInternalformat)
{ {
return GL_INVALID_OPERATION; return GL_INVALID_OPERATION;
} }
......
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