Refactored the support for stereo and keystone RTT setup so that it can be applied to an existing Camera.

This commit is contained in:
Robert Osfield
2013-05-20 19:24:34 +00:00
parent acb4ba8554
commit 455ebbc5f1
8 changed files with 134 additions and 252 deletions

View File

@@ -31,6 +31,7 @@
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers> #include <osgViewer/ViewerEventHandlers>
#include <osgViewer/config/SingleWindow> #include <osgViewer/config/SingleWindow>
#include <osgViewer/config/SingleScreen>
#include <osgViewer/config/WoWVxDisplay> #include <osgViewer/config/WoWVxDisplay>
@@ -75,6 +76,7 @@ int main( int argc, char **argv )
OSG_NOTICE<<" keystone filename = "<<*itr<<std::endl; OSG_NOTICE<<" keystone filename = "<<*itr<<std::endl;
} }
ds->setKeystoneHint(true);
if (!ds->getKeystoneFileNames().empty()) if (!ds->getKeystoneFileNames().empty())
{ {
@@ -88,29 +90,13 @@ int main( int argc, char **argv )
std::string filename; std::string filename;
keystone->getUserValue("filename",filename); keystone->getUserValue("filename",filename);
OSG_NOTICE<<"Loaded keystone "<<filename<<", "<<keystone<<std::endl; OSG_NOTICE<<"Loaded keystone "<<filename<<", "<<keystone<<std::endl;
ds->getKeystones().push_back(keystone);
} }
} }
} }
osgViewer::Keystone::loadKeystoneFiles(ds); viewer.apply(new osgViewer::SingleScreen(0));
if (!ds->getKeystoneHint())
{
OSG_NOTICE<<"Keystone disabled"<<std::endl;
}
if (ds->getStereo())
{
viewer.setUpViewForStereo();
}
else
{
osg::ref_ptr<osgViewer::Keystone> keystone = 0;
if (!(ds->getKeystones().empty())) keystone = dynamic_cast<osgViewer::Keystone*>(ds->getKeystones().front().get());
if (!keystone) keystone = new osgViewer::Keystone;
viewer.setUpViewForKeystone(keystone.get());
}
viewer.realize(); viewer.realize();

View File

