content/canvas/test/webgl-conformance/extra/out-of-bounds-uniform-array-access.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!--
     2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5  -->
     6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     7   "http://www.w3.org/TR/html4/loose.dtd">
     8 <html>
     9 <head>
    10 <meta charset="utf-8">
    11 <title>WebGL ouf of bounds uniform array access.</title>
    12 <link rel="stylesheet" href="../resources/js-test-style.css"/>
    13 <script src="../resources/js-test-pre.js"></script>
    14 <script src="../conformance/resources/webgl-test-utils.js"> </script>
    15 </head>
    16 <body style="background: #666;">
    17 <div id="description"></div>
    18 <div id="console"></div>
    19 <div>elem mult: <span id="elemMultDisplay"></span></div>
    20 <input type="range" id="elemMult" value="4" min="0" max="2048" style="width: 100%;"/>
    21 <div>line width: <span id="lineWidthDisplay"></span></div>
    22 <input type="range" id="lineWidth" value="512" min="0" max="2540" style="width: 100%;"/>
    23 <canvas id="example" width="256" height="256" style="background: black;">
    24 </canvas>
    25 <script id="vshader" type="x-shader/x-vertex">
    26 attribute vec4 vPosition;
    27 varying vec4 v_color;
    28 uniform float lineWidth;
    29 uniform int elemMult;
    30 uniform vec4 someArray[2];
    31 void main()
    32 {
    33     vec2 texcoord = vec2(vPosition.xy * 0.5 + vec2(0.5, 0.5));
    34     int index = int(texcoord.x + texcoord.y * lineWidth) * elemMult;
    35     v_color = someArray[index];
    36     gl_Position = vPosition;
    37 }
    38 </script>
    40 <script id="fshader" type="x-shader/x-fragment">
    41 precision mediump float;
    42 varying vec4 v_color;
    43 void main()
    44 {
    45   gl_FragColor = v_color * vec4(1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0) + vec4(0,0,0,0.5);
    46 }
    47 </script>
    48 <script>
    49 window.onload = main;
    50 debug("Tests a WebGL program that accesses out of bounds uniform array elements");
    52 function main() {
    53   var wtu = WebGLTestUtils;
    54   var gl = wtu.create3DContext("example");
    55   var program = wtu.setupProgram(
    56       gl,
    57       ['vshader', 'fshader'],
    58       ['vPosition'], [0]);
    59   var gridRes = 255;
    60   wtu.setupQuad(gl, gridRes, 0);
    61   var lineWidthLoc = gl.getUniformLocation(program, "lineWidth");
    62   var elemMultLoc = gl.getUniformLocation(program, "elemMult");
    63   assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
    65   var lineWidth = 512;
    66   var lineWidthElem = document.getElementById("lineWidth");
    67   var lineWidthDisplayElem = document.getElementById("lineWidthDisplay");
    69   lineWidthElem.value = lineWidth;
    71   lineWidthElem.addEventListener('change', function(event) {
    72       //console.log(event.target.value);
    73       lineWidth = event.target.value;
    74       draw();
    75     }, false);
    77   var elemMult = 4;
    78   var elemMultElem = document.getElementById("elemMult");
    79   var elemMultDisplayElem = document.getElementById("elemMultDisplay");
    81   elemMultElem.value = elemMult;
    83   elemMultElem.addEventListener('change', function(event) {
    84       //console.log(event.target.value);
    85       elemMult = event.target.value;
    86       draw();
    87     }, false);
    89   draw();
    91   function draw() {
    92     lineWidthDisplayElem.innerText = lineWidth;
    93     elemMultDisplayElem.innerText = elemMult;
    94     gl.uniform1f(lineWidthLoc, lineWidth);
    95     gl.uniform1i(elemMultLoc, elemMult);
    96     gl.drawElements(gl.TRIANGLES, gridRes * gridRes * 6, gl.UNSIGNED_SHORT, 0);
    97   }
    99   successfullyParsed = true;
   100 }
   102 </script>
   103 </body>
   104 </html>

mercurial