Commit fb7685f4 by Geoff Lang Committed by Commit Bot

Validate texture parameters for >0 after rounding.

From the spec (2.3.1 Data Conversion For State-Setting Commands): "Validation of values performed by state-setting commands is performed after conversion, unless specified otherwise for a specific command." BUG=783574 Change-Id: I9edf585a17489ad284bc85a1c3c2236b53ee34d9 Reviewed-on: https://chromium-review.googlesource.com/766569Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 7caa80e7
...@@ -81,6 +81,12 @@ GLenum ConvertToGLenum(ParamType param) ...@@ -81,6 +81,12 @@ GLenum ConvertToGLenum(ParamType param)
return ConvertToGLenum(GL_NONE, param); return ConvertToGLenum(GL_NONE, param);
} }
template <typename ParamType>
GLenum ConvertToGLint(ParamType param)
{
return CastQueryValueTo<GLint>(GL_NONE, param);
}
// The GL state query API types are: bool, int, uint, float, int64, uint64 // The GL state query API types are: bool, int, uint, float, int64, uint64
template <typename QueryT> template <typename QueryT>
void CastStateValues(Context *context, GLenum nativeType, GLenum pname, void CastStateValues(Context *context, GLenum nativeType, GLenum pname,
......
...@@ -5505,7 +5505,7 @@ bool ValidateTexParameterBase(Context *context, ...@@ -5505,7 +5505,7 @@ bool ValidateTexParameterBase(Context *context,
break; break;
case GL_TEXTURE_BASE_LEVEL: case GL_TEXTURE_BASE_LEVEL:
if (params[0] < 0) if (ConvertToGLint(params[0]) < 0)
{ {
context->handleError(InvalidValue() << "Base level must be at least 0."); context->handleError(InvalidValue() << "Base level must be at least 0.");
return false; return false;
...@@ -5531,7 +5531,7 @@ bool ValidateTexParameterBase(Context *context, ...@@ -5531,7 +5531,7 @@ bool ValidateTexParameterBase(Context *context,
break; break;
case GL_TEXTURE_MAX_LEVEL: case GL_TEXTURE_MAX_LEVEL:
if (params[0] < 0) if (ConvertToGLint(params[0]) < 0)
{ {
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel);
return false; return false;
......
...@@ -3662,6 +3662,25 @@ TEST_P(Texture2DTestES3, StaleUnpackData) ...@@ -3662,6 +3662,25 @@ TEST_P(Texture2DTestES3, StaleUnpackData)
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
} }
// Ensure that texture parameters passed as floats that are converted to ints are rounded before
// validating they are less than 0.
TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
{
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
// Use a negative number that will round to zero when converted to an integer
// According to the spec(2.3.1 Data Conversion For State - Setting Commands):
// "Validation of values performed by state-setting commands is performed after conversion,
// unless specified otherwise for a specific command."
GLfloat param = -7.30157126e-07f;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
EXPECT_GL_NO_ERROR();
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
EXPECT_GL_NO_ERROR();
}
// This test covers a D3D format redefinition bug for 3D textures. The base level format was not // This test covers a D3D format redefinition bug for 3D textures. The base level format was not
// being properly checked, and the texture storage of the previous texture format was persisting. // being properly checked, and the texture storage of the previous texture format was persisting.
// This would result in an ASSERT in debug and incorrect rendering in release. // This would result in an ASSERT in debug and incorrect rendering in release.
......
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