@@ -289,8 +289,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture); osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture);
osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone); osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone);
osg::Camera* assignStereoCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, double eyeScale); osg::Camera* assignStereoCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, double eyeScale);
void setUpViewForStereo(); void assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySettings* ds);
void setUpViewForKeystone(Keystone* keystone);
struct StereoSlaveCallback : public osg::View::Slave::UpdateSlaveCallback struct StereoSlaveCallback : public osg::View::Slave::UpdateSlaveCallback
{ {

View File

@@ -23,9 +23,9 @@ class OSGVIEWER_EXPORT SingleWindow : public ViewConfig
{ {
public: public:
SingleWindow():_x(0),_y(0),_width(-1),_height(-1),_screenNum(0),_border(true),_overrideRedirect(false) {} SingleWindow():_x(0),_y(0),_width(-1),_height(-1),_screenNum(0),_windowDecoration(true),_overrideRedirect(false) {}
SingleWindow(int x, int y, int width, int height, unsigned int screenNum=0):_x(x),_y(y),_width(width),_height(height),_screenNum(screenNum),_border(true),_overrideRedirect(false) {} SingleWindow(int x, int y, int width, int height, unsigned int screenNum=0):_x(x),_y(y),_width(width),_height(height),_screenNum(screenNum),_windowDecoration(true),_overrideRedirect(false) {}
SingleWindow(const SingleWindow& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):ViewConfig(rhs,copyop), _x(rhs._x),_y(rhs._y),_width(rhs._width),_height(rhs._height),_screenNum(rhs._screenNum),_border(rhs._border), _overrideRedirect(rhs._overrideRedirect) {} SingleWindow(const SingleWindow& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):ViewConfig(rhs,copyop), _x(rhs._x),_y(rhs._y),_width(rhs._width),_height(rhs._height),_screenNum(rhs._screenNum),_windowDecoration(rhs._windowDecoration), _overrideRedirect(rhs._overrideRedirect) {}
META_Object(osgViewer,SingleWindow); META_Object(osgViewer,SingleWindow);
@@ -46,8 +46,8 @@ class OSGVIEWER_EXPORT SingleWindow : public ViewConfig
void setScreenNum(unsigned int sn) { _screenNum = sn; } void setScreenNum(unsigned int sn) { _screenNum = sn; }
unsigned int getScreenNum() const { return _screenNum; } unsigned int getScreenNum() const { return _screenNum; }
void setBorder(bool border) { _border = border; } void setWindowDecoration(bool wd) { _windowDecoration = wd; }
bool getBorder() const { return _border; } bool getWindowDecoration() const { return _windowDecoration; }
void setOverrideRedirect(bool override) { _overrideRedirect = override; } void setOverrideRedirect(bool override) { _overrideRedirect = override; }
bool getOverrideRedirect() const { return _overrideRedirect; } bool getOverrideRedirect() const { return _overrideRedirect; }
@@ -56,7 +56,7 @@ class OSGVIEWER_EXPORT SingleWindow : public ViewConfig
int _x, _y, _width, _height; int _x, _y, _width, _height;
unsigned int _screenNum; unsigned int _screenNum;
bool _border; bool _windowDecoration;
bool _overrideRedirect; bool _overrideRedirect;
}; };

View File

@@ -1385,10 +1385,10 @@ static const GLubyte patternCheckerboard[] = {
0xAA, 0xAA, 0xAA, 0xAA}; 0xAA, 0xAA, 0xAA, 0xAA};
void View::setUpViewForStereo() void View::assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySettings* ds)
{ {
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); if (!camera || camera->getGraphicsContext()==0) return;
if (!ds->getStereo()) return; if (!ds->getStereo() && !ds->getKeystoneHint()) return;
ds->setUseSceneViewForStereoHint(false); ds->setUseSceneViewForStereoHint(false);
@@ -1418,53 +1418,37 @@ void View::setUpViewForStereo()
double distance = osg::DisplaySettings::instance()->getScreenDistance(); double distance = osg::DisplaySettings::instance()->getScreenDistance();
double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0); double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0);
getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 1.0f,10000.0f); camera->setProjectionMatrixAsPerspective( vfov, width/height, 1.0f,10000.0f);
} }
int screenNum = 0; osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext();
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); osg::ref_ptr<osg::GraphicsContext::Traits> traits = const_cast<osg::GraphicsContext::Traits*>(camera->getGraphicsContext()->getTraits());
if (!wsi)
if (!ds->getStereo())
{ {
OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; // load or create a Keystone object
return; osg::ref_ptr<osgViewer::Keystone> keystone = 0;
} if (!(ds->getKeystones().empty())) keystone = dynamic_cast<osgViewer::Keystone*>(ds->getKeystones().front().get());
if (!keystone) keystone = new osgViewer::Keystone;
// unsigned int numScreens = wsi->getNumScreens(si); // create distortion texture
osg::ref_ptr<osg::Texture> texture = createDistortionTexture(traits->width, traits->height);
osg::GraphicsContext::ScreenIdentifier si; // create RTT Camera
si.readDISPLAY(); assignRenderToTextureCamera(gc.get(), traits->width, traits->height, texture.get());
// displayNum has not been set so reset it to 0. // create Keystone distortion camera
if (si.displayNum<0) si.displayNum = 0; osg::ref_ptr<osg::Camera> distortion_camera = assignKeystoneDistortionCamera(ds, gc.get(),
0, 0, traits->width, traits->height,
traits->doubleBuffer ? GL_BACK : GL_FRONT,
texture.get(), keystone.get());
// attach Keystone editing event handler.
distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
si.screenNum = screenNum; camera->setGraphicsContext(0);
unsigned int width, height;
wsi->getScreenResolution(si, width, height);
// width/=2; height/=2;
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
traits->hostName = si.hostName;
traits->displayNum = si.displayNum;
traits->screenNum = si.screenNum;
traits->x = 0;
traits->y = 0;
traits->width = width;
traits->height = height;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
OSG_NOTICE<<"traits->stencil="<<traits->stencil<<std::endl;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc)
{
OSG_NOTICE<<"GraphicsWindow has not been created successfully."<<std::endl;
return; return;
} }
@@ -1472,6 +1456,9 @@ void View::setUpViewForStereo()
{ {
case(osg::DisplaySettings::QUAD_BUFFER): case(osg::DisplaySettings::QUAD_BUFFER):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
// left Camera left buffer // left Camera left buffer
osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK_LEFT : GL_FRONT_LEFT, -1.0); osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK_LEFT : GL_FRONT_LEFT, -1.0);
left_camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); left_camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
@@ -1556,6 +1543,9 @@ void View::setUpViewForStereo()
} }
case(osg::DisplaySettings::ANAGLYPHIC): case(osg::DisplaySettings::ANAGLYPHIC):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
// left Camera red // left Camera red
osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0); osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0);
left_camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); left_camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
@@ -1635,9 +1625,9 @@ void View::setUpViewForStereo()
right_keystone_camera->getOrCreateStateSet()->setAttribute(new osg::ColorMask(false, true, true, true)); right_keystone_camera->getOrCreateStateSet()->setAttribute(new osg::ColorMask(false, true, true, true));
// attach Keystone editing event handler. // attach Keystone editing event handler.
right_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get())); left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get()));
getCamera()->setAllowEventFocus(false); camera->setAllowEventFocus(false);
} }
else else
@@ -1668,15 +1658,17 @@ void View::setUpViewForStereo()
// create Keystone distortion camera // create Keystone distortion camera
osg::ref_ptr<osg::Camera> camera = assignKeystoneDistortionCamera(ds, gc.get(), osg::ref_ptr<osg::Camera> distortion_camera = assignKeystoneDistortionCamera(ds, gc.get(),
0, 0, traits->width, traits->height, 0, 0, traits->width, traits->height,
traits->doubleBuffer ? GL_BACK : GL_FRONT, traits->doubleBuffer ? GL_BACK : GL_FRONT,
texture.get(), keystone.get()); texture.get(), keystone.get());
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
// attach Keystone editing event handler. // attach Keystone editing event handler.
camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
camera->setAllowEventFocus(false);
} }
} }
@@ -1684,6 +1676,9 @@ void View::setUpViewForStereo()
} }
case(osg::DisplaySettings::HORIZONTAL_SPLIT): case(osg::DisplaySettings::HORIZONTAL_SPLIT):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
bool left_eye_left_viewport = ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT; bool left_eye_left_viewport = ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT;
int left_start = (left_eye_left_viewport) ? 0 : traits->width/2; int left_start = (left_eye_left_viewport) ? 0 : traits->width/2;
int right_start = (left_eye_left_viewport) ? traits->width/2 : 0; int right_start = (left_eye_left_viewport) ? traits->width/2 : 0;
@@ -1765,7 +1760,7 @@ void View::setUpViewForStereo()
// attach Keystone editing event handler. // attach Keystone editing event handler.
right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get())); right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get()));
getCamera()->setAllowEventFocus(false); camera->setAllowEventFocus(false);
} }
@@ -1773,6 +1768,9 @@ void View::setUpViewForStereo()
} }
case(osg::DisplaySettings::VERTICAL_SPLIT): case(osg::DisplaySettings::VERTICAL_SPLIT):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
bool left_eye_bottom_viewport = ds->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_BOTTOM_VIEWPORT; bool left_eye_bottom_viewport = ds->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_BOTTOM_VIEWPORT;
int left_start = (left_eye_bottom_viewport) ? 0 : traits->height/2; int left_start = (left_eye_bottom_viewport) ? 0 : traits->height/2;
int right_start = (left_eye_bottom_viewport) ? traits->height/2 : 0; int right_start = (left_eye_bottom_viewport) ? traits->height/2 : 0;
@@ -1861,7 +1859,7 @@ void View::setUpViewForStereo()
// attach Keystone editing event handler. // attach Keystone editing event handler.
right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get())); right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get()));
getCamera()->setAllowEventFocus(false); camera->setAllowEventFocus(false);
} }
@@ -1869,6 +1867,9 @@ void View::setUpViewForStereo()
} }
case(osg::DisplaySettings::LEFT_EYE): case(osg::DisplaySettings::LEFT_EYE):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
// single window, whole window, just left eye offsets // single window, whole window, just left eye offsets
osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0); osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0);
@@ -1903,20 +1904,23 @@ void View::setUpViewForStereo()
// create Keystone distortion camera // create Keystone distortion camera
osg::ref_ptr<osg::Camera> camera = assignKeystoneDistortionCamera(ds, gc.get(), osg::ref_ptr<osg::Camera> distortion_camera = assignKeystoneDistortionCamera(ds, gc.get(),
0, 0, traits->width, traits->height, 0, 0, traits->width, traits->height,
traits->doubleBuffer ? GL_BACK : GL_FRONT, traits->doubleBuffer ? GL_BACK : GL_FRONT,
texture.get(), keystone.get()); texture.get(), keystone.get());
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
// attach Keystone editing event handler. // attach Keystone editing event handler.
camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
} }
break; break;
} }
case(osg::DisplaySettings::RIGHT_EYE): case(osg::DisplaySettings::RIGHT_EYE):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
// single window, whole window, just right eye offsets // single window, whole window, just right eye offsets
osg::ref_ptr<osg::Camera> right_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0); osg::ref_ptr<osg::Camera> right_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0);
@@ -1950,15 +1954,15 @@ void View::setUpViewForStereo()
right_camera->attach(osg::Camera::COLOR_BUFFER, texture.get()); right_camera->attach(osg::Camera::COLOR_BUFFER, texture.get());
// create Keystone distortion camera // create Keystone distortion camera
osg::ref_ptr<osg::Camera> camera = assignKeystoneDistortionCamera(ds, gc.get(), osg::ref_ptr<osg::Camera> distortion_camera = assignKeystoneDistortionCamera(ds, gc.get(),
0, 0, traits->width, traits->height, 0, 0, traits->width, traits->height,
traits->doubleBuffer ? GL_BACK : GL_FRONT, traits->doubleBuffer ? GL_BACK : GL_FRONT,
texture.get(), keystone.get()); texture.get(), keystone.get());
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); distortion_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1);
// attach Keystone editing event handler. // attach Keystone editing event handler.
camera->addEventCallback(new KeystoneHandler(keystone.get())); distortion_camera->addEventCallback(new KeystoneHandler(keystone.get()));
} }
break; break;
} }
@@ -1966,6 +1970,9 @@ void View::setUpViewForStereo()
case(osg::DisplaySettings::VERTICAL_INTERLACE): case(osg::DisplaySettings::VERTICAL_INTERLACE):
case(osg::DisplaySettings::CHECKERBOARD): case(osg::DisplaySettings::CHECKERBOARD):
{ {
// disconect the camera from the graphics context.
camera->setGraphicsContext(0);
// set up the stencil buffer // set up the stencil buffer
{ {
osg::ref_ptr<osg::Camera> camera = new osg::Camera; osg::ref_ptr<osg::Camera> camera = new osg::Camera;
@@ -2016,93 +2023,29 @@ void View::setUpViewForStereo()
// left Camera // left Camera
{ {
osg::ref_ptr<osg::Camera> camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0); osg::ref_ptr<osg::Camera> left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0);
camera->setClearMask(0); left_camera->setClearMask(0);
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); left_camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); left_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1);
osg::ref_ptr<osg::Stencil> stencil = new osg::Stencil; osg::ref_ptr<osg::Stencil> stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::EQUAL, 0, ~0u); stencil->setFunction(osg::Stencil::EQUAL, 0, ~0u);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP);
camera->getOrCreateStateSet()->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON); left_camera->getOrCreateStateSet()->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON);
} }
// right Camera // right Camera
{ {
osg::ref_ptr<osg::Camera> camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0); osg::ref_ptr<osg::Camera> right_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0);
camera->setClearMask(GL_DEPTH_BUFFER_BIT); right_camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2);
osg::ref_ptr<osg::Stencil> stencil = new osg::Stencil; osg::ref_ptr<osg::Stencil> stencil = new osg::Stencil;
stencil->setFunction(osg::Stencil::NOTEQUAL, 0, ~0u); stencil->setFunction(osg::Stencil::NOTEQUAL, 0, ~0u);
stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP);
camera->getOrCreateStateSet()->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON); right_camera->getOrCreateStateSet()->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON);
} }
break; break;
} }
} }
} }
void View::setUpViewForKeystone(Keystone* keystone)
{
int screenNum = 0;
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
return;
}
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(si, width, height);
// width/=2; height/=2;
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;
traits->height = height;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc)
{
OSG_NOTICE<<"GraphicsWindow has not been created successfully."<<std::endl;
return;
}
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get();
// create distortion texture
osg::ref_ptr<osg::Texture> texture = createDistortionTexture(width, height);
// create RTT Camera
assignRenderToTextureCamera(gc.get(), width, height, texture.get());
// create Keystone distortion camera
osg::ref_ptr<osg::Camera> camera = assignKeystoneDistortionCamera(ds, gc.get(),
0, 0, width, height,
traits->doubleBuffer ? GL_BACK : GL_FRONT,
texture.get(), keystone);
// attach Keystone editing event handler.
camera->addEventCallback(new KeystoneHandler(keystone));
}

