From 6dec61842d1c7a6dcc2dd019690edb395c2c8c52 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 28 Jul 2007 10:28:40 +0000 Subject: [PATCH] Introduce Camera::s/getRenderer(). --- examples/osgviewerFOX/CMakeLists.txt | 2 +- include/osg/Camera | 10 +++++----- include/osgUtil/SceneView | 5 +++-- src/osg/Camera.cpp | 11 ++++++++--- src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp | 2 +- src/osgUtil/CullVisitor.cpp | 4 ++-- src/osgUtil/SceneView.cpp | 14 ++++++++++++-- src/osgWrappers/osg/Camera.cpp | 19 +++++++++---------- src/osgWrappers/osgUtil/SceneView.cpp | 12 ++++++------ 9 files changed, 47 insertions(+), 32 deletions(-) diff --git a/examples/osgviewerFOX/CMakeLists.txt b/examples/osgviewerFOX/CMakeLists.txt index 4baacb99f..6518e4a38 100644 --- a/examples/osgviewerFOX/CMakeLists.txt +++ b/examples/osgviewerFOX/CMakeLists.txt @@ -1,6 +1,6 @@ SET(TARGET_SRC FOX_OSG.cpp FOX_OSG_MDIView.cpp osgviewerFOX.cpp ) -SET(TARGET_H FOX_OSG_MDIView.h osgviewerFOX.cpp osgviewerFOX.h) +SET(TARGET_H FOX_OSG.h FOX_OSG_MDIView.h osgviewerFOX.h) INCLUDE_DIRECTORIES( ${FOX_INCLUDE_DIR} ) SET(TARGET_EXTERNAL_LIBRARIES ${FOX_LIBRARY} ) diff --git a/include/osg/Camera b/include/osg/Camera index c3c5d2f99..48cd47bd6 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -373,13 +373,13 @@ class OSG_EXPORT Camera : public Transform, public CullSettings /** Set the Rendering object that is used to implement rendering of the subgraph.*/ - void setRenderingCache(unsigned int contextID, osg::Object* rc) { _renderingCache[contextID] = rc; } + void setRenderer(osg::Object* rc) { _renderer = rc; } /** Get the Rendering object that is used to implement rendering of the subgraph.*/ - osg::Object* getRenderingCache(unsigned int contextID) { return _renderingCache[contextID].get(); } + osg::Object* getRenderer() { return _renderer.get(); } /** Get the const Rendering object that is used to implement rendering of the subgraph.*/ - const osg::Object* getRenderingCache(unsigned int contextID) const { return _renderingCache[contextID].get(); } + const osg::Object* getRenderer() const { return _renderer.get(); } /** Draw callback for custom operations.*/ @@ -467,11 +467,11 @@ class OSG_EXPORT Camera : public Transform, public CullSettings RenderTargetImplementation _renderTargetFallback; BufferAttachmentMap _bufferAttachmentMap; - ref_ptr _cameraThread; + ref_ptr _cameraThread; ref_ptr _graphicsContext; - buffered_object< ref_ptr > _renderingCache; + ref_ptr _renderer; ref_ptr _preDrawCallback; ref_ptr _postDrawCallback; diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index c99262678..1a0c50e57 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -61,7 +61,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings virtual void setDefaults(unsigned int options); /** Set the camera used to represent the camera view of this SceneView.*/ - void setCamera(osg::Camera* camera); + void setCamera(osg::Camera* camera, bool assumeOwnershipOfCamera = true); /** Get the camera used to represent the camera view of this SceneView.*/ osg::Camera* getCamera() { return _camera.get(); } @@ -502,7 +502,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings osg::ref_ptr _frameStamp; - osg::ref_ptr _camera; + osg::observer_ptr _camera; + osg::ref_ptr _cameraWithOwnership; osg::ref_ptr _globalStateSet; osg::ref_ptr _light; diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index 238d16e8a..82f11c93c 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -251,15 +251,20 @@ void Camera::detach(BufferComponent buffer) void Camera::resizeGLObjectBuffers(unsigned int maxSize) { - _renderingCache.resize(maxSize); + if (_renderer.valid()) + { + const_cast(this)->_renderer->resizeGLObjectBuffers(maxSize); + } Transform::resizeGLObjectBuffers(maxSize); } void Camera::releaseGLObjects(osg::State* state) const { - if (state) const_cast(this)->_renderingCache[state->getContextID()] = 0; - else const_cast(this)->_renderingCache.setAllElementsTo(0); + if (_renderer.valid()) + { + const_cast(this)->_renderer->releaseGLObjects(state); + } Transform::releaseGLObjects(state); } diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index 3f08fe398..f499d269d 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -75,7 +75,7 @@ class FLTReaderWriter : public ReaderWriter virtual bool acceptsExtension(const std::string& extension) const { - return equalCaseInsensitive(extension,"flt"); + return equalCaseInsensitive(extension,"flt") || extension.empty(); } virtual ReadResult readObject(const std::string& file, const Options* options) const diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index dc80bf1ec..ada86de51 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -1190,11 +1190,11 @@ void CullVisitor::apply(osg::Camera& camera) // use render to texture stage. // create the render to texture stage. - osg::ref_ptr rsCache = dynamic_cast(camera.getRenderingCache(contextID)); + osg::ref_ptr rsCache = dynamic_cast(camera.getRenderer()); if (!rsCache) { rsCache = new osgUtil::RenderStageCache; - camera.setRenderingCache(contextID, rsCache.get()); + camera.setRenderer(rsCache.get()); } osg::ref_ptr rtts = rsCache->getRenderStage(this); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index dd4ed91e1..b75024b6f 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -95,7 +95,7 @@ SceneView::SceneView(DisplaySettings* ds) _prioritizeTextures = false; - _camera = new Camera; + setCamera(new Camera); _camera->setViewport(new Viewport); _camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); @@ -132,6 +132,7 @@ SceneView::SceneView(const SceneView& rhs, const osg::CopyOp& copyop): _prioritizeTextures = rhs._prioritizeTextures; _camera = rhs._camera; + _cameraWithOwnership = rhs._cameraWithOwnership; _initCalled = rhs._initCalled; @@ -231,7 +232,7 @@ void SceneView::setDefaults(unsigned int options) _camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); } -void SceneView::setCamera(osg::Camera* camera) +void SceneView::setCamera(osg::Camera* camera, bool assumeOwnershipOfCamera) { if (camera) { @@ -241,6 +242,15 @@ void SceneView::setCamera(osg::Camera* camera) { osg::notify(osg::NOTICE)<<"Warning: attempt to assign a NULL camera to SceneView not permitted."<