Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / canvas / test / webgl-mochitest / test_no_arr_points.html
blobc4556c9b5c51c8fa66d932074c4d275f078137ed
1 <!DOCTYPE HTML>
2 <title>WebGL test: Drawing without attrib arrays</title>
3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
5 <script src="driver-info.js"></script>
6 <script src="webgl-util.js"></script>
7 <script id="vs-no-attrib" type="x-shader/x-vertex">
9 void main(void) {
10 gl_PointSize = 64.0;
11 gl_Position = vec4(vec3(0.0), 1.0);
14 </script>
15 <script id="vs-attrib" type="x-shader/x-vertex">
17 attribute vec3 aPosition;
19 void main(void) {
20 gl_PointSize = 64.0;
21 gl_Position = vec4(aPosition, 1.0);
24 </script>
25 <script id="fs" type="x-shader/x-fragment">
27 precision mediump float;
29 void main(void) {
30 gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
33 </script>
34 <body>
35 <canvas id="c" width="64" height="64"></canvas>
36 <script>
38 // Give ourselves a scope to return early from:
39 (function() {
40 var gl = c.getContext('webgl');
41 if (!gl) {
42 todo(false, 'WebGL is unavailable.');
43 return;
46 DriverInfo.dump(x => ok(true, x));
48 var attribProg = WebGLUtil.createProgramByIds(gl, 'vs-attrib', 'fs');
49 var noAttribProg = WebGLUtil.createProgramByIds(gl, 'vs-no-attrib', 'fs');
50 if (!attribProg || !noAttribProg) {
51 ok(false, 'Program linking should succeed.');
52 return;
55 attribProg.aPosition = gl.getAttribLocation(attribProg, "aPosition");
56 ok(attribProg.aPosition >= 0, '`aPosition` should be valid.');
58 function isScreenBlack() {
59 var pixels = gl.drawingBufferWidth * gl.drawingBufferHeight;
60 var data = new Uint8Array(4 * pixels);
61 gl.readPixels(0, 0,
62 gl.drawingBufferWidth, gl.drawingBufferHeight,
63 gl.RGBA, gl.UNSIGNED_BYTE,
64 data);
66 var accum = 0;
67 for (var i = 0; i < pixels; i++) {
68 accum += data[4*i + 0];
69 accum += data[4*i + 1];
70 accum += data[4*i + 2];
73 return accum == 0;
76 function checkGLError(func, info) {
77 var error = gl.getError();
78 func(!error, '[' + info + '] gl.getError should be 0, was 0x' + error.toString(16) + '.');
81 function testDrawing(info) {
82 var cruelNumber = 1024*1024;
83 // Really, we should test for INT32_MAX-1 here, but we don't gracefully chunk these calls,
84 // and so try to create a VBO of size INT32_MAX-1 to pretend that vert attrib 0 is an array.
85 // (INT32_MAX-1 because we check that `first+count` is a valid GLsizei, which is int32_t)
86 var UINT16_MAX = 0xffff;
87 var INT32_MAX = 0x7fffffff;
88 var UINT32_MAX = 0xffffffff;
90 // `first` needs room for `first+count` <= sizeof(GLsizei) == INT32_MAX
91 var hugeFirst = Math.min(cruelNumber, INT32_MAX-1);
92 var hugeIndex = Math.min(cruelNumber, UINT32_MAX);
94 var indexType = gl.UNSIGNED_SHORT;
95 var indexStride = 2;
96 var indexArr = new Uint16Array([0, 1, Math.min(hugeIndex, UINT16_MAX)]);
97 if (gl.getExtension('OES_element_index_uint')) {
98 indexType = gl.UNSIGNED_INT;
99 indexStride = 4;
100 indexArr = new Uint32Array([0, 1, hugeIndex]);
103 gl.clear(gl.COLOR_BUFFER_BIT);
104 gl.drawArrays(gl.POINTS, 0, 1);
105 ok(!isScreenBlack(), '[' + info + '] drawArrays should color pixels.');
107 gl.clear(gl.COLOR_BUFFER_BIT);
108 gl.drawArrays(gl.POINTS, hugeFirst, 1);
109 ok(!isScreenBlack(), '[' + info + '] drawArrays[huge first] should color pixels.');
111 checkGLError(ok, info);
113 var elemTestFunc = ok;
114 var checkGLTestFunc = ok;
115 if (DriverInfo.getDriver() == DriverInfo.DRIVER.ANDROID_X86_EMULATOR) {
116 // ...but the Android 4.2 x86 emulator environment is different
117 elemTestFunc = todo;
118 checkGLTestFunc = ok;
121 // Now for drawElements:
122 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
123 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indexArr, gl.STATIC_DRAW);
125 gl.clear(gl.COLOR_BUFFER_BIT);
126 gl.drawElements(gl.POINTS, 1, indexType, 0);
127 elemTestFunc(!isScreenBlack(), '[' + info + '] drawElements[0] should color pixels.');
129 gl.clear(gl.COLOR_BUFFER_BIT);
130 gl.drawElements(gl.POINTS, 1, indexType, 1*indexStride);
131 elemTestFunc(!isScreenBlack(), '[' + info + '] drawElements[1] should color pixels.');
133 gl.clear(gl.COLOR_BUFFER_BIT);
134 gl.drawElements(gl.POINTS, 1, indexType, 2*indexStride);
135 elemTestFunc(!isScreenBlack(), '[' + info + '] drawElements[huge offset] should color pixels.');
137 checkGLError(checkGLTestFunc, info);
140 // Begin drawing
141 gl.clearColor(0.0, 0.0, 0.0, 1.0);
142 gl.disable(gl.DEPTH_TEST);
144 // No-attrib prog:
145 gl.useProgram(noAttribProg);
146 testDrawing('no-attrib');
148 // One-attrib, no-array prog:
149 gl.useProgram(attribProg);
150 gl.disableVertexAttribArray(attribProg.aPosition);
151 gl.vertexAttrib3fv(attribProg.aPosition, [0.0, 0.0, 0.0]);
152 testDrawing('one-attrib, no-array');
153 })();
155 </script>