Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / programs / gl-get-active-uniform.html
blob295b5987cc4a4b6261b86cf2a97c247ab4b2b896
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL getActiveUniform conformance test.</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/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()
23 gl_Position = vec4(0, 0, 0, 1);
25 </script>
26 <script id="fshader" type="x-shader/x-fragment">
27 precision mediump float;
28 uniform $type uniform0;
29 void main()
31 gl_FragColor = vec4(0,$access,0,1);
33 </script>
34 <script id="fshaderA" type="x-shader/x-fragment">
35 precision mediump float;
36 uniform float uniform0;
37 void main()
39 gl_FragColor = vec4(0,uniform0,0,1);
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()
48 gl_FragColor = vec4(0,uniform0,uniform1,1);
50 </script>
51 <script>
52 "use strict";
53 description("Tests getActiveUniform for various types");
55 var wtu = WebGLTestUtils;
56 var gl = wtu.create3DContext("example");
58 var tests = [
59 { glType: gl.FLOAT, size: 1, type: 'float', access: 'uniform0'},
60 { glType: gl.FLOAT_VEC2, size: 1, type: 'vec2', access: 'uniform0[1]'},
61 { glType: gl.FLOAT_VEC3, size: 1, type: 'vec3', access: 'uniform0[2]'},
62 { glType: gl.FLOAT_VEC4, size: 1, type: 'vec4', access: 'uniform0[3]'},
63 { glType: gl.FLOAT_MAT2, size: 1, type: 'mat2', access: 'uniform0[1][1]'},
64 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: 'uniform0[2][2]'},
65 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: 'uniform0[2][2]'},
66 { glType: gl.FLOAT_MAT4, size: 1, type: 'mat4', access: 'uniform0[3][3]'},
67 { glType: gl.INT, size: 1, type: 'int', access: 'float(uniform0)'},
68 { glType: gl.INT_VEC2, size: 1, type: 'ivec2', access: 'float(uniform0[1])'},
69 { glType: gl.INT_VEC3, size: 1, type: 'ivec3', access: 'float(uniform0[2])'},
70 { glType: gl.INT_VEC4, size: 1, type: 'ivec4', access: 'float(uniform0[3])'},
71 { glType: gl.BOOL, size: 1, type: 'bool', access: 'float(uniform0)'},
72 { glType: gl.BOOL_VEC2, size: 1, type: 'bvec2', access: 'float(uniform0[1])'},
73 { glType: gl.BOOL_VEC3, size: 1, type: 'bvec3', access: 'float(uniform0[2])'},
74 { glType: gl.BOOL_VEC4, size: 1, type: 'bvec4', access: 'float(uniform0[3])'},
75 { glType: gl.SAMPLER_2D, size: 1, type: 'sampler2D', access: 'texture2D(uniform0, vec2(0,0)).x'},
76 { glType: gl.SAMPLER_CUBE, size: 1, type: 'samplerCube', access: 'textureCube(uniform0, vec3(0,1,0)).x'}
79 var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER);
80 var source = document.getElementById('fshader').text;
82 function createProgram(type, access) {
83 var fs = wtu.loadShader(
84 gl,
85 source.replace('$type', type).replace('$access', access),
86 gl.FRAGMENT_SHADER);
87 var program = wtu.setupProgram(gl, [vs, fs]);
88 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup");
89 return program;
92 for (var tt = 0; tt < tests.length; ++tt) {
93 var t = tests[tt];
94 var program = createProgram(t.type, t.access);
95 var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
96 var found = false;
97 for (var ii = 0; ii < numUniforms; ++ii) {
98 var info = gl.getActiveUniform(program, ii);
99 if (info.name == 'uniform0') {
100 found = true;
101 assertMsg(info.type == t.glType,
102 "type must be " + wtu.glEnumToString(gl, t.glType) + " was " +
103 wtu.glEnumToString(gl, info.type));
104 assertMsg(info.size == t.size,
105 "size must be " + t.size + ' was ' + info.size);
108 if (!found) {
109 testFailed("uniform 'uniform0' not found");
113 var p1 = wtu.setupProgram(gl, [vs, 'fshaderA']);
114 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program A");
115 var p2 = wtu.setupProgram(gl, [vs, 'fshaderB']);
116 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program B");
117 var l1 = gl.getUniformLocation(p1, 'uniform0');
118 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p1");
119 var l2 = gl.getUniformLocation(p2, 'uniform0');
120 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p2");
122 gl.useProgram(p2);
123 gl.uniform1f(l2, 1);
124 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors setting uniform 0");
125 gl.uniform1f(l1, 2);
126 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
127 "setting a uniform using a location from another program");
129 var successfullyParsed = true;
130 </script>
131 <script src="../../js/js-test-post.js"></script>
133 </body>
134 </html>