Commit b8126691 by Jamie Madill Committed by Commit Bot

Framebuffer: Add an update attachment helper function.

This will allow us to set that certain attachments need to be initialized in a single place. BUG=angleproject:1635 Change-Id: I98c10206ef27670847969c726a8620c4d26400d6 Reviewed-on: https://chromium-review.googlesource.com/469150 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent b2931601
......@@ -1142,56 +1142,60 @@ void Framebuffer::setAttachmentImpl(GLenum type,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource)
{
if (binding == GL_DEPTH_STENCIL || binding == GL_DEPTH_STENCIL_ATTACHMENT)
switch (binding)
{
// ensure this is a legitimate depth+stencil format
FramebufferAttachmentObject *attachmentObj = resource;
if (resource)
case GL_DEPTH_STENCIL:
case GL_DEPTH_STENCIL_ATTACHMENT:
{
FramebufferAttachment::Target target(binding, textureIndex);
const Format &format = resource->getAttachmentFormat(target);
if (format.info->depthBits == 0 || format.info->stencilBits == 0)
// ensure this is a legitimate depth+stencil format
FramebufferAttachmentObject *attachmentObj = resource;
if (resource)
{
// Attaching nullptr detaches the current attachment.
attachmentObj = nullptr;
FramebufferAttachment::Target target(binding, textureIndex);
const Format &format = resource->getAttachmentFormat(target);
if (format.info->depthBits == 0 || format.info->stencilBits == 0)
{
// Attaching nullptr detaches the current attachment.
attachmentObj = nullptr;
}
}
}
mState.mDepthAttachment.attach(type, binding, textureIndex, attachmentObj);
mState.mStencilAttachment.attach(type, binding, textureIndex, attachmentObj);
mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT);
mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT);
BindResourceChannel(&mDirtyDepthAttachmentBinding, resource);
BindResourceChannel(&mDirtyStencilAttachmentBinding, resource);
return;
}
updateAttachment(&mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT,
&mDirtyDepthAttachmentBinding, type, binding, textureIndex,
attachmentObj);
updateAttachment(&mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT,
&mDirtyStencilAttachmentBinding, type, binding, textureIndex,
attachmentObj);
return;
}
switch (binding)
{
case GL_DEPTH:
case GL_DEPTH_ATTACHMENT:
mState.mDepthAttachment.attach(type, binding, textureIndex, resource);
mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT);
BindResourceChannel(&mDirtyDepthAttachmentBinding, resource);
updateAttachment(&mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT,
&mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource);
break;
case GL_STENCIL:
case GL_STENCIL_ATTACHMENT:
mState.mStencilAttachment.attach(type, binding, textureIndex, resource);
mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT);
BindResourceChannel(&mDirtyStencilAttachmentBinding, resource);
updateAttachment(&mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT,
&mDirtyStencilAttachmentBinding, type, binding, textureIndex,
resource);
break;
case GL_BACK:
mState.mColorAttachments[0].attach(type, binding, textureIndex, resource);
mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0);
// No need for a resource binding for the default FBO, it's always complete.
break;
default:
{
size_t colorIndex = binding - GL_COLOR_ATTACHMENT0;
ASSERT(colorIndex < mState.mColorAttachments.size());
mState.mColorAttachments[colorIndex].attach(type, binding, textureIndex, resource);
mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex);
BindResourceChannel(&mDirtyColorAttachmentBindings[colorIndex], resource);
size_t dirtyBit = DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex;
updateAttachment(&mState.mColorAttachments[colorIndex], dirtyBit,
&mDirtyColorAttachmentBindings[colorIndex], type, binding,
textureIndex, resource);
bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE);
mState.mEnabledDrawBuffers.set(colorIndex, enabled);
......@@ -1200,6 +1204,19 @@ void Framebuffer::setAttachmentImpl(GLenum type,
}
}
void Framebuffer::updateAttachment(FramebufferAttachment *attachment,
size_t dirtyBit,
OnAttachmentDirtyBinding *onDirtyBinding,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource)
{
attachment->attach(type, binding, textureIndex, resource);
mDirtyBits.set(dirtyBit);
BindResourceChannel(onDirtyBinding, resource);
}
void Framebuffer::resetAttachment(const Context *context, GLenum binding)
{
setAttachment(context, GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr);
......
......@@ -285,6 +285,13 @@ class Framebuffer final : public LabeledObject, public OnAttachmentDirtyReceiver
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
void updateAttachment(FramebufferAttachment *attachment,
size_t dirtyBit,
OnAttachmentDirtyBinding *onDirtyBinding,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
FramebufferState mState;
rx::FramebufferImpl *mImpl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment