2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL Point with gl_PointCoord in Fragment Shader Test
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <canvas id=
"canvas" width=
"64" height=
"64"> </canvas>
19 <div id=
"console"></div>
20 <script id=
"vs" type=
"x-shader/x-vertex">
23 // The X and Y coordinates of the center of the point.
24 attribute vec2 a_vertex;
26 uniform float u_pointSize;
29 gl_PointSize = u_pointSize;
30 gl_Position = vec4(a_vertex,
0.0,
1.0);
32 // The color of the point.
33 v_color = vec4(
0.0,
1.0,
0.0,
1.0);
37 <script id=
"fs" type=
"x-shader/x-fragment">
38 precision mediump float;
43 // It seems as long as this mathematical expression references
44 // gl_PointCoord, the fragment's color is incorrect.
45 vec2 diff = gl_PointCoord - vec2(
.5,
.5);
46 if (length(diff)
> 0.5)
49 // The point should be a solid color.
50 gl_FragColor = v_color;
56 description("This is a regression test for a graphics driver bug affecting end caps on roads in MapsGL.");
60 var wtu
= WebGLTestUtils
;
61 var canvas
= document
.getElementById("canvas");
62 var canvasWidth
= canvas
.width
;
63 var canvasHeight
= canvas
.height
;
64 var output
= document
.getElementById("console");
65 var gl
= wtu
.create3DContext(canvas
);
68 var pointSizeRange
= gl
.getParameter(gl
.ALIASED_POINT_SIZE_RANGE
);
69 // This test can't really run without a maximum point size of at least 2
70 if (pointSizeRange
[1] < 2.0) {
71 debug("This test needs a maximum ALIASED_POINT_SIZE_RANGE of at least 2");
75 var vs
= wtu
.loadShaderFromScript(gl
, "vs", gl
.VERTEX_SHADER
);
76 var fs
= wtu
.loadShaderFromScript(gl
, "fs", gl
.FRAGMENT_SHADER
);
78 testFailed("Loading shaders failed");
82 var program
= wtu
.setupProgram(gl
, [vs
, fs
], ['a_vertex']);
84 testFailed("Loading program failed");
88 gl
.useProgram(program
);
89 gl
.clearColor(0, 0, 0, 1.0);
90 gl
.disable(gl
.DEPTH_TEST
);
91 gl
.clear(gl
.COLOR_BUFFER_BIT
);
93 // uniform float u_pointSize;
94 var uni
= gl
.getUniformLocation(program
, 'u_pointSize');
95 gl
.uniform1f(uni
, Math
.min(20.0, pointSizeRange
[1]));
98 var buffer
= gl
.createBuffer();
99 gl
.bindBuffer(gl
.ARRAY_BUFFER
, buffer
);
100 var vertexData
= new Float32Array([
103 gl
.bufferData(gl
.ARRAY_BUFFER
, vertexData
, gl
.STATIC_DRAW
);
104 gl
.enableVertexAttribArray(0);
105 gl
.vertexAttribPointer(0, 2, gl
.FLOAT
, false, 0, 0);
107 gl
.drawArrays(gl
.POINTS
, 0, 1);
108 wtu
.checkCanvasRect(gl
, canvasWidth
/ 2, canvasHeight
/ 2, 1, 1,
109 [0, 255, 0, 255], "Center pixel should be green", 2);
115 var successfullyParsed
= true;
117 <script src=
"../../js/js-test-post.js"></script>