Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / transform_feedback / unwritten-output-defaults-to-zero.html
blob615ab9bab18790440c26ed35804e419c89849c55
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 vec4 in_data;
22 uniform int flag;
23 out vec4 out_data;
24 void main(void) {
25 if (flag > 0) {
26 out_data = in_data + vec4(2.0, 3.0, 4.0, 5.0);
29 </script>
30 <script id="fshader" type="x-shader/x-fragment">#version 300 es
31 precision mediump float;
32 out vec4 out_color;
33 void main(void) {
34 out_color = vec4(1.0, 1.0, 1.0, 1.0);
36 </script>
37 <script>
38 "use strict";
39 description("This test verifies if an output variable is specified to be streamed to a transform feedback buffer but not actually written, the value defaults to 0.");
41 debug("");
43 var wtu = WebGLTestUtils;
44 var canvas = document.getElementById("canvas");
45 var gl = wtu.create3DContext(canvas, null, 2);
47 if (!gl) {
48 testFailed("WebGL context does not exist");
49 } else {
50 testPassed("WebGL context exists");
52 debug("");
53 debug("Testing transform feedback works fine");
54 runTest(1);
56 debug("");
57 debug("Testing unwritten output variables default to zero");
58 runTest(0);
61 function runTest(flag) {
62 var in_data = [
63 1.0, 2.0, 3.0, 4.0,
64 2.0, 4.0, 8.0, 16.0,
65 0.75, 0.5, 0.25, 0.0
68 var in_buffer = gl.createBuffer();
69 gl.bindBuffer(gl.ARRAY_BUFFER, in_buffer);
70 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(in_data), gl.STATIC_DRAW);
72 var out_buffer = gl.createBuffer();
73 gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
74 gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, Float32Array.BYTES_PER_ELEMENT * in_data.length, gl.STATIC_DRAW);
76 // Create the transform feedback program
77 var program = wtu.setupTransformFeedbackProgram(gl, ["vshader", "fshader"],
78 ["out_data"], gl.SEPARATE_ATTRIBS,
79 ["in_data"]);
80 var loc = gl.getUniformLocation(program, "flag");
81 if (!program || !loc) {
82 testFailed("Fail to set up the program");
83 return;
85 gl.uniform1i(loc, flag);
86 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Set up program should succeed");
88 // Draw the the transform feedback buffers
89 var tf = gl.createTransformFeedback();
91 gl.enableVertexAttribArray(0);
92 gl.bindBuffer(gl.ARRAY_BUFFER, in_buffer);
93 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 16, 0);
95 gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf);
96 gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, out_buffer);
98 gl.enable(gl.RASTERIZER_DISCARD);
99 gl.beginTransformFeedback(gl.POINTS);
101 gl.drawArrays(gl.POINTS, 0, 3);
103 gl.endTransformFeedback();
104 gl.disable(gl.RASTERIZER_DISCARD);
106 gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
108 // Verify the output buffer contents
109 var expected_data;
110 if (flag > 0) {
111 expected_data = [
112 3.0, 5.0, 7.0, 9.0,
113 4.0, 7.0, 12.0, 21.0,
114 2.75, 3.5, 4.25, 5.0
116 } else {
117 expected_data = [
118 0.0, 0.0, 0.0, 0.0,
119 0.0, 0.0, 0.0, 0.0,
120 0.0, 0.0, 0.0, 0.0
123 gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, out_buffer);
124 wtu.checkFloatBuffer(gl, gl.TRANSFORM_FEEDBACK_BUFFER, expected_data);
127 debug("");
128 var successfullyParsed = true;
129 </script>
130 <script src="../../js/js-test-post.js"></script>
132 </body>
133 </html>