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 // PointParameterTest.cpp: Tests basic usage of GLES1 point parameters.
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 PointParameterTest : public ANGLETest<>
19 {
20 protected:
PointParameterTest()21 PointParameterTest()
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(PointParameterTest,InitialState)34 TEST_P(PointParameterTest, InitialState)
35 {
36 GLfloat params[3] = {};
37 glGetFloatv(GL_POINT_SIZE, params);
38 EXPECT_GL_NO_ERROR();
39 EXPECT_EQ(1.0f, params[0]);
40
41 EXPECT_GL_FALSE(glIsEnabled(GL_POINT_SMOOTH));
42 EXPECT_GL_NO_ERROR();
43
44 glGetFloatv(GL_POINT_SIZE_MIN, params);
45 EXPECT_GL_NO_ERROR();
46 EXPECT_EQ(0.0f, params[0]);
47
48 // The user-specified point size, GL_POINT_SIZE_MAX,
49 // is initially equal to the implementation maximum.
50 GLfloat range[2] = {};
51 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, range);
52 EXPECT_GL_NO_ERROR();
53
54 glGetFloatv(GL_POINT_SIZE_MAX, params);
55 EXPECT_GL_NO_ERROR();
56 EXPECT_EQ(range[1], params[0]);
57
58 glGetFloatv(GL_POINT_FADE_THRESHOLD_SIZE, params);
59 EXPECT_GL_NO_ERROR();
60 EXPECT_EQ(1.0f, params[0]);
61
62 glGetFloatv(GL_POINT_DISTANCE_ATTENUATION, params);
63 EXPECT_GL_NO_ERROR();
64 EXPECT_EQ(1.0f, params[0]);
65 EXPECT_EQ(0.0f, params[1]);
66 EXPECT_EQ(0.0f, params[2]);
67
68 EXPECT_GL_FALSE(glIsEnabled(GL_POINT_SPRITE_OES));
69 EXPECT_GL_NO_ERROR();
70 }
71
72 // Negative test for parameter names
TEST_P(PointParameterTest,NegativeEnum)73 TEST_P(PointParameterTest, NegativeEnum)
74 {
75 glPointParameterf(0, 0.0f);
76 EXPECT_GL_ERROR(GL_INVALID_ENUM);
77
78 glPointParameterfv(0, nullptr);
79 EXPECT_GL_ERROR(GL_INVALID_ENUM);
80
81 glPointParameterf(GL_POINT_DISTANCE_ATTENUATION, 0.0f);
82 EXPECT_GL_ERROR(GL_INVALID_ENUM);
83 }
84
85 // Negative test for parameter values
TEST_P(PointParameterTest,NegativeValue)86 TEST_P(PointParameterTest, NegativeValue)
87 {
88 glPointParameterf(GL_POINT_SIZE_MIN, -1.0f);
89 EXPECT_GL_ERROR(GL_INVALID_VALUE);
90
91 glPointParameterf(GL_POINT_SIZE_MAX, -1.0f);
92 EXPECT_GL_ERROR(GL_INVALID_VALUE);
93
94 glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, -1.0f);
95 EXPECT_GL_ERROR(GL_INVALID_VALUE);
96
97 GLfloat badPointDistanceAttenuation[3] = {1.0f, -1.0f, 1.0f};
98 glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, badPointDistanceAttenuation);
99 EXPECT_GL_ERROR(GL_INVALID_VALUE);
100
101 glPointSize(-1.0f);
102 EXPECT_GL_ERROR(GL_INVALID_VALUE);
103 }
104
105 // Tests that point parameters can be set.
TEST_P(PointParameterTest,Set)106 TEST_P(PointParameterTest, Set)
107 {
108 GLfloat params[3] = {};
109
110 GLfloat range[2] = {};
111 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, range);
112 EXPECT_GL_NO_ERROR();
113
114 if (range[0] != range[1])
115 {
116 glPointSize(range[0]);
117 EXPECT_GL_NO_ERROR();
118 glGetFloatv(GL_POINT_SIZE, params);
119 EXPECT_GL_NO_ERROR();
120 EXPECT_EQ(range[0], params[0]);
121
122 glPointSize(range[1]);
123 EXPECT_GL_NO_ERROR();
124 glGetFloatv(GL_POINT_SIZE, params);
125 EXPECT_GL_NO_ERROR();
126 EXPECT_EQ(range[1], params[0]);
127 }
128
129 glPointParameterf(GL_POINT_SIZE_MIN, 1.0f);
130 EXPECT_GL_NO_ERROR();
131 glPointParameterf(GL_POINT_SIZE_MAX, 10.0f);
132 EXPECT_GL_NO_ERROR();
133
134 glGetFloatv(GL_POINT_SIZE_MIN, params);
135 EXPECT_GL_NO_ERROR();
136 EXPECT_EQ(1.0f, params[0]);
137
138 glGetFloatv(GL_POINT_SIZE_MAX, params);
139 EXPECT_GL_NO_ERROR();
140 EXPECT_EQ(10.0f, params[0]);
141
142 glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 5.0f);
143 EXPECT_GL_NO_ERROR();
144 glGetFloatv(GL_POINT_FADE_THRESHOLD_SIZE, params);
145 EXPECT_EQ(5.0f, params[0]);
146
147 GLfloat distanceAttenuation[3] = {1.0f, 2.0f, 3.0f};
148 glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, distanceAttenuation);
149 EXPECT_GL_NO_ERROR();
150 glGetFloatv(GL_POINT_DISTANCE_ATTENUATION, params);
151 EXPECT_EQ(1.0f, params[0]);
152 EXPECT_EQ(2.0f, params[1]);
153 EXPECT_EQ(3.0f, params[2]);
154 }
155
156 ANGLE_INSTANTIATE_TEST_ES1(PointParameterTest);
157