Moved the stencilRef and stencilBackRef back to Context's state structure.

TRAC #22044 stencilRef and stencilBackRef are now set through the setDepthStencilState on Renderer. Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1438 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c820c123
...@@ -84,11 +84,9 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n ...@@ -84,11 +84,9 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n
mState.depthStencil.depthMask = true; mState.depthStencil.depthMask = true;
mState.depthStencil.stencilTest = false; mState.depthStencil.stencilTest = false;
mState.depthStencil.stencilFunc = GL_ALWAYS; mState.depthStencil.stencilFunc = GL_ALWAYS;
mState.depthStencil.stencilRef = 0;
mState.depthStencil.stencilMask = -1; mState.depthStencil.stencilMask = -1;
mState.depthStencil.stencilWritemask = -1; mState.depthStencil.stencilWritemask = -1;
mState.depthStencil.stencilBackFunc = GL_ALWAYS; mState.depthStencil.stencilBackFunc = GL_ALWAYS;
mState.depthStencil.stencilBackRef = 0;
mState.depthStencil.stencilBackMask = - 1; mState.depthStencil.stencilBackMask = - 1;
mState.depthStencil.stencilBackWritemask = -1; mState.depthStencil.stencilBackWritemask = -1;
mState.depthStencil.stencilFail = GL_KEEP; mState.depthStencil.stencilFail = GL_KEEP;
...@@ -98,6 +96,9 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n ...@@ -98,6 +96,9 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n
mState.depthStencil.stencilBackPassDepthFail = GL_KEEP; mState.depthStencil.stencilBackPassDepthFail = GL_KEEP;
mState.depthStencil.stencilBackPassDepthPass = GL_KEEP; mState.depthStencil.stencilBackPassDepthPass = GL_KEEP;
mState.stencilRef = 0;
mState.stencilBackRef = 0;
mState.sampleCoverage = false; mState.sampleCoverage = false;
mState.sampleCoverageValue = 1.0f; mState.sampleCoverageValue = 1.0f;
mState.sampleCoverageInvert = false; mState.sampleCoverageInvert = false;
...@@ -482,14 +483,14 @@ bool Context::isStencilTestEnabled() const ...@@ -482,14 +483,14 @@ bool Context::isStencilTestEnabled() const
void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
{ {
mState.depthStencil.stencilFunc = stencilFunc; mState.depthStencil.stencilFunc = stencilFunc;
mState.depthStencil.stencilRef = (stencilRef > 0) ? stencilRef : 0; mState.stencilRef = (stencilRef > 0) ? stencilRef : 0;
mState.depthStencil.stencilMask = stencilMask; mState.depthStencil.stencilMask = stencilMask;
} }
void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
{ {
mState.depthStencil.stencilBackFunc = stencilBackFunc; mState.depthStencil.stencilBackFunc = stencilBackFunc;
mState.depthStencil.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
mState.depthStencil.stencilBackMask = stencilBackMask; mState.depthStencil.stencilBackMask = stencilBackMask;
} }
...@@ -1346,10 +1347,10 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1346,10 +1347,10 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; break; case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; break;
case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); break; case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); break;
case GL_STENCIL_FUNC: *params = mState.depthStencil.stencilFunc; break; case GL_STENCIL_FUNC: *params = mState.depthStencil.stencilFunc; break;
case GL_STENCIL_REF: *params = mState.depthStencil.stencilRef; break; case GL_STENCIL_REF: *params = mState.stencilRef; break;
case GL_STENCIL_VALUE_MASK: *params = mState.depthStencil.stencilMask; break; case GL_STENCIL_VALUE_MASK: *params = mState.depthStencil.stencilMask; break;
case GL_STENCIL_BACK_FUNC: *params = mState.depthStencil.stencilBackFunc; break; case GL_STENCIL_BACK_FUNC: *params = mState.depthStencil.stencilBackFunc; break;
case GL_STENCIL_BACK_REF: *params = mState.depthStencil.stencilBackRef; break; case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; break;
case GL_STENCIL_BACK_VALUE_MASK: *params = mState.depthStencil.stencilBackMask; break; case GL_STENCIL_BACK_VALUE_MASK: *params = mState.depthStencil.stencilBackMask; break;
case GL_STENCIL_FAIL: *params = mState.depthStencil.stencilFail; break; case GL_STENCIL_FAIL: *params = mState.depthStencil.stencilFail; break;
case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilPassDepthFail; break; case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilPassDepthFail; break;
...@@ -1960,9 +1961,8 @@ void Context::applyState(GLenum drawMode) ...@@ -1960,9 +1961,8 @@ void Context::applyState(GLenum drawMode)
mRenderer->setBlendState(mState.blend, mState.blendColor, mask); mRenderer->setBlendState(mState.blend, mState.blendColor, mask);
unsigned int stencilSize = framebufferObject->hasStencil() ? framebufferObject->getStencilbuffer()->getStencilSize() : 0; unsigned int stencilSize = framebufferObject->hasStencil() ? framebufferObject->getStencilbuffer()->getStencilSize() : 0;
mRenderer->setDepthStencilState(mState.depthStencil, mRenderer->setDepthStencilState(mState.depthStencil, mState.stencilRef, mState.stencilBackRef,
mState.rasterizer.frontFace == GL_CCW, mState.rasterizer.frontFace == GL_CCW, stencilSize);
stencilSize);
} }
GLenum Context::applyVertexBuffer(GLint first, GLsizei count, GLsizei instances, GLsizei *repeatDraw) GLenum Context::applyVertexBuffer(GLint first, GLsizei count, GLsizei instances, GLsizei *repeatDraw)
......
...@@ -164,6 +164,8 @@ struct State ...@@ -164,6 +164,8 @@ struct State
bool sampleCoverageInvert; bool sampleCoverageInvert;
DepthStencilState depthStencil; DepthStencilState depthStencil;
GLint stencilRef;
GLint stencilBackRef;
GLfloat lineWidth; GLfloat lineWidth;
......
...@@ -87,14 +87,12 @@ struct DepthStencilState ...@@ -87,14 +87,12 @@ struct DepthStencilState
bool stencilTest; bool stencilTest;
GLenum stencilFunc; GLenum stencilFunc;
GLint stencilRef;
GLuint stencilMask; GLuint stencilMask;
GLenum stencilFail; GLenum stencilFail;
GLenum stencilPassDepthFail; GLenum stencilPassDepthFail;
GLenum stencilPassDepthPass; GLenum stencilPassDepthPass;
GLuint stencilWritemask; GLuint stencilWritemask;
GLenum stencilBackFunc; GLenum stencilBackFunc;
GLint stencilBackRef;
GLuint stencilBackMask; GLuint stencilBackMask;
GLenum stencilBackFail; GLenum stencilBackFail;
GLenum stencilBackPassDepthFail; GLenum stencilBackPassDepthFail;
......
...@@ -76,8 +76,8 @@ class Renderer ...@@ -76,8 +76,8 @@ class Renderer
virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize) = 0; virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize) = 0;
virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
unsigned int sampleMask) = 0; unsigned int sampleMask) = 0;
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, bool frontFaceCCW, virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
unsigned int stencilSize) = 0; int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) = 0;
virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth, virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
unsigned int renderTargetHeight) = 0; unsigned int renderTargetHeight) = 0;
......
...@@ -311,8 +311,8 @@ void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color ...@@ -311,8 +311,8 @@ void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color
mForceSetBlendState = false; mForceSetBlendState = false;
} }
void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, bool frontFaceCCW, void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
unsigned int stencilSize) int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize)
{ {
// TODO // TODO
UNIMPLEMENTED(); UNIMPLEMENTED();
......
...@@ -51,8 +51,8 @@ class Renderer11 : public Renderer ...@@ -51,8 +51,8 @@ class Renderer11 : public Renderer
virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize); virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize);
virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
unsigned int sampleMask); unsigned int sampleMask);
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, bool frontFaceCCW, virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
unsigned int stencilSize); int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize);
virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth, virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
unsigned int renderTargetHeight); unsigned int renderTargetHeight);
......
...@@ -745,11 +745,13 @@ void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::Color ...@@ -745,11 +745,13 @@ void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::Color
mForceSetBlendState = false; mForceSetBlendState = false;
} }
void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, bool frontFaceCCW, void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
unsigned int stencilSize) int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize)
{ {
bool depthStencilStateChanged = mForceSetDepthStencilState || bool depthStencilStateChanged = mForceSetDepthStencilState ||
memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0; memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0;
bool stencilRefChanged = mForceSetDepthStencilState || stencilRef != mCurStencilRef ||
stencilBackRef != mCurStencilBackRef;
bool frontFaceCCWChanged = mForceSetDepthStencilState || frontFaceCCW != mCurFrontFaceCCW; bool frontFaceCCWChanged = mForceSetDepthStencilState || frontFaceCCW != mCurFrontFaceCCW;
bool stencilSizeChanged = mForceSetDepthStencilState || stencilSize != mCurStencilSize; bool stencilSizeChanged = mForceSetDepthStencilState || stencilSize != mCurStencilSize;
...@@ -768,7 +770,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -768,7 +770,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
mCurDepthStencilState = depthStencilState; mCurDepthStencilState = depthStencilState;
} }
if (depthStencilStateChanged || frontFaceCCWChanged || stencilSizeChanged) if (depthStencilStateChanged || stencilRefChanged || frontFaceCCWChanged || stencilSizeChanged)
{ {
if (depthStencilState.stencilTest && stencilSize > 0) if (depthStencilState.stencilTest && stencilSize > 0)
{ {
...@@ -780,7 +782,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -780,7 +782,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK; const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK;
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK; const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK;
if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
depthStencilState.stencilRef != depthStencilState.stencilBackRef || stencilRef != stencilBackRef ||
depthStencilState.stencilMask != depthStencilState.stencilBackMask) depthStencilState.stencilMask != depthStencilState.stencilBackMask)
{ {
ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL."); ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL.");
...@@ -796,7 +798,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -796,7 +798,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
gl_d3d9::ConvertComparison(depthStencilState.stencilFunc)); gl_d3d9::ConvertComparison(depthStencilState.stencilFunc));
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF,
(depthStencilState.stencilRef < (GLint)maxStencil) ? depthStencilState.stencilRef : maxStencil); (stencilRef < (int)maxStencil) ? stencilRef : maxStencil);
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK,
depthStencilState.stencilMask); depthStencilState.stencilMask);
...@@ -813,7 +815,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -813,7 +815,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
gl_d3d9::ConvertComparison(depthStencilState.stencilBackFunc)); gl_d3d9::ConvertComparison(depthStencilState.stencilBackFunc));
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF,
(depthStencilState.stencilBackRef < (GLint)maxStencil) ? depthStencilState.stencilBackRef : maxStencil); (stencilBackRef < (int)maxStencil) ? stencilBackRef : maxStencil);
mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mDevice->SetRenderState(!frontFaceCCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK,
depthStencilState.stencilBackMask); depthStencilState.stencilBackMask);
...@@ -831,6 +833,8 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -831,6 +833,8 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
mDevice->SetRenderState(D3DRS_ZWRITEENABLE, depthStencilState.depthMask ? TRUE : FALSE); mDevice->SetRenderState(D3DRS_ZWRITEENABLE, depthStencilState.depthMask ? TRUE : FALSE);
mCurStencilRef = stencilRef;
mCurStencilBackRef = stencilBackRef;
mCurFrontFaceCCW = frontFaceCCW; mCurFrontFaceCCW = frontFaceCCW;
mCurStencilSize = stencilSize; mCurStencilSize = stencilSize;
} }
......
...@@ -74,8 +74,8 @@ class Renderer9 : public Renderer ...@@ -74,8 +74,8 @@ class Renderer9 : public Renderer
virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize); virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize);
virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
unsigned int sampleMask); unsigned int sampleMask);
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, bool frontFaceCCW, virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
unsigned int stencilSize); int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize);
virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth, virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
unsigned int renderTargetHeight); unsigned int renderTargetHeight);
...@@ -183,6 +183,8 @@ class Renderer9 : public Renderer ...@@ -183,6 +183,8 @@ class Renderer9 : public Renderer
// previously set render states // previously set render states
bool mForceSetDepthStencilState; bool mForceSetDepthStencilState;
gl::DepthStencilState mCurDepthStencilState; gl::DepthStencilState mCurDepthStencilState;
int mCurStencilRef;
int mCurStencilBackRef;
bool mCurFrontFaceCCW; bool mCurFrontFaceCCW;
unsigned int mCurStencilSize; unsigned int mCurStencilSize;
......
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