Skip to content

Commit

Permalink
Test that deleted fbo attachments behave same as undeleted wrt DEPTH_…
Browse files Browse the repository at this point in the history
…STENCIL_ATTACHMENT (#3582) (#3583)

Test that deleted fbo attachments behave same as undeleted wrt
DEPTH_STENCIL_ATTACHMENT.
  • Loading branch information
kkinnunen-apple authored Oct 6, 2023
1 parent ce353bf commit c98b096
Showing 1 changed file with 93 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@
gl.deleteFramebuffer(fbo);
}

function testDepthStencilAttachmentBehaviors() {
function testDepthStencilAttachmentBehaviors(testOrphanedRenderbuffers) {
let suffix = testOrphanedRenderbuffers ? " with deleted renderbuffer" : "";
debug("");
debug("Checking ES3 DEPTH_STENCIL_ATTACHMENT behaviors are implemented for WebGL 2");
debug("Checking ES3 DEPTH_STENCIL_ATTACHMENT behaviors are implemented for WebGL 2" + suffix);
// DEPTH_STENCIL_ATTACHMENT is treated as an independent attachment point in WebGL 1;
// however, in WebGL 2, it is treated as an alias for DEPTH_ATTACHMENT + STENCIL_ATTACHMENT.
var size = 16;
Expand All @@ -127,24 +128,45 @@
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA8, size, size);
checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);

var depthBuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, size, size);
function createDepthBuffer() {
let buffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, buffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, size, size);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
return buffer;
}

function createStencilBuffer() {
let buffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, buffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, size, size);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
return buffer;
}

var stencilBuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, stencilBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, size, size);
function createDepthStencilBuffer() {
let buffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, buffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, size, size);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
return buffer;
}

var depthStencilBuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, size, size);
function orphan(renderbuffer) {
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.deleteRenderbuffer(renderbuffer);
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
}

wtu.glErrorShouldBe(gl, gl.NO_ERROR);

debug("");
debug("color + depth");
debug("color + depth" + suffix);
var depthBuffer = createDepthBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
if (testOrphanedRenderbuffers)
orphan(depthBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
Expand All @@ -153,9 +175,12 @@
checkBufferBits(gl.DEPTH_ATTACHMENT);

debug("");
debug("color + depth + stencil: depth != stencil");
debug("color + depth + stencil: depth != stencil" + suffix);
var stencilBuffer = createStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencilBuffer);
if (testOrphanedRenderbuffers)
orphan(stencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", stencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
Expand All @@ -170,9 +195,12 @@
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);

debug("");
debug("color + depth: DEPTH_STENCIL for DEPTH_ATTACHMENT");
debug("color + depth: DEPTH_STENCIL for DEPTH_ATTACHMENT" + suffix);
var depthStencilBuffer = createDepthStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
if (testOrphanedRenderbuffers)
orphan(depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
Expand All @@ -181,9 +209,16 @@
checkBufferBits(gl.DEPTH_ATTACHMENT);

debug("");
debug("color + depth + stencil: DEPTH_STENCIL for DEPTH_ATTACHMENT and STENCIL_ATTACHMENT");
debug("color + depth + stencil: DEPTH_STENCIL for DEPTH_ATTACHMENT and STENCIL_ATTACHMENT" + suffix);
if (testOrphanedRenderbuffers) {
depthStencilBuffer = createDepthStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
}
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
if (testOrphanedRenderbuffers)
orphan(depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
Expand All @@ -192,7 +227,7 @@
checkBufferBits(gl.DEPTH_STENCIL_ATTACHMENT);

debug("");
debug("color + depth_stencil");
debug("color + depth_stencil" + suffix);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH24_STENCIL8, size, size, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, null);
Expand All @@ -209,8 +244,12 @@
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

if (testOrphanedRenderbuffers)
depthStencilBuffer = createDepthStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
if (testOrphanedRenderbuffers)
orphan(depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
Expand All @@ -219,16 +258,24 @@
checkBufferBits(gl.DEPTH_STENCIL_ATTACHMENT);

debug("");
debug("DEPTH_STENCIL_ATTACHMENT overwrites DEPTH_ATTACHMENT/STENCIL_ATTACHMENT")
debug("DEPTH_STENCIL_ATTACHMENT overwrites DEPTH_ATTACHMENT/STENCIL_ATTACHMENT" + suffix);
if (testOrphanedRenderbuffers)
depthBuffer = createDepthBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
if (testOrphanedRenderbuffers)
orphan(depthBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);

if (testOrphanedRenderbuffers)
depthStencilBuffer = createDepthStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
if (testOrphanedRenderbuffers)
orphan(depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
Expand All @@ -244,9 +291,13 @@
checkBufferBits();

debug("");
debug("STENCIL_ATTACHMENT overwrites stencil set by DEPTH_STENCIL_ATTACHMENT")
debug("STENCIL_ATTACHMENT overwrites stencil set by DEPTH_STENCIL_ATTACHMENT" + suffix);
if (testOrphanedRenderbuffers)
depthStencilBuffer = createDepthStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
if (testOrphanedRenderbuffers)
orphan(depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
Expand All @@ -260,6 +311,28 @@
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
checkBufferBits(gl.DEPTH_ATTACHMENT);

debug("");
debug("DEPTH_ATTACHMENT overwrites depth set by DEPTH_STENCIL_ATTACHMENT" + suffix);
if (testOrphanedRenderbuffers)
depthStencilBuffer = createDepthStencilBuffer();
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilBuffer);
if (testOrphanedRenderbuffers)
orphan(depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

gl.framebufferRenderbuffer(
gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", depthStencilBuffer);
shouldEvaluateTo("gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", null);
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
checkBufferBits(gl.STENCIL_ATTACHMENT);
}

function testFramebufferIncompleteAttachment() {
Expand Down Expand Up @@ -469,7 +542,8 @@
shouldBeNonNull("gl = wtu.create3DContext(undefined, undefined, 2)");

testFramebufferWebGL1RequiredCombinations();
testDepthStencilAttachmentBehaviors();
testDepthStencilAttachmentBehaviors(false);
testDepthStencilAttachmentBehaviors(true);
testFramebufferIncompleteAttachment();
testFramebufferIncompleteMissingAttachment();
testFramebufferWithImagesOfDifferentSizes();
Expand Down

0 comments on commit c98b096

Please sign in to comment.