From b8a6d1ac4dd3798fb1d36814f701f8eb7ead4ae1 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 23 Nov 2009 09:15:47 +0100 Subject: [PATCH] add depth attribute to Effect --- simgear/scene/material/Effect.cxx | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index b8193540..b18f4c62 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -796,6 +797,52 @@ struct VertexProgramPointSizeBuilder : public PassAttributeBuilder InstallAttributeBuilder installPointSize("vertex-program-point-size"); +EffectNameValue depthFunctionInit[] = +{ + {"never", Depth::NEVER}, + {"less", Depth::LESS}, + {"equal", Depth::EQUAL}, + {"lequal", Depth::LEQUAL}, + {"greater", Depth::GREATER}, + {"notequal", Depth::NOTEQUAL}, + {"gequal", Depth::GEQUAL}, + {"always", Depth::ALWAYS} +}; +EffectPropertyMap depthFunction(depthFunctionInit); + +struct DepthBuilder : public PassAttributeBuilder +{ + void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, + const osgDB::ReaderWriter::Options* options) + { + if (!isAttributeActive(effect, prop)) + return; + ref_ptr depth = new Depth; + const SGPropertyNode* pfunc + = getEffectPropertyChild(effect, prop, "function"); + if (pfunc) { + Depth::Function func = Depth::LESS; + findAttr(depthFunction, pfunc, func); + depth->setFunction(func); + } + const SGPropertyNode* pnear + = getEffectPropertyChild(effect, prop, "near"); + if (pnear) + depth->setZNear(pnear->getValue()); + const SGPropertyNode* pfar + = getEffectPropertyChild(effect, prop, "far"); + if (pfar) + depth->setZFar(pnear->getValue()); + const SGPropertyNode* pmask + = getEffectPropertyChild(effect, prop, "write-mask"); + if (pmask) + depth->setWriteMask(pmask->getValue()); + pass->setAttribute(depth.get()); + } +}; + +InstallAttributeBuilder installDepth("depth"); + void buildTechnique(Effect* effect, const SGPropertyNode* prop, const osgDB::ReaderWriter::Options* options) { -- 2.39.5