Commit b8517346 by Geoff Lang

Sync the entire depth stencil state before drawing in RendererGL.

BUG=angleproject:883 Change-Id: I1d748281184ff8111f8ff1c63f56882650b6871b Reviewed-on: https://chromium-review.googlesource.com/266034Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 0fbb600f
...@@ -50,10 +50,24 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren ...@@ -50,10 +50,24 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren
mSampleCoverageEnabled(false), mSampleCoverageEnabled(false),
mSampleCoverageValue(1.0f), mSampleCoverageValue(1.0f),
mSampleCoverageInvert(false), mSampleCoverageInvert(false),
mClearDepth(1.0f), mDepthTestEnabled(false),
mDepthFunc(GL_LESS),
mDepthMask(true), mDepthMask(true),
mClearStencil(0), mStencilTestEnabled(false),
mStencilMask(static_cast<GLuint>(-1)) mStencilFrontFunc(GL_ALWAYS),
mStencilFrontValueMask(static_cast<GLuint>(-1)),
mStencilFrontStencilFailOp(GL_KEEP),
mStencilFrontStencilPassDepthFailOp(GL_KEEP),
mStencilFrontStencilPassDepthPassOp(GL_KEEP),
mStencilFrontWritemask(static_cast<GLuint>(-1)),
mStencilBackFunc(GL_ALWAYS),
mStencilBackValueMask(static_cast<GLuint>(-1)),
mStencilBackStencilFailOp(GL_KEEP),
mStencilBackStencilPassDepthFailOp(GL_KEEP),
mStencilBackStencilPassDepthPassOp(GL_KEEP),
mStencilBackWritemask(static_cast<GLuint>(-1)),
mClearDepth(1.0f),
mClearStencil(0)
{ {
ASSERT(mFunctions); ASSERT(mFunctions);
...@@ -168,7 +182,8 @@ void StateManagerGL::setClearState(const gl::State &state, GLbitfield mask) ...@@ -168,7 +182,8 @@ void StateManagerGL::setClearState(const gl::State &state, GLbitfield mask)
if ((mask & GL_STENCIL_BUFFER_BIT) != 0) if ((mask & GL_STENCIL_BUFFER_BIT) != 0)
{ {
setClearStencil(state.getStencilClearValue()); setClearStencil(state.getStencilClearValue());
setStencilMask(state.getDepthStencilState().stencilMask); setStencilFrontWritemask(state.getDepthStencilState().stencilWritemask);
setStencilBackWritemask(state.getDepthStencilState().stencilBackWritemask);
} }
} }
...@@ -278,8 +293,23 @@ gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data) ...@@ -278,8 +293,23 @@ gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data)
setSampleCoverage(state.getSampleCoverageValue(), state.getSampleCoverageInvert()); setSampleCoverage(state.getSampleCoverageValue(), state.getSampleCoverageInvert());
const gl::DepthStencilState &depthStencilState = state.getDepthStencilState(); const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
setDepthMask(depthStencilState.depthMask); setDepthTestEnabled(depthStencilState.depthTest);
setStencilMask(depthStencilState.stencilMask); if (depthStencilState.depthTest)
{
setDepthFunc(depthStencilState.depthFunc);
setDepthMask(depthStencilState.depthMask);
}
setStencilTestEnabled(depthStencilState.stencilTest);
if (depthStencilState.stencilTest)
{
setStencilFrontWritemask(state.getDepthStencilState().stencilWritemask);
setStencilBackWritemask(state.getDepthStencilState().stencilBackWritemask);
setStencilFrontFuncs(depthStencilState.stencilFunc, state.getStencilRef(), depthStencilState.stencilMask);
setStencilBackFuncs(depthStencilState.stencilBackFunc, state.getStencilBackRef(), depthStencilState.stencilBackMask);
setStencilFrontOps(depthStencilState.stencilFail, depthStencilState.stencilPassDepthFail, depthStencilState.stencilPassDepthPass);
setStencilBackOps(depthStencilState.stencilBackFail, depthStencilState.stencilBackPassDepthFail, depthStencilState.stencilBackPassDepthPass);
}
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
...@@ -416,12 +446,28 @@ void StateManagerGL::setSampleCoverage(float value, bool invert) ...@@ -416,12 +446,28 @@ void StateManagerGL::setSampleCoverage(float value, bool invert)
} }
} }
void StateManagerGL::setClearDepth(float clearDepth) void StateManagerGL::setDepthTestEnabled(bool enabled)
{ {
if (mClearDepth != clearDepth) if (mDepthTestEnabled != enabled)
{ {
mClearDepth = clearDepth; mDepthTestEnabled = enabled;
mFunctions->clearDepth(mClearDepth); if (mDepthTestEnabled)
{
mFunctions->enable(GL_DEPTH_TEST);
}
else
{
mFunctions->disable(GL_DEPTH_TEST);
}
}
}
void StateManagerGL::setDepthFunc(GLenum depthFunc)
{
if (mDepthFunc != depthFunc)
{
mDepthFunc = depthFunc;
mFunctions->depthFunc(mDepthFunc);
} }
} }
...@@ -434,21 +480,99 @@ void StateManagerGL::setDepthMask(bool mask) ...@@ -434,21 +480,99 @@ void StateManagerGL::setDepthMask(bool mask)
} }
} }
void StateManagerGL::setClearStencil(GLint clearStencil) void StateManagerGL::setStencilTestEnabled(bool enabled)
{ {
if (mClearStencil != clearStencil) if (mStencilTestEnabled != enabled)
{ {
mClearStencil = clearStencil; mStencilTestEnabled = enabled;
mFunctions->clearStencil(mClearStencil); if (mStencilTestEnabled)
{
mFunctions->enable(GL_STENCIL_TEST);
}
else
{
mFunctions->disable(GL_STENCIL_TEST);
}
} }
} }
void StateManagerGL::setStencilMask(GLuint mask) void StateManagerGL::setStencilFrontWritemask(GLuint mask)
{ {
if (mStencilMask != mask) if (mStencilFrontWritemask != mask)
{ {
mStencilMask = mask; mStencilFrontWritemask = mask;
mFunctions->stencilMask(mStencilMask); mFunctions->stencilMaskSeparate(GL_FRONT, mStencilFrontWritemask);
}
}
void StateManagerGL::setStencilBackWritemask(GLuint mask)
{
if (mStencilBackWritemask != mask)
{
mStencilBackWritemask = mask;
mFunctions->stencilMaskSeparate(GL_BACK, mStencilBackWritemask);
}
}
void StateManagerGL::setStencilFrontFuncs(GLenum func, GLint ref, GLuint mask)
{
if (mStencilFrontFunc != func || mStencilFrontRef != ref || mStencilFrontValueMask != mask)
{
mStencilFrontFunc = func;
mStencilFrontRef = ref;
mStencilFrontValueMask = mask;
mFunctions->stencilFuncSeparate(GL_FRONT, mStencilFrontFunc, mStencilFrontRef, mStencilFrontValueMask);
}
}
void StateManagerGL::setStencilBackFuncs(GLenum func, GLint ref, GLuint mask)
{
if (mStencilBackFunc != func || mStencilBackRef != ref || mStencilBackValueMask != mask)
{
mStencilBackFunc = func;
mStencilBackRef = ref;
mStencilBackValueMask = mask;
mFunctions->stencilFuncSeparate(GL_BACK, mStencilBackFunc, mStencilBackRef, mStencilBackValueMask);
}
}
void StateManagerGL::setStencilFrontOps(GLenum sfail, GLenum dpfail, GLenum dppass)
{
if (mStencilFrontStencilFailOp != sfail || mStencilFrontStencilPassDepthFailOp != dpfail || mStencilFrontStencilPassDepthPassOp != dppass)
{
mStencilFrontStencilFailOp = sfail;
mStencilFrontStencilPassDepthFailOp = dpfail;
mStencilFrontStencilPassDepthPassOp = dppass;
mFunctions->stencilOpSeparate(GL_FRONT, mStencilFrontStencilFailOp, mStencilFrontStencilPassDepthFailOp, mStencilFrontStencilPassDepthPassOp);
}
}
void StateManagerGL::setStencilBackOps(GLenum sfail, GLenum dpfail, GLenum dppass)
{
if (mStencilBackStencilFailOp != sfail || mStencilBackStencilPassDepthFailOp != dpfail || mStencilBackStencilPassDepthPassOp != dppass)
{
mStencilBackStencilFailOp = sfail;
mStencilBackStencilPassDepthFailOp = dpfail;
mStencilBackStencilPassDepthPassOp = dppass;
mFunctions->stencilOpSeparate(GL_BACK, mStencilBackStencilFailOp, mStencilBackStencilPassDepthFailOp, mStencilBackStencilPassDepthPassOp);
}
}
void StateManagerGL::setClearDepth(float clearDepth)
{
if (mClearDepth != clearDepth)
{
mClearDepth = clearDepth;
mFunctions->clearDepth(mClearDepth);
}
}
void StateManagerGL::setClearStencil(GLint clearStencil)
{
if (mClearStencil != clearStencil)
{
mClearStencil = clearStencil;
mFunctions->clearStencil(mClearStencil);
} }
} }
......
...@@ -64,10 +64,19 @@ class StateManagerGL : angle::NonCopyable ...@@ -64,10 +64,19 @@ class StateManagerGL : angle::NonCopyable
void setSampleCoverageEnabled(bool enabled); void setSampleCoverageEnabled(bool enabled);
void setSampleCoverage(float value, bool invert); void setSampleCoverage(float value, bool invert);
void setClearDepth(float clearDepth); void setDepthTestEnabled(bool enabled);
void setDepthFunc(GLenum depthFunc);
void setDepthMask(bool mask); void setDepthMask(bool mask);
void setStencilTestEnabled(bool enabled);
void setStencilFrontWritemask(GLuint mask);
void setStencilBackWritemask(GLuint mask);
void setStencilFrontFuncs(GLenum func, GLint ref, GLuint mask);
void setStencilBackFuncs(GLenum func, GLint ref, GLuint mask);
void setStencilFrontOps(GLenum sfail, GLenum dpfail, GLenum dppass);
void setStencilBackOps(GLenum sfail, GLenum dpfail, GLenum dppass);
void setClearDepth(float clearDepth);
void setClearStencil(GLint clearStencil); void setClearStencil(GLint clearStencil);
void setStencilMask(GLuint mask);
const FunctionsGL *mFunctions; const FunctionsGL *mFunctions;
...@@ -106,11 +115,27 @@ class StateManagerGL : angle::NonCopyable ...@@ -106,11 +115,27 @@ class StateManagerGL : angle::NonCopyable
float mSampleCoverageValue; float mSampleCoverageValue;
bool mSampleCoverageInvert; bool mSampleCoverageInvert;
float mClearDepth; bool mDepthTestEnabled;
GLenum mDepthFunc;
bool mDepthMask; bool mDepthMask;
bool mStencilTestEnabled;
GLenum mStencilFrontFunc;
GLint mStencilFrontRef;
GLuint mStencilFrontValueMask;
GLenum mStencilFrontStencilFailOp;
GLenum mStencilFrontStencilPassDepthFailOp;
GLenum mStencilFrontStencilPassDepthPassOp;
GLuint mStencilFrontWritemask;
GLenum mStencilBackFunc;
GLint mStencilBackRef;
GLuint mStencilBackValueMask;
GLenum mStencilBackStencilFailOp;
GLenum mStencilBackStencilPassDepthFailOp;
GLenum mStencilBackStencilPassDepthPassOp;
GLuint mStencilBackWritemask;
float mClearDepth;
GLint mClearStencil; GLint mClearStencil;
GLuint mStencilMask;
}; };
} }
......
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