Commit 308d745d by Frank Henigman Committed by Commit Bot

Don't use GL_FRAMEBUFFER_SRGB unless available.

Don't try to enable or disable GL_FRAMEBUFFER_SRGB unless extensions.sRGBWriteControl is true. For example if you try it with Mesa GLES2 you get a GL error. BUG=angleproject:1896 Change-Id: I5f5b4e8ea4f5a7c6913f27761a6e2dc88aacc78c Reviewed-on: https://chromium-review.googlesource.com/443824 Commit-Queue: Frank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 4e0e6f8a
......@@ -330,7 +330,7 @@ void ContextGL::popGroupMarker()
void ContextGL::syncState(const gl::State::DirtyBits &dirtyBits)
{
mRenderer->getStateManager()->syncState(mState.getState(), dirtyBits);
mRenderer->getStateManager()->syncState(mState, dirtyBits);
}
GLint ContextGL::getGPUDisjoint()
......
......@@ -167,7 +167,7 @@ Error FramebufferGL::invalidateSub(size_t count,
Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask)
{
syncClearState(mask);
syncClearState(context, mask);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
mFunctions->clear(mask);
......@@ -179,7 +179,7 @@ Error FramebufferGL::clearBufferfv(ContextImpl *context,
GLint drawbuffer,
const GLfloat *values)
{
syncClearBufferState(buffer, drawbuffer);
syncClearBufferState(context, buffer, drawbuffer);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
mFunctions->clearBufferfv(buffer, drawbuffer, values);
......@@ -191,7 +191,7 @@ Error FramebufferGL::clearBufferuiv(ContextImpl *context,
GLint drawbuffer,
const GLuint *values)
{
syncClearBufferState(buffer, drawbuffer);
syncClearBufferState(context, buffer, drawbuffer);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
mFunctions->clearBufferuiv(buffer, drawbuffer, values);
......@@ -203,7 +203,7 @@ Error FramebufferGL::clearBufferiv(ContextImpl *context,
GLint drawbuffer,
const GLint *values)
{
syncClearBufferState(buffer, drawbuffer);
syncClearBufferState(context, buffer, drawbuffer);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
mFunctions->clearBufferiv(buffer, drawbuffer, values);
......@@ -216,7 +216,7 @@ Error FramebufferGL::clearBufferfi(ContextImpl *context,
GLfloat depth,
GLint stencil)
{
syncClearBufferState(buffer, drawbuffer);
syncClearBufferState(context, buffer, drawbuffer);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil);
......@@ -343,7 +343,7 @@ Error FramebufferGL::blit(ContextImpl *context,
}
// Enable FRAMEBUFFER_SRGB if needed
mStateManager->setFramebufferSRGBEnabledForFramebuffer(true, this);
mStateManager->setFramebufferSRGBEnabledForFramebuffer(context->getContextState(), true, this);
GLenum blitMask = mask;
if (needManualColorBlit && (mask & GL_COLOR_BUFFER_BIT) && readAttachmentSamples <= 1)
......@@ -461,7 +461,7 @@ bool FramebufferGL::isDefault() const
return mIsDefault;
}
void FramebufferGL::syncClearState(GLbitfield mask)
void FramebufferGL::syncClearState(ContextImpl *context, GLbitfield mask)
{
if (mFunctions->standard == STANDARD_GL_DESKTOP)
{
......@@ -478,16 +478,16 @@ void FramebufferGL::syncClearState(GLbitfield mask)
}
}
mStateManager->setFramebufferSRGBEnabled(hasSRGBAttachment);
mStateManager->setFramebufferSRGBEnabled(context->getContextState(), hasSRGBAttachment);
}
else
{
mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
mStateManager->setFramebufferSRGBEnabled(context->getContextState(), !mIsDefault);
}
}
}
void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
void FramebufferGL::syncClearBufferState(ContextImpl *context, GLenum buffer, GLint drawBuffer)
{
if (mFunctions->standard == STANDARD_GL_DESKTOP)
{
......@@ -510,12 +510,13 @@ void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
if (attachment != nullptr)
{
mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB);
mStateManager->setFramebufferSRGBEnabled(context->getContextState(),
attachment->getColorEncoding() == GL_SRGB);
}
}
else
{
mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
mStateManager->setFramebufferSRGBEnabled(context->getContextState(), !mIsDefault);
}
}
}
......
......@@ -86,8 +86,8 @@ class FramebufferGL : public FramebufferImpl
bool isDefault() const;
private:
void syncClearState(GLbitfield mask);
void syncClearBufferState(GLenum buffer, GLint drawBuffer);
void syncClearState(ContextImpl *context, GLbitfield mask);
void syncClearBufferState(ContextImpl *context, GLenum buffer, GLint drawBuffer);
gl::Error readPixelsRowByRowWorkaround(const gl::Rectangle &area,
GLenum format,
......
......@@ -1376,8 +1376,11 @@ void StateManagerGL::setClearStencil(GLint clearStencil)
}
}
void StateManagerGL::syncState(const gl::State &state, const gl::State::DirtyBits &glDirtyBits)
void StateManagerGL::syncState(const gl::ContextState &data,
const gl::State::DirtyBits &glDirtyBits)
{
const gl::State &state = data.getState();
// The the current framebuffer binding sometimes requires resetting the srgb blending
if (glDirtyBits[gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING] &&
mFunctions->standard == STANDARD_GL_DESKTOP)
......@@ -1630,7 +1633,7 @@ void StateManagerGL::syncState(const gl::State &state, const gl::State::DirtyBit
break;
case gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB:
setFramebufferSRGBEnabledForFramebuffer(
state.getFramebufferSRGB(),
data, state.getFramebufferSRGB(),
GetImplAs<FramebufferGL>(state.getDrawFramebuffer()));
break;
default:
......@@ -1649,8 +1652,13 @@ void StateManagerGL::syncState(const gl::State &state, const gl::State::DirtyBit
}
}
void StateManagerGL::setFramebufferSRGBEnabled(bool enabled)
void StateManagerGL::setFramebufferSRGBEnabled(const gl::ContextState &data, bool enabled)
{
if (!data.getExtensions().sRGBWriteControl)
{
return;
}
if (mFramebufferSRGBEnabled != enabled)
{
mFramebufferSRGBEnabled = enabled;
......@@ -1666,7 +1674,8 @@ void StateManagerGL::setFramebufferSRGBEnabled(bool enabled)
}
}
void StateManagerGL::setFramebufferSRGBEnabledForFramebuffer(bool enabled,
void StateManagerGL::setFramebufferSRGBEnabledForFramebuffer(const gl::ContextState &data,
bool enabled,
const FramebufferGL *framebuffer)
{
if (mFunctions->standard == STANDARD_GL_DESKTOP && framebuffer->isDefault())
......@@ -1676,11 +1685,11 @@ void StateManagerGL::setFramebufferSRGBEnabledForFramebuffer(bool enabled,
// 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.
setFramebufferSRGBEnabled(false);
setFramebufferSRGBEnabled(data, false);
}
else
{
setFramebufferSRGBEnabled(enabled);
setFramebufferSRGBEnabled(data, enabled);
}
}
......
......@@ -123,8 +123,10 @@ class StateManagerGL final : angle::NonCopyable
GLint skipPixels,
GLuint packBuffer);
void setFramebufferSRGBEnabled(bool enabled);
void setFramebufferSRGBEnabledForFramebuffer(bool enabled, const FramebufferGL *framebuffer);
void setFramebufferSRGBEnabled(const gl::ContextState &data, bool enabled);
void setFramebufferSRGBEnabledForFramebuffer(const gl::ContextState &data,
bool enabled,
const FramebufferGL *framebuffer);
void setDitherEnabled(bool enabled);
......@@ -158,7 +160,7 @@ class StateManagerGL final : angle::NonCopyable
void resumeQuery(GLenum type);
gl::Error onMakeCurrent(const gl::ContextState &data);
void syncState(const gl::State &state, const gl::State::DirtyBits &glDirtyBits);
void syncState(const gl::ContextState &data, const gl::State::DirtyBits &glDirtyBits);
GLuint getBoundBuffer(GLenum type);
......
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