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: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/gl/ContextGL.cpp b/src/libANGLE/renderer/gl/ContextGL.cpp
index 23de402..ffa4ba8 100644
--- a/src/libANGLE/renderer/gl/ContextGL.cpp
+++ b/src/libANGLE/renderer/gl/ContextGL.cpp
@@ -330,7 +330,7 @@
void ContextGL::syncState(const gl::State::DirtyBits &dirtyBits)
{
- mRenderer->getStateManager()->syncState(mState.getState(), dirtyBits);
+ mRenderer->getStateManager()->syncState(mState, dirtyBits);
}
GLint ContextGL::getGPUDisjoint()
diff --git a/src/libANGLE/renderer/gl/FramebufferGL.cpp b/src/libANGLE/renderer/gl/FramebufferGL.cpp
index 8cf144f..a4b4ccd 100644
--- a/src/libANGLE/renderer/gl/FramebufferGL.cpp
+++ b/src/libANGLE/renderer/gl/FramebufferGL.cpp
@@ -167,7 +167,7 @@
Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask)
{
- syncClearState(mask);
+ syncClearState(context, mask);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
mFunctions->clear(mask);
@@ -179,7 +179,7 @@
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 @@
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 @@
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 @@
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 @@
}
// 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 @@
return mIsDefault;
}
-void FramebufferGL::syncClearState(GLbitfield mask)
+void FramebufferGL::syncClearState(ContextImpl *context, GLbitfield mask)
{
if (mFunctions->standard == STANDARD_GL_DESKTOP)
{
@@ -478,16 +478,16 @@
}
}
- 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 @@
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);
}
}
}
diff --git a/src/libANGLE/renderer/gl/FramebufferGL.h b/src/libANGLE/renderer/gl/FramebufferGL.h
index eb2f7c7..6fc8554 100644
--- a/src/libANGLE/renderer/gl/FramebufferGL.h
+++ b/src/libANGLE/renderer/gl/FramebufferGL.h
@@ -86,8 +86,8 @@
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,
diff --git a/src/libANGLE/renderer/gl/StateManagerGL.cpp b/src/libANGLE/renderer/gl/StateManagerGL.cpp
index 8225197..8a87391 100644
--- a/src/libANGLE/renderer/gl/StateManagerGL.cpp
+++ b/src/libANGLE/renderer/gl/StateManagerGL.cpp
@@ -1376,8 +1376,11 @@
}
}
-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 @@
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::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::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 @@
// 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);
}
}
diff --git a/src/libANGLE/renderer/gl/StateManagerGL.h b/src/libANGLE/renderer/gl/StateManagerGL.h
index 8fbe5d6..2e9effb 100644
--- a/src/libANGLE/renderer/gl/StateManagerGL.h
+++ b/src/libANGLE/renderer/gl/StateManagerGL.h
@@ -123,8 +123,10 @@
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 @@
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);