sampler-array-using-loop-index.html (2014B)
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>Sampler arrays using loop index should compile fine.</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 <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script id="vshader" type="x-shader/x-vertex"> 21 attribute vec4 vPosition; 22 void main() 23 { 24 gl_Position = vPosition; 25 } 26 </script> 27 28 <script id="fshader" type="x-shader/x-fragment"> 29 precision mediump float; 30 uniform sampler2D uni[2]; 31 32 float zero(int x) 33 { 34 return float(x) - float(x); 35 } 36 37 void main() 38 { 39 vec4 c = vec4(0,0,0,0); 40 for (int ii = 1; ii < 3; ++ii) { 41 if (c.x > 255.0) { 42 c.x = 255.0 + zero(ii); 43 break; 44 } 45 c += texture2D(uni[ii - 1], vec2(0.5, 0.5)); 46 } 47 gl_FragColor = c; 48 } 49 </script> 50 <script> 51 "use strict"; 52 description(document.title); 53 var wtu = WebGLTestUtils; 54 var gl = wtu.create3DContext("example"); 55 var program = wtu.setupTexturedQuad(gl); 56 57 //------------------------------------------------------------------------------ 58 var program = wtu.setupProgram( 59 gl, ['vshader', 'fshader'], ['vPosition'], undefined, true); 60 61 for (var ii = 0; ii < 2; ++ii) { 62 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); 63 gl.activeTexture(gl.TEXTURE0 + ii); 64 var tex = gl.createTexture(); 65 wtu.fillTexture(gl, tex, 1, 1, [32, 16, 8, ii * 9], 0); 66 gl.uniform1i(loc, ii); 67 } 68 69 wtu.clearAndDrawUnitQuad(gl); 70 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 71 wtu.checkCanvas(gl, [64, 32, 16, 9], 72 "Should render correctly", 1); 73 74 var successfullyParsed = true; 75 76 </script> 77 <script src="../../../js/js-test-post.js"></script> 78 79 </body> 80 </html>