Commit 13e31bb0 by Geoff Lang Committed by Commit Bot

GL: Check framebuffer completeness before running blit shaders.

Cube map destination textures may not be complete until all faces have been initialized. BUG=693090 Change-Id: I19816c9def3b9663491397cded5d24ca808a3f78 Reviewed-on: https://chromium-review.googlesource.com/982393Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 7b7d2e6a
......@@ -514,26 +514,37 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source,
return gl::NoError();
}
gl::Error BlitGL::copySubTexture(const gl::Context *context,
TextureGL *source,
size_t sourceLevel,
GLenum sourceComponentType,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
GLenum destComponentType,
const gl::Extents &sourceSize,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset,
bool needsLumaWorkaround,
GLenum lumaFormat,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha)
gl::ErrorOrResult<bool> BlitGL::copySubTexture(const gl::Context *context,
TextureGL *source,
size_t sourceLevel,
GLenum sourceComponentType,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
GLenum destComponentType,
const gl::Extents &sourceSize,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset,
bool needsLumaWorkaround,
GLenum lumaFormat,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha)
{
ASSERT(source->getType() == gl::TextureType::_2D);
ANGLE_TRY(initializeResources());
// Make sure the destination texture can be rendered to before setting anything else up. Some
// cube maps may not be renderable until all faces have been filled.
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ToGLenum(destTarget),
dest->getTextureID(), static_cast<GLint>(destLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
return false;
}
BlitProgramType blitProgramType = getBlitProgramType(sourceComponentType, destComponentType);
BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(blitProgramType, &blitProgram));
......@@ -598,14 +609,10 @@ gl::Error BlitGL::copySubTexture(const gl::Context *context,
mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, unpackUnmultiplyAlpha);
}
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ToGLenum(destTarget),
dest->getTextureID(), static_cast<GLint>(destLevel));
mStateManager->bindVertexArray(mVAO, 0);
mFunctions->drawArrays(GL_TRIANGLES, 0, 3);
return gl::NoError();
return true;
}
gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context,
......@@ -686,19 +693,25 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context,
return gl::NoError();
}
gl::Error BlitGL::copyTexSubImage(TextureGL *source,
size_t sourceLevel,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset)
gl::ErrorOrResult<bool> BlitGL::copyTexSubImage(TextureGL *source,
size_t sourceLevel,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset)
{
ANGLE_TRY(initializeResources());
// Make sure the source texture can create a complete framebuffer before continuing.
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
source->getTextureID(), static_cast<GLint>(sourceLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
return false;
}
mStateManager->bindTexture(dest->getType(), dest->getTextureID());
......@@ -706,7 +719,7 @@ gl::Error BlitGL::copyTexSubImage(TextureGL *source,
destOffset.y, sourceArea.x, sourceArea.y, sourceArea.width,
sourceArea.height);
return gl::NoError();
return true;
}
gl::ErrorOrResult<bool> BlitGL::clearRenderableTexture(TextureGL *source,
......
......@@ -66,22 +66,22 @@ class BlitGL : angle::NonCopyable
const gl::Rectangle &destArea,
GLenum filter);
gl::Error copySubTexture(const gl::Context *context,
TextureGL *source,
size_t sourceLevel,
GLenum sourceComponentType,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
GLenum destComponentType,
const gl::Extents &sourceSize,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset,
bool needsLumaWorkaround,
GLenum lumaFormat,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha);
gl::ErrorOrResult<bool> copySubTexture(const gl::Context *context,
TextureGL *source,
size_t sourceLevel,
GLenum sourceComponentType,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
GLenum destComponentType,
const gl::Extents &sourceSize,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset,
bool needsLumaWorkaround,
GLenum lumaFormat,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha);
gl::Error copySubTextureCPUReadback(const gl::Context *context,
TextureGL *source,
......@@ -98,13 +98,13 @@ class BlitGL : angle::NonCopyable
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha);
gl::Error copyTexSubImage(TextureGL *source,
size_t sourceLevel,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset);
gl::ErrorOrResult<bool> copyTexSubImage(TextureGL *source,
size_t sourceLevel,
TextureGL *dest,
gl::TextureTarget destTarget,
size_t destLevel,
const gl::Rectangle &sourceArea,
const gl::Offset &destOffset);
gl::ErrorOrResult<bool> clearRenderableTexture(TextureGL *source,
GLenum sizedInternalFormat,
......
......@@ -771,8 +771,14 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context,
sourceFormatContainSupersetOfDestFormat && sourceComponentType == destComponentType &&
!destSRGB)
{
return mBlitter->copyTexSubImage(sourceGL, sourceLevel, this, target, level, sourceArea,
destOffset);
bool copySucceded = false;
ANGLE_TRY_RESULT(mBlitter->copyTexSubImage(sourceGL, sourceLevel, this, target, level,
sourceArea, destOffset),
copySucceded);
if (copySucceded)
{
return gl::NoError();
}
}
// Check if the destination is renderable and copy on the GPU
......@@ -780,11 +786,17 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context,
if (!destSRGB && nativegl::SupportsNativeRendering(mFunctions, getType(),
destLevelInfo.nativeInternalFormat))
{
return mBlitter->copySubTexture(context, sourceGL, sourceLevel, sourceComponentType, this,
target, level, destComponentType, sourceImageDesc.size,
sourceArea, destOffset, needsLumaWorkaround,
sourceLevelInfo.sourceFormat, unpackFlipY,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha);
bool copySucceded = false;
ANGLE_TRY_RESULT(mBlitter->copySubTexture(
context, sourceGL, sourceLevel, sourceComponentType, this, target,
level, destComponentType, sourceImageDesc.size, sourceArea, destOffset,
needsLumaWorkaround, sourceLevelInfo.sourceFormat, unpackFlipY,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha),
copySucceded);
if (copySucceded)
{
return gl::NoError();
}
}
// Fall back to CPU-readback
......
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