tor-browser

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

gl-bindattriblocation-aliasing.js (2147B)


      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 
      7 "use strict";
      8 
      9 var runBindAttribLocationAliasingTest = function(wtu, gl, glFragmentShader, vertexShaderTemplate) {
     10    var typeInfo = [
     11        { type: 'float',    asVec4: 'vec4(0.0, $(var), 0.0, 1.0)' },
     12        { type: 'vec2',     asVec4: 'vec4($(var), 0.0, 1.0)' },
     13        { type: 'vec3',     asVec4: 'vec4($(var), 1.0)' },
     14        { type: 'vec4',     asVec4: '$(var)' },
     15    ];
     16    var maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
     17    // Test all type combinations of a_1 and a_2.
     18    typeInfo.forEach(function(typeInfo1) {
     19        typeInfo.forEach(function(typeInfo2) {
     20            debug('attribute_1: ' + typeInfo1.type + ' attribute_2: ' + typeInfo2.type);
     21            var replaceParams = {
     22                type_1: typeInfo1.type,
     23                type_2: typeInfo2.type,
     24                gl_Position_1: wtu.replaceParams(typeInfo1.asVec4, {var: 'a_1'}),
     25                gl_Position_2: wtu.replaceParams(typeInfo2.asVec4, {var: 'a_2'})
     26            };
     27            var strVertexShader = wtu.replaceParams(vertexShaderTemplate, replaceParams);
     28            var glVertexShader = wtu.loadShader(gl, strVertexShader, gl.VERTEX_SHADER);
     29            assertMsg(glVertexShader != null, "Vertex shader compiled successfully.");
     30            // Bind both a_1 and a_2 to the same position and verify the link fails.
     31            // Do so for all valid positions available.
     32            for (var l = 0; l < maxAttributes; l++) {
     33                var glProgram = gl.createProgram();
     34                gl.bindAttribLocation(glProgram, l, 'a_1');
     35                gl.bindAttribLocation(glProgram, l, 'a_2');
     36                gl.attachShader(glProgram, glVertexShader);
     37                gl.attachShader(glProgram, glFragmentShader);
     38                gl.linkProgram(glProgram);
     39                var linkStatus = gl.getProgramParameter(glProgram, gl.LINK_STATUS);
     40                assertMsg(!linkStatus, "Link should fail when both attributes are aliased to location " + l);
     41            }
     42        });
     43    });
     44 };