1 //
2 // Copyright 2018 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 // AlphaFuncTest.cpp: Tests basic usage of glAlphaFunc.
8
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11
12 #include "util/random_utils.h"
13
14 #include <stdint.h>
15
16 using namespace angle;
17
18 class AlphaFuncTest : public ANGLETest
19 {
20 protected:
AlphaFuncTest()21 AlphaFuncTest()
22 {
23 setWindowWidth(32);
24 setWindowHeight(32);
25 setConfigRedBits(8);
26 setConfigGreenBits(8);
27 setConfigBlueBits(8);
28 setConfigAlphaBits(8);
29 setConfigDepthBits(24);
30 }
31 };
32
33 // Checks that disable / enable works as expected.
TEST_P(AlphaFuncTest,EnableDisable)34 TEST_P(AlphaFuncTest, EnableDisable)
35 {
36 EXPECT_GL_FALSE(glIsEnabled(GL_ALPHA_TEST));
37 EXPECT_GL_NO_ERROR();
38
39 glEnable(GL_ALPHA_TEST);
40 EXPECT_GL_NO_ERROR();
41
42 EXPECT_GL_TRUE(glIsEnabled(GL_ALPHA_TEST));
43 EXPECT_GL_NO_ERROR();
44
45 glDisable(GL_ALPHA_TEST);
46 EXPECT_GL_NO_ERROR();
47
48 EXPECT_GL_FALSE(glIsEnabled(GL_ALPHA_TEST));
49 EXPECT_GL_NO_ERROR();
50 }
51
52 // Negative test: Checks that invalid enums for alpha test function generate the proper GL error.
TEST_P(AlphaFuncTest,SetFuncNegative)53 TEST_P(AlphaFuncTest, SetFuncNegative)
54 {
55 glAlphaFunc((GLenum)0, 0.0f);
56 EXPECT_GL_ERROR(GL_INVALID_ENUM);
57
58 glAlphaFunc((GLenum)1, 0.0f);
59 EXPECT_GL_ERROR(GL_INVALID_ENUM);
60
61 glAlphaFunc((GLenum)GL_ALPHA, 0.0f);
62 EXPECT_GL_ERROR(GL_INVALID_ENUM);
63 }
64
65 // Query test: Checks that the alpha test ref value can be obtained with glGetFloatv.
TEST_P(AlphaFuncTest,SetFuncGetFloat)66 TEST_P(AlphaFuncTest, SetFuncGetFloat)
67 {
68 GLfloat alphaTestVal = -1.0f;
69 glAlphaFunc(GL_ALWAYS, 0.0f);
70 glGetFloatv(GL_ALPHA_TEST_REF, &alphaTestVal);
71 EXPECT_GL_NO_ERROR();
72 EXPECT_EQ(0.0f, alphaTestVal);
73
74 glAlphaFunc(GL_ALWAYS, 0.4f);
75 glGetFloatv(GL_ALPHA_TEST_REF, &alphaTestVal);
76 EXPECT_GL_NO_ERROR();
77 EXPECT_EQ(0.4f, alphaTestVal);
78 }
79
80 // Query test: Checks that the alpha test ref value can be obtained with glGetIntegerv,
81 // with proper scaling.
TEST_P(AlphaFuncTest,SetFuncGetInt)82 TEST_P(AlphaFuncTest, SetFuncGetInt)
83 {
84 GLint alphaTestVal = -1;
85 glAlphaFunc(GL_ALWAYS, 0.0f);
86 glGetIntegerv(GL_ALPHA_TEST_REF, &alphaTestVal);
87 EXPECT_GL_NO_ERROR();
88 EXPECT_EQ(0, alphaTestVal);
89
90 glAlphaFunc(GL_ALWAYS, 1.0f);
91 glGetIntegerv(GL_ALPHA_TEST_REF, &alphaTestVal);
92 EXPECT_GL_NO_ERROR();
93 EXPECT_EQ(std::numeric_limits<GLint>::max(), alphaTestVal);
94 }
95
96 ANGLE_INSTANTIATE_TEST_ES1(AlphaFuncTest);
97