arrayOutOfBounds.html (5279B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <!-- 6 Copyright (c) 2019 The Khronos Group Inc. 7 Use of this source code is governed by an MIT-style license that can be 8 found in the LICENSE.txt file. 9 --> 10 <link rel="stylesheet" type="text/css" href="../unit.css" /> 11 <script type="application/javascript" src="../unit.js"></script> 12 <script type="application/javascript" src="../util.js"></script> 13 <script type="application/javascript"> 14 15 Tests.startUnit = function () { 16 var canvas = document.getElementById('gl'); 17 var gl = getGLContext(canvas); 18 return [gl]; 19 } 20 21 Tests.testOk = function(gl) { 22 var sh = new Filter(gl, 'okvert', 'frag'); 23 assertOk(function(){sh.apply();}); 24 sh.destroy(); 25 26 var sh = new Filter(gl, 'vert', 'okfrag'); 27 assertOk(function(){sh.apply();}); 28 sh.destroy(); 29 30 var sh = new Filter(gl, 'vert', 'frag'); 31 assertOk(function(){sh.apply();}); 32 sh.destroy(); 33 } 34 35 var arr = ['cr', 'cw', 'vr', 'vw']; 36 arr.forEach(function(e){ 37 if (e == 'cr' || e == 'cw') { 38 Tests['test'+e+'vert'] = function(gl) { 39 var sh = new Filter(gl, e+'vert', 'frag'); 40 assertFail(function(){sh.apply();}); 41 sh.destroy(); 42 } 43 } 44 Tests['test'+e+'frag'] = function(gl) { 45 var sh = new Filter(gl, 'vert', e+'frag'); 46 assertFail(function(){sh.apply();}); 47 sh.destroy(); 48 } 49 }); 50 51 52 </script> 53 <script id="okvert" type="x-shader/x-vertex"> 54 55 56 attribute vec3 Vertex; 57 attribute vec2 Tex; 58 varying vec2 TexCoord; 59 void main() 60 { 61 TexCoord = Tex; 62 float x[3]; 63 x[0] = 1.0; 64 x[1] = 2.0; 65 x[2] = 3.0; 66 gl_Position = vec4(Vertex, x[2]); 67 } 68 </script> 69 <script id="crvert" type="x-shader/x-vertex"> 70 71 72 attribute vec3 Vertex; 73 attribute vec2 Tex; 74 varying vec2 TexCoord; 75 void main() 76 { 77 TexCoord = Tex; 78 float x[3]; 79 x[0] = 1.0; 80 x[1] = 2.0; 81 x[2] = 3.0; 82 gl_Position = vec4(Vertex, x[4]); 83 } 84 </script> 85 <script id="cwvert" type="x-shader/x-vertex"> 86 87 88 attribute vec3 Vertex; 89 attribute vec2 Tex; 90 varying vec2 TexCoord; 91 void main() 92 { 93 TexCoord = Tex; 94 float x[3]; 95 x[0] = 1.0; 96 x[1] = 2.0; 97 x[2] = 3.0; 98 x[4] = Vertex.z; 99 gl_Position = vec4(Vertex, x[4]); 100 } 101 </script> 102 <!-- This one can't be required to fail compilation, because vertex shaders must support arbitrary array indexing --> 103 <script id="vrvert" type="x-shader/x-vertex"> 104 105 106 attribute vec3 Vertex; 107 attribute vec2 Tex; 108 varying vec2 TexCoord; 109 void main() 110 { 111 TexCoord = Tex; 112 float x[3]; 113 x[0] = 1.0; 114 x[1] = 2.0; 115 x[2] = 3.0; 116 int idx = 4 * int(max(1.0, Vertex.x*20.0)); 117 gl_Position = vec4(Vertex, x[idx]); 118 } 119 </script> 120 <!-- This one can't be required to fail compilation, because vertex shaders must support arbitrary array indexing --> 121 <script id="vwvert" type="x-shader/x-vertex"> 122 123 124 attribute vec3 Vertex; 125 attribute vec2 Tex; 126 varying vec2 TexCoord; 127 void main() 128 { 129 TexCoord = Tex; 130 float x[3]; 131 x[0] = 1.0; 132 x[1] = 2.0; 133 x[2] = 3.0; 134 int idx = 4 * int(max(1.0, Vertex.x*20.0)); 135 x[idx] = Vertex.z; 136 gl_Position = vec4(Vertex, x[idx]); 137 } 138 </script> 139 <script id="vert" type="x-shader/x-vertex"> 140 141 142 attribute vec3 Vertex; 143 attribute vec2 Tex; 144 varying vec2 TexCoord; 145 void main() 146 { 147 TexCoord = Tex; 148 gl_Position = vec4(Vertex, 0.0); 149 } 150 </script> 151 152 <script id="okfrag" type="x-shader/x-fragment"> 153 154 155 precision mediump float; 156 157 varying vec2 TexCoord; 158 159 void main() 160 { 161 float x[3]; 162 x[0] = 1.0; 163 x[1] = 2.0; 164 x[2] = 3.0; 165 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[2]); 166 } 167 </script> 168 <script id="crfrag" type="x-shader/x-fragment"> 169 170 171 precision mediump float; 172 173 varying vec2 TexCoord; 174 175 void main() 176 { 177 float x[3]; 178 x[0] = 1.0; 179 x[1] = 2.0; 180 x[2] = 3.0; 181 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[4]); 182 } 183 </script> 184 <script id="cwfrag" type="x-shader/x-fragment"> 185 186 187 precision mediump float; 188 189 varying vec2 TexCoord; 190 191 void main() 192 { 193 float x[3]; 194 x[0] = 1.0; 195 x[1] = 2.0; 196 x[2] = 3.0; 197 198 x[4] = 6.0; 199 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[4]); 200 } 201 </script> 202 <!-- This one actually fails because of WebGL's restrictions on indexing expressions in fragment shaders --> 203 <script id="vrfrag" type="x-shader/x-fragment"> 204 205 206 precision mediump float; 207 208 varying vec2 TexCoord; 209 210 void main() 211 { 212 float x[3]; 213 x[0] = 1.0; 214 x[1] = 2.0; 215 x[2] = 3.0; 216 217 int idx = 4 * int(max(1.0, TexCoord.x*20.0)); 218 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[idx]); 219 } 220 </script> 221 <!-- This one actually fails because of WebGL's restrictions on indexing expressions in fragment shaders --> 222 <script id="vwfrag" type="x-shader/x-fragment"> 223 224 225 precision mediump float; 226 227 varying vec2 TexCoord; 228 229 void main() 230 { 231 float x[3]; 232 x[0] = 1.0; 233 x[1] = 2.0; 234 x[2] = 3.0; 235 236 int idx = 4 * int(max(1.0, TexCoord.x*20.0)); 237 x[idx] = 6.0; 238 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[idx]); 239 } 240 </script> 241 <script id="frag" type="x-shader/x-fragment"> 242 243 244 precision mediump float; 245 246 varying vec2 TexCoord; 247 248 void main() 249 { 250 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, 1.0); 251 } 252 </script> 253 254 255 <style>canvas{ position:absolute; }</style> 256 </head><body> 257 <canvas id="gl" width="16" height="16"></canvas> 258 </body></html>