tor-browser

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

gl-bindAttribLocation-nonexistent-attribute.html (2933B)


      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 -->
      6 <!DOCTYPE html>
      7 <html>
      8 <head>
      9 <meta charset="utf-8">
     10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
     11 <script src="../../js/js-test-pre.js"></script>
     12 <script src="../../js/webgl-test-utils.js"></script>
     13 <title>bindAttribLocation with nonexistent attribute name</title>
     14 </head>
     15 <body>
     16 <div id="description"></div>
     17 <div id="console"></div>
     18 <canvas id="canvas" width="8" height="8"></canvas>
     19 <script id="vertexShader" type="text/something-not-javascript">
     20 precision highp float;
     21 attribute vec4 attr;
     22 void main() {
     23    gl_Position = vec4(attr);
     24 }
     25 </script>
     26 <script>
     27 "use strict";
     28 description("This test verifies that calling bindAttribLocation with a non-existent attribute location is fine.");
     29 
     30 // OpenGL ES 2.0.25 section 2.10 page 34.
     31 
     32 var wtu = WebGLTestUtils;
     33 var canvas = document.getElementById("canvas");
     34 var gl = wtu.create3DContext(canvas);
     35 var fragmentShader = wtu.loadShader(gl, wtu.simpleColorFragmentShader, gl.FRAGMENT_SHADER);
     36 var vertexShader = wtu.loadShaderFromScript(gl, 'vertexShader', gl.VERTEX_SHADER);
     37 assertMsg(vertexShader != null, "Vertex shader compiled successfully.");
     38 
     39 var checkAttribLocation = function(program, expectedLocation) {
     40    var location = gl.getAttribLocation(program, 'attr');
     41    if (location != expectedLocation) {
     42        testFailed('Unexpected location for attr: ' + location);
     43    } else {
     44        testPassed('Location of attr is: ' + location);
     45    }
     46 }
     47 
     48 var testProgramNonExistentAttributeBound = function() {
     49    var program = gl.createProgram();
     50    gl.bindAttribLocation(program, 0, 'attr');
     51    gl.bindAttribLocation(program, 1, 'bogus_attr');
     52    gl.attachShader(program, vertexShader);
     53    gl.attachShader(program, fragmentShader);
     54    gl.linkProgram(program);
     55    var linkStatus = gl.getProgramParameter(program, gl.LINK_STATUS);
     56    expectTrue(linkStatus, "Link should succeed even if a non-existent attribute is bound.");
     57    if (linkStatus) {
     58        checkAttribLocation(program, 0);
     59    }
     60 };
     61 var testProgramNonExistentAttributeOverlap = function() {
     62    var program = gl.createProgram();
     63    gl.bindAttribLocation(program, 1, 'attr');
     64    gl.bindAttribLocation(program, 1, 'bogus_attr');
     65    gl.attachShader(program, vertexShader);
     66    gl.attachShader(program, fragmentShader);
     67    gl.linkProgram(program);
     68    var linkStatus = gl.getProgramParameter(program, gl.LINK_STATUS);
     69    expectTrue(linkStatus, "Link should succeed even if a non-existent attribute is bound to the same location as an attribute that's present in the shader text.");
     70    if (linkStatus) {
     71        checkAttribLocation(program, 1);
     72    }
     73 };
     74 
     75 testProgramNonExistentAttributeBound();
     76 testProgramNonExistentAttributeOverlap();
     77 
     78 var successfullyParsed = true;
     79 </script>
     80 <script src="../../js/js-test-post.js"></script>
     81 </body>
     82 </html>