Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / renderbuffers / framebuffer-test.html
blob6bf4878cab7d96682ff2f94253dcc7d1eb874959
1 <!--
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.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
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>
16 </head>
17 <body>
18 <div id="description"></div>
19 <div id="console"></div>
20 <canvas id="canvas" width="2" height="2"> </canvas>
21 <script>
22 "use strict";
23 description("This tests framebuffer/renderbuffer-related functions");
25 debug("");
26 debug("Canvas.getContext");
28 var wtu = WebGLTestUtils;
29 var canvas = document.getElementById("canvas");
30 var gl = wtu.create3DContext(canvas);
31 if (!gl) {
32 testFailed("context does not exist");
33 } else {
34 testPassed("context exists");
36 debug("");
37 debug("Checking framebuffer/renderbuffer stuff.");
39 gl.getFramebufferAttachmentParameter(
40 gl.FRAMEBUFFER,
41 gl.COLOR_ATTACHMENT0,
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,
56 0, // level
57 gl.RGBA, // internalFormat
58 canvas.width, // width
59 canvas.height, // height
60 0, // border
61 gl.RGBA, // format
62 gl.UNSIGNED_BYTE, // type
63 null); // data
64 gl.framebufferTexture2D(
65 gl.FRAMEBUFFER,
66 gl.COLOR_ATTACHMENT0,
67 gl.TEXTURE_2D,
68 tex,
69 0);
70 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
71 "trying to attach a texture to default framebuffer should generate INVALID_OPERATION.");
73 gl.framebufferRenderbuffer(
74 gl.FRAMEBUFFER,
75 gl.COLOR_ATTACHMENT0,
76 gl.RENDERBUFFER,
77 null);
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(
88 gl.FRAMEBUFFER,
89 gl.COLOR_ATTACHMENT0,
90 gl.RENDERBUFFER,
91 rb);
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(
106 target,
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.");
169 debug("");
170 var successfullyParsed = true;
172 </script>
173 <script src="../../js/js-test-post.js"></script>
175 </body>
176 </html>