Introduce Camera::s/getRenderer().

This commit is contained in:
Robert Osfield 2007-07-28 10:28:40 +00:00
parent f38be8c7a8
commit 6dec61842d
9 changed files with 47 additions and 32 deletions

View File

@ -1,6 +1,6 @@
SET(TARGET_SRC FOX_OSG.cpp FOX_OSG_MDIView.cpp osgviewerFOX.cpp ) 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} ) INCLUDE_DIRECTORIES( ${FOX_INCLUDE_DIR} )
SET(TARGET_EXTERNAL_LIBRARIES ${FOX_LIBRARY} ) SET(TARGET_EXTERNAL_LIBRARIES ${FOX_LIBRARY} )

View File

@ -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.*/ /** 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.*/ /** 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.*/ /** 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.*/ /** Draw callback for custom operations.*/
@ -467,11 +467,11 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
RenderTargetImplementation _renderTargetFallback; RenderTargetImplementation _renderTargetFallback;
BufferAttachmentMap _bufferAttachmentMap; BufferAttachmentMap _bufferAttachmentMap;
ref_ptr<OperationThread> _cameraThread; ref_ptr<OperationThread> _cameraThread;
ref_ptr<GraphicsContext> _graphicsContext; ref_ptr<GraphicsContext> _graphicsContext;
buffered_object< ref_ptr<Object> > _renderingCache; ref_ptr<Object> _renderer;
ref_ptr<DrawCallback> _preDrawCallback; ref_ptr<DrawCallback> _preDrawCallback;
ref_ptr<DrawCallback> _postDrawCallback; ref_ptr<DrawCallback> _postDrawCallback;

View File

@ -61,7 +61,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
virtual void setDefaults(unsigned int options); virtual void setDefaults(unsigned int options);
/** Set the camera used to represent the camera view of this SceneView.*/ /** 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.*/ /** Get the camera used to represent the camera view of this SceneView.*/
osg::Camera* getCamera() { return _camera.get(); } osg::Camera* getCamera() { return _camera.get(); }
@ -502,7 +502,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
osg::ref_ptr<osg::FrameStamp> _frameStamp; osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<osg::Camera> _camera; osg::observer_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::Camera> _cameraWithOwnership;
osg::ref_ptr<osg::StateSet> _globalStateSet; osg::ref_ptr<osg::StateSet> _globalStateSet;
osg::ref_ptr<osg::Light> _light; osg::ref_ptr<osg::Light> _light;

View File

@ -251,15 +251,20 @@ void Camera::detach(BufferComponent buffer)
void Camera::resizeGLObjectBuffers(unsigned int maxSize) void Camera::resizeGLObjectBuffers(unsigned int maxSize)
{ {
_renderingCache.resize(maxSize); if (_renderer.valid())
{
const_cast<Camera*>(this)->_renderer->resizeGLObjectBuffers(maxSize);
}
Transform::resizeGLObjectBuffers(maxSize); Transform::resizeGLObjectBuffers(maxSize);
} }
void Camera::releaseGLObjects(osg::State* state) const void Camera::releaseGLObjects(osg::State* state) const
{ {
if (state) const_cast<Camera*>(this)->_renderingCache[state->getContextID()] = 0; if (_renderer.valid())
else const_cast<Camera*>(this)->_renderingCache.setAllElementsTo(0); {
const_cast<Camera*>(this)->_renderer->releaseGLObjects(state);
}
Transform::releaseGLObjects(state); Transform::releaseGLObjects(state);
} }

View File

@ -75,7 +75,7 @@ class FLTReaderWriter : public ReaderWriter
virtual bool acceptsExtension(const std::string& extension) const 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 virtual ReadResult readObject(const std::string& file, const Options* options) const

View File

@ -1190,11 +1190,11 @@ void CullVisitor::apply(osg::Camera& camera)
// use render to texture stage. // use render to texture stage.
// create the render to texture stage. // create the render to texture stage.
osg::ref_ptr<osgUtil::RenderStageCache> rsCache = dynamic_cast<osgUtil::RenderStageCache*>(camera.getRenderingCache(contextID)); osg::ref_ptr<osgUtil::RenderStageCache> rsCache = dynamic_cast<osgUtil::RenderStageCache*>(camera.getRenderer());
if (!rsCache) if (!rsCache)
{ {
rsCache = new osgUtil::RenderStageCache; rsCache = new osgUtil::RenderStageCache;
camera.setRenderingCache(contextID, rsCache.get()); camera.setRenderer(rsCache.get());
} }
osg::ref_ptr<osgUtil::RenderStage> rtts = rsCache->getRenderStage(this); osg::ref_ptr<osgUtil::RenderStage> rtts = rsCache->getRenderStage(this);

View File

