tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gl-get-frag-data-location.html (3902B)


      1 <!--
      2 Copyright (c) 2021 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 -->
      6 
      7 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     11 <title>WebGL Conformance Tests: Verify getFragDataLocation</title>
     12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
     13 <script src="../../js/desktop-gl-constants.js"></script>
     14 <script src="../../js/js-test-pre.js"></script>
     15 <script src="../../js/webgl-test-utils.js"></script>
     16 </head>
     17 <body>
     18 <div id="description"></div>
     19 <canvas id="canvas" style="width: 4px; height: 4px;"> </canvas>
     20 <div id="console"></div>
     21 <script id="vs" type="x-shader/x-vertex">#version 300 es
     22 void main() {
     23  gl_Position = vec4(0, 0, 0, 1);
     24 }
     25 </script>
     26 
     27 <script id="fs" type="x-shader/x-fragment">#version 300 es
     28 precision mediump float;
     29 layout(location = 2) out vec4 fragColor0;
     30 layout(location = 0) out vec4 fragColor1;
     31 void main() {
     32  fragColor0 = vec4(0, 1, 0, 1);
     33  fragColor1 = vec4(1, 0, 0, 1);
     34 }
     35 </script>
     36 
     37 <script id="fs-array" type="x-shader/x-fragment">#version 300 es
     38 precision mediump float;
     39 out vec4 fragColor[2];
     40 void main() {
     41  fragColor[0] = vec4(0, 1, 0, 1);
     42  fragColor[1] = vec4(1, 0, 0, 1);
     43 }
     44 </script>
     45 
     46 <script id="vs-es2" type="x-shader/x-vertex">
     47 void main() {
     48  gl_Position = vec4(0, 0, 0, 1);
     49 }
     50 </script>
     51 <script id="fs-es2" type="x-shader/x-fragment">
     52 precision mediump float;
     53 void main() {
     54  gl_FragColor = vec4(0, 1, 0, 1);
     55 }
     56 </script>
     57 
     58 <script>
     59 "use strict";
     60 description("This test verifies getFragDataLocation behaviors.");
     61 
     62 debug("");
     63 
     64 var wtu = WebGLTestUtils;
     65 var canvas = document.getElementById("canvas");
     66 var gl = wtu.create3DContext(canvas, null, 2);
     67 
     68 if (!gl) {
     69  testFailed("WebGL context does not exist");
     70 } else {
     71  testPassed("WebGL context exists");
     72  runTests();
     73 }
     74 
     75 function runTests() {
     76  window.program = wtu.setupProgram(gl, ["vs", "fs"]);
     77  window.programArray = wtu.setupProgram(gl, ["vs", "fs-array"]);
     78  window.programEs2 = wtu.setupProgram(gl, ["vs-es2", "fs-es2"]);
     79  if (!program || !programArray || !programEs2) {
     80    testFailed("Set up program failed");
     81    return;
     82  }
     83  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from set up");
     84 
     85  shouldBe("gl.getFragDataLocation(program, 'gl_FragColor')", "-1");
     86  shouldBe("gl.getFragDataLocation(programArray, 'gl_FragColor')", "-1");
     87  shouldBe("gl.getFragDataLocation(programEs2, 'gl_FragColor')", "-1");
     88  shouldBe("gl.getFragDataLocation(program, 'gl_FragData')", "-1");
     89  shouldBe("gl.getFragDataLocation(programArray, 'gl_FragData')", "-1");
     90  shouldBe("gl.getFragDataLocation(programEs2, 'gl_FragData')", "-1");
     91  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from gl_* queries");
     92 
     93  var loc0 = gl.getFragDataLocation(program, "fragColor0");
     94  var loc1 = gl.getFragDataLocation(program, "fragColor1");
     95  if (loc0 != 2 || loc1 != 0) {
     96    testFailed("Fail to query scalar output variable locations, " +
     97               "expected: fragColor0->2, fragColor1->0, " +
     98               "got: fragColor0->" + loc0 + ", fragColor1->" + loc1);
     99  } else {
    100    testPassed("getFragDataLocation on scalar variables works fine");
    101  }
    102 
    103  var loc = gl.getFragDataLocation(programArray, "fragColor");
    104  loc0 = gl.getFragDataLocation(programArray, "fragColor[0]");
    105  loc1 = gl.getFragDataLocation(programArray, "fragColor[1]");
    106  if (loc < 0 || loc0 < 0 || loc1 < 0 || loc != loc0 || loc0 + 1 != loc1) {
    107    testFailed("Fail to query scalar output variable locations, " +
    108               "expected: fragColor->0, fragColor[0]->0, fragColor[1]->1, " +
    109               "got: fragColor->" + loc + ", fragColor[0]->" + loc0 + ", fragColor[1]->" + loc1);
    110  } else {
    111    testPassed("getFragDataLocation on variable arrays works fine");
    112  }
    113  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from testing");
    114 }
    115 
    116 var successfullyParsed = true;
    117 </script>
    118 <script src="../../js/js-test-post.js"></script>
    119 
    120 </body>
    121 </html>