forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
framebuffer-test.html
175 lines (152 loc) · 7.51 KB
/
framebuffer-test.html
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!--
Copyright (c) 2009 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebGL Framebuffer Test</title>
<link rel="stylesheet" href="../resources/js-test-style.css"/>
<script src="../resources/js-test-pre.js"></script>
<script src="resources/webgl-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
description("This tests framebuffer/renderbuffer-related functions");
debug("");
debug("Canvas.getContext");
var canvas = document.getElementById("canvas");
var gl = create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking framebuffer/renderbuffer stuff.");
var value = gl.getFramebufferAttachmentParameter(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE,
"calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE.");
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D,
0, // level
gl.RGBA, // internalFormat
canvas.width, // width
canvas.height, // height
0, // border
gl.RGBA, // format
gl.UNSIGNED_BYTE, // type
null); // data
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D,
tex,
0);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"trying to attach a texture to default framebuffer should generate INVALID_OPERATION.");
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.RENDERBUFFER,
null);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION.");
var rb = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height);
glErrorShouldBe(gl, gl.NO_ERROR,
"allocating renderbuffer storage of a newly created renderbuffer should succeed.");
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.RENDERBUFFER,
rb);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION.");
var fbtex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, fbtex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
glErrorShouldBe(gl, gl.NO_ERROR,
"binding a newly created framebuffer should succeed.");
var target = 0x8CA8; // GL_READ_FRAMEBUFFER
gl.getFramebufferAttachmentParameter(
target,
gl.COLOR_ATTACHMENT0,
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
assertMsg(gl.checkFramebufferStatus(target) == 0,
"calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0.");
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
gl.bindFramebuffer(target, gl.createFramebuffer());
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING),
"calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING.");
gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
var attachment = 0x8CE1; // GL_COLOR_ATTACHMENT1
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0);
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb);
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
0x8210); // GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
glErrorShouldBe(gl, gl.INVALID_ENUM,
"calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM.");
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
glErrorShouldBe(gl, gl.NO_ERROR,
"attaching a texture to a framebuffer should succeed.");
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
glErrorShouldBe(gl, gl.NO_ERROR,
"detaching a texture from a framebuffer should succeed.");
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 1);
glErrorShouldBe(gl, gl.INVALID_VALUE,
"calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE.");
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
glErrorShouldBe(gl, gl.NO_ERROR,
"attaching a renderbuffer to a framebuffer should succeed.");
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, null);
glErrorShouldBe(gl, gl.NO_ERROR,
"detaching a renderbuffer from a framebuffer should succeed.");
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
glErrorShouldBe(gl, gl.NO_ERROR,
"binding default (null) framebuffer should succeed.");
}
debug("");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
<script>
</script>
</body>
</html>