Some improvements for BlitFramebuffer.
This change can
1. Skip color blitting when draw buffers are disabled.
2. Skip depth/stencil blitting when depth/stencil buffer has no image.
3. Return early if possible.
4. Move the logic above from D3D backend to common part.
BUG=angleproject:1677
Change-Id: I1662d214b72fb8caa4a95c86d9b8a67984b6071a
Reviewed-on: https://chromium-review.googlesource.com/423135
Commit-Queue: Yunchao He <yunchao.he@intel.com>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Framebuffer.cpp b/src/libANGLE/Framebuffer.cpp
index 72886d6..6efe537 100644
--- a/src/libANGLE/Framebuffer.cpp
+++ b/src/libANGLE/Framebuffer.cpp
@@ -840,7 +840,31 @@
GLbitfield mask,
GLenum filter)
{
- return mImpl->blit(context, sourceArea, destArea, mask, filter);
+ GLbitfield blitMask = mask;
+
+ // Note that blitting is called against draw framebuffer.
+ // See the code in gl::Context::blitFramebuffer.
+ if ((mask & GL_COLOR_BUFFER_BIT) && !hasEnabledDrawBuffer())
+ {
+ blitMask &= ~GL_COLOR_BUFFER_BIT;
+ }
+
+ if ((mask & GL_STENCIL_BUFFER_BIT) && mState.getStencilAttachment() == nullptr)
+ {
+ blitMask &= ~GL_STENCIL_BUFFER_BIT;
+ }
+
+ if ((mask & GL_DEPTH_BUFFER_BIT) && mState.getDepthAttachment() == nullptr)
+ {
+ blitMask &= ~GL_DEPTH_BUFFER_BIT;
+ }
+
+ if (!blitMask)
+ {
+ return NoError();
+ }
+
+ return mImpl->blit(context, sourceArea, destArea, blitMask, filter);
}
int Framebuffer::getSamples(const ContextState &state)
diff --git a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
index f6eef6f..e86f913 100644
--- a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
+++ b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
@@ -263,38 +263,10 @@
{
const auto &glState = context->getGLState();
const gl::Framebuffer *sourceFramebuffer = glState.getReadFramebuffer();
- bool blitRenderTarget = false;
- if ((mask & GL_COLOR_BUFFER_BIT) && sourceFramebuffer->getReadColorbuffer() != nullptr &&
- mState.getFirstColorAttachment() != nullptr)
- {
- blitRenderTarget = true;
- }
-
- bool blitStencil = false;
- if ((mask & GL_STENCIL_BUFFER_BIT) && sourceFramebuffer->getStencilbuffer() != nullptr &&
- mState.getStencilAttachment() != nullptr)
- {
- blitStencil = true;
- }
-
- bool blitDepth = false;
- if ((mask & GL_DEPTH_BUFFER_BIT) && sourceFramebuffer->getDepthbuffer() != nullptr &&
- mState.getDepthAttachment() != nullptr)
- {
- blitDepth = true;
- }
-
- if (blitRenderTarget || blitDepth || blitStencil)
- {
- const gl::Rectangle *scissor =
- glState.isScissorTestEnabled() ? &glState.getScissor() : nullptr;
- gl::Error error = blitImpl(sourceArea, destArea, scissor, blitRenderTarget, blitDepth,
- blitStencil, filter, sourceFramebuffer);
- if (error.isError())
- {
- return error;
- }
- }
+ const gl::Rectangle *scissor = glState.isScissorTestEnabled() ? &glState.getScissor() : nullptr;
+ ANGLE_TRY(blitImpl(sourceArea, destArea, scissor, (mask & GL_COLOR_BUFFER_BIT) != 0,
+ (mask & GL_DEPTH_BUFFER_BIT) != 0, (mask & GL_STENCIL_BUFFER_BIT) != 0,
+ filter, sourceFramebuffer));
return gl::Error(GL_NO_ERROR);
}