Moved SimpleViewer and GraphicsWindow into their own osgViewer library, updated simpleviewer examples to reflect this change

This commit is contained in:
Robert Osfield
2006-11-02 12:27:15 +00:00
parent f9fb99dc43
commit e0f395fd07
35 changed files with 470 additions and 117 deletions

View File

@@ -1,91 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_GRAPHICWINDOW
#define OSG_GRAPHICWINDOW 1
#include <osg/GraphicsContext>
#include <osg/Notify>
#include <osgGA/EventQueue>
namespace osgGA {
/** Base class for providing Windowing API agnostic access to creating and managing graphisc window and events.
* Note, the GraphicsWindow is subclassed from osg::GraphicsContext, and to provide an implemention you'll need to implement its
* range of pure virtual functions, you'll find these all have naming convention methodNameImplemention(..).
* GraphicsWindow adds the event queue ontop of the GraphicsContext, thereby adding a mechnism for adapting Windowing events
* as well as basics graphics context work, you should wire up custom GraphicsWindowImplementation to push their events through
* into the EventQueue. */
class OSGGA_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgGA::GUIActionAdapter
{
public:
GraphicsWindow() { _eventQueue = new osgGA::EventQueue; }
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
public:
/** Realise the GraphicsContext implementation,
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual bool realizeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<<std::endl; return false; }
/** Return true if the graphics context has been realised, and is ready to use, implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual bool isRealizedImplementation() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::isRealizedImplementation() not implemented."<<std::endl; return false; }
/** Close the graphics context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void closeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::closeImplementation() not implemented."<<std::endl; }
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; }
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; }
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::void bindPBufferToTextureImplementation(..) not implemented."<<std::endl; }
/** Swap the front and back buffers implementation.
* Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */
virtual void swapBuffersImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow:: swapBuffersImplementation() not implemented."<<std::endl; }
public:
// Override from GUIActionAdapter
virtual void requestRedraw() {}
// Override from GUIActionAdapter
virtual void requestContinuousUpdate(bool /*needed*/=true) {}
// Override from GUIActionAdapter
virtual void requestWarpPointer(float /*x*/,float /*y*/) {}
protected:
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
};
}
#endif

View File

@@ -1,103 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGGA_SimpleViewer
#define OSGGA_SimpleViewer 1
#include <osgGA/EventVisitor>
#include <osgGA/MatrixManipulator>
#include <osgGA/GraphicsWindow>
#include <osgDB/DatabasePager>
#include <list>
namespace osgGA{
/** SimpleViewer provide a simple interface for setting up rendering of an scene graph, using a single camera view within a single window.*/
class OSGGA_EXPORT SimpleViewer : public virtual osgGA::GraphicsWindow
{
public:
SimpleViewer();
virtual ~SimpleViewer();
void setSceneData(osg::Node* node);
osg::Node* getSceneData();
const osg::Node* getSceneData() const;
osg::CameraNode* getCamera();
const osg::CameraNode* getCamera() const;
void setCameraManipulator(MatrixManipulator* manipulator);
MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
const MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
typedef std::list< osg::ref_ptr<GUIEventHandler> > EventHandlers;
void addEventHandler(GUIEventHandler* eventHandler);
EventHandlers& getEventHandlers() { return _eventHandlers; }
const EventHandlers& getEventHandlers() const { return _eventHandlers; }
void setDatabasePager(osgDB::DatabasePager* dp);
osgDB::DatabasePager* getDatabasePager() { return _databasePager.get(); }
const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); }
/** Render a complete new frame.
* Calls frameAdvance(), frameEventTraversal(), frameUpateTraversal(), frameCullTraversal() and frameDrawTraversal().
* Note, no internal makeCurrent() is issued before, or swap buffers called after frame(), these operations are the responsibility of the calling code.*/
virtual void frame();
virtual void frameAdvance();
virtual void frameEventTraversal();
virtual void frameUpdateTraversal();
virtual void frameCullTraversal();
virtual void frameDrawTraversal();
/** Release all OpenGL objects associated with this viewer's scenegraph. Note, does not deleted the actual OpenGL objects, it just releases them to the pending GL object delete lists which will need flushing once a valid graphics context is obtained.*/
virtual void releaseAllGLObjects();
/** Clean up all OpenGL objects associated with this viewer's scenegraph. Note, must only be called from the graphics context associated with this viewer.*/
virtual void cleanup();
public:
osgUtil::SceneView* getSceneView() { return _sceneView.get(); }
const osgUtil::SceneView* getSceneView() const { return _sceneView.get(); }
void init();
protected:
bool _firstFrame;
osg::Timer_t _startTick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<osgUtil::SceneView> _sceneView;
osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator;
EventHandlers _eventHandlers;
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
};
}
#endif