]> git.mxchange.org Git - simgear.git/commitdiff
Fix render order of canvas elements
authorThomas Geymayer <tomgey@gmail.com>
Fri, 12 Jul 2013 14:13:06 +0000 (16:13 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 12 Jul 2013 14:13:06 +0000 (16:13 +0200)
simgear/canvas/Canvas.cxx
simgear/canvas/ODGauge.cxx
simgear/canvas/elements/CanvasElement.cxx
simgear/canvas/elements/CanvasText.cxx

index d2f97ed1ec85ff56c473a8bd2599abe0eab9a810..fa6712389c22ecaf2357cfb9b225f98f090ed63d 100644 (file)
@@ -227,9 +227,6 @@ namespace canvas
 
       camera->addChild(_root_group->getMatrixTransform());
 
-      // Ensure objects are drawn in order of traversal
-      camera->getOrCreateStateSet()->setBinName("TraversalOrderBin");
-
       if( _texture.serviceable() )
       {
         setStatusFlags(STATUS_OK);
index ce49eb31316370fd68046f33e86f854a07083b9a..ebc92fe582d309eb07ee815be77f38f1a80ca585 100644 (file)
@@ -43,6 +43,7 @@
 #include <osg/ShadeModel>
 #include <osg/StateSet>
 #include <osg/FrameBufferObject> // for GL_DEPTH_STENCIL_EXT on Windows
+#include <osgUtil/RenderBin>
 
 #include <cassert>
 
@@ -51,6 +52,46 @@ namespace simgear
 namespace canvas
 {
 
+  class PreOrderBin:
+    public osgUtil::RenderBin
+  {
+    public:
+
+      PreOrderBin()
+      {}
+      PreOrderBin( const RenderBin& rhs,
+                   const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ):
+        RenderBin(rhs, copyop)
+      {}
+
+      virtual osg::Object* cloneType() const
+      {
+        return new PreOrderBin();
+      }
+      virtual osg::Object* clone(const osg::CopyOp& copyop) const
+      {
+        return new PreOrderBin(*this,copyop);
+      }
+      virtual bool isSameKindAs(const osg::Object* obj) const
+      {
+        return dynamic_cast<const PreOrderBin*>(obj) != 0L;
+      }
+      virtual const char* className() const
+      {
+        return "PreOrderBin";
+      }
+
+      virtual void sort()
+      {
+        // Do not sort to keep traversal order...
+      }
+  };
+
+  OSG_INIT_SINGLETON_PROXY(
+    PreOrderBinProxy,
+    (osgUtil::RenderBin::addRenderBinPrototype("PreOrderBin", new PreOrderBin))
+  );
+
   //----------------------------------------------------------------------------
   ODGauge::ODGauge():
     _size_x( -1 ),
index 8d33eff2ce308b72bdf2e9d9276209067a9d54a3..a12711691770db7fb5aa849cda230ebe93447bc8 100644 (file)
@@ -521,6 +521,15 @@ namespace canvas
     {
       addStyle("clip", "", &Element::setClip, false);
     }
+
+    // Ensure elements are drawn in order they appear in the element tree
+    _transform->getOrCreateStateSet()
+              ->setRenderBinDetails
+              (
+                0,
+                "PreOrderBin",
+                osg::StateSet::OVERRIDE_RENDERBIN_DETAILS
+              );
   }
 
   //----------------------------------------------------------------------------
index 1aca55dbe16a2b8b524c380cad64fd325433a505..e04ff79e7adc5630bf83bb4c79dfd5275e0f72cc 100644 (file)
@@ -54,7 +54,7 @@ namespace canvas
   Text::TextOSG::TextOSG(canvas::Text* text):
     _text_element(text)
   {
-
+    setBackdropImplementation(NO_DEPTH_BUFFER);
   }
 
   //----------------------------------------------------------------------------