View File

@@ -21,6 +21,7 @@
#include <osgDB/Registry> #include <osgDB/Registry>
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgGA/TrackballManipulator> #include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
@@ -300,6 +301,9 @@ bool Viewer::readConfiguration(const std::string& filename)
{ {
OSG_NOTICE<<"Using osgViewer::Config : "<<config->className()<<std::endl; OSG_NOTICE<<"Using osgViewer::Config : "<<config->className()<<std::endl;
config->configure(*this); config->configure(*this);
osgDB::writeObjectFile(*config,"test.osgt");
return true; return true;
} }
@@ -468,29 +472,13 @@ void Viewer::realize()
if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum);
else setUpViewInWindow(x,y,width,height); else setUpViewInWindow(x,y,width,height);
} }
else if (screenNum>=0)
{
setUpViewOnSingleScreen(screenNum);
}
else else
{ {
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); setUpViewAcrossAllScreens();
if (ds->getKeystoneHint() && !ds->getKeystoneFileNames().empty()) osgViewer::Keystone::loadKeystoneFiles(ds);
bool useKeystones = ds->getKeystoneHint() && !ds->getKeystones().empty();
if (ds->getStereo() && (!ds->getUseSceneViewForStereoHint() || useKeystones))
{
setUpViewForStereo();
}
else if (useKeystones)
{
osgViewer::Keystone* keystone = dynamic_cast<osgViewer::Keystone*>(ds->getKeystones().front().get());
setUpViewForKeystone(keystone);
}
else if (screenNum>=0)
{
setUpViewOnSingleScreen(screenNum);
}
else
{
setUpViewAcrossAllScreens();
}
} }
} }

