From c2a59415ceca557591b6be60f16d289a62370f08 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 30 Apr 2010 11:48:30 +0000 Subject: [PATCH] Changed DisplaySetting::instance() to return a ref_ptr<>& rathern than a raw C pointer to enable apps to delete the singleton or assign their own. --- include/osg/DisplaySettings | 4 +- src/osg/DisplaySettings.cpp | 4 +- src/osgViewer/Renderer.cpp | 4 +- src/osgViewer/View.cpp | 6 +-- .../introspection/osg/DisplaySettings.cpp | 44 ++++++++++++++++++- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 3a1a6cafe..1b6e4d4a3 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -15,6 +15,7 @@ #define OSG_DisplaySettings 1 #include +#include #include #include @@ -33,8 +34,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced public: /** Maintain a DisplaySettings singleton for objects to query at runtime.*/ - static DisplaySettings* instance(); - + static ref_ptr& instance(); DisplaySettings(): Referenced(true) diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 63b9f56ba..2efeaaa0b 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -23,10 +23,10 @@ using namespace osg; using namespace std; -DisplaySettings* DisplaySettings::instance() +ref_ptr& DisplaySettings::instance() { static ref_ptr s_displaySettings = new DisplaySettings; - return s_displaySettings.get(); + return s_displaySettings; } DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced(true) diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index 20dad3625..f78822bbd 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -195,7 +195,7 @@ Renderer::Renderer(osg::Camera* camera): osgViewer::View* view = dynamic_cast(_camera->getView()); osg::DisplaySettings* ds = _camera->getDisplaySettings() ? _camera->getDisplaySettings() : - ((view && view->getDisplaySettings()) ? view->getDisplaySettings() : osg::DisplaySettings::instance()); + ((view && view->getDisplaySettings()) ? view->getDisplaySettings() : osg::DisplaySettings::instance().get()); unsigned int sceneViewOptions = osgUtil::SceneView::HEADLIGHT; if (view) @@ -291,7 +291,7 @@ void Renderer::updateSceneView(osgUtil::SceneView* sceneView) if (databasePager) databasePager->setCompileGLObjectsForContextID(state->getContextID(), true); osg::DisplaySettings* ds = _camera->getDisplaySettings() ? _camera->getDisplaySettings() : - ((view &&view->getDisplaySettings()) ? view->getDisplaySettings() : osg::DisplaySettings::instance()); + ((view &&view->getDisplaySettings()) ? view->getDisplaySettings() : osg::DisplaySettings::instance().get()); sceneView->setDisplaySettings(ds); diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 3e42e88bb..ade4760dd 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -427,7 +427,7 @@ void View::setUpViewAcrossAllScreens() return; } - osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); double fovy, aspectRatio, zNear, zFar; _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); @@ -575,7 +575,7 @@ void View::setUpViewAcrossAllScreens() void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum) { - osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); @@ -633,7 +633,7 @@ void View::setUpViewOnSingleScreen(unsigned int screenNum) return; } - osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); osg::GraphicsContext::ScreenIdentifier si; si.readDISPLAY(); diff --git a/src/osgWrappers/introspection/osg/DisplaySettings.cpp b/src/osgWrappers/introspection/osg/DisplaySettings.cpp index 20f499161..9146ef9bd 100644 --- a/src/osgWrappers/introspection/osg/DisplaySettings.cpp +++ b/src/osgWrappers/introspection/osg/DisplaySettings.cpp @@ -67,8 +67,8 @@ TYPE_NAME_ALIAS(int, osg::DisplaySettings::ImplicitBufferAttachmentMask) BEGIN_OBJECT_REFLECTOR(osg::DisplaySettings) I_DeclaringFile("osg/DisplaySettings"); I_BaseType(osg::Referenced); - I_StaticMethod0(osg::DisplaySettings *, instance, - __DisplaySettings_P1__instance_S, + I_StaticMethod0(osg::ref_ptr< osg::DisplaySettings > &, instance, + __ref_ptrT1_DisplaySettings__R1__instance_S, "Maintain a DisplaySettings singleton for objects to query at runtime. ", ""); I_Constructor0(____DisplaySettings, @@ -591,3 +591,43 @@ BEGIN_OBJECT_REFLECTOR(osg::DisplaySettings) __void__setStereoMode__StereoMode); END_REFLECTOR +BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::DisplaySettings >) + I_DeclaringFile("osg/ref_ptr"); + I_Constructor0(____ref_ptr, + "", + ""); + I_Constructor1(IN, osg::DisplaySettings *, ptr, + Properties::NON_EXPLICIT, + ____ref_ptr__T_P1, + "", + ""); + I_Constructor1(IN, const osg::ref_ptr< osg::DisplaySettings > &, rp, + Properties::NON_EXPLICIT, + ____ref_ptr__C5_ref_ptr_R1, + "", + ""); + I_Method0(osg::DisplaySettings *, get, + Properties::NON_VIRTUAL, + __T_P1__get, + "", + ""); + I_Method0(bool, valid, + Properties::NON_VIRTUAL, + __bool__valid, + "", + ""); + I_Method0(osg::DisplaySettings *, release, + Properties::NON_VIRTUAL, + __T_P1__release, + "", + ""); + I_Method1(void, swap, IN, osg::ref_ptr< osg::DisplaySettings > &, rp, + Properties::NON_VIRTUAL, + __void__swap__ref_ptr_R1, + "", + ""); + I_SimpleProperty(osg::DisplaySettings *, , + __T_P1__get, + 0); +END_REFLECTOR +