@ -95,7 +95,7 @@ SceneView::SceneView(DisplaySettings* ds)
_prioritizeTextures = false; _prioritizeTextures = false;
_camera = new Camera; setCamera(new Camera);
_camera->setViewport(new Viewport); _camera->setViewport(new Viewport);
_camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); _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; _prioritizeTextures = rhs._prioritizeTextures;
_camera = rhs._camera; _camera = rhs._camera;
_cameraWithOwnership = rhs._cameraWithOwnership;
_initCalled = rhs._initCalled; _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)); _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) 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."<<std::endl; osg::notify(osg::NOTICE)<<"Warning: attempt to assign a NULL camera to SceneView not permitted."<<std::endl;
} }
if (assumeOwnershipOfCamera)
{
_cameraWithOwnership = _camera.get();
}
else
{
_cameraWithOwnership = 0;
}
} }
void SceneView::setSceneData(osg::Node* node) void SceneView::setSceneData(osg::Node* node)

View File

@ -476,19 +476,19 @@ BEGIN_OBJECT_REFLECTOR(osg::Camera)
__C5_GraphicsContext_P1__getGraphicsContext, __C5_GraphicsContext_P1__getGraphicsContext,
"Get the const GraphicsContext. ", "Get the const GraphicsContext. ",
""); "");
I_Method2(void, setRenderingCache, IN, unsigned int, contextID, IN, osg::Object *, rc, I_Method1(void, setRenderer, IN, osg::Object *, rc,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setRenderingCache__unsigned_int__osg_Object_P1, __void__setRenderer__osg_Object_P1,
"Set the Rendering object that is used to implement rendering of the subgraph. ", "Set the Rendering object that is used to implement rendering of the subgraph. ",
""); "");
I_Method1(osg::Object *, getRenderingCache, IN, unsigned int, contextID, I_Method0(osg::Object *, getRenderer,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__osg_Object_P1__getRenderingCache__unsigned_int, __osg_Object_P1__getRenderer,
"Get the Rendering object that is used to implement rendering of the subgraph. ", "Get the Rendering object that is used to implement rendering of the subgraph. ",
""); "");
I_Method1(const osg::Object *, getRenderingCache, IN, unsigned int, contextID, I_Method0(const osg::Object *, getRenderer,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__C5_osg_Object_P1__getRenderingCache__unsigned_int, __C5_osg_Object_P1__getRenderer,
"Get the const Rendering object that is used to implement rendering of the subgraph. ", "Get the const Rendering object that is used to implement rendering of the subgraph. ",
""); "");
I_Method1(void, setPreDrawCallback, IN, osg::Camera::DrawCallback *, cb, I_Method1(void, setPreDrawCallback, IN, osg::Camera::DrawCallback *, cb,
@ -606,10 +606,9 @@ BEGIN_OBJECT_REFLECTOR(osg::Camera)
I_SimpleProperty(osg::Camera::RenderTargetImplementation, RenderTargetImplementation, I_SimpleProperty(osg::Camera::RenderTargetImplementation, RenderTargetImplementation,
__RenderTargetImplementation__getRenderTargetImplementation, __RenderTargetImplementation__getRenderTargetImplementation,
__void__setRenderTargetImplementation__RenderTargetImplementation); __void__setRenderTargetImplementation__RenderTargetImplementation);
I_IndexedProperty(osg::Object *, RenderingCache, I_SimpleProperty(osg::Object *, Renderer,
__osg_Object_P1__getRenderingCache__unsigned_int, __osg_Object_P1__getRenderer,
__void__setRenderingCache__unsigned_int__osg_Object_P1, __void__setRenderer__osg_Object_P1);
0);
I_SimpleProperty(osg::Stats *, Stats, I_SimpleProperty(osg::Stats *, Stats,
__osg_Stats_P1__getStats, __osg_Stats_P1__getStats,
__void__setStats__osg_Stats_P1); __void__setStats__osg_Stats_P1);

View File

@ -121,11 +121,11 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::SceneView)
__void__setDefaults__unsigned_int, __void__setDefaults__unsigned_int,
"Set scene view to use default global state, light, camera and render visitor. ", "Set scene view to use default global state, light, camera and render visitor. ",
""); "");
I_Method1(void, setCamera, IN, osg::Camera *, camera, I_MethodWithDefaults2(void, setCamera, IN, osg::Camera *, camera, , IN, bool, assumeOwnershipOfCamera, true,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setCamera__osg_Camera_P1, __void__setCamera__osg_Camera_P1__bool,
"Set the camera used to represent the camera view of this SceneView. ", "Set the camera used to represent the camera view of this SceneView. ",
""); "");
I_Method0(osg::Camera *, getCamera, I_Method0(osg::Camera *, getCamera,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__osg_Camera_P1__getCamera, __osg_Camera_P1__getCamera,
@ -784,7 +784,7 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::SceneView)
__void__setActiveUniforms__int); __void__setActiveUniforms__int);
I_SimpleProperty(osg::Camera *, Camera, I_SimpleProperty(osg::Camera *, Camera,
__osg_Camera_P1__getCamera, __osg_Camera_P1__getCamera,
__void__setCamera__osg_Camera_P1); 0);
I_SimpleProperty(const osg::Vec4 &, ClearColor, I_SimpleProperty(const osg::Vec4 &, ClearColor,
__C5_osg_Vec4_R1__getClearColor, __C5_osg_Vec4_R1__getClearColor,
__void__setClearColor__C5_osg_Vec4_R1); __void__setClearColor__C5_osg_Vec4_R1);