4 ** Copyright (c) 2013 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>WebGL Point with gl_PointCoord in Fragment Shader Test</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test-utils.js"></script>
38 <div id="description"></div>
39 <canvas id="canvas" width="64" height="64"> </canvas>
40 <div id="console"></div>
41 <script id="vs" type="x-shader/x-vertex">
44 // The X and Y coordinates of the center of the point.
45 attribute vec2 a_vertex;
47 uniform float u_pointSize;
50 gl_PointSize = u_pointSize;
51 gl_Position = vec4(a_vertex, 0.0, 1.0);
53 // The color of the point.
54 v_color = vec4(0.0, 1.0, 0.0, 1.0);
58 <script id="fs" type="x-shader/x-fragment">
59 precision mediump float;
64 // It seems as long as this mathematical expression references
65 // gl_PointCoord, the fragment's color is incorrect.
66 vec2 diff = gl_PointCoord - vec2(.5, .5);
67 if (length(diff) > 0.5)
70 // The point should be a solid color.
71 gl_FragColor = v_color;
77 description("This is a regression test for a graphics driver bug affecting end caps on roads in MapsGL.");
81 var wtu = WebGLTestUtils;
82 var canvas = document.getElementById("canvas");
83 var canvasWidth = canvas.width;
84 var canvasHeight = canvas.height;
85 var output = document.getElementById("console");
86 var gl = wtu.create3DContext(canvas);
89 var pointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
90 // This test can't really run without a maximum point size of at least 2
91 if (pointSizeRange[1] < 2.0) {
92 debug("This test needs a maximum ALIASED_POINT_SIZE_RANGE of at least 2");
96 var vs = wtu.loadShaderFromScript(gl, "vs", gl.VERTEX_SHADER);
97 var fs = wtu.loadShaderFromScript(gl, "fs", gl.FRAGMENT_SHADER);
99 testFailed("Loading shaders failed");
103 var program = wtu.setupProgram(gl, [vs, fs], ['a_vertex']);
105 testFailed("Loading program failed");
109 gl.useProgram(program);
110 gl.clearColor(0, 0, 0, 1.0);
111 gl.disable(gl.DEPTH_TEST);
112 gl.clear(gl.COLOR_BUFFER_BIT);
114 // uniform float u_pointSize;
115 var uni = gl.getUniformLocation(program, 'u_pointSize');
116 gl.uniform1f(uni, Math.min(20.0, pointSizeRange[1]));
119 var buffer = gl.createBuffer();
120 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
121 var vertexData = new Float32Array([
124 gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.STATIC_DRAW);
125 gl.enableVertexAttribArray(0);
126 gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
128 gl.drawArrays(gl.POINTS, 0, 1);
129 wtu.checkCanvasRect(gl, canvasWidth / 2, canvasHeight / 2, 1, 1,
130 [0, 255, 0, 255], "Center pixel should be green", 2);
136 var successfullyParsed = true;
138 <script src="../../resources/js-test-post.js"></script>