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.
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>
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
26 out_data = in_data + vec4(
2.0,
3.0,
4.0,
5.0);
30 <script id=
"fshader" type=
"x-shader/x-fragment">#version
300 es
31 precision mediump float;
34 out_color = vec4(
1.0,
1.0,
1.0,
1.0);
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.");
43 var wtu
= WebGLTestUtils
;
44 var canvas
= document
.getElementById("canvas");
45 var gl
= wtu
.create3DContext(canvas
, null, 2);
48 testFailed("WebGL context does not exist");
50 testPassed("WebGL context exists");
53 debug("Testing transform feedback works fine");
57 debug("Testing unwritten output variables default to zero");
61 function runTest(flag
) {
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
,
80 var loc
= gl
.getUniformLocation(program
, "flag");
81 if (!program
|| !loc
) {
82 testFailed("Fail to set up the program");
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
113 4.0, 7.0, 12.0, 21.0,
123 gl
.bindBuffer(gl
.TRANSFORM_FEEDBACK_BUFFER
, out_buffer
);
124 wtu
.checkFloatBuffer(gl
, gl
.TRANSFORM_FEEDBACK_BUFFER
, expected_data
);
128 var successfullyParsed
= true;
130 <script src=
"../../js/js-test-post.js"></script>