summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/rendering/framebuffer-texture-clear.html
blob: dc5d60def850a1ab194c8a29866b3b2fb87aa7ad (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
<!--
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 framebuffer clearColor with pure 0/1</title>
<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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
"use strict";
// This test verifies a Mac Intel HD 6000/6100 driver bug. See crbug.com/710443.
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas");

function InitializeRGBAData(width, height)
{
  var size = 4 * width * height;
  var data = new Uint8Array(size);
  for (var i = 0; i < size; i++) {
    data[i] = 128;
  }
  return data;
}

function testFramebufferTextureClearWithPureZeroOrOne(clearColor, expectedColor) {
  var width = 32;
  var height = 32;
  var texture0 = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, texture0);
  // It seems that if we add texParameteri here, all cases can pass no matter
  // you use texParameteri or not in Line 85.
  // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  var texData = InitializeRGBAData(width, height);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, texData);

  var fbo0 = gl.createFramebuffer();
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo0);
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture0, 0);
  gl.viewport(0, 0, width, height);
  gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
  gl.clear(gl.COLOR_BUFFER_BIT);

  var texture1 = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, texture1);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  var fbo1 = gl.createFramebuffer();
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo1);
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture1, 0);

  wtu.setupTexturedQuad(gl);

  gl.bindTexture(gl.TEXTURE_2D, texture0);
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  gl.bindFramebuffer(gl.FRAMEBUFFER, fbo1);
  gl.viewport(0, 0, width, height);
  gl.drawArrays(gl.TRIANGLES, 0, 6);

  wtu.checkCanvasRect(gl, 0, 0, 1, 1, expectedColor);

  gl.deleteTexture(texture0);
  gl.deleteFramebuffer(fbo0);
  gl.deleteTexture(texture1);
  gl.deleteFramebuffer(fbo1);
}

description("Test that if clear fbo texture color with pure 0/1 and sample this texture to draw to another fbo, the final render color should be consistent with the clear color.");

for(var index = 0; index < 16; index++)
{
  var r = (index & 8) / 8;
  var g = (index & 4) / 4;
  var b = (index & 2) / 2;
  var a = index & 1;
  var clearColor = [r, g, b, a];
  var expectedColor = [r * 255, g * 255, b * 255, a * 255];
  testFramebufferTextureClearWithPureZeroOrOne(clearColor, expectedColor);
}

debug("");
var successfullyParsed = true;

</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>