summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/state/gl-geterror.html
blob: ad5c18e267ce05e82f3e8a4fbef7586d14880741 (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
<!--
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">
<title>WebGL get error conformance test.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/desktop-gl-constants.js"></script>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="1" height="1" style="width: 256px; height: 48px;"></canvas>
<div id="description"></div><div id="console"></div>
<script>
"use strict";
description("Test getError.");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);

gl.enable(desktopGL.ALPHA_TEST);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "should generate INVALID_ENUM");
gl.viewport(-1, -1, -1, -1);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should generate INVALID_VALUE");
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "should generate INVALID_OPERATION");

// Generate 2 errors of each type for 6 total possible errors.
// The OpenGL ES 2.0 spec section 2.5 says the implementation is allowed to
// either return the first error or many errors in an unspecied order.
gl.viewport(-1, -1, -1, -1);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.enable(desktopGL.ALPHA_TEST);
gl.viewport(-1, -1, -1, -1);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
// Note: This error is specifically last because we know it will be synthasized
// by WebGL at least when implemented on top of Desktop OpenGL
gl.enable(desktopGL.ALPHA_TEST);

var err1 = gl.getError();
var err2 = gl.getError();
var err3 = gl.getError();
var err4 = gl.getError();
var err5 = gl.getError();
var err6 = gl.getError();

debug("");
if (err2 == gl.NO_ERROR) {
  debug("This WebGL implementation looks like it uses the 'first error' method");
  debug("There should be 1 error, the first one generated");
  shouldBeTrue('err1 == gl.INVALID_VALUE && err2 == gl.NO_ERROR && err3 == gl.NO_ERROR');
} else {
  debug("This WebGL implementation looks like it uses the many error method");
  debug("Check is that at least one of the errors is the first error");
  shouldBeTrue('err1 == gl.INVALID_VALUE || ' +
               'err2 == gl.INVALID_VALUE || ' +
               'err3 == gl.INVALID_VALUE || ' +
               'err4 == gl.INVALID_VALUE || ' +
               'err5 == gl.INVALID_VALUE || ' +
               'err6 == gl.INVALID_VALUE');
  shouldBeTrue('gl.getError() == gl.NO_ERROR');
}

debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>