Commit 1b1a8640 by Luc Ferron Committed by Commit Bot

Support correct validation for samplerParameterf with GL_TEXTURE_MAX_ANISOTROPY_EXT

Bug: angleproject:2072 Change-Id: I3e0b63f2a63e8769e3eab2be3aa0403317ed0707 Reviewed-on: https://chromium-review.googlesource.com/881707Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Luc Ferron <lucferron@google.com>
parent 112a3a8e
...@@ -391,6 +391,35 @@ bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) ...@@ -391,6 +391,35 @@ bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params)
return true; return true;
} }
bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context)
{
if (!context->getExtensions().textureFilterAnisotropic)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled);
return false;
}
return true;
}
bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue)
{
if (!ValidateTextureMaxAnisotropyExtensionEnabled(context))
{
return false;
}
GLfloat largest = context->getExtensions().maxTextureAnisotropy;
if (paramValue < 1 || paramValue > largest)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds);
return false;
}
return true;
}
bool ValidateFragmentShaderColorBufferTypeMatch(ValidationContext *context) bool ValidateFragmentShaderColorBufferTypeMatch(ValidationContext *context)
{ {
const Program *program = context->getGLState().getProgram(); const Program *program = context->getGLState().getProgram();
...@@ -4890,9 +4919,8 @@ bool ValidateGetTexParameterBase(Context *context, GLenum target, GLenum pname, ...@@ -4890,9 +4919,8 @@ bool ValidateGetTexParameterBase(Context *context, GLenum target, GLenum pname,
break; break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT: case GL_TEXTURE_MAX_ANISOTROPY_EXT:
if (!context->getExtensions().textureFilterAnisotropic) if (!ValidateTextureMaxAnisotropyExtensionEnabled(context))
{ {
ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled);
return false; return false;
} }
break; break;
...@@ -5378,17 +5406,13 @@ bool ValidateTexParameterBase(Context *context, ...@@ -5378,17 +5406,13 @@ bool ValidateTexParameterBase(Context *context,
break; break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT: case GL_TEXTURE_MAX_ANISOTROPY_EXT:
if (!context->getExtensions().textureFilterAnisotropic)
{ {
context->handleError(InvalidEnum() << "GL_EXT_texture_anisotropic is not enabled."); GLfloat paramValue = static_cast<GLfloat>(params[0]);
return false; if (!ValidateTextureMaxAnisotropyValue(context, paramValue))
} {
return false;
// we assume the parameter passed to this validation method is truncated, not rounded }
if (params[0] < 1) ASSERT(static_cast<ParamType>(paramValue) == params[0]);
{
context->handleError(InvalidValue() << "Max anisotropy must be at least 1.");
return false;
} }
break; break;
...@@ -5652,6 +5676,16 @@ bool ValidateSamplerParameterBase(Context *context, ...@@ -5652,6 +5676,16 @@ bool ValidateSamplerParameterBase(Context *context,
} }
break; break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
{
GLfloat paramValue = static_cast<GLfloat>(params[0]);
if (!ValidateTextureMaxAnisotropyValue(context, paramValue))
{
return false;
}
}
break;
default: default:
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
return false; return false;
...@@ -5698,6 +5732,13 @@ bool ValidateGetSamplerParameterBase(Context *context, ...@@ -5698,6 +5732,13 @@ bool ValidateGetSamplerParameterBase(Context *context,
case GL_TEXTURE_COMPARE_FUNC: case GL_TEXTURE_COMPARE_FUNC:
break; break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
if (!ValidateTextureMaxAnisotropyExtensionEnabled(context))
{
return false;
}
break;
case GL_TEXTURE_SRGB_DECODE_EXT: case GL_TEXTURE_SRGB_DECODE_EXT:
if (!context->getExtensions().textureSRGBDecode) if (!context->getExtensions().textureSRGBDecode)
{ {
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
'<(angle_path)/src/tests/gl_tests/RobustBufferAccessBehaviorTest.cpp', '<(angle_path)/src/tests/gl_tests/RobustBufferAccessBehaviorTest.cpp',
'<(angle_path)/src/tests/gl_tests/RobustClientMemoryTest.cpp', '<(angle_path)/src/tests/gl_tests/RobustClientMemoryTest.cpp',
'<(angle_path)/src/tests/gl_tests/RobustResourceInitTest.cpp', '<(angle_path)/src/tests/gl_tests/RobustResourceInitTest.cpp',
'<(angle_path)/src/tests/gl_tests/SamplersTest.cpp',
'<(angle_path)/src/tests/gl_tests/ShaderStorageBufferTest.cpp', '<(angle_path)/src/tests/gl_tests/ShaderStorageBufferTest.cpp',
'<(angle_path)/src/tests/gl_tests/SimpleOperationTest.cpp', '<(angle_path)/src/tests/gl_tests/SimpleOperationTest.cpp',
'<(angle_path)/src/tests/gl_tests/SixteenBppTextureTest.cpp', '<(angle_path)/src/tests/gl_tests/SixteenBppTextureTest.cpp',
......
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SamplerTest.cpp : Tests for samplers.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
namespace angle
{
class SamplersTest : public ANGLETest
{
protected:
SamplersTest() {}
// Sets a value for GL_TEXTURE_MAX_ANISOTROPY_EXT and expects it to fail.
void validateInvalidAnisotropy(GLSampler &sampler, float invalidValue)
{
glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, invalidValue);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
// Sets a value for GL_TEXTURE_MAX_ANISOTROPY_EXT and expects it to work.
void validateValidAnisotropy(GLSampler &sampler, float validValue)
{
glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, validValue);
EXPECT_GL_NO_ERROR();
GLfloat valueToVerify = 0.0f;
glGetSamplerParameterfv(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, &valueToVerify);
ASSERT_EQ(valueToVerify, validValue);
}
};
// Verify that samplerParameterf supports TEXTURE_MAX_ANISOTROPY_EXT valid values.
TEST_P(SamplersTest, ValidTextureSamplerMaxAnisotropyExt)
{
GLSampler sampler;
// Exact min
validateValidAnisotropy(sampler, 1.0f);
GLfloat maxValue = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxValue);
// Max value
validateValidAnisotropy(sampler, maxValue - 1);
// In-between
GLfloat between = (1.0f + maxValue) / 2;
validateValidAnisotropy(sampler, between);
}
// Verify an error is thrown if we try to go under the minimum value for
// GL_TEXTURE_MAX_ANISOTROPY_EXT
TEST_P(SamplersTest, InvalidUnderTextureSamplerMaxAnisotropyExt)
{
GLSampler sampler;
// Under min
validateInvalidAnisotropy(sampler, 0.0f);
}
// Verify an error is thrown if we try to go over the max value for
// GL_TEXTURE_MAX_ANISOTROPY_EXT
TEST_P(SamplersTest, InvalidOverTextureSamplerMaxAnisotropyExt)
{
GLSampler sampler;
GLfloat maxValue = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxValue);
maxValue += 1;
validateInvalidAnisotropy(sampler, maxValue);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
// Samplers are only supported on ES3.
ANGLE_INSTANTIATE_TEST(SamplersTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
} // namespace
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