Update for OpenSceneGraph 3.3.2 API changes.

This commit is contained in:
Thomas Geymayer
2014-08-09 17:18:21 +02:00
parent 519326f751
commit 791273c61d
14 changed files with 190 additions and 37 deletions

View File

@@ -44,6 +44,7 @@
#include <osg/ShadeModel>
#include <osg/StateSet>
#include <osg/FrameBufferObject> // for GL_DEPTH_STENCIL_EXT on Windows
#include <osg/Version>
#include <osgUtil/RenderBin>
#include <cassert>
@@ -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<osg::NodeCallback*>(camera->getCullCallback())
#endif
: 0;
clear();
allocRT(cull_callback);
}

View File

@@ -27,6 +27,7 @@
#include <osg/Drawable>
#include <osg/Geode>
#include <osg/StateAttribute>
#include <osg/Version>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/foreach.hpp>
@@ -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 );

View File

@@ -413,7 +413,14 @@ namespace canvas
&& child->getNameString() == "visible"
&& child->getBoolValue() )
{
CullCallback* cb = static_cast<CullCallback*>(_geom->getCullCallback());
CullCallback* cb =
#if OSG_VERSION_LESS_THAN(3,3,2)
static_cast<CullCallback*>
#else
dynamic_cast<CullCallback*>
#endif
( _geom->getCullCallback() );
if( cb )
cb->cullNextFrame();
}

View File

@@ -20,6 +20,7 @@
#include <simgear/scene/util/parse_color.hxx>
#include <osg/Drawable>
#include <osg/Version>
#include <vg/openvg.h>
#include <cassert>
@@ -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();

View File

@@ -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() )

View File

@@ -18,6 +18,9 @@
#define SIMGEAR_EFFECT_GEODE_HXX 1
#include <osg/Geode>
#include <osg/Version>
#include <boost/iterator/iterator_adaptor.hpp>
#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<osg::Drawable>,
boost::use_default,
osg::ref_ptr<osg::Drawable> // 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<osg::Drawable> 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> _effect;

View File

@@ -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;
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<osg::Drawable::CullCallback*>(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;
}
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<EffectCullVisitor*>( cv );
EffectGeode::DrawablesIterator drawablesEnd = itr;

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -23,9 +23,10 @@
#define _SG_VASI_DRAWABLE_HXX
#include <simgear/compiler.h>
#include <simgear/math/SGMath.hxx>
#include <osg/Drawable>
#include <simgear/math/SGMath.hxx>
#include <osg/Version>
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;

View File

@@ -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)

View File

@@ -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;

View File

@@ -24,7 +24,9 @@
#endif
#include "SGEnlargeBoundingBox.hxx"
#include <osg/Drawable>
#include <osg/Version>
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),

View File

@@ -20,6 +20,7 @@
#include "UpdateOnceCallback.hxx"
#include <osg/Node>
#include <osg/NodeVisitor>
namespace simgear
{