Remove DepthTestEnabled() and fix depth writes for depth function Always

This commit is contained in:
Austin Eng 2017-07-21 18:35:56 -04:00 committed by Austin Eng
parent cc8d2d529d
commit ccf1fa2330
4 changed files with 10 additions and 17 deletions

View File

@ -24,10 +24,6 @@ namespace backend {
: depthInfo(builder->depthInfo), stencilInfo(builder->stencilInfo) {
}
bool DepthStencilStateBase::DepthTestEnabled() const {
return depthInfo.compareFunction != nxt::CompareFunction::Always;
}
bool DepthStencilStateBase::StencilTestEnabled() const {
return stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
stencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||

View File

@ -47,7 +47,6 @@ namespace backend {
uint32_t writeMask = 0xff;
};
bool DepthTestEnabled() const;
bool StencilTestEnabled() const;
const DepthInfo& GetDepth() const;
const StencilInfo& GetStencil() const;

View File

@ -67,14 +67,11 @@ namespace metal {
: DepthStencilStateBase(builder) {
MTLDepthStencilDescriptor* mtlDepthStencilDescriptor = [MTLDepthStencilDescriptor new];
if (DepthTestEnabled()) {
auto& depth = GetDepth();
mtlDepthStencilDescriptor.depthCompareFunction = MetalDepthStencilCompareFunction(depth.compareFunction);
mtlDepthStencilDescriptor.depthWriteEnabled = depth.depthWriteEnabled;
}
auto& depth = GetDepth();
mtlDepthStencilDescriptor.depthCompareFunction = MetalDepthStencilCompareFunction(depth.compareFunction);
mtlDepthStencilDescriptor.depthWriteEnabled = depth.depthWriteEnabled;
auto& stencil = GetStencil();
if (StencilTestEnabled()) {
MTLStencilDescriptor* backFaceStencil = [MTLStencilDescriptor new];
MTLStencilDescriptor* frontFaceStencil = [MTLStencilDescriptor new];

View File

@ -74,14 +74,15 @@ namespace opengl {
}
void DepthStencilState::ApplyNow(PersistentPipelineState &persistentPipelineState) const {
if (DepthTestEnabled()) {
glEnable(GL_DEPTH_TEST);
} else {
glDisable(GL_DEPTH_TEST);
}
auto& depthInfo = GetDepth();
// Depth writes only occur if depth is enabled
if (depthInfo.compareFunction == nxt::CompareFunction::Always && !depthInfo.depthWriteEnabled) {
glDisable(GL_DEPTH_TEST);
} else {
glEnable(GL_DEPTH_TEST);
}
if (depthInfo.depthWriteEnabled) {
glDepthMask(GL_TRUE);
} else {