Commit d4f180b2 by Geoff Lang Committed by Geoff Lang

Validate compressed texture dimensions based on the per-format compressed block…

Validate compressed texture dimensions based on the per-format compressed block sizes rather than hard-coded values. TRAC #23630 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods
parent ce635695
......@@ -62,6 +62,25 @@ bool ValidImageSize(const gl::Context *context, GLenum target, GLint level, GLsi
return true;
}
bool ValidCompressedImageSize(const gl::Context *context, GLint internalFormat, GLsizei width, GLsizei height)
{
GLuint clientVersion = context->getClientVersion();
if (!IsFormatCompressed(internalFormat, clientVersion))
{
return false;
}
GLint blockWidth = GetCompressedBlockWidth(internalFormat, clientVersion);
GLint blockHeight = GetCompressedBlockHeight(internalFormat, clientVersion);
if (width < 0 || (width > blockWidth && width % blockWidth != 0) ||
height < 0 || (height > blockHeight && height % blockHeight != 0))
{
return false;
}
return true;
}
bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
GLenum internalformat, GLsizei width, GLsizei height,
bool angleExtension)
......
......@@ -16,6 +16,7 @@ class Context;
bool ValidMipLevel(const gl::Context *context, GLenum target, GLint level);
bool ValidImageSize(const gl::Context *context, GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth);
bool ValidCompressedImageSize(const gl::Context *context, GLint internalFormat, GLsizei width, GLsizei height);
bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
GLenum internalformat, GLsizei width, GLsizei height,
......
......@@ -22,21 +22,6 @@
namespace gl
{
static bool validCompressedImageSize(GLsizei width, GLsizei height)
{
if (width != 1 && width != 2 && width % 4 != 0)
{
return false;
}
if (height != 1 && height != 2 && height % 4 != 0)
{
return false;
}
return true;
}
static bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
gl::Texture2D *texture)
......@@ -128,11 +113,6 @@ bool ValidateES2TexImageParameters(gl::Context *context, GLenum target, GLint le
return gl::error(GL_INVALID_VALUE, false);
}
if (isCompressed && !validCompressedImageSize(width, height))
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (level < 0 || xoffset < 0 ||
std::numeric_limits<GLsizei>::max() - xoffset < width ||
std::numeric_limits<GLsizei>::max() - yoffset < height)
......@@ -239,6 +219,11 @@ bool ValidateES2TexImageParameters(gl::Context *context, GLenum target, GLint le
GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
if (isCompressed)
{
if (!ValidCompressedImageSize(context, actualInternalFormat, width, height))
{
return gl::error(GL_INVALID_OPERATION, false);
}
switch (actualInternalFormat)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
......
......@@ -21,21 +21,6 @@
namespace gl
{
static bool validCompressedImageSize(GLsizei width, GLsizei height)
{
if (width != 1 && width != 2 && width % 4 != 0)
{
return false;
}
if (height != 1 && height != 2 && height % 4 != 0)
{
return false;
}
return true;
}
bool ValidateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint border, GLenum format, GLenum type, const GLvoid *pixels)
......@@ -46,11 +31,6 @@ bool ValidateES3TexImageParameters(gl::Context *context, GLenum target, GLint le
return gl::error(GL_INVALID_VALUE, false);
}
if (isCompressed && !validCompressedImageSize(width, height))
{
return gl::error(GL_INVALID_OPERATION, false);
}
// Verify zero border
if (border != 0)
{
......@@ -178,6 +158,11 @@ bool ValidateES3TexImageParameters(gl::Context *context, GLenum target, GLint le
GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
if (isCompressed)
{
if (!ValidCompressedImageSize(context, actualInternalFormat, width, height))
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (!gl::IsFormatCompressed(actualInternalFormat, context->getClientVersion()))
{
return gl::error(GL_INVALID_ENUM, false);
......
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