mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-05 20:55:58 +00:00
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:
parent
376f1c6a8e
commit
f51be34864
@ -22,8 +22,8 @@ namespace backend {
|
|||||||
|
|
||||||
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
|
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
|
||||||
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
|
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
|
||||||
depthInfo(builder->depthInfo),
|
depthInfo(builder->depthInfo), backStencilInfo(builder->backStencilInfo),
|
||||||
stencilInfos { builder->stencilInfos[0], builder->stencilInfos[1] } {
|
frontStencilInfo(builder->frontStencilInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DepthStencilStateBase::DepthIsEnabled() const {
|
bool DepthStencilStateBase::DepthIsEnabled() const {
|
||||||
@ -38,15 +38,12 @@ namespace backend {
|
|||||||
return depthInfo;
|
return depthInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil(nxt::Face face) const {
|
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetBackStencil() const {
|
||||||
switch (face) {
|
return backStencilInfo;
|
||||||
case nxt::Face::Back:
|
}
|
||||||
return stencilInfos[0];
|
|
||||||
case nxt::Face::Front:
|
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetFrontStencil() const {
|
||||||
return stencilInfos[1];
|
return frontStencilInfo;
|
||||||
default:
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,40 +75,34 @@ namespace backend {
|
|||||||
void DepthStencilStateBuilder::SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
void DepthStencilStateBuilder::SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
||||||
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass) {
|
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass) {
|
||||||
if (face & nxt::Face::Back) {
|
if (face & nxt::Face::Back) {
|
||||||
auto& stencilInfo = stencilInfos[0];
|
backStencilInfo.stencilFail = stencilFail;
|
||||||
stencilInfo.stencilFail = stencilFail;
|
backStencilInfo.depthFail = stencilFail;
|
||||||
stencilInfo.depthFail = stencilFail;
|
backStencilInfo.stencilPass = stencilPass;
|
||||||
stencilInfo.stencilPass = stencilPass;
|
|
||||||
}
|
}
|
||||||
if (face & nxt::Face::Front) {
|
if (face & nxt::Face::Front) {
|
||||||
auto& stencilInfo = stencilInfos[1];
|
frontStencilInfo.stencilFail = stencilFail;
|
||||||
stencilInfo.stencilFail = stencilFail;
|
frontStencilInfo.depthFail = stencilFail;
|
||||||
stencilInfo.depthFail = stencilFail;
|
frontStencilInfo.stencilPass = stencilPass;
|
||||||
stencilInfo.stencilPass = stencilPass;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction) {
|
void DepthStencilStateBuilder::SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction) {
|
||||||
if (face & nxt::Face::Back) {
|
if (face & nxt::Face::Back) {
|
||||||
auto& stencilInfo = stencilInfos[0];
|
backStencilInfo.compareFunction = stencilCompareFunction;
|
||||||
stencilInfo.compareFunction = stencilCompareFunction;
|
|
||||||
}
|
}
|
||||||
if (face & nxt::Face::Front) {
|
if (face & nxt::Face::Front) {
|
||||||
auto& stencilInfo = stencilInfos[1];
|
frontStencilInfo.compareFunction = stencilCompareFunction;
|
||||||
stencilInfo.compareFunction = stencilCompareFunction;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetStencilMask(nxt::Face face, uint32_t readMask, uint32_t writeMask) {
|
void DepthStencilStateBuilder::SetStencilMask(nxt::Face face, uint32_t readMask, uint32_t writeMask) {
|
||||||
if (face & nxt::Face::Back) {
|
if (face & nxt::Face::Back) {
|
||||||
auto& stencilInfo = stencilInfos[0];
|
backStencilInfo.readMask = readMask;
|
||||||
stencilInfo.readMask = readMask;
|
backStencilInfo.writeMask = writeMask;
|
||||||
stencilInfo.writeMask = writeMask;
|
|
||||||
}
|
}
|
||||||
if (face & nxt::Face::Front) {
|
if (face & nxt::Face::Front) {
|
||||||
auto& stencilInfo = stencilInfos[1];
|
frontStencilInfo.readMask = readMask;
|
||||||
stencilInfo.readMask = readMask;
|
frontStencilInfo.writeMask = writeMask;
|
||||||
stencilInfo.writeMask = writeMask;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,13 +45,15 @@ namespace backend {
|
|||||||
bool DepthIsEnabled() const;
|
bool DepthIsEnabled() const;
|
||||||
bool StencilIsEnabled() const;
|
bool StencilIsEnabled() const;
|
||||||
const DepthInfo& GetDepth() const;
|
const DepthInfo& GetDepth() const;
|
||||||
const StencilInfo& GetStencil(nxt::Face face) const;
|
const StencilInfo& GetBackStencil() const;
|
||||||
|
const StencilInfo& GetFrontStencil() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool depthEnabled = false;
|
bool depthEnabled = false;
|
||||||
bool stencilEnabled = false;
|
bool stencilEnabled = false;
|
||||||
DepthInfo depthInfo;
|
DepthInfo depthInfo;
|
||||||
StencilInfo stencilInfos[2];
|
StencilInfo backStencilInfo;
|
||||||
|
StencilInfo frontStencilInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DepthStencilStateBuilder : public Builder<DepthStencilStateBase> {
|
class DepthStencilStateBuilder : public Builder<DepthStencilStateBase> {
|
||||||
@ -76,7 +78,8 @@ namespace backend {
|
|||||||
bool depthEnabled;
|
bool depthEnabled;
|
||||||
bool stencilEnabled;
|
bool stencilEnabled;
|
||||||
DepthStencilStateBase::DepthInfo depthInfo;
|
DepthStencilStateBase::DepthInfo depthInfo;
|
||||||
DepthStencilStateBase::StencilInfo stencilInfos[2];
|
DepthStencilStateBase::StencilInfo backStencilInfo;
|
||||||
|
DepthStencilStateBase::StencilInfo frontStencilInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -735,8 +735,8 @@ namespace metal {
|
|||||||
MTLStencilDescriptor* backFaceStencil = [MTLStencilDescriptor new];
|
MTLStencilDescriptor* backFaceStencil = [MTLStencilDescriptor new];
|
||||||
MTLStencilDescriptor* frontFaceStencil = [MTLStencilDescriptor new];
|
MTLStencilDescriptor* frontFaceStencil = [MTLStencilDescriptor new];
|
||||||
|
|
||||||
auto& back = GetStencil(nxt::Face::Back);
|
auto& back = GetBackStencil();
|
||||||
auto& front = GetStencil(nxt::Face::Front);
|
auto& front = GetFrontStencil();
|
||||||
|
|
||||||
backFaceStencil.stencilCompareFunction = DepthStencilCompareFunction(back.compareFunction);
|
backFaceStencil.stencilCompareFunction = DepthStencilCompareFunction(back.compareFunction);
|
||||||
backFaceStencil.stencilFailureOperation = StencilOperation(back.stencilFail);
|
backFaceStencil.stencilFailureOperation = StencilOperation(back.stencilFail);
|
||||||
|
@ -214,8 +214,8 @@ namespace opengl {
|
|||||||
|
|
||||||
if (StencilIsEnabled()) {
|
if (StencilIsEnabled()) {
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
auto& back = GetStencil(nxt::Face::Back);
|
auto& back = GetBackStencil();
|
||||||
auto& front = GetStencil(nxt::Face::Front);
|
auto& front = GetFrontStencil();
|
||||||
|
|
||||||
glStencilOpSeparate(GL_BACK,
|
glStencilOpSeparate(GL_BACK,
|
||||||
OpenGLStencilOperation(back.stencilFail),
|
OpenGLStencilOperation(back.stencilFail),
|
||||||
@ -238,8 +238,8 @@ namespace opengl {
|
|||||||
|
|
||||||
void DepthStencilState::ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference) {
|
void DepthStencilState::ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference) {
|
||||||
if (StencilIsEnabled()) {
|
if (StencilIsEnabled()) {
|
||||||
auto& back = GetStencil(nxt::Face::Back);
|
auto& back = GetBackStencil();
|
||||||
auto& front = GetStencil(nxt::Face::Front);
|
auto& front = GetFrontStencil();
|
||||||
glStencilFuncSeparate(GL_BACK,
|
glStencilFuncSeparate(GL_BACK,
|
||||||
OpenGLCompareFunction(back.compareFunction),
|
OpenGLCompareFunction(back.compareFunction),
|
||||||
backReference,
|
backReference,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user