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.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#define OSG_DisplaySettings 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -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<DisplaySettings>& instance();
|
||||
|
||||
DisplaySettings():
|
||||
Referenced(true)
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
using namespace osg;
|
||||
using namespace std;
|
||||
|
||||
DisplaySettings* DisplaySettings::instance()
|
||||
ref_ptr<DisplaySettings>& DisplaySettings::instance()
|
||||
{
|
||||
static ref_ptr<DisplaySettings> s_displaySettings = new DisplaySettings;
|
||||
return s_displaySettings.get();
|
||||
return s_displaySettings;
|
||||
}
|
||||
|
||||
DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced(true)
|
||||
|
||||
@@ -195,7 +195,7 @@ Renderer::Renderer(osg::Camera* camera):
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(_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);
|
||||
|
||||
|
||||
@@ -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<osg::GraphicsContext::Traits> 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();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user