1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // Some of the pointsprite tests below were ported from Khronos WebGL
7*8975f5c5SAndroid Build Coastguard Worker // conformance test suite.
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
10*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker #include <cmath>
13*8975f5c5SAndroid Build Coastguard Worker
14*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker constexpr char kVertexShaderSource[] =
17*8975f5c5SAndroid Build Coastguard Worker R"(attribute vec4 vPosition;
18*8975f5c5SAndroid Build Coastguard Worker uniform float uPointSize;
19*8975f5c5SAndroid Build Coastguard Worker void main()
20*8975f5c5SAndroid Build Coastguard Worker {
21*8975f5c5SAndroid Build Coastguard Worker gl_PointSize = uPointSize;
22*8975f5c5SAndroid Build Coastguard Worker gl_Position = vPosition;
23*8975f5c5SAndroid Build Coastguard Worker })";
24*8975f5c5SAndroid Build Coastguard Worker
25*8975f5c5SAndroid Build Coastguard Worker constexpr GLfloat kMinMaxPointSize = 1.0f;
26*8975f5c5SAndroid Build Coastguard Worker
27*8975f5c5SAndroid Build Coastguard Worker class PointSpritesTest : public ANGLETest<>
28*8975f5c5SAndroid Build Coastguard Worker {
29*8975f5c5SAndroid Build Coastguard Worker protected:
30*8975f5c5SAndroid Build Coastguard Worker const int windowWidth = 256;
31*8975f5c5SAndroid Build Coastguard Worker const int windowHeight = 256;
PointSpritesTest()32*8975f5c5SAndroid Build Coastguard Worker PointSpritesTest()
33*8975f5c5SAndroid Build Coastguard Worker {
34*8975f5c5SAndroid Build Coastguard Worker setWindowWidth(windowWidth);
35*8975f5c5SAndroid Build Coastguard Worker setWindowHeight(windowHeight);
36*8975f5c5SAndroid Build Coastguard Worker setConfigRedBits(8);
37*8975f5c5SAndroid Build Coastguard Worker setConfigGreenBits(8);
38*8975f5c5SAndroid Build Coastguard Worker setConfigBlueBits(8);
39*8975f5c5SAndroid Build Coastguard Worker setConfigAlphaBits(8);
40*8975f5c5SAndroid Build Coastguard Worker }
41*8975f5c5SAndroid Build Coastguard Worker
s2p(float s)42*8975f5c5SAndroid Build Coastguard Worker float s2p(float s) { return (s + 1.0f) * 0.5f * (GLfloat)windowWidth; }
43*8975f5c5SAndroid Build Coastguard Worker
testPointCoordAndPointSizeCompliance(GLProgram & program)44*8975f5c5SAndroid Build Coastguard Worker void testPointCoordAndPointSizeCompliance(GLProgram &program)
45*8975f5c5SAndroid Build Coastguard Worker {
46*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
47*8975f5c5SAndroid Build Coastguard Worker
48*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSizeRange[2] = {};
49*8975f5c5SAndroid Build Coastguard Worker glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
50*8975f5c5SAndroid Build Coastguard Worker
51*8975f5c5SAndroid Build Coastguard Worker GLfloat maxPointSize = pointSizeRange[1];
52*8975f5c5SAndroid Build Coastguard Worker
53*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(maxPointSize >= 1);
54*8975f5c5SAndroid Build Coastguard Worker maxPointSize = floorf(maxPointSize);
55*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE((int)maxPointSize % 1 == 0);
56*8975f5c5SAndroid Build Coastguard Worker
57*8975f5c5SAndroid Build Coastguard Worker maxPointSize = std::min(maxPointSize, 64.0f);
58*8975f5c5SAndroid Build Coastguard Worker GLfloat pointWidth = maxPointSize / windowWidth;
59*8975f5c5SAndroid Build Coastguard Worker GLint step = static_cast<GLint>(floorf(maxPointSize / 4));
60*8975f5c5SAndroid Build Coastguard Worker GLint pointStep = std::max<GLint>(1, step);
61*8975f5c5SAndroid Build Coastguard Worker
62*8975f5c5SAndroid Build Coastguard Worker GLint pointSizeLoc = glGetUniformLocation(program, "uPointSize");
63*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
64*8975f5c5SAndroid Build Coastguard Worker
65*8975f5c5SAndroid Build Coastguard Worker glUniform1f(pointSizeLoc, maxPointSize);
66*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
67*8975f5c5SAndroid Build Coastguard Worker
68*8975f5c5SAndroid Build Coastguard Worker GLfloat pixelOffset = ((int)maxPointSize % 2) ? (1.0f / (GLfloat)windowWidth) : 0;
69*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexObject;
70*8975f5c5SAndroid Build Coastguard Worker
71*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexObject);
72*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
73*8975f5c5SAndroid Build Coastguard Worker
74*8975f5c5SAndroid Build Coastguard Worker GLfloat thePoints[] = {-0.5f + pixelOffset, -0.5f + pixelOffset, 0.5f + pixelOffset,
75*8975f5c5SAndroid Build Coastguard Worker -0.5f + pixelOffset, -0.5f + pixelOffset, 0.5f + pixelOffset,
76*8975f5c5SAndroid Build Coastguard Worker 0.5f + pixelOffset, 0.5f + pixelOffset};
77*8975f5c5SAndroid Build Coastguard Worker
78*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW);
79*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
80*8975f5c5SAndroid Build Coastguard Worker
81*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(0);
82*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
83*8975f5c5SAndroid Build Coastguard Worker
84*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
85*8975f5c5SAndroid Build Coastguard Worker
86*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, 4);
87*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
88*8975f5c5SAndroid Build Coastguard Worker
89*8975f5c5SAndroid Build Coastguard Worker for (float py = 0; py < 2; ++py)
90*8975f5c5SAndroid Build Coastguard Worker {
91*8975f5c5SAndroid Build Coastguard Worker for (float px = 0; px < 2; ++px)
92*8975f5c5SAndroid Build Coastguard Worker {
93*8975f5c5SAndroid Build Coastguard Worker float pointX = -0.5f + px + pixelOffset;
94*8975f5c5SAndroid Build Coastguard Worker float pointY = -0.5f + py + pixelOffset;
95*8975f5c5SAndroid Build Coastguard Worker for (int yy = 0; yy < maxPointSize; yy += pointStep)
96*8975f5c5SAndroid Build Coastguard Worker {
97*8975f5c5SAndroid Build Coastguard Worker for (int xx = 0; xx < maxPointSize; xx += pointStep)
98*8975f5c5SAndroid Build Coastguard Worker {
99*8975f5c5SAndroid Build Coastguard Worker // formula for s and t from OpenGL ES 2.0 spec section 3.3
100*8975f5c5SAndroid Build Coastguard Worker float xw = s2p(pointX);
101*8975f5c5SAndroid Build Coastguard Worker float yw = s2p(pointY);
102*8975f5c5SAndroid Build Coastguard Worker float u = xx / maxPointSize * 2 - 1;
103*8975f5c5SAndroid Build Coastguard Worker float v = yy / maxPointSize * 2 - 1;
104*8975f5c5SAndroid Build Coastguard Worker int xf = static_cast<int>(floorf(s2p(pointX + u * pointWidth)));
105*8975f5c5SAndroid Build Coastguard Worker int yf = static_cast<int>(floorf(s2p(pointY + v * pointWidth)));
106*8975f5c5SAndroid Build Coastguard Worker float s = 0.5f + (xf + 0.5f - xw) / maxPointSize;
107*8975f5c5SAndroid Build Coastguard Worker float t = 0.5f + (yf + 0.5f - yw) / maxPointSize;
108*8975f5c5SAndroid Build Coastguard Worker GLubyte color[4] = {static_cast<GLubyte>(floorf(s * 255)),
109*8975f5c5SAndroid Build Coastguard Worker static_cast<GLubyte>(floorf((1 - t) * 255)), 0, 255};
110*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(xf, yf, color[0], color[1], color[2], color[3], 4);
111*8975f5c5SAndroid Build Coastguard Worker }
112*8975f5c5SAndroid Build Coastguard Worker }
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker }
115*8975f5c5SAndroid Build Coastguard Worker }
116*8975f5c5SAndroid Build Coastguard Worker };
117*8975f5c5SAndroid Build Coastguard Worker
118*8975f5c5SAndroid Build Coastguard Worker // Checks gl_PointCoord and gl_PointSize
119*8975f5c5SAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/sdk/tests/conformance/glsl/variables/gl-pointcoord.html
TEST_P(PointSpritesTest,PointCoordAndPointSizeCompliance)120*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointCoordAndPointSizeCompliance)
121*8975f5c5SAndroid Build Coastguard Worker {
122*8975f5c5SAndroid Build Coastguard Worker constexpr char fs[] =
123*8975f5c5SAndroid Build Coastguard Worker R"(precision mediump float;
124*8975f5c5SAndroid Build Coastguard Worker void main()
125*8975f5c5SAndroid Build Coastguard Worker {
126*8975f5c5SAndroid Build Coastguard Worker gl_FragColor = vec4(gl_PointCoord.x, gl_PointCoord.y, 0, 1);
127*8975f5c5SAndroid Build Coastguard Worker })";
128*8975f5c5SAndroid Build Coastguard Worker
129*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVertexShaderSource, fs);
130*8975f5c5SAndroid Build Coastguard Worker
131*8975f5c5SAndroid Build Coastguard Worker testPointCoordAndPointSizeCompliance(program);
132*8975f5c5SAndroid Build Coastguard Worker }
133*8975f5c5SAndroid Build Coastguard Worker
134*8975f5c5SAndroid Build Coastguard Worker // Checks gl_PointCoord and gl_PointSize, but use the gl_PointCoord inside a function.
135*8975f5c5SAndroid Build Coastguard Worker // In Vulkan, we need to inject some code into the shader to flip the Y coordinate, and we
136*8975f5c5SAndroid Build Coastguard Worker // need to make sure this code injection works even if someone uses gl_PointCoord outside the
137*8975f5c5SAndroid Build Coastguard Worker // main function.
TEST_P(PointSpritesTest,UsingPointCoordInsideFunction)138*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, UsingPointCoordInsideFunction)
139*8975f5c5SAndroid Build Coastguard Worker {
140*8975f5c5SAndroid Build Coastguard Worker constexpr char fs[] =
141*8975f5c5SAndroid Build Coastguard Worker R"(precision mediump float;
142*8975f5c5SAndroid Build Coastguard Worker void foo()
143*8975f5c5SAndroid Build Coastguard Worker {
144*8975f5c5SAndroid Build Coastguard Worker gl_FragColor = vec4(gl_PointCoord.x, gl_PointCoord.y, 0, 1);
145*8975f5c5SAndroid Build Coastguard Worker }
146*8975f5c5SAndroid Build Coastguard Worker
147*8975f5c5SAndroid Build Coastguard Worker void main()
148*8975f5c5SAndroid Build Coastguard Worker {
149*8975f5c5SAndroid Build Coastguard Worker foo();
150*8975f5c5SAndroid Build Coastguard Worker })";
151*8975f5c5SAndroid Build Coastguard Worker
152*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVertexShaderSource, fs);
153*8975f5c5SAndroid Build Coastguard Worker
154*8975f5c5SAndroid Build Coastguard Worker testPointCoordAndPointSizeCompliance(program);
155*8975f5c5SAndroid Build Coastguard Worker }
156*8975f5c5SAndroid Build Coastguard Worker
157*8975f5c5SAndroid Build Coastguard Worker // Verify that drawing a point without enabling any attributes succeeds
158*8975f5c5SAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-no-attributes.html
TEST_P(PointSpritesTest,PointWithoutAttributesCompliance)159*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointWithoutAttributesCompliance)
160*8975f5c5SAndroid Build Coastguard Worker {
161*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSizeRange[2] = {};
162*8975f5c5SAndroid Build Coastguard Worker glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
163*8975f5c5SAndroid Build Coastguard Worker GLfloat maxPointSize = pointSizeRange[1];
164*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(maxPointSize < kMinMaxPointSize);
165*8975f5c5SAndroid Build Coastguard Worker
166*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(void main()
167*8975f5c5SAndroid Build Coastguard Worker {
168*8975f5c5SAndroid Build Coastguard Worker gl_PointSize = 2.0;
169*8975f5c5SAndroid Build Coastguard Worker gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
170*8975f5c5SAndroid Build Coastguard Worker })";
171*8975f5c5SAndroid Build Coastguard Worker
172*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Blue());
173*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
174*8975f5c5SAndroid Build Coastguard Worker
175*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
176*8975f5c5SAndroid Build Coastguard Worker
177*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, 1);
178*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
179*8975f5c5SAndroid Build Coastguard Worker
180*8975f5c5SAndroid Build Coastguard Worker // expect the center pixel to be blue
181*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ((windowWidth - 1) / 2, (windowHeight - 1) / 2, GLColor::blue);
182*8975f5c5SAndroid Build Coastguard Worker }
183*8975f5c5SAndroid Build Coastguard Worker
184*8975f5c5SAndroid Build Coastguard Worker // This is a regression test for a graphics driver bug affecting end caps on roads in MapsGL
185*8975f5c5SAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-with-gl-pointcoord-in-fragment-shader.html
TEST_P(PointSpritesTest,PointCoordRegressionTest)186*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointCoordRegressionTest)
187*8975f5c5SAndroid Build Coastguard Worker {
188*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSizeRange[2] = {};
189*8975f5c5SAndroid Build Coastguard Worker glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
190*8975f5c5SAndroid Build Coastguard Worker GLfloat maxPointSize = pointSizeRange[1];
191*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(maxPointSize < kMinMaxPointSize);
192*8975f5c5SAndroid Build Coastguard Worker
193*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] = R"(precision mediump float;
194*8975f5c5SAndroid Build Coastguard Worker varying vec4 v_color;
195*8975f5c5SAndroid Build Coastguard Worker void main()
196*8975f5c5SAndroid Build Coastguard Worker {
197*8975f5c5SAndroid Build Coastguard Worker // It seems as long as this mathematical expression references
198*8975f5c5SAndroid Build Coastguard Worker // gl_PointCoord, the fragment's color is incorrect.
199*8975f5c5SAndroid Build Coastguard Worker vec2 diff = gl_PointCoord - vec2(.5, .5);
200*8975f5c5SAndroid Build Coastguard Worker if (length(diff) > 0.5)
201*8975f5c5SAndroid Build Coastguard Worker discard;
202*8975f5c5SAndroid Build Coastguard Worker
203*8975f5c5SAndroid Build Coastguard Worker // The point should be a solid color.
204*8975f5c5SAndroid Build Coastguard Worker gl_FragColor = v_color;
205*8975f5c5SAndroid Build Coastguard Worker })";
206*8975f5c5SAndroid Build Coastguard Worker
207*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(varying vec4 v_color;
208*8975f5c5SAndroid Build Coastguard Worker // The X and Y coordinates of the center of the point.
209*8975f5c5SAndroid Build Coastguard Worker attribute vec2 a_vertex;
210*8975f5c5SAndroid Build Coastguard Worker uniform float u_pointSize;
211*8975f5c5SAndroid Build Coastguard Worker void main()
212*8975f5c5SAndroid Build Coastguard Worker {
213*8975f5c5SAndroid Build Coastguard Worker gl_PointSize = u_pointSize;
214*8975f5c5SAndroid Build Coastguard Worker gl_Position = vec4(a_vertex, 0.0, 1.0);
215*8975f5c5SAndroid Build Coastguard Worker // The color of the point.
216*8975f5c5SAndroid Build Coastguard Worker v_color = vec4(0.0, 1.0, 0.0, 1.0);
217*8975f5c5SAndroid Build Coastguard Worker })";
218*8975f5c5SAndroid Build Coastguard Worker
219*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, kFS);
220*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
221*8975f5c5SAndroid Build Coastguard Worker
222*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
223*8975f5c5SAndroid Build Coastguard Worker
224*8975f5c5SAndroid Build Coastguard Worker glClearColor(0, 0, 0, 1);
225*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_DEPTH_TEST);
226*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
227*8975f5c5SAndroid Build Coastguard Worker
228*8975f5c5SAndroid Build Coastguard Worker GLint pointSizeLoc = glGetUniformLocation(program, "u_pointSize");
229*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
230*8975f5c5SAndroid Build Coastguard Worker
231*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSize = std::min<GLfloat>(20.0f, maxPointSize);
232*8975f5c5SAndroid Build Coastguard Worker glUniform1f(pointSizeLoc, pointSize);
233*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
234*8975f5c5SAndroid Build Coastguard Worker
235*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexObject;
236*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
237*8975f5c5SAndroid Build Coastguard Worker
238*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexObject);
239*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
240*8975f5c5SAndroid Build Coastguard Worker
241*8975f5c5SAndroid Build Coastguard Worker GLfloat thePoints[] = {0.0f, 0.0f};
242*8975f5c5SAndroid Build Coastguard Worker
243*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW);
244*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
245*8975f5c5SAndroid Build Coastguard Worker
246*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(0);
247*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
248*8975f5c5SAndroid Build Coastguard Worker
249*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, 1);
250*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
251*8975f5c5SAndroid Build Coastguard Worker
252*8975f5c5SAndroid Build Coastguard Worker // expect the center pixel to be green
253*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_EQ((windowWidth - 1) / 2, (windowHeight - 1) / 2, 0, 255, 0, 255);
254*8975f5c5SAndroid Build Coastguard Worker }
255*8975f5c5SAndroid Build Coastguard Worker
256*8975f5c5SAndroid Build Coastguard Worker // Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled
257*8975f5c5SAndroid Build Coastguard Worker // https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-size.html
TEST_P(PointSpritesTest,PointSizeEnabledCompliance)258*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointSizeEnabledCompliance)
259*8975f5c5SAndroid Build Coastguard Worker {
260*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] = R"(precision mediump float;
261*8975f5c5SAndroid Build Coastguard Worker varying vec4 color;
262*8975f5c5SAndroid Build Coastguard Worker
263*8975f5c5SAndroid Build Coastguard Worker void main()
264*8975f5c5SAndroid Build Coastguard Worker {
265*8975f5c5SAndroid Build Coastguard Worker gl_FragColor = color;
266*8975f5c5SAndroid Build Coastguard Worker })";
267*8975f5c5SAndroid Build Coastguard Worker
268*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(attribute vec3 pos;
269*8975f5c5SAndroid Build Coastguard Worker attribute vec4 colorIn;
270*8975f5c5SAndroid Build Coastguard Worker uniform float pointSize;
271*8975f5c5SAndroid Build Coastguard Worker varying vec4 color;
272*8975f5c5SAndroid Build Coastguard Worker
273*8975f5c5SAndroid Build Coastguard Worker void main()
274*8975f5c5SAndroid Build Coastguard Worker {
275*8975f5c5SAndroid Build Coastguard Worker gl_PointSize = pointSize;
276*8975f5c5SAndroid Build Coastguard Worker color = colorIn;
277*8975f5c5SAndroid Build Coastguard Worker gl_Position = vec4(pos, 1.0);
278*8975f5c5SAndroid Build Coastguard Worker })";
279*8975f5c5SAndroid Build Coastguard Worker
280*8975f5c5SAndroid Build Coastguard Worker // The WebGL test is drawn on a 2x2 canvas. Emulate this by setting a 2x2 viewport.
281*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, 2, 2);
282*8975f5c5SAndroid Build Coastguard Worker
283*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, kFS);
284*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
285*8975f5c5SAndroid Build Coastguard Worker
286*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
287*8975f5c5SAndroid Build Coastguard Worker
288*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_BLEND);
289*8975f5c5SAndroid Build Coastguard Worker
290*8975f5c5SAndroid Build Coastguard Worker // The choice of (0.4, 0.4) ensures that the centers of the surrounding
291*8975f5c5SAndroid Build Coastguard Worker // pixels are not contained within the point when it is of size 1, but
292*8975f5c5SAndroid Build Coastguard Worker // that they definitely are when it is of size 2.
293*8975f5c5SAndroid Build Coastguard Worker GLfloat vertices[] = {0.4f, 0.4f, 0.0f};
294*8975f5c5SAndroid Build Coastguard Worker GLubyte colors[] = {255, 0, 0, 255};
295*8975f5c5SAndroid Build Coastguard Worker
296*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexObject;
297*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
298*8975f5c5SAndroid Build Coastguard Worker
299*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexObject);
300*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
301*8975f5c5SAndroid Build Coastguard Worker
302*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(colors), nullptr, GL_STATIC_DRAW);
303*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
304*8975f5c5SAndroid Build Coastguard Worker
305*8975f5c5SAndroid Build Coastguard Worker glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
306*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
307*8975f5c5SAndroid Build Coastguard Worker
308*8975f5c5SAndroid Build Coastguard Worker glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);
309*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
310*8975f5c5SAndroid Build Coastguard Worker
311*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
312*8975f5c5SAndroid Build Coastguard Worker
313*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
314*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(0);
315*8975f5c5SAndroid Build Coastguard Worker
316*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0,
317*8975f5c5SAndroid Build Coastguard Worker reinterpret_cast<void *>(sizeof(vertices)));
318*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(1);
319*8975f5c5SAndroid Build Coastguard Worker
320*8975f5c5SAndroid Build Coastguard Worker GLint pointSizeLoc = glGetUniformLocation(program, "pointSize");
321*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
322*8975f5c5SAndroid Build Coastguard Worker
323*8975f5c5SAndroid Build Coastguard Worker glUniform1f(pointSizeLoc, 1.0f);
324*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
325*8975f5c5SAndroid Build Coastguard Worker
326*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(ArraySize(vertices)) / 3);
327*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
328*8975f5c5SAndroid Build Coastguard Worker
329*8975f5c5SAndroid Build Coastguard Worker // Test the pixels around the target Red pixel to ensure
330*8975f5c5SAndroid Build Coastguard Worker // they are the expected color values
331*8975f5c5SAndroid Build Coastguard Worker for (GLint y = 0; y < 2; ++y)
332*8975f5c5SAndroid Build Coastguard Worker {
333*8975f5c5SAndroid Build Coastguard Worker for (GLint x = 0; x < 2; ++x)
334*8975f5c5SAndroid Build Coastguard Worker {
335*8975f5c5SAndroid Build Coastguard Worker // 1x1 is expected to be a red pixel
336*8975f5c5SAndroid Build Coastguard Worker // All others are black
337*8975f5c5SAndroid Build Coastguard Worker GLubyte expectedColor[4] = {0, 0, 0, 0};
338*8975f5c5SAndroid Build Coastguard Worker if (x == 1 && y == 1)
339*8975f5c5SAndroid Build Coastguard Worker {
340*8975f5c5SAndroid Build Coastguard Worker expectedColor[0] = 255;
341*8975f5c5SAndroid Build Coastguard Worker expectedColor[3] = 255;
342*8975f5c5SAndroid Build Coastguard Worker }
343*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_EQ(x, y, expectedColor[0], expectedColor[1], expectedColor[2],
344*8975f5c5SAndroid Build Coastguard Worker expectedColor[3]);
345*8975f5c5SAndroid Build Coastguard Worker }
346*8975f5c5SAndroid Build Coastguard Worker }
347*8975f5c5SAndroid Build Coastguard Worker
348*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSizeRange[2] = {};
349*8975f5c5SAndroid Build Coastguard Worker glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
350*8975f5c5SAndroid Build Coastguard Worker
351*8975f5c5SAndroid Build Coastguard Worker if (pointSizeRange[1] >= 2.0)
352*8975f5c5SAndroid Build Coastguard Worker {
353*8975f5c5SAndroid Build Coastguard Worker // Draw a point of size 2 and verify it fills the appropriate region.
354*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
355*8975f5c5SAndroid Build Coastguard Worker
356*8975f5c5SAndroid Build Coastguard Worker glUniform1f(pointSizeLoc, 2.0f);
357*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
358*8975f5c5SAndroid Build Coastguard Worker
359*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(ArraySize(vertices)) / 3);
360*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
361*8975f5c5SAndroid Build Coastguard Worker
362*8975f5c5SAndroid Build Coastguard Worker // Test the pixels to ensure the target is ALL Red pixels
363*8975f5c5SAndroid Build Coastguard Worker for (GLint y = 0; y < 2; ++y)
364*8975f5c5SAndroid Build Coastguard Worker {
365*8975f5c5SAndroid Build Coastguard Worker for (GLint x = 0; x < 2; ++x)
366*8975f5c5SAndroid Build Coastguard Worker {
367*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
368*8975f5c5SAndroid Build Coastguard Worker }
369*8975f5c5SAndroid Build Coastguard Worker }
370*8975f5c5SAndroid Build Coastguard Worker }
371*8975f5c5SAndroid Build Coastguard Worker }
372*8975f5c5SAndroid Build Coastguard Worker
373*8975f5c5SAndroid Build Coastguard Worker // Verify that rendering works correctly when gl_PointSize is declared in a shader but isn't used
TEST_P(PointSpritesTest,PointSizeDeclaredButUnused)374*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointSizeDeclaredButUnused)
375*8975f5c5SAndroid Build Coastguard Worker {
376*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(attribute highp vec4 position;
377*8975f5c5SAndroid Build Coastguard Worker void main(void)
378*8975f5c5SAndroid Build Coastguard Worker {
379*8975f5c5SAndroid Build Coastguard Worker gl_PointSize = 1.0;
380*8975f5c5SAndroid Build Coastguard Worker gl_Position = position;
381*8975f5c5SAndroid Build Coastguard Worker })";
382*8975f5c5SAndroid Build Coastguard Worker
383*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red());
384*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
385*8975f5c5SAndroid Build Coastguard Worker
386*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
387*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, "position", 0.5f, 1.0f);
388*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
389*8975f5c5SAndroid Build Coastguard Worker
390*8975f5c5SAndroid Build Coastguard Worker // expect the center pixel to be red
391*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 0, 0, 255);
392*8975f5c5SAndroid Build Coastguard Worker }
393*8975f5c5SAndroid Build Coastguard Worker
394*8975f5c5SAndroid Build Coastguard Worker // Test to cover a bug where the D3D11 rasterizer state would not be update when switching between
395*8975f5c5SAndroid Build Coastguard Worker // draw types. This causes the cull face to potentially be incorrect when drawing emulated point
396*8975f5c5SAndroid Build Coastguard Worker // spites.
TEST_P(PointSpritesTest,PointSpriteAlternatingDrawTypes)397*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointSpriteAlternatingDrawTypes)
398*8975f5c5SAndroid Build Coastguard Worker {
399*8975f5c5SAndroid Build Coastguard Worker // TODO(anglebug.com/42262976): Investigate possible ARM driver bug.
400*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsFuchsia() && IsARM() && IsVulkan());
401*8975f5c5SAndroid Build Coastguard Worker
402*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSizeRange[2] = {};
403*8975f5c5SAndroid Build Coastguard Worker glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
404*8975f5c5SAndroid Build Coastguard Worker GLfloat maxPointSize = pointSizeRange[1];
405*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(maxPointSize < kMinMaxPointSize);
406*8975f5c5SAndroid Build Coastguard Worker
407*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(uniform float u_pointSize;
408*8975f5c5SAndroid Build Coastguard Worker void main()
409*8975f5c5SAndroid Build Coastguard Worker {
410*8975f5c5SAndroid Build Coastguard Worker gl_PointSize = u_pointSize;
411*8975f5c5SAndroid Build Coastguard Worker gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
412*8975f5c5SAndroid Build Coastguard Worker })";
413*8975f5c5SAndroid Build Coastguard Worker
414*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(pointProgram, kVS, essl1_shaders::fs::Blue());
415*8975f5c5SAndroid Build Coastguard Worker
416*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(quadProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
417*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
418*8975f5c5SAndroid Build Coastguard Worker
419*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_CULL_FACE);
420*8975f5c5SAndroid Build Coastguard Worker glCullFace(GL_FRONT);
421*8975f5c5SAndroid Build Coastguard Worker
422*8975f5c5SAndroid Build Coastguard Worker const GLfloat quadVertices[] = {
423*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, 0.5f, 1.0f, -1.0f, 0.5f, -1.0f, -1.0f, 0.5f,
424*8975f5c5SAndroid Build Coastguard Worker
425*8975f5c5SAndroid Build Coastguard Worker -1.0f, 1.0f, 0.5f, 1.0f, 1.0f, 0.5f, 1.0f, -1.0f, 0.5f,
426*8975f5c5SAndroid Build Coastguard Worker };
427*8975f5c5SAndroid Build Coastguard Worker
428*8975f5c5SAndroid Build Coastguard Worker glUseProgram(quadProgram);
429*8975f5c5SAndroid Build Coastguard Worker GLint positionLocation = glGetAttribLocation(quadProgram, essl1_shaders::PositionAttrib());
430*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices);
431*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(positionLocation);
432*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_TRIANGLES, 0, 6);
433*8975f5c5SAndroid Build Coastguard Worker
434*8975f5c5SAndroid Build Coastguard Worker glUseProgram(pointProgram);
435*8975f5c5SAndroid Build Coastguard Worker GLint pointSizeLoc = glGetUniformLocation(pointProgram, "u_pointSize");
436*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
437*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSize = std::min<GLfloat>(16.0f, maxPointSize);
438*8975f5c5SAndroid Build Coastguard Worker glUniform1f(pointSizeLoc, pointSize);
439*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
440*8975f5c5SAndroid Build Coastguard Worker
441*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, 1);
442*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
443*8975f5c5SAndroid Build Coastguard Worker
444*8975f5c5SAndroid Build Coastguard Worker // expect the center pixel to be blue
445*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
446*8975f5c5SAndroid Build Coastguard Worker }
447*8975f5c5SAndroid Build Coastguard Worker
448*8975f5c5SAndroid Build Coastguard Worker // This checks for an NVIDIA driver bug where points larger than the maximum reported point size can
449*8975f5c5SAndroid Build Coastguard Worker // be drawn. Point size should be clamped to the point size range as specified in GLES 3.0.5 section
450*8975f5c5SAndroid Build Coastguard Worker // 3.4.
TEST_P(PointSpritesTest,PointSizeAboveMaxIsClamped)451*8975f5c5SAndroid Build Coastguard Worker TEST_P(PointSpritesTest, PointSizeAboveMaxIsClamped)
452*8975f5c5SAndroid Build Coastguard Worker {
453*8975f5c5SAndroid Build Coastguard Worker // Failed on NVIDIA GeForce GTX 1080 - no pixels from the point were detected in the
454*8975f5c5SAndroid Build Coastguard Worker // framebuffer. http://anglebug.com/42260857
455*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsD3D9());
456*8975f5c5SAndroid Build Coastguard Worker
457*8975f5c5SAndroid Build Coastguard Worker // Failed on AMD OSX and Windows trybots - no pixels from the point were detected in the
458*8975f5c5SAndroid Build Coastguard Worker // framebuffer. http://anglebug.com/42260859
459*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
460*8975f5c5SAndroid Build Coastguard Worker
461*8975f5c5SAndroid Build Coastguard Worker // TODO(anglebug.com/40096805)
462*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsMetal() && IsAMD());
463*8975f5c5SAndroid Build Coastguard Worker
464*8975f5c5SAndroid Build Coastguard Worker GLfloat pointSizeRange[2] = {};
465*8975f5c5SAndroid Build Coastguard Worker glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
466*8975f5c5SAndroid Build Coastguard Worker GLfloat maxPointSize = pointSizeRange[1];
467*8975f5c5SAndroid Build Coastguard Worker
468*8975f5c5SAndroid Build Coastguard Worker if (maxPointSize < 4)
469*8975f5c5SAndroid Build Coastguard Worker {
470*8975f5c5SAndroid Build Coastguard Worker // This test is only able to test larger points.
471*8975f5c5SAndroid Build Coastguard Worker return;
472*8975f5c5SAndroid Build Coastguard Worker }
473*8975f5c5SAndroid Build Coastguard Worker
474*8975f5c5SAndroid Build Coastguard Worker // Create a renderbuffer that has height and width equal to the max point size.
475*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer renderbuffer;
476*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
477*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, static_cast<GLsizei>(maxPointSize),
478*8975f5c5SAndroid Build Coastguard Worker static_cast<GLsizei>(maxPointSize));
479*8975f5c5SAndroid Build Coastguard Worker // Switch the render target from the default window surface to the newly created renderbuffer so
480*8975f5c5SAndroid Build Coastguard Worker // that the test can handle implementations with a very large max point size.
481*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
482*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
483*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
484*8975f5c5SAndroid Build Coastguard Worker
485*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, maxPointSize, maxPointSize);
486*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
487*8975f5c5SAndroid Build Coastguard Worker
488*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] =
489*8975f5c5SAndroid Build Coastguard Worker "attribute vec2 vPosition;\n"
490*8975f5c5SAndroid Build Coastguard Worker "uniform float uPointSize;\n"
491*8975f5c5SAndroid Build Coastguard Worker "void main()\n"
492*8975f5c5SAndroid Build Coastguard Worker "{\n"
493*8975f5c5SAndroid Build Coastguard Worker " gl_PointSize = uPointSize;\n"
494*8975f5c5SAndroid Build Coastguard Worker " gl_Position = vec4(vPosition, 0, 1);\n"
495*8975f5c5SAndroid Build Coastguard Worker "}\n";
496*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red());
497*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
498*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
499*8975f5c5SAndroid Build Coastguard Worker
500*8975f5c5SAndroid Build Coastguard Worker GLfloat testPointSize = floorf(maxPointSize * 2.0f);
501*8975f5c5SAndroid Build Coastguard Worker
502*8975f5c5SAndroid Build Coastguard Worker GLint pointSizeLoc = glGetUniformLocation(program, "uPointSize");
503*8975f5c5SAndroid Build Coastguard Worker glUniform1f(pointSizeLoc, testPointSize);
504*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
505*8975f5c5SAndroid Build Coastguard Worker
506*8975f5c5SAndroid Build Coastguard Worker // The point will be a square centered at gl_Position. As the framebuffer is the same size as
507*8975f5c5SAndroid Build Coastguard Worker // the square, setting the center of the point on the right edge of the viewport will result in
508*8975f5c5SAndroid Build Coastguard Worker // the left edge of the point square to be at the center of the viewport.
509*8975f5c5SAndroid Build Coastguard Worker GLfloat pointXPosition = 1;
510*8975f5c5SAndroid Build Coastguard Worker
511*8975f5c5SAndroid Build Coastguard Worker GLBuffer vertexBuffer;
512*8975f5c5SAndroid Build Coastguard Worker glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
513*8975f5c5SAndroid Build Coastguard Worker GLfloat thePoints[] = {pointXPosition, 0.0f};
514*8975f5c5SAndroid Build Coastguard Worker glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW);
515*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
516*8975f5c5SAndroid Build Coastguard Worker
517*8975f5c5SAndroid Build Coastguard Worker glEnableVertexAttribArray(0);
518*8975f5c5SAndroid Build Coastguard Worker glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
519*8975f5c5SAndroid Build Coastguard Worker
520*8975f5c5SAndroid Build Coastguard Worker // Clear the framebuffer to green
521*8975f5c5SAndroid Build Coastguard Worker glClearColor(0, 1, 0, 1);
522*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
523*8975f5c5SAndroid Build Coastguard Worker
524*8975f5c5SAndroid Build Coastguard Worker // Draw the red point
525*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, 1);
526*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
527*8975f5c5SAndroid Build Coastguard Worker
528*8975f5c5SAndroid Build Coastguard Worker // Pixels to the right of the framebuffer center should be covered by the point.
529*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(maxPointSize / 2 + 2, maxPointSize / 2, 255, 0, 0, 255, 1);
530*8975f5c5SAndroid Build Coastguard Worker
531*8975f5c5SAndroid Build Coastguard Worker // Pixels to the left of the framebuffer center should not be covered by the point.
532*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(maxPointSize / 2 - 2, maxPointSize / 2, 0, 255, 0, 255, 1);
533*8975f5c5SAndroid Build Coastguard Worker }
534*8975f5c5SAndroid Build Coastguard Worker
535*8975f5c5SAndroid Build Coastguard Worker // Use this to select which configurations (e.g. which renderer, which GLES
536*8975f5c5SAndroid Build Coastguard Worker // major version) these tests should be run against.
537*8975f5c5SAndroid Build Coastguard Worker //
538*8975f5c5SAndroid Build Coastguard Worker // We test on D3D11 9_3 because the existing D3D11 PointSprite implementation
539*8975f5c5SAndroid Build Coastguard Worker // uses Geometry Shaders which are not supported for 9_3.
540*8975f5c5SAndroid Build Coastguard Worker // D3D9 and D3D11 are also tested to ensure no regressions.
541*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_ES2_AND(PointSpritesTest,
542*8975f5c5SAndroid Build Coastguard Worker ES2_VULKAN().enable(Feature::EmulatedPrerotation90),
543*8975f5c5SAndroid Build Coastguard Worker ES2_VULKAN().enable(Feature::EmulatedPrerotation180),
544*8975f5c5SAndroid Build Coastguard Worker ES2_VULKAN().enable(Feature::EmulatedPrerotation270));
545