View File

@@ -16,73 +16,15 @@
#include <osgViewer/View> #include <osgViewer/View>
#include <osgViewer/GraphicsWindow> #include <osgViewer/GraphicsWindow>
#include <osgViewer/config/SingleWindow>
#include <osg/io_utils> #include <osg/io_utils>
using namespace osgViewer; using namespace osgViewer;
void SingleScreen::configure(osgViewer::View& view) const void SingleScreen::configure(osgViewer::View& view) const
{ {
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); osg::ref_ptr<osgViewer::SingleWindow> singleWindow = new SingleWindow(0,0,-1,-1,_screenNum);
if (!wsi) singleWindow->setWindowDecoration(false);
{ singleWindow->configure(view);
OSG_NOTICE<<"SingleScreen::configure() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
return;
}
osg::DisplaySettings* ds = getActiveDisplaySetting(view);;
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(si, width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
traits->hostName = si.hostName;
traits->displayNum = si.displayNum;
traits->screenNum = si.screenNum;
traits->x = 0;
traits->y = 0;
traits->width = width;
traits->height = height;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
view.getCamera()->setGraphicsContext(gc.get());
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
if (gw)
{
OSG_INFO<<"SingleScreen::configure() - GraphicsWindow has been created successfully."<<std::endl;
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
}
else
{
OSG_NOTICE<<" GraphicsWindow has not been created successfully."<<std::endl;
}
double fovy, aspectRatio, zNear, zFar;
view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
double newAspectRatio = double(traits->width) / double(traits->height);
double aspectRatioChange = newAspectRatio / aspectRatio;
if (aspectRatioChange != 1.0)
{
view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
}
view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
view.getCamera()->setDrawBuffer(buffer);
view.getCamera()->setReadBuffer(buffer);
} }

