Added perlimnary support for reading the DISPLAY variable.
This commit is contained in:
@@ -29,24 +29,24 @@ class OSG_EXPORT GraphicsContext : public Object
|
||||
|
||||
struct OSG_EXPORT ScreenIdentifier
|
||||
{
|
||||
ScreenIdentifier():
|
||||
displayNum(0),
|
||||
screenNum(0) {}
|
||||
ScreenIdentifier();
|
||||
|
||||
ScreenIdentifier(unsigned int in_screenNum):
|
||||
displayNum(0),
|
||||
screenNum(in_screenNum) {}
|
||||
ScreenIdentifier(int in_screenNum);
|
||||
|
||||
ScreenIdentifier(const std::string& in_hostName,unsigned int in_displayNum, unsigned int in_screenNum):
|
||||
hostName(in_hostName),
|
||||
displayNum(in_displayNum),
|
||||
screenNum(in_screenNum) {}
|
||||
|
||||
ScreenIdentifier(const std::string& in_hostName,int in_displayNum, int in_screenNum);
|
||||
|
||||
/** Return the display name in the form hostName::displayNum:screenNum. */
|
||||
std::string displayName() const;
|
||||
|
||||
/** Read the DISPLAY environmental variable, and set the ScreenIdentifier accordingly.*/
|
||||
void readDISPLAY();
|
||||
|
||||
/** Set the screenIndentifier from the displayName string.*/
|
||||
void setScreenIdentifier(const std::string& displayName);
|
||||
|
||||
std::string hostName;
|
||||
unsigned int displayNum;
|
||||
unsigned int screenNum;
|
||||
int displayNum;
|
||||
int screenNum;
|
||||
};
|
||||
|
||||
/** GraphicsContext Traits object provides the specification of what type of graphics context is required.*/
|
||||
@@ -138,6 +138,7 @@ class OSG_EXPORT GraphicsContext : public Object
|
||||
/** Callback to be implemented to provide access to Windowing API's ability to create Windows/pbuffers.*/
|
||||
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;
|
||||
|
||||
@@ -132,7 +132,7 @@ class OSG_EXPORT View : public osg::Object
|
||||
|
||||
virtual ~View();
|
||||
|
||||
virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera) { return 0; }
|
||||
virtual osg::GraphicsOperation* createRenderer(osg::Camera*) { return 0; }
|
||||
|
||||
osg::ref_ptr<osg::Stats> _stats;
|
||||
|
||||
|
||||
@@ -59,6 +59,18 @@ GraphicsContext* GraphicsContext::createGraphicsContext(Traits* traits)
|
||||
return 0;
|
||||
}
|
||||
|
||||
GraphicsContext::ScreenIdentifier::ScreenIdentifier():
|
||||
displayNum(0),
|
||||
screenNum(0) {}
|
||||
|
||||
GraphicsContext::ScreenIdentifier::ScreenIdentifier(int in_screenNum):
|
||||
displayNum(0),
|
||||
screenNum(in_screenNum) {}
|
||||
|
||||
GraphicsContext::ScreenIdentifier::ScreenIdentifier(const std::string& in_hostName,int in_displayNum, int in_screenNum):
|
||||
hostName(in_hostName),
|
||||
displayNum(in_displayNum),
|
||||
screenNum(in_screenNum) {}
|
||||
|
||||
std::string GraphicsContext::ScreenIdentifier::displayName() const
|
||||
{
|
||||
@@ -67,6 +79,60 @@ std::string GraphicsContext::ScreenIdentifier::displayName() const
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
void GraphicsContext::ScreenIdentifier::readDISPLAY()
|
||||
{
|
||||
const char* ptr = 0;
|
||||
if ((ptr=getenv("DISPLAY")) != 0)
|
||||
{
|
||||
setScreenIdentifier(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContext::ScreenIdentifier::setScreenIdentifier(const std::string& displayName)
|
||||
{
|
||||
std::string::size_type colon = displayName.find_last_of(':');
|
||||
std::string::size_type point = displayName.find_last_of('.');
|
||||
|
||||
if (point!=std::string::npos &&
|
||||
colon==std::string::npos &&
|
||||
point < colon) point = std::string::npos;
|
||||
|
||||
if (colon==std::string::npos)
|
||||
{
|
||||
hostName = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
hostName = displayName.substr(0,colon);
|
||||
}
|
||||
|
||||
std::string::size_type startOfDisplayNum = (colon==std::string::npos) ? 0 : colon+1;
|
||||
std::string::size_type endOfDisplayNum = (point==std::string::npos) ? displayName.size() : point;
|
||||
|
||||
if (startOfDisplayNum<endOfDisplayNum)
|
||||
{
|
||||
displayNum = atoi(displayName.substr(startOfDisplayNum,endOfDisplayNum-startOfDisplayNum).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
displayNum = -1;
|
||||
}
|
||||
|
||||
if (point!=std::string::npos && point+1<displayName.size())
|
||||
{
|
||||
screenNum = atoi(displayName.substr(point+1,displayName.size()-point-1).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
screenNum = -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
osg::notify(osg::NOTICE)<<" hostName ["<<hostName<<"]"<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" displayNum "<<displayNum<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" screenNum "<<screenNum<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
class ContextData
|
||||
{
|
||||
|
||||
@@ -266,13 +266,24 @@ void View::setUpViewAcrossAllScreens()
|
||||
double fovy, aspectRatio, zNear, zFar;
|
||||
_camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
|
||||
unsigned int numScreens = wsi->getNumScreens();
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
unsigned int numScreens = wsi->getNumScreens(si);
|
||||
if (numScreens==1)
|
||||
{
|
||||
if (si.screenNum<0) si.screenNum = 0;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
@@ -336,10 +347,15 @@ void View::setUpViewAcrossAllScreens()
|
||||
|
||||
for(unsigned int i=0; i<numScreens; ++i)
|
||||
{
|
||||
si.screenNum = i;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(i), width, height);
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->screenNum = i;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
@@ -410,6 +426,10 @@ void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int s
|
||||
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||
|
||||
traits->readDISPLAY();
|
||||
if (traits->displayNum<0) traits->displayNum = 0;
|
||||
|
||||
traits->screenNum = screenNum;
|
||||
traits->x = x;
|
||||
traits->y = y;
|
||||
@@ -471,11 +491,21 @@ void View::setUpViewOnSingleScreen(unsigned int screenNum)
|
||||
|
||||
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
||||
|
||||
osg::GraphicsContext::ScreenIdentifier si;
|
||||
si.readDISPLAY();
|
||||
|
||||
// displayNum has not been set so reset it to 0.
|
||||
if (si.displayNum<0) si.displayNum = 0;
|
||||
|
||||
si.screenNum = screenNum;
|
||||
|
||||
unsigned int width, height;
|
||||
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(screenNum), width, height);
|
||||
wsi->getScreenResolution(si, width, height);
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||
traits->screenNum = screenNum;
|
||||
traits->hostName = si.hostName;
|
||||
traits->displayNum = si.displayNum;
|
||||
traits->screenNum = si.screenNum;
|
||||
traits->x = 0;
|
||||
traits->y = 0;
|
||||
traits->width = width;
|
||||
|
||||
Reference in New Issue
Block a user