summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/reftest/visible-occluded-ref.html
blob: d5a5853165c037a1fd2811b72f7c4c35675a5f63 (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
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<meta charset='UTF-8'>
<!--
Color Test

Clear the four quadrants of the canvas as follows:
+------+------+
| blue |black |
|      |      |
+------+------+
| red  |green |
|      |      |
+------+------+

Clear with a given alpha value. What effect this has depends on the
context-creation args passed to this page.
-->
<html class='reftest-wait'>

<head>
  <script type='text/javascript' src='webgl-utils.js'></script>
  <script type='text/javascript'>
'use strict';

var COLOR_VALUE = 127.0 / 255.0;
var ALPHA_VALUE = 127.0 / 255.0;

function renderFrame(gl) {
  gl.enable(gl.SCISSOR_TEST);

  gl.scissor(0, 0, 100, 100);
  gl.clearColor(COLOR_VALUE, 0.0, 0.0, ALPHA_VALUE);
  gl.clear(gl.COLOR_BUFFER_BIT);

  gl.scissor(100, 0, 100, 100);
  gl.clearColor(0.0, COLOR_VALUE, 0.0, ALPHA_VALUE);
  gl.clear(gl.COLOR_BUFFER_BIT);

  gl.scissor(0, 100, 100, 100);
  gl.clearColor(0.0, 0.0, COLOR_VALUE, ALPHA_VALUE);
  gl.clear(gl.COLOR_BUFFER_BIT);

  gl.scissor(100, 100, 100, 100);
  gl.clearColor(0.0, 0.0, 0.0, ALPHA_VALUE);
  gl.clear(gl.COLOR_BUFFER_BIT);

  gl.scissor(0, 75, 50, 50);
  gl.clearColor(0.0, 0.0, 1.0, 1.0);
  gl.clear(gl.COLOR_BUFFER_BIT);
}

////////////////////////////////////////////////////////////////////////////////
// Boilerplate

var TIMEOUT_MS = 30 * 1000;

function setStatus(text) {
  var elem = document.getElementById('status');
  elem.innerHTML = text;
}

var gIsComplete = false;

function markComplete(statusText) {
  if (!statusText)
    statusText = '';

  if (gIsComplete)
    return;
  gIsComplete = true;

  setStatus(statusText);
  document.documentElement.removeAttribute('class');
}

function markError(text) {
  markComplete('Error: ' + text);
}

function markTimedOut() {
  markError('Timed out waiting on test completion.');
}

function runFrame(gl, frameCount, maxFrameCount) {
  renderFrame(gl);
  frameCount++;

  if (frameCount >= maxFrameCount) {
    console.log('Rendered ' + frameCount + ' frames.');
    markComplete();
    return;
  }

  requestAnimationFrame(function(){
    runFrame(gl, frameCount, maxFrameCount);
  });
}

function runTest() {
  var canvas = document.getElementById('canvas');

  var gl = initGL(canvas);
  if (!gl) {
    markError('WebGL context creation failed.');
    return;
  }

  var maxFrameCount = arg('frame', 1);
  if (maxFrameCount < 1) {
    markError('Invalid `frame` arg: ' + maxFrameCount);
    return;
  }

  setStatus('Waiting...');

  runFrame(gl, 0, maxFrameCount);
  setTimeout(markTimedOut, TIMEOUT_MS);
}
  </script>
</head>

<body onload='runTest();'>
<canvas style="position:fixed; left: 0px; top: 0px;" id='canvas' width='200' height='200'></canvas>
<div id='status'></div>
</body>

</html>