diff options
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers')
6 files changed, 1239 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/00_test_list.txt new file mode 100644 index 000000000..104cada3f --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/00_test_list.txt @@ -0,0 +1,6 @@ +--min-version 1.0.3 feedback-loop.html +--max-version 1.9.9 framebuffer-object-attachment.html +--min-version 1.0.2 framebuffer-state-restoration.html +--max-version 1.9.9 framebuffer-test.html +renderbuffer-initialization.html + diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/feedback-loop.html b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/feedback-loop.html new file mode 100644 index 000000000..a9e3c0b14 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/feedback-loop.html @@ -0,0 +1,125 @@ +<!-- + +/* +** Copyright (c) 2014 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title>WebGL Rendering Feedback Loop</title> + <link rel="stylesheet" href="../../resources/js-test-style.css"/> + <script src="../../js/js-test-pre.js"></script> + <script src="../../js/webgl-test-utils.js"> </script> + </head> + <body> + <canvas id="example" width="1" height="1" style="width: 40px; height: 40px;"></canvas> + <div id="description"></div> + <div id="console"></div> + + <script id="vs" type="text/something-not-javascript"> + attribute vec4 a_position; + attribute vec2 a_texCoord; + varying vec2 v_texCoord; + void main() { + gl_Position = a_position; + v_texCoord = a_texCoord; + } + </script> + <script id="fs" type="text/something-not-javascript"> + precision mediump float; + varying vec2 v_texCoord; + uniform sampler2D u_texture; + void main() { + // Shader swizzles color channels so we can tell if the draw succeeded. + gl_FragColor = texture2D(u_texture, v_texCoord).gbra; + } + </script> + <script> + "use strict"; + description("Checks that rendering feedback loops fail correctly."); + var wtu = WebGLTestUtils; + var gl = wtu.create3DContext("example"); + + var texture = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, + new Uint8Array([255, 0, 0, 255])); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture"); + + var framebuffer = gl.createFramebuffer(); + gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); + + assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE, + "framebuffer should be FRAMEBUFFER_COMPLETE."); + + var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vTexCoord"]); + gl.uniform1i(gl.getUniformLocation(program, "u_texture"), 0); + gl.disable(gl.BLEND); + gl.disable(gl.DEPTH_TEST); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initWebGL"); + + // Drawing with a texture that is also bound to the current framebuffer should fail + var bufferObjects = wtu.setupUnitQuad(gl, 0, 1); + gl.bindTexture(gl.TEXTURE_2D, texture); + wtu.drawUnitQuad(gl); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "after draw with invalid feedback loop"); + + // Ensure that the texture contents did not change after the previous render + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + wtu.clearAndDrawUnitQuad(gl); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); + wtu.checkCanvas(gl, [0, 0, 255, 255], "Should be blue."); + + // Drawing when texture is bound to an inactive uniform should succeed + var texture2 = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, texture2); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, + new Uint8Array([0, 255, 0, 255])); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + + gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); + gl.activeTexture(gl.TEXTURE1); + gl.bindTexture(gl.TEXTURE_2D, texture); + wtu.drawUnitQuad(gl); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after draw where framebuffer texture is bound to inactive texture unit"); + wtu.checkCanvas(gl, [255, 0, 0, 255], "Should be red."); + + var successfullyParsed = true; + </script> + + <script src="../../js/js-test-post.js"></script> + + </body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-object-attachment.html b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-object-attachment.html new file mode 100644 index 000000000..f18454b0d --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-object-attachment.html @@ -0,0 +1,663 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> + +<script> +"use strict"; +var wtu = WebGLTestUtils; +var gl; +var fbo; +var depthBuffer; +var stencilBuffer; +var depthStencilBuffer; +var colorBuffer; +var width; +var height; + +var ALLOW_COMPLETE = 0x01; +var ALLOW_UNSUPPORTED = 0x02; +var ALLOW_INCOMPLETE_ATTACHMENT = 0x04; + +function checkFramebufferForAllowedStatuses(allowedStatuses) +{ + // If the framebuffer is in an error state for multiple reasons, + // we can't guarantee which one will be reported. + var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); + var statusAllowed = ((allowedStatuses & ALLOW_COMPLETE) && (status == gl.FRAMEBUFFER_COMPLETE)) || + ((allowedStatuses & ALLOW_UNSUPPORTED) && (status == gl.FRAMEBUFFER_UNSUPPORTED)) || + ((allowedStatuses & ALLOW_INCOMPLETE_ATTACHMENT) && (status == gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT)); + var msg = "gl.checkFramebufferStatus(gl.FRAMEBUFFER) returned " + status; + if (statusAllowed) + testPassed(msg); + else + testFailed(msg); +} + +function checkBufferBits(attachment0, attachment1) +{ + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) + return; + + var haveDepthBuffer = attachment0 == gl.DEPTH_ATTACHMENT || + attachment0 == gl.DEPTH_STENCIL_ATTACHMENT || + attachment1 == gl.DEPTH_ATTACHMENT || + attachment1 == gl.DEPTH_STENCIL_ATTACHMENT; + var haveStencilBuffer = attachment0 == gl.STENCIL_ATTACHMENT || + attachment0 == gl.DEPTH_STENCIL_ATTACHMENT || + attachment1 == gl.STENCIL_ATTACHMENT || + attachment1 == gl.DEPTH_STENCIL_ATTACHMENT; + + shouldBeTrue("gl.getParameter(gl.RED_BITS) + gl.getParameter(gl.GREEN_BITS) + gl.getParameter(gl.BLUE_BITS) + gl.getParameter(gl.ALPHA_BITS) >= 16"); + + if (haveDepthBuffer) + shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) >= 16"); + else + shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0"); + + if (haveStencilBuffer) + shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) >= 8"); + else + shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) == 0"); +} + +function testAttachment(attachment, buffer, allowedStatuses) +{ + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, buffer); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + checkFramebufferForAllowedStatuses(allowedStatuses); + if ((allowedStatuses & ALLOW_COMPLETE) == 0) { + gl.clear(gl.COLOR_BUFFER_BIT); + wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION); + gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(width * height * 4)); + wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION); + } + checkBufferBits(attachment); + gl.deleteFramebuffer(fbo); +} + +function testAttachments(attachment0, buffer0, attachment1, buffer1, allowedStatuses) +{ + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment0, gl.RENDERBUFFER, buffer0); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, buffer1); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + checkFramebufferForAllowedStatuses(allowedStatuses); + checkBufferBits(attachment0, attachment1); + gl.deleteFramebuffer(fbo); +} + +function testColorRenderbuffer(internalformat, allowedStatuses) +{ + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, internalformat, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + testAttachment(gl.COLOR_ATTACHMENT0, colorBuffer, allowedStatuses); +} + +function testDepthStencilRenderbuffer(allowedStatuses) +{ + shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + + // OpenGL itself doesn't seem to guarantee that e.g. a 2 x 0 + // renderbuffer will report 2 for its width when queried. + if (!(height == 0 && width > 0)) + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)", "width"); + if (!(width == 0 && height > 0)) + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)", "height"); + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)", "gl.DEPTH_STENCIL"); + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)", "0"); + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)", "0"); + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)", "0"); + shouldBe("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)", "0"); + // Avoid verifying these for zero-sized renderbuffers for the time + // being since it appears that even OpenGL doesn't guarantee them. + if (width > 0 && height > 0) { + shouldBeTrue("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE) > 0"); + shouldBeTrue("gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_STENCIL_SIZE) > 0"); + } + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, allowedStatuses); + testDepthStencilDepthStencil(); +} + +function testDepthStencilDepthStencil() +{ + if (!width || !height) { + return; + } + + var tests = [ + { firstFormat: gl.DEPTH_COMPONENT16, + firstAttach: gl.DEPTH_ATTACHMENT, + secondFormat: gl.DEPTH_STENCIL, + secondAttach: gl.DEPTH_STENCIL_ATTACHMENT + }, + { firstFormat: gl.DEPTH_STENCIL, + firstAttach: gl.DEPTH_STENCIL_ATTACHMENT, + secondFormat: gl.DEPTH_COMPONENT16, + secondAttach: gl.DEPTH_ATTACHMENT + } + ]; + for (var ii = 0; ii < tests.length; ++ii) { + var test = tests[ii]; + for (var jj = 0; jj < 2; ++jj) { + var fbo = gl.createFramebuffer(); + var tex = gl.createTexture(); + var firstRb = gl.createRenderbuffer(); + + debug(""); + debug("test: " + wtu.glEnumToString(gl, test.firstFormat) + " vs " + wtu.glEnumToString(gl, test.secondFormat) + " with " + (jj ? "unbind" : "delete")); + + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + // attach texture as color + gl.bindTexture(gl.TEXTURE_2D, tex); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); + + // attach first + gl.bindRenderbuffer(gl.RENDERBUFFER, firstRb); + gl.renderbufferStorage(gl.RENDERBUFFER, test.firstFormat, width, height); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, test.firstAttach, gl.RENDERBUFFER, firstRb); + + shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE'); + gl.enable(gl.DEPTH_TEST); + var program = wtu.setupColorQuad(gl); + // Test it works + wtu.drawUByteColorQuad(gl, [0, 255, 0, 255]); + wtu.drawUByteColorQuad(gl, [255, 0, 0, 255]); // should not draw since DEPTH_FUNC == LESS + wtu.checkCanvasRect(gl, 0, 0, width, height, [0, 255, 0, 255], "should be green"); + + var secondRb = gl.createRenderbuffer(); + + // attach second + gl.bindRenderbuffer(gl.RENDERBUFFER, secondRb); + gl.renderbufferStorage(gl.RENDERBUFFER, test.secondFormat, width, height); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, test.secondAttach, gl.RENDERBUFFER, secondRb); + + if (jj == 0) { + // now delete it + debug("test deleting second renderbuffer"); + gl.deleteRenderbuffer(secondRb); + } else { + // unbind it + debug("test unbinding second renderbuffer"); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, test.secondAttach, gl.RENDERBUFFER, null); + } + + // If the first attachment is not restored this may fail + shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE'); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + + // If the first attachment is not restored this may fail. + gl.clear(gl.DEPTH_BUFFER_BIT); + wtu.drawUByteColorQuad(gl, [0, 255, 0, 255]); + wtu.drawUByteColorQuad(gl, [255, 0, 0, 255]); // should not draw since DEPTH_FUNC == LESS + wtu.checkCanvasRect(gl, 0, 0, width, height, [0, 255, 0, 255], "should be green"); + gl.disable(gl.DEPTH_TEST); + + if (jj == 1) { + gl.deleteRenderbuffer(secondRb); + } + + gl.deleteRenderbuffer(secondRb); + gl.deleteFramebuffer(fbo); + } + } + wtu.glErrorShouldBe(gl, gl.NO_ERROR); +} + +description("Test framebuffer object attachment behaviors"); + +shouldBeNonNull("gl = wtu.create3DContext()"); + +function testFramebufferRequiredCombinations() { + debug("Checking combinations of framebuffer attachments required to be valid"); + + // Per discussion with the OpenGL ES working group, the following framebuffer attachment + // combinations are required to work in all WebGL implementations: + // 1. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + // 2. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_ATTACHMENT = DEPTH_COMPONENT16 renderbuffer + // 3. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_STENCIL_ATTACHMENT = DEPTH_STENCIL renderbuffer + + var fbo = gl.createFramebuffer(); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + + var width = 64; + var height = 64; + + // 1. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + var texture = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); + checkFramebufferForAllowedStatuses(ALLOW_COMPLETE); + checkBufferBits(); + + // 2. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_ATTACHMENT = DEPTH_COMPONENT16 renderbuffer + var renderbuffer = gl.createRenderbuffer(); + gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer); + checkFramebufferForAllowedStatuses(ALLOW_COMPLETE); + checkBufferBits(gl.DEPTH_ATTACHMENT); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null); + + // 3. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_STENCIL_ATTACHMENT = DEPTH_STENCIL renderbuffer + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, renderbuffer); + checkFramebufferForAllowedStatuses(ALLOW_COMPLETE); + checkBufferBits(gl.DEPTH_STENCIL_ATTACHMENT); + + // Clean up + gl.deleteRenderbuffer(renderbuffer); + gl.deleteTexture(texture); + gl.deleteFramebuffer(fbo); +} + +testFramebufferRequiredCombinations(); + +for (width = 0; width <= 2; width += 2) +{ + for (height = 0; height <= 2; height += 2) + { + debug(""); + debug("Dimensions " + width + " x " + height); + + debug("Create renderbuffers"); + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + shouldBeNonNull("depthBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + shouldBeNonNull("stencilBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, stencilBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + + var allowedStatusForGoodCase + = (width == 0 || height == 0) ? ALLOW_INCOMPLETE_ATTACHMENT : ALLOW_COMPLETE; + + // some cases involving stencil seem to be implementation-dependent + var allowedStatusForImplDependentCase = allowedStatusForGoodCase | ALLOW_UNSUPPORTED; + + debug("Attach depth using DEPTH_ATTACHMENT"); + testAttachment(gl.DEPTH_ATTACHMENT, depthBuffer, allowedStatusForGoodCase); + debug("Attach depth using STENCIL_ATTACHMENT"); + testAttachment(gl.STENCIL_ATTACHMENT, depthBuffer, ALLOW_INCOMPLETE_ATTACHMENT); + debug("Attach depth using DEPTH_STENCIL_ATTACHMENT"); + testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthBuffer, ALLOW_INCOMPLETE_ATTACHMENT); + debug("Attach stencil using STENCIL_ATTACHMENT"); + testAttachment(gl.STENCIL_ATTACHMENT, stencilBuffer, allowedStatusForImplDependentCase); + debug("Attach stencil using DEPTH_ATTACHMENT"); + testAttachment(gl.DEPTH_ATTACHMENT, stencilBuffer, ALLOW_INCOMPLETE_ATTACHMENT); + debug("Attach stencil using DEPTH_STENCIL_ATTACHMENT"); + testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, stencilBuffer, ALLOW_INCOMPLETE_ATTACHMENT); + debug("Attach depthStencil using DEPTH_STENCIL_ATTACHMENT"); + testAttachment(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, allowedStatusForGoodCase); + debug("Attach depthStencil using DEPTH_ATTACHMENT"); + testAttachment(gl.DEPTH_ATTACHMENT, depthStencilBuffer, ALLOW_INCOMPLETE_ATTACHMENT); + debug("Attach depthStencil using STENCIL_ATTACHMENT"); + testAttachment(gl.STENCIL_ATTACHMENT, depthStencilBuffer, ALLOW_INCOMPLETE_ATTACHMENT); + + var allowedStatusForConflictedAttachment + = (width == 0 || height == 0) ? ALLOW_UNSUPPORTED | ALLOW_INCOMPLETE_ATTACHMENT + : ALLOW_UNSUPPORTED; + + debug("Attach depth, then stencil, causing conflict"); + testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.STENCIL_ATTACHMENT, stencilBuffer, allowedStatusForConflictedAttachment); + debug("Attach stencil, then depth, causing conflict"); + testAttachments(gl.STENCIL_ATTACHMENT, stencilBuffer, gl.DEPTH_ATTACHMENT, depthBuffer, allowedStatusForConflictedAttachment); + debug("Attach depth, then depthStencil, causing conflict"); + testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, allowedStatusForConflictedAttachment); + debug("Attach depthStencil, then depth, causing conflict"); + testAttachments(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, gl.DEPTH_ATTACHMENT, depthBuffer, allowedStatusForConflictedAttachment); + debug("Attach stencil, then depthStencil, causing conflict"); + testAttachments(gl.DEPTH_ATTACHMENT, depthBuffer, gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, allowedStatusForConflictedAttachment); + debug("Attach depthStencil, then stencil, causing conflict"); + testAttachments(gl.DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer, gl.STENCIL_ATTACHMENT, stencilBuffer, allowedStatusForConflictedAttachment); + + debug("Attach color renderbuffer with internalformat == RGBA4"); + testColorRenderbuffer(gl.RGBA4, allowedStatusForGoodCase); + + debug("Attach color renderbuffer with internalformat == RGB5_A1"); + testColorRenderbuffer(gl.RGB5_A1, allowedStatusForGoodCase); + + debug("Attach color renderbuffer with internalformat == RGB565"); + testColorRenderbuffer(gl.RGB565, allowedStatusForGoodCase); + + debug("Create and attach depthStencil renderbuffer"); + testDepthStencilRenderbuffer(allowedStatusForGoodCase); + } +} + +// Determine if we can attach both color and depth or color and depth_stencil +var depthFormat; +var depthAttachment; + +function checkValidColorDepthCombination() { + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + + shouldBeNonNull("depthBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer); + + return tryDepth(gl.DEPTH_COMPONENT16, gl.DEPTH_ATTACHMENT) || tryDepth(gl.DEPTH_STENCIL, gl.DEPTH_STENCIL_ATTACHMENT); + + function tryDepth(try_format, try_attachment) { + if (depthAttachment) { + // If we've tried once unattach the old one. + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, depthAttachment, gl.RENDERBUFFER, null); + } + depthFormat = try_format; + depthAttachment = try_attachment; + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, depthAttachment, gl.RENDERBUFFER, depthBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 16, 16); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE; + } +} + +if (checkValidColorDepthCombination()) { + testFramebufferIncompleteDimensions(); + testFramebufferIncompleteAttachment(); + testFramebufferIncompleteMissingAttachment(); + testUsingIncompleteFramebuffer(); + testReadingFromMissingAttachment(); +} + +function checkFramebuffer(expected) { + var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER); + var msg = "gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be " + wtu.glEnumToString(gl, expected) + " was " + wtu.glEnumToString(gl, actual); + if (expected != gl.FRAMEBUFFER_COMPLETE) { + msg += " or FRAMEBUFFER_UNSUPPORTED"; + } + if (actual == expected || + (expected != gl.FRAMEBUFFER_COMPLETE && + actual == gl.FRAMBUFFER_UNSUPPORTED)) { + testPassed(msg); + } else { + testFailed(msg); + } +} + +function testUsingIncompleteFramebuffer() { + debug(""); + debug("Test drawing or reading from an incomplete framebuffer"); + var program = wtu.setupTexturedQuad(gl); + var tex = gl.createTexture(); + wtu.fillTexture(gl, tex, 1, 1, [0,255,0,255]); + + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + + shouldBeNonNull("depthBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, depthAttachment, gl.RENDERBUFFER, depthBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 16, 16); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + + // We pick this combination because it works on desktop OpenGL but should not work on OpenGL ES 2.0 + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 32, 16); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS); + debug(""); + debug("Drawing or reading from an incomplete framebuffer should generate INVALID_FRAMEBUFFER_OPERATION"); + testRenderingAndReading(); + + shouldBeNonNull("fbo2 = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo2); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT); + debug(""); + debug("Drawing or reading from an incomplete framebuffer should generate INVALID_FRAMEBUFFER_OPERATION"); + testRenderingAndReading(); + + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 0, 0); + debug(""); + debug("Drawing or reading from an incomplete framebuffer should generate INVALID_FRAMEBUFFER_OPERATION"); + testRenderingAndReading(); + + function testRenderingAndReading() { + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + wtu.clearAndDrawUnitQuad(gl); + wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION, "drawArrays with incomplete framebuffer"); + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); + wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION, "readPixels from incomplete framebuffer"); + // copyTexImage and copyTexSubImage can be either INVALID_FRAMEBUFFER_OPERATION because + // the framebuffer is invalid OR INVALID_OPERATION because in the case of no attachments + // the framebuffer is not of a compatible type. + gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); + wtu.glErrorShouldBe(gl, [gl.INVALID_FRAMEBUFFER_OPERATION, gl.INVALID_OPERATION], "copyTexImage2D from incomplete framebuffer"); + gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 1, 1, 0); + wtu.glErrorShouldBe(gl, [gl.INVALID_FRAMEBUFFER_OPERATION, gl.INVALID_OPERATION], "copyTexSubImage2D from incomplete framebuffer"); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + wtu.glErrorShouldBe(gl, gl.INVALID_FRAMEBUFFER_OPERATION, "clear with incomplete framebuffer"); + } +} + +function testFramebufferIncompleteAttachment() { + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + + debug(""); + debug("Wrong storage type for type of attachment be FRAMEBUFFER_INCOMPLETE_ATTACHMENT (OpenGL ES 2.0 4.4.5)"); + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 16, 16); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT); + + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + + debug(""); + debug("0 size attachment should be FRAMEBUFFER_INCOMPLETE_ATTACHMENT (OpenGL ES 2.0 4.4.5)"); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 0, 0); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR); +} + +function testFramebufferIncompleteMissingAttachment() { + debug(""); + debug("No attachments should be INCOMPLETE_FRAMEBUFFER_MISSING_ATTACHMENT (OpenGL ES 2.0 4.4.5)"); + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT); + + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, null); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR); +} + +function testFramebufferIncompleteDimensions() { + debug(""); + debug("Attachments of different sizes should be FRAMEBUFFER_INCOMPLETE_DIMENSIONS (OpenGL ES 2.0 4.4.5)"); + + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + shouldBeNonNull("colorBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + + shouldBeNonNull("depthBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, depthAttachment, gl.RENDERBUFFER, depthBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 16, 16); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 32, 16); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS); + gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, 16, 16); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 32); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + + var tex = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, tex); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { + return; + } + + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 32, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + checkFramebuffer(gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + checkFramebuffer(gl.FRAMEBUFFER_COMPLETE); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR); +} + +function testReadingFromMissingAttachment() { + debug(""); + debug("Test drawing or reading from a missing framebuffer attachment"); + + shouldBeNonNull("fbo = gl.createFramebuffer()"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + + var size = 16; + + // The only scenario we can verify is an attempt to read or copy + // from a missing color attachment while the framebuffer is still + // complete. + shouldBeNonNull("depthBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, size, size); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "After depth renderbuffer setup"); + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { + debug("Unable to allocate a framebuffer with just a depth attachment; this is legal"); + // Try just a depth/stencil renderbuffer + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null); + shouldBeNonNull("depthStencilBuffer = gl.createRenderbuffer()"); + gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer); + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, size, size); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "After depth+stencil renderbuffer setup"); + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { + debug("Unable to allocate a framebuffer with just a depth+stencil attachment; this is legal"); + return; + } + } + + // The FBO has no color attachment. ReadPixels, CopyTexImage2D, + // and CopyTexSubImage2D should all generate INVALID_OPERATION. + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Before ReadPixels from missing attachment"); + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "After ReadPixels from missing attachment"); + + var tex = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, tex); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Before CopyTexImage2D from missing attachment"); + gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, size, size, 0); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "After CopyTexImage2D from missing attachment"); + + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Before CopyTexSubImage2D from missing attachment"); + gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, size, size); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "After CopyTexSubImage2D from missing attachment"); +} + +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-state-restoration.html b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-state-restoration.html new file mode 100644 index 000000000..a53065365 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-state-restoration.html @@ -0,0 +1,128 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>WebGL Framebuffer state restoration Test</title> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="example" width="50" height="50"> +</canvas> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +var wtu = WebGLTestUtils; +description(); + +function test() { + var gl = wtu.create3DContext("example", {preserveDrawingBuffer: true}); + var program = wtu.setupColorQuad(gl); + var colorLoc = gl.getUniformLocation(program, "u_color"); + gl.enable(gl.DEPTH_TEST); + gl.depthFunc(gl.LESS); + + var testDrawToBackBuffer = function(label) { + debug(""); + debug("drawing to backbuffer " + label); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + // Draw in green + gl.uniform4fv(colorLoc, [0, 1, 0, 1]); + gl.drawArrays(gl.TRIANGLES, 0, 6); + wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); + // Draw in red, should not draw because of depth test. + gl.uniform4fv(colorLoc, [1, 0, 0, 1]); + gl.drawArrays(gl.TRIANGLES, 0, 6); + wtu.checkCanvas(gl, [0, 255, 0, 255], "should still be green"); + } + + var testDrawToFBO = function(label ) { + debug(""); + debug("drawing to framebuffer " + label); + // Draw in green + gl.uniform4fv(colorLoc, [0, 1, 0, 1]); + gl.drawArrays(gl.TRIANGLES, 0, 6); + wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); + // Draw in red as there is not depth buffer. + gl.uniform4fv(colorLoc, [1, 0, 0, 1]); + gl.drawArrays(gl.TRIANGLES, 0, 6); + wtu.checkCanvas(gl, [255, 0, 0, 255], "should be red"); + } + + testDrawToBackBuffer("start"); + + var fbo = gl.createFramebuffer(); + var tex = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, tex); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 50, 50, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { + finishTest(); + return; + } + + wtu.checkCanvas(gl, [0, 0, 0, 0], "should be zero"); + testDrawToFBO("start"); + + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + testDrawToBackBuffer("after drawing to framebuffer"); + + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + testDrawToFBO("after drawing to backbuffer"); + + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + wtu.waitForComposite(function() { + testDrawToBackBuffer("after composite"); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + testDrawToFBO("after drawing to backbuffer after composite"); + wtu.waitForComposite(function() { + testDrawToFBO("after composite"); + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + testDrawToBackBuffer("after drawing to framebuffer after composite"); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); + finishTest(); + }); + }); +} +test(); + +var successfullyParsed = true; +</script> +</body> +</html> + diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-test.html b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-test.html new file mode 100644 index 000000000..1875a7529 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/framebuffer-test.html @@ -0,0 +1,197 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>WebGL Framebuffer Test</title> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +<script src="../../js/desktop-gl-constants.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> +<canvas id="canvas" width="2" height="2"> </canvas> +<script> +"use strict"; +description("This tests framebuffer/renderbuffer-related functions"); + +debug(""); +debug("Canvas.getContext"); + +var wtu = WebGLTestUtils; +var canvas = document.getElementById("canvas"); +var gl = wtu.create3DContext(canvas); +if (!gl) { + testFailed("context does not exist"); +} else { + testPassed("context exists"); + + debug(""); + debug("Checking framebuffer/renderbuffer stuff."); + + gl.getFramebufferAttachmentParameter( + gl.FRAMEBUFFER, + gl.COLOR_ATTACHMENT0, + gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, + "calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION."); + + assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE, + "calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE."); + + var tex = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, tex); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, + 0, // level + gl.RGBA, // internalFormat + canvas.width, // width + canvas.height, // height + 0, // border + gl.RGBA, // format + gl.UNSIGNED_BYTE, // type + null); // data + gl.framebufferTexture2D( + gl.FRAMEBUFFER, + gl.COLOR_ATTACHMENT0, + gl.TEXTURE_2D, + tex, + 0); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, + "trying to attach a texture to default framebuffer should generate INVALID_OPERATION."); + + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, + gl.COLOR_ATTACHMENT0, + gl.RENDERBUFFER, + null); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, + "trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION."); + + var rb = gl.createRenderbuffer(); + gl.bindRenderbuffer(gl.RENDERBUFFER, rb); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "allocating renderbuffer storage of a newly created renderbuffer should succeed."); + + gl.framebufferRenderbuffer( + gl.FRAMEBUFFER, + gl.COLOR_ATTACHMENT0, + gl.RENDERBUFFER, + rb); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, + "trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION."); + + var fbtex = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, fbtex); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + var fb = gl.createFramebuffer(); + + gl.bindFramebuffer(gl.FRAMEBUFFER, fb); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "binding a newly created framebuffer should succeed."); + + var target = desktopGL.READ_FRAMEBUFFER + gl.getFramebufferAttachmentParameter( + target, + gl.COLOR_ATTACHMENT0, + gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); + assertMsg(gl.checkFramebufferStatus(target) == 0, + "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0."); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); + gl.bindFramebuffer(target, gl.createFramebuffer()); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); + assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING), + "calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING."); + gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); + gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); + gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM."); + + var attachment = desktopGL.COLOR_ATTACHMENT1 + gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM."); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM."); + + gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, + gl.COLOR_ATTACHMENT0, + desktopGL.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING); + wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, + "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM."); + + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "attaching a texture to a framebuffer should succeed."); + + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "detaching a texture from a framebuffer should succeed."); + + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 1); + wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, + "calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE."); + + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "attaching a renderbuffer to a framebuffer should succeed."); + + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, null); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "detaching a renderbuffer from a framebuffer should succeed."); + + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, + "binding default (null) framebuffer should succeed."); +} + +debug(""); +var successfullyParsed = true; + +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/renderbuffer-initialization.html b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/renderbuffer-initialization.html new file mode 100644 index 000000000..5e55bd048 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/renderbuffers/renderbuffer-initialization.html @@ -0,0 +1,120 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/js-test-pre.js"></script> +<script src="../../js/webgl-test-utils.js"></script> +</head> +<body> +<canvas id="testbed" width="400" height="400" style="width: 40px; height: 40px;"></canvas> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +var wtu = WebGLTestUtils; +description('Verify renderbuffers are initialized to 0 before being read in WebGL'); + +var gl = wtu.create3DContext("testbed"); +if (!gl) { + testFailed('canvas.getContext() failed'); +} else { + // Set the clear color to green. It should never show up. + gl.clearColor(0, 1, 0, 1); + + runTest(gl, gl.canvas.width, gl.canvas.height, 0); + runTest(gl, gl.canvas.width, gl.canvas.height, 1); + runTest(gl, gl.canvas.width, gl.canvas.height, 0); + runTest(gl, gl.canvas.width, gl.canvas.height, 1); + + // Testing buffer clearing won't change the clear values. + var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE); + shouldBe("clearColor", "[0, 1, 0, 1]"); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors'); +} + +function runTest(gl, width, height, order) +{ + wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], + "internal buffers have been initialized to 0"); + + // fill the back buffer so we know that reading below happens from + // the renderbuffer. + gl.clear(gl.COLOR_BUFFER_BIT); + + var fbo = gl.createFramebuffer(); + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); + var colorbuffer = gl.createRenderbuffer(); + gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer); + switch (order) { + case 0: + allocStorage(width, height); + attachBuffer(colorbuffer); + break; + case 1: + attachBuffer(colorbuffer); + allocStorage(width, height); + break; + } + + function allocStorage(width, height) { + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no error after renderbufferStorage(internalformat = RGBA4).'); + } + + function attachBuffer(colorbuffer) { + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer); + } + + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { + testFailed('Framebuffer incomplete.'); + return; + } + + wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], + "user buffers have been initialized to 0"); + + gl.deleteFramebuffer(fbo); + gl.deleteRenderbuffer(colorbuffer); + + // this clear should not matter we are about to resize + gl.clear(gl.COLOR_BUFFER_BIT); + + gl.canvas.width += 1; + gl.canvas.height += 1; + + debug(''); +} + +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> +</body> +</html> |