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 </head> |
| 14 <body> |
| 15 <div id="description"></div> |
| 16 <div id="console"></div> |
| 17 |
| 18 <script> |
| 19 |
| 20 var gl; |
| 21 var fbo; |
| 22 var depthBuffer; |
| 23 var stencilBuffer; |
| 24 var depthStencilBuffer; |
| 25 var colorBuffer; |
| 26 var width; |
| 27 var height; |
| 28 |
| 29 function testAttachment(attachment, buffer, isConflicted) |
| 30 { |
| 31 shouldBeNonNull("fbo = gl.createFramebuffer()"); |
| 32 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
| 33 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBU
FFER, colorBuffer); |
| 34 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, buff
er); |
| 35 glErrorShouldBe(gl, gl.NO_ERROR); |
| 36 // If the framebuffer is in an error state for multiple reasons, |
| 37 // we can't guarantee which one will be reported. |
| 38 if ((width == 0 || height == 0) && !isConflicted) { |
| 39 // Zero-sized renderbuffers are supposed to result in an incomplete atta
chment. |
| 40 // However, certain combination may violate implementation specific rest
rictions. |
| 41 shouldBeTrue("gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFE
R_INCOMPLETE_ATTACHMENT || gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAME
BUFFER_UNSUPPORTED"); |
| 42 } else if (isConflicted) { |
| 43 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UN
SUPPORTED"); |
| 44 gl.clear(gl.COLOR_BUFFER_BIT); |
| 45 glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION); |
| 46 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8A
rray(width * height * 4)); |
| 47 glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION); |
| 48 } |
| 49 } |
| 50 |
| 51 function testAttachments(attachment0, buffer0, attachment1, buffer1, isConflicte
d) |
| 52 { |
| 53 shouldBeNonNull("fbo = gl.createFramebuffer()"); |
| 54 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
| 55 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBU
FFER, colorBuffer); |
| 56 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment0, gl.RENDERBUFFER, buf
fer0); |
| 57 glErrorShouldBe(gl, gl.NO_ERROR); |
| 58 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, buf
fer1); |
| 59 glErrorShouldBe(gl, gl.NO_ERROR); |
| 60 // If the framebuffer is in an error state for multiple reasons, |
| 61 // we can't guarantee which one will be reported. |
| 62 if ((width == 0 || height == 0) && !isConflicted) { |
| 63 // Zero-sized renderbuffers are supposed to result in an incomplete atta
chment. |
| 64 // However, certain combination may violate implementation specific rest
rictions. |
| 65 shouldBeTrue("gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFE
R_INCOMPLETE_ATTACHMENT || gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAME
BUFFER_UNSUPPORTED"); |
| 66 } else if (isConflicted) { |
| 67 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UN
SUPPORTED"); |
| 68 } |
| 69 } |
| 70 |
| 71 function testColorRenderbuffer(internalformat) |
| 72 { |
| 73 shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); |
| 74 gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); |
| 75 gl.renderbufferStorage(gl.RENDERBUFFER, internalformat, width, height); |
| 76 glErrorShouldBe(gl, gl.NO_ERROR); |
| 77 testAttachment(gl.COLOR_ATTACHMENT0, colorBuffer, false); |
| 78 } |
| 79 |
| 80 function testDepthStencilRenderbuffer() |
| 81 { |
| 82 shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()"); |
| 83 gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer); |
| 84 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); |
| 85 glErrorShouldBe(gl, gl.NO_ERROR); |
| 86 |
| 87 // OpenGL itself doesn't seem to guarantee that e.g. a 2 x 0 |
| 88 // renderbuffer will report 2 for its width when queried. |
| 89 if (!(height == 0 && width > 0)) |
| 90 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_W
IDTH)", "width"); |
| 91 if (!(width == 0 && height > 0)) |
| 92 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_H
EIGHT)", "height"); |
| 93 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTER
NAL_FORMAT)", "gl.DEPTH_STENCIL"); |
| 94 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_S
IZE)", "0"); |
| 95 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN
_SIZE)", "0"); |
| 96 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_
SIZE)", "0"); |
| 97 shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA
_SIZE)", "0"); |
| 98 // Avoid verifying these for zero-sized renderbuffers for the time |
| 99 // being since it appears that even OpenGL doesn't guarantee them. |
| 100 if (width > 0 && height > 0) { |
| 101 shouldBeTrue("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFF
ER_DEPTH_SIZE) > 0"); |
| 102 shouldBeTrue("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFF
ER_STENCIL_SIZE) > 0"); |
| 103 } |
| 104 glErrorShouldBe(gl, gl.NO_ERROR); |
| 105 testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, false); |
| 106 } |
| 107 |
| 108 description("Test framebuffer object attachment behaviors"); |
| 109 |
| 110 for (width = 0; width <= 2; width += 2) |
| 111 { |
| 112 for (height = 0; height <= 2; height += 2) |
| 113 { |
| 114 debug("Dimensions " + width + " x " + height); |
| 115 |
| 116 debug("Create renderbuffers"); |
| 117 shouldBeNonNull("gl = create3DContext()"); |
| 118 shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); |
| 119 gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); |
| 120 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); |
| 121 glErrorShouldBe(gl, gl.NO_ERROR); |
| 122 shouldBeNonNull("depthBuffer = gl.createRenderbuffer()"); |
| 123 gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer); |
| 124 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, hei
ght); |
| 125 glErrorShouldBe(gl, gl.NO_ERROR); |
| 126 shouldBeNonNull("stencilBuffer = gl.createRenderbuffer()"); |
| 127 gl.bindRenderbuffer(gl.RENDERBUFFER, stencilBuffer); |
| 128 gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height
); |
| 129 glErrorShouldBe(gl, gl.NO_ERROR); |
| 130 shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()"); |
| 131 gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer); |
| 132 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height)
; |
| 133 glErrorShouldBe(gl, gl.NO_ERROR); |
| 134 |
| 135 debug("Attach depth using DEPTH_ATTACHMENT"); |
| 136 testAttachment(gl.DEPTH_ATTACHMENT, depthBuffer, false); |
| 137 debug("Attach depth using STENCIL_ATTACHMENT"); |
| 138 testAttachment(gl.STENCIL_ATTACHMENT, depthBuffer, true); |
| 139 debug("Attach depth using DEPTH_STENCIL_ATTACHMENT"); |
| 140 testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthBuffer, true); |
| 141 debug("Attach stencil using STENCIL_ATTACHMENT"); |
| 142 testAttachment(gl.STENCIL_ATTACHMENT, stencilBuffer, false); |
| 143 debug("Attach stencil using DEPTH_ATTACHMENT"); |
| 144 testAttachment(gl.DEPTH_ATTACHMENT, stencilBuffer, true); |
| 145 debug("Attach stencil using DEPTH_STENCIL_ATTACHMENT"); |
| 146 testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, stencilBuffer, true); |
| 147 debug("Attach depthStencil using DEPTH_STENCIL_ATTACHMENT"); |
| 148 testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, false); |
| 149 debug("Attach depthStencil using DEPTH_ATTACHMENT"); |
| 150 testAttachment(gl.DEPTH_ATTACHMENT, depthStencilBuffer, true); |
| 151 debug("Attach depthStencil using STENCIL_ATTACHMENT"); |
| 152 testAttachment(gl.STENCIL_ATTACHMENT, depthStencilBuffer, true); |
| 153 |
| 154 debug("Attach depth, then stencil, causing conflict"); |
| 155 testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.STENCIL_ATTACHMENT,
stencilBuffer, true); |
| 156 debug("Attach stencil, then depth, causing conflict"); |
| 157 testAttachments(gl.STENCIL_ATTACHMENT, stencilBuffer, gl.DEPTH_ATTACHMEN
T, depthBuffer, true); |
| 158 debug("Attach depth, then depthStencil, causing conflict"); |
| 159 testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.DEPTH_STENCIL_ATTAC
HMENT, depthStencilBuffer, true); |
| 160 debug("Attach depthStencil, then depth, causing conflict"); |
| 161 testAttachments(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, gl.DEPT
H_ATTACHMENT, depthBuffer, true); |
| 162 debug("Attach stencil, then depthStencil, causing conflict"); |
| 163 testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.DEPTH_STENCIL_ATTAC
HMENT, depthStencilBuffer, true); |
| 164 debug("Attach depthStencil, then stencil, causing conflict"); |
| 165 testAttachments(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, gl.STEN
CIL_ATTACHMENT, stencilBuffer, true); |
| 166 |
| 167 debug("Attach color renderbuffer with internalformat == RGBA4"); |
| 168 testColorRenderbuffer(gl.RGBA4); |
| 169 |
| 170 debug("Attach color renderbuffer with internalformat == RGB5_A1"); |
| 171 testColorRenderbuffer(gl.RGB5_A1); |
| 172 |
| 173 debug("Attach color renderbuffer with internalformat == RGB565"); |
| 174 testColorRenderbuffer(gl.RGB565); |
| 175 |
| 176 debug("Create and attach depthStencil renderbuffer"); |
| 177 testDepthStencilRenderbuffer(); |
| 178 } |
| 179 } |
| 180 |
| 181 successfullyParsed = true; |
| 182 </script> |
| 183 |
| 184 <script src="../../resources/js-test-post.js"></script> |
| 185 </body> |
| 186 </html> |
OLD | NEW |