From 791273c61de23d2ec383a270db27015d235a9938 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sat, 9 Aug 2014 17:18:21 +0200 Subject: [PATCH] Update for OpenSceneGraph 3.3.2 API changes. --- simgear/canvas/ODGauge.cxx | 11 ++++- simgear/canvas/elements/CanvasElement.cxx | 13 ++++- simgear/canvas/elements/CanvasImage.cxx | 9 +++- simgear/canvas/elements/CanvasPath.cxx | 9 +++- simgear/canvas/elements/CanvasText.cxx | 23 +++++++-- simgear/scene/material/EffectGeode.hxx | 47 +++++++++++++++++- simgear/scene/material/Technique.cxx | 53 +++++++++++++-------- simgear/scene/sky/CloudShaderGeometry.hxx | 8 +++- simgear/scene/tgdb/SGVasiDrawable.cxx | 7 ++- simgear/scene/tgdb/SGVasiDrawable.hxx | 11 ++++- simgear/scene/tgdb/ShaderGeometry.cxx | 16 ++++++- simgear/scene/tgdb/ShaderGeometry.hxx | 9 +++- simgear/scene/util/SGEnlargeBoundingBox.cxx | 10 +++- simgear/scene/util/UpdateOnceCallback.cxx | 1 + 14 files changed, 190 insertions(+), 37 deletions(-) diff --git a/simgear/canvas/ODGauge.cxx b/simgear/canvas/ODGauge.cxx index 5c547eaf..4a2b7fac 100644 --- a/simgear/canvas/ODGauge.cxx +++ b/simgear/canvas/ODGauge.cxx @@ -44,6 +44,7 @@ #include #include #include // for GL_DEPTH_STENCIL_EXT on Windows +#include #include #include @@ -266,7 +267,15 @@ namespace canvas //---------------------------------------------------------------------------- void ODGauge::reinit() { - osg::NodeCallback* cull_callback = camera ? camera->getCullCallback() : 0; + osg::NodeCallback* cull_callback = + camera +#if OSG_VERSION_LESS_THAN(3,3,2) + ? camera->getCullCallback() +#else + ? dynamic_cast(camera->getCullCallback()) +#endif + : 0; + clear(); allocRT(cull_callback); } diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 478cfb8b..f8952925 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -649,7 +650,11 @@ namespace canvas osg::BoundingBox Element::getBoundingBox() const { if( _drawable ) +#if OSG_VERSION_LESS_THAN(3,3,2) return _drawable->getBound(); +#else + return _drawable->getBoundingBox(); +#endif osg::BoundingBox bb; @@ -672,7 +677,13 @@ namespace canvas return osg::BoundingBox(); osg::BoundingBox transformed; - const osg::BoundingBox& bb = _drawable->getBound(); + const osg::BoundingBox& bb = +#if OSG_VERSION_LESS_THAN(3,3,2) + _drawable->getBound(); +#else + _drawable->getBoundingBox(); +#endif + for(int i = 0; i < 4; ++i) transformed.expandBy( bb.corner(i) * m ); diff --git a/simgear/canvas/elements/CanvasImage.cxx b/simgear/canvas/elements/CanvasImage.cxx index 4f4ffc7b..c89c71a4 100644 --- a/simgear/canvas/elements/CanvasImage.cxx +++ b/simgear/canvas/elements/CanvasImage.cxx @@ -413,7 +413,14 @@ namespace canvas && child->getNameString() == "visible" && child->getBoolValue() ) { - CullCallback* cb = static_cast(_geom->getCullCallback()); + CullCallback* cb = +#if OSG_VERSION_LESS_THAN(3,3,2) + static_cast +#else + dynamic_cast +#endif + ( _geom->getCullCallback() ); + if( cb ) cb->cullNextFrame(); } diff --git a/simgear/canvas/elements/CanvasPath.cxx b/simgear/canvas/elements/CanvasPath.cxx index ba5351fe..9eddcb31 100644 --- a/simgear/canvas/elements/CanvasPath.cxx +++ b/simgear/canvas/elements/CanvasPath.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -372,7 +373,13 @@ namespace canvas /** * Compute the bounding box */ - virtual osg::BoundingBox computeBound() const + virtual osg::BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) + computeBound() +#else + computeBoundingBox() +#endif + const { if( _path == VG_INVALID_HANDLE || (_attributes_dirty & PATH) ) return osg::BoundingBox(); diff --git a/simgear/canvas/elements/CanvasText.cxx b/simgear/canvas/elements/CanvasText.cxx index ebe76d41..239383ca 100644 --- a/simgear/canvas/elements/CanvasText.cxx +++ b/simgear/canvas/elements/CanvasText.cxx @@ -45,7 +45,13 @@ namespace canvas SGVec2i sizeForWidth(int w) const; osg::Vec2 handleHit(const osg::Vec2f& pos); - virtual osg::BoundingBox computeBound() const; + virtual osg::BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) + computeBound() +#else + computeBoundingBox() +#endif + const; protected: @@ -467,9 +473,20 @@ namespace canvas } //---------------------------------------------------------------------------- - osg::BoundingBox Text::TextOSG::computeBound() const + osg::BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) + Text::TextOSG::computeBound() +#else + Text::TextOSG::computeBoundingBox() +#endif + const { - osg::BoundingBox bb = osgText::Text::computeBound(); + osg::BoundingBox bb = +#if OSG_VERSION_LESS_THAN(3,3,2) + osgText::Text::computeBound(); +#else + osgText::Text::computeBoundingBox(); +#endif #if OSG_VERSION_LESS_THAN(3,1,0) if( bb.valid() ) diff --git a/simgear/scene/material/EffectGeode.hxx b/simgear/scene/material/EffectGeode.hxx index 515b1a0a..34b87e3a 100644 --- a/simgear/scene/material/EffectGeode.hxx +++ b/simgear/scene/material/EffectGeode.hxx @@ -18,6 +18,9 @@ #define SIMGEAR_EFFECT_GEODE_HXX 1 #include +#include + +#include #include "Effect.hxx" @@ -25,7 +28,41 @@ namespace simgear { class EffectGeode : public osg::Geode { -public: + public: + +#if OSG_VERSION_LESS_THAN(3,3,2) + typedef DrawableList::iterator DrawablesIterator; +#else + class DrawablesIterator: + public boost::iterator_adaptor< + DrawablesIterator, + osg::NodeList::iterator, + osg::ref_ptr, + boost::use_default, + osg::ref_ptr // No reference as Reference type. + // The child list does not contain Drawable + // ref_ptr so we can not return any + // references to them. + > + { + public: + + DrawablesIterator() + {} + + explicit DrawablesIterator(osg::NodeList::iterator const& node_it): + DrawablesIterator::iterator_adaptor_(node_it) + {} + + private: + friend class boost::iterator_core_access; + osg::ref_ptr dereference() const + { + return base_reference()->get()->asDrawable(); + } + }; +#endif + EffectGeode(); EffectGeode(const EffectGeode& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); @@ -34,9 +71,15 @@ public: void setEffect(Effect* effect); virtual void resizeGLObjectBuffers(unsigned int maxSize); virtual void releaseGLObjects(osg::State* = 0) const; - typedef DrawableList::iterator DrawablesIterator; + +#if OSG_VERSION_LESS_THAN(3,3,2) DrawablesIterator drawablesBegin() { return _drawables.begin(); } DrawablesIterator drawablesEnd() { return _drawables.end(); } +#else + DrawablesIterator drawablesBegin() { return DrawablesIterator(_children.begin()); } + DrawablesIterator drawablesEnd() { return DrawablesIterator(_children.end()); } +#endif + void runGenerators(osg::Geometry *geometry); private: osg::ref_ptr _effect; diff --git a/simgear/scene/material/Technique.cxx b/simgear/scene/material/Technique.cxx index d5d9b069..93a17b87 100644 --- a/simgear/scene/material/Technique.cxx +++ b/simgear/scene/material/Technique.cxx @@ -140,27 +140,40 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin, EffectGeode::DrawablesIterator itr = begin; bool computeNearFar = cv->getComputeNearFarMode() != CullVisitor::DO_NOT_COMPUTE_NEAR_FAR; - for (int i = 0; i < NUM_DRAWABLES && itr != end; ++itr, ++i) { - Drawable* drawable = itr->get(); - const BoundingBox& bb = drawable->getBound(); - if ((drawable->getCullCallback() - && drawable->getCullCallback()->cull(cv, drawable, - &cv->getRenderInfo())) - || (isCullingActive && cv->isCulled(bb))) { - depth[i] = FLT_MAX; - continue; - } - if (computeNearFar && bb.valid()) { - if (!cv->updateCalculatedNearFar(matrix, *drawable, false)) { - depth[i] = FLT_MAX; - continue; - } + for (int i = 0; i < NUM_DRAWABLES && itr != end; ++itr, ++i) + { + Drawable* drawable = itr->get(); + +#if OSG_VERSION_LESS_THAN(3,3,2) + const BoundingBox& bb = drawable->getBound(); + osg::Drawable::CullCallback* cull = drawable->getCullCallback(); +#else + const BoundingBox& bb = drawable->getBoundingBox(); + osg::Drawable::CullCallback* cull = + dynamic_cast(drawable->getCullCallback()); +#endif + + if( (cull && cull->cull(cv, drawable, &cv->getRenderInfo())) + || (isCullingActive && cv->isCulled(bb)) ) + { + depth[i] = FLT_MAX; + continue; + } + + if( computeNearFar && bb.valid() ) + { + if( !cv->updateCalculatedNearFar(matrix, *drawable, false) ) + { + depth[i] = FLT_MAX; + continue; } - depth[i] = (bb.valid() - ? cv->getDistanceFromEyePoint(bb.center(), false) - : 0.0f); - if (isNaN(depth[i])) - depth[i] = FLT_MAX; + } + + depth[i] = bb.valid() + ? cv->getDistanceFromEyePoint(bb.center(), false) + : 0.0f; + if( isNaN(depth[i]) ) + depth[i] = FLT_MAX; } EffectCullVisitor* ecv = dynamic_cast( cv ); EffectGeode::DrawablesIterator drawablesEnd = itr; diff --git a/simgear/scene/sky/CloudShaderGeometry.hxx b/simgear/scene/sky/CloudShaderGeometry.hxx index 20d0db81..6d78af2f 100644 --- a/simgear/scene/sky/CloudShaderGeometry.hxx +++ b/simgear/scene/sky/CloudShaderGeometry.hxx @@ -95,7 +95,13 @@ class CloudShaderGeometry : public osg::Drawable { return _cloudsprites[i]; } virtual void drawImplementation(osg::RenderInfo& renderInfo) const; - virtual osg::BoundingBox computeBound() const + virtual osg::BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) + computeBound() +#else + computeBoundingBox() +#endif + const { return _bbox; } diff --git a/simgear/scene/tgdb/SGVasiDrawable.cxx b/simgear/scene/tgdb/SGVasiDrawable.cxx index bb3ce0e4..d66474fe 100644 --- a/simgear/scene/tgdb/SGVasiDrawable.cxx +++ b/simgear/scene/tgdb/SGVasiDrawable.cxx @@ -104,7 +104,12 @@ SGVasiDrawable::drawImplementation(osg::RenderInfo& renderInfo) const } osg::BoundingBox -SGVasiDrawable::computeBound() const +#if OSG_VERSION_LESS_THAN(3,3,2) +SGVasiDrawable::computeBound() +#else +SGVasiDrawable::computeBoundingBox() +#endif +const { osg::BoundingBox bb; for (unsigned i = 0; i < _lights.size(); ++i) diff --git a/simgear/scene/tgdb/SGVasiDrawable.hxx b/simgear/scene/tgdb/SGVasiDrawable.hxx index 242e3935..e4b0479a 100644 --- a/simgear/scene/tgdb/SGVasiDrawable.hxx +++ b/simgear/scene/tgdb/SGVasiDrawable.hxx @@ -23,9 +23,10 @@ #define _SG_VASI_DRAWABLE_HXX #include +#include #include -#include +#include class SGVasiDrawable : public osg::Drawable { struct LightData; @@ -49,7 +50,13 @@ public: const SGVec3f& up); virtual void drawImplementation(osg::RenderInfo& renderInfo) const; - virtual osg::BoundingBox computeBound() const; + virtual osg::BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) + computeBound() +#else + computeBoundingBox() +#endif + const; private: SGVec4f getColor(float angleDeg) const; diff --git a/simgear/scene/tgdb/ShaderGeometry.cxx b/simgear/scene/tgdb/ShaderGeometry.cxx index 36a30934..5d286c31 100644 --- a/simgear/scene/tgdb/ShaderGeometry.cxx +++ b/simgear/scene/tgdb/ShaderGeometry.cxx @@ -60,9 +60,21 @@ void ShaderGeometry::drawImplementation(osg::RenderInfo& renderInfo) const } } -BoundingBox ShaderGeometry::computeBound() const +BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) +ShaderGeometry::computeBound() +#else +ShaderGeometry::computeBoundingBox() +#endif +const { - const BoundingBox& geom_box = _geometry->getBound(); + const BoundingBox& geom_box = +#if OSG_VERSION_LESS_THAN(3,3,2) + _geometry->getBound(); +#else + _geometry->getBoundingBox(); +#endif + BoundingBox bb; const Vec4Array* posScales = _posScaleArray.get(); if (!posScales) diff --git a/simgear/scene/tgdb/ShaderGeometry.hxx b/simgear/scene/tgdb/ShaderGeometry.hxx index 30c72fbe..a5de095f 100644 --- a/simgear/scene/tgdb/ShaderGeometry.hxx +++ b/simgear/scene/tgdb/ShaderGeometry.hxx @@ -58,8 +58,15 @@ class ShaderGeometry : public osg::Drawable META_Object(flightgear, ShaderGeometry); virtual void drawImplementation(osg::RenderInfo& renderInfo) const; - virtual osg::BoundingBox computeBound() const; + virtual osg::BoundingBox +#if OSG_VERSION_LESS_THAN(3,3,2) + computeBound() +#else + computeBoundingBox() +#endif + const; + void setGeometry(osg::Geometry* geometry) { _geometry = geometry; diff --git a/simgear/scene/util/SGEnlargeBoundingBox.cxx b/simgear/scene/util/SGEnlargeBoundingBox.cxx index 8e5d8f3d..5ff19855 100644 --- a/simgear/scene/util/SGEnlargeBoundingBox.cxx +++ b/simgear/scene/util/SGEnlargeBoundingBox.cxx @@ -24,7 +24,9 @@ #endif #include "SGEnlargeBoundingBox.hxx" + #include +#include SGEnlargeBoundingBox::SGEnlargeBoundingBox(float offset) : _offset(offset) @@ -41,7 +43,13 @@ SGEnlargeBoundingBox::SGEnlargeBoundingBox(const SGEnlargeBoundingBox& cb, osg::BoundingBox SGEnlargeBoundingBox::computeBound(const osg::Drawable& drawable) const { - osg::BoundingBox bound = drawable.computeBound(); + osg::BoundingBox bound = +#if OSG_VERSION_LESS_THAN(3,3,2) + drawable.computeBound(); +#else + drawable.computeBoundingBox(); +#endif + if (!bound.valid()) return bound; return osg::BoundingBox(bound._min - osg::Vec3(_offset, _offset, _offset), diff --git a/simgear/scene/util/UpdateOnceCallback.cxx b/simgear/scene/util/UpdateOnceCallback.cxx index 2615df4a..99d0192b 100644 --- a/simgear/scene/util/UpdateOnceCallback.cxx +++ b/simgear/scene/util/UpdateOnceCallback.cxx @@ -20,6 +20,7 @@ #include "UpdateOnceCallback.hxx" #include +#include namespace simgear { -- 2.39.5