Commit 0fbb600f by Geoff Lang

Sync the entire blend state before drawing in RendererGL.

BUG=angleproject:883 Change-Id: I903090c1a7ba90bd479ad8d24f943672eb51054e Reviewed-on: https://chromium-review.googlesource.com/266033Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 08c9cd97
......@@ -431,12 +431,14 @@ void State::setSampleCoverageParams(GLclampf value, bool invert)
mSampleCoverageInvert = invert;
}
void State::getSampleCoverageParams(GLclampf *value, bool *invert) const
GLclampf State::getSampleCoverageValue() const
{
ASSERT(value != NULL && invert != NULL);
return mSampleCoverageValue;
}
*value = mSampleCoverageValue;
*invert = mSampleCoverageInvert;
bool State::getSampleCoverageInvert() const
{
return mSampleCoverageInvert;
}
bool State::isScissorTestEnabled() const
......
......@@ -108,7 +108,8 @@ class State : angle::NonCopyable
bool isSampleCoverageEnabled() const;
void setSampleCoverage(bool enabled);
void setSampleCoverageParams(GLclampf value, bool invert);
void getSampleCoverageParams(GLclampf *value, bool *invert) const;
GLclampf getSampleCoverageValue() const;
bool getSampleCoverageInvert() const;
// Scissor test state toggle & query
bool isScissorTestEnabled() const;
......
......@@ -306,9 +306,7 @@ gl::Error RendererD3D::applyState(const gl::Data &data, GLenum drawMode)
unsigned int mask = 0;
if (data.state->isSampleCoverageEnabled())
{
GLclampf coverageValue;
bool coverageInvert = false;
data.state->getSampleCoverageParams(&coverageValue, &coverageInvert);
GLclampf coverageValue = data.state->getSampleCoverageValue();
if (coverageValue != 0)
{
float threshold = 0.5f;
......@@ -325,6 +323,7 @@ gl::Error RendererD3D::applyState(const gl::Data &data, GLenum drawMode)
}
}
bool coverageInvert = data.state->getSampleCoverageInvert();
if (coverageInvert)
{
mask = ~mask;
......
......@@ -34,10 +34,22 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren
mScissor(0, 0, 0, 0),
mViewport(0, 0, 0, 0),
mClearColor(0.0f, 0.0f, 0.0f, 0.0f),
mBlendEnabled(false),
mBlendColor(0, 0, 0, 0),
mSourceBlendRGB(GL_ONE),
mDestBlendRGB(GL_ZERO),
mSourceBlendAlpha(GL_ONE),
mDestBlendAlpha(GL_ZERO),
mBlendEquationRGB(GL_FUNC_ADD),
mBlendEquationAlpha(GL_FUNC_ADD),
mColorMaskRed(true),
mColorMaskGreen(true),
mColorMaskBlue(true),
mColorMaskAlpha(true),
mSampleAlphaToCoverageEnabled(false),
mSampleCoverageEnabled(false),
mSampleCoverageValue(1.0f),
mSampleCoverageInvert(false),
mClearDepth(1.0f),
mDepthMask(true),
mClearStencil(0),
......@@ -253,7 +265,17 @@ gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data)
setViewport(state.getViewport());
const gl::BlendState &blendState = state.getBlendState();
setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha);
setBlendEnabled(blendState.blend);
if (blendState.blend)
{
setBlendColor(state.getBlendColor());
setBlendFuncs(blendState.sourceBlendRGB, blendState.destBlendRGB, blendState.sourceBlendAlpha, blendState.destBlendAlpha);
setBlendEquations(blendState.blendEquationRGB, blendState.blendEquationAlpha);
setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha);
}
setSampleAlphaToCoverageEnabled(blendState.sampleAlphaToCoverage);
setSampleCoverageEnabled(state.isSampleCoverageEnabled());
setSampleCoverage(state.getSampleCoverageValue(), state.getSampleCoverageInvert());
const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
setDepthMask(depthStencilState.depthMask);
......@@ -289,6 +311,57 @@ void StateManagerGL::setClearColor(const gl::ColorF &clearColor)
}
}
void StateManagerGL::setBlendEnabled(bool enabled)
{
if (mBlendEnabled != enabled)
{
mBlendEnabled = enabled;
if (mBlendEnabled)
{
mFunctions->enable(GL_BLEND);
}
else
{
mFunctions->disable(GL_BLEND);
}
}
}
void StateManagerGL::setBlendColor(const gl::ColorF &blendColor)
{
if (mBlendColor != blendColor)
{
mBlendColor = blendColor;
mFunctions->blendColor(mBlendColor.red, mBlendColor.green, mBlendColor.blue, mBlendColor.alpha);
}
}
void StateManagerGL::setBlendFuncs(GLenum sourceBlendRGB, GLenum destBlendRGB, GLenum sourceBlendAlpha,
GLenum destBlendAlpha)
{
if (mSourceBlendRGB != sourceBlendRGB || mDestBlendRGB != destBlendRGB ||
mSourceBlendAlpha != sourceBlendAlpha || mDestBlendAlpha != destBlendAlpha)
{
mSourceBlendRGB = sourceBlendRGB;
mDestBlendRGB = destBlendRGB;
mSourceBlendAlpha = sourceBlendAlpha;
mDestBlendAlpha = destBlendAlpha;
mFunctions->blendFuncSeparate(mSourceBlendRGB, mDestBlendRGB, mSourceBlendAlpha, mDestBlendAlpha);
}
}
void StateManagerGL::setBlendEquations(GLenum blendEquationRGB, GLenum blendEquationAlpha)
{
if (mBlendEquationRGB != blendEquationRGB || mBlendEquationAlpha != blendEquationAlpha)
{
mBlendEquationRGB = blendEquationRGB;
mBlendEquationAlpha = mDestBlendAlpha;
mFunctions->blendEquationSeparate(mBlendEquationRGB, mBlendEquationAlpha);
}
}
void StateManagerGL::setColorMask(bool red, bool green, bool blue, bool alpha)
{
if (mColorMaskRed != red || mColorMaskGreen != green || mColorMaskBlue != blue || mColorMaskAlpha != alpha)
......@@ -301,6 +374,48 @@ void StateManagerGL::setColorMask(bool red, bool green, bool blue, bool alpha)
}
}
void StateManagerGL::setSampleAlphaToCoverageEnabled(bool enabled)
{
if (mSampleAlphaToCoverageEnabled != enabled)
{
mSampleAlphaToCoverageEnabled = enabled;
if (mSampleAlphaToCoverageEnabled)
{
mFunctions->enable(GL_SAMPLE_ALPHA_TO_COVERAGE);
}
else
{
mFunctions->disable(GL_SAMPLE_ALPHA_TO_COVERAGE);
}
}
}
void StateManagerGL::setSampleCoverageEnabled(bool enabled)
{
if (mSampleCoverageEnabled != enabled)
{
mSampleCoverageEnabled = enabled;
if (mSampleCoverageEnabled)
{
mFunctions->enable(GL_SAMPLE_COVERAGE);
}
else
{
mFunctions->disable(GL_SAMPLE_COVERAGE);
}
}
}
void StateManagerGL::setSampleCoverage(float value, bool invert)
{
if (mSampleCoverageValue != value || mSampleCoverageInvert != invert)
{
mSampleCoverageValue = value;
mSampleCoverageInvert = invert;
mFunctions->sampleCoverage(mSampleCoverageValue, mSampleCoverageInvert);
}
}
void StateManagerGL::setClearDepth(float clearDepth)
{
if (mClearDepth != clearDepth)
......
......@@ -54,7 +54,16 @@ class StateManagerGL : angle::NonCopyable
void setScissor(const gl::Rectangle &scissor);
void setViewport(const gl::Rectangle &viewport);
void setClearColor(const gl::ColorF &clearColor);
void setBlendEnabled(bool enabled);
void setBlendColor(const gl::ColorF &blendColor);
void setBlendFuncs(GLenum sourceBlendRGB, GLenum destBlendRGB, GLenum sourceBlendAlpha, GLenum destBlendAlpha);
void setBlendEquations(GLenum blendEquationRGB, GLenum blendEquationAlpha);
void setColorMask(bool red, bool green, bool blue, bool alpha);
void setSampleAlphaToCoverageEnabled(bool enabled);
void setSampleCoverageEnabled(bool enabled);
void setSampleCoverage(float value, bool invert);
void setClearDepth(float clearDepth);
void setDepthMask(bool mask);
void setClearStencil(GLint clearStencil);
......@@ -79,10 +88,23 @@ class StateManagerGL : angle::NonCopyable
gl::Rectangle mViewport;
gl::ColorF mClearColor;
bool mBlendEnabled;
gl::ColorF mBlendColor;
GLenum mSourceBlendRGB;
GLenum mDestBlendRGB;
GLenum mSourceBlendAlpha;
GLenum mDestBlendAlpha;
GLenum mBlendEquationRGB;
GLenum mBlendEquationAlpha;
bool mColorMaskRed;
bool mColorMaskGreen;
bool mColorMaskBlue;
bool mColorMaskAlpha;
bool mSampleAlphaToCoverageEnabled;
bool mSampleCoverageEnabled;
float mSampleCoverageValue;
bool mSampleCoverageInvert;
float mClearDepth;
bool mDepthMask;
......
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