diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-07-11 23:29:50 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-07-11 23:31:02 +0200 |
commit | 70dd5e7c66b1fe3f82e5b4db2406050baba15f05 (patch) | |
tree | 3f012200ef3c934f33db1a4ef2b790fae3141860 /gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp | |
parent | 3b7ffb477eec078c7036c92c6a51bb5de6de4f28 (diff) | |
parent | 8481fa25d246f1968d0a254ee3c6cdd82c60781a (diff) | |
download | UXP-70dd5e7c66b1fe3f82e5b4db2406050baba15f05.tar UXP-70dd5e7c66b1fe3f82e5b4db2406050baba15f05.tar.gz UXP-70dd5e7c66b1fe3f82e5b4db2406050baba15f05.tar.lz UXP-70dd5e7c66b1fe3f82e5b4db2406050baba15f05.tar.xz UXP-70dd5e7c66b1fe3f82e5b4db2406050baba15f05.zip |
Merge branch 'ANGLE-rollback'
This resolves #624
Note: Cherry-picked some fixes on top of the ANGLE version that we want to keep.
Diffstat (limited to 'gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp')
-rwxr-xr-x | gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp | 199 |
1 files changed, 20 insertions, 179 deletions
diff --git a/gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp b/gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp index 0a058f8ba..4606114ca 100755 --- a/gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp +++ b/gfx/angle/src/libANGLE/renderer/gl/FramebufferGL.cpp @@ -16,18 +16,14 @@ #include "libANGLE/angletypes.h" #include "libANGLE/formatutils.h" #include "libANGLE/renderer/ContextImpl.h" -#include "libANGLE/renderer/gl/BlitGL.h" #include "libANGLE/renderer/gl/FunctionsGL.h" #include "libANGLE/renderer/gl/RenderbufferGL.h" #include "libANGLE/renderer/gl/StateManagerGL.h" #include "libANGLE/renderer/gl/TextureGL.h" #include "libANGLE/renderer/gl/WorkaroundsGL.h" -#include "libANGLE/renderer/gl/formatutilsgl.h" -#include "libANGLE/renderer/gl/renderergl_utils.h" #include "platform/Platform.h" using namespace gl; -using angle::CheckedNumeric; namespace rx { @@ -36,13 +32,11 @@ FramebufferGL::FramebufferGL(const FramebufferState &state, const FunctionsGL *functions, StateManagerGL *stateManager, const WorkaroundsGL &workarounds, - BlitGL *blitter, bool isDefault) : FramebufferImpl(state), mFunctions(functions), mStateManager(stateManager), mWorkarounds(workarounds), - mBlitter(blitter), mFramebufferID(0), mIsDefault(isDefault) { @@ -56,13 +50,11 @@ FramebufferGL::FramebufferGL(GLuint id, const FramebufferState &state, const FunctionsGL *functions, const WorkaroundsGL &workarounds, - BlitGL *blitter, StateManagerGL *stateManager) : FramebufferImpl(state), mFunctions(functions), mStateManager(stateManager), mWorkarounds(workarounds), - mBlitter(blitter), mFramebufferID(id), mIsDefault(true) { @@ -220,14 +212,14 @@ GLenum FramebufferGL::getImplementationColorReadFormat() const { const auto *readAttachment = mState.getReadAttachment(); const Format &format = readAttachment->getFormat(); - return format.info->getReadPixelsFormat(); + return format.info->format; } GLenum FramebufferGL::getImplementationColorReadType() const { const auto *readAttachment = mState.getReadAttachment(); const Format &format = readAttachment->getFormat(); - return format.info->getReadPixelsType(); + return format.info->type; } Error FramebufferGL::readPixels(ContextImpl *context, @@ -241,37 +233,10 @@ Error FramebufferGL::readPixels(ContextImpl *context, const PixelPackState &packState = context->getGLState().getPackState(); mStateManager->setPixelPackState(packState); - nativegl::ReadPixelsFormat readPixelsFormat = - nativegl::GetReadPixelsFormat(mFunctions, mWorkarounds, format, type); - GLenum readFormat = readPixelsFormat.format; - GLenum readType = readPixelsFormat.type; - mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID); + mFunctions->readPixels(area.x, area.y, area.width, area.height, format, type, pixels); - if (mWorkarounds.packOverlappingRowsSeparatelyPackBuffer && packState.pixelBuffer.get() && - packState.rowLength != 0 && packState.rowLength < area.width) - { - return readPixelsRowByRowWorkaround(area, readFormat, readType, packState, pixels); - } - - if (mWorkarounds.packLastRowSeparatelyForPaddingInclusion) - { - gl::Extents size(area.width, area.height, 1); - - bool apply; - ANGLE_TRY_RESULT(ShouldApplyLastRowPaddingWorkaround(size, packState, readFormat, readType, - false, pixels), - apply); - - if (apply) - { - return readPixelsPaddingWorkaround(area, readFormat, readType, packState, pixels); - } - } - - mFunctions->readPixels(area.x, area.y, area.width, area.height, readFormat, readType, pixels); - - return gl::NoError(); + return Error(GL_NO_ERROR); } Error FramebufferGL::blit(ContextImpl *context, @@ -281,80 +246,15 @@ Error FramebufferGL::blit(ContextImpl *context, GLenum filter) { const Framebuffer *sourceFramebuffer = context->getGLState().getReadFramebuffer(); - const Framebuffer *destFramebuffer = context->getGLState().getDrawFramebuffer(); - - const FramebufferAttachment *colorReadAttachment = sourceFramebuffer->getReadColorbuffer(); - GLsizei readAttachmentSamples = colorReadAttachment->getSamples(); - - bool needManualColorBlit = false; - - // TODO(cwallez) when the filter is LINEAR and both source and destination are SRGB, we - // could avoid doing a manual blit. - - // Prior to OpenGL 4.4 BlitFramebuffer (section 18.3.1 of GL 4.3 core profile) reads: - // When values are taken from the read buffer, no linearization is performed, even - // if the format of the buffer is SRGB. - // Starting from OpenGL 4.4 (section 18.3.1) it reads: - // When values are taken from the read buffer, if FRAMEBUFFER_SRGB is enabled and the - // value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the framebuffer attachment - // corresponding to the read buffer is SRGB, the red, green, and blue components are - // converted from the non-linear sRGB color space according [...]. - { - bool sourceSRGB = colorReadAttachment != nullptr && - colorReadAttachment->getColorEncoding() == GL_SRGB; - needManualColorBlit = - needManualColorBlit || (sourceSRGB && mFunctions->isAtMostGL(gl::Version(4, 3))); - } - - // Prior to OpenGL 4.2 BlitFramebuffer (section 4.3.2 of GL 4.1 core profile) reads: - // Blit operations bypass the fragment pipeline. The only fragment operations which - // affect a blit are the pixel ownership test and scissor test. - // Starting from OpenGL 4.2 (section 4.3.2) it reads: - // When values are written to the draw buffers, blit operations bypass the fragment - // pipeline. The only fragment operations which affect a blit are the pixel ownership - // test, the scissor test and sRGB conversion. - if (!needManualColorBlit) - { - bool destSRGB = false; - for (size_t i = 0; i < destFramebuffer->getDrawbufferStateCount(); ++i) - { - const FramebufferAttachment *attachment = destFramebuffer->getDrawBuffer(i); - if (attachment && attachment->getColorEncoding() == GL_SRGB) - { - destSRGB = true; - break; - } - } - - needManualColorBlit = - needManualColorBlit || (destSRGB && mFunctions->isAtMostGL(gl::Version(4, 1))); - } - - // Enable FRAMEBUFFER_SRGB if needed - mStateManager->setFramebufferSRGBEnabledForFramebuffer(true, this); - - GLenum blitMask = mask; - if (needManualColorBlit && (mask & GL_COLOR_BUFFER_BIT) && readAttachmentSamples <= 1) - { - ANGLE_TRY(mBlitter->blitColorBufferWithShader(sourceFramebuffer, destFramebuffer, - sourceArea, destArea, filter)); - blitMask &= ~GL_COLOR_BUFFER_BIT; - } - - if (blitMask == 0) - { - return gl::NoError(); - } - const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer); + mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID()); mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID); mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(), - destArea.x, destArea.y, destArea.x1(), destArea.y1(), blitMask, - filter); + destArea.x, destArea.y, destArea.x1(), destArea.y1(), mask, filter); - return gl::NoError(); + return Error(GL_NO_ERROR); } bool FramebufferGL::checkStatus() const @@ -420,9 +320,17 @@ GLuint FramebufferGL::getFramebufferID() const return mFramebufferID; } -bool FramebufferGL::isDefault() const +void FramebufferGL::syncDrawState() const { - return mIsDefault; + if (mFunctions->standard == STANDARD_GL_DESKTOP) + { + // Enable SRGB blending for all framebuffers except the default framebuffer on Desktop + // OpenGL. + // When SRGB blending is enabled, only SRGB capable formats will use it but the default + // framebuffer will always use it if it is enabled. + // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists. + mStateManager->setFramebufferSRGBEnabled(!mIsDefault); + } } void FramebufferGL::syncClearState(GLbitfield mask) @@ -432,17 +340,17 @@ void FramebufferGL::syncClearState(GLbitfield mask) if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault) { - bool hasSRGBAttachment = false; + bool hasSRBAttachment = false; for (const auto &attachment : mState.getColorAttachments()) { if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB) { - hasSRGBAttachment = true; + hasSRBAttachment = true; break; } } - mStateManager->setFramebufferSRGBEnabled(hasSRGBAttachment); + mStateManager->setFramebufferSRGBEnabled(hasSRBAttachment); } else { @@ -483,71 +391,4 @@ void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer) } } } -gl::Error FramebufferGL::readPixelsRowByRowWorkaround(const gl::Rectangle &area, - GLenum format, - GLenum type, - const gl::PixelPackState &pack, - GLvoid *pixels) const -{ - intptr_t offset = reinterpret_cast<intptr_t>(pixels); - - const gl::InternalFormat &glFormat = - gl::GetInternalFormatInfo(gl::GetSizedInternalFormat(format, type)); - GLuint rowBytes = 0; - ANGLE_TRY_RESULT(glFormat.computeRowPitch(area.width, pack.alignment, pack.rowLength), - rowBytes); - GLuint skipBytes = 0; - ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); - - gl::PixelPackState directPack; - directPack.pixelBuffer = pack.pixelBuffer; - directPack.alignment = 1; - mStateManager->setPixelPackState(directPack); - directPack.pixelBuffer.set(nullptr); - - offset += skipBytes; - for (GLint row = 0; row < area.height; ++row) - { - mFunctions->readPixels(area.x, row + area.y, area.width, 1, format, type, - reinterpret_cast<GLvoid *>(offset)); - offset += row * rowBytes; - } - - return gl::NoError(); -} - -gl::Error FramebufferGL::readPixelsPaddingWorkaround(const gl::Rectangle &area, - GLenum format, - GLenum type, - const gl::PixelPackState &pack, - GLvoid *pixels) const -{ - const gl::InternalFormat &glFormat = - gl::GetInternalFormatInfo(gl::GetSizedInternalFormat(format, type)); - GLuint rowBytes = 0; - ANGLE_TRY_RESULT(glFormat.computeRowPitch(area.width, pack.alignment, pack.rowLength), - rowBytes); - GLuint skipBytes = 0; - ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); - - // Get all by the last row - if (area.height > 1) - { - mFunctions->readPixels(area.x, area.y, area.width, area.height - 1, format, type, pixels); - } - - // Get the last row manually - gl::PixelPackState directPack; - directPack.pixelBuffer = pack.pixelBuffer; - directPack.alignment = 1; - mStateManager->setPixelPackState(directPack); - directPack.pixelBuffer.set(nullptr); - - intptr_t lastRowOffset = - reinterpret_cast<intptr_t>(pixels) + skipBytes + (area.height - 1) * rowBytes; - mFunctions->readPixels(area.x, area.y + area.height - 1, area.width, 1, format, type, - reinterpret_cast<GLvoid *>(lastRowOffset)); - - return gl::NoError(); -} } // namespace rx |