Added support WindowingSystemInterface for querring the number of screens, the screen size and creating GraphicsContexts.

This commit is contained in:
Robert Osfield 2006-12-17 20:49:01 +00:00
parent 982a4db9e2
commit afc77f9b39
5 changed files with 111 additions and 50 deletions

View File

@ -148,7 +148,27 @@ int main( int argc, char **argv )
std::cout<<"Error: failed to loading windowing library: "<<windowingLibrary<<std::endl;
}
unsigned int numberCameras = 3;
osg::GraphicsContext::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
std::cout<<"No WindowSystemInterface available, cannot create windows."<<std::endl;
return 1;
}
unsigned int numScreens = wsi->getNumScreens();
for(unsigned int i=0; i<numScreens; ++i)
{
osg::GraphicsContext::ScreenIdentifier si;
si._screenNum = 0;
unsigned int width, height;
wsi->getScreenResolution(si, width, height);
std::cout<<"screen= "<<i<<" width="<<width<<" height="<<height<<std::endl;
}
unsigned int numberCameras = numScreens;
while (arguments.read("--cameras",numberCameras)) {}
unsigned int xpos = 0;
@ -186,6 +206,8 @@ int main( int argc, char **argv )
CameraList cameraList;
GraphicsContextSet graphicsContextSet;
// create the cameras, graphic contexts and graphic threads.
bool shareContexts = false;
@ -197,6 +219,7 @@ int main( int argc, char **argv )
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->_windowName = "osgcamera";
traits->_screenNum = i % numScreens;
traits->_x = xpos;
traits->_y = ypos;
traits->_width = width;

View File

@ -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);

View File

@ -18,22 +18,22 @@
using namespace osg;
static ref_ptr<GraphicsContext::CreateGraphicContextCallback> s_createGraphicsContextCallback;
static ref_ptr<GraphicsContext::WindowingSystemInterface> 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;
}

View File

@ -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<Producer::RenderSurface> 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;
};

View File

@ -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