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:
parent
f0baf6abba
commit
da1a354502
@ -379,6 +379,29 @@ class OSGVIEWER_EXPORT LODScaleHandler : public osgGA::GUIEventHandler
|
|||||||
int _keyEventDecreaseLODScale;
|
int _keyEventDecreaseLODScale;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Event handler for toggling SyncToVBlank.*/
|
||||||
|
class OSGVIEWER_EXPORT ToggleSyncToVBlankHandler : public osgGA::GUIEventHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ToggleSyncToVBlankHandler();
|
||||||
|
|
||||||
|
void setKeyEventToggleSyncToVBlankHandler(int key) { _keyEventToggleSyncToVBlank = key; }
|
||||||
|
int getKeyEventToggleSyncToVBlankHandler() const { return _keyEventToggleSyncToVBlank; }
|
||||||
|
|
||||||
|
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||||
|
|
||||||
|
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||||
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
int _keyEventToggleSyncToVBlank;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::
|
|||||||
GraphicsWindowCocoaWindow* getWindow() { return _window; }
|
GraphicsWindowCocoaWindow* getWindow() { return _window; }
|
||||||
NSOpenGLPixelFormat* getPixelFormat() { return _pixelformat; }
|
NSOpenGLPixelFormat* getPixelFormat() { return _pixelformat; }
|
||||||
|
|
||||||
void setVSync(bool f);
|
virtual void setSyncToVBlank(bool f);
|
||||||
|
|
||||||
/** adapts a resize / move of the window, coords in global screen space */
|
/** adapts a resize / move of the window, coords in global screen space */
|
||||||
void adaptResize(int x, int y, int w, int h);
|
void adaptResize(int x, int y, int w, int h);
|
||||||
|
@ -1048,7 +1048,7 @@ bool GraphicsWindowCocoa::realizeImplementation()
|
|||||||
|
|
||||||
useCursor(_traits->useCursor);
|
useCursor(_traits->useCursor);
|
||||||
setWindowName(_traits->windowName);
|
setWindowName(_traits->windowName);
|
||||||
setVSync(_traits->vsync);
|
setSyncToVBlank(_traits->vsync);
|
||||||
|
|
||||||
MenubarController::instance()->update();
|
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);
|
GLint VBL(f?1:0);
|
||||||
[_context setValues:&VBL forParameter:NSOpenGLCPSwapInterval];
|
[_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) :
|
InteractiveImageHandler::InteractiveImageHandler(osg::Image* image) :
|
||||||
_image(image),
|
_image(image),
|
||||||
_texture(0),
|
_texture(0),
|
||||||
|
Loading…
Reference in New Issue
Block a user