• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2017 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // SamplerTest.cpp : Tests for samplers.
8 
9 #include "test_utils/ANGLETest.h"
10 
11 #include "test_utils/gl_raii.h"
12 
13 namespace angle
14 {
15 
16 class SamplersTest : public ANGLETest
17 {
18   protected:
SamplersTest()19     SamplersTest() {}
20 
21     // Sets a value for GL_TEXTURE_MAX_ANISOTROPY_EXT and expects it to fail.
validateInvalidAnisotropy(GLSampler & sampler,float invalidValue)22     void validateInvalidAnisotropy(GLSampler &sampler, float invalidValue)
23     {
24         glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, invalidValue);
25         EXPECT_GL_ERROR(GL_INVALID_VALUE);
26     }
27 
28     // Sets a value for GL_TEXTURE_MAX_ANISOTROPY_EXT and expects it to work.
validateValidAnisotropy(GLSampler & sampler,float validValue)29     void validateValidAnisotropy(GLSampler &sampler, float validValue)
30     {
31         glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, validValue);
32         EXPECT_GL_NO_ERROR();
33 
34         GLfloat valueToVerify = 0.0f;
35         glGetSamplerParameterfv(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, &valueToVerify);
36         ASSERT_EQ(valueToVerify, validValue);
37     }
38 };
39 
40 // Verify that samplerParameterf supports TEXTURE_MAX_ANISOTROPY_EXT valid values.
TEST_P(SamplersTest,ValidTextureSamplerMaxAnisotropyExt)41 TEST_P(SamplersTest, ValidTextureSamplerMaxAnisotropyExt)
42 {
43     // http://anglebug.com/4092
44     ANGLE_SKIP_TEST_IF(isSwiftshader());
45     GLSampler sampler;
46 
47     // Exact min
48     validateValidAnisotropy(sampler, 1.0f);
49 
50     GLfloat maxValue = 0.0f;
51     glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxValue);
52 
53     // Max value
54     validateValidAnisotropy(sampler, maxValue - 1);
55 
56     // In-between
57     GLfloat between = (1.0f + maxValue) / 2;
58     validateValidAnisotropy(sampler, between);
59 }
60 
61 // Verify an error is thrown if we try to go under the minimum value for
62 // GL_TEXTURE_MAX_ANISOTROPY_EXT
TEST_P(SamplersTest,InvalidUnderTextureSamplerMaxAnisotropyExt)63 TEST_P(SamplersTest, InvalidUnderTextureSamplerMaxAnisotropyExt)
64 {
65     // http://anglebug.com/4092
66     ANGLE_SKIP_TEST_IF(isSwiftshader());
67     GLSampler sampler;
68 
69     // Under min
70     validateInvalidAnisotropy(sampler, 0.0f);
71 }
72 
73 // Verify an error is thrown if we try to go over the max value for
74 // GL_TEXTURE_MAX_ANISOTROPY_EXT
TEST_P(SamplersTest,InvalidOverTextureSamplerMaxAnisotropyExt)75 TEST_P(SamplersTest, InvalidOverTextureSamplerMaxAnisotropyExt)
76 {
77     // http://anglebug.com/4092
78     ANGLE_SKIP_TEST_IF(isSwiftshader());
79     GLSampler sampler;
80 
81     GLfloat maxValue = 0.0f;
82     glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxValue);
83     maxValue += 1;
84 
85     validateInvalidAnisotropy(sampler, maxValue);
86 }
87 
88 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
89 // tests should be run against.
90 // Samplers are only supported on ES3.
91 ANGLE_INSTANTIATE_TEST_ES3(SamplersTest);
92 }  // namespace angle
93