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, ...@@ -1142,56 +1142,60 @@ void Framebuffer::setAttachmentImpl(GLenum type,
const ImageIndex &textureIndex, const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource) FramebufferAttachmentObject *resource)
{ {
if (binding == GL_DEPTH_STENCIL || binding == GL_DEPTH_STENCIL_ATTACHMENT) switch (binding)
{ {
// ensure this is a legitimate depth+stencil format case GL_DEPTH_STENCIL:
FramebufferAttachmentObject *attachmentObj = resource; case GL_DEPTH_STENCIL_ATTACHMENT:
if (resource)
{ {
FramebufferAttachment::Target target(binding, textureIndex); // ensure this is a legitimate depth+stencil format
const Format &format = resource->getAttachmentFormat(target); FramebufferAttachmentObject *attachmentObj = resource;
if (format.info->depthBits == 0 || format.info->stencilBits == 0) if (resource)
{ {
// Attaching nullptr detaches the current attachment. FramebufferAttachment::Target target(binding, textureIndex);
attachmentObj = nullptr; 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); updateAttachment(&mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT,
mState.mStencilAttachment.attach(type, binding, textureIndex, attachmentObj); &mDirtyDepthAttachmentBinding, type, binding, textureIndex,
mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT); attachmentObj);
mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); updateAttachment(&mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT,
BindResourceChannel(&mDirtyDepthAttachmentBinding, resource); &mDirtyStencilAttachmentBinding, type, binding, textureIndex,
BindResourceChannel(&mDirtyStencilAttachmentBinding, resource); attachmentObj);
return; return;
} }
switch (binding)
{
case GL_DEPTH: case GL_DEPTH:
case GL_DEPTH_ATTACHMENT: case GL_DEPTH_ATTACHMENT:
mState.mDepthAttachment.attach(type, binding, textureIndex, resource); updateAttachment(&mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT,
mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT); &mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource);
BindResourceChannel(&mDirtyDepthAttachmentBinding, resource);
break; break;
case GL_STENCIL: case GL_STENCIL:
case GL_STENCIL_ATTACHMENT: case GL_STENCIL_ATTACHMENT:
mState.mStencilAttachment.attach(type, binding, textureIndex, resource); updateAttachment(&mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT,
mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); &mDirtyStencilAttachmentBinding, type, binding, textureIndex,
BindResourceChannel(&mDirtyStencilAttachmentBinding, resource); resource);
break; break;
case GL_BACK: case GL_BACK:
mState.mColorAttachments[0].attach(type, binding, textureIndex, resource); mState.mColorAttachments[0].attach(type, binding, textureIndex, resource);
mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0); mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0);
// No need for a resource binding for the default FBO, it's always complete. // No need for a resource binding for the default FBO, it's always complete.
break; break;
default: default:
{ {
size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; size_t colorIndex = binding - GL_COLOR_ATTACHMENT0;
ASSERT(colorIndex < mState.mColorAttachments.size()); ASSERT(colorIndex < mState.mColorAttachments.size());
mState.mColorAttachments[colorIndex].attach(type, binding, textureIndex, resource); size_t dirtyBit = DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex;
mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); updateAttachment(&mState.mColorAttachments[colorIndex], dirtyBit,
BindResourceChannel(&mDirtyColorAttachmentBindings[colorIndex], resource); &mDirtyColorAttachmentBindings[colorIndex], type, binding,
textureIndex, resource);
bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE); bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE);
mState.mEnabledDrawBuffers.set(colorIndex, enabled); mState.mEnabledDrawBuffers.set(colorIndex, enabled);
...@@ -1200,6 +1204,19 @@ void Framebuffer::setAttachmentImpl(GLenum type, ...@@ -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) void Framebuffer::resetAttachment(const Context *context, GLenum binding)
{ {
setAttachment(context, GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr); setAttachment(context, GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr);
......
...@@ -285,6 +285,13 @@ class Framebuffer final : public LabeledObject, public OnAttachmentDirtyReceiver ...@@ -285,6 +285,13 @@ class Framebuffer final : public LabeledObject, public OnAttachmentDirtyReceiver
GLenum binding, GLenum binding,
const ImageIndex &textureIndex, const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource); FramebufferAttachmentObject *resource);
void updateAttachment(FramebufferAttachment *attachment,
size_t dirtyBit,
OnAttachmentDirtyBinding *onDirtyBinding,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
FramebufferState mState; FramebufferState mState;
rx::FramebufferImpl *mImpl; 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