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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!--
michael@0 2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE html>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <title>WebGL getActiveUniform conformance test.</title>
michael@0 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 12 <script src="../../resources/js-test-pre.js"></script>
michael@0 13 <script src="../resources/webgl-test.js"> </script>
michael@0 14 <script src="../resources/webgl-test-utils.js"> </script>
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <canvas id="example" width="16" height="16"></canvas>
michael@0 18 <div id="description"></div>
michael@0 19 <div id="console"></div>
michael@0 20 <script id="vshader" type="x-shader/x-vertex">
michael@0 21 void main()
michael@0 22 {
michael@0 23 gl_Position = vec4(0, 0, 0, 1);
michael@0 24 }
michael@0 25 </script>
michael@0 26 <script id="fshader" type="x-shader/x-fragment">
michael@0 27 precision mediump float;
michael@0 28 uniform $type uniform0;
michael@0 29 void main()
michael@0 30 {
michael@0 31 gl_FragColor = vec4(0,$access,0,1);
michael@0 32 }
michael@0 33 </script>
michael@0 34 <script id="fshaderA" type="x-shader/x-fragment">
michael@0 35 precision mediump float;
michael@0 36 uniform float uniform0;
michael@0 37 void main()
michael@0 38 {
michael@0 39 gl_FragColor = vec4(0,uniform0,0,1);
michael@0 40 }
michael@0 41 </script>
michael@0 42 <script id="fshaderB" type="x-shader/x-fragment">
michael@0 43 precision mediump float;
michael@0 44 uniform float uniform0;
michael@0 45 uniform float uniform1;
michael@0 46 void main()
michael@0 47 {
michael@0 48 gl_FragColor = vec4(0,uniform0,uniform1,1);
michael@0 49 }
michael@0 50 </script>
michael@0 51 <script>
michael@0 52 description("Tests getActiveUniform for various types");
michael@0 53
michael@0 54 var wtu = WebGLTestUtils;
michael@0 55 var gl = wtu.create3DContext("example");
michael@0 56
michael@0 57 var tests = [
michael@0 58 { glType: gl.FLOAT, size: 1, type: 'float', access: 'uniform0'},
michael@0 59 { glType: gl.FLOAT_VEC2, size: 1, type: 'vec2', access: 'uniform0[1]'},
michael@0 60 { glType: gl.FLOAT_VEC3, size: 1, type: 'vec3', access: 'uniform0[2]'},
michael@0 61 { glType: gl.FLOAT_VEC4, size: 1, type: 'vec4', access: 'uniform0[3]'},
michael@0 62 { glType: gl.FLOAT_MAT2, size: 1, type: 'mat2', access: 'uniform0[1][1]'},
michael@0 63 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: 'uniform0[2][2]'},
michael@0 64 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: 'uniform0[2][2]'},
michael@0 65 { glType: gl.FLOAT_MAT4, size: 1, type: 'mat4', access: 'uniform0[3][3]'},
michael@0 66 { glType: gl.INT, size: 1, type: 'int', access: 'float(uniform0)'},
michael@0 67 { glType: gl.INT_VEC2, size: 1, type: 'ivec2', access: 'float(uniform0[1])'},
michael@0 68 { glType: gl.INT_VEC3, size: 1, type: 'ivec3', access: 'float(uniform0[2])'},
michael@0 69 { glType: gl.INT_VEC4, size: 1, type: 'ivec4', access: 'float(uniform0[3])'},
michael@0 70 { glType: gl.BOOL, size: 1, type: 'bool', access: 'float(uniform0)'},
michael@0 71 { glType: gl.BOOL_VEC2, size: 1, type: 'bvec2', access: 'float(uniform0[1])'},
michael@0 72 { glType: gl.BOOL_VEC3, size: 1, type: 'bvec3', access: 'float(uniform0[2])'},
michael@0 73 { glType: gl.BOOL_VEC4, size: 1, type: 'bvec4', access: 'float(uniform0[3])'},
michael@0 74 { glType: gl.SAMPLER_2D,
michael@0 75 size: 1,
michael@0 76 type: 'sampler2D',
michael@0 77 access: 'texture2D(uniform0, vec2(0,0)).x'
michael@0 78 },
michael@0 79 { glType: gl.SAMPLER_CUBE,
michael@0 80 size: 1,
michael@0 81 type: 'samplerCube',
michael@0 82 access: 'textureCube(uniform0, vec3(0,1,0)).x'
michael@0 83 }
michael@0 84 ];
michael@0 85
michael@0 86 var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER);
michael@0 87 var source = document.getElementById('fshader').text;
michael@0 88
michael@0 89 function createProgram(type, access) {
michael@0 90 var fs = wtu.loadShader(
michael@0 91 gl,
michael@0 92 source.replace('$type', type).replace('$access', access),
michael@0 93 gl.FRAGMENT_SHADER);
michael@0 94 var program = wtu.setupProgram(gl, [vs, fs]);
michael@0 95 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup");
michael@0 96 return program;
michael@0 97 }
michael@0 98
michael@0 99 for (var tt = 0; tt < tests.length; ++tt) {
michael@0 100 var t = tests[tt];
michael@0 101 var program = createProgram(t.type, t.access);
michael@0 102 var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
michael@0 103 var found = false;
michael@0 104 for (var ii = 0; ii < numUniforms; ++ii) {
michael@0 105 var info = gl.getActiveUniform(program, ii);
michael@0 106 if (info.name == 'uniform0') {
michael@0 107 found = true;
michael@0 108 assertMsg(info.type == t.glType,
michael@0 109 "type must be " + wtu.glEnumToString(gl, t.glType) + " was " +
michael@0 110 wtu.glEnumToString(gl, info.type));
michael@0 111 assertMsg(info.size == t.size,
michael@0 112 "size must be " + t.size + ' was ' + info.size);
michael@0 113 }
michael@0 114 }
michael@0 115 if (!found) {
michael@0 116 testFailed("uniform 'uniform0' not found");
michael@0 117 }
michael@0 118 }
michael@0 119
michael@0 120 var p1 = wtu.setupProgram(gl, [vs, 'fshaderA']);
michael@0 121 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program A");
michael@0 122 var p2 = wtu.setupProgram(gl, [vs, 'fshaderB']);
michael@0 123 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program B");
michael@0 124 var l1 = gl.getUniformLocation(p1, 'uniform0');
michael@0 125 glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p1");
michael@0 126 var l2 = gl.getUniformLocation(p2, 'uniform0');
michael@0 127 glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p2");
michael@0 128
michael@0 129 gl.useProgram(p2);
michael@0 130 gl.uniform1f(l2, 1);
michael@0 131 glErrorShouldBe(gl, gl.NO_ERROR, "no errors setting uniform 0");
michael@0 132 gl.uniform1f(l1, 2);
michael@0 133 glErrorShouldBe(gl, gl.INVALID_OPERATION,
michael@0 134 "setting a uniform using a location from another program");
michael@0 135
michael@0 136 successfullyParsed = true;
michael@0 137 </script>
michael@0 138 <script>finishTest();</script>
michael@0 139
michael@0 140 </body>
michael@0 141 </html>
michael@0 142
michael@0 143

mercurial