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'
>
12 gl_Position = vec4(
0,
0,
0,
1);
16 <script id='fragSource' type='none'
>
17 precision mediump float;
20 gl_FragColor = vec4(
0,
1,
0,
1);
28 const c
= document
.createElement('canvas');
29 c
.width
= c
.height
= 1;
30 const gl
= c
.getContext('webgl');
32 todo(false, 'WebGL is unavailable.');
35 document
.body
.appendChild(c
);
37 const vs
= gl
.createShader(gl
.VERTEX_SHADER
);
38 gl
.shaderSource(vs
, vertSource
.innerHTML
.trim());
40 const fs
= gl
.createShader(gl
.FRAGMENT_SHADER
);
41 gl
.shaderSource(fs
, fragSource
.innerHTML
.trim());
43 const prog
= gl
.createProgram();
44 gl
.attachShader(prog
, vs
);
45 gl
.attachShader(prog
, fs
);
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');
76 SimpleTest
.waitForExplicitFinish();
79 ['webgl.force-index-validation', -1]
81 const prefEnv
= {'set': prefArrArr
};
82 SpecialPowers
.pushPrefEnv(prefEnv
, test
);