content/canvas/test/webgl-conformance/conformance/limits/gl-min-uniforms.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     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>
    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>
    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);
    71 //------------------------------------------------------------------------------
    72 var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['vPosition'], [0]);
    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 }
    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);
    83 //------------------------------------------------------------------------------
    84 var program = wtu.setupProgram(gl, ['vshader2', 'fshader2'], ['vPosition'], [0]);
    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 }
    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);
    96 successfullyParsed = true;
    98 </script>
    99 <script>finishTest();</script>
   101 </body>
   102 </html>

mercurial