Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / rendering / point-with-gl-pointcoord-in-fragment-shader.html
1 <!--
2
3 /*
4 ** Copyright (c) 2013 The Khronos Group Inc.
5 **
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:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
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.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
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>
36 </head>
37 <body>
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">
42 varying vec4 v_color;
43
44 // The X and Y coordinates of the center of the point.
45 attribute vec2 a_vertex;
46
47 uniform float u_pointSize;
48
49 void main(void) {
50   gl_PointSize = u_pointSize;
51   gl_Position = vec4(a_vertex, 0.0, 1.0);
52
53   // The color of the point.
54   v_color = vec4(0.0, 1.0, 0.0, 1.0);
55 }
56
57 </script>
58 <script id="fs" type="x-shader/x-fragment">
59 precision mediump float;
60
61 varying vec4 v_color;
62
63 void main(void) {
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)
68     discard;
69
70   // The point should be a solid color.
71   gl_FragColor = v_color;
72 }
73 </script>
74 <script>
75 "use strict";
76 // Radar 13239314
77 description("This is a regression test for a graphics driver bug affecting end caps on roads in MapsGL.");
78
79 debug("");
80
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);
87
88 function runTest() {
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");
93     return;
94   }
95
96   var vs = wtu.loadShaderFromScript(gl, "vs", gl.VERTEX_SHADER);
97   var fs = wtu.loadShaderFromScript(gl, "fs", gl.FRAGMENT_SHADER);
98   if (!vs || !fs) {
99     testFailed("Loading shaders failed");
100     return;
101   }
102
103   var program = wtu.setupProgram(gl, [vs, fs], ['a_vertex']);
104   if (!program) {
105     testFailed("Loading program failed");
106     return;
107   }
108
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);
113
114   // uniform float u_pointSize;
115   var uni = gl.getUniformLocation(program, 'u_pointSize');
116   gl.uniform1f(uni, Math.min(20.0, pointSizeRange[1]));
117
118   // vertex
119   var buffer = gl.createBuffer();
120   gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
121   var vertexData = new Float32Array([
122     0, 0,
123   ]);
124   gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.STATIC_DRAW);
125   gl.enableVertexAttribArray(0);
126   gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
127
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);
131 }
132
133 runTest();
134
135 debug("");
136 var successfullyParsed = true;
137 </script>
138 <script src="../../resources/js-test-post.js"></script>
139 </body>
140 </html>