2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL Framebuffer Test
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
15 <script src=
"../../js/desktop-gl-constants.js"></script>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
20 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
23 description("This tests framebuffer/renderbuffer-related functions");
26 debug("Canvas.getContext");
28 var wtu
= WebGLTestUtils
;
29 var canvas
= document
.getElementById("canvas");
30 var gl
= wtu
.create3DContext(canvas
);
32 testFailed("context does not exist");
34 testPassed("context exists");
37 debug("Checking framebuffer/renderbuffer stuff.");
39 gl
.getFramebufferAttachmentParameter(
42 gl
.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
);
43 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
44 "calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
46 assertMsg(gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
,
47 "calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE.");
49 var tex
= gl
.createTexture();
50 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
51 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
52 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
53 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
54 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
55 gl
.texImage2D(gl
.TEXTURE_2D
,
57 gl
.RGBA
, // internalFormat
58 canvas
.width
, // width
59 canvas
.height
, // height
62 gl
.UNSIGNED_BYTE
, // type
64 gl
.framebufferTexture2D(
70 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
71 "trying to attach a texture to default framebuffer should generate INVALID_OPERATION.");
73 gl
.framebufferRenderbuffer(
78 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
79 "trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION.");
81 var rb
= gl
.createRenderbuffer();
82 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, rb
);
83 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA4
, canvas
.width
, canvas
.height
);
84 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
85 "allocating renderbuffer storage of a newly created renderbuffer should succeed.");
87 gl
.framebufferRenderbuffer(
92 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
,
93 "trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION.");
95 var fbtex
= gl
.createTexture();
96 gl
.bindTexture(gl
.TEXTURE_2D
, fbtex
);
97 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, canvas
.width
, canvas
.height
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
98 var fb
= gl
.createFramebuffer();
100 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb
);
101 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
102 "binding a newly created framebuffer should succeed.");
104 var target
= desktopGL
.READ_FRAMEBUFFER
105 gl
.getFramebufferAttachmentParameter(
107 gl
.COLOR_ATTACHMENT0
,
108 gl
.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
);
109 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
110 "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
111 assertMsg(gl
.checkFramebufferStatus(target
) == 0,
112 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0.");
113 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
114 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
115 gl
.bindFramebuffer(target
, gl
.createFramebuffer());
116 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
117 "calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
118 assertMsg(fb
== gl
.getParameter(gl
.FRAMEBUFFER_BINDING
),
119 "calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING.");
120 gl
.getFramebufferAttachmentParameter(target
, gl
.COLOR_ATTACHMENT0
, gl
.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
);
121 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
122 "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
123 gl
.framebufferTexture2D(target
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, fbtex
, 0);
124 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
125 "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
126 gl
.framebufferRenderbuffer(target
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, rb
);
127 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
128 "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
130 var attachment
= desktopGL
.COLOR_ATTACHMENT1
131 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, attachment
, gl
.TEXTURE_2D
, fbtex
, 0);
132 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
133 "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
134 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, attachment
, gl
.RENDERBUFFER
, rb
);
135 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
136 "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
138 gl
.getFramebufferAttachmentParameter(gl
.FRAMEBUFFER
,
139 gl
.COLOR_ATTACHMENT0
,
140 desktopGL
.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
);
141 wtu
.glErrorShouldBe(gl
, gl
.INVALID_ENUM
,
142 "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM.");
144 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, fbtex
, 0);
145 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
146 "attaching a texture to a framebuffer should succeed.");
148 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, null, 0);
149 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
150 "detaching a texture from a framebuffer should succeed.");
152 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, fbtex
, 1);
153 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
,
154 "calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE.");
156 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, rb
);
157 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
158 "attaching a renderbuffer to a framebuffer should succeed.");
160 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, null);
161 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
162 "detaching a renderbuffer from a framebuffer should succeed.");
164 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, null);
165 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
166 "binding default (null) framebuffer should succeed.");
170 var successfullyParsed
= true;
173 <script src=
"../../js/js-test-post.js"></script>