Refactored Renderer::setDepthStencilState to no longer require the stencil size parameter.

TRAC #22145 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1517 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 237bc7e5
...@@ -1812,9 +1812,8 @@ void Context::applyState(GLenum drawMode) ...@@ -1812,9 +1812,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;
mRenderer->setDepthStencilState(mState.depthStencil, mState.stencilRef, mState.stencilBackRef, mRenderer->setDepthStencilState(mState.depthStencil, mState.stencilRef, mState.stencilBackRef,
mState.rasterizer.frontFace == GL_CCW, stencilSize); mState.rasterizer.frontFace == GL_CCW);
} }
// Applies the shaders and shader constants to the Direct3D 9 device // Applies the shaders and shader constants to the Direct3D 9 device
......
...@@ -85,7 +85,7 @@ class Renderer ...@@ -85,7 +85,7 @@ class Renderer
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, int stencilRef, virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) = 0; int stencilBackRef, bool frontFaceCCW) = 0;
virtual void setScissorRectangle(const gl::Rectangle &scissor) = 0; virtual void setScissorRectangle(const gl::Rectangle &scissor) = 0;
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar,
......
...@@ -311,7 +311,7 @@ void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color ...@@ -311,7 +311,7 @@ void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color
} }
void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) int stencilBackRef, bool frontFaceCCW)
{ {
if (mForceSetDepthStencilState || if (mForceSetDepthStencilState ||
memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 ||
......
...@@ -52,7 +52,7 @@ class Renderer11 : public Renderer ...@@ -52,7 +52,7 @@ class Renderer11 : public Renderer
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, int stencilRef, virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize); int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor); virtual void setScissorRectangle(const gl::Rectangle &scissor);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar,
......
...@@ -798,14 +798,13 @@ void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::Color ...@@ -798,14 +798,13 @@ void Renderer9::setBlendState(const gl::BlendState &blendState, const gl::Color
} }
void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) int stencilBackRef, bool frontFaceCCW)
{ {
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 || bool stencilRefChanged = mForceSetDepthStencilState || stencilRef != mCurStencilRef ||
stencilBackRef != mCurStencilBackRef; stencilBackRef != mCurStencilBackRef;
bool frontFaceCCWChanged = mForceSetDepthStencilState || frontFaceCCW != mCurFrontFaceCCW; bool frontFaceCCWChanged = mForceSetDepthStencilState || frontFaceCCW != mCurFrontFaceCCW;
bool stencilSizeChanged = mForceSetDepthStencilState || stencilSize != mCurStencilSize;
if (depthStencilStateChanged) if (depthStencilStateChanged)
{ {
...@@ -822,9 +821,9 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -822,9 +821,9 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
mCurDepthStencilState = depthStencilState; mCurDepthStencilState = depthStencilState;
} }
if (depthStencilStateChanged || stencilRefChanged || frontFaceCCWChanged || stencilSizeChanged) if (depthStencilStateChanged || stencilRefChanged || frontFaceCCWChanged)
{ {
if (depthStencilState.stencilTest && stencilSize > 0) if (depthStencilState.stencilTest && mCurStencilSize > 0)
{ {
mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE); mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
...@@ -842,7 +841,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -842,7 +841,7 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
} }
// get the maximum size of the stencil ref // get the maximum size of the stencil ref
GLuint maxStencil = (1 << stencilSize) - 1; unsigned int maxStencil = (1 << mCurStencilSize) - 1;
mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mDevice->SetRenderState(frontFaceCCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK,
depthStencilState.stencilWritemask); depthStencilState.stencilWritemask);
...@@ -888,7 +887,6 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt ...@@ -888,7 +887,6 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
mCurStencilRef = stencilRef; mCurStencilRef = stencilRef;
mCurStencilBackRef = stencilBackRef; mCurStencilBackRef = stencilBackRef;
mCurFrontFaceCCW = frontFaceCCW; mCurFrontFaceCCW = frontFaceCCW;
mCurStencilSize = stencilSize;
} }
mForceSetDepthStencilState = false; mForceSetDepthStencilState = false;
...@@ -1083,6 +1081,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1083,6 +1081,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
!mDepthStencilInitialized) !mDepthStencilInitialized)
{ {
unsigned int depthSize = 0; unsigned int depthSize = 0;
unsigned int stencilSize = 0;
// Apply the depth stencil on the device // Apply the depth stencil on the device
if (depthStencil) if (depthStencil)
...@@ -1105,6 +1104,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1105,6 +1104,7 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
depthStencilSurface->Release(); depthStencilSurface->Release();
depthSize = depthStencil->getDepthSize(); depthSize = depthStencil->getDepthSize();
stencilSize = depthStencil->getStencilSize();
} }
else else
{ {
...@@ -1117,6 +1117,12 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1117,6 +1117,12 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
mForceSetRasterState = true; mForceSetRasterState = true;
} }
if (!mDepthStencilInitialized || stencilSize != mCurStencilSize)
{
mCurStencilSize = stencilSize;
mForceSetDepthStencilState = true;
}
mAppliedDepthbufferSerial = depthbufferSerial; mAppliedDepthbufferSerial = depthbufferSerial;
mAppliedStencilbufferSerial = stencilbufferSerial; mAppliedStencilbufferSerial = stencilbufferSerial;
mDepthStencilInitialized = true; mDepthStencilInitialized = true;
......
...@@ -87,7 +87,7 @@ class Renderer9 : public Renderer ...@@ -87,7 +87,7 @@ class Renderer9 : public Renderer
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, int stencilRef, virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize); int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor); virtual void setScissorRectangle(const gl::Rectangle &scissor);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar,
...@@ -246,6 +246,7 @@ class Renderer9 : public Renderer ...@@ -246,6 +246,7 @@ class Renderer9 : public Renderer
bool mDepthStencilInitialized; bool mDepthStencilInitialized;
bool mRenderTargetDescInitialized; bool mRenderTargetDescInitialized;
rx::RenderTarget::Desc mRenderTargetDesc; rx::RenderTarget::Desc mRenderTargetDesc;
unsigned int mCurStencilSize;
unsigned int mCurDepthSize; unsigned int mCurDepthSize;
IDirect3DStateBlock9 *mMaskedClearSavedState; IDirect3DStateBlock9 *mMaskedClearSavedState;
...@@ -256,7 +257,6 @@ class Renderer9 : public Renderer ...@@ -256,7 +257,6 @@ class Renderer9 : public Renderer
int mCurStencilRef; int mCurStencilRef;
int mCurStencilBackRef; int mCurStencilBackRef;
bool mCurFrontFaceCCW; bool mCurFrontFaceCCW;
unsigned int mCurStencilSize;
bool mForceSetRasterState; bool mForceSetRasterState;
gl::RasterizerState mCurRasterState; gl::RasterizerState mCurRasterState;
......
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