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