mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:36:30 +02:00
Merge pull request #8321 from jherico/depth_fix
Fix depth state caching / resetting
This commit is contained in:
commit
af9032e6fb
1 changed files with 46 additions and 39 deletions
|
@ -158,69 +158,76 @@ void GLBackend::do_setStateDepthBias(Vec2 bias) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::do_setStateDepthTest(State::DepthTest test) {
|
void GLBackend::do_setStateDepthTest(State::DepthTest test) {
|
||||||
if (_pipeline._stateCache.depthTest != test) {
|
const auto& current = _pipeline._stateCache.depthTest;
|
||||||
|
if (current != test) {
|
||||||
if (test.isEnabled()) {
|
if (test.isEnabled()) {
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthMask(test.getWriteMask());
|
|
||||||
glDepthFunc(COMPARISON_TO_GL[test.getFunction()]);
|
|
||||||
} else {
|
} else {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
if (test.getWriteMask() != current.getWriteMask()) {
|
||||||
|
glDepthMask(test.getWriteMask());
|
||||||
|
}
|
||||||
|
if (test.getFunction() != current.getFunction()) {
|
||||||
|
glDepthFunc(COMPARISON_TO_GL[test.getFunction()]);
|
||||||
|
}
|
||||||
if (CHECK_GL_ERROR()) {
|
if (CHECK_GL_ERROR()) {
|
||||||
qDebug() << "DepthTest" << (test.isEnabled() ? "Enabled" : "Disabled")
|
qDebug() << "DepthTest" << (test.isEnabled() ? "Enabled" : "Disabled")
|
||||||
<< "Mask=" << (test.getWriteMask() ? "Write" : "no Write")
|
<< "Mask=" << (test.getWriteMask() ? "Write" : "no Write")
|
||||||
<< "Func=" << test.getFunction()
|
<< "Func=" << test.getFunction()
|
||||||
<< "Raw=" << test.getRaw();
|
<< "Raw=" << test.getRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
_pipeline._stateCache.depthTest = test;
|
_pipeline._stateCache.depthTest = test;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::do_setStateStencil(State::StencilActivation activation, State::StencilTest frontTest, State::StencilTest backTest) {
|
void GLBackend::do_setStateStencil(State::StencilActivation activation, State::StencilTest testFront, State::StencilTest testBack) {
|
||||||
|
const auto& currentActivation = _pipeline._stateCache.stencilActivation;
|
||||||
if ((_pipeline._stateCache.stencilActivation != activation)
|
const auto& currentTestFront = _pipeline._stateCache.stencilTestFront;
|
||||||
|| (_pipeline._stateCache.stencilTestFront != frontTest)
|
const auto& currentTestBack = _pipeline._stateCache.stencilTestBack;
|
||||||
|| (_pipeline._stateCache.stencilTestBack != backTest)) {
|
if ((currentActivation != activation)
|
||||||
|
|| (currentTestFront != testFront)
|
||||||
|
|| (currentTestBack != testBack)) {
|
||||||
|
|
||||||
if (activation.isEnabled()) {
|
if (activation.isEnabled()) {
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
|
||||||
if (activation.getWriteMaskFront() != activation.getWriteMaskBack()) {
|
|
||||||
glStencilMaskSeparate(GL_FRONT, activation.getWriteMaskFront());
|
|
||||||
glStencilMaskSeparate(GL_BACK, activation.getWriteMaskBack());
|
|
||||||
} else {
|
|
||||||
glStencilMask(activation.getWriteMaskFront());
|
|
||||||
}
|
|
||||||
|
|
||||||
static GLenum STENCIL_OPS[] = {
|
|
||||||
GL_KEEP,
|
|
||||||
GL_ZERO,
|
|
||||||
GL_REPLACE,
|
|
||||||
GL_INCR_WRAP,
|
|
||||||
GL_DECR_WRAP,
|
|
||||||
GL_INVERT,
|
|
||||||
GL_INCR,
|
|
||||||
GL_DECR };
|
|
||||||
|
|
||||||
if (frontTest != backTest) {
|
|
||||||
glStencilOpSeparate(GL_FRONT, STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]);
|
|
||||||
glStencilFuncSeparate(GL_FRONT, COMPARISON_TO_GL[frontTest.getFunction()], frontTest.getReference(), frontTest.getReadMask());
|
|
||||||
|
|
||||||
glStencilOpSeparate(GL_BACK, STENCIL_OPS[backTest.getFailOp()], STENCIL_OPS[backTest.getPassOp()], STENCIL_OPS[backTest.getDepthFailOp()]);
|
|
||||||
glStencilFuncSeparate(GL_BACK, COMPARISON_TO_GL[backTest.getFunction()], backTest.getReference(), backTest.getReadMask());
|
|
||||||
} else {
|
|
||||||
glStencilOp(STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]);
|
|
||||||
glStencilFunc(COMPARISON_TO_GL[frontTest.getFunction()], frontTest.getReference(), frontTest.getReadMask());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (activation.getWriteMaskFront() != activation.getWriteMaskBack()) {
|
||||||
|
glStencilMaskSeparate(GL_FRONT, activation.getWriteMaskFront());
|
||||||
|
glStencilMaskSeparate(GL_BACK, activation.getWriteMaskBack());
|
||||||
|
} else {
|
||||||
|
glStencilMask(activation.getWriteMaskFront());
|
||||||
|
}
|
||||||
|
|
||||||
|
static GLenum STENCIL_OPS[State::NUM_STENCIL_OPS] = {
|
||||||
|
GL_KEEP,
|
||||||
|
GL_ZERO,
|
||||||
|
GL_REPLACE,
|
||||||
|
GL_INCR_WRAP,
|
||||||
|
GL_DECR_WRAP,
|
||||||
|
GL_INVERT,
|
||||||
|
GL_INCR,
|
||||||
|
GL_DECR };
|
||||||
|
|
||||||
|
if (testFront != testBack) {
|
||||||
|
glStencilOpSeparate(GL_FRONT, STENCIL_OPS[testFront.getFailOp()], STENCIL_OPS[testFront.getPassOp()], STENCIL_OPS[testFront.getDepthFailOp()]);
|
||||||
|
glStencilFuncSeparate(GL_FRONT, COMPARISON_TO_GL[testFront.getFunction()], testFront.getReference(), testFront.getReadMask());
|
||||||
|
|
||||||
|
glStencilOpSeparate(GL_BACK, STENCIL_OPS[testBack.getFailOp()], STENCIL_OPS[testBack.getPassOp()], STENCIL_OPS[testBack.getDepthFailOp()]);
|
||||||
|
glStencilFuncSeparate(GL_BACK, COMPARISON_TO_GL[testBack.getFunction()], testBack.getReference(), testBack.getReadMask());
|
||||||
|
} else {
|
||||||
|
glStencilOp(STENCIL_OPS[testFront.getFailOp()], STENCIL_OPS[testFront.getPassOp()], STENCIL_OPS[testFront.getDepthFailOp()]);
|
||||||
|
glStencilFunc(COMPARISON_TO_GL[testFront.getFunction()], testFront.getReference(), testFront.getReadMask());
|
||||||
|
}
|
||||||
|
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
|
|
||||||
_pipeline._stateCache.stencilActivation = activation;
|
_pipeline._stateCache.stencilActivation = activation;
|
||||||
_pipeline._stateCache.stencilTestFront = frontTest;
|
_pipeline._stateCache.stencilTestFront = testFront;
|
||||||
_pipeline._stateCache.stencilTestBack = backTest;
|
_pipeline._stateCache.stencilTestBack = testBack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue