2 <title>WebGL test: bug
958723</title>
3 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
5 <script src=
"driver-info.js"></script>
6 <script src=
"webgl-util.js"></script>
10 function TestAttribs(attribs
) {
11 ok(true, 'Testing attribs: ' + JSON
.stringify(attribs
));
12 var canvas
= document
.createElement('canvas');
13 var gl
= canvas
.getContext('experimental-webgl', attribs
);
14 ok(gl
, 'No tested attribs should result in failure to create a context');
18 var actual
= gl
.getContextAttributes();
20 ok(actual
.alpha
== attribs
.alpha
,
21 'Resulting `alpha` should match request.');
22 ok(actual
.premultipliedAlpha
== attribs
.premultipliedAlpha
,
23 'Resulting `premultipliedAlpha` should match request.');
24 ok(actual
.preserveDrawingBuffer
== attribs
.preserveDrawingBuffer
,
25 'Resulting `preserveDrawingBuffer` should match request.');
27 // "The depth, stencil and antialias attributes, when set to true, are
28 // requests, not requirements."
29 if (!attribs
.antialias
) {
30 ok(!actual
.antialias
, 'No `antialias` if not requested.');
33 ok(!actual
.depth
, 'No `depth` if not requested.');
35 if (!attribs
.stencil
) {
36 ok(!actual
.stencil
, 'No `stencil` if not requested.');
39 var hasAlpha
= !!gl
.getParameter(gl
.ALPHA_BITS
);
40 var hasDepth
= !!gl
.getParameter(gl
.DEPTH_BITS
);
41 var hasStencil
= !!gl
.getParameter(gl
.STENCIL_BITS
);
42 var hasAntialias
= !!gl
.getParameter(gl
.SAMPLES
);
44 ok(hasAlpha
== actual
.alpha
, 'Bits should match `alpha` attrib.');
45 ok(hasAntialias
== actual
.antialias
, 'Bits should match `antialias` attrib.');
46 ok(hasDepth
== actual
.depth
, 'Bits should match `depth` attrib.');
47 ok(hasStencil
== actual
.stencil
, 'Bits should match `stencil` attrib.');
50 function CloneAttribs(attribs
) {
53 antialias
: attribs
.antialias
,
55 premultipliedAlpha
: attribs
.premultipliedAlpha
,
56 preserveDrawingBuffer
: attribs
.preserveDrawingBuffer
,
57 stencil
: attribs
.stencil
,
61 function SplitForAttrib(list
, attrib
) {
67 throw 'Attrib is already true.';
69 var clone
= CloneAttribs(cur
);
79 function GenAttribList() {
84 premultipliedAlpha
: false,
85 preserveDrawingBuffer
: false,
89 list
= SplitForAttrib(list
, 'alpha');
90 list
= SplitForAttrib(list
, 'antialias');
91 list
= SplitForAttrib(list
, 'depth');
92 list
= SplitForAttrib(list
, 'premultipliedAlpha');
93 list
= SplitForAttrib(list
, 'preserveDrawingBuffer');
94 list
= SplitForAttrib(list
, 'stencil');
96 if (list
.length
!= 1<<6)
97 throw 'Attribs list length wrong: ' + list
.length
;
102 var list
= GenAttribList();
103 for (var i
in list
) {
104 var attribs
= list
[i
];
105 TestAttribs(attribs
);
108 ok(true, 'Test complete.');