]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/ODGauge.cxx
Add simple keyboard event demo application.
[simgear.git] / simgear / canvas / ODGauge.cxx
index 17858db7514afb035a09786b4acd8a2e8730d12b..5c547eafa1af784ddc0cfffb46f278bad1cae190 100644 (file)
@@ -29,6 +29,7 @@
 #endif
 
 #include "ODGauge.hxx"
+#include "Canvas.hxx"
 #include "CanvasSystemAdapter.hxx"
 
 #include <simgear/debug/logstream.hxx>
@@ -43,6 +44,7 @@
 #include <osg/ShadeModel>
 #include <osg/StateSet>
 #include <osg/FrameBufferObject> // for GL_DEPTH_STENCIL_EXT on Windows
+#include <osgUtil/RenderBin>
 
 #include <cassert>
 
@@ -51,6 +53,58 @@ 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...
+      }
+  };
+
+#ifndef OSG_INIT_SINGLETON_PROXY
+  /**
+   * http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk/include/osg/Object
+   *
+   * Helper macro that creates a static proxy object to call singleton function
+   * on it's construction, ensuring that the singleton gets initialized at
+   * startup.
+   */
+#  define OSG_INIT_SINGLETON_PROXY(ProxyName, Func)\
+          static struct ProxyName{ ProxyName() { Func; } } s_##ProxyName;
+#endif
+
+  OSG_INIT_SINGLETON_PROXY(
+    PreOrderBinProxy,
+    (osgUtil::RenderBin::addRenderBinPrototype("PreOrderBin", new PreOrderBin))
+  );
+
   //----------------------------------------------------------------------------
   ODGauge::ODGauge():
     _size_x( -1 ),
@@ -70,12 +124,6 @@ namespace canvas
     clear();
   }
 
-  //----------------------------------------------------------------------------
-  void ODGauge::setSystemAdapter(const SystemAdapterPtr& system_adapter)
-  {
-    _system_adapter = system_adapter;
-  }
-
   //----------------------------------------------------------------------------
   void ODGauge::setSize(int size_x, int size_y)
   {
@@ -160,7 +208,7 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  bool ODGauge::serviceable(void)
+  bool ODGauge::serviceable() const
   {
     return _flags & AVAILABLE;
   }
@@ -201,6 +249,7 @@ namespace canvas
     if( !texture )
     {
       texture = new osg::Texture2D;
+      texture->setResizeNonPowerOfTwoHint(false);
       texture->setTextureSize(_size_x, _size_y);
       texture->setInternalFormat(GL_RGBA);
     }
@@ -208,8 +257,8 @@ namespace canvas
     updateSampling();
     updateBlendMode();
 
-    if( _system_adapter )
-      _system_adapter->addCamera(camera.get());
+    if( Canvas::getSystemAdapter() )
+      Canvas::getSystemAdapter()->addCamera(camera.get());
 
     _flags |= AVAILABLE;
   }
@@ -225,8 +274,8 @@ namespace canvas
   //----------------------------------------------------------------------------
   void ODGauge::clear()
   {
-    if( camera.valid() && _system_adapter )
-      _system_adapter->removeCamera(camera.get());
+    if( camera.valid() && Canvas::getSystemAdapter() )
+      Canvas::getSystemAdapter()->removeCamera(camera.get());
     camera.release();
     texture.release();