OLD | NEW |
(Empty) | |
| 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> |
| 39 |
| 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"
); |
| 51 |
| 52 function main() { |
| 53 var wtu = WebGLTestUtils; |
| 54 var canvas = document.getElementById("example"); |
| 55 |
| 56 var gl = wtu.create3DContext(canvas); |
| 57 var program = wtu.setupProgram( |
| 58 gl, |
| 59 [wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER), |
| 60 wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER)], |
| 61 ['vPosition'], [0]); |
| 62 var gridRes = 255; |
| 63 wtu.setupQuad(gl, gridRes, 0); |
| 64 var lineWidthLoc = gl.getUniformLocation(program, "lineWidth"); |
| 65 var elemMultLoc = gl.getUniformLocation(program, "elemMult"); |
| 66 assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup."); |
| 67 |
| 68 var lineWidth = 512; |
| 69 var lineWidthElem = document.getElementById("lineWidth"); |
| 70 var lineWidthDisplayElem = document.getElementById("lineWidthDisplay"); |
| 71 |
| 72 lineWidthElem.value = lineWidth; |
| 73 |
| 74 lineWidthElem.addEventListener('change', function(event) { |
| 75 //console.log(event.target.value); |
| 76 lineWidth = event.target.value; |
| 77 draw(); |
| 78 }, false); |
| 79 |
| 80 var elemMult = 4; |
| 81 var elemMultElem = document.getElementById("elemMult"); |
| 82 var elemMultDisplayElem = document.getElementById("elemMultDisplay"); |
| 83 |
| 84 elemMultElem.value = elemMult; |
| 85 |
| 86 elemMultElem.addEventListener('change', function(event) { |
| 87 //console.log(event.target.value); |
| 88 elemMult = event.target.value; |
| 89 draw(); |
| 90 }, false); |
| 91 |
| 92 draw(); |
| 93 |
| 94 function draw() { |
| 95 lineWidthDisplayElem.innerText = lineWidth; |
| 96 elemMultDisplayElem.innerText = elemMult; |
| 97 gl.uniform1f(lineWidthLoc, lineWidth); |
| 98 gl.uniform1i(elemMultLoc, elemMult); |
| 99 gl.drawElements(gl.TRIANGLES, gridRes * gridRes * 6, gl.UNSIGNED_SHORT, 0); |
| 100 } |
| 101 |
| 102 successfullyParsed = true; |
| 103 } |
| 104 |
| 105 </script> |
| 106 </body> |
| 107 </html> |
| 108 |
| 109 |
OLD | NEW |