|
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;"></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 description(document.title); |
|
67 var wtu = WebGLTestUtils; |
|
68 var gl = wtu.create3DContext("example"); |
|
69 var program = wtu.setupTexturedQuad(gl); |
|
70 |
|
71 //------------------------------------------------------------------------------ |
|
72 var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['vPosition'], [0]); |
|
73 |
|
74 for (var ii = 0; ii < 128; ++ii) { |
|
75 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); |
|
76 gl.uniform4f(loc, 2/256, 2/512, 2/1024, ii/8128); |
|
77 } |
|
78 |
|
79 wtu.drawQuad(gl); |
|
80 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
|
81 wtu.checkCanvasRect(gl, 0, 0, gl.canvas.width, gl.canvas.height, [255, 127, 64, 255], "Should render 255,127,64,32 (+/-1)", 1); |
|
82 |
|
83 //------------------------------------------------------------------------------ |
|
84 var program = wtu.setupProgram(gl, ['vshader2', 'fshader2'], ['vPosition'], [0]); |
|
85 |
|
86 for (var ii = 0; ii < 16; ++ii) { |
|
87 var loc = gl.getUniformLocation(program, "uni[" + ii + "]"); |
|
88 gl.uniform4f(loc, 16/2048, 16/1024, 16/512, ii); |
|
89 } |
|
90 |
|
91 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
|
92 wtu.drawQuad(gl); |
|
93 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
|
94 wtu.checkCanvasRect(gl, 0, 0, gl.canvas.width, gl.canvas.height, [32, 64, 127, 255], "Should render 32,64,127,255 (+/-1)", 1); |
|
95 |
|
96 successfullyParsed = true; |
|
97 |
|
98 </script> |
|
99 <script>finishTest();</script> |
|
100 |
|
101 </body> |
|
102 </html> |
|
103 |
|
104 |