]> git.mxchange.org Git - simgear.git/commitdiff
Adding Icecode GL's polygon-offset support for effects
authorPSadrozinski <psadrozinski@gmail.com>
Sun, 6 Nov 2011 14:47:29 +0000 (09:47 -0500)
committerPSadrozinski <psadrozinski@gmail.com>
Sun, 6 Nov 2011 14:47:29 +0000 (09:47 -0500)
simgear/scene/material/Effect.cxx

index 33e272c1cd4530ad8d6ab41f1046e446a6dfa2c6..1a52c65948e97363f3397591c50892df05dfe598 100644 (file)
@@ -46,6 +46,7 @@
 #include <osg/Material>
 #include <osg/Math>
 #include <osg/PolygonMode>
+#include <osg/PolygonOffset>
 #include <osg/Program>
 #include <osg/Referenced>
 #include <osg/RenderInfo>
@@ -1059,6 +1060,34 @@ struct PolygonModeBuilder : public PassAttributeBuilder
 
 InstallAttributeBuilder<PolygonModeBuilder> installPolygonMode("polygon-mode");
 
+struct PolygonOffsetBuilder : public PassAttributeBuilder
+{
+    void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
+                        const SGReaderWriterXMLOptions* options)
+    {
+        if (!isAttributeActive(effect, prop))
+            return;
+        
+        const SGPropertyNode* factor
+           = getEffectPropertyChild(effect, prop, "factor");
+        const SGPropertyNode* units
+           = getEffectPropertyChild(effect, prop, "units");
+        
+        ref_ptr<PolygonOffset> polyoffset = new PolygonOffset;
+        
+        polyoffset->setFactor(factor->getFloatValue());
+        polyoffset->setUnits(units->getFloatValue());
+
+        SG_LOG(SG_INPUT, SG_BULK,
+                   "Set PolygonOffset to " << polyoffset->getFactor() << polyoffset->getUnits() );            
+
+        pass->setAttributeAndModes(polyoffset.get(),
+                                   StateAttribute::OVERRIDE|StateAttribute::ON);
+    }
+};
+
+InstallAttributeBuilder<PolygonOffsetBuilder> installPolygonOffset("polygon-offset");
+
 struct VertexProgramTwoSideBuilder : public PassAttributeBuilder
 {
     void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,