View File

@@ -15,6 +15,13 @@
#include <osgViewer/Renderer> #include <osgViewer/Renderer>
#include <osgViewer/View> #include <osgViewer/View>
#include <osgViewer/GraphicsWindow> #include <osgViewer/GraphicsWindow>
#include <osgViewer/Keystone>
#include <osg/TextureRectangle>
#include <osg/Texture1D>
#include <osg/TexMat>
#include <osg/Stencil>
#include <osg/PolygonStipple>
#include <osg/io_utils> #include <osg/io_utils>
@@ -29,7 +36,7 @@ void SingleWindow::configure(osgViewer::View& view) const
return; return;
} }
osg::DisplaySettings* ds = getActiveDisplaySetting(view);; osg::DisplaySettings* ds = getActiveDisplaySetting(view);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);
@@ -41,7 +48,7 @@ void SingleWindow::configure(osgViewer::View& view) const
traits->y = _y; traits->y = _y;
traits->width = _width; traits->width = _width;
traits->height = _height; traits->height = _height;
traits->windowDecoration = _border; traits->windowDecoration = _windowDecoration;
traits->overrideRedirect = _overrideRedirect; traits->overrideRedirect = _overrideRedirect;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
@@ -93,4 +100,21 @@ void SingleWindow::configure(osgViewer::View& view) const
view.getCamera()->setDrawBuffer(buffer); view.getCamera()->setDrawBuffer(buffer);
view.getCamera()->setReadBuffer(buffer); view.getCamera()->setReadBuffer(buffer);
OSG_NOTICE<<"Here"<<std::endl;
if (ds->getKeystoneHint())
{
if (ds->getKeystoneHint() && !ds->getKeystoneFileNames().empty())
{
osgViewer::Keystone::loadKeystoneFiles(ds);
}
if (ds->getKeystones().empty()) ds->getKeystones().push_back(new Keystone);
view.assignStereoOrKeystoneToCamera(view.getCamera(), ds);
}
else if (ds->getStereo() && ds->getUseSceneViewForStereoHint())
{
view.assignStereoOrKeystoneToCamera(view.getCamera(), ds);
}
} }

View File

@@ -14,6 +14,6 @@ REGISTER_OBJECT_WRAPPER( osgViewer_SingleWindow,
ADD_INT_SERIALIZER( Width, -1); ADD_INT_SERIALIZER( Width, -1);
ADD_INT_SERIALIZER( Height, -1); ADD_INT_SERIALIZER( Height, -1);
ADD_UINT_SERIALIZER( ScreenNum, 0u); ADD_UINT_SERIALIZER( ScreenNum, 0u);
ADD_BOOL_SERIALIZER( Border, true); ADD_BOOL_SERIALIZER( WindowDecoration, true);
ADD_BOOL_SERIALIZER( OverrideRedirect, true); ADD_BOOL_SERIALIZER( OverrideRedirect, false);
} }