Commit 4e57520a by Geoff Lang Committed by Commit Bot

GL: Update BlitGL to use ANGLE_GL_TRY.

BUG=angleproject:3020 Change-Id: I587e638ca9dea2cb84aaad68aa8d1ce32fc62053 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1769062Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent ac7c876b
......@@ -35,29 +35,29 @@ namespace rx
namespace
{
angle::Result CheckCompileStatus(ContextGL *contextGL,
angle::Result CheckCompileStatus(const gl::Context *context,
const rx::FunctionsGL *functions,
GLuint shader)
{
GLint compileStatus = GL_FALSE;
functions->getShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
ANGLE_GL_TRY(context, functions->getShaderiv(shader, GL_COMPILE_STATUS, &compileStatus));
ASSERT(compileStatus == GL_TRUE);
ANGLE_CHECK(contextGL, compileStatus == GL_TRUE, "Failed to compile internal blit shader.",
GL_OUT_OF_MEMORY);
ANGLE_CHECK(GetImplAs<ContextGL>(context), compileStatus == GL_TRUE,
"Failed to compile internal blit shader.", GL_OUT_OF_MEMORY);
return angle::Result::Continue;
}
angle::Result CheckLinkStatus(ContextGL *contextGL,
angle::Result CheckLinkStatus(const gl::Context *context,
const rx::FunctionsGL *functions,
GLuint program)
{
GLint linkStatus = GL_FALSE;
functions->getProgramiv(program, GL_LINK_STATUS, &linkStatus);
ANGLE_GL_TRY(context, functions->getProgramiv(program, GL_LINK_STATUS, &linkStatus));
ASSERT(linkStatus == GL_TRUE);
ANGLE_CHECK(contextGL, linkStatus == GL_TRUE, "Failed to link internal blit program.",
GL_OUT_OF_MEMORY);
ANGLE_CHECK(GetImplAs<ContextGL>(context), linkStatus == GL_TRUE,
"Failed to link internal blit program.", GL_OUT_OF_MEMORY);
return angle::Result::Continue;
}
......@@ -199,14 +199,17 @@ angle::Result PrepareForClear(StateManagerGL *stateManager,
return angle::Result::Continue;
}
void UnbindAttachments(const FunctionsGL *functions,
angle::Result UnbindAttachments(const gl::Context *context,
const FunctionsGL *functions,
GLenum framebufferTarget,
const ClearBindTargetVector &bindTargets)
{
for (GLenum bindTarget : bindTargets)
{
functions->framebufferRenderbuffer(framebufferTarget, bindTarget, GL_RENDERBUFFER, 0);
ANGLE_GL_TRY(context, functions->framebufferRenderbuffer(framebufferTarget, bindTarget,
GL_RENDERBUFFER, 0));
}
return angle::Result::Continue;
}
} // anonymous namespace
......@@ -282,8 +285,10 @@ angle::Result BlitGL::copyImageToLUMAWorkaroundTexture(const gl::Context *contex
mStateManager->setPixelUnpackState(unpack);
mStateManager->setPixelUnpackBuffer(
context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack));
ANGLE_GL_TRY_ALWAYS_CHECK(
context,
mFunctions->texImage2D(ToGLenum(target), static_cast<GLint>(level), internalFormat,
sourceArea.width, sourceArea.height, 0, format, readType, nullptr);
sourceArea.width, sourceArea.height, 0, format, readType, nullptr));
return copySubImageToLUMAWorkaroundTexture(context, texture, textureType, target, lumaFormat,
level, gl::Offset(0, 0, 0), sourceArea, source);
......@@ -299,7 +304,7 @@ angle::Result BlitGL::copySubImageToLUMAWorkaroundTexture(const gl::Context *con
const gl::Rectangle &sourceArea,
gl::Framebuffer *source)
{
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(context, BlitProgramType::FLOAT_TO_FLOAT, &blitProgram));
......@@ -318,8 +323,10 @@ angle::Result BlitGL::copySubImageToLUMAWorkaroundTexture(const gl::Context *con
nativegl::GetCopyTexImageImageFormat(mFunctions, mFeatures, readFormat, readType);
mStateManager->bindTexture(gl::TextureType::_2D, mScratchTextures[0]);
mFunctions->copyTexImage2D(GL_TEXTURE_2D, 0, copyTexImageFormat.internalFormat, sourceArea.x,
sourceArea.y, sourceArea.width, sourceArea.height, 0);
ANGLE_GL_TRY_ALWAYS_CHECK(
context, mFunctions->copyTexImage2D(GL_TEXTURE_2D, 0, copyTexImageFormat.internalFormat,
sourceArea.x, sourceArea.y, sourceArea.width,
sourceArea.height, 0));
// Set the swizzle of the scratch texture so that the channels sample into the correct emulated
// LUMA channels.
......@@ -329,58 +336,63 @@ angle::Result BlitGL::copySubImageToLUMAWorkaroundTexture(const gl::Context *con
GL_ZERO,
GL_ZERO,
};
mFunctions->texParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
ANGLE_GL_TRY(context,
mFunctions->texParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle));
// Make a temporary framebuffer using the second scratch texture to render the swizzled result
// to.
mStateManager->bindTexture(gl::TextureType::_2D, mScratchTextures[1]);
mFunctions->texImage2D(
GL_TEXTURE_2D, 0, copyTexImageFormat.internalFormat, sourceArea.width, sourceArea.height, 0,
gl::GetUnsizedFormat(copyTexImageFormat.internalFormat), readType, nullptr);
ANGLE_GL_TRY_ALWAYS_CHECK(
context, mFunctions->texImage2D(GL_TEXTURE_2D, 0, copyTexImageFormat.internalFormat,
sourceArea.width, sourceArea.height, 0,
gl::GetUnsizedFormat(copyTexImageFormat.internalFormat),
readType, nullptr));
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
mScratchTextures[1], 0);
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, mScratchTextures[1], 0));
// Render to the destination texture, sampling from the scratch texture
ScopedGLState scopedState;
ANGLE_TRY(scopedState.enter(context, gl::Rectangle(0, 0, sourceArea.width, sourceArea.height)));
scopedState.willUseTextureUnit(context, 0);
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ANGLE_TRY(setScratchTextureParameter(context, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
ANGLE_TRY(setScratchTextureParameter(context, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
mStateManager->activeTexture(0);
mStateManager->bindTexture(gl::TextureType::_2D, mScratchTextures[0]);
mStateManager->useProgram(blitProgram->program);
mFunctions->uniform1i(blitProgram->sourceTextureLocation, 0);
mFunctions->uniform2f(blitProgram->scaleLocation, 1.0, 1.0);
mFunctions->uniform2f(blitProgram->offsetLocation, 0.0, 0.0);
mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, 0);
mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, 0);
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->sourceTextureLocation, 0));
ANGLE_GL_TRY(context, mFunctions->uniform2f(blitProgram->scaleLocation, 1.0, 1.0));
ANGLE_GL_TRY(context, mFunctions->uniform2f(blitProgram->offsetLocation, 0.0, 0.0));
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, 0));
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, 0));
mStateManager->bindVertexArray(mVAO, 0);
mFunctions->drawArrays(GL_TRIANGLES, 0, 3);
ANGLE_GL_TRY(context, mFunctions->drawArrays(GL_TRIANGLES, 0, 3));
// Copy the swizzled texture to the destination texture
mStateManager->bindTexture(textureType, texture);
if (nativegl::UseTexImage3D(textureType))
{
mFunctions->copyTexSubImage3D(ToGLenum(target), static_cast<GLint>(level), destOffset.x,
destOffset.y, destOffset.z, 0, 0, sourceArea.width,
sourceArea.height);
ANGLE_GL_TRY(context,
mFunctions->copyTexSubImage3D(ToGLenum(target), static_cast<GLint>(level),
destOffset.x, destOffset.y, destOffset.z, 0, 0,
sourceArea.width, sourceArea.height));
}
else
{
ASSERT(nativegl::UseTexImage2D(textureType));
mFunctions->copyTexSubImage2D(ToGLenum(target), static_cast<GLint>(level), destOffset.x,
destOffset.y, 0, 0, sourceArea.width, sourceArea.height);
ANGLE_GL_TRY(context, mFunctions->copyTexSubImage2D(
ToGLenum(target), static_cast<GLint>(level), destOffset.x,
destOffset.y, 0, 0, sourceArea.width, sourceArea.height));
}
// Finally orphan the scratch textures so they can be GCed by the driver.
orphanScratchTextures();
ANGLE_TRY(orphanScratchTextures(context));
ANGLE_TRY(scopedState.exit(context));
return angle::Result::Continue;
......@@ -393,7 +405,7 @@ angle::Result BlitGL::blitColorBufferWithShader(const gl::Context *context,
const gl::Rectangle &destAreaIn,
GLenum filter)
{
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
BlitProgram *blitProgram = nullptr;
ANGLE_TRY(getBlitProgram(context, BlitProgramType::FLOAT_TO_FLOAT, &blitProgram));
......@@ -437,17 +449,19 @@ angle::Result BlitGL::blitColorBufferWithShader(const gl::Context *context,
mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceGL->getFramebufferID());
mStateManager->bindTexture(gl::TextureType::_2D, textureId);
ANGLE_GL_TRY_ALWAYS_CHECK(
context,
mFunctions->copyTexImage2D(GL_TEXTURE_2D, 0, format, inBoundsSource.x, inBoundsSource.y,
inBoundsSource.width, inBoundsSource.height, 0);
inBoundsSource.width, inBoundsSource.height, 0));
// Translate sourceArea to be relative to the copied image.
sourceArea.x -= inBoundsSource.x;
sourceArea.y -= inBoundsSource.y;
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
setScratchTextureParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
ANGLE_TRY(setScratchTextureParameter(context, GL_TEXTURE_MIN_FILTER, filter));
ANGLE_TRY(setScratchTextureParameter(context, GL_TEXTURE_MAG_FILTER, filter));
ANGLE_TRY(setScratchTextureParameter(context, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
ANGLE_TRY(setScratchTextureParameter(context, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
}
// Transform the source area to the texture coordinate space (where 0.0 and 1.0 correspond to
......@@ -482,17 +496,19 @@ angle::Result BlitGL::blitColorBufferWithShader(const gl::Context *context,
mStateManager->bindTexture(gl::TextureType::_2D, textureId);
mStateManager->useProgram(blitProgram->program);
mFunctions->uniform1i(blitProgram->sourceTextureLocation, 0);
mFunctions->uniform2f(blitProgram->scaleLocation, texCoordScale.x(), texCoordScale.y());
mFunctions->uniform2f(blitProgram->offsetLocation, texCoordOffset.x(), texCoordOffset.y());
mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, 0);
mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, 0);
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->sourceTextureLocation, 0));
ANGLE_GL_TRY(context, mFunctions->uniform2f(blitProgram->scaleLocation, texCoordScale.x(),
texCoordScale.y()));
ANGLE_GL_TRY(context, mFunctions->uniform2f(blitProgram->offsetLocation, texCoordOffset.x(),
texCoordOffset.y()));
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, 0));
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, 0));
const FramebufferGL *destGL = GetImplAs<FramebufferGL>(dest);
mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, destGL->getFramebufferID());
mStateManager->bindVertexArray(mVAO, 0);
mFunctions->drawArrays(GL_TRIANGLES, 0, 3);
ANGLE_GL_TRY(context, mFunctions->drawArrays(GL_TRIANGLES, 0, 3));
ANGLE_TRY(scopedState.exit(context));
return angle::Result::Continue;
......@@ -519,14 +535,15 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context,
ASSERT(source->getType() == gl::TextureType::_2D ||
source->getType() == gl::TextureType::External ||
source->getType() == gl::TextureType::Rectangle);
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
// 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),
destID, static_cast<GLint>(destLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
ToGLenum(destTarget), destID,
static_cast<GLint>(destLevel)));
GLenum status = ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
if (status != GL_FRAMEBUFFER_COMPLETE)
{
*copySucceededOut = false;
......@@ -589,22 +606,25 @@ angle::Result BlitGL::copySubTexture(const gl::Context *context,
}
mStateManager->useProgram(blitProgram->program);
mFunctions->uniform1i(blitProgram->sourceTextureLocation, 0);
mFunctions->uniform2f(blitProgram->scaleLocation, scale.x(), scale.y());
mFunctions->uniform2f(blitProgram->offsetLocation, offset.x(), offset.y());
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->sourceTextureLocation, 0));
ANGLE_GL_TRY(context, mFunctions->uniform2f(blitProgram->scaleLocation, scale.x(), scale.y()));
ANGLE_GL_TRY(context,
mFunctions->uniform2f(blitProgram->offsetLocation, offset.x(), offset.y()));
if (unpackPremultiplyAlpha == unpackUnmultiplyAlpha)
{
mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, 0);
mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, 0);
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, 0));
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, 0));
}
else
{
mFunctions->uniform1i(blitProgram->multiplyAlphaLocation, unpackPremultiplyAlpha);
mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation, unpackUnmultiplyAlpha);
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->multiplyAlphaLocation,
unpackPremultiplyAlpha));
ANGLE_GL_TRY(context, mFunctions->uniform1i(blitProgram->unMultiplyAlphaLocation,
unpackUnmultiplyAlpha));
}
mStateManager->bindVertexArray(mVAO, 0);
mFunctions->drawArrays(GL_TRIANGLES, 0, 3);
ANGLE_GL_TRY(context, mFunctions->drawArrays(GL_TRIANGLES, 0, 3));
*copySucceededOut = true;
ANGLE_TRY(scopedState.exit(context));
......@@ -629,7 +649,7 @@ angle::Result BlitGL::copySubTextureCPUReadback(const gl::Context *context,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha)
{
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
ContextGL *contextGL = GetImplAs<ContextGL>(context);
......@@ -643,10 +663,10 @@ angle::Result BlitGL::copySubTextureCPUReadback(const gl::Context *context,
gl::Rectangle readPixelsArea = sourceArea;
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
ToGLenum(source->getType()), source->getTextureID(),
static_cast<GLint>(sourceLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ToGLenum(source->getType()),
source->getTextureID(), static_cast<GLint>(sourceLevel)));
GLenum status = ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
if (status != GL_FRAMEBUFFER_COMPLETE)
{
// The source texture cannot be read with glReadPixels. Copy it into another RGBA texture
......@@ -657,9 +677,11 @@ angle::Result BlitGL::copySubTextureCPUReadback(const gl::Context *context,
gl::TextureType scratchTextureType = gl::TextureType::_2D;
mStateManager->bindTexture(scratchTextureType, mScratchTextures[0]);
ANGLE_GL_TRY_ALWAYS_CHECK(
context,
mFunctions->texImage2D(ToGLenum(scratchTextureType), 0, texImageFormat.internalFormat,
sourceArea.width, sourceArea.height, 0, texImageFormat.format,
texImageFormat.type, nullptr);
texImageFormat.type, nullptr));
bool copySucceeded = false;
ANGLE_TRY(copySubTexture(
......@@ -675,15 +697,16 @@ angle::Result BlitGL::copySubTextureCPUReadback(const gl::Context *context,
// Bind the scratch texture as the readback texture
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
ToGLenum(scratchTextureType), mScratchTextures[0], 0);
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
ToGLenum(scratchTextureType),
mScratchTextures[0], 0));
// The scratch texture sized to sourceArea so adjust the readpixels area
readPixelsArea.x = 0;
readPixelsArea.y = 0;
// Recheck the status
status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
status = ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
}
ASSERT(status == GL_FRAMEBUFFER_COMPLETE);
......@@ -718,8 +741,9 @@ angle::Result BlitGL::copySubTextureCPUReadback(const gl::Context *context,
unpack.alignment = 1;
mStateManager->setPixelUnpackState(unpack);
mStateManager->setPixelUnpackBuffer(nullptr);
mFunctions->readPixels(readPixelsArea.x, readPixelsArea.y, readPixelsArea.width,
readPixelsArea.height, readPixelsFormat, GL_UNSIGNED_BYTE, sourceMemory);
ANGLE_GL_TRY(context, mFunctions->readPixels(readPixelsArea.x, readPixelsArea.y,
readPixelsArea.width, readPixelsArea.height,
readPixelsFormat, GL_UNSIGNED_BYTE, sourceMemory));
angle::FormatID destFormatID =
angle::Format::InternalFormatToID(destInternalFormatInfo.sizedInternalFormat);
......@@ -740,14 +764,16 @@ angle::Result BlitGL::copySubTextureCPUReadback(const gl::Context *context,
nativegl::GetTexSubImageFormat(mFunctions, mFeatures, destFormat, destType);
mStateManager->bindTexture(dest->getType(), dest->getTextureID());
mFunctions->texSubImage2D(ToGLenum(destTarget), static_cast<GLint>(destLevel), destOffset.x,
ANGLE_GL_TRY(context, mFunctions->texSubImage2D(
ToGLenum(destTarget), static_cast<GLint>(destLevel), destOffset.x,
destOffset.y, readPixelsArea.width, readPixelsArea.height,
texSubImageFormat.format, texSubImageFormat.type, destMemory);
texSubImageFormat.format, texSubImageFormat.type, destMemory));
return angle::Result::Continue;
}
angle::Result BlitGL::copyTexSubImage(TextureGL *source,
angle::Result BlitGL::copyTexSubImage(const gl::Context *context,
TextureGL *source,
size_t sourceLevel,
TextureGL *dest,
gl::TextureTarget destTarget,
......@@ -756,14 +782,14 @@ angle::Result BlitGL::copyTexSubImage(TextureGL *source,
const gl::Offset &destOffset,
bool *copySucceededOut)
{
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
// Make sure the source texture can create a complete framebuffer before continuing.
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
ToGLenum(source->getType()), source->getTextureID(),
static_cast<GLint>(sourceLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ToGLenum(source->getType()),
source->getTextureID(), static_cast<GLint>(sourceLevel)));
GLenum status = ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
if (status != GL_FRAMEBUFFER_COMPLETE)
{
*copySucceededOut = false;
......@@ -772,21 +798,23 @@ angle::Result BlitGL::copyTexSubImage(TextureGL *source,
mStateManager->bindTexture(dest->getType(), dest->getTextureID());
mFunctions->copyTexSubImage2D(ToGLenum(destTarget), static_cast<GLint>(destLevel), destOffset.x,
destOffset.y, sourceArea.x, sourceArea.y, sourceArea.width,
sourceArea.height);
ANGLE_GL_TRY(context,
mFunctions->copyTexSubImage2D(ToGLenum(destTarget), static_cast<GLint>(destLevel),
destOffset.x, destOffset.y, sourceArea.x,
sourceArea.y, sourceArea.width, sourceArea.height));
*copySucceededOut = true;
return angle::Result::Continue;
}
angle::Result BlitGL::clearRenderableTexture(TextureGL *source,
angle::Result BlitGL::clearRenderableTexture(const gl::Context *context,
TextureGL *source,
GLenum sizedInternalFormat,
int numTextureLayers,
const gl::ImageIndex &imageIndex,
bool *clearSucceededOut)
{
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
ClearBindTargetVector bindTargets;
ClearBindTargetVector unbindTargets;
......@@ -795,26 +823,26 @@ angle::Result BlitGL::clearRenderableTexture(TextureGL *source,
&clearMask));
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
UnbindAttachments(mFunctions, GL_FRAMEBUFFER, unbindTargets);
ANGLE_TRY(UnbindAttachments(context, mFunctions, GL_FRAMEBUFFER, unbindTargets));
if (nativegl::UseTexImage2D(source->getType()))
{
ASSERT(numTextureLayers == 1);
for (GLenum bindTarget : bindTargets)
{
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, bindTarget,
ToGLenum(imageIndex.getTarget()),
source->getTextureID(), imageIndex.getLevelIndex());
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(
GL_FRAMEBUFFER, bindTarget, ToGLenum(imageIndex.getTarget()),
source->getTextureID(), imageIndex.getLevelIndex()));
}
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
GLenum status = ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
if (status == GL_FRAMEBUFFER_COMPLETE)
{
mFunctions->clear(clearMask);
ANGLE_GL_TRY(context, mFunctions->clear(clearMask));
}
else
{
UnbindAttachments(mFunctions, GL_FRAMEBUFFER, bindTargets);
ANGLE_TRY(UnbindAttachments(context, mFunctions, GL_FRAMEBUFFER, bindTargets));
*clearSucceededOut = false;
return angle::Result::Continue;
}
......@@ -828,18 +856,20 @@ angle::Result BlitGL::clearRenderableTexture(TextureGL *source,
{
for (GLenum bindTarget : bindTargets)
{
mFunctions->framebufferTexture(GL_FRAMEBUFFER, bindTarget, source->getTextureID(),
imageIndex.getLevelIndex());
ANGLE_GL_TRY(context, mFunctions->framebufferTexture(GL_FRAMEBUFFER, bindTarget,
source->getTextureID(),
imageIndex.getLevelIndex()));
}
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
GLenum status =
ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
if (status == GL_FRAMEBUFFER_COMPLETE)
{
mFunctions->clear(clearMask);
ANGLE_GL_TRY(context, mFunctions->clear(clearMask));
}
else
{
UnbindAttachments(mFunctions, GL_FRAMEBUFFER, bindTargets);
ANGLE_TRY(UnbindAttachments(context, mFunctions, GL_FRAMEBUFFER, bindTargets));
*clearSucceededOut = false;
return angle::Result::Continue;
}
......@@ -858,19 +888,20 @@ angle::Result BlitGL::clearRenderableTexture(TextureGL *source,
{
for (GLenum bindTarget : bindTargets)
{
mFunctions->framebufferTextureLayer(
ANGLE_GL_TRY(context, mFunctions->framebufferTextureLayer(
GL_FRAMEBUFFER, bindTarget, source->getTextureID(),
imageIndex.getLevelIndex(), layer + firstLayer);
imageIndex.getLevelIndex(), layer + firstLayer));
}
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
GLenum status =
ANGLE_GL_TRY(context, mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER));
if (status == GL_FRAMEBUFFER_COMPLETE)
{
mFunctions->clear(clearMask);
ANGLE_GL_TRY(context, mFunctions->clear(clearMask));
}
else
{
UnbindAttachments(mFunctions, GL_FRAMEBUFFER, bindTargets);
ANGLE_TRY(UnbindAttachments(context, mFunctions, GL_FRAMEBUFFER, bindTargets));
*clearSucceededOut = false;
return angle::Result::Continue;
}
......@@ -878,14 +909,16 @@ angle::Result BlitGL::clearRenderableTexture(TextureGL *source,
}
}
UnbindAttachments(mFunctions, GL_FRAMEBUFFER, bindTargets);
ANGLE_TRY(UnbindAttachments(context, mFunctions, GL_FRAMEBUFFER, bindTargets));
*clearSucceededOut = true;
return angle::Result::Continue;
}
angle::Result BlitGL::clearRenderbuffer(RenderbufferGL *source, GLenum sizedInternalFormat)
angle::Result BlitGL::clearRenderbuffer(const gl::Context *context,
RenderbufferGL *source,
GLenum sizedInternalFormat)
{
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
ClearBindTargetVector bindTargets;
ClearBindTargetVector unbindTargets;
......@@ -894,25 +927,27 @@ angle::Result BlitGL::clearRenderbuffer(RenderbufferGL *source, GLenum sizedInte
&clearMask));
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
UnbindAttachments(mFunctions, GL_FRAMEBUFFER, unbindTargets);
ANGLE_TRY(UnbindAttachments(context, mFunctions, GL_FRAMEBUFFER, unbindTargets));
for (GLenum bindTarget : bindTargets)
{
mFunctions->framebufferRenderbuffer(GL_FRAMEBUFFER, bindTarget, GL_RENDERBUFFER,
source->getRenderbufferID());
ANGLE_GL_TRY(context,
mFunctions->framebufferRenderbuffer(
GL_FRAMEBUFFER, bindTarget, GL_RENDERBUFFER, source->getRenderbufferID()));
}
mFunctions->clear(clearMask);
ANGLE_GL_TRY(context, mFunctions->clear(clearMask));
// Unbind
for (GLenum bindTarget : bindTargets)
{
mFunctions->framebufferRenderbuffer(GL_FRAMEBUFFER, bindTarget, GL_RENDERBUFFER, 0);
ANGLE_GL_TRY(context, mFunctions->framebufferRenderbuffer(GL_FRAMEBUFFER, bindTarget,
GL_RENDERBUFFER, 0));
}
return angle::Result::Continue;
}
angle::Result BlitGL::clearFramebuffer(FramebufferGL *source)
angle::Result BlitGL::clearFramebuffer(const gl::Context *context, FramebufferGL *source)
{
// initializeResources skipped because no local state is used
......@@ -921,53 +956,56 @@ angle::Result BlitGL::clearFramebuffer(FramebufferGL *source)
ANGLE_TRY(SetClearState(mStateManager, true, true, true, &clearMask));
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, source->getFramebufferID());
mFunctions->clear(clearMask);
ANGLE_GL_TRY(context, mFunctions->clear(clearMask));
return angle::Result::Continue;
}
angle::Result BlitGL::clearRenderableTextureAlphaToOne(GLuint texture,
angle::Result BlitGL::clearRenderableTextureAlphaToOne(const gl::Context *context,
GLuint texture,
gl::TextureTarget target,
size_t level)
{
// Clearing the alpha of 3D textures is not supported/needed yet.
ASSERT(nativegl::UseTexImage2D(TextureTargetToType(target)));
ANGLE_TRY(initializeResources());
ANGLE_TRY(initializeResources(context));
mStateManager->setClearColor(gl::ColorF(0.0f, 0.0f, 0.0f, 1.0f));
mStateManager->setColorMask(false, false, false, true);
mStateManager->setScissorTestEnabled(false);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ToGLenum(target),
texture, static_cast<GLint>(level));
mFunctions->clear(GL_COLOR_BUFFER_BIT);
ANGLE_GL_TRY(context, mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
ToGLenum(target), texture,
static_cast<GLint>(level)));
ANGLE_GL_TRY(context, mFunctions->clear(GL_COLOR_BUFFER_BIT));
// Unbind the texture from the the scratch framebuffer
mFunctions->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
ANGLE_GL_TRY(context, mFunctions->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, 0));
return angle::Result::Continue;
}
angle::Result BlitGL::initializeResources()
angle::Result BlitGL::initializeResources(const gl::Context *context)
{
for (size_t i = 0; i < ArraySize(mScratchTextures); i++)
{
if (mScratchTextures[i] == 0)
{
mFunctions->genTextures(1, &mScratchTextures[i]);
ANGLE_GL_TRY(context, mFunctions->genTextures(1, &mScratchTextures[i]));
}
}
if (mScratchFBO == 0)
{
mFunctions->genFramebuffers(1, &mScratchFBO);
ANGLE_GL_TRY(context, mFunctions->genFramebuffers(1, &mScratchFBO));
}
if (mVertexBuffer == 0)
{
mFunctions->genBuffers(1, &mVertexBuffer);
ANGLE_GL_TRY(context, mFunctions->genBuffers(1, &mVertexBuffer));
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
// Use a single, large triangle, to avoid arithmetic precision issues where fragments
......@@ -976,12 +1014,13 @@ angle::Result BlitGL::initializeResources()
-0.5f, 0.0f, 1.5f, 0.0f, 0.5f, 2.0f,
};
mFunctions->bufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, vertexData, GL_STATIC_DRAW);
ANGLE_GL_TRY(context, mFunctions->bufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, vertexData,
GL_STATIC_DRAW));
}
if (mVAO == 0)
{
mFunctions->genVertexArrays(1, &mVAO);
ANGLE_GL_TRY(context, mFunctions->genVertexArrays(1, &mVAO));
mStateManager->bindVertexArray(mVAO, 0);
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
......@@ -989,19 +1028,20 @@ angle::Result BlitGL::initializeResources()
// Enable all attributes with the same buffer so that it doesn't matter what location the
// texcoord attribute is assigned
GLint maxAttributes = 0;
mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttributes);
ANGLE_GL_TRY(context, mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttributes));
for (GLint i = 0; i < maxAttributes; i++)
{
mFunctions->enableVertexAttribArray(i);
mFunctions->vertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
ANGLE_GL_TRY(context, mFunctions->enableVertexAttribArray(i));
ANGLE_GL_TRY(context,
mFunctions->vertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
}
}
return angle::Result::Continue;
}
void BlitGL::orphanScratchTextures()
angle::Result BlitGL::orphanScratchTextures(const gl::Context *context)
{
for (auto texture : mScratchTextures)
{
......@@ -1009,19 +1049,23 @@ void BlitGL::orphanScratchTextures()
gl::PixelUnpackState unpack;
mStateManager->setPixelUnpackState(unpack);
mStateManager->setPixelUnpackBuffer(nullptr);
mFunctions->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE,
nullptr);
ANGLE_GL_TRY(context, mFunctions->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 0, GL_RGBA,
GL_UNSIGNED_BYTE, nullptr));
}
return angle::Result::Continue;
}
void BlitGL::setScratchTextureParameter(GLenum param, GLenum value)
angle::Result BlitGL::setScratchTextureParameter(const gl::Context *context,
GLenum param,
GLenum value)
{
for (auto texture : mScratchTextures)
{
mStateManager->bindTexture(gl::TextureType::_2D, texture);
mFunctions->texParameteri(GL_TEXTURE_2D, param, value);
mFunctions->texParameteri(GL_TEXTURE_2D, param, value);
ANGLE_GL_TRY(context, mFunctions->texParameteri(GL_TEXTURE_2D, param, value));
ANGLE_GL_TRY(context, mFunctions->texParameteri(GL_TEXTURE_2D, param, value));
}
return angle::Result::Continue;
}
BlitGL::BlitProgramType BlitGL::getBlitProgramType(gl::TextureType sourceTextureType,
......@@ -1057,12 +1101,10 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
BlitProgramType type,
BlitProgram **program)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
BlitProgram &result = mBlitPrograms[type];
if (result.program == 0)
{
result.program = mFunctions->createProgram();
result.program = ANGLE_GL_TRY(context, mFunctions->createProgram());
// Depending on what types need to be output by the shaders, different versions need to be
// used.
......@@ -1119,13 +1161,13 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
std::string vsSourceStr = vsSourceStream.str();
const char *vsSourceCStr = vsSourceStr.c_str();
GLuint vs = mFunctions->createShader(GL_VERTEX_SHADER);
mFunctions->shaderSource(vs, 1, &vsSourceCStr, nullptr);
mFunctions->compileShader(vs);
ANGLE_TRY(CheckCompileStatus(contextGL, mFunctions, vs));
GLuint vs = ANGLE_GL_TRY(context, mFunctions->createShader(GL_VERTEX_SHADER));
ANGLE_GL_TRY(context, mFunctions->shaderSource(vs, 1, &vsSourceCStr, nullptr));
ANGLE_GL_TRY(context, mFunctions->compileShader(vs));
ANGLE_TRY(CheckCompileStatus(context, mFunctions, vs));
mFunctions->attachShader(result.program, vs);
mFunctions->deleteShader(vs);
ANGLE_GL_TRY(context, mFunctions->attachShader(result.program, vs));
ANGLE_GL_TRY(context, mFunctions->deleteShader(vs));
}
{
......@@ -1238,26 +1280,28 @@ angle::Result BlitGL::getBlitProgram(const gl::Context *context,
std::string fsSourceStr = fsSourceStream.str();
const char *fsSourceCStr = fsSourceStr.c_str();
GLuint fs = mFunctions->createShader(GL_FRAGMENT_SHADER);
mFunctions->shaderSource(fs, 1, &fsSourceCStr, nullptr);
mFunctions->compileShader(fs);
ANGLE_TRY(CheckCompileStatus(contextGL, mFunctions, fs));
GLuint fs = ANGLE_GL_TRY(context, mFunctions->createShader(GL_FRAGMENT_SHADER));
ANGLE_GL_TRY(context, mFunctions->shaderSource(fs, 1, &fsSourceCStr, nullptr));
ANGLE_GL_TRY(context, mFunctions->compileShader(fs));
ANGLE_TRY(CheckCompileStatus(context, mFunctions, fs));
mFunctions->attachShader(result.program, fs);
mFunctions->deleteShader(fs);
ANGLE_GL_TRY(context, mFunctions->attachShader(result.program, fs));
ANGLE_GL_TRY(context, mFunctions->deleteShader(fs));
}
mFunctions->linkProgram(result.program);
ANGLE_TRY(CheckLinkStatus(contextGL, mFunctions, result.program));
ANGLE_GL_TRY(context, mFunctions->linkProgram(result.program));
ANGLE_TRY(CheckLinkStatus(context, mFunctions, result.program));
result.sourceTextureLocation =
mFunctions->getUniformLocation(result.program, "u_source_texture");
result.scaleLocation = mFunctions->getUniformLocation(result.program, "u_scale");
result.offsetLocation = mFunctions->getUniformLocation(result.program, "u_offset");
result.multiplyAlphaLocation =
mFunctions->getUniformLocation(result.program, "u_multiply_alpha");
result.unMultiplyAlphaLocation =
mFunctions->getUniformLocation(result.program, "u_unmultiply_alpha");
result.sourceTextureLocation = ANGLE_GL_TRY(
context, mFunctions->getUniformLocation(result.program, "u_source_texture"));
result.scaleLocation =
ANGLE_GL_TRY(context, mFunctions->getUniformLocation(result.program, "u_scale"));
result.offsetLocation =
ANGLE_GL_TRY(context, mFunctions->getUniformLocation(result.program, "u_offset"));
result.multiplyAlphaLocation = ANGLE_GL_TRY(
context, mFunctions->getUniformLocation(result.program, "u_multiply_alpha"));
result.unMultiplyAlphaLocation = ANGLE_GL_TRY(
context, mFunctions->getUniformLocation(result.program, "u_unmultiply_alpha"));
}
*program = &result;
......
......@@ -107,7 +107,8 @@ class BlitGL : angle::NonCopyable
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha);
angle::Result copyTexSubImage(TextureGL *source,
angle::Result copyTexSubImage(const gl::Context *context,
TextureGL *source,
size_t sourceLevel,
TextureGL *dest,
gl::TextureTarget destTarget,
......@@ -116,25 +117,31 @@ class BlitGL : angle::NonCopyable
const gl::Offset &destOffset,
bool *copySucceededOut);
angle::Result clearRenderableTexture(TextureGL *source,
angle::Result clearRenderableTexture(const gl::Context *context,
TextureGL *source,
GLenum sizedInternalFormat,
int numTextureLayers,
const gl::ImageIndex &imageIndex,
bool *clearSucceededOut);
angle::Result clearRenderbuffer(RenderbufferGL *source, GLenum sizedInternalFormat);
angle::Result clearRenderbuffer(const gl::Context *context,
RenderbufferGL *source,
GLenum sizedInternalFormat);
angle::Result clearFramebuffer(FramebufferGL *source);
angle::Result clearFramebuffer(const gl::Context *context, FramebufferGL *source);
angle::Result clearRenderableTextureAlphaToOne(GLuint texture,
angle::Result clearRenderableTextureAlphaToOne(const gl::Context *context,
GLuint texture,
gl::TextureTarget target,
size_t level);
angle::Result initializeResources();
angle::Result initializeResources(const gl::Context *context);
private:
void orphanScratchTextures();
void setScratchTextureParameter(GLenum param, GLenum value);
angle::Result orphanScratchTextures(const gl::Context *context);
angle::Result setScratchTextureParameter(const gl::Context *context,
GLenum param,
GLenum value);
const FunctionsGL *mFunctions;
const angle::FeaturesGL &mFeatures;
......
......@@ -113,7 +113,7 @@ GLuint RenderbufferGL::getRenderbufferID() const
angle::Result RenderbufferGL::initializeContents(const gl::Context *context,
const gl::ImageIndex &imageIndex)
{
return mBlitter->clearRenderbuffer(this, mNativeInternalFormat);
return mBlitter->clearRenderbuffer(context, this, mNativeInternalFormat);
}
GLenum RenderbufferGL::getNativeInternalFormat() const
......
......@@ -41,7 +41,7 @@ angle::Result SurfaceGL::initializeContents(const gl::Context *context,
ASSERT(framebufferGL->isDefault());
BlitGL *blitter = GetBlitGL(context);
ANGLE_TRY(blitter->clearFramebuffer(framebufferGL));
ANGLE_TRY(blitter->clearFramebuffer(context, framebufferGL));
return angle::Result::Continue;
}
......
......@@ -879,8 +879,8 @@ angle::Result TextureGL::copySubTextureHelper(const gl::Context *context,
!destSRGB && sourceGL->getType() == gl::TextureType::_2D)
{
bool copySucceeded = false;
ANGLE_TRY(blitter->copyTexSubImage(sourceGL, sourceLevel, this, target, level, sourceArea,
destOffset, &copySucceeded));
ANGLE_TRY(blitter->copyTexSubImage(context, sourceGL, sourceLevel, this, target, level,
sourceArea, destOffset, &copySucceeded));
if (copySucceeded)
{
return angle::Result::Continue;
......@@ -1802,7 +1802,7 @@ angle::Result TextureGL::initializeContents(const gl::Context *context,
int levelDepth = mState.getImageDesc(imageIndex).size.depth;
bool clearSucceeded = false;
ANGLE_TRY(blitter->clearRenderableTexture(this, nativeInternalFormat, levelDepth,
ANGLE_TRY(blitter->clearRenderableTexture(context, this, nativeInternalFormat, levelDepth,
imageIndex, &clearSucceeded));
if (clearSucceeded)
{
......
......@@ -319,7 +319,8 @@ angle::Result IOSurfaceSurfaceCGL::initializeAlphaChannel(const gl::Context *con
}
BlitGL *blitter = GetBlitGL(context);
ANGLE_TRY(blitter->clearRenderableTextureAlphaToOne(texture, gl::TextureTarget::Rectangle, 0));
ANGLE_TRY(blitter->clearRenderableTextureAlphaToOne(context, texture,
gl::TextureTarget::Rectangle, 0));
mAlphaInitialized = true;
return angle::Result::Continue;
}
......
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