X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fcanvas%2FODGauge.cxx;h=5c547eafa1af784ddc0cfffb46f278bad1cae190;hb=519326f7518b6e8760a53db6ebebd692655ef7be;hp=45edf9a9fa2e39e79667b641899449a1e3024192;hpb=7dd83dd2d11a1e0ffc0a8d3f21b4eb497ebc5985;p=simgear.git diff --git a/simgear/canvas/ODGauge.cxx b/simgear/canvas/ODGauge.cxx index 45edf9a9..5c547eaf 100644 --- a/simgear/canvas/ODGauge.cxx +++ b/simgear/canvas/ODGauge.cxx @@ -29,6 +29,7 @@ #endif #include "ODGauge.hxx" +#include "Canvas.hxx" #include "CanvasSystemAdapter.hxx" #include @@ -43,6 +44,7 @@ #include #include #include // for GL_DEPTH_STENCIL_EXT on Windows +#include #include @@ -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(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) { @@ -98,6 +146,12 @@ namespace canvas updateCoordinateFrame(); } + //---------------------------------------------------------------------------- + osg::Vec2s ODGauge::getViewSize() const + { + return osg::Vec2s(_view_width, _view_height); + } + //---------------------------------------------------------------------------- void ODGauge::useImageCoords(bool use) { @@ -154,7 +208,7 @@ namespace canvas } //---------------------------------------------------------------------------- - bool ODGauge::serviceable(void) + bool ODGauge::serviceable() const { return _flags & AVAILABLE; } @@ -195,6 +249,7 @@ namespace canvas if( !texture ) { texture = new osg::Texture2D; + texture->setResizeNonPowerOfTwoHint(false); texture->setTextureSize(_size_x, _size_y); texture->setInternalFormat(GL_RGBA); } @@ -202,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; } @@ -219,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();