summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJere Tuliniemi <jere.tuliniemi@qt.io>2020-03-02 14:39:42 +0200
committerJere Tuliniemi <jere.tuliniemi@qt.io>2020-03-03 07:45:16 +0200
commitabc9048c6806083673b44a6bcf1176bfaadb4335 (patch)
treed16ac7abf6df1ad5acfa08b014b553b44a6a8885
parentd9986892bf0cccc60c53d42dfc556d37226cf5d2 (diff)
Add depth function customization for custom materials
Example usage: <Pass> <Depth func="greater-than-or-equal" mask="false"/> </Pass> Task-number: QT3DS-3821 Change-Id: I8cf347026ad51ec80837e7ca87fcd836115c0d74 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/dm/systems/Qt3DSDMMetaData.cpp15
-rw-r--r--src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp12
-rw-r--r--src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp5
-rw-r--r--src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h21
4 files changed, 53 insertions, 0 deletions
diff --git a/src/dm/systems/Qt3DSDMMetaData.cpp b/src/dm/systems/Qt3DSDMMetaData.cpp
index 6cae7f8..0db75da 100644
--- a/src/dm/systems/Qt3DSDMMetaData.cpp
+++ b/src/dm/systems/Qt3DSDMMetaData.cpp
@@ -4045,6 +4045,21 @@ public:
theDstBlendFuc));
// if we have blending we have transparency
theMaterial.m_HasTransparency = true;
+ } else if (AreEqual("Depth", inStream.GetNarrowElementName())) {
+ const char8_t *depthFuncStr = "";
+ const char8_t *depthMaskStr = "";
+ inStream.Att("func", depthFuncStr);
+ inStream.Att("mask", depthMaskStr);
+
+ qt3ds::render::NVRenderBoolOp::Enum depthFunc
+ = ParseBoolOp(depthFuncStr);
+ bool depthMask = true;
+
+ if (AreEqual("false", depthMaskStr))
+ depthMask = false;
+
+ theMaterial.m_CustomerMaterialCommands.push_back(
+ new SApplyDepth(depthFunc, depthMask));
} else if (AreEqual("RenderState",
inStream.GetNarrowElementName())) {
const char8_t *name = "";
diff --git a/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp b/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp
index 496d783..593687b 100644
--- a/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp
+++ b/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp
@@ -1381,6 +1381,13 @@ struct SMaterialSystem : public ICustomMaterialSystem
}
}
+ void ApplyDepth(const SApplyDepth &inCommand)
+ {
+ NVRenderContext &theContext(m_Context->GetRenderContext());
+ theContext.SetDepthFunction(inCommand.m_depthFunc);
+ theContext.SetDepthWriteEnabled(inCommand.m_depthMask);
+ }
+
void ApplyBlending(const SApplyBlending &inCommand)
{
NVRenderContext &theContext(m_Context->GetRenderContext());
@@ -1847,6 +1854,9 @@ struct SMaterialSystem : public ICustomMaterialSystem
case CommandTypes::ApplyBlending:
ApplyBlending(static_cast<const SApplyBlending &>(theCommand));
break;
+ case CommandTypes::ApplyDepth:
+ ApplyDepth(static_cast<const SApplyDepth &>(theCommand));
+ break;
case CommandTypes::ApplyBufferValue:
if (theCurrentShader)
ApplyBufferValue(inMaterial, *theCurrentShader->m_Shader,
@@ -1870,6 +1880,8 @@ struct SMaterialSystem : public ICustomMaterialSystem
theContext.CreateRasterizerState(0.0, 0.0, qt3ds::render::NVRenderFaces::Back);
theContext.SetRasterizerState(state);
theContext.SetCullingEnabled(true);
+ theContext.SetDepthFunction(NVRenderBoolOp::LessThanOrEqual);
+ theContext.SetDepthWriteEnabled(true);
// Release any per-frame buffers
for (QT3DSU32 idx = 0; idx < m_AllocatedBuffers.size(); ++idx) {
diff --git a/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp b/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp
index a836989..6553ee9 100644
--- a/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp
+++ b/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp
@@ -90,6 +90,8 @@ namespace render {
return sizeof(SApplyDepthValue);
case CommandTypes::ApplyInstanceValue:
return sizeof(SApplyInstanceValue);
+ case CommandTypes::ApplyDepth:
+ return sizeof(SApplyDepth);
case CommandTypes::ApplyBlending:
return sizeof(SApplyBlending);
case CommandTypes::ApplyRenderState:
@@ -155,6 +157,9 @@ namespace render {
case CommandTypes::ApplyInstanceValue:
CopyConstructCommandT<SApplyInstanceValue>(inDataBuffer, inCommand, inStrTable);
break;
+ case CommandTypes::ApplyDepth:
+ CopyConstructCommandT<SApplyDepth>(inDataBuffer, inCommand, inStrTable);
+ break;
case CommandTypes::ApplyBlending:
CopyConstructCommandT<SApplyBlending>(inDataBuffer, inCommand, inStrTable);
break;
diff --git a/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h b/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h
index d42507b..0628d8d 100644
--- a/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h
+++ b/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h
@@ -54,6 +54,7 @@ namespace render {
// Apply the depth buffer as an input texture.
ApplyDepthValue,
Render, // Render to current FBO
+ ApplyDepth,
ApplyBlending,
ApplyRenderState, // apply a render state
ApplyBlitFramebuffer,
@@ -490,6 +491,26 @@ namespace render {
}
};
+ struct SApplyDepth : public SCommand
+ {
+ NVRenderBoolOp::Enum m_depthFunc;
+ bool m_depthMask;
+
+ SApplyDepth(NVRenderBoolOp::Enum depthFunc, bool depthMask)
+ : SCommand(CommandTypes::ApplyDepth)
+ , m_depthFunc(depthFunc)
+ , m_depthMask(depthMask)
+ {
+ }
+
+ SApplyDepth(const SApplyDepth &other, IStringTable &)
+ : SCommand(CommandTypes::ApplyDepth)
+ , m_depthFunc(other.m_depthFunc)
+ , m_depthMask(other.m_depthMask)
+ {
+ }
+ };
+
struct SApplyBlending : public SCommand
{
NVRenderSrcBlendFunc::Enum m_SrcBlendFunc;