summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/programs/get-active-test.html
blob: ce2b4f9b1abf101a39a91f4b04f8dcf50e8b9cb8 (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
<!--
Copyright (c) 2019 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("Test of getActiveAttrib and getActiveUniform");

var wtu = WebGLTestUtils;
var context = wtu.create3DContext();
var context2 = wtu.create3DContext();
var program = wtu.loadStandardProgram(context);
var program2 = wtu.loadProgramFromFile(context2,
                           "../../resources/intArrayUniformShader.vert",
                           "../../resources/noopUniformShader.frag");

wtu.glErrorShouldBe(context, context.NO_ERROR);
shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'");
shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4");
shouldBe("context.getActiveUniform(program, 0).size", "1");
shouldBeNull("context.getActiveUniform(program, 1)");
wtu.glErrorShouldBe(context, context.INVALID_VALUE);
shouldBeNull("context.getActiveUniform(program, -1)");
wtu.glErrorShouldBe(context, context.INVALID_VALUE);
shouldThrow("context.getActiveUniform(null, 0)");
wtu.glErrorShouldBe(context, context.NO_ERROR);

// we don't know the order the attribs will appear.
var info = [
  context.getActiveAttrib(program, 0),
  context.getActiveAttrib(program, 1)
];
for (var ii = 0; ii < info.length; ++ii)
    shouldBeNonNull("info[ii]");

var expected = [
  { name: 'a_normal', type: context.FLOAT_VEC3, size: 1 },
  { name: 'a_vertex', type: context.FLOAT_VEC4, size: 1 }
];

if (info[0].name != expected[0].name) {
  var t = info[0];
  info[0] = info[1];
  info[1] = t;
}

for (var ii = 0; ii < info.length; ++ii) {
  shouldBe("info[ii].name", "expected[ii].name");
  shouldBe("info[ii].type", "expected[ii].type");
  shouldBe("info[ii].size", "expected[ii].size");
}

// we don't know the order the uniforms will appear.
var info2 = [
    context2.getActiveUniform(program2, 0),
    context2.getActiveUniform(program2, 1)
];
for (var ii = 0; ii < info2.length; ++ii)
    shouldBeNonNull("info2[ii]");

var expected2 = [
    { name: 'ival', type: context2.INT, size: 1 },
    { name: 'ival2[0]', type: context2.INT, size: 2 }
];

if (info2[0].name != expected2[0].name) {
    t = info2[0];
    info2[0] = info2[1];
    info2[1] = t;
}

for (var ii = 0; ii < info2.length; ++ii) {
    shouldBe("info2[ii].name", "expected2[ii].name");
    shouldBe("info2[ii].type", "expected2[ii].type");
    shouldBe("info2[ii].size", "expected2[ii].size");
}

shouldBeNull("context.getActiveAttrib(program, 2)");
wtu.glErrorShouldBe(context, context.INVALID_VALUE);
shouldBeNull("context.getActiveAttrib(program, -1)");
wtu.glErrorShouldBe(context, context.INVALID_VALUE);
shouldThrow("context.getActiveAttrib(null, 0)");
wtu.glErrorShouldBe(context, context.NO_ERROR);

wtu.glErrorShouldBe(context2, context.NO_ERROR);

debug("Check trying to get attribs from different context");
shouldBeNull("context2.getActiveAttrib(program, 0)");
wtu.glErrorShouldBe(context2, context2.INVALID_OPERATION);
shouldBeNull("context2.getActiveUniform(program, 0)");
wtu.glErrorShouldBe(context2, context2.INVALID_OPERATION);

debug("Check trying to get attribs from deleted program");
context.deleteProgram(program);
shouldBeNull("context.getActiveUniform(program, 0)");
wtu.glErrorShouldBe(context, context.INVALID_VALUE);
shouldBeNull("context.getActiveAttrib(program, 0)");
wtu.glErrorShouldBe(context, context.INVALID_VALUE);

var successfullyParsed = true;
</script>

<script src="../../js/js-test-post.js"></script>
</body>
</html>