From fe98c3d7f594203b8af9c82c76c2bb8d3c7e15a9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 12 Jan 2019 11:27:18 +0000 Subject: [PATCH] Moved resizeGLObjects/releaseGLObjects out of Referenced to avoid multiple inheritance warnings --- include/osg/GraphicsThread | 8 ++++++++ include/osg/Referenced | 4 ++-- include/osgUtil/StateGraph | 14 +++++++++----- src/osgUtil/SceneView.cpp | 24 ++++++++++++++++++------ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/include/osg/GraphicsThread b/include/osg/GraphicsThread index 8001cc5f3..5effe7b8e 100644 --- a/include/osg/GraphicsThread +++ b/include/osg/GraphicsThread @@ -42,6 +42,14 @@ struct OSG_EXPORT GraphicsOperation : public Operation virtual void operator () (Object* object); virtual void operator () (GraphicsContext* context) = 0; + + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {} + + /** If State is non-zero, this function releases any associated OpenGL objects for + * the specified graphics context. Otherwise, releases OpenGL objects + * for all graphics contexts. */ + virtual void releaseGLObjects(osg::State* = 0) const {} }; diff --git a/include/osg/Referenced b/include/osg/Referenced index 2c83276c0..90811233f 100644 --- a/include/osg/Referenced +++ b/include/osg/Referenced @@ -115,7 +115,7 @@ class OSG_EXPORT Referenced /** Remove Observer that is observing this object.*/ void removeObserver(Observer* observer) const; - +#if 0 /** Resize any per context GLObject buffers to specified size. */ virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {} @@ -123,7 +123,7 @@ class OSG_EXPORT Referenced * the specified graphics context. Otherwise, releases OpenGL objects * for all graphics contexts. */ virtual void releaseGLObjects(osg::State* = 0) const {} - +#endif public: friend class DeleteHandler; diff --git a/include/osgUtil/StateGraph b/include/osgUtil/StateGraph index e170342b1..897cc48f2 100644 --- a/include/osgUtil/StateGraph +++ b/include/osgUtil/StateGraph @@ -38,7 +38,7 @@ struct LessDepthSortFunctor /** StateGraph - contained in a renderBin, defines the scene to be drawn. */ -class OSGUTIL_EXPORT StateGraph : public osg::Referenced +class OSGUTIL_EXPORT StateGraph : public osg::Object { public: @@ -66,7 +66,6 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced bool _dynamic; StateGraph(): - osg::Referenced(false), _parent(NULL), _stateset(NULL), _depth(0), @@ -78,7 +77,6 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced } StateGraph(StateGraph* parent,const osg::StateSet* stateset): - osg::Referenced(false), _parent(parent), _stateset(stateset), _depth(0), @@ -95,7 +93,13 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced ~StateGraph() {} - StateGraph* cloneType() const { return new StateGraph; } + + virtual osg::Object* cloneType() const { return new StateGraph(); } + virtual StateGraph* cloneStateGraph() const { return new StateGraph(); } + virtual osg::Object* clone(const osg::CopyOp&) const { return new StateGraph(); } + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=0L; } + virtual const char* libraryName() const { return "osgUtil"; } + virtual const char* className() const { return "StateGraph"; } void setUserData(osg::Referenced* obj) { _userData = obj; } osg::Referenced* getUserData() { return _userData.get(); } @@ -345,7 +349,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced private: /// disallow copy construction. - StateGraph(const StateGraph&):osg::Referenced() {} + StateGraph(const StateGraph&) : osg::Object() {} /// disallow copy operator. StateGraph& operator = (const StateGraph&) { return *this; } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 9abde8c5f..c6310a090 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -720,11 +720,11 @@ void SceneView::cull() { if (!_cullVisitorLeft.valid()) _cullVisitorLeft = _cullVisitor->clone(); - if (!_stateGraphLeft.valid()) _stateGraphLeft = _stateGraph->cloneType(); + if (!_stateGraphLeft.valid()) _stateGraphLeft = _stateGraph->cloneStateGraph(); if (!_renderStageLeft.valid()) _renderStageLeft = osg::clone(_renderStage.get(), osg::CopyOp::DEEP_COPY_ALL); if (!_cullVisitorRight.valid()) _cullVisitorRight = _cullVisitor->clone(); - if (!_stateGraphRight.valid()) _stateGraphRight = _stateGraph->cloneType(); + if (!_stateGraphRight.valid()) _stateGraphRight = _stateGraph->cloneStateGraph(); if (!_renderStageRight.valid()) _renderStageRight = osg::clone(_renderStage.get(), osg::CopyOp::DEEP_COPY_ALL); _cullVisitorLeft->setDatabaseRequestHandler(_cullVisitor->getDatabaseRequestHandler()); @@ -931,11 +931,15 @@ void SceneView::resizeGLObjectBuffers(unsigned int maxSize) { struct Resize { - unsigned int maxSize = 1; + unsigned int maxSize; Resize(unsigned int ms) : maxSize(ms) {} void operator() (osg::Referenced* object) + { + operator()(dynamic_cast(object)); + } + void operator() (osg::Object* object) { if (object) object->resizeGLObjectBuffers(maxSize); } @@ -960,11 +964,19 @@ void SceneView::releaseGLObjects(osg::State* state) const struct Release { - void operator() (const osg::Referenced* object) + osg::State* _state; + + Release(State* state) : _state(state) {} + + void operator() (osg::Referenced* object) { - if (object) object->releaseGLObjects(); + operator()(dynamic_cast(object)); } - } operation; + void operator() (osg::Object* object) + { + if (object) object->releaseGLObjects(_state); + } + } operation(state); operation(_localStateSet.get()); operation(_updateVisitor.get());