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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/webgl-conformance/conformance/programs/gl-get-active-uniform.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +<!--
     1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.6 +Use of this source code is governed by a BSD-style license that can be
     1.7 +found in the LICENSE file.
     1.8 + -->
     1.9 +<!DOCTYPE html>
    1.10 +<html>
    1.11 +<head>
    1.12 +<meta charset="utf-8">
    1.13 +<title>WebGL getActiveUniform conformance test.</title>
    1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/>
    1.15 +<script src="../../resources/js-test-pre.js"></script>
    1.16 +<script src="../resources/webgl-test.js"> </script>
    1.17 +<script src="../resources/webgl-test-utils.js"> </script>
    1.18 +</head>
    1.19 +<body>
    1.20 +<canvas id="example" width="16" height="16"></canvas>
    1.21 +<div id="description"></div>
    1.22 +<div id="console"></div>
    1.23 +<script id="vshader" type="x-shader/x-vertex">
    1.24 +void main()
    1.25 +{
    1.26 +    gl_Position = vec4(0, 0, 0, 1);
    1.27 +}
    1.28 +</script>
    1.29 +<script id="fshader" type="x-shader/x-fragment">
    1.30 +precision mediump float;
    1.31 +uniform $type uniform0;
    1.32 +void main()
    1.33 +{
    1.34 +    gl_FragColor = vec4(0,$access,0,1);
    1.35 +}
    1.36 +</script>
    1.37 +<script id="fshaderA" type="x-shader/x-fragment">
    1.38 +precision mediump float;
    1.39 +uniform float uniform0;
    1.40 +void main()
    1.41 +{
    1.42 +    gl_FragColor = vec4(0,uniform0,0,1);
    1.43 +}
    1.44 +</script>
    1.45 +<script id="fshaderB" type="x-shader/x-fragment">
    1.46 +precision mediump float;
    1.47 +uniform float uniform0;
    1.48 +uniform float uniform1;
    1.49 +void main()
    1.50 +{
    1.51 +    gl_FragColor = vec4(0,uniform0,uniform1,1);
    1.52 +}
    1.53 +</script>
    1.54 +<script>
    1.55 +description("Tests getActiveUniform for various types");
    1.56 +
    1.57 +var wtu = WebGLTestUtils;
    1.58 +var gl = wtu.create3DContext("example");
    1.59 +
    1.60 +var tests = [
    1.61 +{ glType: gl.FLOAT,      size: 1, type: 'float', access: 'uniform0'},
    1.62 +{ glType: gl.FLOAT_VEC2, size: 1, type: 'vec2',  access: 'uniform0[1]'},
    1.63 +{ glType: gl.FLOAT_VEC3, size: 1, type: 'vec3',  access: 'uniform0[2]'},
    1.64 +{ glType: gl.FLOAT_VEC4, size: 1, type: 'vec4',  access: 'uniform0[3]'},
    1.65 +{ glType: gl.FLOAT_MAT2, size: 1, type: 'mat2',  access: 'uniform0[1][1]'},
    1.66 +{ glType: gl.FLOAT_MAT3, size: 1, type: 'mat3',  access: 'uniform0[2][2]'},
    1.67 +{ glType: gl.FLOAT_MAT3, size: 1, type: 'mat3',  access: 'uniform0[2][2]'},
    1.68 +{ glType: gl.FLOAT_MAT4, size: 1, type: 'mat4',  access: 'uniform0[3][3]'},
    1.69 +{ glType: gl.INT,        size: 1, type: 'int',   access: 'float(uniform0)'},
    1.70 +{ glType: gl.INT_VEC2,   size: 1, type: 'ivec2', access: 'float(uniform0[1])'},
    1.71 +{ glType: gl.INT_VEC3,   size: 1, type: 'ivec3', access: 'float(uniform0[2])'},
    1.72 +{ glType: gl.INT_VEC4,   size: 1, type: 'ivec4', access: 'float(uniform0[3])'},
    1.73 +{ glType: gl.BOOL,       size: 1, type: 'bool',  access: 'float(uniform0)'},
    1.74 +{ glType: gl.BOOL_VEC2,  size: 1, type: 'bvec2', access: 'float(uniform0[1])'},
    1.75 +{ glType: gl.BOOL_VEC3,  size: 1, type: 'bvec3', access: 'float(uniform0[2])'},
    1.76 +{ glType: gl.BOOL_VEC4,  size: 1, type: 'bvec4', access: 'float(uniform0[3])'},
    1.77 +{ glType: gl.SAMPLER_2D,
    1.78 +  size: 1,
    1.79 +  type: 'sampler2D',
    1.80 +  access: 'texture2D(uniform0, vec2(0,0)).x'
    1.81 +},
    1.82 +{ glType: gl.SAMPLER_CUBE,
    1.83 +  size: 1,
    1.84 +  type: 'samplerCube',
    1.85 +  access: 'textureCube(uniform0, vec3(0,1,0)).x'
    1.86 +}
    1.87 +];
    1.88 +
    1.89 +var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER);
    1.90 +var source = document.getElementById('fshader').text;
    1.91 +
    1.92 +function createProgram(type, access) {
    1.93 +  var fs = wtu.loadShader(
    1.94 +      gl,
    1.95 +      source.replace('$type', type).replace('$access', access),
    1.96 +      gl.FRAGMENT_SHADER);
    1.97 +  var program = wtu.setupProgram(gl, [vs, fs]);
    1.98 +  glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup");
    1.99 +  return program;
   1.100 +}
   1.101 +
   1.102 +for (var tt = 0; tt < tests.length; ++tt) {
   1.103 +  var t = tests[tt];
   1.104 +  var program = createProgram(t.type, t.access);
   1.105 +  var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
   1.106 +  var found = false;
   1.107 +  for (var ii = 0; ii < numUniforms; ++ii) {
   1.108 +    var info = gl.getActiveUniform(program, ii);
   1.109 +    if (info.name == 'uniform0') {
   1.110 +      found = true;
   1.111 +      assertMsg(info.type == t.glType,
   1.112 +                "type must be " + wtu.glEnumToString(gl, t.glType) + " was " +
   1.113 +                wtu.glEnumToString(gl, info.type));
   1.114 +      assertMsg(info.size == t.size,
   1.115 +                "size must be " + t.size + ' was ' + info.size);
   1.116 +    }
   1.117 +  }
   1.118 +  if (!found) {
   1.119 +    testFailed("uniform 'uniform0' not found");
   1.120 +  }
   1.121 +}
   1.122 +
   1.123 +var p1 = wtu.setupProgram(gl, [vs, 'fshaderA']);
   1.124 +glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program A");
   1.125 +var p2 = wtu.setupProgram(gl, [vs, 'fshaderB']);
   1.126 +glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program B");
   1.127 +var l1 = gl.getUniformLocation(p1, 'uniform0');
   1.128 +glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p1");
   1.129 +var l2 = gl.getUniformLocation(p2, 'uniform0');
   1.130 +glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p2");
   1.131 +
   1.132 +gl.useProgram(p2);
   1.133 +gl.uniform1f(l2, 1);
   1.134 +glErrorShouldBe(gl, gl.NO_ERROR, "no errors setting uniform 0");
   1.135 +gl.uniform1f(l1, 2);
   1.136 +glErrorShouldBe(gl, gl.INVALID_OPERATION,
   1.137 +                "setting a uniform using a location from another program");
   1.138 +
   1.139 +successfullyParsed = true;
   1.140 +</script>
   1.141 +<script>finishTest();</script>
   1.142 +
   1.143 +</body>
   1.144 +</html>
   1.145 +
   1.146 +

mercurial