summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/programs/get-uniform-indices.html
blob: d42add065c6bc601e4ab212500e7ef7003da4558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!--
Copyright (c) 2022 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>

<script>
"use strict";
description("This test verifies getUniformIndices behaviors.");

debug("");

var wtu = WebGLTestUtils;

const e_canvas = document.createElement('canvas');
const gl = e_canvas.getContext('webgl2');

const VSRC = `\
  #version 300 es
  precision mediump float;
  uniform float u_vert_scalar;
  uniform float u_vert_arr[3];
  uniform float u_both_scalar;
  uniform float u_both_arr[3];
  void main() {
    gl_Position = vec4(0, 0, 0, 1);
    gl_Position.r += u_vert_scalar;
    gl_Position.r += u_vert_arr[1];
    gl_Position.r += u_both_scalar;
    gl_Position.r += u_both_arr[1];
  }
`;

const FSRC = `\
  #version 300 es
  precision mediump float;
  uniform float u_frag_scalar;
  uniform float u_frag_arr[3];
  uniform float u_both_scalar;
  uniform float u_both_arr[3];
  out vec4 o_frag_color;
  void main() {
    o_frag_color = vec4(0, 0, 0, 1);
    o_frag_color.r += u_frag_scalar;
    o_frag_color.r += u_frag_arr[1];
    o_frag_color.r += u_both_scalar;
    o_frag_color.r += u_both_arr[1];
  }
`;

(() => {
  if (!gl) {
    testFailed("WebGL context does not exist");
    return;
  }

  window.prog = wtu.setupProgram(gl, [VSRC, FSRC]);
  if (!prog) {
    testFailed("Setting up program failed");
    return;
  }
  let err = gl.getError();
  if (err) throw err;

  const IS_ACTIVE_BY_NAME = {
    'u_vert_scalar'   : true,
    'u_vert_scalar[0]': false,
    'u_vert_arr'      : true,
    'u_vert_arr[0]'   : true, // Even if the [0] is unused, the name enumerated
                              // via getActiveUniforms for this array is 'u_vert_arr[0]'.
    'u_vert_arr[1]'   : false,

    'u_frag_scalar'   : true,
    'u_frag_scalar[0]': false,
    'u_frag_arr'      : true,
    'u_frag_arr[0]'   : true,
    'u_frag_arr[1]'   : false,

    'u_both_scalar'   : true,
    'u_both_scalar[0]': false,
    'u_both_arr'      : true,
    'u_both_arr[0]'   : true,
    'u_both_arr[1]'   : false,
  };
  const NAMES = Object.keys(IS_ACTIVE_BY_NAME);
  const active_ids = gl.getUniformIndices(prog, NAMES);

  err = gl.getError();
  if (err) throw err;

  NAMES.forEach((name, i) => {
    const active_id_was = active_ids[i];
    const is_active_expected = IS_ACTIVE_BY_NAME[name];
    const is_active_was = active_id_was != gl.INVALID_INDEX;
    expectTrue(is_active_was == is_active_expected,
               `getUniformIndices([, '${name}' ,]) -> [, ${active_id_was} ,], should be [, ${is_active_expected ? '0<=N<INVALID_INDEX' : 'INVALID_INDEX'} ,]`);
    if (is_active_was) {
      const info = gl.getActiveUniform(prog, active_id_was);
      expectTrue(info.name.startsWith(name), `'${info.name}'.startsWith('${name}')`);
    }
  });
})();

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>