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> |
| 7 <html> |
| 8 <head> |
| 9 <meta charset="utf-8"> |
| 10 <title>WebGL the minimum number of uniforms are supported.</title> |
| 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 12 <script src="../../resources/js-test-pre.js"></script> |
| 13 <script src="../resources/webgl-test.js"> </script> |
| 14 <script src="../resources/webgl-test-utils.js"> </script> |
| 15 </head> |
| 16 <body> |
| 17 <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></c
anvas> |
| 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 var wtu = WebGLTestUtils; |
| 67 var canvas = document.getElementById("example"); |
| 68 var gl = wtu.create3DContext(canvas); |
| 69 var program = wtu.setupTexturedQuad(gl); |
| 70 |
| 71 //------------------------------------------------------------------------------ |
| 72 var program = wtu.setupProgram( |
| 73 gl, |
| 74 [wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER), |
| 75 wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER)], |
| 76 ['vPosition'], [0]); |
| 77 |
| 78 for (var ii = 0; ii < 128; ++ii) { |
| 79 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); |
| 80 gl.uniform4f(loc, 2/256, 2/512, 2/1024, ii/8128); |
| 81 } |
| 82 |
| 83 wtu.drawQuad(gl); |
| 84 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 85 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 127, 64, 255],
"Should render 255,127,64,32 (+/-1)", 1); |
| 86 |
| 87 //------------------------------------------------------------------------------ |
| 88 var program = wtu.setupProgram( |
| 89 gl, |
| 90 [wtu.loadShaderFromScript(gl, 'vshader2', gl.VERTEX_SHADER), |
| 91 wtu.loadShaderFromScript(gl, 'fshader2', gl.FRAGMENT_SHADER)], |
| 92 ['vPosition'], [0]); |
| 93 |
| 94 for (var ii = 0; ii < 16; ++ii) { |
| 95 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); |
| 96 gl.uniform4f(loc, 16/2048, 16/1024, 16/512, ii); |
| 97 } |
| 98 |
| 99 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 100 wtu.drawQuad(gl); |
| 101 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
| 102 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [32, 64, 127, 255], "
Should render 32,64,127,255 (+/-1)", 1); |
| 103 |
| 104 successfullyParsed = true; |
| 105 |
| 106 </script> |
| 107 <script src="../../resources/js-test-post.js"></script> |
| 108 |
| 109 </body> |
| 110 </html> |
| 111 |
| 112 |
OLD | NEW |