From afc77f9b39f2d0c7736523b74e0b0ad94d5ca4cc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2006 20:49:01 +0000 Subject: [PATCH] Added support WindowingSystemInterface for querring the number of screens, the screen size and creating GraphicsContexts. --- examples/osgcamera/osgcamera.cpp | 25 ++++++++- include/osg/GraphicsContext | 38 ++++++++----- src/osg/GraphicsContext.cpp | 14 ++--- .../GraphicsContextImplementation.cpp | 29 +++++++--- src/osgWrappers/osg/GraphicsContext.cpp | 55 ++++++++++++------- 5 files changed, 111 insertions(+), 50 deletions(-) diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index 15bbfdf83..e074767ec 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -148,7 +148,27 @@ int main( int argc, char **argv ) std::cout<<"Error: failed to loading windowing library: "<getNumScreens(); + for(unsigned int i=0; igetScreenResolution(si, width, height); + + std::cout<<"screen= "< traits = new osg::GraphicsContext::Traits; traits->_windowName = "osgcamera"; + traits->_screenNum = i % numScreens; traits->_x = xpos; traits->_y = ypos; traits->_width = width; diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index e51d4975e..a59e81856 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -24,12 +24,21 @@ class OSG_EXPORT GraphicsContext : public Referenced { public: + struct ScreenIdentifier + { + ScreenIdentifier(): + _displayNum(0), + _screenNum(0) {} + + std::string _hostName; + unsigned int _displayNum; + unsigned int _screenNum; + }; + /** GraphicsContext Traits object provides the specification of what type of graphics context is required.*/ - struct Traits : public osg::Referenced + struct Traits : public osg::Referenced, public ScreenIdentifier { Traits(): - _displayNum(0), - _screenNum(0), _x(0), _y(0), _width(0), @@ -50,12 +59,7 @@ class OSG_EXPORT GraphicsContext : public Referenced _face(0), _mipMapGeneration(false), _sharedContext() {} - - // where graphic context is be hosted. - std::string _hostName; - unsigned int _displayNum; - unsigned int _screenNum; - + // graphics context orginal and size unsigned int _x; unsigned int _y; @@ -92,19 +96,23 @@ class OSG_EXPORT GraphicsContext : public Referenced /** Callback to be implemented to provide access to Windowing API's ability to create Windows/pbuffers.*/ - struct CreateGraphicContextCallback : public osg::Referenced + struct WindowingSystemInterface : public osg::Referenced { + virtual unsigned int getNumScreens(const ScreenIdentifier& screenIdentifier = ScreenIdentifier()) = 0; + + virtual void getScreenResolution(const ScreenIdentifier& screenIdentifier, unsigned int& width, unsigned int& height) = 0; + virtual GraphicsContext* createGraphicsContext(Traits* traits) = 0; - virtual ~CreateGraphicContextCallback() {}; + virtual ~WindowingSystemInterface() {}; }; - /** Set the create graphics context callback - this callback should be supplied by the windows toolkit. */ - static void setCreateGraphicsContextCallback(CreateGraphicContextCallback* callback); + /** Set the querry the windowing system for screens and create graphics context - this functor should be supplied by the windows toolkit. */ + static void setWindowingSystemInterface(WindowingSystemInterface* wsInterface); - /** Get the create graphics context callback*/ - static CreateGraphicContextCallback* getCreateGraphicsContextCallback(); + /** Get the WindowingSystemInterface*/ + static WindowingSystemInterface* getWindowingSystemInterface(); /** Create a graphics context for a specified set of traits.*/ static GraphicsContext* createGraphicsContext(Traits* traits); diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index b9ab28fa8..5b63b065f 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -18,22 +18,22 @@ using namespace osg; -static ref_ptr s_createGraphicsContextCallback; +static ref_ptr s_WindowingSystemInterface; -void GraphicsContext::setCreateGraphicsContextCallback(CreateGraphicContextCallback* callback) +void GraphicsContext::setWindowingSystemInterface(WindowingSystemInterface* callback) { - s_createGraphicsContextCallback = callback; + s_WindowingSystemInterface = callback; } -GraphicsContext::CreateGraphicContextCallback* GraphicsContext::getCreateGraphicsContextCallback() +GraphicsContext::WindowingSystemInterface* GraphicsContext::getWindowingSystemInterface() { - return s_createGraphicsContextCallback.get(); + return s_WindowingSystemInterface.get(); } GraphicsContext* GraphicsContext::createGraphicsContext(Traits* traits) { - if (s_createGraphicsContextCallback.valid()) - return s_createGraphicsContextCallback->createGraphicsContext(traits); + if (s_WindowingSystemInterface.valid()) + return s_WindowingSystemInterface->createGraphicsContext(traits); else return 0; } diff --git a/src/osgProducer/GraphicsContextImplementation.cpp b/src/osgProducer/GraphicsContextImplementation.cpp index 0954ba433..e85316d73 100644 --- a/src/osgProducer/GraphicsContextImplementation.cpp +++ b/src/osgProducer/GraphicsContextImplementation.cpp @@ -20,28 +20,43 @@ using namespace osgProducer; namespace osgProducer { - struct MyCreateGraphicContexCallback : public osg::GraphicsContext::CreateGraphicContextCallback + struct MyWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface { + virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier) + { + return Producer::RenderSurface::getNumberOfScreens(); + } + + virtual void getScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int& width, unsigned int& height) + { + osg::ref_ptr rs = new Producer::RenderSurface; + rs->setHostName(screenIdentifier._hostName); + rs->setDisplayNum(screenIdentifier._displayNum); + rs->setScreenNum(screenIdentifier._screenNum); + rs->getScreenSize(width, height); + } + + virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits* traits) { return new GraphicsContextImplementation(traits); } }; - struct RegisterCreateGraphicsContextCallbackProxy + struct RegisterWindowingSystemInterfaceProxy { - RegisterCreateGraphicsContextCallbackProxy() + RegisterWindowingSystemInterfaceProxy() { - osg::GraphicsContext::setCreateGraphicsContextCallback(new MyCreateGraphicContexCallback); + osg::GraphicsContext::setWindowingSystemInterface(new MyWindowingSystemInterface); } - ~RegisterCreateGraphicsContextCallbackProxy() + ~RegisterWindowingSystemInterfaceProxy() { - osg::GraphicsContext::setCreateGraphicsContextCallback(0); + osg::GraphicsContext::setWindowingSystemInterface(0); } }; - RegisterCreateGraphicsContextCallbackProxy createGraphicsContextCallbackProxy; + RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy; }; diff --git a/src/osgWrappers/osg/GraphicsContext.cpp b/src/osgWrappers/osg/GraphicsContext.cpp index 6caf2f6b4..d65559d05 100644 --- a/src/osgWrappers/osg/GraphicsContext.cpp +++ b/src/osgWrappers/osg/GraphicsContext.cpp @@ -120,13 +120,13 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext) __void__swapBuffersImplementation, "Swap the front and back buffers implementation. ", "Pure virtual - must be implemented by Concrate implementations of GraphicsContext. "); - I_StaticMethod1(void, setCreateGraphicsContextCallback, IN, osg::GraphicsContext::CreateGraphicContextCallback *, callback, - __void__setCreateGraphicsContextCallback__CreateGraphicContextCallback_P1_S, - "Set the create graphics context callback - this callback should be supplied by the windows toolkit. ", + I_StaticMethod1(void, setWindowingSystemInterface, IN, osg::GraphicsContext::WindowingSystemInterface *, wsInterface, + __void__setWindowingSystemInterface__WindowingSystemInterface_P1_S, + "Set the querry the windowing system for screens and create graphics context - this functor should be supplied by the windows toolkit. ", ""); - I_StaticMethod0(osg::GraphicsContext::CreateGraphicContextCallback *, getCreateGraphicsContextCallback, - __CreateGraphicContextCallback_P1__getCreateGraphicsContextCallback_S, - "Get the create graphics context callback. ", + I_StaticMethod0(osg::GraphicsContext::WindowingSystemInterface *, getWindowingSystemInterface, + __WindowingSystemInterface_P1__getWindowingSystemInterface_S, + "Get the WindowingSystemInterface. ", ""); I_StaticMethod1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits, __GraphicsContext_P1__createGraphicsContext__Traits_P1_S, @@ -155,25 +155,21 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext) 0); END_REFLECTOR -BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext::CreateGraphicContextCallback) - I_BaseType(osg::Referenced); - I_Constructor0(____CreateGraphicContextCallback, - "", - ""); - I_Method1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits, - __GraphicsContext_P1__createGraphicsContext__Traits_P1, - "", - ""); -END_REFLECTOR - -BEGIN_OBJECT_REFLECTOR(osg::GraphicsContext::Traits) - I_BaseType(osg::Referenced); - I_Constructor0(____Traits, +BEGIN_VALUE_REFLECTOR(osg::GraphicsContext::ScreenIdentifier) + I_Constructor0(____ScreenIdentifier, "", ""); I_PublicMemberProperty(std::string, _hostName); I_PublicMemberProperty(unsigned int, _displayNum); I_PublicMemberProperty(unsigned int, _screenNum); +END_REFLECTOR + +BEGIN_OBJECT_REFLECTOR(osg::GraphicsContext::Traits) + I_BaseType(osg::Referenced); + I_BaseType(osg::GraphicsContext::ScreenIdentifier); + I_Constructor0(____Traits, + "", + ""); I_PublicMemberProperty(unsigned int, _x); I_PublicMemberProperty(unsigned int, _y); I_PublicMemberProperty(unsigned int, _width); @@ -197,3 +193,22 @@ BEGIN_OBJECT_REFLECTOR(osg::GraphicsContext::Traits) I_PublicMemberProperty(osg::GraphicsContext *, _sharedContext); END_REFLECTOR +BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext::WindowingSystemInterface) + I_BaseType(osg::Referenced); + I_Constructor0(____WindowingSystemInterface, + "", + ""); + I_MethodWithDefaults1(unsigned int, getNumScreens, IN, const osg::GraphicsContext::ScreenIdentifier &, screenIdentifier, osg::GraphicsContext::ScreenIdentifier(), + __unsigned_int__getNumScreens__C5_ScreenIdentifier_R1, + "", + ""); + I_Method3(void, getScreenResolution, IN, const osg::GraphicsContext::ScreenIdentifier &, screenIdentifier, IN, unsigned int &, width, IN, unsigned int &, height, + __void__getScreenResolution__C5_ScreenIdentifier_R1__unsigned_int_R1__unsigned_int_R1, + "", + ""); + I_Method1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits, + __GraphicsContext_P1__createGraphicsContext__Traits_P1, + "", + ""); +END_REFLECTOR +