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
|
<!--
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>
<script src="../../js/webgl-test-utils.js"></script>
<script>
"use strict";
var wtu = WebGLTestUtils;
// This declaration needs to be global for "shouldBe" to see it
var gl;
function init()
{
description('Verify that a WebGL context with alpha:false still works correctly after handling textures with an alpha channel.');
runTest();
}
function getWebGL(contextAttribs)
{
return wtu.create3DContext("c", contextAttribs);
}
function runTest()
{
var buf = new Uint8Array(1 * 1 * 4);
shouldBeNonNull("gl = getWebGL({ alpha: false, antialias: false })");
// Clear to black. Alpha channel of clearColor() is ignored.
gl.clearColor(0.0, 0.0, 0.0, 0.7);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 255],
"Alpha channel of clearColor should be ignored");
wtu.waitForComposite(function() {
// Make a new framebuffer and attach a texture with an alpha channel.
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
// Clear texture. Note that alpha channel is not 1.0.
gl.clearColor(1.0, 0.0, 0.0, 0.5);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 0, 0, 128],
"Alpha channel of clearColor should be obeyed for FBO with alpha channel",
1);
// Bind back buffer and check that its alpha channel is still 1.0.
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 255],
"Alpha channel of back buffer should still be 255");
finishTest();
});
}
</script>
</head>
<body onload="init()">
<div id="description"></div>
<div id="console"></div>
<canvas width="20" height="20" style="border: 1px solid blue;" id="c"></canvas>
</body>
</html>
|