test_backbuffer_channels.html (3128B)
1 <!DOCTYPE HTML> 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> 7 <body> 8 <script> 9 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'); 15 if (!gl) 16 return; 17 18 var actual = gl.getContextAttributes(); 19 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.'); 26 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.'); 31 } 32 if (!attribs.depth) { 33 ok(!actual.depth, 'No `depth` if not requested.'); 34 } 35 if (!attribs.stencil) { 36 ok(!actual.stencil, 'No `stencil` if not requested.'); 37 } 38 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); 43 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.'); 48 } 49 50 function CloneAttribs(attribs) { 51 return { 52 alpha: attribs.alpha, 53 antialias: attribs.antialias, 54 depth: attribs.depth, 55 premultipliedAlpha: attribs.premultipliedAlpha, 56 preserveDrawingBuffer: attribs.preserveDrawingBuffer, 57 stencil: attribs.stencil, 58 }; 59 } 60 61 function SplitForAttrib(list, attrib) { 62 var ret = []; 63 64 for (var i in list) { 65 var cur = list[i]; 66 if (cur[attrib]) 67 throw 'Attrib is already true.'; 68 69 var clone = CloneAttribs(cur); 70 clone[attrib] = true; 71 72 ret.push(cur); 73 ret.push(clone); 74 } 75 76 return ret; 77 } 78 79 function GenAttribList() { 80 var base = { 81 alpha: false, 82 antialias: false, 83 depth: false, 84 premultipliedAlpha: false, 85 preserveDrawingBuffer: false, 86 stencil: false, 87 }; 88 var list = [base]; 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'); 95 96 if (list.length != 1<<6) 97 throw 'Attribs list length wrong: ' + list.length; 98 99 return list; 100 } 101 102 var list = GenAttribList(); 103 for (var i in list) { 104 var attribs = list[i]; 105 TestAttribs(attribs); 106 } 107 108 ok(true, 'Test complete.'); 109 110 </script>