Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / transform_feedback / two-unreferenced-varyings.html
blob2173fd35aeda81c88a4174ebe0bc487c7dae2de0
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 <title>WebGL Transform Feedback Conformance Tests</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
19 <div id="console"></div>
20 <script id="vshader" type="x-shader/x-vertex">#version 300 es
21 in vec3 position;
22 out vec3 outAttrib1;
23 out vec3 outAttrib2;
24 void main()
26 outAttrib1 = position;
27 outAttrib2 = position;
28 gl_Position = vec4(position, 1);
30 </script>
31 <script id="fshader" type="x-shader/x-fragment">#version 300 es
32 precision mediump float;
33 out vec4 color;
34 in vec3 outAttrib1;
35 in vec3 outAttrib2;
36 void main()
38 color = vec4(0);
40 </script>
41 <script>
42 "use strict";
43 description("This test covers an ANGLE bug with two transform feedback varyings. When the two are declared, but not referenced in the fragment shader, ANGLE would fail capture.");
45 debug("");
47 var wtu = WebGLTestUtils;
48 var canvas = document.getElementById("canvas");
49 var gl = wtu.create3DContext(canvas, null, 2);
50 var quadVB;
52 if (!gl) {
53 testFailed("WebGL context does not exist");
54 } else {
55 testPassed("WebGL context exists");
57 debug("");
58 debug("Testing transform feedback with two unreferenced outputs");
59 runTest();
62 function getQuadVerts(depth) {
63 var quadVerts = new Float32Array(3 * 6);
64 quadVerts[0] = -1.0; quadVerts[1] = 1.0; quadVerts[2] = depth;
65 quadVerts[3] = -1.0; quadVerts[4] = -1.0; quadVerts[5] = depth;
66 quadVerts[6] = 1.0; quadVerts[7] = -1.0; quadVerts[8] = depth;
67 quadVerts[9] = -1.0; quadVerts[10] = 1.0; quadVerts[11] = depth;
68 quadVerts[12] = 1.0; quadVerts[13] = -1.0; quadVerts[14] = depth;
69 quadVerts[15] = 1.0; quadVerts[16] = 1.0; quadVerts[17] = depth;
70 return quadVerts;
73 function drawQuad(depth) {
74 if (!quadVB) {
75 quadVB = gl.createBuffer()
78 var quadVerts = getQuadVerts(depth);
80 gl.bindBuffer(gl.ARRAY_BUFFER, quadVB);
81 gl.bufferData(gl.ARRAY_BUFFER, quadVerts, gl.STATIC_DRAW);
82 gl.vertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 0, 0);
83 gl.enableVertexAttribArray(0);
84 gl.drawArrays(gl.TRIANGLES, 0, 6);
87 function runTest() {
89 // Create the transform feedback program
90 var program = wtu.setupTransformFeedbackProgram(gl, ["vshader", "fshader"],
91 ["outAttrib1", "outAttrib2"], gl.INTERLEAVED_ATTRIBS,
92 ["position"]);
93 if (!program) {
94 testFailed("Fail to set up the program");
95 return;
98 // Init transform feedback buffers
99 var out_buffer = gl.createBuffer();
100 gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
101 gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * 3 * 2 * 6,
102 gl.STREAM_DRAW);
104 var tf = gl.createTransformFeedback();
106 gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf);
107 gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, out_buffer);
108 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Init transform feedback should succeed");
110 // Draw the quad
111 gl.useProgram(program)
112 gl.beginTransformFeedback(gl.TRIANGLES);
113 drawQuad(0.5);
114 gl.endTransformFeedback();
115 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Draw with transform feedback should succeed");
117 // Verify the output buffer contents
118 var quadVerts = getQuadVerts(0.5);
119 var expected_data = [];
120 for (var i = 0; i < quadVerts.length; i += 3) {
121 for (var count = 0; count < 2; count++) {
122 expected_data[expected_data.length] = quadVerts[i];
123 expected_data[expected_data.length] = quadVerts[i+1];
124 expected_data[expected_data.length] = quadVerts[i+2];
127 wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expected_data);
130 debug("");
131 var successfullyParsed = true;
132 </script>
133 <script src="../../js/js-test-post.js"></script>
135 </body>
136 </html>