tor-browser

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

gl-bind-attrib-location-test.html (4472B)


      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 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     11 <title>WebGL BindAttribLocation 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>
     15 </head>
     16 <body>
     17 <div id="description"></div>
     18 <div id="console"></div>
     19 <canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></canvas>
     20 <script id="vshader" type="text/something-not-javascript">
     21 attribute vec4 vPosition;
     22 attribute vec4 vColor;
     23 varying vec4 color;
     24 void main()
     25 {
     26  gl_Position = vPosition;
     27  color = vColor;
     28 }
     29 </script>
     30 <script id="fshader" type="text/something-not-javascript">
     31 precision mediump float;
     32 
     33 varying vec4 color;
     34 void main()
     35 {
     36  gl_FragColor = color;
     37 }
     38 </script>
     39 <script>
     40 "use strict";
     41 description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.");
     42 
     43 debug("");
     44 debug("Canvas.getContext");
     45 
     46 var wtu = WebGLTestUtils;
     47 var gl = wtu.create3DContext("canvas");
     48 shouldBeNonNull("gl");
     49 
     50 debug("");
     51 debug("Checking gl.bindAttribLocation.");
     52 
     53 var program = gl.createProgram();
     54 gl.bindAttribLocation(program, 0, "gl_foo");
     55 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
     56    "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
     57 gl.bindAttribLocation(program, 0, "gl_TexCoord0");
     58 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
     59    "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
     60 
     61 var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER);
     62 var fs = wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER);
     63 gl.attachShader(program, vs);
     64 gl.attachShader(program, fs);
     65 
     66 var positions = gl.createBuffer();
     67 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
     68 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
     69 
     70 var colors = gl.createBuffer();
     71 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
     72 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
     73    0,1,0,1,
     74    0,1,0,1,
     75    0,1,0,1]), gl.STATIC_DRAW);
     76 
     77 function setBindLocations(colorLocation, positionLocation) {
     78  gl.bindAttribLocation(program, positionLocation, "vPosition");
     79  gl.bindAttribLocation(program, colorLocation, "vColor");
     80  gl.linkProgram(program);
     81  gl.useProgram(program);
     82  var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
     83  assertMsg(linked, "program linked successfully");
     84 
     85  debug("vPosition:" + gl.getAttribLocation(program, "vPosition"))
     86  debug("vColor   :" + gl.getAttribLocation(program, "vColor"))
     87  assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation,
     88            "location of vPosition should be " + positionLocation);
     89  assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
     90            "location of vColor should be " + colorLocation);
     91 
     92  var ploc = gl.getAttribLocation(program, "vPosition");
     93  var cloc = gl.getAttribLocation(program, "vColor");
     94  gl.bindBuffer(gl.ARRAY_BUFFER, positions);
     95  gl.enableVertexAttribArray(positionLocation);
     96  gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
     97  gl.bindBuffer(gl.ARRAY_BUFFER, colors);
     98  gl.enableVertexAttribArray(colorLocation);
     99  gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
    100 }
    101 
    102 function checkDraw(colorLocation, positionLocation, r, g, b, a) {
    103  gl.clearColor(0, 0, 0, 1);
    104  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    105  gl.drawArrays(gl.TRIANGLES, 0, 3);
    106 
    107  var width = 50;
    108  var height = 50;
    109 
    110  // Test several locations
    111  wtu.checkCanvasRect(gl, 0, 0, width, 1, [0, 0, 0, 255],
    112      "First line should be all black");
    113  wtu.checkCanvasRect(gl, 20, 15, 10, 1, [r, g, b, a],
    114      "Line 15 should be red for at least 10 rgba pixels starting 20 pixels in");
    115  wtu.checkCanvasRect(gl, 0, height - 1, width, 0, [0, 0, 0, 255],
    116      "Last line should be all black");
    117 
    118  gl.disableVertexAttribArray(positionLocation);
    119  gl.disableVertexAttribArray(colorLocation);
    120 }
    121 
    122 setBindLocations(2, 3);
    123 checkDraw(2, 3, 0, 255, 0, 255);
    124 
    125 setBindLocations(0, 3);
    126 gl.disableVertexAttribArray(0);
    127 gl.vertexAttrib4f(0, 1, 0, 0, 1);
    128 checkDraw(0, 3, 255, 0, 0, 255);
    129 
    130 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
    131 
    132 debug("");
    133 var successfullyParsed = true;
    134 
    135 </script>
    136 <script src="../../js/js-test-post.js"></script>
    137 
    138 </body>
    139 </html>