Commit 5a808b86 by Geoff Lang Committed by Commit Bot

GL: Allow BlitGL to copy from external textures.

BUG=967410 Change-Id: I503dda6f2493b56123a8bd369e2f1305971abb4e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1364110Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 44462cd6
...@@ -516,7 +516,8 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context, ...@@ -516,7 +516,8 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context,
bool unpackUnmultiplyAlpha, bool unpackUnmultiplyAlpha,
bool *copySucceededOut) bool *copySucceededOut)
{ {
ASSERT(source->getType() == gl::TextureType::_2D); ASSERT(source->getType() == gl::TextureType::_2D ||
source->getType() == gl::TextureType::External);
ANGLE_TRY(initializeResources()); ANGLE_TRY(initializeResources());
// Make sure the destination texture can be rendered to before setting anything else up. Some // Make sure the destination texture can be rendered to before setting anything else up. Some
...@@ -531,8 +532,9 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context, ...@@ -531,8 +532,9 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context,
return angle::Result::Continue; return angle::Result::Continue;
} }
BlitProgramType blitProgramType = getBlitProgramType(sourceComponentType, destComponentType); BlitProgramType blitProgramType =
BlitProgram *blitProgram = nullptr; getBlitProgramType(source->getType(), sourceComponentType, destComponentType);
BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(context, blitProgramType, &blitProgram)); ANGLE_TRY(getBlitProgram(context, blitProgramType, &blitProgram));
// Setup the source texture // Setup the source texture
...@@ -568,7 +570,7 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context, ...@@ -568,7 +570,7 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context,
scopedState.willUseTextureUnit(context, 0); scopedState.willUseTextureUnit(context, 0);
mStateManager->activeTexture(0); mStateManager->activeTexture(0);
mStateManager->bindTexture(gl::TextureType::_2D, source->getTextureID()); mStateManager->bindTexture(source->getType(), source->getTextureID());
Vector2 scale(sourceArea.width / static_cast<float>(sourceSize.width), Vector2 scale(sourceArea.width / static_cast<float>(sourceSize.width),
sourceArea.height / static_cast<float>(sourceSize.height)); sourceArea.height / static_cast<float>(sourceSize.height));
...@@ -703,8 +705,9 @@ angle::Result BlitGL::copyTexSubImage(TextureGL *source, ...@@ -703,8 +705,9 @@ angle::Result BlitGL::copyTexSubImage(TextureGL *source,
// Make sure the source texture can create a complete framebuffer before continuing. // Make sure the source texture can create a complete framebuffer before continuing.
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO); mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
source->getTextureID(), static_cast<GLint>(sourceLevel)); ToGLenum(source->getType()), source->getTextureID(),
static_cast<GLint>(sourceLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER); GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) if (status != GL_FRAMEBUFFER_COMPLETE)
{ {
...@@ -942,7 +945,8 @@ void BlitGL::setScratchTextureParameter(GLenum param, GLenum value) ...@@ -942,7 +945,8 @@ void BlitGL::setScratchTextureParameter(GLenum param, GLenum value)
} }
} }
BlitGL::BlitProgramType BlitGL::getBlitProgramType(GLenum sourceComponentType, BlitGL::BlitProgramType BlitGL::getBlitProgramType(gl::TextureType sourceTextureType,
GLenum sourceComponentType,
GLenum destComponentType) GLenum destComponentType)
{ {
if (sourceComponentType == GL_UNSIGNED_INT) if (sourceComponentType == GL_UNSIGNED_INT)
...@@ -956,12 +960,16 @@ BlitGL::BlitProgramType BlitGL::getBlitProgramType(GLenum sourceComponentType, ...@@ -956,12 +960,16 @@ BlitGL::BlitProgramType BlitGL::getBlitProgramType(GLenum sourceComponentType,
ASSERT(sourceComponentType != GL_INT); ASSERT(sourceComponentType != GL_INT);
if (destComponentType == GL_UNSIGNED_INT) if (destComponentType == GL_UNSIGNED_INT)
{ {
return BlitProgramType::FLOAT_TO_UINT; return sourceTextureType == gl::TextureType::External
? BlitProgramType::FLOAT_TO_UINT_EXTERNAL
: BlitProgramType::FLOAT_TO_UINT;
} }
else else
{ {
// Dest is a float type // Dest is a float type
return BlitProgramType::FLOAT_TO_FLOAT; return sourceTextureType == gl::TextureType::External
? BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL
: BlitProgramType::FLOAT_TO_FLOAT;
} }
} }
} }
...@@ -985,7 +993,8 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -985,7 +993,8 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
std::string fsInputVariableQualifier; std::string fsInputVariableQualifier;
std::string fsOutputVariableQualifier; std::string fsOutputVariableQualifier;
std::string sampleFunction; std::string sampleFunction;
if (type == BlitProgramType::FLOAT_TO_FLOAT) if (type == BlitProgramType::FLOAT_TO_FLOAT ||
type == BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL)
{ {
version = "100"; version = "100";
vsInputVariableQualifier = "attribute"; vsInputVariableQualifier = "attribute";
...@@ -1044,6 +1053,7 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1044,6 +1053,7 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
// Sampling texture uniform changes depending on source texture type. // Sampling texture uniform changes depending on source texture type.
std::string samplerType; std::string samplerType;
std::string samplerResultType; std::string samplerResultType;
std::string extensionRequirements;
switch (type) switch (type)
{ {
case BlitProgramType::FLOAT_TO_FLOAT: case BlitProgramType::FLOAT_TO_FLOAT:
...@@ -1052,6 +1062,13 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1052,6 +1062,13 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
samplerResultType = "vec4"; samplerResultType = "vec4";
break; break;
case BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL:
case BlitProgramType::FLOAT_TO_UINT_EXTERNAL:
samplerType = "samplerExternalOES";
samplerResultType = "vec4";
extensionRequirements = "#extension GL_OES_EGL_image_external : require";
break;
case BlitProgramType::UINT_TO_UINT: case BlitProgramType::UINT_TO_UINT:
samplerType = "usampler2D"; samplerType = "usampler2D";
samplerResultType = "uvec4"; samplerResultType = "uvec4";
...@@ -1069,12 +1086,15 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1069,12 +1086,15 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
switch (type) switch (type)
{ {
case BlitProgramType::FLOAT_TO_FLOAT: case BlitProgramType::FLOAT_TO_FLOAT:
case BlitProgramType::FLOAT_TO_FLOAT_EXTERNAL:
ASSERT(version == "100");
outputType = ""; outputType = "";
outputVariableName = "gl_FragColor"; outputVariableName = "gl_FragColor";
outputMultiplier = "1.0"; outputMultiplier = "1.0";
break; break;
case BlitProgramType::FLOAT_TO_UINT: case BlitProgramType::FLOAT_TO_UINT:
case BlitProgramType::FLOAT_TO_UINT_EXTERNAL:
case BlitProgramType::UINT_TO_UINT: case BlitProgramType::UINT_TO_UINT:
outputType = "uvec4"; outputType = "uvec4";
outputVariableName = "outputUint"; outputVariableName = "outputUint";
...@@ -1089,6 +1109,7 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context, ...@@ -1089,6 +1109,7 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
// Compile the fragment shader // Compile the fragment shader
std::ostringstream fsSourceStream; std::ostringstream fsSourceStream;
fsSourceStream << "#version " << version << "\n"; fsSourceStream << "#version " << version << "\n";
fsSourceStream << extensionRequirements << "\n";
fsSourceStream << "precision highp float;\n"; fsSourceStream << "precision highp float;\n";
fsSourceStream << "uniform " << samplerType << " u_source_texture;\n"; fsSourceStream << "uniform " << samplerType << " u_source_texture;\n";
......
...@@ -142,11 +142,15 @@ class BlitGL : angle::NonCopyable ...@@ -142,11 +142,15 @@ class BlitGL : angle::NonCopyable
enum class BlitProgramType enum class BlitProgramType
{ {
FLOAT_TO_FLOAT, FLOAT_TO_FLOAT,
FLOAT_TO_FLOAT_EXTERNAL,
FLOAT_TO_UINT, FLOAT_TO_UINT,
FLOAT_TO_UINT_EXTERNAL,
UINT_TO_UINT, UINT_TO_UINT,
}; };
static BlitProgramType getBlitProgramType(GLenum sourceComponentType, GLenum destComponentType); static BlitProgramType getBlitProgramType(gl::TextureType sourceTextureType,
GLenum sourceComponentType,
GLenum destComponentType);
angle::Result getBlitProgram(const gl::Context *context, angle::Result getBlitProgram(const gl::Context *context,
BlitProgramType type, BlitProgramType type,
BlitProgram **program); BlitProgram **program);
......
...@@ -785,7 +785,8 @@ angle::Result TextureGL::copySubTextureHelper(const gl::Context *context, ...@@ -785,7 +785,8 @@ angle::Result TextureGL::copySubTextureHelper(const gl::Context *context,
sourceGL->mState.getImageDesc(NonCubeTextureTypeToTarget(source->getType()), sourceLevel); sourceGL->mState.getImageDesc(NonCubeTextureTypeToTarget(source->getType()), sourceLevel);
// Check is this is a simple copySubTexture that can be done with a copyTexSubImage // Check is this is a simple copySubTexture that can be done with a copyTexSubImage
ASSERT(sourceGL->getType() == gl::TextureType::_2D); ASSERT(sourceGL->getType() == gl::TextureType::_2D ||
source->getType() == gl::TextureType::External);
const LevelInfoGL &sourceLevelInfo = const LevelInfoGL &sourceLevelInfo =
sourceGL->getLevelInfo(NonCubeTextureTypeToTarget(source->getType()), sourceLevel); sourceGL->getLevelInfo(NonCubeTextureTypeToTarget(source->getType()), sourceLevel);
bool needsLumaWorkaround = sourceLevelInfo.lumaWorkaround.enabled; bool needsLumaWorkaround = sourceLevelInfo.lumaWorkaround.enabled;
...@@ -800,7 +801,7 @@ angle::Result TextureGL::copySubTextureHelper(const gl::Context *context, ...@@ -800,7 +801,7 @@ angle::Result TextureGL::copySubTextureHelper(const gl::Context *context,
bool destSRGB = destFormat.colorEncoding == GL_SRGB; bool destSRGB = destFormat.colorEncoding == GL_SRGB;
if (!unpackFlipY && unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !needsLumaWorkaround && if (!unpackFlipY && unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !needsLumaWorkaround &&
sourceFormatContainSupersetOfDestFormat && sourceComponentType == destComponentType && sourceFormatContainSupersetOfDestFormat && sourceComponentType == destComponentType &&
!destSRGB) !destSRGB && sourceGL->getType() == gl::TextureType::_2D)
{ {
bool copySucceeded = false; bool copySucceeded = false;
ANGLE_TRY(blitter->copyTexSubImage(sourceGL, sourceLevel, this, target, level, sourceArea, ANGLE_TRY(blitter->copyTexSubImage(sourceGL, sourceLevel, this, target, level, sourceArea,
......
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