Context now uses the new structures storing state.

TRAC #22041 Context now uses the new structures for holding rasterizer, blend, depth stencil and scissor state andcalls the new set methods on the Renderer interface to set state. Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1422 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 493d4f87
...@@ -52,46 +52,55 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n ...@@ -52,46 +52,55 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n
mState.depthClearValue = 1.0f; mState.depthClearValue = 1.0f;
mState.stencilClearValue = 0; mState.stencilClearValue = 0;
mState.cullFace = false; mState.rasterizer.cullFace = false;
mState.cullMode = GL_BACK; mState.rasterizer.cullMode = GL_BACK;
mState.frontFace = GL_CCW; mState.rasterizer.frontFace = GL_CCW;
mState.depthTest = false; mState.rasterizer.polygonOffsetFill = false;
mState.depthFunc = GL_LESS; mState.rasterizer.polygonOffsetFactor = 0.0f;
mState.blend = false; mState.rasterizer.polygonOffsetUnits = 0.0f;
mState.sourceBlendRGB = GL_ONE; mState.rasterizer.scissorTest = false;
mState.sourceBlendAlpha = GL_ONE; mState.scissor.x = 0;
mState.destBlendRGB = GL_ZERO; mState.scissor.y = 0;
mState.destBlendAlpha = GL_ZERO; mState.scissor.width = 0;
mState.blendEquationRGB = GL_FUNC_ADD; mState.scissor.height = 0;
mState.blendEquationAlpha = GL_FUNC_ADD;
mState.blend.blend = false;
mState.blend.sourceBlendRGB = GL_ONE;
mState.blend.sourceBlendAlpha = GL_ONE;
mState.blend.destBlendRGB = GL_ZERO;
mState.blend.destBlendAlpha = GL_ZERO;
mState.blend.blendEquationRGB = GL_FUNC_ADD;
mState.blend.blendEquationAlpha = GL_FUNC_ADD;
mState.blend.sampleAlphaToCoverage = false;
mState.blend.dither = true;
mState.blendColor.red = 0; mState.blendColor.red = 0;
mState.blendColor.green = 0; mState.blendColor.green = 0;
mState.blendColor.blue = 0; mState.blendColor.blue = 0;
mState.blendColor.alpha = 0; mState.blendColor.alpha = 0;
mState.stencilTest = false;
mState.stencilFunc = GL_ALWAYS; mState.depthStencil.depthTest = false;
mState.stencilRef = 0; mState.depthStencil.depthFunc = GL_LESS;
mState.stencilMask = -1; mState.depthStencil.depthMask = true;
mState.stencilWritemask = -1; mState.depthStencil.stencilTest = false;
mState.stencilBackFunc = GL_ALWAYS; mState.depthStencil.stencilFunc = GL_ALWAYS;
mState.stencilBackRef = 0; mState.depthStencil.stencilRef = 0;
mState.stencilBackMask = - 1; mState.depthStencil.stencilMask = -1;
mState.stencilBackWritemask = -1; mState.depthStencil.stencilWritemask = -1;
mState.stencilFail = GL_KEEP; mState.depthStencil.stencilBackFunc = GL_ALWAYS;
mState.stencilPassDepthFail = GL_KEEP; mState.depthStencil.stencilBackRef = 0;
mState.stencilPassDepthPass = GL_KEEP; mState.depthStencil.stencilBackMask = - 1;
mState.stencilBackFail = GL_KEEP; mState.depthStencil.stencilBackWritemask = -1;
mState.stencilBackPassDepthFail = GL_KEEP; mState.depthStencil.stencilFail = GL_KEEP;
mState.stencilBackPassDepthPass = GL_KEEP; mState.depthStencil.stencilPassDepthFail = GL_KEEP;
mState.polygonOffsetFill = false; mState.depthStencil.stencilPassDepthPass = GL_KEEP;
mState.polygonOffsetFactor = 0.0f; mState.depthStencil.stencilBackFail = GL_KEEP;
mState.polygonOffsetUnits = 0.0f; mState.depthStencil.stencilBackPassDepthFail = GL_KEEP;
mState.sampleAlphaToCoverage = false; mState.depthStencil.stencilBackPassDepthPass = GL_KEEP;
mState.sampleCoverage = false; mState.sampleCoverage = false;
mState.sampleCoverageValue = 1.0f; mState.sampleCoverageValue = 1.0f;
mState.sampleCoverageInvert = false; mState.sampleCoverageInvert = false;
mState.scissorTest = false;
mState.dither = true;
mState.generateMipmapHint = GL_DONT_CARE; mState.generateMipmapHint = GL_DONT_CARE;
mState.fragmentShaderDerivativeHint = GL_DONT_CARE; mState.fragmentShaderDerivativeHint = GL_DONT_CARE;
...@@ -104,16 +113,10 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n ...@@ -104,16 +113,10 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n
mState.zNear = 0.0f; mState.zNear = 0.0f;
mState.zFar = 1.0f; mState.zFar = 1.0f;
mState.scissorX = 0; mState.blend.colorMaskRed = true;
mState.scissorY = 0; mState.blend.colorMaskGreen = true;
mState.scissorWidth = 0; mState.blend.colorMaskBlue = true;
mState.scissorHeight = 0; mState.blend.colorMaskAlpha = true;
mState.colorMaskRed = true;
mState.colorMaskGreen = true;
mState.colorMaskBlue = true;
mState.colorMaskAlpha = true;
mState.depthMask = true;
if (shareContext != NULL) if (shareContext != NULL)
{ {
...@@ -306,10 +309,10 @@ void Context::makeCurrent(egl::Surface *surface) ...@@ -306,10 +309,10 @@ void Context::makeCurrent(egl::Surface *surface)
mState.viewportWidth = surface->getWidth(); mState.viewportWidth = surface->getWidth();
mState.viewportHeight = surface->getHeight(); mState.viewportHeight = surface->getHeight();
mState.scissorX = 0; mState.scissor.x = 0;
mState.scissorY = 0; mState.scissor.y = 0;
mState.scissorWidth = surface->getWidth(); mState.scissor.width = surface->getWidth();
mState.scissorHeight = surface->getHeight(); mState.scissor.height = surface->getHeight();
mHasBeenCurrent = true; mHasBeenCurrent = true;
} }
...@@ -406,55 +409,55 @@ void Context::setClearStencil(int stencil) ...@@ -406,55 +409,55 @@ void Context::setClearStencil(int stencil)
void Context::setCullFace(bool enabled) void Context::setCullFace(bool enabled)
{ {
if (mState.cullFace != enabled) if (mState.rasterizer.cullFace != enabled)
{ {
mState.cullFace = enabled; mState.rasterizer.cullFace = enabled;
mCullStateDirty = true; mCullStateDirty = true;
} }
} }
bool Context::isCullFaceEnabled() const bool Context::isCullFaceEnabled() const
{ {
return mState.cullFace; return mState.rasterizer.cullFace;
} }
void Context::setCullMode(GLenum mode) void Context::setCullMode(GLenum mode)
{ {
if (mState.cullMode != mode) if (mState.rasterizer.cullMode != mode)
{ {
mState.cullMode = mode; mState.rasterizer.cullMode = mode;
mCullStateDirty = true; mCullStateDirty = true;
} }
} }
void Context::setFrontFace(GLenum front) void Context::setFrontFace(GLenum front)
{ {
if (mState.frontFace != front) if (mState.rasterizer.frontFace != front)
{ {
mState.frontFace = front; mState.rasterizer.frontFace = front;
mFrontFaceDirty = true; mFrontFaceDirty = true;
} }
} }
void Context::setDepthTest(bool enabled) void Context::setDepthTest(bool enabled)
{ {
if (mState.depthTest != enabled) if (mState.depthStencil.depthTest != enabled)
{ {
mState.depthTest = enabled; mState.depthStencil.depthTest = enabled;
mDepthStateDirty = true; mDepthStateDirty = true;
} }
} }
bool Context::isDepthTestEnabled() const bool Context::isDepthTestEnabled() const
{ {
return mState.depthTest; return mState.depthStencil.depthTest;
} }
void Context::setDepthFunc(GLenum depthFunc) void Context::setDepthFunc(GLenum depthFunc)
{ {
if (mState.depthFunc != depthFunc) if (mState.depthStencil.depthFunc != depthFunc)
{ {
mState.depthFunc = depthFunc; mState.depthStencil.depthFunc = depthFunc;
mDepthStateDirty = true; mDepthStateDirty = true;
} }
} }
...@@ -467,29 +470,29 @@ void Context::setDepthRange(float zNear, float zFar) ...@@ -467,29 +470,29 @@ void Context::setDepthRange(float zNear, float zFar)
void Context::setBlend(bool enabled) void Context::setBlend(bool enabled)
{ {
if (mState.blend != enabled) if (mState.blend.blend != enabled)
{ {
mState.blend = enabled; mState.blend.blend = enabled;
mBlendStateDirty = true; mBlendStateDirty = true;
} }
} }
bool Context::isBlendEnabled() const bool Context::isBlendEnabled() const
{ {
return mState.blend; return mState.blend.blend;
} }
void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
{ {
if (mState.sourceBlendRGB != sourceRGB || if (mState.blend.sourceBlendRGB != sourceRGB ||
mState.sourceBlendAlpha != sourceAlpha || mState.blend.sourceBlendAlpha != sourceAlpha ||
mState.destBlendRGB != destRGB || mState.blend.destBlendRGB != destRGB ||
mState.destBlendAlpha != destAlpha) mState.blend.destBlendAlpha != destAlpha)
{ {
mState.sourceBlendRGB = sourceRGB; mState.blend.sourceBlendRGB = sourceRGB;
mState.destBlendRGB = destRGB; mState.blend.destBlendRGB = destRGB;
mState.sourceBlendAlpha = sourceAlpha; mState.blend.sourceBlendAlpha = sourceAlpha;
mState.destBlendAlpha = destAlpha; mState.blend.destBlendAlpha = destAlpha;
mBlendStateDirty = true; mBlendStateDirty = true;
} }
} }
...@@ -511,137 +514,137 @@ void Context::setBlendColor(float red, float green, float blue, float alpha) ...@@ -511,137 +514,137 @@ void Context::setBlendColor(float red, float green, float blue, float alpha)
void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
{ {
if (mState.blendEquationRGB != rgbEquation || if (mState.blend.blendEquationRGB != rgbEquation ||
mState.blendEquationAlpha != alphaEquation) mState.blend.blendEquationAlpha != alphaEquation)
{ {
mState.blendEquationRGB = rgbEquation; mState.blend.blendEquationRGB = rgbEquation;
mState.blendEquationAlpha = alphaEquation; mState.blend.blendEquationAlpha = alphaEquation;
mBlendStateDirty = true; mBlendStateDirty = true;
} }
} }
void Context::setStencilTest(bool enabled) void Context::setStencilTest(bool enabled)
{ {
if (mState.stencilTest != enabled) if (mState.depthStencil.stencilTest != enabled)
{ {
mState.stencilTest = enabled; mState.depthStencil.stencilTest = enabled;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
bool Context::isStencilTestEnabled() const bool Context::isStencilTestEnabled() const
{ {
return mState.stencilTest; return mState.depthStencil.stencilTest;
} }
void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
{ {
if (mState.stencilFunc != stencilFunc || if (mState.depthStencil.stencilFunc != stencilFunc ||
mState.stencilRef != stencilRef || mState.depthStencil.stencilRef != stencilRef ||
mState.stencilMask != stencilMask) mState.depthStencil.stencilMask != stencilMask)
{ {
mState.stencilFunc = stencilFunc; mState.depthStencil.stencilFunc = stencilFunc;
mState.stencilRef = (stencilRef > 0) ? stencilRef : 0; mState.depthStencil.stencilRef = (stencilRef > 0) ? stencilRef : 0;
mState.stencilMask = stencilMask; mState.depthStencil.stencilMask = stencilMask;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
{ {
if (mState.stencilBackFunc != stencilBackFunc || if (mState.depthStencil.stencilBackFunc != stencilBackFunc ||
mState.stencilBackRef != stencilBackRef || mState.depthStencil.stencilBackRef != stencilBackRef ||
mState.stencilBackMask != stencilBackMask) mState.depthStencil.stencilBackMask != stencilBackMask)
{ {
mState.stencilBackFunc = stencilBackFunc; mState.depthStencil.stencilBackFunc = stencilBackFunc;
mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; mState.depthStencil.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
mState.stencilBackMask = stencilBackMask; mState.depthStencil.stencilBackMask = stencilBackMask;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
void Context::setStencilWritemask(GLuint stencilWritemask) void Context::setStencilWritemask(GLuint stencilWritemask)
{ {
if (mState.stencilWritemask != stencilWritemask) if (mState.depthStencil.stencilWritemask != stencilWritemask)
{ {
mState.stencilWritemask = stencilWritemask; mState.depthStencil.stencilWritemask = stencilWritemask;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
void Context::setStencilBackWritemask(GLuint stencilBackWritemask) void Context::setStencilBackWritemask(GLuint stencilBackWritemask)
{ {
if (mState.stencilBackWritemask != stencilBackWritemask) if (mState.depthStencil.stencilBackWritemask != stencilBackWritemask)
{ {
mState.stencilBackWritemask = stencilBackWritemask; mState.depthStencil.stencilBackWritemask = stencilBackWritemask;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
{ {
if (mState.stencilFail != stencilFail || if (mState.depthStencil.stencilFail != stencilFail ||
mState.stencilPassDepthFail != stencilPassDepthFail || mState.depthStencil.stencilPassDepthFail != stencilPassDepthFail ||
mState.stencilPassDepthPass != stencilPassDepthPass) mState.depthStencil.stencilPassDepthPass != stencilPassDepthPass)
{ {
mState.stencilFail = stencilFail; mState.depthStencil.stencilFail = stencilFail;
mState.stencilPassDepthFail = stencilPassDepthFail; mState.depthStencil.stencilPassDepthFail = stencilPassDepthFail;
mState.stencilPassDepthPass = stencilPassDepthPass; mState.depthStencil.stencilPassDepthPass = stencilPassDepthPass;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
{ {
if (mState.stencilBackFail != stencilBackFail || if (mState.depthStencil.stencilBackFail != stencilBackFail ||
mState.stencilBackPassDepthFail != stencilBackPassDepthFail || mState.depthStencil.stencilBackPassDepthFail != stencilBackPassDepthFail ||
mState.stencilBackPassDepthPass != stencilBackPassDepthPass) mState.depthStencil.stencilBackPassDepthPass != stencilBackPassDepthPass)
{ {
mState.stencilBackFail = stencilBackFail; mState.depthStencil.stencilBackFail = stencilBackFail;
mState.stencilBackPassDepthFail = stencilBackPassDepthFail; mState.depthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail;
mState.stencilBackPassDepthPass = stencilBackPassDepthPass; mState.depthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass;
mStencilStateDirty = true; mStencilStateDirty = true;
} }
} }
void Context::setPolygonOffsetFill(bool enabled) void Context::setPolygonOffsetFill(bool enabled)
{ {
if (mState.polygonOffsetFill != enabled) if (mState.rasterizer.polygonOffsetFill != enabled)
{ {
mState.polygonOffsetFill = enabled; mState.rasterizer.polygonOffsetFill = enabled;
mPolygonOffsetStateDirty = true; mPolygonOffsetStateDirty = true;
} }
} }
bool Context::isPolygonOffsetFillEnabled() const bool Context::isPolygonOffsetFillEnabled() const
{ {
return mState.polygonOffsetFill; return mState.rasterizer.polygonOffsetFill;
} }
void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units) void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units)
{ {
if (mState.polygonOffsetFactor != factor || if (mState.rasterizer.polygonOffsetFactor != factor ||
mState.polygonOffsetUnits != units) mState.rasterizer.polygonOffsetUnits != units)
{ {
mState.polygonOffsetFactor = factor; mState.rasterizer.polygonOffsetFactor = factor;
mState.polygonOffsetUnits = units; mState.rasterizer.polygonOffsetUnits = units;
mPolygonOffsetStateDirty = true; mPolygonOffsetStateDirty = true;
} }
} }
void Context::setSampleAlphaToCoverage(bool enabled) void Context::setSampleAlphaToCoverage(bool enabled)
{ {
if (mState.sampleAlphaToCoverage != enabled) if (mState.blend.sampleAlphaToCoverage != enabled)
{ {
mState.sampleAlphaToCoverage = enabled; mState.blend.sampleAlphaToCoverage = enabled;
mSampleStateDirty = true; mSampleStateDirty = true;
} }
} }
bool Context::isSampleAlphaToCoverageEnabled() const bool Context::isSampleAlphaToCoverageEnabled() const
{ {
return mState.sampleAlphaToCoverage; return mState.blend.sampleAlphaToCoverage;
} }
void Context::setSampleCoverage(bool enabled) void Context::setSampleCoverage(bool enabled)
...@@ -671,30 +674,30 @@ void Context::setSampleCoverageParams(GLclampf value, bool invert) ...@@ -671,30 +674,30 @@ void Context::setSampleCoverageParams(GLclampf value, bool invert)
void Context::setScissorTest(bool enabled) void Context::setScissorTest(bool enabled)
{ {
if (mState.scissorTest != enabled) if (mState.rasterizer.scissorTest != enabled)
{ {
mState.scissorTest = enabled; mState.rasterizer.scissorTest = enabled;
mScissorStateDirty = true; mScissorStateDirty = true;
} }
} }
bool Context::isScissorTestEnabled() const bool Context::isScissorTestEnabled() const
{ {
return mState.scissorTest; return mState.rasterizer.scissorTest;
} }
void Context::setDither(bool enabled) void Context::setDither(bool enabled)
{ {
if (mState.dither != enabled) if (mState.blend.dither != enabled)
{ {
mState.dither = enabled; mState.blend.dither = enabled;
mDitherStateDirty = true; mDitherStateDirty = true;
} }
} }
bool Context::isDitherEnabled() const bool Context::isDitherEnabled() const
{ {
return mState.dither; return mState.blend.dither;
} }
void Context::setLineWidth(GLfloat width) void Context::setLineWidth(GLfloat width)
...@@ -725,35 +728,35 @@ void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) ...@@ -725,35 +728,35 @@ 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.scissorX != x || mState.scissorY != y || if (mState.scissor.x != x || mState.scissor.y != y ||
mState.scissorWidth != width || mState.scissorHeight != height) mState.scissor.width != width || mState.scissor.height != height)
{ {
mState.scissorX = x; mState.scissor.x = x;
mState.scissorY = y; mState.scissor.y = y;
mState.scissorWidth = width; mState.scissor.width = width;
mState.scissorHeight = height; mState.scissor.height = height;
mScissorStateDirty = true; 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.colorMaskRed != red || mState.colorMaskGreen != green || if (mState.blend.colorMaskRed != red || mState.blend.colorMaskGreen != green ||
mState.colorMaskBlue != blue || mState.colorMaskAlpha != alpha) mState.blend.colorMaskBlue != blue || mState.blend.colorMaskAlpha != alpha)
{ {
mState.colorMaskRed = red; mState.blend.colorMaskRed = red;
mState.colorMaskGreen = green; mState.blend.colorMaskGreen = green;
mState.colorMaskBlue = blue; mState.blend.colorMaskBlue = blue;
mState.colorMaskAlpha = alpha; mState.blend.colorMaskAlpha = alpha;
mMaskStateDirty = true; mMaskStateDirty = true;
} }
} }
void Context::setDepthMask(bool mask) void Context::setDepthMask(bool mask)
{ {
if (mState.depthMask != mask) if (mState.depthStencil.depthMask != mask)
{ {
mState.depthMask = mask; mState.depthStencil.depthMask = mask;
mMaskStateDirty = true; mMaskStateDirty = true;
} }
} }
...@@ -1370,22 +1373,22 @@ bool Context::getBooleanv(GLenum pname, GLboolean *params) ...@@ -1370,22 +1373,22 @@ bool Context::getBooleanv(GLenum pname, GLboolean *params)
{ {
case GL_SHADER_COMPILER: *params = GL_TRUE; break; case GL_SHADER_COMPILER: *params = GL_TRUE; break;
case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break; case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break;
case GL_DEPTH_WRITEMASK: *params = mState.depthMask; break; case GL_DEPTH_WRITEMASK: *params = mState.depthStencil.depthMask; break;
case GL_COLOR_WRITEMASK: case GL_COLOR_WRITEMASK:
params[0] = mState.colorMaskRed; params[0] = mState.blend.colorMaskRed;
params[1] = mState.colorMaskGreen; params[1] = mState.blend.colorMaskGreen;
params[2] = mState.colorMaskBlue; params[2] = mState.blend.colorMaskBlue;
params[3] = mState.colorMaskAlpha; params[3] = mState.blend.colorMaskAlpha;
break; break;
case GL_CULL_FACE: *params = mState.cullFace; break; case GL_CULL_FACE: *params = mState.rasterizer.cullFace; break;
case GL_POLYGON_OFFSET_FILL: *params = mState.polygonOffsetFill; break; case GL_POLYGON_OFFSET_FILL: *params = mState.rasterizer.polygonOffsetFill; break;
case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.sampleAlphaToCoverage; break; case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.blend.sampleAlphaToCoverage; break;
case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; break; case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; break;
case GL_SCISSOR_TEST: *params = mState.scissorTest; break; case GL_SCISSOR_TEST: *params = mState.rasterizer.scissorTest; break;
case GL_STENCIL_TEST: *params = mState.stencilTest; break; case GL_STENCIL_TEST: *params = mState.depthStencil.stencilTest; break;
case GL_DEPTH_TEST: *params = mState.depthTest; break; case GL_DEPTH_TEST: *params = mState.depthStencil.depthTest; break;
case GL_BLEND: *params = mState.blend; break; case GL_BLEND: *params = mState.blend.blend; break;
case GL_DITHER: *params = mState.dither; break; case GL_DITHER: *params = mState.blend.dither; break;
case GL_CONTEXT_ROBUST_ACCESS_EXT: *params = mRobustAccess ? GL_TRUE : GL_FALSE; break; case GL_CONTEXT_ROBUST_ACCESS_EXT: *params = mRobustAccess ? GL_TRUE : GL_FALSE; break;
default: default:
return false; return false;
...@@ -1405,8 +1408,8 @@ bool Context::getFloatv(GLenum pname, GLfloat *params) ...@@ -1405,8 +1408,8 @@ bool Context::getFloatv(GLenum pname, GLfloat *params)
case GL_LINE_WIDTH: *params = mState.lineWidth; break; case GL_LINE_WIDTH: *params = mState.lineWidth; break;
case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break; case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break;
case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break; case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break;
case GL_POLYGON_OFFSET_FACTOR: *params = mState.polygonOffsetFactor; break; case GL_POLYGON_OFFSET_FACTOR: *params = mState.rasterizer.polygonOffsetFactor; break;
case GL_POLYGON_OFFSET_UNITS: *params = mState.polygonOffsetUnits; break; case GL_POLYGON_OFFSET_UNITS: *params = mState.rasterizer.polygonOffsetUnits; break;
case GL_ALIASED_LINE_WIDTH_RANGE: case GL_ALIASED_LINE_WIDTH_RANGE:
params[0] = gl::ALIASED_LINE_WIDTH_RANGE_MIN; params[0] = gl::ALIASED_LINE_WIDTH_RANGE_MIN;
params[1] = gl::ALIASED_LINE_WIDTH_RANGE_MAX; params[1] = gl::ALIASED_LINE_WIDTH_RANGE_MAX;
...@@ -1477,27 +1480,27 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1477,27 +1480,27 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; break; case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; break;
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.stencilFunc; break; case GL_STENCIL_FUNC: *params = mState.depthStencil.stencilFunc; break;
case GL_STENCIL_REF: *params = mState.stencilRef; break; case GL_STENCIL_REF: *params = mState.depthStencil.stencilRef; break;
case GL_STENCIL_VALUE_MASK: *params = mState.stencilMask; break; case GL_STENCIL_VALUE_MASK: *params = mState.depthStencil.stencilMask; break;
case GL_STENCIL_BACK_FUNC: *params = mState.stencilBackFunc; break; case GL_STENCIL_BACK_FUNC: *params = mState.depthStencil.stencilBackFunc; break;
case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; break; case GL_STENCIL_BACK_REF: *params = mState.depthStencil.stencilBackRef; break;
case GL_STENCIL_BACK_VALUE_MASK: *params = mState.stencilBackMask; break; case GL_STENCIL_BACK_VALUE_MASK: *params = mState.depthStencil.stencilBackMask; break;
case GL_STENCIL_FAIL: *params = mState.stencilFail; break; case GL_STENCIL_FAIL: *params = mState.depthStencil.stencilFail; break;
case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.stencilPassDepthFail; break; case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilPassDepthFail; break;
case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.stencilPassDepthPass; break; case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.depthStencil.stencilPassDepthPass; break;
case GL_STENCIL_BACK_FAIL: *params = mState.stencilBackFail; break; case GL_STENCIL_BACK_FAIL: *params = mState.depthStencil.stencilBackFail; break;
case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.stencilBackPassDepthFail; break; case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilBackPassDepthFail; break;
case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.stencilBackPassDepthPass; break; case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.depthStencil.stencilBackPassDepthPass; break;
case GL_DEPTH_FUNC: *params = mState.depthFunc; break; case GL_DEPTH_FUNC: *params = mState.depthStencil.depthFunc; break;
case GL_BLEND_SRC_RGB: *params = mState.sourceBlendRGB; break; case GL_BLEND_SRC_RGB: *params = mState.blend.sourceBlendRGB; break;
case GL_BLEND_SRC_ALPHA: *params = mState.sourceBlendAlpha; break; case GL_BLEND_SRC_ALPHA: *params = mState.blend.sourceBlendAlpha; break;
case GL_BLEND_DST_RGB: *params = mState.destBlendRGB; break; case GL_BLEND_DST_RGB: *params = mState.blend.destBlendRGB; break;
case GL_BLEND_DST_ALPHA: *params = mState.destBlendAlpha; break; case GL_BLEND_DST_ALPHA: *params = mState.blend.destBlendAlpha; break;
case GL_BLEND_EQUATION_RGB: *params = mState.blendEquationRGB; break; case GL_BLEND_EQUATION_RGB: *params = mState.blend.blendEquationRGB; break;
case GL_BLEND_EQUATION_ALPHA: *params = mState.blendEquationAlpha; break; case GL_BLEND_EQUATION_ALPHA: *params = mState.blend.blendEquationAlpha; break;
case GL_STENCIL_WRITEMASK: *params = mState.stencilWritemask; break; case GL_STENCIL_WRITEMASK: *params = mState.depthStencil.stencilWritemask; break;
case GL_STENCIL_BACK_WRITEMASK: *params = mState.stencilBackWritemask; break; case GL_STENCIL_BACK_WRITEMASK: *params = mState.depthStencil.stencilBackWritemask; break;
case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; break; case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; break;
case GL_SUBPIXEL_BITS: *params = 4; break; case GL_SUBPIXEL_BITS: *params = 4; break;
case GL_MAX_TEXTURE_SIZE: *params = getMaximumTextureDimension(); break; case GL_MAX_TEXTURE_SIZE: *params = getMaximumTextureDimension(); break;
...@@ -1592,13 +1595,13 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1592,13 +1595,13 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
params[3] = mState.viewportHeight; params[3] = mState.viewportHeight;
break; break;
case GL_SCISSOR_BOX: case GL_SCISSOR_BOX:
params[0] = mState.scissorX; params[0] = mState.scissor.x;
params[1] = mState.scissorY; params[1] = mState.scissor.y;
params[2] = mState.scissorWidth; params[2] = mState.scissor.width;
params[3] = mState.scissorHeight; params[3] = mState.scissor.height;
break; break;
case GL_CULL_FACE_MODE: *params = mState.cullMode; break; case GL_CULL_FACE_MODE: *params = mState.rasterizer.cullMode; break;
case GL_FRONT_FACE: *params = mState.frontFace; break; case GL_FRONT_FACE: *params = mState.rasterizer.frontFace; break;
case GL_RED_BITS: case GL_RED_BITS:
case GL_GREEN_BITS: case GL_GREEN_BITS:
case GL_BLUE_BITS: case GL_BLUE_BITS:
...@@ -2011,21 +2014,8 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -2011,21 +2014,8 @@ bool Context::applyRenderTarget(bool ignoreViewport)
if (mScissorStateDirty) if (mScissorStateDirty)
{ {
if (mState.scissorTest) mRenderer->setScissorRectangle(mState.scissor, static_cast<int>(mRenderTargetDesc.Width),
{ static_cast<int>(mRenderTargetDesc.Height));
RECT rect;
rect.left = clamp(mState.scissorX, 0L, static_cast<LONG>(mRenderTargetDesc.Width));
rect.top = clamp(mState.scissorY, 0L, static_cast<LONG>(mRenderTargetDesc.Height));
rect.right = clamp(mState.scissorX + mState.scissorWidth, 0L, static_cast<LONG>(mRenderTargetDesc.Width));
rect.bottom = clamp(mState.scissorY + mState.scissorHeight, 0L, static_cast<LONG>(mRenderTargetDesc.Height));
mDevice->SetScissorRect(&rect);
mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
}
else
{
mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
}
mScissorStateDirty = false; mScissorStateDirty = false;
} }
...@@ -2054,6 +2044,8 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -2054,6 +2044,8 @@ bool Context::applyRenderTarget(bool ignoreViewport)
mDxUniformsDirty = false; mDxUniformsDirty = false;
} }
mRenderer->applyRenderTarget(framebufferObject);
return true; return true;
} }
...@@ -2065,216 +2057,29 @@ void Context::applyState(GLenum drawMode) ...@@ -2065,216 +2057,29 @@ void Context::applyState(GLenum drawMode)
Framebuffer *framebufferObject = getDrawFramebuffer(); Framebuffer *framebufferObject = getDrawFramebuffer();
GLint frontCCW = programBinary->getDxFrontCCWLocation(); GLint frontCCW = programBinary->getDxFrontCCWLocation();
GLint ccw = (mState.frontFace == GL_CCW); GLint ccw = (mState.rasterizer.frontFace == GL_CCW);
programBinary->setUniform1iv(frontCCW, 1, &ccw); programBinary->setUniform1iv(frontCCW, 1, &ccw);
GLint pointsOrLines = programBinary->getDxPointsOrLinesLocation(); GLint pointsOrLines = programBinary->getDxPointsOrLinesLocation();
GLint alwaysFront = !isTriangleMode(drawMode); GLint alwaysFront = !isTriangleMode(drawMode);
programBinary->setUniform1iv(pointsOrLines, 1, &alwaysFront); programBinary->setUniform1iv(pointsOrLines, 1, &alwaysFront);
bool zeroColorMaskAllowed = mRenderer->getAdapterVendor() != VENDOR_ID_AMD; if (mCullStateDirty || mFrontFaceDirty || mPolygonOffsetStateDirty)
// Apparently some ATI cards have a bug where a draw with a zero color
// write mask can cause later draws to have incorrect results. Instead,
// set a nonzero color write mask but modify the blend state so that no
// drawing is done.
// http://code.google.com/p/angleproject/issues/detail?id=169
if (mCullStateDirty || mFrontFaceDirty)
{
if (mState.cullFace)
{
mDevice->SetRenderState(D3DRS_CULLMODE, gl_d3d9::ConvertCullMode(mState.cullMode, mState.frontFace));
}
else
{
mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
}
mCullStateDirty = false;
}
if (mDepthStateDirty)
{
if (mState.depthTest)
{
mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
mDevice->SetRenderState(D3DRS_ZFUNC, gl_d3d9::ConvertComparison(mState.depthFunc));
}
else
{
mDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
}
mDepthStateDirty = false;
}
if (!zeroColorMaskAllowed && (mMaskStateDirty || mBlendStateDirty))
{
mBlendStateDirty = true;
mMaskStateDirty = true;
}
if (mBlendStateDirty)
{
if (mState.blend)
{
mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
if (mState.sourceBlendRGB != GL_CONSTANT_ALPHA && mState.sourceBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA &&
mState.destBlendRGB != GL_CONSTANT_ALPHA && mState.destBlendRGB != GL_ONE_MINUS_CONSTANT_ALPHA)
{
mDevice->SetRenderState(D3DRS_BLENDFACTOR, gl_d3d9::ConvertColor(mState.blendColor));
}
else
{
mDevice->SetRenderState(D3DRS_BLENDFACTOR, D3DCOLOR_RGBA(unorm<8>(mState.blendColor.alpha),
unorm<8>(mState.blendColor.alpha),
unorm<8>(mState.blendColor.alpha),
unorm<8>(mState.blendColor.alpha)));
}
mDevice->SetRenderState(D3DRS_SRCBLEND, gl_d3d9::ConvertBlendFunc(mState.sourceBlendRGB));
mDevice->SetRenderState(D3DRS_DESTBLEND, gl_d3d9::ConvertBlendFunc(mState.destBlendRGB));
mDevice->SetRenderState(D3DRS_BLENDOP, gl_d3d9::ConvertBlendOp(mState.blendEquationRGB));
if (mState.sourceBlendRGB != mState.sourceBlendAlpha ||
mState.destBlendRGB != mState.destBlendAlpha ||
mState.blendEquationRGB != mState.blendEquationAlpha)
{
mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
mDevice->SetRenderState(D3DRS_SRCBLENDALPHA, gl_d3d9::ConvertBlendFunc(mState.sourceBlendAlpha));
mDevice->SetRenderState(D3DRS_DESTBLENDALPHA, gl_d3d9::ConvertBlendFunc(mState.destBlendAlpha));
mDevice->SetRenderState(D3DRS_BLENDOPALPHA, gl_d3d9::ConvertBlendOp(mState.blendEquationAlpha));
}
else
{
mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE);
}
}
else
{
mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
mBlendStateDirty = false;
}
if (mStencilStateDirty || mFrontFaceDirty)
{
if (mState.stencilTest && framebufferObject->hasStencil())
{
mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
// FIXME: Unsupported by D3D9
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF = D3DRS_STENCILREF;
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK = D3DRS_STENCILMASK;
const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK;
if (mState.stencilWritemask != mState.stencilBackWritemask ||
mState.stencilRef != mState.stencilBackRef ||
mState.stencilMask != mState.stencilBackMask)
{
ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are invalid under WebGL.");
return error(GL_INVALID_OPERATION);
}
// get the maximum size of the stencil ref
gl::Renderbuffer *stencilbuffer = framebufferObject->getStencilbuffer();
GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1;
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask);
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC,
gl_d3d9::ConvertComparison(mState.stencilFunc));
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil);
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilMask);
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
gl_d3d9::ConvertStencilOp(mState.stencilFail));
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
gl_d3d9::ConvertStencilOp(mState.stencilPassDepthFail));
mDevice->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
gl_d3d9::ConvertStencilOp(mState.stencilPassDepthPass));
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilBackWritemask);
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILFUNC : D3DRS_CCW_STENCILFUNC,
gl_d3d9::ConvertComparison(mState.stencilBackFunc));
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILREF : D3DRS_CCW_STENCILREF, (mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil);
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILMASK : D3DRS_CCW_STENCILMASK, mState.stencilBackMask);
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
gl_d3d9::ConvertStencilOp(mState.stencilBackFail));
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
gl_d3d9::ConvertStencilOp(mState.stencilBackPassDepthFail));
mDevice->SetRenderState(mState.frontFace == GL_CW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
gl_d3d9::ConvertStencilOp(mState.stencilBackPassDepthPass));
}
else
{
mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
}
mStencilStateDirty = false;
mFrontFaceDirty = false;
}
if (mMaskStateDirty)
{
int colorMask = gl_d3d9::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen,
mState.colorMaskBlue, mState.colorMaskAlpha);
if (colorMask == 0 && !zeroColorMaskAllowed)
{
// Enable green channel, but set blending so nothing will be drawn.
mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_GREEN);
mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
mDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
}
else
{ {
mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, colorMask); const gl::Renderbuffer *depthbuffer = framebufferObject->getDepthbuffer();
} unsigned int depthSize = depthbuffer ? depthbuffer->getDepthSize() : 0;
mDevice->SetRenderState(D3DRS_ZWRITEENABLE, mState.depthMask ? TRUE : FALSE);
mMaskStateDirty = false;
}
if (mPolygonOffsetStateDirty) mRenderer->setRasterizerState(mState.rasterizer, depthSize);
{
if (mState.polygonOffsetFill)
{
gl::Renderbuffer *depthbuffer = framebufferObject->getDepthbuffer();
if (depthbuffer)
{
mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor));
float depthBias = ldexp(mState.polygonOffsetUnits, -(int)(depthbuffer->getDepthSize()));
mDevice->SetRenderState(D3DRS_DEPTHBIAS, *((DWORD*)&depthBias));
}
}
else
{
mDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, 0);
mDevice->SetRenderState(D3DRS_DEPTHBIAS, 0);
}
mCullStateDirty = false;
mPolygonOffsetStateDirty = false; mPolygonOffsetStateDirty = false;
} }
if (mSampleStateDirty) if (mBlendStateDirty || mMaskStateDirty)
{ {
if (mState.sampleAlphaToCoverage) unsigned int mask = 0;
{
FIXME("Sample alpha to coverage is unimplemented.");
}
mDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
if (mState.sampleCoverage) if (mState.sampleCoverage)
{ {
unsigned int mask = 0;
if (mState.sampleCoverageValue != 0) if (mState.sampleCoverageValue != 0)
{ {
float threshold = 0.5f; float threshold = 0.5f;
...@@ -2295,22 +2100,27 @@ void Context::applyState(GLenum drawMode) ...@@ -2295,22 +2100,27 @@ void Context::applyState(GLenum drawMode)
{ {
mask = ~mask; mask = ~mask;
} }
mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, mask);
} }
else else
{ {
mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); mask = 0xFFFFFFFF;
} }
mSampleStateDirty = false; mRenderer->setBlendState(mState.blend, mState.blendColor, mask);
mBlendStateDirty = false;
} }
if (mDitherStateDirty) if (mStencilStateDirty || mFrontFaceDirty || mDepthStateDirty)
{ {
mDevice->SetRenderState(D3DRS_DITHERENABLE, mState.dither ? TRUE : FALSE); unsigned int stencilSize = framebufferObject->hasStencil() ? framebufferObject->getStencilbuffer()->getStencilSize() : 0;
mDitherStateDirty = false; mRenderer->setDepthStencilState(mState.depthStencil,
mState.rasterizer.frontFace == GL_CCW,
stencilSize);
mDepthStateDirty = false;
mStencilStateDirty = false;
mFrontFaceDirty = false;
} }
} }
...@@ -2809,7 +2619,7 @@ void Context::clear(GLbitfield mask) ...@@ -2809,7 +2619,7 @@ void Context::clear(GLbitfield mask)
if (mask & GL_DEPTH_BUFFER_BIT) if (mask & GL_DEPTH_BUFFER_BIT)
{ {
mask &= ~GL_DEPTH_BUFFER_BIT; mask &= ~GL_DEPTH_BUFFER_BIT;
if (mState.depthMask && framebufferObject->getDepthbufferType() != GL_NONE) if (mState.depthStencil.depthMask && framebufferObject->getDepthbufferType() != GL_NONE)
{ {
flags |= D3DCLEAR_ZBUFFER; flags |= D3DCLEAR_ZBUFFER;
} }
...@@ -2860,13 +2670,14 @@ void Context::clear(GLbitfield mask) ...@@ -2860,13 +2670,14 @@ void Context::clear(GLbitfield mask)
float depth = clamp01(mState.depthClearValue); float depth = clamp01(mState.depthClearValue);
int stencil = mState.stencilClearValue & 0x000000FF; int stencil = mState.stencilClearValue & 0x000000FF;
bool alphaUnmasked = (d3d9_gl::GetAlphaSize(mRenderTargetDesc.Format) == 0) || mState.colorMaskAlpha;
bool alphaUnmasked = (d3d9_gl::GetAlphaSize(mRenderTargetDesc.Format) == 0) || mState.blend.colorMaskAlpha;
const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) && const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) &&
(mState.stencilWritemask & stencilUnmasked) != stencilUnmasked; (mState.depthStencil.stencilWritemask & stencilUnmasked) != stencilUnmasked;
const bool needMaskedColorClear = (flags & D3DCLEAR_TARGET) && const bool needMaskedColorClear = (flags & D3DCLEAR_TARGET) &&
!(mState.colorMaskRed && mState.colorMaskGreen && !(mState.blend.colorMaskRed && mState.blend.colorMaskGreen &&
mState.colorMaskBlue && alphaUnmasked); mState.blend.colorMaskBlue && alphaUnmasked);
if (needMaskedColorClear || needMaskedStencilClear) if (needMaskedColorClear || needMaskedStencilClear)
{ {
...@@ -2929,7 +2740,11 @@ void Context::clear(GLbitfield mask) ...@@ -2929,7 +2740,11 @@ void Context::clear(GLbitfield mask)
if (flags & D3DCLEAR_TARGET) if (flags & D3DCLEAR_TARGET)
{ {
mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, gl_d3d9::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, mState.colorMaskBlue, mState.colorMaskAlpha)); mDevice->SetRenderState(D3DRS_COLORWRITEENABLE,
gl_d3d9::ConvertColorMask(mState.blend.colorMaskRed,
mState.blend.colorMaskGreen,
mState.blend.colorMaskBlue,
mState.blend.colorMaskAlpha));
} }
else else
{ {
...@@ -2942,7 +2757,7 @@ void Context::clear(GLbitfield mask) ...@@ -2942,7 +2757,7 @@ void Context::clear(GLbitfield mask)
mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
mDevice->SetRenderState(D3DRS_STENCILREF, stencil); mDevice->SetRenderState(D3DRS_STENCILREF, stencil);
mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, mState.stencilWritemask); mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, mState.depthStencil.stencilWritemask);
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);
...@@ -3744,7 +3559,7 @@ bool Context::skipDraw(GLenum drawMode) ...@@ -3744,7 +3559,7 @@ bool Context::skipDraw(GLenum drawMode)
} }
else if (isTriangleMode(drawMode)) else if (isTriangleMode(drawMode))
{ {
if (mState.cullFace && mState.cullMode == GL_FRONT_AND_BACK) if (mState.rasterizer.cullFace && mState.rasterizer.cullMode == GL_FRONT_AND_BACK)
{ {
return true; return true;
} }
...@@ -3974,36 +3789,36 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -3974,36 +3789,36 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
RECT sourceScissoredRect = sourceRect; RECT sourceScissoredRect = sourceRect;
RECT destScissoredRect = destRect; RECT destScissoredRect = destRect;
if (mState.scissorTest) if (mState.rasterizer.scissorTest)
{ {
// Only write to parts of the destination framebuffer which pass the scissor test // Only write to parts of the destination framebuffer which pass the scissor test
// Please note: the destRect is now in D3D-style coordinates, so the *top* of the // Please note: the destRect is now in D3D-style coordinates, so the *top* of the
// rect will be checked against scissorY, rather than the bottom. // rect will be checked against scissorY, rather than the bottom.
if (destRect.left < mState.scissorX) if (destRect.left < mState.scissor.x)
{ {
int xDiff = mState.scissorX - destRect.left; int xDiff = mState.scissor.x - destRect.left;
destScissoredRect.left = mState.scissorX; destScissoredRect.left = mState.scissor.x;
sourceScissoredRect.left += xDiff; sourceScissoredRect.left += xDiff;
} }
if (destRect.right > mState.scissorX + mState.scissorWidth) if (destRect.right > mState.scissor.x + mState.scissor.width)
{ {
int xDiff = destRect.right - (mState.scissorX + mState.scissorWidth); int xDiff = destRect.right - (mState.scissor.x + mState.scissor.width);
destScissoredRect.right = mState.scissorX + mState.scissorWidth; destScissoredRect.right = mState.scissor.x + mState.scissor.width;
sourceScissoredRect.right -= xDiff; sourceScissoredRect.right -= xDiff;
} }
if (destRect.top < mState.scissorY) if (destRect.top < mState.scissor.y)
{ {
int yDiff = mState.scissorY - destRect.top; int yDiff = mState.scissor.y - destRect.top;
destScissoredRect.top = mState.scissorY; destScissoredRect.top = mState.scissor.y;
sourceScissoredRect.top += yDiff; sourceScissoredRect.top += yDiff;
} }
if (destRect.bottom > mState.scissorY + mState.scissorHeight) if (destRect.bottom > mState.scissor.y + mState.scissor.height)
{ {
int yDiff = destRect.bottom - (mState.scissorY + mState.scissorHeight); int yDiff = destRect.bottom - (mState.scissor.y + mState.scissor.height);
destScissoredRect.bottom = mState.scissorY + mState.scissorHeight; destScissoredRect.bottom = mState.scissor.y + mState.scissor.height;
sourceScissoredRect.bottom -= yDiff; sourceScissoredRect.bottom -= yDiff;
} }
} }
......
...@@ -154,43 +154,16 @@ struct State ...@@ -154,43 +154,16 @@ struct State
GLclampf depthClearValue; GLclampf depthClearValue;
int stencilClearValue; int stencilClearValue;
bool cullFace; RasterizerState rasterizer;
GLenum cullMode; Rectangle scissor;
GLenum frontFace;
bool depthTest; BlendState blend;
GLenum depthFunc;
bool blend;
GLenum sourceBlendRGB;
GLenum destBlendRGB;
GLenum sourceBlendAlpha;
GLenum destBlendAlpha;
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
Color blendColor; Color blendColor;
bool stencilTest;
GLenum stencilFunc;
GLint stencilRef;
GLuint stencilMask;
GLenum stencilFail;
GLenum stencilPassDepthFail;
GLenum stencilPassDepthPass;
GLuint stencilWritemask;
GLenum stencilBackFunc;
GLint stencilBackRef;
GLuint stencilBackMask;
GLenum stencilBackFail;
GLenum stencilBackPassDepthFail;
GLenum stencilBackPassDepthPass;
GLuint stencilBackWritemask;
bool polygonOffsetFill;
GLfloat polygonOffsetFactor;
GLfloat polygonOffsetUnits;
bool sampleAlphaToCoverage;
bool sampleCoverage; bool sampleCoverage;
GLclampf sampleCoverageValue; GLclampf sampleCoverageValue;
bool sampleCoverageInvert; bool sampleCoverageInvert;
bool scissorTest;
bool dither; DepthStencilState depthStencil;
GLfloat lineWidth; GLfloat lineWidth;
...@@ -204,17 +177,6 @@ struct State ...@@ -204,17 +177,6 @@ struct State
float zNear; float zNear;
float zFar; float zFar;
GLint scissorX;
GLint scissorY;
GLsizei scissorWidth;
GLsizei scissorHeight;
bool colorMaskRed;
bool colorMaskGreen;
bool colorMaskBlue;
bool colorMaskAlpha;
bool depthMask;
unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
BindingPointer<Buffer> arrayBuffer; BindingPointer<Buffer> arrayBuffer;
BindingPointer<Buffer> elementArrayBuffer; BindingPointer<Buffer> elementArrayBuffer;
......
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