Use explicit front and back stencil state.

Previously stencil states were stored in array. This commit changes the
DepthStencilState to explicitly store a front and back stencil.
This commit is contained in:
Austin Eng 2017-05-31 09:29:05 -04:00 committed by Corentin Wallez
parent 376f1c6a8e
commit f51be34864
4 changed files with 37 additions and 43 deletions

View File

@ -22,8 +22,8 @@ namespace backend {
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
depthInfo(builder->depthInfo),
stencilInfos { builder->stencilInfos[0], builder->stencilInfos[1] } {
depthInfo(builder->depthInfo), backStencilInfo(builder->backStencilInfo),
frontStencilInfo(builder->frontStencilInfo) {
}
bool DepthStencilStateBase::DepthIsEnabled() const {
@ -38,15 +38,12 @@ namespace backend {
return depthInfo;
}
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil(nxt::Face face) const {
switch (face) {
case nxt::Face::Back:
return stencilInfos[0];
case nxt::Face::Front:
return stencilInfos[1];
default:
ASSERT(false);
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetBackStencil() const {
return backStencilInfo;
}
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetFrontStencil() const {
return frontStencilInfo;
}
@ -78,40 +75,34 @@ namespace backend {
void DepthStencilStateBuilder::SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass) {
if (face & nxt::Face::Back) {
auto& stencilInfo = stencilInfos[0];
stencilInfo.stencilFail = stencilFail;
stencilInfo.depthFail = stencilFail;
stencilInfo.stencilPass = stencilPass;
backStencilInfo.stencilFail = stencilFail;
backStencilInfo.depthFail = stencilFail;
backStencilInfo.stencilPass = stencilPass;
}
if (face & nxt::Face::Front) {
auto& stencilInfo = stencilInfos[1];
stencilInfo.stencilFail = stencilFail;
stencilInfo.depthFail = stencilFail;
stencilInfo.stencilPass = stencilPass;
frontStencilInfo.stencilFail = stencilFail;
frontStencilInfo.depthFail = stencilFail;
frontStencilInfo.stencilPass = stencilPass;
}
}
void DepthStencilStateBuilder::SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction) {
if (face & nxt::Face::Back) {
auto& stencilInfo = stencilInfos[0];
stencilInfo.compareFunction = stencilCompareFunction;
backStencilInfo.compareFunction = stencilCompareFunction;
}
if (face & nxt::Face::Front) {
auto& stencilInfo = stencilInfos[1];
stencilInfo.compareFunction = stencilCompareFunction;
frontStencilInfo.compareFunction = stencilCompareFunction;
}
}
void DepthStencilStateBuilder::SetStencilMask(nxt::Face face, uint32_t readMask, uint32_t writeMask) {
if (face & nxt::Face::Back) {
auto& stencilInfo = stencilInfos[0];
stencilInfo.readMask = readMask;
stencilInfo.writeMask = writeMask;
backStencilInfo.readMask = readMask;
backStencilInfo.writeMask = writeMask;
}
if (face & nxt::Face::Front) {
auto& stencilInfo = stencilInfos[1];
stencilInfo.readMask = readMask;
stencilInfo.writeMask = writeMask;
frontStencilInfo.readMask = readMask;
frontStencilInfo.writeMask = writeMask;
}
}

View File

@ -45,13 +45,15 @@ namespace backend {
bool DepthIsEnabled() const;
bool StencilIsEnabled() const;
const DepthInfo& GetDepth() const;
const StencilInfo& GetStencil(nxt::Face face) const;
const StencilInfo& GetBackStencil() const;
const StencilInfo& GetFrontStencil() const;
private:
bool depthEnabled = false;
bool stencilEnabled = false;
DepthInfo depthInfo;
StencilInfo stencilInfos[2];
StencilInfo backStencilInfo;
StencilInfo frontStencilInfo;
};
class DepthStencilStateBuilder : public Builder<DepthStencilStateBase> {
@ -76,7 +78,8 @@ namespace backend {
bool depthEnabled;
bool stencilEnabled;
DepthStencilStateBase::DepthInfo depthInfo;
DepthStencilStateBase::StencilInfo stencilInfos[2];
DepthStencilStateBase::StencilInfo backStencilInfo;
DepthStencilStateBase::StencilInfo frontStencilInfo;
};
}

View File

@ -735,8 +735,8 @@ namespace metal {
MTLStencilDescriptor* backFaceStencil = [MTLStencilDescriptor new];
MTLStencilDescriptor* frontFaceStencil = [MTLStencilDescriptor new];
auto& back = GetStencil(nxt::Face::Back);
auto& front = GetStencil(nxt::Face::Front);
auto& back = GetBackStencil();
auto& front = GetFrontStencil();
backFaceStencil.stencilCompareFunction = DepthStencilCompareFunction(back.compareFunction);
backFaceStencil.stencilFailureOperation = StencilOperation(back.stencilFail);

View File

@ -214,8 +214,8 @@ namespace opengl {
if (StencilIsEnabled()) {
glEnable(GL_STENCIL_TEST);
auto& back = GetStencil(nxt::Face::Back);
auto& front = GetStencil(nxt::Face::Front);
auto& back = GetBackStencil();
auto& front = GetFrontStencil();
glStencilOpSeparate(GL_BACK,
OpenGLStencilOperation(back.stencilFail),
@ -238,8 +238,8 @@ namespace opengl {
void DepthStencilState::ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference) {
if (StencilIsEnabled()) {
auto& back = GetStencil(nxt::Face::Back);
auto& front = GetStencil(nxt::Face::Front);
auto& back = GetBackStencil();
auto& front = GetFrontStencil();
glStencilFuncSeparate(GL_BACK,
OpenGLCompareFunction(back.compareFunction),
backReference,