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
|
<!DOCTYPE HTML>
<title>WebGL test: bug 958723</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script src="driver-info.js"></script>
<script src="webgl-util.js"></script>
<body>
<script>
function TestAttribs(attribs) {
ok(true, 'Testing attribs: ' + JSON.stringify(attribs));
var canvas = document.createElement('canvas');
var gl = canvas.getContext('experimental-webgl', attribs);
ok(gl, 'No tested attribs should result in failure to create a context');
if (!gl)
return;
var actual = gl.getContextAttributes();
ok(actual.alpha == attribs.alpha,
'Resulting `alpha` should match request.');
ok(actual.premultipliedAlpha == attribs.premultipliedAlpha,
'Resulting `premultipliedAlpha` should match request.');
ok(actual.preserveDrawingBuffer == attribs.preserveDrawingBuffer,
'Resulting `preserveDrawingBuffer` should match request.');
// "The depth, stencil and antialias attributes, when set to true, are
// requests, not requirements."
if (!attribs.antialias) {
ok(!actual.antialias, 'No `antialias` if not requested.');
}
if (!attribs.depth) {
ok(!actual.depth, 'No `depth` if not requested.');
}
if (!attribs.stencil) {
ok(!actual.stencil, 'No `stencil` if not requested.');
}
var hasAlpha = !!gl.getParameter(gl.ALPHA_BITS);
var hasDepth = !!gl.getParameter(gl.DEPTH_BITS);
var hasStencil = !!gl.getParameter(gl.STENCIL_BITS);
var hasAntialias = !!gl.getParameter(gl.SAMPLES);
ok(hasAlpha == actual.alpha, 'Bits should match `alpha` attrib.');
ok(hasAntialias == actual.antialias, 'Bits should match `antialias` attrib.');
ok(hasDepth == actual.depth, 'Bits should match `depth` attrib.');
ok(hasStencil == actual.stencil, 'Bits should match `stencil` attrib.');
}
function CloneAttribs(attribs) {
return {
alpha: attribs.alpha,
antialias: attribs.antialias,
depth: attribs.depth,
premultipliedAlpha: attribs.premultipliedAlpha,
preserveDrawingBuffer: attribs.preserveDrawingBuffer,
stencil: attribs.stencil,
};
}
function SplitForAttrib(list, attrib) {
var ret = [];
for (var i in list) {
var cur = list[i];
if (cur[attrib])
throw 'Attrib is already true.';
var clone = CloneAttribs(cur);
clone[attrib] = true;
ret.push(cur);
ret.push(clone);
}
return ret;
}
function GenAttribList() {
var base = {
alpha: false,
antialias: false,
depth: false,
premultipliedAlpha: false,
preserveDrawingBuffer: false,
stencil: false,
};
var list = [base];
list = SplitForAttrib(list, 'alpha');
list = SplitForAttrib(list, 'antialias');
list = SplitForAttrib(list, 'depth');
list = SplitForAttrib(list, 'premultipliedAlpha');
list = SplitForAttrib(list, 'preserveDrawingBuffer');
list = SplitForAttrib(list, 'stencil');
if (list.length != 1<<6)
throw 'Attribs list length wrong: ' + list.length;
return list;
}
var list = GenAttribList();
for (var i in list) {
var attribs = list[i];
TestAttribs(attribs);
}
ok(true, 'Test complete.');
</script>
|