OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. |
| 5 --> |
| 6 <!DOCTYPE html> |
| 7 <html> |
| 8 <head> |
| 9 <meta charset="utf-8"> |
| 10 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 11 <script src="../../resources/js-test-pre.js"></script> |
| 12 <script src="../resources/webgl-test.js"></script> |
| 13 <script src="../resources/webgl-test-utils.js"></script> |
| 14 </head> |
| 15 <body> |
| 16 <div id="description"></div> |
| 17 <div id="console"></div> |
| 18 |
| 19 <script> |
| 20 description("Tests deletion behavior for texture, renderbuffer, shader, and prog
ram"); |
| 21 |
| 22 var wtu = WebGLTestUtils; |
| 23 var gl = wtu.create3DContext(); |
| 24 var shouldGenerateGLError = wtu.shouldGenerateGLError; |
| 25 |
| 26 debug(""); |
| 27 debug("shader and program deletion"); |
| 28 |
| 29 var vertexShader = wtu.loadStandardVertexShader(gl); |
| 30 assertMsg(vertexShader, "vertex shader loaded"); |
| 31 var fragmentShader = wtu.loadStandardFragmentShader(gl); |
| 32 assertMsg(fragmentShader, "fragment shader loaded"); |
| 33 |
| 34 var program = gl.createProgram(); |
| 35 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.attachShader(program, vertexShader)")
; |
| 36 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.attachShader(program, fragmentShader)
"); |
| 37 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.linkProgram(program)"); |
| 38 shouldBeTrue("gl.getProgramParameter(program, gl.LINK_STATUS)"); |
| 39 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.useProgram(program)"); |
| 40 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteShader(vertexShader)"); |
| 41 shouldBeTrue("gl.isShader(vertexShader)"); |
| 42 shouldBeTrue("gl.getShaderParameter(vertexShader, gl.DELETE_STATUS)"); |
| 43 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.detachShader(program, vertexShader)")
; |
| 44 shouldBeFalse("gl.isShader(vertexShader)"); |
| 45 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteShader(fragmentShader)"); |
| 46 shouldBeTrue("gl.isShader(fragmentShader)"); |
| 47 shouldBeTrue("gl.getShaderParameter(fragmentShader, gl.DELETE_STATUS)"); |
| 48 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteProgram(program)"); |
| 49 shouldBeTrue("gl.isProgram(program)"); |
| 50 shouldBeTrue("gl.getProgramParameter(program, gl.DELETE_STATUS)"); |
| 51 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.useProgram(null)"); |
| 52 shouldBeFalse("gl.isProgram(program)"); |
| 53 shouldBeFalse("gl.isShader(fragmentShader)"); |
| 54 |
| 55 debug(""); |
| 56 debug("texture deletion"); |
| 57 |
| 58 var fbo = gl.createFramebuffer(), fbo2 = gl.createFramebuffer(), fbo3 = gl.creat
eFramebuffer(); |
| 59 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)"
); |
| 60 |
| 61 var tex = gl.createTexture(); |
| 62 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_2D, tex)"); |
| 63 shouldBe("gl.getParameter(gl.TEXTURE_BINDING_2D)", "tex"); |
| 64 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.framebufferTexture2D(gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)"); |
| 65 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "tex"); |
| 66 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteTexture(tex)"); |
| 67 // Deleting a texture bound to the currently-bound fbo is the same as |
| 68 // detaching the textue from fbo first, then delete the texture. |
| 69 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.NONE"); |
| 70 shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.getFramebufferAttachmentParameter
(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)"); |
| 71 shouldBeFalse("gl.isTexture(tex)"); |
| 72 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_2D)"); |
| 73 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_2D, tex)"); |
| 74 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_2D)"); |
| 75 |
| 76 var texCubeMap = gl.createTexture(); |
| 77 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_CUBE_MAP, texC
ubeMap)"); |
| 78 shouldBe("gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP)", "texCubeMap"); |
| 79 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteTexture(texCubeMap)"); |
| 80 shouldBeFalse("gl.isTexture(texCubeMap)"); |
| 81 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP)"); |
| 82 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_CUBE_MAP, texC
ubeMap)"); |
| 83 shouldBeNull("gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP)"); |
| 84 |
| 85 var t = gl.createTexture(); |
| 86 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_2D, t)"); |
| 87 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTU
RE_WRAP_S, gl.CLAMP_TO_EDGE)"); |
| 88 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteTexture(t)"); |
| 89 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindTexture(gl.TEXTURE_2D, t)"); |
| 90 shouldGenerateGLError(gl, gl.INVALID_OPERATION, "gl.texParameteri(gl.TEXTURE_2D,
gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)"); |
| 91 |
| 92 debug(""); |
| 93 debug("renderbuffer deletion"); |
| 94 |
| 95 var rbo = gl.createRenderbuffer(), rbo2 = gl.createRenderbuffer(), rbo3 = gl.cre
ateRenderbuffer(); |
| 96 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo
)"); |
| 97 shouldBe("gl.getParameter(gl.RENDERBUFFER_BINDING)", "rbo"); |
| 98 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.framebufferRenderbuffer(gl.FRAMEBUFFE
R, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo)"); |
| 99 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", "rbo"); |
| 100 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteRenderbuffer(rbo)"); |
| 101 // Deleting a renderbuffer bound to the currently-bound fbo is the same as |
| 102 // detaching the renderbuffer from fbo first, then delete the renderbuffer. |
| 103 shouldBe("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)", "gl.NONE"); |
| 104 shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.getFramebufferAttachmentParameter
(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)"); |
| 105 shouldBeFalse("gl.isRenderbuffer(rbo)"); |
| 106 shouldBeNull("gl.getParameter(gl.RENDERBUFFER_BINDING)"); |
| 107 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo
)"); |
| 108 shouldBeNull("gl.getParameter(gl.RENDERBUFFER_BINDING)"); |
| 109 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindRenderbuffer(gl.RENDERBUFFER, rbo
2)"); |
| 110 shouldBe("gl.getParameter(gl.RENDERBUFFER_BINDING)", "rbo2"); |
| 111 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteRenderbuffer(rbo3)"); |
| 112 shouldBe("gl.getParameter(gl.RENDERBUFFER_BINDING)", "rbo2"); |
| 113 |
| 114 debug(""); |
| 115 debug("buffer deletion"); |
| 116 |
| 117 var buffer = gl.createBuffer(); |
| 118 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer)")
; |
| 119 shouldBe("gl.getParameter(gl.ARRAY_BUFFER_BINDING)", "buffer"); |
| 120 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteBuffer(buffer)"); |
| 121 shouldBeFalse("gl.isBuffer(buffer)"); |
| 122 shouldBeNull("gl.getParameter(gl.ARRAY_BUFFER_BINDING)"); |
| 123 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ARRAY_BUFFER, buffer)")
; |
| 124 shouldBeNull("gl.getParameter(gl.ARRAY_BUFFER_BINDING)"); |
| 125 |
| 126 var bufferElement = gl.createBuffer(); |
| 127 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, b
ufferElement)"); |
| 128 shouldBe("gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING)", "bufferElement"); |
| 129 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteBuffer(bufferElement)"); |
| 130 shouldBeFalse("gl.isBuffer(bufferElement)"); |
| 131 shouldBeNull("gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING)"); |
| 132 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, b
ufferElement)"); |
| 133 shouldBeNull("gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING)"); |
| 134 |
| 135 var b = gl.createBuffer(); |
| 136 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ARRAY_BUFFER, b)"); |
| 137 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bufferData(gl.ARRAY_BUFFER, 1, gl.STA
TIC_DRAW)"); |
| 138 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteBuffer(b)"); |
| 139 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindBuffer(gl.ARRAY_BUFFER, b)"); |
| 140 shouldGenerateGLError(gl, gl.INVALID_OPERATION, "gl.bufferData(gl.ARRAY_BUFFER,
1, gl.STATIC_DRAW)"); |
| 141 |
| 142 debug(""); |
| 143 debug("framebuffer deletion"); |
| 144 |
| 145 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)"
); |
| 146 shouldBe("gl.getParameter(gl.FRAMEBUFFER_BINDING)", "fbo"); |
| 147 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteFramebuffer(fbo)"); |
| 148 shouldBeFalse("gl.isFramebuffer(fbo)"); |
| 149 shouldBeNull("gl.getParameter(gl.FRAMEBUFFER_BINDING)"); |
| 150 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)"
); |
| 151 shouldBeNull("gl.getParameter(gl.FRAMEBUFFER_BINDING)"); |
| 152 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2)
"); |
| 153 shouldBe("gl.getParameter(gl.FRAMEBUFFER_BINDING)", "fbo2"); |
| 154 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.deleteFramebuffer(fbo3)"); |
| 155 shouldBe("gl.getParameter(gl.FRAMEBUFFER_BINDING)", "fbo2"); |
| 156 |
| 157 successfullyParsed = true; |
| 158 </script> |
| 159 |
| 160 <script src="../../resources/js-test-post.js"></script> |
| 161 </body> |
| 162 </html> |
OLD | NEW |