gl-min-uniforms.html (2972B)
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>WebGL the minimum number of uniforms are supported.</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 #define NUM_UNIFORMS 128 // See spec 22 attribute vec4 vPosition; 23 uniform vec4 uni[NUM_UNIFORMS]; 24 varying vec4 color; 25 void main() 26 { 27 gl_Position = vPosition; 28 vec4 c = vec4(0,0,0,0); 29 for (int ii = 0; ii < NUM_UNIFORMS; ++ii) { 30 c += uni[ii]; 31 } 32 color = c; 33 } 34 </script> 35 36 <script id="fshader" type="x-shader/x-fragment"> 37 precision mediump float; 38 varying vec4 color; 39 void main() 40 { 41 gl_FragColor = color; 42 } 43 </script> 44 <script id="vshader2" type="x-shader/x-vertex"> 45 attribute vec4 vPosition; 46 void main() 47 { 48 gl_Position = vPosition; 49 } 50 </script> 51 52 <script id="fshader2" type="x-shader/x-fragment"> 53 precision mediump float; 54 #define NUM_UNIFORMS 16 // See spec 55 uniform vec4 uni[NUM_UNIFORMS]; 56 void main() 57 { 58 vec4 c = vec4(0,0,0,0); 59 for (int ii = 0; ii < NUM_UNIFORMS; ++ii) { 60 c += uni[ii]; 61 } 62 gl_FragColor = vec4(c.r, c.g, c.b, c.a / 120.0); 63 } 64 </script> 65 <script> 66 "use strict"; 67 description(document.title); 68 var wtu = WebGLTestUtils; 69 var gl = wtu.create3DContext("example"); 70 var program = wtu.setupTexturedQuad(gl); 71 72 //------------------------------------------------------------------------------ 73 var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['vPosition'], [0]); 74 75 for (var ii = 0; ii < 128; ++ii) { 76 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); 77 gl.uniform4f(loc, 2/256, 2/512, 2/1024, ii/8128); 78 } 79 80 wtu.clearAndDrawUnitQuad(gl); 81 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 82 wtu.checkCanvasRect(gl, 0, 0, gl.canvas.width, gl.canvas.height, [255, 127, 64, 255], "Should render 255,127,64,32 (+/-1)", 1); 83 84 //------------------------------------------------------------------------------ 85 var program = wtu.setupProgram(gl, ['vshader2', 'fshader2'], ['vPosition'], [0]); 86 87 for (var ii = 0; ii < 16; ++ii) { 88 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); 89 gl.uniform4f(loc, 16/2048, 16/1024, 16/512, ii); 90 } 91 92 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 93 wtu.clearAndDrawUnitQuad(gl); 94 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 95 wtu.checkCanvasRect(gl, 0, 0, gl.canvas.width, gl.canvas.height, [32, 64, 127, 255], "Should render 32,64,127,255 (+/-1)", 1); 96 97 var successfullyParsed = true; 98 99 </script> 100 <script src="../../js/js-test-post.js"></script> 101 102 </body> 103 </html>