2 Copyright (c) 2022 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 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
12 <script src=
"../../js/js-test-pre.js"></script>
13 <script src=
"../../js/webgl-test-utils.js"></script>
16 <div id=
"description"></div>
17 <div id=
"console"></div>
21 description("This test verifies getUniformIndices behaviors.");
25 var wtu
= WebGLTestUtils
;
27 const e_canvas
= document
.createElement('canvas');
28 const gl
= e_canvas
.getContext('webgl2');
32 precision mediump float;
33 uniform float u_vert_scalar;
34 uniform float u_vert_arr[3];
35 uniform float u_both_scalar;
36 uniform float u_both_arr[3];
38 gl_Position = vec4(0, 0, 0, 1);
39 gl_Position.r += u_vert_scalar;
40 gl_Position.r += u_vert_arr[1];
41 gl_Position.r += u_both_scalar;
42 gl_Position.r += u_both_arr[1];
48 precision mediump float;
49 uniform float u_frag_scalar;
50 uniform float u_frag_arr[3];
51 uniform float u_both_scalar;
52 uniform float u_both_arr[3];
53 out vec4 o_frag_color;
55 o_frag_color = vec4(0, 0, 0, 1);
56 o_frag_color.r += u_frag_scalar;
57 o_frag_color.r += u_frag_arr[1];
58 o_frag_color.r += u_both_scalar;
59 o_frag_color.r += u_both_arr[1];
65 testFailed("WebGL context does not exist");
69 window
.prog
= wtu
.setupProgram(gl
, [VSRC
, FSRC
]);
71 testFailed("Setting up program failed");
74 let err
= gl
.getError();
77 const IS_ACTIVE_BY_NAME
= {
78 'u_vert_scalar' : true,
79 'u_vert_scalar[0]': false,
81 'u_vert_arr[0]' : true, // Even if the [0] is unused, the name enumerated
82 // via getActiveUniforms for this array is 'u_vert_arr[0]'.
83 'u_vert_arr[1]' : false,
85 'u_frag_scalar' : true,
86 'u_frag_scalar[0]': false,
88 'u_frag_arr[0]' : true,
89 'u_frag_arr[1]' : false,
91 'u_both_scalar' : true,
92 'u_both_scalar[0]': false,
94 'u_both_arr[0]' : true,
95 'u_both_arr[1]' : false,
97 const NAMES
= Object
.keys(IS_ACTIVE_BY_NAME
);
98 const active_ids
= gl
.getUniformIndices(prog
, NAMES
);
103 NAMES
.forEach((name
, i
) => {
104 const active_id_was
= active_ids
[i
];
105 const is_active_expected
= IS_ACTIVE_BY_NAME
[name
];
106 const is_active_was
= active_id_was
!= gl
.INVALID_INDEX
;
107 expectTrue(is_active_was
== is_active_expected
,
108 `getUniformIndices([, '${name}' ,]) -> [, ${active_id_was} ,], should be [, ${is_active_expected ? '0<=N<INVALID_INDEX' : 'INVALID_INDEX'} ,]`);
110 const info
= gl
.getActiveUniform(prog
, active_id_was
);
111 expectTrue(info
.name
.startsWith(name
), `'${info.name}'.startsWith('${name}')`);
116 var successfullyParsed
= true;
118 <script src=
"../../js/js-test-post.js"></script>