Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / canvas / test / webgl-mochitest / test_without_index_validation.html
blob01e028539d502c713ed12a6cb938fc3f71c83b23
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset='utf-8'>
5 <title>WebGL test: Drawing without index validation</title>
6 <script src='/tests/SimpleTest/SimpleTest.js'></script>
7 <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
9 <script id='vertSource' type='none'>
10 void main(void) {
11 gl_PointSize = 1.0;
12 gl_Position = vec4(0, 0, 0, 1);
14 </script>
16 <script id='fragSource' type='none'>
17 precision mediump float;
19 void main(void) {
20 gl_FragColor = vec4(0, 1, 0, 1);
22 </script>
23 </head>
24 <body>
25 <script>
27 function test() {
28 const c = document.createElement('canvas');
29 c.width = c.height = 1;
30 const gl = c.getContext('webgl');
31 if (!gl) {
32 todo(false, 'WebGL is unavailable.');
33 return;
35 document.body.appendChild(c);
37 const vs = gl.createShader(gl.VERTEX_SHADER);
38 gl.shaderSource(vs, vertSource.innerHTML.trim());
39 gl.compileShader(vs);
40 const fs = gl.createShader(gl.FRAGMENT_SHADER);
41 gl.shaderSource(fs, fragSource.innerHTML.trim());
42 gl.compileShader(fs);
43 const prog = gl.createProgram();
44 gl.attachShader(prog, vs);
45 gl.attachShader(prog, fs);
46 gl.linkProgram(prog);
47 gl.useProgram(prog);
49 gl.clearColor(1,0,0,1);
50 const pixel = new Uint32Array(1);
51 const pixelData = new Uint8Array(pixel.buffer);
53 function expectPixel(expected, info) {
54 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
55 ok(pixel[0] == expected,
56 '[' + info + '] Expected 0x' + expected.toString(16) + ', was 0x' + pixel[0].toString(16));
59 gl.clear(gl.COLOR_BUFFER_BIT);
60 expectPixel(0xFF0000FF, 'Clear');
62 gl.drawArrays(gl.POINTS, 0, 1);
63 expectPixel(0xFF00FF00, 'DrawArrays');
65 const indexBuffer = gl.createBuffer();
66 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
67 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array([0]), gl.STATIC_DRAW);
69 gl.clear(gl.COLOR_BUFFER_BIT);
70 gl.drawElements(gl.POINTS, 1, gl.UNSIGNED_SHORT, 0);
71 expectPixel(0xFF00FF00, 'DrawElements');
73 SimpleTest.finish();
76 SimpleTest.waitForExplicitFinish();
78 const prefArrArr = [
79 ['webgl.force-index-validation', -1]
81 const prefEnv = {'set': prefArrArr};
82 SpecialPowers.pushPrefEnv(prefEnv, test);
84 </script>
85 </body>
86 </html>