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.
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>
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">
23 gl_Position = vec4(
0,
0,
0,
1);
26 <script id=
"fshader" type=
"x-shader/x-fragment">
27 precision mediump float;
28 uniform $type uniform0;
31 gl_FragColor = vec4(
0,$access,
0,
1);
34 <script id=
"fshaderA" type=
"x-shader/x-fragment">
35 precision mediump float;
36 uniform float uniform0;
39 gl_FragColor = vec4(
0,uniform0,
0,
1);
42 <script id=
"fshaderB" type=
"x-shader/x-fragment">
43 precision mediump float;
44 uniform float uniform0;
45 uniform float uniform1;
48 gl_FragColor = vec4(
0,uniform0,uniform1,
1);
53 description("Tests getActiveUniform for various types");
55 var wtu
= WebGLTestUtils
;
56 var gl
= wtu
.create3DContext("example");
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(
85 source
.replace('$type', type
).replace('$access', access
),
87 var program
= wtu
.setupProgram(gl
, [vs
, fs
]);
88 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "no errors from setup");
92 for (var tt
= 0; tt
< tests
.length
; ++tt
) {
94 var program
= createProgram(t
.type
, t
.access
);
95 var numUniforms
= gl
.getProgramParameter(program
, gl
.ACTIVE_UNIFORMS
);
97 for (var ii
= 0; ii
< numUniforms
; ++ii
) {
98 var info
= gl
.getActiveUniform(program
, ii
);
99 if (info
.name
== 'uniform0') {
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
);
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");
124 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "no errors setting uniform 0");
126 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
127 "setting a uniform using a location from another program");
129 var successfullyParsed
= true;
131 <script src=
"../../js/js-test-post.js"></script>