From Ulrich Hertlien with little bits from Robert Osfield and Chris Hanson, added provisionl support for controlling sync to vblank.
This commit is contained in:
@@ -134,6 +134,14 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
|
|||||||
/** Create a new mouse cursor from the usual bitmap data.*/
|
/** Create a new mouse cursor from the usual bitmap data.*/
|
||||||
//virtual MouseCursor createCursor(const char *data, const char *mask, unsigned w, unsigned h, unsigned hotx, unsigned hoty) { osg::notify(osg::NOTICE)<<"GraphicsWindow::createCursor(..) not implemented."<<std::endl; }
|
//virtual MouseCursor createCursor(const char *data, const char *mask, unsigned w, unsigned h, unsigned hotx, unsigned hoty) { osg::notify(osg::NOTICE)<<"GraphicsWindow::createCursor(..) not implemented."<<std::endl; }
|
||||||
|
|
||||||
|
/** Set sync-to-vblank. */
|
||||||
|
virtual void setSyncToVBlank(bool on)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE) << "GraphicsWindow::setSyncToVBlank(" << on << ") not implemented." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getSyncToVBlank() const { return _traits.valid() ? _traits->vsync : true; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Return whether a valid and usable GraphicsContext has been created.*/
|
/** Return whether a valid and usable GraphicsContext has been created.*/
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ class OSGVIEWER_EXPORT HelpHandler : public osgGA::GUIEventHandler
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Event handler for adding on screen stats reporting to Viewers.*/
|
/**
|
||||||
|
* Event handler for adding on screen stats reporting to Viewers.
|
||||||
|
*/
|
||||||
class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -91,6 +93,9 @@ class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
|||||||
void setKeyEventPrintsOutStats(int key) { _keyEventPrintsOutStats = key; }
|
void setKeyEventPrintsOutStats(int key) { _keyEventPrintsOutStats = key; }
|
||||||
int getKeyEventPrintsOutStats() const { return _keyEventPrintsOutStats; }
|
int getKeyEventPrintsOutStats() const { return _keyEventPrintsOutStats; }
|
||||||
|
|
||||||
|
void setKeyEventToggleVSync(int key) { _keyEventToggleVSync = key; }
|
||||||
|
int getKeyEventToggleVSync() const { return _keyEventToggleVSync; }
|
||||||
|
|
||||||
double getBlockMultiplier() const { return _blockMultiplier; }
|
double getBlockMultiplier() const { return _blockMultiplier; }
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
@@ -123,6 +128,7 @@ class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
|||||||
|
|
||||||
int _keyEventTogglesOnScreenStats;
|
int _keyEventTogglesOnScreenStats;
|
||||||
int _keyEventPrintsOutStats;
|
int _keyEventPrintsOutStats;
|
||||||
|
int _keyEventToggleVSync;
|
||||||
|
|
||||||
int _statsType;
|
int _statsType;
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer:
|
|||||||
_initialized(false),
|
_initialized(false),
|
||||||
_realized(false),
|
_realized(false),
|
||||||
_ownsWindow(true),
|
_ownsWindow(true),
|
||||||
_currentCursor(RightArrowCursor)
|
_currentCursor(RightArrowCursor),
|
||||||
|
_currentVSync(true)
|
||||||
{
|
{
|
||||||
_traits = traits;
|
_traits = traits;
|
||||||
|
|
||||||
@@ -108,7 +109,10 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer:
|
|||||||
virtual void setWindowName (const std::string & name);
|
virtual void setWindowName (const std::string & name);
|
||||||
virtual void useCursor(bool cursorOn);
|
virtual void useCursor(bool cursorOn);
|
||||||
virtual void setCursor(MouseCursor mouseCursor);
|
virtual void setCursor(MouseCursor mouseCursor);
|
||||||
|
|
||||||
|
/** Set sync-to-vblank. */
|
||||||
|
virtual void setSyncToVBlank(bool on);
|
||||||
|
|
||||||
WindowRef getNativeWindowRef() { return _window; }
|
WindowRef getNativeWindowRef() { return _window; }
|
||||||
|
|
||||||
bool handleMouseEvent(EventRef theEvent);
|
bool handleMouseEvent(EventRef theEvent);
|
||||||
@@ -168,6 +172,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer:
|
|||||||
bool _closeRequested;
|
bool _closeRequested;
|
||||||
UInt32 _lastModifierKeys;
|
UInt32 _lastModifierKeys;
|
||||||
MouseCursor _currentCursor;
|
MouseCursor _currentCursor;
|
||||||
|
bool _currentVSync;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, p
|
|||||||
|
|
||||||
/** Set mouse cursor to a specific shape.*/
|
/** Set mouse cursor to a specific shape.*/
|
||||||
virtual void setCursor(MouseCursor cursor);
|
virtual void setCursor(MouseCursor cursor);
|
||||||
|
|
||||||
|
/** Set sync-to-vblank. */
|
||||||
|
virtual void setSyncToVBlank(bool on);
|
||||||
|
|
||||||
/** Handle a native (Win32) windowing event as received from the system */
|
/** Handle a native (Win32) windowing event as received from the system */
|
||||||
virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
|
virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
|
||||||
|
|
||||||
|
|||||||
@@ -345,19 +345,18 @@ void GraphicsWindowCarbon::installEventHandler() {
|
|||||||
|
|
||||||
bool GraphicsWindowCarbon::realizeImplementation()
|
bool GraphicsWindowCarbon::realizeImplementation()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!_initialized) init();
|
if (!_initialized) init();
|
||||||
if (!_initialized) return false;
|
if (!_initialized) return false;
|
||||||
if (!_traits) return false;
|
if (!_traits) return false;
|
||||||
|
|
||||||
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon:: realizeIMplementation" << std::endl;
|
osg::notify(osg::INFO) << "GraphicsWindowCarbon::realizeImplementation" << std::endl;
|
||||||
|
|
||||||
setWindowDecoration(_traits->windowDecoration);
|
setWindowDecoration(_traits->windowDecoration);
|
||||||
useCursor(_traits->useCursor);
|
useCursor(_traits->useCursor);
|
||||||
|
|
||||||
// move the window to the right screen
|
// move the window to the right screen
|
||||||
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
|
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
|
||||||
int screenLeft(0), screenTop(0);
|
int screenLeft = 0, screenTop = 0;
|
||||||
if (wsi)
|
if (wsi)
|
||||||
{
|
{
|
||||||
wsi->getScreenTopLeft((*_traits), screenLeft, screenTop);
|
wsi->getScreenTopLeft((*_traits), screenLeft, screenTop);
|
||||||
@@ -377,10 +376,10 @@ bool GraphicsWindowCarbon::realizeImplementation()
|
|||||||
err = CreateNewWindow(kDocumentWindowClass, attr, &bounds, &_window);
|
err = CreateNewWindow(kDocumentWindowClass, attr, &bounds, &_window);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::realizeImplementation() failed creating a window: " << err << std::endl;
|
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::realizeImplementation: failed to create window: " << err << std::endl;
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::realizeImplementation() - window created with bounds(" << bounds.top << ", " << bounds.left << ", " << bounds.bottom << ", " << bounds.right << ")" << std::endl;
|
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::realizeImplementation: window created with bounds(" << bounds.top << ", " << bounds.left << ", " << bounds.bottom << ", " << bounds.right << ")" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -407,10 +406,8 @@ bool GraphicsWindowCarbon::realizeImplementation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_context = aglCreateContext (_pixelFormat, sharedContextCarbon);
|
_context = aglCreateContext (_pixelFormat, sharedContextCarbon);
|
||||||
|
|
||||||
|
|
||||||
if (!_context) {
|
if (!_context) {
|
||||||
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::realizeImplementation failed creating a context: " << aglGetError() << std::endl;
|
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::realizeImplementation: failed to create context: " << aglGetError() << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,17 +438,18 @@ bool GraphicsWindowCarbon::realizeImplementation()
|
|||||||
#endif
|
#endif
|
||||||
if (cgerr != kCGLNoError )
|
if (cgerr != kCGLNoError )
|
||||||
{
|
{
|
||||||
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon:: Multi-threaded OpenGL Execution not available" << std::endl;
|
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::realizeImplementation: multi-threaded OpenGL Execution not available" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InitCursor();
|
InitCursor();
|
||||||
|
|
||||||
//enable vsync
|
// enable vsync
|
||||||
if (_traits->vsync) {
|
if (_traits->vsync) {
|
||||||
GLint swap = 1;
|
GLint swap = 1;
|
||||||
aglSetInteger (_context, AGL_SWAP_INTERVAL, &swap);
|
aglSetInteger (_context, AGL_SWAP_INTERVAL, &swap);
|
||||||
}
|
}
|
||||||
|
_currentVSync = _traits->vsync;
|
||||||
|
|
||||||
_realized = true;
|
_realized = true;
|
||||||
return _realized;
|
return _realized;
|
||||||
@@ -485,7 +483,7 @@ void GraphicsWindowCarbon::closeImplementation()
|
|||||||
// OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::closeImplementation" << std::endl;
|
// OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::closeImplementation" << std::endl;
|
||||||
_valid = false;
|
_valid = false;
|
||||||
_realized = false;
|
_realized = false;
|
||||||
|
|
||||||
// there's a possibility that the MenubarController is destructed already, so prevent a crash:
|
// there's a possibility that the MenubarController is destructed already, so prevent a crash:
|
||||||
MenubarController* mbc = MenubarController::instance();
|
MenubarController* mbc = MenubarController::instance();
|
||||||
if (mbc) mbc->detachWindow(this);
|
if (mbc) mbc->detachWindow(this);
|
||||||
@@ -495,7 +493,7 @@ void GraphicsWindowCarbon::closeImplementation()
|
|||||||
aglDestroyPixelFormat(_pixelFormat);
|
aglDestroyPixelFormat(_pixelFormat);
|
||||||
_pixelFormat = NULL;
|
_pixelFormat = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_context)
|
if (_context)
|
||||||
{
|
{
|
||||||
aglSetDrawable(_context, NULL);
|
aglSetDrawable(_context, NULL);
|
||||||
@@ -503,7 +501,7 @@ void GraphicsWindowCarbon::closeImplementation()
|
|||||||
aglDestroyContext(_context);
|
aglDestroyContext(_context);
|
||||||
_context = NULL;
|
_context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ownsWindow && _window) DisposeWindow(_window);
|
if (_ownsWindow && _window) DisposeWindow(_window);
|
||||||
_window = NULL;
|
_window = NULL;
|
||||||
}
|
}
|
||||||
@@ -512,6 +510,16 @@ void GraphicsWindowCarbon::closeImplementation()
|
|||||||
|
|
||||||
void GraphicsWindowCarbon::swapBuffersImplementation()
|
void GraphicsWindowCarbon::swapBuffersImplementation()
|
||||||
{
|
{
|
||||||
|
// check for vsync change
|
||||||
|
if (_traits.valid() && _traits->vsync != _currentVSync)
|
||||||
|
{
|
||||||
|
const bool on = _traits->vsync;
|
||||||
|
GLint swap = (on ? 1 : 0);
|
||||||
|
aglSetInteger (_context, AGL_SWAP_INTERVAL, &swap);
|
||||||
|
osg::notify(osg::NOTICE) << "GraphicsWindowCarbon: VSync=" << (on ? "on" : "off") << std::endl;
|
||||||
|
_currentVSync = on;
|
||||||
|
}
|
||||||
|
|
||||||
aglSwapBuffers(_context);
|
aglSwapBuffers(_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +574,7 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
|
|||||||
if (mouseButton==3) mouseButton = 2;
|
if (mouseButton==3) mouseButton = 2;
|
||||||
else if (mouseButton==2) mouseButton = 3;
|
else if (mouseButton==2) mouseButton = 3;
|
||||||
|
|
||||||
// check tablet pointer device and map it to a musebutton
|
// check tablet pointer device and map it to a mouse button
|
||||||
TabletProximityRec theTabletRecord; // The Tablet Proximity Record
|
TabletProximityRec theTabletRecord; // The Tablet Proximity Record
|
||||||
// Extract the Tablet Proximity reccord from the event.
|
// Extract the Tablet Proximity reccord from the event.
|
||||||
if(noErr == GetEventParameter(theEvent, kEventParamTabletProximityRec,
|
if(noErr == GetEventParameter(theEvent, kEventParamTabletProximityRec,
|
||||||
@@ -585,7 +593,7 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
|
|||||||
pointerType = osgGA::GUIEventAdapter::PUCK;
|
pointerType = osgGA::GUIEventAdapter::PUCK;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: //eraser
|
case 3: // eraser
|
||||||
pointerType = osgGA::GUIEventAdapter::ERASER;
|
pointerType = osgGA::GUIEventAdapter::ERASER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -615,8 +623,8 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
|
|||||||
{
|
{
|
||||||
case kEventMouseDown:
|
case kEventMouseDown:
|
||||||
{
|
{
|
||||||
float mx =wheresMyMouse.h;
|
float mx = wheresMyMouse.h;
|
||||||
float my =wheresMyMouse.v;
|
float my = wheresMyMouse.v;
|
||||||
transformMouseXY(mx, my);
|
transformMouseXY(mx, my);
|
||||||
|
|
||||||
lastEmulatedMouseButton = 0;
|
lastEmulatedMouseButton = 0;
|
||||||
@@ -641,8 +649,8 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
|
|||||||
break;
|
break;
|
||||||
case kEventMouseUp:
|
case kEventMouseUp:
|
||||||
{
|
{
|
||||||
float mx =wheresMyMouse.h;
|
float mx = wheresMyMouse.h;
|
||||||
float my =wheresMyMouse.v;
|
float my = wheresMyMouse.v;
|
||||||
transformMouseXY(mx, my);
|
transformMouseXY(mx, my);
|
||||||
if (lastEmulatedMouseButton > 0) {
|
if (lastEmulatedMouseButton > 0) {
|
||||||
getEventQueue()->mouseButtonRelease(mx, my, lastEmulatedMouseButton);
|
getEventQueue()->mouseButtonRelease(mx, my, lastEmulatedMouseButton);
|
||||||
@@ -662,11 +670,10 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
|
|||||||
sizeof(TabletPointRec), NULL, (void *)&theTabletRecord)) {
|
sizeof(TabletPointRec), NULL, (void *)&theTabletRecord)) {
|
||||||
|
|
||||||
getEventQueue()->penPressure(theTabletRecord.pressure / 65535.0f);
|
getEventQueue()->penPressure(theTabletRecord.pressure / 65535.0f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float mx =wheresMyMouse.h;
|
float mx = wheresMyMouse.h;
|
||||||
float my =wheresMyMouse.v;
|
float my = wheresMyMouse.v;
|
||||||
transformMouseXY(mx, my);
|
transformMouseXY(mx, my);
|
||||||
getEventQueue()->mouseMotion(mx, my);
|
getEventQueue()->mouseMotion(mx, my);
|
||||||
}
|
}
|
||||||
@@ -705,23 +712,23 @@ bool GraphicsWindowCarbon::handleMouseEvent(EventRef theEvent)
|
|||||||
case 11:
|
case 11:
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kEventParamMouseWheelSmoothVerticalDelta = 'saxy', // typeSInt32
|
kEventParamMouseWheelSmoothVerticalDelta = 'saxy', // typeSInt32
|
||||||
kEventParamMouseWheelSmoothHorizontalDelta = 'saxx' // typeSInt32
|
kEventParamMouseWheelSmoothHorizontalDelta = 'saxx' // typeSInt32
|
||||||
};
|
};
|
||||||
|
|
||||||
SInt32 scroll_delta_x = 0;
|
SInt32 scroll_delta_x = 0;
|
||||||
SInt32 scroll_delta_y = 0;
|
SInt32 scroll_delta_y = 0;
|
||||||
OSErr err = noErr;
|
OSErr err = noErr;
|
||||||
err = GetEventParameter( theEvent, kEventParamMouseWheelSmoothVerticalDelta, typeLongInteger, NULL, sizeof(scroll_delta_y), NULL, &scroll_delta_y );
|
err = GetEventParameter( theEvent, kEventParamMouseWheelSmoothVerticalDelta, typeLongInteger, NULL, sizeof(scroll_delta_y), NULL, &scroll_delta_y );
|
||||||
err = GetEventParameter( theEvent, kEventParamMouseWheelSmoothHorizontalDelta, typeLongInteger, NULL, sizeof(scroll_delta_x), NULL, &scroll_delta_x );
|
err = GetEventParameter( theEvent, kEventParamMouseWheelSmoothHorizontalDelta, typeLongInteger, NULL, sizeof(scroll_delta_x), NULL, &scroll_delta_x );
|
||||||
|
|
||||||
if ((scroll_delta_x != 0) || (scroll_delta_y != 0)) {
|
if ((scroll_delta_x != 0) || (scroll_delta_y != 0)) {
|
||||||
getEventQueue()->mouseScroll2D( scroll_delta_x, scroll_delta_y);
|
getEventQueue()->mouseScroll2D( scroll_delta_x, scroll_delta_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -759,15 +766,16 @@ bool GraphicsWindowCarbon::handleKeyboardEvent(EventRef theEvent)
|
|||||||
case kEventRawKeyDown:
|
case kEventRawKeyDown:
|
||||||
case kEventRawKeyRepeat:
|
case kEventRawKeyRepeat:
|
||||||
{
|
{
|
||||||
|
//osg::notify(osg::INFO) << "GraphicsWindowCarbon::keyPress Up" << std::endl;
|
||||||
//getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
|
//getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
|
||||||
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::keyPress" << std::endl;
|
//OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::keyPress" << std::endl;
|
||||||
getEventQueue()->keyPress(keychar);
|
getEventQueue()->keyPress(keychar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kEventRawKeyUp:
|
case kEventRawKeyUp:
|
||||||
{
|
{
|
||||||
OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::keyPress" << std::endl;
|
//OSG_NOTIFY(osg::INFO) << "GraphicsWindowCarbon::keyPress" << std::endl;
|
||||||
//getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
|
//getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
|
||||||
getEventQueue()->keyRelease(keychar);
|
getEventQueue()->keyRelease(keychar);
|
||||||
break;
|
break;
|
||||||
@@ -940,34 +948,24 @@ void GraphicsWindowCarbon::grabFocus()
|
|||||||
void GraphicsWindowCarbon::grabFocusIfPointerInWindow()
|
void GraphicsWindowCarbon::grabFocusIfPointerInWindow()
|
||||||
{
|
{
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
OSG_NOTIFY(osg::ALWAYS) << "GraphicsWindowCarbon::grabFocusIfPointerInWindow" << std::endl;
|
OSG_NOTIFY(osg::ALWAYS) << "GraphicsWindowCarbon::grabFocusIfPointerInWindow: not implemented" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicsWindowCarbon::useCursor(bool cursorOn)
|
void GraphicsWindowCarbon::useCursor(bool cursorOn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_traits.valid())
|
if (_traits.valid())
|
||||||
_traits->useCursor = cursorOn;
|
_traits->useCursor = cursorOn;
|
||||||
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
|
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
|
||||||
if (wsi == NULL) {
|
if (wsi == NULL) {
|
||||||
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::useCursor :: could not get OSXCarbonWindowingSystemInterface" << std::endl;
|
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::useCursor: could not get OSXCarbonWindowingSystemInterface" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGDirectDisplayID displayId = wsi->getDisplayID((*_traits));
|
CGDirectDisplayID displayId = wsi->getDisplayID((*_traits));
|
||||||
CGDisplayErr err = kCGErrorSuccess;
|
CGDisplayErr err = (cursorOn ? CGDisplayShowCursor(displayId) : CGDisplayHideCursor(displayId));
|
||||||
switch (cursorOn)
|
|
||||||
{
|
|
||||||
case true:
|
|
||||||
err = CGDisplayShowCursor(displayId);
|
|
||||||
break;
|
|
||||||
case false:
|
|
||||||
err = CGDisplayHideCursor(displayId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (err != kCGErrorSuccess) {
|
if (err != kCGErrorSuccess) {
|
||||||
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::useCursor failed with " << err << std::endl;
|
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::useCursor: failed with " << err << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -975,9 +973,10 @@ void GraphicsWindowCarbon::useCursor(bool cursorOn)
|
|||||||
// FIXME: I used deprecated functions, but don't know if there are any substitutable newer functions...
|
// FIXME: I used deprecated functions, but don't know if there are any substitutable newer functions...
|
||||||
void GraphicsWindowCarbon::setCursor(MouseCursor mouseCursor)
|
void GraphicsWindowCarbon::setCursor(MouseCursor mouseCursor)
|
||||||
{
|
{
|
||||||
UInt32 cursor;
|
|
||||||
if (_currentCursor == mouseCursor)
|
if (_currentCursor == mouseCursor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
UInt32 cursor;
|
||||||
switch (mouseCursor)
|
switch (mouseCursor)
|
||||||
{
|
{
|
||||||
case NoCursor:
|
case NoCursor:
|
||||||
@@ -1009,6 +1008,12 @@ void GraphicsWindowCarbon::setCursor(MouseCursor mouseCursor)
|
|||||||
ShowCursor();
|
ShowCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphicsWindowCarbon::setSyncToVBlank(bool on)
|
||||||
|
{
|
||||||
|
if (_traits.valid()) {
|
||||||
|
_traits->vsync = on;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicsWindowCarbon::setWindowName (const std::string& name)
|
void GraphicsWindowCarbon::setWindowName (const std::string& name)
|
||||||
{
|
{
|
||||||
@@ -1026,7 +1031,7 @@ void GraphicsWindowCarbon::requestWarpPointer(float x,float y)
|
|||||||
|
|
||||||
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
|
DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface());
|
||||||
if (wsi == NULL) {
|
if (wsi == NULL) {
|
||||||
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::useCursor :: could not get OSXCarbonWindowingSystemInterface" << std::endl;
|
OSG_NOTIFY(osg::WARN) << "GraphicsWindowCarbon::useCursor: could not get OSXCarbonWindowingSystemInterface" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1778,46 +1778,53 @@ bool GraphicsWindowWin32::realizeImplementation()
|
|||||||
init();
|
init();
|
||||||
if (!_initialized) return false;
|
if (!_initialized) return false;
|
||||||
}
|
}
|
||||||
{
|
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
|
||||||
{
|
|
||||||
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
|
|
||||||
if (graphicsHandleWin32)
|
|
||||||
{
|
|
||||||
struct RestoreContext
|
|
||||||
{
|
|
||||||
RestoreContext()
|
|
||||||
{
|
|
||||||
_hdc = wglGetCurrentDC();
|
|
||||||
_hglrc = wglGetCurrentContext();
|
|
||||||
}
|
|
||||||
~RestoreContext()
|
|
||||||
{
|
|
||||||
if (_hdc)
|
|
||||||
{
|
|
||||||
wglMakeCurrent(_hdc,_hglrc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
HDC _hdc;
|
|
||||||
HGLRC _hglrc;
|
|
||||||
} restoreContext;
|
|
||||||
|
|
||||||
_realized = true;
|
|
||||||
bool result = makeCurrent();
|
|
||||||
_realized = false;
|
|
||||||
|
|
||||||
if (!result)
|
if (_traits.valid() && (_traits->sharedContext || _traits->vsync))
|
||||||
|
{
|
||||||
|
// make context current so we can test capabilities and set up context sharing
|
||||||
|
struct RestoreContext
|
||||||
|
{
|
||||||
|
RestoreContext()
|
||||||
|
{
|
||||||
|
_hdc = wglGetCurrentDC();
|
||||||
|
_hglrc = wglGetCurrentContext();
|
||||||
|
}
|
||||||
|
~RestoreContext()
|
||||||
|
{
|
||||||
|
if (_hdc)
|
||||||
{
|
{
|
||||||
return false;
|
wglMakeCurrent(_hdc,_hglrc);
|
||||||
}
|
|
||||||
if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext()))
|
|
||||||
{
|
|
||||||
reportErrorForScreen("GraphicsWindowWin32::realizeImplementation() - Unable to share OpenGL context", _traits->screenNum, ::GetLastError());
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
HDC _hdc;
|
||||||
|
HGLRC _hglrc;
|
||||||
|
} restoreContext;
|
||||||
|
|
||||||
|
_realized = true;
|
||||||
|
bool result = makeCurrent();
|
||||||
|
_realized = false;
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set up sharing of contexts if required
|
||||||
|
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
|
||||||
|
if (graphicsHandleWin32)
|
||||||
|
{
|
||||||
|
if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext()))
|
||||||
|
{
|
||||||
|
reportErrorForScreen("GraphicsWindowWin32::realizeImplementation() - Unable to share OpenGL context", _traits->screenNum, ::GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if vysnc should be on then enable it.
|
||||||
|
if (_traits->vsync)
|
||||||
|
{
|
||||||
|
setSyncToVBlank(_traits->vsync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2164,6 +2171,36 @@ HCURSOR GraphicsWindowWin32::getOrCreateCursor(MouseCursor mouseCursor)
|
|||||||
return _mouseCursorMap[mouseCursor];
|
return _mouseCursorMap[mouseCursor];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphicsWindowWin32::setSyncToVBlank( bool on )
|
||||||
|
{
|
||||||
|
if (_traits.valid())
|
||||||
|
{
|
||||||
|
_traits->vsync = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// we ought to properly check if the extension is listed as supported rather than just
|
||||||
|
// if the function pointer resolves through wglGetProcAddress, but in practice everything
|
||||||
|
// supports this extension
|
||||||
|
typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int );
|
||||||
|
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;
|
||||||
|
|
||||||
|
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
|
||||||
|
if( wglSwapIntervalEXT )
|
||||||
|
{
|
||||||
|
int swapInterval = (on ? 1 : 0);
|
||||||
|
wglSwapIntervalEXT(swapInterval);
|
||||||
|
OSG_INFO << "GraphicsWindowWin32::setSyncToVBlank " << (on ? "on" : "off") << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_INFO << "GraphicsWindowWin32::setSyncToVBlank(bool) not supported" << std::endl;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
OSG_INFO << "GraphicsWindowWin32::setSyncToVBlank(bool) not yet implemented."<< std::endl;
|
||||||
|
#endf
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask )
|
void GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask )
|
||||||
{
|
{
|
||||||
modifierMask = 0;
|
modifierMask = 0;
|
||||||
|
|||||||
@@ -1066,6 +1066,14 @@ void GraphicsWindowX11::swapBuffersImplementation()
|
|||||||
eglSwapBuffers( _eglDisplay, _eglSurface );
|
eglSwapBuffers( _eglDisplay, _eglSurface );
|
||||||
checkEGLError("after eglSwapBuffers()");
|
checkEGLError("after eglSwapBuffers()");
|
||||||
#else
|
#else
|
||||||
|
#if 0
|
||||||
|
if (_traits.valid() && _traits->vsync) {
|
||||||
|
|
||||||
|
unsigned int counter;
|
||||||
|
glXGetVideoSyncSGI(&counter);
|
||||||
|
glXWaitVideoSyncSGI(1, 0, &counter);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
glXSwapBuffers( _display, _window );
|
glXSwapBuffers( _display, _window );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -211,13 +211,11 @@ Viewer::~Viewer()
|
|||||||
{
|
{
|
||||||
//OSG_NOTIFY(osg::NOTICE)<<"Viewer::~Viewer()"<<std::endl;
|
//OSG_NOTIFY(osg::NOTICE)<<"Viewer::~Viewer()"<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
Threads threads;
|
Threads threads;
|
||||||
getAllThreads(threads);
|
getAllThreads(threads);
|
||||||
|
|
||||||
OSG_NOTIFY(osg::INFO)<<"Viewer::~Viewer():: start destructor getThreads = "<<threads.size()<<std::endl;
|
OSG_NOTIFY(osg::INFO)<<"Viewer::~Viewer():: start destructor getThreads = "<<threads.size()<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
stopThreading();
|
stopThreading();
|
||||||
|
|
||||||
if (_scene.valid() && _scene->getDatabasePager())
|
if (_scene.valid() && _scene->getDatabasePager())
|
||||||
@@ -241,8 +239,7 @@ Viewer::~Viewer()
|
|||||||
|
|
||||||
getAllThreads(threads);
|
getAllThreads(threads);
|
||||||
|
|
||||||
OSG_NOTIFY(osg::INFO)<<"Viewer::~Viewer() end destrcutor getThreads = "<<threads.size()<<std::endl;
|
OSG_NOTIFY(osg::INFO)<<"Viewer::~Viewer() end destructor getThreads = "<<threads.size()<<std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::take(View& rhs)
|
void Viewer::take(View& rhs)
|
||||||
|
|||||||
Reference in New Issue
Block a user