5 <script src=
"../../../resources/js-test.js"></script>
6 <script src=
"resources/webgl-test.js"></script>
7 <script src=
"resources/webgl-test-utils.js"></script>
10 <div id=
"description"></div>
11 <div id=
"console"></div>
14 description("Tests deletion behavior for texture, renderbuffer, shader, and program");
17 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
19 var wtu
= WebGLTestUtils
;
20 var gl
= wtu
.create3DContext();
21 var shouldGenerateGLError
= wtu
.shouldGenerateGLError
;
24 debug("shader and program deletion");
26 var vertexShader
= wtu
.loadStandardVertexShader(gl
);
27 assertMsg(vertexShader
, "vertex shader loaded");
28 var fragmentShader
= wtu
.loadStandardFragmentShader(gl
);
29 assertMsg(fragmentShader
, "fragment shader loaded");
31 var program
= gl
.createProgram();
32 shouldBeNonNull("program");
33 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.attachShader(program, vertexShader)");
34 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.attachShader(program, fragmentShader)");
35 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.linkProgram(program)");
36 shouldBeTrue("gl.getProgramParameter(program, gl.LINK_STATUS)");
37 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.useProgram(program)");
38 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteShader(vertexShader)");
39 shouldBeTrue("gl.isShader(vertexShader)");
40 shouldBeTrue("gl.getShaderParameter(vertexShader, gl.DELETE_STATUS)");
41 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.detachShader(program, vertexShader)");
42 shouldBeFalse("gl.isShader(vertexShader)");
43 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteShader(fragmentShader)");
44 shouldBeTrue("gl.isShader(fragmentShader)");
45 shouldBeTrue("gl.getShaderParameter(fragmentShader, gl.DELETE_STATUS)");
46 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteProgram(program)");
47 shouldBeTrue("gl.isProgram(program)");
48 shouldBeTrue("gl.getProgramParameter(program, gl.DELETE_STATUS)");
49 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.useProgram(null)");
50 shouldBeFalse("gl.isProgram(program)");
51 shouldBeFalse("gl.isShader(fragmentShader)");
54 debug("texture deletion");
56 var fbo
= gl
.createFramebuffer(), fbo2
= gl
.createFramebuffer(), fbo3
= gl
.createFramebuffer();
57 shouldBeNonNull("fbo");
58 shouldBeNonNull("fbo2");
59 shouldBeNonNull("fbo3");
60 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
62 var tex
= gl
.createTexture();
63 shouldBeNonNull("tex");
64 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, tex)");
65 shouldBe("gl.getParameter(gl.TEXTURE_BINDING_2D)", "tex");
66 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)");
67 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "tex");
68 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.TEXTURE");
69 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteTexture(tex)");
70 // Deleting a texture bound to the currently-bound fbo is the same as
71 // detaching the textue from fbo first, then delete the texture.
72 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.NONE");
73 shouldGenerateGLError(gl
, gl
.INVALID_ENUM
, "gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)");
74 shouldBeFalse("gl.isTexture(tex)");
75 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_2D)");
76 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, tex)");
77 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_2D)");
79 var texCubeMap
= gl
.createTexture();
80 shouldBeNonNull("texCubeMap");
81 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap)");
82 shouldBe("gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP)", "texCubeMap");
83 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteTexture(texCubeMap)");
84 shouldBeFalse("gl.isTexture(texCubeMap)");
85 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP)");
86 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCubeMap)");
87 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP)");
89 var t
= gl
.createTexture();
91 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, t)");
92 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)");
93 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteTexture(t)");
94 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, t)");
95 shouldGenerateGLError(gl
, gl
.INVALID_OPERATION
, "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)");
97 var t2
= gl
.createTexture();
98 shouldBeNonNull("t2");
99 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.activeTexture(gl.TEXTURE0)");
100 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, t2)");
101 shouldBe("gl.getParameter(gl.TEXTURE_BINDING_2D)", "t2");
102 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.activeTexture(gl.TEXTURE1)");
103 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, t2)");
104 shouldBe("gl.getParameter(gl.TEXTURE_BINDING_2D)", "t2");
105 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteTexture(t2)");
106 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_2D)");
107 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.activeTexture(gl.TEXTURE0)");
108 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_2D)");
111 debug("renderbuffer deletion");
113 var rbo
= gl
.createRenderbuffer(), rbo2
= gl
.createRenderbuffer(), rbo3
= gl
.createRenderbuffer();
114 shouldBeNonNull("rbo");
115 shouldBeNonNull("rbo2");
116 shouldBeNonNull("rbo3");
117 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)");
118 shouldBe("gl.getParameter(gl.RENDERBUFFER_BINDING)", "rbo");
119 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)");
120 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "rbo");
121 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteRenderbuffer(rbo)");
122 // Deleting a renderbuffer bound to the currently-bound fbo is the same as
123 // detaching the renderbuffer from fbo first, then delete the renderbuffer.
124 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.NONE");
125 shouldGenerateGLError(gl
, gl
.INVALID_ENUM
, "gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)");
126 shouldBeFalse("gl.isRenderbuffer(rbo)");
127 shouldBeNull("gl.getParameter(gl.RENDERBUFFER_BINDING)");
128 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)");
129 shouldBeNull("gl.getParameter(gl.RENDERBUFFER_BINDING)");
130 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo2)");
131 shouldBe("gl.getParameter(gl.RENDERBUFFER_BINDING)", "rbo2");
132 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteRenderbuffer(rbo3)");
133 shouldBe("gl.getParameter(gl.RENDERBUFFER_BINDING)", "rbo2");
136 debug("using deleted renderbuffer");
137 rbo
= gl
.createRenderbuffer();
138 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)");
139 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16)");
140 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
141 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)");
142 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
143 // make backbuffer red
144 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
145 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(1,0,0,1)");
146 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
148 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
149 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,1,0,1)");
150 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
152 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
153 // delete renderbuffer. It should still be attached to fbo though.
154 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteRenderbuffer(rbo)");
155 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [255,0,0,255], "backbuffer should be red")');
156 // Use fbo that has deleted rbo.
157 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
158 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [0,255,0,255], "fbo should be green")');
159 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,0,1,1)");
160 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
161 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [0,0,255,255], "fbo should be blue")');
163 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
164 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [255,0,0,255], "backbuffer should be red")');
168 debug("renderbuffer attached twice to same framebuffer");
169 rbo
= gl
.createRenderbuffer();
170 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)");
171 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16)");
172 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
173 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)");
174 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
175 rbo2
= gl
.createRenderbuffer();
176 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo2)");
177 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16)");
178 // attach rbo2 at two attachment points incompatible with it
179 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, rbo2)");
180 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, rbo2)");
181 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "rbo2");
182 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "rbo2");
183 // fbo can't be complete as rbo2 is attached at incompatible attachment points
184 shouldNotBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
185 // now we delete rbo2, which detaches it from the two attachment points where it currently is attached
186 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteRenderbuffer(rbo2)");
187 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.NONE");
188 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.NONE");
189 // we should now be in the same state as before with only rbo attached, so fbo should be complete again
190 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
191 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "rbo");
193 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteRenderbuffer(rbo)");
194 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
199 debug("using deleted texture");
200 tex
= gl
.createTexture();
201 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, tex)");
202 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
203 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)");
204 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)");
205 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
207 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
208 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,1,0,1)");
209 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
211 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
212 // delete texture. It should still be attached to fbo though.
213 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteTexture(tex)");
214 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255,0,0,255], "backbuffer should be red")');
215 // Use fbo that has deleted texture.
216 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
217 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0,255,0,255], "fbo should be green")');
218 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,0,1,1)");
219 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
220 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0,0,255,255], "fbo should be blue")');
222 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
223 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [255,0,0,255], "backbuffer should be red")');
227 debug("using deleted renderbuffer");
228 rbo
= gl
.createRenderbuffer();
229 shouldBeNonNull("rbo");
230 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)");
231 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16)");
232 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
233 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)");
234 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
235 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2)");
236 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)");
237 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
238 // make backbuffer red
239 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
240 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(1,0,0,1)");
241 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
243 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
244 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,1,0,1)");
245 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
246 // delete renderbuffer. It should still be attached to fbo2 though.
247 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteRenderbuffer(rbo)");
248 // fbo has no attachments
249 shouldNotBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
250 // Use fbo2 that has deleted rbo.
251 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2)");
252 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [0,255,0,255], "fbo should be green")');
253 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,0,1,1)");
254 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
255 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [0,0,255,255], "fbo should be blue")');
256 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "rbo");
258 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
259 shouldGenerateGLError(gl
, gl
.INVALID_ENUM
, "gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)");
260 shouldGenerateGLError(gl
, gl
.NONE
, "gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)");
261 shouldNotBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
263 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
264 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [255,0,0,255], "backbuffer should be red")');
268 debug("using deleted texture");
269 tex
= gl
.createTexture();
270 shouldBeNonNull("tex");
271 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindTexture(gl.TEXTURE_2D, tex)");
272 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
273 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)");
274 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)");
275 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
276 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2)");
277 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)");
279 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
280 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,1,0,1)");
281 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
282 // delete texture. It should still be attached to fbo2 though.
283 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteTexture(tex)");
284 // fbo has no attachments
285 shouldNotBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
286 // Use fbo that has deleted texture.
287 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2)");
288 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
289 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0,255,0,255], "fbo should be green")');
290 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,0,1,1)");
291 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
292 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0,0,255,255], "fbo should be blue")');
293 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "tex");
295 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
296 shouldGenerateGLError(gl
, gl
.INVALID_ENUM
, "gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)");
297 shouldNotBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
299 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
300 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [255,0,0,255], "backbuffer should be red")');
304 debug("buffer deletion");
306 var buffer
= gl
.createBuffer();
307 shouldBeNonNull("buffer");
308 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer)");
309 shouldBe("gl.getParameter(gl.ARRAY_BUFFER_BINDING)", "buffer");
310 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteBuffer(buffer)");
311 shouldBeFalse("gl.isBuffer(buffer)");
312 shouldBeNull("gl.getParameter(gl.ARRAY_BUFFER_BINDING)");
313 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer)");
314 shouldBeNull("gl.getParameter(gl.ARRAY_BUFFER_BINDING)");
316 var buffer2
= gl
.createBuffer();
317 shouldBeNonNull("buffer2");
318 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer2)");
319 shouldBe("gl.getParameter(gl.ARRAY_BUFFER_BINDING)", "buffer2");
320 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, null)");
321 shouldBeNull("gl.getParameter(gl.ARRAY_BUFFER_BINDING)");
322 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteBuffer(buffer2)");
323 shouldBeFalse("gl.isBuffer(buffer2)");
324 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer2)");
325 shouldBeNull("gl.getParameter(gl.ARRAY_BUFFER_BINDING)");
327 var bufferElement
= gl
.createBuffer();
328 shouldBeNonNull("bufferElement");
329 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferElement)");
330 shouldBe("gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING)", "bufferElement");
331 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteBuffer(bufferElement)");
332 shouldBeFalse("gl.isBuffer(bufferElement)");
333 shouldBeNull("gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING)");
334 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferElement)");
335 shouldBeNull("gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING)");
337 var b
= gl
.createBuffer();
338 shouldBeNonNull("b");
339 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, b)");
340 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW)");
341 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteBuffer(b)");
342 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, b)");
343 shouldGenerateGLError(gl
, gl
.INVALID_OPERATION
, "gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STATIC_DRAW)");
345 var b1
= gl
.createBuffer();
346 shouldBeNonNull("b1");
347 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, b1);");
348 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.enableVertexAttribArray(1);");
349 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0);");
350 var b2
= gl
.createBuffer();
351 shouldBeNonNull("b2");
352 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindBuffer(gl.ARRAY_BUFFER, b2);");
353 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.enableVertexAttribArray(2);");
354 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.vertexAttribPointer(2, 4, gl.FLOAT, false, 0, 0);");
355 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.enableVertexAttribArray(3);");
356 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.vertexAttribPointer(3, 4, gl.FLOAT, false, 0, 0);");
357 shouldBe("gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)", "b1");
358 shouldBe("gl.getVertexAttrib(2, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)", "b2");
359 shouldBe("gl.getVertexAttrib(3, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)", "b2");
360 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteBuffer(b2);");
361 shouldBe("gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)", "b1");
362 shouldBeNull("gl.getVertexAttrib(2, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)");
363 shouldBeNull("gl.getVertexAttrib(3, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)");
364 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteBuffer(b1);");
365 shouldBeNull("gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)");
368 debug("framebuffer deletion");
370 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
371 shouldBe("gl.getParameter(gl.FRAMEBUFFER_BINDING)", "fbo");
372 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteFramebuffer(fbo)");
373 shouldBeFalse("gl.isFramebuffer(fbo)");
374 shouldBeNull("gl.getParameter(gl.FRAMEBUFFER_BINDING)");
375 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
376 shouldBeNull("gl.getParameter(gl.FRAMEBUFFER_BINDING)");
377 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2)");
378 shouldBe("gl.getParameter(gl.FRAMEBUFFER_BINDING)", "fbo2");
379 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteFramebuffer(fbo3)");
380 shouldBe("gl.getParameter(gl.FRAMEBUFFER_BINDING)", "fbo2");
382 fbo
= gl
.createFramebuffer();
383 rbo
= gl
.createRenderbuffer();
384 shouldBeNonNull("fbo");
385 shouldBeNonNull("rbo");
386 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
387 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo)");
388 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16)");
389 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)");
390 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
) {
391 // set backbuffer to red
392 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
393 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(1,0,0,1)");
394 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
395 // set framebuffer to green
396 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)");
397 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,1,0,1)");
398 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
400 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 16, 16, [0,255,0,255], "fbo should be green")');
401 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 16, 16, 1, 1, [0,0,0,0], "outside fbo should be black")');
402 // delete framebuffer. because this was the bound fbo the backbuffer should be active now
403 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.deleteFramebuffer(fbo)");
405 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 300, 150, [255,0,0,255], "backbuffer should be red")');
406 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 300, 0, 300, 300, [0,0,0,0], "outside backbuffer should be black")');
407 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 150, 300, 300, [0,0,0,0], "outside backbuffer should be black")');
408 // check drawing to backbuffer
409 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clearColor(0,1,0,1)");
410 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.clear(gl.COLOR_BUFFER_BIT)");
411 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 300, 150, [0,255,0,255], "fbo should be green")');
412 shouldGenerateGLError(gl
, gl
.NO_ERROR
, "gl.bindFramebuffer(gl.FRAMEBUFFER, null)");
413 // check again because many buggy implementations will have bound to the true backbuffer on deleteFramebuffer.
414 shouldGenerateGLError(gl
, gl
.NO_ERROR
, 'wtu.checkCanvasRect(gl, 0, 0, 300, 150, [0,255,0,255], "fbo should be green")');
417 successfullyParsed
= true;