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 outAttrib1 = position;
27 outAttrib2 = position;
28 gl_Position = vec4(position,
1);
31 <script id=
"fshader" type=
"x-shader/x-fragment">#version
300 es
32 precision mediump float;
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.");
47 var wtu
= WebGLTestUtils
;
48 var canvas
= document
.getElementById("canvas");
49 var gl
= wtu
.create3DContext(canvas
, null, 2);
53 testFailed("WebGL context does not exist");
55 testPassed("WebGL context exists");
58 debug("Testing transform feedback with two unreferenced outputs");
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
;
73 function drawQuad(depth
) {
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);
89 // Create the transform feedback program
90 var program
= wtu
.setupTransformFeedbackProgram(gl
, ["vshader", "fshader"],
91 ["outAttrib1", "outAttrib2"], gl
.INTERLEAVED_ATTRIBS
,
94 testFailed("Fail to set up the program");
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,
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");
111 gl
.useProgram(program
)
112 gl
.beginTransformFeedback(gl
.TRIANGLES
);
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
);
131 var successfullyParsed
= true;
133 <script src=
"../../js/js-test-post.js"></script>