Removed the dirty state flags from Context.

TRAC #22041 Renderers will now be minimizing state changes themselves. Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1424 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d084c620
...@@ -357,17 +357,6 @@ void Context::markAllStateDirty() ...@@ -357,17 +357,6 @@ void Context::markAllStateDirty()
mVertexDeclarationCache.markStateDirty(); mVertexDeclarationCache.markStateDirty();
mClearStateDirty = true;
mCullStateDirty = true;
mDepthStateDirty = true;
mMaskStateDirty = true;
mBlendStateDirty = true;
mStencilStateDirty = true;
mPolygonOffsetStateDirty = true;
mScissorStateDirty = true;
mSampleStateDirty = true;
mDitherStateDirty = true;
mFrontFaceDirty = true;
mDxUniformsDirty = true; mDxUniformsDirty = true;
} }
...@@ -409,11 +398,7 @@ void Context::setClearStencil(int stencil) ...@@ -409,11 +398,7 @@ void Context::setClearStencil(int stencil)
void Context::setCullFace(bool enabled) void Context::setCullFace(bool enabled)
{ {
if (mState.rasterizer.cullFace != enabled)
{
mState.rasterizer.cullFace = enabled; mState.rasterizer.cullFace = enabled;
mCullStateDirty = true;
}
} }
bool Context::isCullFaceEnabled() const bool Context::isCullFaceEnabled() const
...@@ -423,29 +408,17 @@ bool Context::isCullFaceEnabled() const ...@@ -423,29 +408,17 @@ bool Context::isCullFaceEnabled() const
void Context::setCullMode(GLenum mode) void Context::setCullMode(GLenum mode)
{ {
if (mState.rasterizer.cullMode != mode)
{
mState.rasterizer.cullMode = mode; mState.rasterizer.cullMode = mode;
mCullStateDirty = true;
}
} }
void Context::setFrontFace(GLenum front) void Context::setFrontFace(GLenum front)
{ {
if (mState.rasterizer.frontFace != front)
{
mState.rasterizer.frontFace = front; mState.rasterizer.frontFace = front;
mFrontFaceDirty = true;
}
} }
void Context::setDepthTest(bool enabled) void Context::setDepthTest(bool enabled)
{ {
if (mState.depthStencil.depthTest != enabled)
{
mState.depthStencil.depthTest = enabled; mState.depthStencil.depthTest = enabled;
mDepthStateDirty = true;
}
} }
bool Context::isDepthTestEnabled() const bool Context::isDepthTestEnabled() const
...@@ -455,11 +428,7 @@ bool Context::isDepthTestEnabled() const ...@@ -455,11 +428,7 @@ bool Context::isDepthTestEnabled() const
void Context::setDepthFunc(GLenum depthFunc) void Context::setDepthFunc(GLenum depthFunc)
{ {
if (mState.depthStencil.depthFunc != depthFunc)
{
mState.depthStencil.depthFunc = depthFunc; mState.depthStencil.depthFunc = depthFunc;
mDepthStateDirty = true;
}
} }
void Context::setDepthRange(float zNear, float zFar) void Context::setDepthRange(float zNear, float zFar)
...@@ -470,11 +439,7 @@ void Context::setDepthRange(float zNear, float zFar) ...@@ -470,11 +439,7 @@ void Context::setDepthRange(float zNear, float zFar)
void Context::setBlend(bool enabled) void Context::setBlend(bool enabled)
{ {
if (mState.blend.blend != enabled)
{
mState.blend.blend = enabled; mState.blend.blend = enabled;
mBlendStateDirty = true;
}
} }
bool Context::isBlendEnabled() const bool Context::isBlendEnabled() const
...@@ -484,52 +449,29 @@ bool Context::isBlendEnabled() const ...@@ -484,52 +449,29 @@ bool Context::isBlendEnabled() const
void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
{ {
if (mState.blend.sourceBlendRGB != sourceRGB ||
mState.blend.sourceBlendAlpha != sourceAlpha ||
mState.blend.destBlendRGB != destRGB ||
mState.blend.destBlendAlpha != destAlpha)
{
mState.blend.sourceBlendRGB = sourceRGB; mState.blend.sourceBlendRGB = sourceRGB;
mState.blend.destBlendRGB = destRGB; mState.blend.destBlendRGB = destRGB;
mState.blend.sourceBlendAlpha = sourceAlpha; mState.blend.sourceBlendAlpha = sourceAlpha;
mState.blend.destBlendAlpha = destAlpha; mState.blend.destBlendAlpha = destAlpha;
mBlendStateDirty = true;
}
} }
void Context::setBlendColor(float red, float green, float blue, float alpha) void Context::setBlendColor(float red, float green, float blue, float alpha)
{ {
if (mState.blendColor.red != red ||
mState.blendColor.green != green ||
mState.blendColor.blue != blue ||
mState.blendColor.alpha != alpha)
{
mState.blendColor.red = red; mState.blendColor.red = red;
mState.blendColor.green = green; mState.blendColor.green = green;
mState.blendColor.blue = blue; mState.blendColor.blue = blue;
mState.blendColor.alpha = alpha; mState.blendColor.alpha = alpha;
mBlendStateDirty = true;
}
} }
void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
{ {
if (mState.blend.blendEquationRGB != rgbEquation ||
mState.blend.blendEquationAlpha != alphaEquation)
{
mState.blend.blendEquationRGB = rgbEquation; mState.blend.blendEquationRGB = rgbEquation;
mState.blend.blendEquationAlpha = alphaEquation; mState.blend.blendEquationAlpha = alphaEquation;
mBlendStateDirty = true;
}
} }
void Context::setStencilTest(bool enabled) void Context::setStencilTest(bool enabled)
{ {
if (mState.depthStencil.stencilTest != enabled)
{
mState.depthStencil.stencilTest = enabled; mState.depthStencil.stencilTest = enabled;
mStencilStateDirty = true;
}
} }
bool Context::isStencilTestEnabled() const bool Context::isStencilTestEnabled() const
...@@ -539,107 +481,61 @@ bool Context::isStencilTestEnabled() const ...@@ -539,107 +481,61 @@ bool Context::isStencilTestEnabled() const
void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
{ {
if (mState.depthStencil.stencilFunc != stencilFunc ||
mState.depthStencil.stencilRef != stencilRef ||
mState.depthStencil.stencilMask != stencilMask)
{
mState.depthStencil.stencilFunc = stencilFunc; mState.depthStencil.stencilFunc = stencilFunc;
mState.depthStencil.stencilRef = (stencilRef > 0) ? stencilRef : 0; mState.depthStencil.stencilRef = (stencilRef > 0) ? stencilRef : 0;
mState.depthStencil.stencilMask = stencilMask; mState.depthStencil.stencilMask = stencilMask;
mStencilStateDirty = true;
}
} }
void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
{ {
if (mState.depthStencil.stencilBackFunc != stencilBackFunc ||
mState.depthStencil.stencilBackRef != stencilBackRef ||
mState.depthStencil.stencilBackMask != stencilBackMask)
{
mState.depthStencil.stencilBackFunc = stencilBackFunc; mState.depthStencil.stencilBackFunc = stencilBackFunc;
mState.depthStencil.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; mState.depthStencil.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
mState.depthStencil.stencilBackMask = stencilBackMask; mState.depthStencil.stencilBackMask = stencilBackMask;
mStencilStateDirty = true;
}
} }
void Context::setStencilWritemask(GLuint stencilWritemask) void Context::setStencilWritemask(GLuint stencilWritemask)
{ {
if (mState.depthStencil.stencilWritemask != stencilWritemask)
{
mState.depthStencil.stencilWritemask = stencilWritemask; mState.depthStencil.stencilWritemask = stencilWritemask;
mStencilStateDirty = true;
}
} }
void Context::setStencilBackWritemask(GLuint stencilBackWritemask) void Context::setStencilBackWritemask(GLuint stencilBackWritemask)
{ {
if (mState.depthStencil.stencilBackWritemask != stencilBackWritemask)
{
mState.depthStencil.stencilBackWritemask = stencilBackWritemask; mState.depthStencil.stencilBackWritemask = stencilBackWritemask;
mStencilStateDirty = true;
}
} }
void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
{ {
if (mState.depthStencil.stencilFail != stencilFail ||
mState.depthStencil.stencilPassDepthFail != stencilPassDepthFail ||
mState.depthStencil.stencilPassDepthPass != stencilPassDepthPass)
{
mState.depthStencil.stencilFail = stencilFail; mState.depthStencil.stencilFail = stencilFail;
mState.depthStencil.stencilPassDepthFail = stencilPassDepthFail; mState.depthStencil.stencilPassDepthFail = stencilPassDepthFail;
mState.depthStencil.stencilPassDepthPass = stencilPassDepthPass; mState.depthStencil.stencilPassDepthPass = stencilPassDepthPass;
mStencilStateDirty = true;
}
} }
void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
{ {
if (mState.depthStencil.stencilBackFail != stencilBackFail ||
mState.depthStencil.stencilBackPassDepthFail != stencilBackPassDepthFail ||
mState.depthStencil.stencilBackPassDepthPass != stencilBackPassDepthPass)
{
mState.depthStencil.stencilBackFail = stencilBackFail; mState.depthStencil.stencilBackFail = stencilBackFail;
mState.depthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; mState.depthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail;
mState.depthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; mState.depthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass;
mStencilStateDirty = true;
}
} }
void Context::setPolygonOffsetFill(bool enabled) void Context::setPolygonOffsetFill(bool enabled)
{ {
if (mState.rasterizer.polygonOffsetFill != enabled)
{
mState.rasterizer.polygonOffsetFill = enabled; mState.rasterizer.polygonOffsetFill = enabled;
mPolygonOffsetStateDirty = true;
}
} }
bool Context::isPolygonOffsetFillEnabled() const bool Context::isPolygonOffsetFillEnabled() const
{ {
return mState.rasterizer.polygonOffsetFill; return mState.rasterizer.polygonOffsetFill;
} }
void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units) void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units)
{ {
if (mState.rasterizer.polygonOffsetFactor != factor ||
mState.rasterizer.polygonOffsetUnits != units)
{
mState.rasterizer.polygonOffsetFactor = factor; mState.rasterizer.polygonOffsetFactor = factor;
mState.rasterizer.polygonOffsetUnits = units; mState.rasterizer.polygonOffsetUnits = units;
mPolygonOffsetStateDirty = true;
}
} }
void Context::setSampleAlphaToCoverage(bool enabled) void Context::setSampleAlphaToCoverage(bool enabled)
{ {
if (mState.blend.sampleAlphaToCoverage != enabled)
{
mState.blend.sampleAlphaToCoverage = enabled; mState.blend.sampleAlphaToCoverage = enabled;
mSampleStateDirty = true;
}
} }
bool Context::isSampleAlphaToCoverageEnabled() const bool Context::isSampleAlphaToCoverageEnabled() const
...@@ -649,11 +545,7 @@ bool Context::isSampleAlphaToCoverageEnabled() const ...@@ -649,11 +545,7 @@ bool Context::isSampleAlphaToCoverageEnabled() const
void Context::setSampleCoverage(bool enabled) void Context::setSampleCoverage(bool enabled)
{ {
if (mState.sampleCoverage != enabled)
{
mState.sampleCoverage = enabled; mState.sampleCoverage = enabled;
mSampleStateDirty = true;
}
} }
bool Context::isSampleCoverageEnabled() const bool Context::isSampleCoverageEnabled() const
...@@ -663,22 +555,13 @@ bool Context::isSampleCoverageEnabled() const ...@@ -663,22 +555,13 @@ bool Context::isSampleCoverageEnabled() const
void Context::setSampleCoverageParams(GLclampf value, bool invert) void Context::setSampleCoverageParams(GLclampf value, bool invert)
{ {
if (mState.sampleCoverageValue != value ||
mState.sampleCoverageInvert != invert)
{
mState.sampleCoverageValue = value; mState.sampleCoverageValue = value;
mState.sampleCoverageInvert = invert; mState.sampleCoverageInvert = invert;
mSampleStateDirty = true;
}
} }
void Context::setScissorTest(bool enabled) void Context::setScissorTest(bool enabled)
{ {
if (mState.rasterizer.scissorTest != enabled)
{
mState.rasterizer.scissorTest = enabled; mState.rasterizer.scissorTest = enabled;
mScissorStateDirty = true;
}
} }
bool Context::isScissorTestEnabled() const bool Context::isScissorTestEnabled() const
...@@ -688,11 +571,7 @@ bool Context::isScissorTestEnabled() const ...@@ -688,11 +571,7 @@ bool Context::isScissorTestEnabled() const
void Context::setDither(bool enabled) void Context::setDither(bool enabled)
{ {
if (mState.blend.dither != enabled)
{
mState.blend.dither = enabled; mState.blend.dither = enabled;
mDitherStateDirty = true;
}
} }
bool Context::isDitherEnabled() const bool Context::isDitherEnabled() const
...@@ -728,37 +607,23 @@ void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) ...@@ -728,37 +607,23 @@ void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
{ {
if (mState.scissor.x != x || mState.scissor.y != y ||
mState.scissor.width != width || mState.scissor.height != height)
{
mState.scissor.x = x; mState.scissor.x = x;
mState.scissor.y = y; mState.scissor.y = y;
mState.scissor.width = width; mState.scissor.width = width;
mState.scissor.height = height; mState.scissor.height = height;
mScissorStateDirty = true;
}
} }
void Context::setColorMask(bool red, bool green, bool blue, bool alpha) void Context::setColorMask(bool red, bool green, bool blue, bool alpha)
{ {
if (mState.blend.colorMaskRed != red || mState.blend.colorMaskGreen != green ||
mState.blend.colorMaskBlue != blue || mState.blend.colorMaskAlpha != alpha)
{
mState.blend.colorMaskRed = red; mState.blend.colorMaskRed = red;
mState.blend.colorMaskGreen = green; mState.blend.colorMaskGreen = green;
mState.blend.colorMaskBlue = blue; mState.blend.colorMaskBlue = blue;
mState.blend.colorMaskAlpha = alpha; mState.blend.colorMaskAlpha = alpha;
mMaskStateDirty = true;
}
} }
void Context::setDepthMask(bool mask) void Context::setDepthMask(bool mask)
{ {
if (mState.depthStencil.depthMask != mask)
{
mState.depthStencil.depthMask = mask; mState.depthStencil.depthMask = mask;
mMaskStateDirty = true;
}
} }
void Context::setActiveSampler(unsigned int active) void Context::setActiveSampler(unsigned int active)
...@@ -1915,7 +1780,6 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1915,7 +1780,6 @@ bool Context::applyRenderTarget(bool ignoreViewport)
} }
mDevice->SetRenderTarget(0, renderTarget); mDevice->SetRenderTarget(0, renderTarget);
mAppliedRenderTargetSerial = renderTargetSerial; mAppliedRenderTargetSerial = renderTargetSerial;
mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets.
renderTargetChanged = true; renderTargetChanged = true;
renderTarget->Release(); renderTarget->Release();
} }
...@@ -2012,12 +1876,8 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -2012,12 +1876,8 @@ bool Context::applyRenderTarget(bool ignoreViewport)
mDxUniformsDirty = true; mDxUniformsDirty = true;
} }
if (mScissorStateDirty)
{
mRenderer->setScissorRectangle(mState.scissor, static_cast<int>(mRenderTargetDesc.Width), mRenderer->setScissorRectangle(mState.scissor, static_cast<int>(mRenderTargetDesc.Width),
static_cast<int>(mRenderTargetDesc.Height)); static_cast<int>(mRenderTargetDesc.Height));
mScissorStateDirty = false;
}
if (mState.currentProgram && mDxUniformsDirty) if (mState.currentProgram && mDxUniformsDirty)
{ {
...@@ -2064,19 +1924,11 @@ void Context::applyState(GLenum drawMode) ...@@ -2064,19 +1924,11 @@ void Context::applyState(GLenum drawMode)
GLint alwaysFront = !isTriangleMode(drawMode); GLint alwaysFront = !isTriangleMode(drawMode);
programBinary->setUniform1iv(pointsOrLines, 1, &alwaysFront); programBinary->setUniform1iv(pointsOrLines, 1, &alwaysFront);
if (mCullStateDirty || mFrontFaceDirty || mPolygonOffsetStateDirty)
{
const gl::Renderbuffer *depthbuffer = framebufferObject->getDepthbuffer(); const gl::Renderbuffer *depthbuffer = framebufferObject->getDepthbuffer();
unsigned int depthSize = depthbuffer ? depthbuffer->getDepthSize() : 0; unsigned int depthSize = depthbuffer ? depthbuffer->getDepthSize() : 0;
mRenderer->setRasterizerState(mState.rasterizer, depthSize); mRenderer->setRasterizerState(mState.rasterizer, depthSize);
mCullStateDirty = false;
mPolygonOffsetStateDirty = false;
}
if (mBlendStateDirty || mMaskStateDirty)
{
unsigned int mask = 0; unsigned int mask = 0;
if (mState.sampleCoverage) if (mState.sampleCoverage)
{ {
...@@ -2105,23 +1957,12 @@ void Context::applyState(GLenum drawMode) ...@@ -2105,23 +1957,12 @@ void Context::applyState(GLenum drawMode)
{ {
mask = 0xFFFFFFFF; mask = 0xFFFFFFFF;
} }
mRenderer->setBlendState(mState.blend, mState.blendColor, mask); mRenderer->setBlendState(mState.blend, mState.blendColor, mask);
mBlendStateDirty = false;
}
if (mStencilStateDirty || mFrontFaceDirty || mDepthStateDirty)
{
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.rasterizer.frontFace == GL_CCW, mState.rasterizer.frontFace == GL_CCW,
stencilSize); stencilSize);
mDepthStateDirty = false;
mStencilStateDirty = false;
mFrontFaceDirty = false;
}
} }
GLenum Context::applyVertexBuffer(GLint first, GLsizei count, GLsizei instances, GLsizei *repeatDraw) GLenum Context::applyVertexBuffer(GLint first, GLsizei count, GLsizei instances, GLsizei *repeatDraw)
...@@ -2761,7 +2602,6 @@ void Context::clear(GLbitfield mask) ...@@ -2761,7 +2602,6 @@ void Context::clear(GLbitfield mask)
mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE);
mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE);
mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
mStencilStateDirty = true;
} }
else else
{ {
......
...@@ -588,20 +588,6 @@ class Context ...@@ -588,20 +588,6 @@ class Context
bool mSupportsTextureFilterAnisotropy; bool mSupportsTextureFilterAnisotropy;
int mNumCompressedTextureFormats; int mNumCompressedTextureFormats;
// state caching flags
bool mClearStateDirty;
bool mCullStateDirty;
bool mDepthStateDirty;
bool mMaskStateDirty;
bool mPixelPackingStateDirty;
bool mBlendStateDirty;
bool mStencilStateDirty;
bool mPolygonOffsetStateDirty;
bool mScissorStateDirty;
bool mSampleStateDirty;
bool mFrontFaceDirty;
bool mDitherStateDirty;
IDirect3DStateBlock9 *mMaskedClearSavedState; IDirect3DStateBlock9 *mMaskedClearSavedState;
ResourceManager *mResourceManager; ResourceManager *mResourceManager;
......
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