Commit 17a4b6e7 by Qin Jiajia Committed by Angle LUCI CQ

Fix that clear-srgb-color-buffer is not correct

This change removes the limitation that syncClearState/ syncClearBufferState is only for STANDARD_GL_DESKTOP so that it works on chromeos. Test: conformance2/rendering/clear-srgb-color-buffer.html deqp/functional/gles3/fbocolorbuffer/clear.html Bug: chromium:1208297 Change-Id: I7c5fed3545f623cca3f2245c67fddaf3401388b5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3010630Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
parent b73eee71
......@@ -1379,32 +1379,27 @@ bool FramebufferGL::hasEmulatedAlphaChannelTextureAttachment() const
void FramebufferGL::syncClearState(const gl::Context *context, GLbitfield mask)
{
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
if (functions->standard == STANDARD_GL_DESKTOP)
if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled &&
(mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
{
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled &&
(mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
bool hasSRGBAttachment = false;
for (const auto &attachment : mState.getColorAttachments())
{
bool hasSRGBAttachment = false;
for (const auto &attachment : mState.getColorAttachments())
if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
{
if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
{
hasSRGBAttachment = true;
break;
}
hasSRGBAttachment = true;
break;
}
stateManager->setFramebufferSRGBEnabled(context, hasSRGBAttachment);
}
else
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
}
stateManager->setFramebufferSRGBEnabled(context, hasSRGBAttachment);
}
else
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
}
}
......@@ -1412,41 +1407,36 @@ void FramebufferGL::syncClearBufferState(const gl::Context *context,
GLenum buffer,
GLint drawBuffer)
{
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
if (functions->standard == STANDARD_GL_DESKTOP)
if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled && buffer == GL_COLOR &&
!mIsDefault)
{
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled && buffer == GL_COLOR &&
!mIsDefault)
// If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
// is an SRGB format.
const auto &drawbufferState = mState.getDrawBufferStates();
const auto &colorAttachments = mState.getColorAttachments();
const FramebufferAttachment *attachment = nullptr;
if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
{
// If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
// is an SRGB format.
const auto &drawbufferState = mState.getDrawBufferStates();
const auto &colorAttachments = mState.getColorAttachments();
const FramebufferAttachment *attachment = nullptr;
if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
{
size_t attachmentIdx =
static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
attachment = &colorAttachments[attachmentIdx];
}
if (attachment != nullptr)
{
stateManager->setFramebufferSRGBEnabled(context,
attachment->getColorEncoding() == GL_SRGB);
}
size_t attachmentIdx =
static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
attachment = &colorAttachments[attachmentIdx];
}
else
if (attachment != nullptr)
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
stateManager->setFramebufferSRGBEnabled(context,
attachment->getColorEncoding() == GL_SRGB);
}
}
else
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
}
}
bool FramebufferGL::modifyInvalidateAttachmentsForEmulatedDefaultFBO(
......
......@@ -2005,10 +2005,7 @@ angle::Result StateManagerGL::syncState(const gl::Context *context,
}
// Changing the draw framebuffer binding sometimes requires resetting srgb blending.
if (mFunctions->standard == STANDARD_GL_DESKTOP)
{
iter.setLaterBit(gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE);
}
iter.setLaterBit(gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE);
// If the framebuffer is emulating RGB on top of RGBA, the color mask has to be
// updated
......@@ -2225,10 +2222,10 @@ void StateManagerGL::setFramebufferSRGBEnabledForFramebuffer(const gl::Context *
bool enabled,
const FramebufferGL *framebuffer)
{
if (mFunctions->standard == STANDARD_GL_DESKTOP && framebuffer->isDefault())
if (framebuffer->isDefault())
{
// Obey the framebuffer sRGB state for blending on all framebuffers except the default
// framebuffer on Desktop OpenGL.
// framebuffer.
// 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.
......
......@@ -1885,7 +1885,7 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature
isIntel && IsApple() && IsSkylake(device) && GetMacOSVersion() < OSVersion(10, 13, 2));
ANGLE_FEATURE_CONDITION(features, doesSRGBClearsOnLinearFramebufferAttachments,
functions->standard == STANDARD_GL_DESKTOP && (isIntel || isAMD));
isIntel || isAMD);
ANGLE_FEATURE_CONDITION(features, emulateMaxVertexAttribStride,
IsLinux() && functions->standard == STANDARD_GL_DESKTOP && isAMD);
......
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