Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / more / functions / drawElements.html
blobf0c3bb3d27dd7f97d62f7c565c84283e780ab7a0
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <!--
6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
9 -->
10 <link rel="stylesheet" type="text/css" href="../unit.css" />
11 <script type="application/javascript" src="../unit.js"></script>
12 <script type="application/javascript" src="../util.js"></script>
13 <script type="application/javascript">
15 var verts = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
16 var normals = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0];
17 var texcoords = [0.0,0.0, 1.0,0.0, 0.0,1.0];
18 var indices = [0,1,2]
20 Tests.startUnit = function () {
21 var canvas = document.getElementById('gl');
22 var gl = wrapGLContext(getGLContext(canvas));
23 var prog = new Shader(gl, 'vert', 'frag');
24 prog.use();
25 var sh = prog.shader.program;
26 var v = gl.getAttribLocation(sh, 'Vertex');
27 var n = gl.getAttribLocation(sh, 'Normal');
28 var t = gl.getAttribLocation(sh, 'Tex');
29 return [gl,prog,v,n,t];
32 Tests.setup = function(gl, prog, v,n,t) {
33 assert(0 == gl.getError());
34 return [gl, prog, v,n,t];
36 Tests.teardown = function(gl, prog, v,n,t) {
37 gl.disableVertexAttribArray(v);
38 gl.disableVertexAttribArray(n);
39 gl.disableVertexAttribArray(t);
42 Tests.endUnit = function(gl, prog, v,n,t) {
43 prog.destroy();
46 Tests.testDrawElementsVBO = function(gl, prog, v,n,t) {
47 var vbo = new VBO(gl,
48 {size:3, data:Quad.vertices},
49 {elements:true, data:Quad.indices});
50 vbo.draw(v);
51 assert(gl.NO_ERROR == checkError(gl, "vbo.draw"));
52 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);});
53 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);});
54 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*1);});
55 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);});
56 vbo.destroy();
57 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy"));
60 Tests.testDrawElementsVBOMulti = function(gl, prog, v,n,t) {
61 // creates VBOs for the quad arrays, binds them with
62 // vertexAttribPointer and calls drawElements
63 var vbo = new VBO(gl,
64 {size:3, data:Quad.vertices},
65 {size:3, data:Quad.normals},
66 {size:2, data:Quad.texcoords},
67 {elements:true, data:Quad.indices});
68 vbo.draw(v, n, t);
69 assert(gl.NO_ERROR == checkError(gl, "vbo.draw"));
70 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);});
71 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*2);});
72 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);});
73 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);});
74 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range",
75 function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2);});
76 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 2",
77 function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2);});
78 gl.bindBuffer(gl.ARRAY_BUFFER, null);
79 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[1]);
80 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0);
81 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);});
82 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*2);});
83 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);});
84 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);});
85 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 3",
86 function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2);});
87 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 4",
88 function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2);});
89 vbo.destroy();
90 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy"));
94 </script>
95 <script id="vert" type="x-shader/x-vertex">
96 attribute vec3 Vertex;
97 attribute vec3 Normal;
98 attribute vec2 Tex;
100 varying vec4 texCoord0;
101 void main()
103 gl_Position = vec4(Vertex * Normal, 1.0);
104 texCoord0 = vec4(Tex,0.0,0.0) + gl_Position;
106 </script>
107 <script id="frag" type="x-shader/x-fragment">
108 precision mediump float;
110 varying vec4 texCoord0;
111 void main()
113 vec4 c = texCoord0;
114 gl_FragColor = c;
116 </script>
119 <style>canvas{ position:absolute; }</style>
120 </head><body>
121 <canvas id="gl" width="1" height="1"></canvas>
122 </body></html>