Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / buffers / index-validation-with-resized-buffer.html
blob182768085fcc7a33b6afd81b762d4c2ed72fea37
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../js/js-test-pre.js"></script>
13 <script src="../../js/webgl-test-utils.js"></script>
14 </head>
15 <body>
16 <canvas id="example" width="1" height="1"></canvas>
17 <div id="description"></div>
18 <div id="console"></div>
20 <script id="vs" type="x-shader/x-vertex">
21 attribute vec4 vPosition;
22 attribute vec4 vColor;
23 varying vec4 color;
24 void main() {
25 gl_Position = vPosition;
26 color = vColor;
28 </script>
29 <script id="fs" type="x-shader/x-fragment">
30 precision mediump float;
31 varying vec4 color;
32 void main() {
33 gl_FragColor = color;
35 </script>
36 <script>
37 "use strict";
38 description('Test that updating the size of a vertex buffer is properly noticed by the WebGL implementation.')
40 var wtu = WebGLTestUtils;
41 var gl = wtu.create3DContext("example");
42 var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vColor"]);
43 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initialization");
45 var vertexObject = gl.createBuffer();
46 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
47 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
48 [-1,1,0, 1,1,0, -1,-1,0,
49 -1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW);
50 gl.enableVertexAttribArray(0);
51 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
52 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup");
54 var texCoordObject = gl.createBuffer();
55 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject);
56 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(
57 [0,0, 1,0, 0,1,
58 0,1, 1,0, 1,1]), gl.STATIC_DRAW);
59 gl.enableVertexAttribArray(1);
60 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
61 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture coord setup");
63 // Now resize these buffers because we want to change what we're drawing.
64 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
65 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
66 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0,
67 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW);
68 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after vertex redefinition");
69 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject);
70 gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([
71 255, 0, 0, 255,
72 255, 0, 0, 255,
73 255, 0, 0, 255,
74 255, 0, 0, 255,
75 0, 255, 0, 255,
76 0, 255, 0, 255,
77 0, 255, 0, 255,
78 0, 255, 0, 255]), gl.STATIC_DRAW);
79 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0);
80 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition");
82 var numQuads = 2;
83 var indices = new Uint8Array(numQuads * 6);
84 for (var ii = 0; ii < numQuads; ++ii) {
85 var offset = ii * 6;
86 var quad = (ii == (numQuads - 1)) ? 4 : 0;
87 indices[offset + 0] = quad + 0;
88 indices[offset + 1] = quad + 1;
89 indices[offset + 2] = quad + 2;
90 indices[offset + 3] = quad + 2;
91 indices[offset + 4] = quad + 1;
92 indices[offset + 5] = quad + 3;
94 var indexObject = gl.createBuffer();
95 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject);
96 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
97 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices");
98 gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0);
99 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
101 debug("")
102 var successfullyParsed = true;
103 </script>
105 <script src="../../js/js-test-post.js"></script>
106 </body>
107 </html>