mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 21:47:47 +00:00
Fix some nits from depth-stencil PR
This commit is contained in:
committed by
Corentin Wallez
parent
58c76b3fe4
commit
001c2ea98f
@@ -29,16 +29,14 @@ namespace backend {
|
||||
}
|
||||
|
||||
bool DepthStencilStateBase::StencilTestEnabled() const {
|
||||
return (
|
||||
stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
|
||||
return stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
|
||||
stencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.back.depthFail != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.front.compareFunction != nxt::CompareFunction::Always ||
|
||||
stencilInfo.front.stencilFail != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.front.depthFail != nxt::StencilOperation::Keep ||
|
||||
stencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep
|
||||
);
|
||||
stencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep;
|
||||
}
|
||||
|
||||
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
||||
|
||||
@@ -185,7 +185,6 @@ namespace opengl {
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
||||
// DepthStencilState* depthStencilState = ToBackend(lastPipeline->GetDepthStencilState());
|
||||
persistentPipelineState.SetStencilReference(cmd->reference);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -95,32 +95,20 @@ namespace opengl {
|
||||
|
||||
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction);
|
||||
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction);
|
||||
|
||||
persistentPipelineState.CacheStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
|
||||
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
|
||||
|
||||
glStencilOpSeparate(GL_BACK,
|
||||
OpenGLStencilOperation(stencilInfo.back.stencilFail),
|
||||
OpenGLStencilOperation(stencilInfo.back.depthFail),
|
||||
OpenGLStencilOperation(stencilInfo.back.depthStencilPass)
|
||||
);
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
backCompareFunction,
|
||||
persistentPipelineState.GetCachedStencilReference(),
|
||||
stencilInfo.readMask
|
||||
);
|
||||
glStencilMaskSeparate(GL_BACK, stencilInfo.writeMask);
|
||||
|
||||
glStencilOpSeparate(GL_FRONT,
|
||||
OpenGLStencilOperation(stencilInfo.front.stencilFail),
|
||||
OpenGLStencilOperation(stencilInfo.front.depthFail),
|
||||
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
|
||||
);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
frontCompareFunction,
|
||||
persistentPipelineState.GetCachedStencilReference(),
|
||||
stencilInfo.readMask
|
||||
);
|
||||
glStencilMaskSeparate(GL_FRONT, stencilInfo.writeMask);
|
||||
|
||||
glStencilMask(stencilInfo.writeMask);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,36 +20,40 @@ namespace backend {
|
||||
namespace opengl {
|
||||
|
||||
void PersistentPipelineState::SetDefaultState() {
|
||||
stencilBackCompareFunction = GL_ALWAYS;
|
||||
stencilFrontCompareFunction = GL_ALWAYS;
|
||||
stencilReadMask = 0xff;
|
||||
SetStencilReference(0);
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::CacheStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
||||
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
||||
if (this->stencilBackCompareFunction == stencilBackCompareFunction &&
|
||||
this->stencilFrontCompareFunction == stencilFrontCompareFunction &&
|
||||
this->stencilReadMask == stencilReadMask) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->stencilBackCompareFunction = stencilBackCompareFunction;
|
||||
this->stencilFrontCompareFunction = stencilFrontCompareFunction;
|
||||
this->stencilReadMask = stencilReadMask;
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
||||
if (this->stencilReference != stencilReference) {
|
||||
this->stencilReference = stencilReference;
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
if (this->stencilReference == stencilReference) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->stencilReference = stencilReference;
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::CallGLStencilFunc() {
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
stencilBackCompareFunction,
|
||||
stencilReference,
|
||||
stencilReadMask
|
||||
);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
stencilReadMask);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
stencilFrontCompareFunction,
|
||||
stencilReference,
|
||||
stencilReadMask
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
GLuint PersistentPipelineState::GetCachedStencilReference() const {
|
||||
return stencilReference;
|
||||
stencilReadMask);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,15 +25,16 @@ namespace opengl {
|
||||
class PersistentPipelineState {
|
||||
public:
|
||||
void SetDefaultState();
|
||||
void CacheStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask);
|
||||
void SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask);
|
||||
void SetStencilReference(uint32_t stencilReference);
|
||||
GLuint GetCachedStencilReference() const;
|
||||
|
||||
private:
|
||||
GLenum stencilBackCompareFunction;
|
||||
GLenum stencilFrontCompareFunction;
|
||||
GLuint stencilReadMask;
|
||||
GLuint stencilReference;
|
||||
void CallGLStencilFunc();
|
||||
|
||||
GLenum stencilBackCompareFunction = GL_ALWAYS;
|
||||
GLenum stencilFrontCompareFunction = GL_ALWAYS;
|
||||
GLuint stencilReadMask = 0xffffffff;
|
||||
GLuint stencilReference = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user