Scissor test state is set as part of the Renderer::setScissor method.

TRAC #22206 Moved scissorTest out of RasterizerState. Fixes buffer-offscreen-test and buffer-preserve-test CTS regressions. Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1549 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 31240487
......@@ -50,7 +50,7 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n
mState.rasterizer.polygonOffsetFill = false;
mState.rasterizer.polygonOffsetFactor = 0.0f;
mState.rasterizer.polygonOffsetUnits = 0.0f;
mState.rasterizer.scissorTest = false;
mState.scissorTest = false;
mState.scissor.x = 0;
mState.scissor.y = 0;
mState.scissor.width = 0;
......@@ -523,12 +523,12 @@ void Context::setSampleCoverageParams(GLclampf value, bool invert)
void Context::setScissorTest(bool enabled)
{
mState.rasterizer.scissorTest = enabled;
mState.scissorTest = enabled;
}
bool Context::isScissorTestEnabled() const
{
return mState.rasterizer.scissorTest;
return mState.scissorTest;
}
void Context::setDither(bool enabled)
......@@ -1211,7 +1211,7 @@ bool Context::getBooleanv(GLenum pname, GLboolean *params)
case GL_POLYGON_OFFSET_FILL: *params = mState.rasterizer.polygonOffsetFill; break;
case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.blend.sampleAlphaToCoverage; break;
case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; break;
case GL_SCISSOR_TEST: *params = mState.rasterizer.scissorTest; break;
case GL_SCISSOR_TEST: *params = mState.scissorTest; break;
case GL_STENCIL_TEST: *params = mState.depthStencil.stencilTest; break;
case GL_DEPTH_TEST: *params = mState.depthStencil.depthTest; break;
case GL_BLEND: *params = mState.blend.blend; break;
......@@ -1723,7 +1723,7 @@ bool Context::applyRenderTarget(bool ignoreViewport)
}
mDxUniformsDirty = false;
mRenderer->setScissorRectangle(mState.scissor);
mRenderer->setScissorRectangle(mState.scissor, mState.scissorTest);
return true;
}
......@@ -2738,7 +2738,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
Rectangle sourceScissoredRect = sourceRect;
Rectangle destScissoredRect = destRect;
if (mState.rasterizer.scissorTest)
if (mState.scissorTest)
{
// Only write to parts of the destination framebuffer which pass the scissor test.
if (destRect.x < mState.scissor.x)
......
......@@ -145,6 +145,7 @@ struct State
int stencilClearValue;
RasterizerState rasterizer;
bool scissorTest;
Rectangle scissor;
BlendState blend;
......
......@@ -55,8 +55,6 @@ struct RasterizerState
bool polygonOffsetFill;
GLfloat polygonOffsetFactor;
GLfloat polygonOffsetUnits;
bool scissorTest;
};
struct BlendState
......
......@@ -168,7 +168,7 @@ bool RenderStateCache::compareRasterizerStates(const RasterizerStateKey &a, cons
}
ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState,
unsigned int depthSize)
bool scissorEnabled, unsigned int depthSize)
{
if (!mDevice)
{
......@@ -178,6 +178,7 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer
RasterizerStateKey key;
key.rasterizerState = rasterState;
key.scissorEnabled = scissorEnabled;
key.depthSize = depthSize;
RasterizerStateMap::iterator i = mRasterizerStateCache.find(key);
......@@ -215,7 +216,7 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer
rasterDesc.DepthBiasClamp = 0.0f; // MSDN documentation of DepthBiasClamp implies a value of zero will preform no clamping, must be tested though.
rasterDesc.SlopeScaledDepthBias = rasterState.polygonOffsetUnits;
rasterDesc.DepthClipEnable = TRUE;
rasterDesc.ScissorEnable = rasterState.scissorTest ? TRUE : FALSE;
rasterDesc.ScissorEnable = scissorEnabled ? TRUE : FALSE;
rasterDesc.MultisampleEnable = TRUE;
rasterDesc.AntialiasedLineEnable = FALSE;
......
......@@ -31,7 +31,7 @@ class RenderStateCache
// Increments refcount on the returned blend state, Release() must be called.
ID3D11BlendState *getBlendState(const gl::BlendState &blendState);
ID3D11RasterizerState *getRasterizerState(const gl::RasterizerState &rasterState,
unsigned int depthSize);
bool scissorEnabled, unsigned int depthSize);
ID3D11DepthStencilState* getDepthStencilState(const gl::DepthStencilState &dsState);
private:
......@@ -54,6 +54,7 @@ class RenderStateCache
struct RasterizerStateKey
{
gl::RasterizerState rasterizerState;
bool scissorEnabled;
unsigned int depthSize;
};
static std::size_t hashRasterizerState(const RasterizerStateKey &rasterState);
......
......@@ -89,7 +89,7 @@ class Renderer
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW) = 0;
virtual void setScissorRectangle(const gl::Rectangle &scissor) = 0;
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
......
......@@ -269,10 +269,11 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
{
if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0)
{
ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mCurDepthSize);
ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled,
mCurDepthSize);
if (!dxRasterState)
{
ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the "
ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the default"
"rasterizer state.");
}
......@@ -355,19 +356,29 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS
mForceSetDepthStencilState = false;
}
void Renderer11::setScissorRectangle(const gl::Rectangle &scissor)
void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
{
if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0)
if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 ||
enabled != mScissorEnabled)
{
D3D11_RECT rect;
rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width));
rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height));
rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width));
rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height));
if (enabled)
{
D3D11_RECT rect;
rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width));
rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height));
rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width));
rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height));
mDeviceContext->RSSetScissorRects(1, &rect);
}
mDeviceContext->RSSetScissorRects(1, &rect);
if (enabled != mScissorEnabled)
{
mForceSetRasterState = true;
}
mCurScissor = scissor;
mScissorEnabled = enabled;
}
mForceSetScissor = false;
......@@ -720,9 +731,9 @@ void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *
return;
}
if (mCurScissor.x > 0 || mCurScissor.y > 0 ||
mCurScissor.x + mCurScissor.width < renderTarget->getWidth() ||
mCurScissor.y + mCurScissor.height < renderTarget->getHeight())
if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 ||
mCurScissor.x + mCurScissor.width < renderTarget->getWidth() ||
mCurScissor.y + mCurScissor.height < renderTarget->getHeight()))
{
// TODO: clearing of subregion of render target
UNIMPLEMENTED();
......@@ -769,9 +780,9 @@ void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *
return;
}
if (mCurScissor.x > 0 || mCurScissor.y > 0 ||
mCurScissor.x + mCurScissor.width < renderTarget->getWidth() ||
mCurScissor.y + mCurScissor.height < renderTarget->getHeight())
if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 ||
mCurScissor.x + mCurScissor.width < renderTarget->getWidth() ||
mCurScissor.y + mCurScissor.height < renderTarget->getHeight()))
{
// TODO: clearing of subregion of depth stencil view
UNIMPLEMENTED();
......
......@@ -55,7 +55,7 @@ class Renderer11 : public Renderer
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor);
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms);
......@@ -179,6 +179,7 @@ class Renderer11 : public Renderer
// Currently applied scissor rectangle
bool mForceSetScissor;
bool mScissorEnabled;
gl::Rectangle mCurScissor;
// Currently applied viewport
......
......@@ -644,8 +644,6 @@ void Renderer9::setRasterizerState(const gl::RasterizerState &rasterState)
mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
}
mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, rasterState.scissorTest ? TRUE : FALSE);
if (rasterState.polygonOffsetFill)
{
if (mCurDepthSize > 0)
......@@ -860,19 +858,27 @@ void Renderer9::setDepthStencilState(const gl::DepthStencilState &depthStencilSt
mForceSetDepthStencilState = false;
}
void Renderer9::setScissorRectangle(const gl::Rectangle &scissor)
void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
{
bool scissorChanged = mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0;
bool scissorChanged = mForceSetScissor ||
memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 ||
enabled != mScissorEnabled;
if (scissorChanged)
{
RECT rect;
rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width));
rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height));
rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width));
rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height));
mDevice->SetScissorRect(&rect);
if (enabled)
{
RECT rect;
rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width));
rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height));
rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width));
rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height));
mDevice->SetScissorRect(&rect);
}
mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, enabled ? TRUE : FALSE);
mScissorEnabled = enabled;
mCurScissor = scissor;
}
......
......@@ -84,7 +84,7 @@ class Renderer9 : public Renderer
virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor);
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms);
......@@ -241,6 +241,7 @@ class Renderer9 : public Renderer
bool mForceSetScissor;
gl::Rectangle mCurScissor;
bool mScissorEnabled;
unsigned int mCurRenderTargetWidth;
unsigned int mCurRenderTargetHeight;
......
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