From 41f7efbab6217642628d018e9601838e87de7059 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 May 2018 10:47:50 +0100 Subject: [PATCH] Imoroved backwards compatibility with 3.6 --- include/osg/Callback | 2 +- include/osg/Object | 8 ++++++++ include/osg/Uniform | 2 ++ include/osg/UniformBase | 3 +++ src/osg/Callback.cpp | 11 +++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/osg/Callback b/include/osg/Callback index 07924b52f..e1250abee 100644 --- a/include/osg/Callback +++ b/include/osg/Callback @@ -286,7 +286,7 @@ public: virtual bool run(osg::Object* object, osg::Object* data); /** do customized update code.*/ - virtual void operator () (UniformBase*, NodeVisitor*) {} + virtual void operator () (UniformBase* ub, NodeVisitor* nv); virtual void operator () (Uniform*, NodeVisitor*) {} diff --git a/include/osg/Object b/include/osg/Object index f15257e2b..a03ec1226 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -135,6 +135,14 @@ class OSG_EXPORT Object : public Referenced * Equivalent to dynamic_cast(this).*/ virtual Uniform* asUniform() { return 0; } + /** convert 'const this' into a const Uniform pointer if Object is a Uniform, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const UniformBase* asUniformBase() const { return 0; } + + /** Convert 'this' into a Uniform pointer if Object is a Uniform, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual UniformBase* asUniformBase() { return 0; } + /** convert 'const this' into a const Uniform pointer if Object is a Uniform, otherwise return 0. * Equivalent to dynamic_cast(this).*/ virtual const Uniform* asUniform() const { return 0; } diff --git a/include/osg/Uniform b/include/osg/Uniform index b15fc7a47..1d3668c5f 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -627,6 +627,8 @@ class OSG_EXPORT Uniform : public UniformBase virtual void apply(const GLExtensions* ext, GLint location) const; + typedef osg::UniformCallback Callback; + protected: virtual ~Uniform(); diff --git a/include/osg/UniformBase b/include/osg/UniformBase index 1d778fdd4..62bf5e4eb 100644 --- a/include/osg/UniformBase +++ b/include/osg/UniformBase @@ -33,6 +33,9 @@ class OSG_EXPORT UniformBase : public Object META_Object(osg, UniformBase); + virtual const UniformBase* asUniformBase() const { return this; } + virtual UniformBase* asUniformBase() { return this; } + /** Set the name of the glUniform, ensuring it is only set once.*/ virtual void setName( const std::string& name ); diff --git a/src/osg/Callback.cpp b/src/osg/Callback.cpp index 064da571a..d005c9329 100644 --- a/src/osg/Callback.cpp +++ b/src/osg/Callback.cpp @@ -15,6 +15,7 @@ #include #include #include +#include using namespace osg; @@ -162,3 +163,13 @@ bool DrawableCullCallback::cull(osg::NodeVisitor* nv, osg::Drawable* drawable, o { return cull(nv, drawable, renderInfo? renderInfo->getState():0); } + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// +void UniformCallback::operator () (UniformBase* ub, NodeVisitor* nv) +{ + Uniform* uniform = ub->asUniform(); + if (uniform) this->operator()(uniform, nv); +}