OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <title>WebGL Framebuffer Test</title> |
| 33 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 34 <script src="../../resources/js-test-pre.js"></script> |
| 35 <script src="../resources/webgl-test.js"></script> |
| 36 <script src="../../resources/desktop-gl-constants.js"></script> |
| 37 </head> |
| 38 <body> |
| 39 <div id="description"></div> |
| 40 <div id="console"></div> |
| 41 <canvas id="canvas" width="2" height="2"> </canvas> |
| 42 <script> |
| 43 description("This tests framebuffer/renderbuffer-related functions"); |
| 44 |
| 45 debug(""); |
| 46 debug("Canvas.getContext"); |
| 47 |
| 48 var canvas = document.getElementById("canvas"); |
| 49 var gl = create3DContext(canvas); |
| 50 if (!gl) { |
| 51 testFailed("context does not exist"); |
| 52 } else { |
| 53 testPassed("context exists"); |
| 54 |
| 55 debug(""); |
| 56 debug("Checking framebuffer/renderbuffer stuff."); |
| 57 |
| 58 var value = gl.getFramebufferAttachmentParameter( |
| 59 gl.FRAMEBUFFER, |
| 60 gl.COLOR_ATTACHMENT0, |
| 61 gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); |
| 62 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 63 "calling getFramebufferAttachmentParameter on the default framebuffe
r should generate INVALID_OPERATION."); |
| 64 |
| 65 assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE
, |
| 66 "calling checkFramebufferStatus on the default framebuffer should ge
nerate FRAMEBUFFER_COMPLETE."); |
| 67 |
| 68 var tex = gl.createTexture(); |
| 69 gl.bindTexture(gl.TEXTURE_2D, tex); |
| 70 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 71 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 73 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 74 gl.texImage2D(gl.TEXTURE_2D, |
| 75 0, // level |
| 76 gl.RGBA, // internalFormat |
| 77 canvas.width, // width |
| 78 canvas.height, // height |
| 79 0, // border |
| 80 gl.RGBA, // format |
| 81 gl.UNSIGNED_BYTE, // type |
| 82 null); // data |
| 83 gl.framebufferTexture2D( |
| 84 gl.FRAMEBUFFER, |
| 85 gl.COLOR_ATTACHMENT0, |
| 86 gl.TEXTURE_2D, |
| 87 tex, |
| 88 0); |
| 89 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 90 "trying to attach a texture to default framebuffer should generate I
NVALID_OPERATION."); |
| 91 |
| 92 gl.framebufferRenderbuffer( |
| 93 gl.FRAMEBUFFER, |
| 94 gl.COLOR_ATTACHMENT0, |
| 95 gl.RENDERBUFFER, |
| 96 null); |
| 97 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 98 "trying to detach default renderbuffer from default framebuffer shou
ld generate INVALID_OPERATION."); |
| 99 |
| 100 var rb = gl.createRenderbuffer(); |
| 101 gl.bindRenderbuffer(gl.RENDERBUFFER, rb); |
| 102 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height)
; |
| 103 glErrorShouldBe(gl, gl.NO_ERROR, |
| 104 "allocating renderbuffer storage of a newly created renderbuffer sho
uld succeed."); |
| 105 |
| 106 gl.framebufferRenderbuffer( |
| 107 gl.FRAMEBUFFER, |
| 108 gl.COLOR_ATTACHMENT0, |
| 109 gl.RENDERBUFFER, |
| 110 rb); |
| 111 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 112 "trying to attach a renderbuffer to the default framebuffer should g
enerate INVALID_OPERATION."); |
| 113 |
| 114 var fbtex = gl.createTexture(); |
| 115 gl.bindTexture(gl.TEXTURE_2D, fbtex); |
| 116 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RG
BA, gl.UNSIGNED_BYTE, null); |
| 117 var fb = gl.createFramebuffer(); |
| 118 |
| 119 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); |
| 120 glErrorShouldBe(gl, gl.NO_ERROR, |
| 121 "binding a newly created framebuffer should succeed."); |
| 122 |
| 123 var target = desktopGL.READ_FRAMEBUFFER |
| 124 gl.getFramebufferAttachmentParameter( |
| 125 target, |
| 126 gl.COLOR_ATTACHMENT0, |
| 127 gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); |
| 128 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 129 "calling getFramebufferAttachmentParameter with target = READ_FRAMEB
UFFER should generate INVALID_ENUM."); |
| 130 assertMsg(gl.checkFramebufferStatus(target) == 0, |
| 131 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER shoul
d return 0."); |
| 132 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 133 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER shoul
d generate INVALID_ENUM."); |
| 134 gl.bindFramebuffer(target, gl.createFramebuffer()); |
| 135 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 136 "calling bindFramebuffer with target = READ_FRAMEBUFFER should gener
ate INVALID_ENUM."); |
| 137 assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING), |
| 138 "calling bindFramebuffer with target = READ_FRAMEBUFFER should not c
hange FRAMEBUFFER_BINDING."); |
| 139 gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUF
FER_ATTACHMENT_OBJECT_TYPE); |
| 140 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 141 "calling getFramebufferAttachmentParameter with target = READ_FRAMEB
UFFER should generate INVALID_ENUM."); |
| 142 gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0)
; |
| 143 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 144 "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should
generate INVALID_ENUM."); |
| 145 gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb); |
| 146 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 147 "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER shou
ld generate INVALID_ENUM."); |
| 148 |
| 149 var attachment = desktopGL.COLOR_ATTACHMENT1 |
| 150 gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0); |
| 151 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 152 "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 s
hould generate INVALID_ENUM."); |
| 153 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb); |
| 154 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 155 "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1
should generate INVALID_ENUM."); |
| 156 |
| 157 gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, |
| 158 gl.COLOR_ATTACHMENT0, |
| 159 desktopGL.FRAMEBUFFER_ATTACHMENT_COLOR_EN
CODING); |
| 160 glErrorShouldBe(gl, gl.INVALID_ENUM, |
| 161 "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFF
ER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM."); |
| 162 |
| 163 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, f
btex, 0); |
| 164 glErrorShouldBe(gl, gl.NO_ERROR, |
| 165 "attaching a texture to a framebuffer should succeed."); |
| 166 |
| 167 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, n
ull, 0); |
| 168 glErrorShouldBe(gl, gl.NO_ERROR, |
| 169 "detaching a texture from a framebuffer should succeed."); |
| 170 |
| 171 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, f
btex, 1); |
| 172 glErrorShouldBe(gl, gl.INVALID_VALUE, |
| 173 "calling framebufferTexture2D with non-zero mipmap level should gene
rate INVALID_VALUE."); |
| 174 |
| 175 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFF
ER, rb); |
| 176 glErrorShouldBe(gl, gl.NO_ERROR, |
| 177 "attaching a renderbuffer to a framebuffer should succeed."); |
| 178 |
| 179 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFF
ER, null); |
| 180 glErrorShouldBe(gl, gl.NO_ERROR, |
| 181 "detaching a renderbuffer from a framebuffer should succeed."); |
| 182 |
| 183 gl.bindFramebuffer(gl.FRAMEBUFFER, null); |
| 184 glErrorShouldBe(gl, gl.NO_ERROR, |
| 185 "binding default (null) framebuffer should succeed."); |
| 186 } |
| 187 |
| 188 debug(""); |
| 189 successfullyParsed = true; |
| 190 |
| 191 </script> |
| 192 <script src="../../resources/js-test-post.js"></script> |
| 193 |
| 194 </body> |
| 195 </html> |
OLD | NEW |