tor-browser

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

attrib-location-length-limits.html (4150B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <!--
      6 Copyright (c) 2019 The Khronos Group Inc.
      7 Use of this source code is governed by an MIT-style license that can be
      8 found in the LICENSE.txt file.
      9 -->
     10 <title>WebGL attrib location length tests</title>
     11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     12 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
     13 <script src="../../../js/js-test-pre.js"></script>
     14 <script src="../../../js/webgl-test-utils.js"> </script>
     15 </head>
     16 <body>
     17 <canvas id="example" width="50" height="50">
     18 There is supposed to be an example drawing here, but it's not important.
     19 </canvas>
     20 <div id="description">Verify limits on the lengths of attribute locations per WebGL spec, "Maximum Uniform and Attribute Location Lengths".</div>
     21 <div id="console"></div>
     22 <script id="goodVertexShader" type="x-shader/x-vertex">
     23 // A vertex shader where the needed attrib location is exactly 256 characters.
     24 attribute vec4 vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
     25 
     26 void main()
     27 {
     28    gl_Position = vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
     29 }
     30 </script>
     31 <script id="badVertexShader" type="x-shader/x-vertex">
     32 // A vertex shader where the needed attrib location is 257 characters.
     33 attribute vec4 vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567;
     34 
     35 void main()
     36 {
     37    gl_Position = vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567;
     38 }
     39 </script>
     40 <script id="fragmentShader" type="x-shader/x-fragment">
     41 precision mediump float;
     42 
     43 void main() {
     44    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
     45 }
     46 </script>
     47 <script>
     48 "use strict";
     49 description("test attrib location length limit");
     50 
     51 var wtu = WebGLTestUtils;
     52 var gl = wtu.create3DContext("example");
     53 
     54 debug("Test attrib location underneath the length limit");
     55 var program = wtu.loadProgramFromScript(gl, "goodVertexShader", "fragmentShader");
     56 shouldBe('gl.getProgramParameter(program, gl.LINK_STATUS)', 'true');
     57 var attrib256Name = "vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";
     58 gl.bindAttribLocation(program, 0, attrib256Name);
     59 wtu.glErrorShouldBe(gl, gl.NONE);
     60 var attribLoc = gl.getAttribLocation(program, attrib256Name);
     61 if (attribLoc == -1) {
     62    testFailed("attrib location was -1, should not be");
     63 } else {
     64    testPassed("attrib location should not be -1");
     65 }
     66 wtu.glErrorShouldBe(gl, gl.NONE);
     67 
     68 debug("Test attrib location over the length limit");
     69 var attrib257Name = attrib256Name + "7";
     70 
     71 debug("Shader compilation or link should fail");
     72 shouldBe('wtu.loadProgramFromScriptExpectError(gl, "badVertexShader", "fragmentShader")', 'null');
     73 wtu.glErrorShouldBe(gl, gl.NONE);
     74 
     75 debug("Attempt to bind too-long attrib location should produce error");
     76 program = gl.createProgram();
     77 gl.bindAttribLocation(program, 0, attrib257Name);
     78 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE);
     79 
     80 debug("Attempt to fetch too-long attrib location should produce error");
     81 program = wtu.loadStandardProgram(gl);
     82 shouldBe('gl.getAttribLocation(program, attrib257Name)', '-1');
     83 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE);
     84 
     85 var successfullyParsed = true;
     86 </script>
     87 <script src="../../../js/js-test-post.js"></script>
     88 </body>
     89 </html>