summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/context/context-attributes-depth-stencil-antialias-obeyed.html
blob: 7cd91959f0537901712aea5ef671dd60e9e11810 (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
<!--
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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";

function getWebGL(attribs) {
  var canvas = document.createElement("canvas");
  if (!canvas)
    return null;

  // We can't use wtu.create3DContext because it defaults to antialias=false.
  var names = ["webgl2"];
  var gl = null;
  for (var i = 0; i < names.length; ++i) {
    try {
      gl = canvas.getContext(names[i], attribs);
    } catch (e) {
    }
    if (gl) {
      break;
    }
  }
  if (!gl)
    return null;
  return gl;
}

function testAttribs(attribs) {
  var antialias, depth, stencil;
  if (!attribs) {
    antialias = true;
    depth = true;
    stencil = false;
    debug("Testing default attributes: { antialias: true, depth: true, stencil:false }");
  } else {
    antialias = attribs.antialias;
    depth = attribs.depth;
    stencil = attribs.stencil;
    debug("Testing specified attributes: { antialias: " + antialias + ", depth: " + depth + ", stencil: " + stencil + " }");
  }
  var gl = getWebGL(attribs);
  if (!gl) {
    testFailed("Fail to create a context");
    return;
  }
  var actual_attribs = gl.getContextAttributes();
  if (antialias != actual_attribs.antialias)
    testFailed("antialias = " + antialias + " is not obeyed")
  if (depth != actual_attribs.depth)
    testFailed("depth = " + depth + " is not obeyed")
  if (stencil != actual_attribs.stencil)
    testFailed("stencil = " + stencil + " is not obeyed")
  if (antialias == actual_attribs.antialias &&
      depth == actual_attribs.depth &&
      stencil == actual_attribs.stencil) {
    testPassed("Context created with the correct antialias, depth, and stencil.");
  }
}

description('Verify WebGLContextAttributes are working as specified, including depth, stencil, antialias');
testAttribs(null);  // Default attribs
testAttribs({antialias: true, depth: true, stencil: true});
testAttribs({antialias: false, depth: true, stencil: true});
testAttribs({antialias: true, depth: false, stencil: true});
testAttribs({antialias: false, depth: false, stencil: true});
testAttribs({antialias: true, depth: true, stencil: false});
testAttribs({antialias: false, depth: true, stencil: false});
testAttribs({antialias: true, depth: false, stencil: false});
testAttribs({antialias: false, depth: false, stencil: false});

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