Commit 8f215a4b by Nicolas Capens Committed by Nicolas Capens

Refactor CopyTexImage format validation.

Deduplicate common functions and remove unsized color buffer formats. Change-Id: I76b3b507c27c8bfa932aab64a9338e2a124a25da Reviewed-on: https://swiftshader-review.googlesource.com/16289Tested-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 03589986
...@@ -54,69 +54,6 @@ static bool validImageSize(GLint level, GLsizei width, GLsizei height) ...@@ -54,69 +54,6 @@ static bool validImageSize(GLint level, GLsizei width, GLsizei height)
return true; return true;
} }
static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFormat)
{
if(IsCompressed(textureFormat, egl::getClientVersion()))
{
return error(GL_INVALID_OPERATION, false);
}
// [OpenGL ES 2.0.24] table 3.9
switch(textureFormat)
{
case GL_ALPHA:
if(colorbufferFormat != GL_ALPHA &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_OES &&
colorbufferFormat != GL_BGRA8_EXT &&
colorbufferFormat != GL_RGBA16F_EXT &&
colorbufferFormat != GL_RGBA32F_EXT)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_LUMINANCE:
case GL_RGB:
if(colorbufferFormat != GL_RGB &&
colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8_OES &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_OES &&
colorbufferFormat != GL_RGB16F_EXT &&
colorbufferFormat != GL_RGB32F_EXT &&
colorbufferFormat != GL_BGRA8_EXT &&
colorbufferFormat != GL_RGBA16F_EXT &&
colorbufferFormat != GL_RGBA32F_EXT)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
if(colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_OES &&
colorbufferFormat != GL_BGRA8_EXT &&
colorbufferFormat != GL_RGBA16F_EXT &&
colorbufferFormat != GL_RGBA32F_EXT)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_DEPTH_COMPONENT:
case GL_DEPTH_STENCIL_OES:
return error(GL_INVALID_OPERATION, false);
default:
return error(GL_INVALID_ENUM, false);
}
return true;
}
void ActiveTexture(GLenum texture) void ActiveTexture(GLenum texture)
{ {
TRACE("(GLenum texture = 0x%X)", texture); TRACE("(GLenum texture = 0x%X)", texture);
...@@ -1054,7 +991,7 @@ void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, ...@@ -1054,7 +991,7 @@ void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x,
GLenum colorbufferFormat = source->getFormat(); GLenum colorbufferFormat = source->getFormat();
if(!validateColorBufferFormat(internalformat, colorbufferFormat)) if(!ValidateCopyFormats(internalformat, colorbufferFormat))
{ {
return; return;
} }
......
...@@ -53,57 +53,6 @@ static bool validImageSize(GLint level, GLsizei width, GLsizei height) ...@@ -53,57 +53,6 @@ static bool validImageSize(GLint level, GLsizei width, GLsizei height)
return true; return true;
} }
static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFormat)
{
if(IsCompressed(textureFormat, egl::getClientVersion()))
{
return error(GL_INVALID_OPERATION, false);
}
switch(textureFormat)
{
case GL_ALPHA:
if(colorbufferFormat != GL_ALPHA &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_LUMINANCE:
case GL_RGB:
if(colorbufferFormat != GL_RGB &&
colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8 &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
if(colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_DEPTH_COMPONENT:
case GL_DEPTH_STENCIL:
return error(GL_INVALID_OPERATION, false);
default:
return error(GL_INVALID_ENUM, false);
}
return true;
}
static FormatMap BuildFormatMap3D() static FormatMap BuildFormatMap3D()
{ {
FormatMap map; FormatMap map;
...@@ -798,7 +747,7 @@ GL_APICALL void GL_APIENTRY glCopyTexSubImage3D(GLenum target, GLint level, GLin ...@@ -798,7 +747,7 @@ GL_APICALL void GL_APIENTRY glCopyTexSubImage3D(GLenum target, GLint level, GLin
GLenum textureFormat = texture->getFormat(target, level); GLenum textureFormat = texture->getFormat(target, level);
if(!validateColorBufferFormat(textureFormat, colorbufferFormat)) if(!ValidateCopyFormats(textureFormat, colorbufferFormat))
{ {
return; return;
} }
......
...@@ -610,6 +610,66 @@ namespace es2 ...@@ -610,6 +610,66 @@ namespace es2
return GL_NONE; return GL_NONE;
} }
bool ValidateCopyFormats(GLenum textureFormat, GLenum colorbufferFormat)
{
if(IsCompressed(textureFormat, egl::getClientVersion()))
{
return error(GL_INVALID_OPERATION, false);
}
// [OpenGL ES 2.0.24] table 3.9
// [OpenGL ES 3.0.5] table 3.16
switch(textureFormat)
{
case GL_ALPHA:
if(colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8 &&
colorbufferFormat != GL_BGRA8_EXT &&
colorbufferFormat != GL_RGBA16F_EXT &&
colorbufferFormat != GL_RGBA32F_EXT)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_LUMINANCE:
case GL_RGB:
if(colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8 &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8 &&
colorbufferFormat != GL_RGB16F_EXT &&
colorbufferFormat != GL_RGB32F_EXT &&
colorbufferFormat != GL_BGRA8_EXT &&
colorbufferFormat != GL_RGBA16F_EXT &&
colorbufferFormat != GL_RGBA32F_EXT)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
if(colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8 &&
colorbufferFormat != GL_BGRA8_EXT &&
colorbufferFormat != GL_RGBA16F_EXT &&
colorbufferFormat != GL_RGBA32F_EXT)
{
return error(GL_INVALID_OPERATION, false);
}
break;
case GL_DEPTH_COMPONENT:
case GL_DEPTH_STENCIL_OES:
return error(GL_INVALID_OPERATION, false);
default:
return error(GL_INVALID_ENUM, false);
}
return true;
}
bool IsValidReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type, GLint clientVersion) bool IsValidReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type, GLint clientVersion)
{ {
// GL_NV_read_depth // GL_NV_read_depth
......
...@@ -48,6 +48,7 @@ namespace es2 ...@@ -48,6 +48,7 @@ namespace es2
GLsizei width, GLsizei height, GLenum format, GLenum type, Texture *texture, GLint clientVersion); 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, GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, Texture *texture, GLint clientVersion); GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, Texture *texture, GLint clientVersion);
bool ValidateCopyFormats(GLenum textureFormat, GLenum colorbufferFormat);
bool IsValidReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type, GLint clientVersion); bool IsValidReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type, GLint clientVersion);
bool IsDepthTexture(GLenum format); bool IsDepthTexture(GLenum format);
bool IsStencilTexture(GLenum format); bool IsStencilTexture(GLenum format);
......
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