From Stephan Huber, "attached you'll find a small enhancement for GraphicsWindowCocoa to
implement the recently introduced setSyncToVBlank-method. Additionally I added a ToggleSyncToVBlank-eventhandler to osgViewer. I used it to test the code, perhaps you'll find it useful and include it in the distribution."
This commit is contained in:
@@ -1048,7 +1048,7 @@ bool GraphicsWindowCocoa::realizeImplementation()
|
||||
|
||||
useCursor(_traits->useCursor);
|
||||
setWindowName(_traits->windowName);
|
||||
setVSync(_traits->vsync);
|
||||
setSyncToVBlank(_traits->vsync);
|
||||
|
||||
MenubarController::instance()->update();
|
||||
|
||||
@@ -1419,11 +1419,12 @@ void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// setVSync
|
||||
// setSyncToVBlank
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
void GraphicsWindowCocoa::setVSync(bool f)
|
||||
void GraphicsWindowCocoa::setSyncToVBlank(bool f)
|
||||
{
|
||||
if (_traits.valid()) _traits->vsync = f;
|
||||
GLint VBL(f?1:0);
|
||||
[_context setValues:&VBL forParameter:NSOpenGLCPSwapInterval];
|
||||
}
|
||||
|
||||
@@ -626,6 +626,66 @@ void LODScaleHandler::getUsage(osg::ApplicationUsage& usage) const
|
||||
}
|
||||
}
|
||||
|
||||
ToggleSyncToVBlankHandler::ToggleSyncToVBlankHandler():
|
||||
_keyEventToggleSyncToVBlank('v')
|
||||
{
|
||||
}
|
||||
|
||||
bool ToggleSyncToVBlankHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
||||
{
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
|
||||
if (!view) return false;
|
||||
|
||||
osgViewer::ViewerBase* viewer = view->getViewerBase();
|
||||
|
||||
if (viewer == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ea.getHandled()) return false;
|
||||
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
{
|
||||
if (ea.getKey() == _keyEventToggleSyncToVBlank)
|
||||
{
|
||||
// Increase resolution
|
||||
osgViewer::Viewer::Windows windows;
|
||||
|
||||
viewer->getWindows(windows);
|
||||
for(osgViewer::Viewer::Windows::iterator itr = windows.begin();
|
||||
itr != windows.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->setSyncToVBlank( !(*itr)->getSyncToVBlank() );
|
||||
}
|
||||
|
||||
aa.requestRedraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ToggleSyncToVBlankHandler::getUsage(osg::ApplicationUsage& usage) const
|
||||
{
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr<<char(_keyEventToggleSyncToVBlank);
|
||||
usage.addKeyboardMouseBinding(ostr.str(),"Toggle SyncToVBlank.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InteractiveImageHandler::InteractiveImageHandler(osg::Image* image) :
|
||||
_image(image),
|
||||
_texture(0),
|
||||
|
||||
Reference in New Issue
Block a user