1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/extra/out-of-bounds-uniform-array-access.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 1.10 + "http://www.w3.org/TR/html4/loose.dtd"> 1.11 +<html> 1.12 +<head> 1.13 +<meta charset="utf-8"> 1.14 +<title>WebGL ouf of bounds uniform array access.</title> 1.15 +<link rel="stylesheet" href="../resources/js-test-style.css"/> 1.16 +<script src="../resources/js-test-pre.js"></script> 1.17 +<script src="../conformance/resources/webgl-test-utils.js"> </script> 1.18 +</head> 1.19 +<body style="background: #666;"> 1.20 +<div id="description"></div> 1.21 +<div id="console"></div> 1.22 +<div>elem mult: <span id="elemMultDisplay"></span></div> 1.23 +<input type="range" id="elemMult" value="4" min="0" max="2048" style="width: 100%;"/> 1.24 +<div>line width: <span id="lineWidthDisplay"></span></div> 1.25 +<input type="range" id="lineWidth" value="512" min="0" max="2540" style="width: 100%;"/> 1.26 +<canvas id="example" width="256" height="256" style="background: black;"> 1.27 +</canvas> 1.28 +<script id="vshader" type="x-shader/x-vertex"> 1.29 +attribute vec4 vPosition; 1.30 +varying vec4 v_color; 1.31 +uniform float lineWidth; 1.32 +uniform int elemMult; 1.33 +uniform vec4 someArray[2]; 1.34 +void main() 1.35 +{ 1.36 + vec2 texcoord = vec2(vPosition.xy * 0.5 + vec2(0.5, 0.5)); 1.37 + int index = int(texcoord.x + texcoord.y * lineWidth) * elemMult; 1.38 + v_color = someArray[index]; 1.39 + gl_Position = vPosition; 1.40 +} 1.41 +</script> 1.42 + 1.43 +<script id="fshader" type="x-shader/x-fragment"> 1.44 +precision mediump float; 1.45 +varying vec4 v_color; 1.46 +void main() 1.47 +{ 1.48 + 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); 1.49 +} 1.50 +</script> 1.51 +<script> 1.52 +window.onload = main; 1.53 +debug("Tests a WebGL program that accesses out of bounds uniform array elements"); 1.54 + 1.55 +function main() { 1.56 + var wtu = WebGLTestUtils; 1.57 + var gl = wtu.create3DContext("example"); 1.58 + var program = wtu.setupProgram( 1.59 + gl, 1.60 + ['vshader', 'fshader'], 1.61 + ['vPosition'], [0]); 1.62 + var gridRes = 255; 1.63 + wtu.setupQuad(gl, gridRes, 0); 1.64 + var lineWidthLoc = gl.getUniformLocation(program, "lineWidth"); 1.65 + var elemMultLoc = gl.getUniformLocation(program, "elemMult"); 1.66 + assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup."); 1.67 + 1.68 + var lineWidth = 512; 1.69 + var lineWidthElem = document.getElementById("lineWidth"); 1.70 + var lineWidthDisplayElem = document.getElementById("lineWidthDisplay"); 1.71 + 1.72 + lineWidthElem.value = lineWidth; 1.73 + 1.74 + lineWidthElem.addEventListener('change', function(event) { 1.75 + //console.log(event.target.value); 1.76 + lineWidth = event.target.value; 1.77 + draw(); 1.78 + }, false); 1.79 + 1.80 + var elemMult = 4; 1.81 + var elemMultElem = document.getElementById("elemMult"); 1.82 + var elemMultDisplayElem = document.getElementById("elemMultDisplay"); 1.83 + 1.84 + elemMultElem.value = elemMult; 1.85 + 1.86 + elemMultElem.addEventListener('change', function(event) { 1.87 + //console.log(event.target.value); 1.88 + elemMult = event.target.value; 1.89 + draw(); 1.90 + }, false); 1.91 + 1.92 + draw(); 1.93 + 1.94 + function draw() { 1.95 + lineWidthDisplayElem.innerText = lineWidth; 1.96 + elemMultDisplayElem.innerText = elemMult; 1.97 + gl.uniform1f(lineWidthLoc, lineWidth); 1.98 + gl.uniform1i(elemMultLoc, elemMult); 1.99 + gl.drawElements(gl.TRIANGLES, gridRes * gridRes * 6, gl.UNSIGNED_SHORT, 0); 1.100 + } 1.101 + 1.102 + successfullyParsed = true; 1.103 +} 1.104 + 1.105 +</script> 1.106 +</body> 1.107 +</html> 1.108 + 1.109 +