summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/rendering/draw-buffers-dirty-state-bug.html
blob: 2b54d4c255f2914f751b29a171e5f79d2277b952 (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
<!--
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 Draw Buffers Dirty State Bug Conformance Tests</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>
<canvas id="canvas" width="64" height="64"> </canvas>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">#version 300 es
in vec4 a_position;
void main() {
    gl_Position = a_position;
}
</script>
<script id="fshader" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
void main() {
    my_FragColor = vec4(1, 0, 0, 1);
}
</script>
<script>
"use strict";
description("This test verifies a bug in draw buffers dirty state management in Chrome (crbug.com/678153).");

debug("");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, null, 2);

if (!gl) {
  testFailed("WebGL context does not exist");
} else {
  testPassed("WebGL context exists");

  runTest();

  debug("");
  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
}

function runTest() {
  debug("");

  var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_position"]);
  wtu.setupUnitQuad(gl);

  var width = 2, height = 2;

  var colorTex = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, colorTex);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);

  var depthTex = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, depthTex);
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT24, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);

  var fb = gl.createFramebuffer();
  gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0);

  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Setup should cause no GL errors");

  wtu.clearAndDrawUnitQuad(gl);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Clear and draw should cause no GL errors");
  wtu.checkCanvasRect(gl, 0, 0, width, height, [255, 0, 0, 255], "should be red");

  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTex, 0);
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);

  wtu.clearAndDrawUnitQuad(gl);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Clear and draw should cause no GL errors");

  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, null, 0);
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0);

  wtu.checkCanvasRect(gl, 0, 0, width, height, [255, 0, 0, 255], "should be red");

  gl.clearColor(0.0, 1.0, 0.0, 1.0);
  gl.clear(gl.COLOR_BUFFER_BIT);
  // Previously in Chrome, switching around the attachments on a framebuffer
  // affected a DrawBuffers cache that was maintained properly during draw
  // calls, but not clears.
  wtu.checkCanvasRect(gl, 0, 0, width, height, [0, 255, 0, 255], "should be green");

  gl.deleteProgram(program);
  gl.deleteFramebuffer(fb);
  gl.deleteTexture(colorTex);
  gl.deleteTexture(depthTex);
}

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

</body>
</html>