content/canvas/test/webgl-conformance/conformance/programs/gl-get-active-uniform.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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 getActiveUniform conformance test.</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="16" height="16"></canvas>
    18 <div id="description"></div>
    19 <div id="console"></div>
    20 <script id="vshader" type="x-shader/x-vertex">
    21 void main()
    22 {
    23     gl_Position = vec4(0, 0, 0, 1);
    24 }
    25 </script>
    26 <script id="fshader" type="x-shader/x-fragment">
    27 precision mediump float;
    28 uniform $type uniform0;
    29 void main()
    30 {
    31     gl_FragColor = vec4(0,$access,0,1);
    32 }
    33 </script>
    34 <script id="fshaderA" type="x-shader/x-fragment">
    35 precision mediump float;
    36 uniform float uniform0;
    37 void main()
    38 {
    39     gl_FragColor = vec4(0,uniform0,0,1);
    40 }
    41 </script>
    42 <script id="fshaderB" type="x-shader/x-fragment">
    43 precision mediump float;
    44 uniform float uniform0;
    45 uniform float uniform1;
    46 void main()
    47 {
    48     gl_FragColor = vec4(0,uniform0,uniform1,1);
    49 }
    50 </script>
    51 <script>
    52 description("Tests getActiveUniform for various types");
    54 var wtu = WebGLTestUtils;
    55 var gl = wtu.create3DContext("example");
    57 var tests = [
    58 { glType: gl.FLOAT,      size: 1, type: 'float', access: 'uniform0'},
    59 { glType: gl.FLOAT_VEC2, size: 1, type: 'vec2',  access: 'uniform0[1]'},
    60 { glType: gl.FLOAT_VEC3, size: 1, type: 'vec3',  access: 'uniform0[2]'},
    61 { glType: gl.FLOAT_VEC4, size: 1, type: 'vec4',  access: 'uniform0[3]'},
    62 { glType: gl.FLOAT_MAT2, size: 1, type: 'mat2',  access: 'uniform0[1][1]'},
    63 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3',  access: 'uniform0[2][2]'},
    64 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3',  access: 'uniform0[2][2]'},
    65 { glType: gl.FLOAT_MAT4, size: 1, type: 'mat4',  access: 'uniform0[3][3]'},
    66 { glType: gl.INT,        size: 1, type: 'int',   access: 'float(uniform0)'},
    67 { glType: gl.INT_VEC2,   size: 1, type: 'ivec2', access: 'float(uniform0[1])'},
    68 { glType: gl.INT_VEC3,   size: 1, type: 'ivec3', access: 'float(uniform0[2])'},
    69 { glType: gl.INT_VEC4,   size: 1, type: 'ivec4', access: 'float(uniform0[3])'},
    70 { glType: gl.BOOL,       size: 1, type: 'bool',  access: 'float(uniform0)'},
    71 { glType: gl.BOOL_VEC2,  size: 1, type: 'bvec2', access: 'float(uniform0[1])'},
    72 { glType: gl.BOOL_VEC3,  size: 1, type: 'bvec3', access: 'float(uniform0[2])'},
    73 { glType: gl.BOOL_VEC4,  size: 1, type: 'bvec4', access: 'float(uniform0[3])'},
    74 { glType: gl.SAMPLER_2D,
    75   size: 1,
    76   type: 'sampler2D',
    77   access: 'texture2D(uniform0, vec2(0,0)).x'
    78 },
    79 { glType: gl.SAMPLER_CUBE,
    80   size: 1,
    81   type: 'samplerCube',
    82   access: 'textureCube(uniform0, vec3(0,1,0)).x'
    83 }
    84 ];
    86 var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER);
    87 var source = document.getElementById('fshader').text;
    89 function createProgram(type, access) {
    90   var fs = wtu.loadShader(
    91       gl,
    92       source.replace('$type', type).replace('$access', access),
    93       gl.FRAGMENT_SHADER);
    94   var program = wtu.setupProgram(gl, [vs, fs]);
    95   glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup");
    96   return program;
    97 }
    99 for (var tt = 0; tt < tests.length; ++tt) {
   100   var t = tests[tt];
   101   var program = createProgram(t.type, t.access);
   102   var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
   103   var found = false;
   104   for (var ii = 0; ii < numUniforms; ++ii) {
   105     var info = gl.getActiveUniform(program, ii);
   106     if (info.name == 'uniform0') {
   107       found = true;
   108       assertMsg(info.type == t.glType,
   109                 "type must be " + wtu.glEnumToString(gl, t.glType) + " was " +
   110                 wtu.glEnumToString(gl, info.type));
   111       assertMsg(info.size == t.size,
   112                 "size must be " + t.size + ' was ' + info.size);
   113     }
   114   }
   115   if (!found) {
   116     testFailed("uniform 'uniform0' not found");
   117   }
   118 }
   120 var p1 = wtu.setupProgram(gl, [vs, 'fshaderA']);
   121 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program A");
   122 var p2 = wtu.setupProgram(gl, [vs, 'fshaderB']);
   123 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program B");
   124 var l1 = gl.getUniformLocation(p1, 'uniform0');
   125 glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p1");
   126 var l2 = gl.getUniformLocation(p2, 'uniform0');
   127 glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p2");
   129 gl.useProgram(p2);
   130 gl.uniform1f(l2, 1);
   131 glErrorShouldBe(gl, gl.NO_ERROR, "no errors setting uniform 0");
   132 gl.uniform1f(l1, 2);
   133 glErrorShouldBe(gl, gl.INVALID_OPERATION,
   134                 "setting a uniform using a location from another program");
   136 successfullyParsed = true;
   137 </script>
   138 <script>finishTest();</script>
   140 </body>
   141 </html>

mercurial