no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / dom / canvas / test / webgl-mochitest / regress / test_bug_1268096.html
blob0262c52d8ce64418fde062a71ac9de8b1e297a8d
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset='UTF-8'/>
5 <script src='/tests/SimpleTest/SimpleTest.js'></script>
6 <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
7 <script src='../webgl-util.js'></script>
8 <script id='vs' type='x-shader/x-vertex'>
10 attribute vec2 aPosition;
12 void main(void) {
13 gl_PointSize = 16.0;
14 gl_Position = vec4(aPosition, 0, 1);
17 </script>
18 <script id='fs' type='x-shader/x-fragment'>
20 precision mediump float;
22 uniform vec4 uColor;
24 void main(void) {
25 gl_FragColor = uColor;
28 </script>
29 </head>
30 <body>
31 <script>
33 function GetPixel(gl, x, y) {
34 var pixel = new Uint8Array(4);
35 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
36 return pixel;
39 function ColorStr(arr) {
40 return '{' + arr.map(function(x) { return '' + x; }).join(', ') + '}';
43 function PixelShouldBe(gl, x, y, ref, prefix) {
44 if (prefix) {
45 prefix += ': ';
48 var test = GetPixel(gl, x, y);
50 var testStr = ColorStr(test);
51 var refStr = ColorStr(ref.map(value => value * 255));
52 ok(testStr == refStr, prefix + 'Should be ' + refStr + ', was ' + testStr + '.');
55 function GetProgram(gl) {
56 var prog = WebGLUtil.createProgramByIds(gl, 'vs', 'fs');
58 prog.aPosition = gl.getAttribLocation(prog, 'aPosition');
59 ok(prog.aPosition >= 0, '`aPosition` should be valid.');
61 prog.uColor = gl.getUniformLocation(prog, 'uColor');
62 ok(prog.uColor, '`uColor` should be valid.');
64 return prog;
67 // Give ourselves a scope to return early from:
68 (function () {
69 var c = document.createElement('canvas');
70 document.body.appendChild(c);
71 var gl = c.getContext('webgl', { depth: false, antialias: false });
72 if (!gl) {
73 todo(false, 'WebGL is unavailable.');
74 return;
77 ////////
79 // With default culling, it works fine.
80 // The problem seems to be that the virtual quads generated from points are wound 'backwards'.
81 gl.enable(gl.CULL_FACE);
82 gl.cullFace(gl.BACK); // Cull back faces.
84 ////////
86 var vertArr = new Float32Array([
87 -1, -1,
88 +1, -1,
89 -1, +1,
90 ]);
92 var vbo = gl.createBuffer();
93 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
94 gl.bufferData(gl.ARRAY_BUFFER, vertArr, gl.STATIC_DRAW);
96 ////////
98 var triProg = GetProgram(gl);
99 var pointProg = GetProgram(gl);
100 if (!triProg || !pointProg) {
101 ok(false, 'Program linking should succeed.');
102 return;
105 ok(triProg.aPosition == pointProg.aPosition, 'aPosition should match.');
106 gl.enableVertexAttribArray(triProg.aPosition);
107 gl.vertexAttribPointer(triProg.aPosition, 2, gl.FLOAT, false, 0, 0);
109 ////////
111 gl.useProgram(triProg);
112 var triColor = [1, 0, 0, 1];
113 gl.uniform4fv(triProg.uColor, triColor);
115 gl.useProgram(pointProg);
116 var pointColor = [0, 1, 0, 1];
117 gl.uniform4fv(pointProg.uColor, pointColor);
119 ////////
121 gl.clearColor(0, 0, 0, 1);
122 gl.clear(gl.COLOR_BUFFER_BIT);
124 gl.useProgram(triProg);
125 gl.drawArrays(gl.TRIANGLES, 0, 3);
127 gl.useProgram(pointProg);
128 gl.drawArrays(gl.POINTS, 0, 3);
130 ////////
132 PixelShouldBe(gl, 32, 32, triColor, 'Tri');
133 PixelShouldBe(gl, 0, 0, pointColor, 'Point');
135 ok(true, 'Test complete');
136 })();
138 </script>
139 </body>
140 </html>