GraphicsWindow
Go to the documentation of this file.
/* -*-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 OSGVIEWER_GRAPHICWINDOW
#define OSGVIEWER_GRAPHICWINDOW 1
#include <osg/GraphicsContext>
#include <osg/Notify>
#include <osgGA/EventQueue>
#include <osgGA/GUIActionAdapter>
#include <osgViewer/Export>
extern "C"
{
typedef void (* CGraphicsWindowFunction) (void);
}
namespace osgViewer {
class View;
class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgGA::GUIActionAdapter
{
public:
GraphicsWindow() { _eventQueue = new osgGA::EventQueue; _eventQueue->setGraphicsContext(this); }
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindow*>(object)!=0; }
virtual const char* libraryName() const { return "osgViewer"; }
virtual const char* className() const { return "GraphicsWindow"; }
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
virtual bool checkEvents() { return !(_eventQueue->empty()); }
void setWindowRectangle(int x, int y, int width, int height)
{
if (setWindowRectangleImplementation(x ,y ,width, height) && _traits.valid())
{
resized(x,y,width,height);
}
}
virtual bool setWindowRectangleImplementation(int /*x*/, int /*y*/, int /*width*/, int /*height*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowRectangleImplementation(..) not implemented."<<std::endl; return false; }
virtual void getWindowRectangle(int& x, int& y, int& width, int& height) { if (_traits.valid()) { x = _traits->x; y = _traits->y; width = _traits->width; height = _traits->height; } }
void setWindowDecoration(bool flag)
{
if (setWindowDecorationImplementation(flag) && _traits.valid())
{
_traits->windowDecoration = flag;
}
}
virtual bool setWindowDecorationImplementation(bool /*flag*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowDecorationImplementation(..) not implemented."<<std::endl; return false; }
virtual bool getWindowDecoration() const { return _traits.valid() ? _traits->windowDecoration : false; }
virtual void grabFocus() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocus(..) not implemented."<<std::endl; }
virtual void grabFocusIfPointerInWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocusIfPointerInWindow(..) not implemented."<<std::endl; }
virtual void raiseWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::raiseWindow(..) not implemented."<<std::endl; }
enum MouseCursor {
InheritCursor,
NoCursor,
RightArrowCursor,
LeftArrowCursor,
InfoCursor,
DestroyCursor,
HelpCursor,
CycleCursor,
SprayCursor,
WaitCursor,
TextCursor,
CrosshairCursor,
HandCursor,
UpDownCursor,
LeftRightCursor,
TopSideCursor,
BottomSideCursor,
LeftSideCursor,
RightSideCursor,
TopLeftCorner,
TopRightCorner,
BottomRightCorner,
BottomLeftCorner
};
virtual void setWindowName(const std::string& /*name*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowName(..) not implemented."<<std::endl; }
virtual std::string getWindowName() { return _traits.valid() ? _traits->windowName : ""; }
virtual void useCursor(bool cursorOn) { setCursor(cursorOn ? InheritCursor : NoCursor); }
virtual void setCursor(MouseCursor /*mouseCursor*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setCursor(..) not implemented."<<std::endl; }
//virtual MouseCursor createCursor(const char *data, const char *mask, unsigned w, unsigned h, unsigned hotx, unsigned hoty) { osg::notify(osg::NOTICE)<<"GraphicsWindow::createCursor(..) not implemented."<<std::endl; }
virtual void setSyncToVBlank(bool on)
{
osg::notify(osg::NOTICE) << "GraphicsWindow::setSyncToVBlank(" << on << ") not implemented." << std::endl;
}
bool getSyncToVBlank() const { return _traits.valid() ? _traits->vsync : true; }
virtual void setSwapGroup(bool on, GLuint group, GLuint barrier)
{
osg::notify(osg::NOTICE) << "GraphicsWindow::setSwapGroup(" << on << " " << group << " " << barrier << ") not implemented." << std::endl;
}
void getSwapGroup(bool& on, GLuint& group, GLuint& barrier) const { on = _traits->swapGroupEnabled; group = _traits->swapGroup; barrier = _traits->swapBarrier; }
public:
virtual bool valid() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::valid() not implemented."<<std::endl; return false; }
virtual bool realizeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<<std::endl; return false; }
virtual bool isRealizedImplementation() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::isRealizedImplementation() not implemented."<<std::endl; return false; }
virtual void closeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::closeImplementation() not implemented."<<std::endl; }
virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false;}
virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false;}
virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::bindPBufferToTextureImplementation(..) not implemented."<<std::endl; }
virtual void swapBuffersImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow:: swapBuffersImplementation() not implemented."<<std::endl; }
public:
typedef std::list<osgViewer::View*> Views;
void getViews(Views& views);
// 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;
};
class GraphicsWindowEmbedded : public GraphicsWindow
{
public:
GraphicsWindowEmbedded(osg::GraphicsContext::Traits* traits=0)
{
_traits = traits;
init();
}
GraphicsWindowEmbedded(int x, int y, int width, int height)
{
_traits = new GraphicsContext::Traits;
_traits->x = x;
_traits->y = y;
_traits->width = width;
_traits->height = height;
init();
}
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowEmbedded*>(object)!=0; }
virtual const char* libraryName() const { return "osgViewer"; }
virtual const char* className() const { return "GraphicsWindowEmbedded"; }
void init()
{
if (valid())
{
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );
}
else
{
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
}
}
}
// dummy implementations, assume that graphics context is *always* current and valid.
virtual bool valid() const { return true; }
virtual bool realizeImplementation() { return true; }
virtual bool isRealizedImplementation() const { return true; }
virtual void closeImplementation() {}
virtual bool makeCurrentImplementation() { return true; }
virtual bool releaseContextImplementation() { return true; }
virtual void swapBuffersImplementation() {}
virtual void grabFocus() {}
virtual void grabFocusIfPointerInWindow() {}
virtual void raiseWindow() {}
};
struct GraphicsWindowFunctionProxy
{
GraphicsWindowFunctionProxy(CGraphicsWindowFunction function) { (function)(); }
};
#define USE_GRAPICSWINDOW_IMPLEMENTATION(ext) \
extern "C" void graphicswindow_##ext(void); \
static osgViewer::GraphicsWindowFunctionProxy graphicswindowproxy_##ext(graphicswindow_##ext);
#if defined(_WIN32)
#define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(Win32)
#elif defined(__APPLE__)
#if defined(OSG_WINDOWING_SYSTEM_CARBON)
#define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(Carbon)
#else
#define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(Cocoa)
#endif
#else
#define USE_GRAPHICSWINDOW() USE_GRAPICSWINDOW_IMPLEMENTATION(X11)
#endif
}
#endif
EventQueue
GUIActionAdapter
GraphicsContext
CGraphicsWindowFunction
void(* CGraphicsWindowFunction)(void)
Definition GraphicsWindow:28
Notify
osgGA::EventQueue
Definition EventQueue:31
osgGA::GUIActionAdapter
Definition GUIActionAdapter:62
osgViewer::GraphicsWindowEmbedded::GraphicsWindowEmbedded
GraphicsWindowEmbedded(int x, int y, int width, int height)
Definition GraphicsWindow:229
osgViewer::GraphicsWindowEmbedded::closeImplementation
virtual void closeImplementation()
Definition GraphicsWindow:267
osgViewer::GraphicsWindowEmbedded::valid
virtual bool valid() const
Definition GraphicsWindow:264
osgViewer::GraphicsWindowEmbedded::releaseContextImplementation
virtual bool releaseContextImplementation()
Definition GraphicsWindow:269
osgViewer::GraphicsWindowEmbedded::grabFocus
virtual void grabFocus()
Definition GraphicsWindow:271
osgViewer::GraphicsWindowEmbedded::swapBuffersImplementation
virtual void swapBuffersImplementation()
Definition GraphicsWindow:270
osgViewer::GraphicsWindowEmbedded::isSameKindAs
virtual bool isSameKindAs(const Object *object) const
Definition GraphicsWindow:240
osgViewer::GraphicsWindowEmbedded::className
virtual const char * className() const
Definition GraphicsWindow:242
osgViewer::GraphicsWindowEmbedded::isRealizedImplementation
virtual bool isRealizedImplementation() const
Definition GraphicsWindow:266
osgViewer::GraphicsWindowEmbedded::GraphicsWindowEmbedded
GraphicsWindowEmbedded(osg::GraphicsContext::Traits *traits=0)
Definition GraphicsWindow:221
osgViewer::GraphicsWindowEmbedded::libraryName
virtual const char * libraryName() const
Definition GraphicsWindow:241
osgViewer::GraphicsWindowEmbedded::init
void init()
Definition GraphicsWindow:244
osgViewer::GraphicsWindowEmbedded::realizeImplementation
virtual bool realizeImplementation()
Definition GraphicsWindow:265
osgViewer::GraphicsWindowEmbedded::raiseWindow
virtual void raiseWindow()
Definition GraphicsWindow:273
osgViewer::GraphicsWindowEmbedded::makeCurrentImplementation
virtual bool makeCurrentImplementation()
Definition GraphicsWindow:268
osgViewer::GraphicsWindowEmbedded::grabFocusIfPointerInWindow
virtual void grabFocusIfPointerInWindow()
Definition GraphicsWindow:272
osgViewer::GraphicsWindow::grabFocus
virtual void grabFocus()
Definition GraphicsWindow:91
osgViewer::GraphicsWindow::isRealizedImplementation
virtual bool isRealizedImplementation() const
Definition GraphicsWindow:168
osgViewer::GraphicsWindow::setWindowName
virtual void setWindowName(const std::string &)
Definition GraphicsWindow:127
osgViewer::GraphicsWindow::setSyncToVBlank
virtual void setSyncToVBlank(bool on)
Definition GraphicsWindow:142
osgViewer::GraphicsWindow::setWindowDecoration
void setWindowDecoration(bool flag)
Definition GraphicsWindow:75
osgViewer::GraphicsWindow::makeContextCurrentImplementation
virtual bool makeContextCurrentImplementation(GraphicsContext *)
Definition GraphicsWindow:180
osgViewer::GraphicsWindow::requestWarpPointer
virtual void requestWarpPointer(float, float)
Definition GraphicsWindow:207
osgViewer::GraphicsWindow::_eventQueue
osg::ref_ptr< osgGA::EventQueue > _eventQueue
Definition GraphicsWindow:212
osgViewer::GraphicsWindow::setWindowDecorationImplementation
virtual bool setWindowDecorationImplementation(bool)
Definition GraphicsWindow:84
osgViewer::GraphicsWindow::setWindowRectangle
void setWindowRectangle(int x, int y, int width, int height)
Definition GraphicsWindow:60
osgViewer::GraphicsWindow::Views
std::list< osgViewer::View * > Views
Definition GraphicsWindow:195
osgViewer::GraphicsWindow::makeCurrentImplementation
virtual bool makeCurrentImplementation()
Definition GraphicsWindow:176
osgViewer::GraphicsWindow::getWindowDecoration
virtual bool getWindowDecoration() const
Definition GraphicsWindow:88
osgViewer::GraphicsWindow::setEventQueue
void setEventQueue(osgGA::EventQueue *eventQueue)
Definition GraphicsWindow:52
osgViewer::GraphicsWindow::GraphicsWindow
GraphicsWindow()
Definition GraphicsWindow:46
osgViewer::GraphicsWindow::requestContinuousUpdate
virtual void requestContinuousUpdate(bool=true)
Definition GraphicsWindow:204
osgViewer::GraphicsWindow::getEventQueue
const osgGA::EventQueue * getEventQueue() const
Definition GraphicsWindow:54
osgViewer::GraphicsWindow::closeImplementation
virtual void closeImplementation()
Definition GraphicsWindow:172
osgViewer::GraphicsWindow::getWindowName
virtual std::string getWindowName()
Definition GraphicsWindow:130
osgViewer::GraphicsWindow::getViews
void getViews(Views &views)
osgViewer::GraphicsWindow::MouseCursor
MouseCursor
Definition GraphicsWindow:100
osgViewer::GraphicsWindow::LeftArrowCursor
@ LeftArrowCursor
Definition GraphicsWindow:104
osgViewer::GraphicsWindow::BottomSideCursor
@ BottomSideCursor
Definition GraphicsWindow:117
osgViewer::GraphicsWindow::TopSideCursor
@ TopSideCursor
Definition GraphicsWindow:116
osgViewer::GraphicsWindow::SprayCursor
@ SprayCursor
Definition GraphicsWindow:109
osgViewer::GraphicsWindow::InheritCursor
@ InheritCursor
Definition GraphicsWindow:101
osgViewer::GraphicsWindow::LeftSideCursor
@ LeftSideCursor
Definition GraphicsWindow:118
osgViewer::GraphicsWindow::LeftRightCursor
@ LeftRightCursor
Definition GraphicsWindow:115
osgViewer::GraphicsWindow::BottomLeftCorner
@ BottomLeftCorner
Definition GraphicsWindow:123
osgViewer::GraphicsWindow::BottomRightCorner
@ BottomRightCorner
Definition GraphicsWindow:122
osgViewer::GraphicsWindow::TopRightCorner
@ TopRightCorner
Definition GraphicsWindow:121
osgViewer::GraphicsWindow::CycleCursor
@ CycleCursor
Definition GraphicsWindow:108
osgViewer::GraphicsWindow::CrosshairCursor
@ CrosshairCursor
Definition GraphicsWindow:112
osgViewer::GraphicsWindow::HelpCursor
@ HelpCursor
Definition GraphicsWindow:107
osgViewer::GraphicsWindow::DestroyCursor
@ DestroyCursor
Definition GraphicsWindow:106
osgViewer::GraphicsWindow::WaitCursor
@ WaitCursor
Definition GraphicsWindow:110
osgViewer::GraphicsWindow::TextCursor
@ TextCursor
Definition GraphicsWindow:111
osgViewer::GraphicsWindow::HandCursor
@ HandCursor
Definition GraphicsWindow:113
osgViewer::GraphicsWindow::RightArrowCursor
@ RightArrowCursor
Definition GraphicsWindow:103
osgViewer::GraphicsWindow::TopLeftCorner
@ TopLeftCorner
Definition GraphicsWindow:120
osgViewer::GraphicsWindow::RightSideCursor
@ RightSideCursor
Definition GraphicsWindow:119
osgViewer::GraphicsWindow::UpDownCursor
@ UpDownCursor
Definition GraphicsWindow:114
osgViewer::GraphicsWindow::InfoCursor
@ InfoCursor
Definition GraphicsWindow:105
osgViewer::GraphicsWindow::NoCursor
@ NoCursor
Definition GraphicsWindow:102
osgViewer::GraphicsWindow::libraryName
virtual const char * libraryName() const
Definition GraphicsWindow:49
osgViewer::GraphicsWindow::raiseWindow
virtual void raiseWindow()
Definition GraphicsWindow:97
osgViewer::GraphicsWindow::valid
virtual bool valid() const
Definition GraphicsWindow:160
osgViewer::GraphicsWindow::setWindowRectangleImplementation
virtual bool setWindowRectangleImplementation(int, int, int, int)
Definition GraphicsWindow:69
osgViewer::GraphicsWindow::useCursor
virtual void useCursor(bool cursorOn)
Definition GraphicsWindow:133
osgViewer::GraphicsWindow::grabFocusIfPointerInWindow
virtual void grabFocusIfPointerInWindow()
Definition GraphicsWindow:94
osgViewer::GraphicsWindow::requestRedraw
virtual void requestRedraw()
osgViewer::GraphicsWindow::getSyncToVBlank
bool getSyncToVBlank() const
Definition GraphicsWindow:147
osgViewer::GraphicsWindow::isSameKindAs
virtual bool isSameKindAs(const Object *object) const
Definition GraphicsWindow:48
osgViewer::GraphicsWindow::swapBuffersImplementation
virtual void swapBuffersImplementation()
Definition GraphicsWindow:191
osgViewer::GraphicsWindow::realizeImplementation
virtual bool realizeImplementation()
Definition GraphicsWindow:164
osgViewer::GraphicsWindow::getSwapGroup
void getSwapGroup(bool &on, GLuint &group, GLuint &barrier) const
Definition GraphicsWindow:155
osgViewer::GraphicsWindow::releaseContextImplementation
virtual bool releaseContextImplementation()
Definition GraphicsWindow:183
osgViewer::GraphicsWindow::getEventQueue
osgGA::EventQueue * getEventQueue()
Definition GraphicsWindow:53
osgViewer::GraphicsWindow::bindPBufferToTextureImplementation
virtual void bindPBufferToTextureImplementation(GLenum)
Definition GraphicsWindow:187
osgViewer::GraphicsWindow::getWindowRectangle
virtual void getWindowRectangle(int &x, int &y, int &width, int &height)
Definition GraphicsWindow:72
osgViewer::GraphicsWindow::checkEvents
virtual bool checkEvents()
Definition GraphicsWindow:57
osgViewer::GraphicsWindow::setCursor
virtual void setCursor(MouseCursor)
Definition GraphicsWindow:136
osgViewer::GraphicsWindow::setSwapGroup
virtual void setSwapGroup(bool on, GLuint group, GLuint barrier)
Definition GraphicsWindow:150
osgViewer::GraphicsWindow::className
virtual const char * className() const
Definition GraphicsWindow:50
osgViewer::View
Definition osgViewer/View:76
osg::GraphicsContext
Definition GraphicsContext:30
osg::GraphicsContext::resized
void resized(int x, int y, int width, int height)
Definition GraphicsContext:476
osg::GraphicsContext::_traits
ref_ptr< Traits > _traits
Definition GraphicsContext:544
osg::GraphicsContext::createNewContextID
static unsigned int createNewContextID()
osg::GraphicsContext::GraphicsContext
GraphicsContext()
osg::GraphicsContext::incrementContextIDUsageCount
static void incrementContextIDUsageCount(unsigned int contextID)
osg::GraphicsContext::setState
void setState(State *state)
Definition GraphicsContext:331
osg::GraphicsContext::getState
State * getState()
Definition GraphicsContext:334
osg::Object::Object
Object()
Definition Object:69
osg::State
Definition State:80
osg::State::setContextID
void setContextID(unsigned int contextID)
Definition State:111
osg::State::setGraphicsContext
void setGraphicsContext(GraphicsContext *context)
Definition State:87
osg::ref_ptr
Definition ref_ptr:32
osgViewer
osg::NOTICE
@ NOTICE
Definition Notify:34
osg::notify
std::ostream & notify(void)
Definition Notify:80
Export
OSGVIEWER_EXPORT
#define OSGVIEWER_EXPORT
Definition osgViewer/Export:40
osgViewer::GraphicsWindowFunctionProxy::GraphicsWindowFunctionProxy
GraphicsWindowFunctionProxy(CGraphicsWindowFunction function)
Definition GraphicsWindow:279
osg::GraphicsContext::Traits
Definition GraphicsContext:70