From 8e5c3363ef516a81bb4f917bd4c264da7d1751e2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Feb 2008 15:30:55 +0000 Subject: [PATCH] From Stephan Huber, "Attached you'll find some enhancements by Adrian Egli and me for the carbon-implementation of GraphicsWindow. Now you can use an AGLDrawable in conjunction with osgViewer/osgCompositeViewer." Changes from Robert Osfield, changed std::cout to osg::notify(osg::INFO) --- .../osgViewer/api/Carbon/GraphicsWindowCarbon | 12 +++--- src/osgViewer/GraphicsWindowCarbon.cpp | 42 +++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/osgViewer/api/Carbon/GraphicsWindowCarbon b/include/osgViewer/api/Carbon/GraphicsWindowCarbon index fa5c18aff..6e6ed73e4 100644 --- a/include/osgViewer/api/Carbon/GraphicsWindowCarbon +++ b/include/osgViewer/api/Carbon/GraphicsWindowCarbon @@ -113,16 +113,18 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow class WindowData : public osg::Referenced { public: - WindowData(WindowRef window): - _window(window), _installEventHandler(false) {} + WindowData(WindowRef window, AGLDrawable* drawable=NULL ): //ADEGLI + _window(window), _AGLDrawable(drawable) ,_installEventHandler(false) {} //ADEGLI WindowRef getNativeWindowRef() { return _window; } void setInstallEventHandler(bool flag) { _installEventHandler = flag; } bool installEventHandler() { return _installEventHandler; } - + AGLDrawable* getAGLDrawable() { return _AGLDrawable; } //ADEGLI + private: - WindowRef _window; - bool _installEventHandler; + WindowRef _window; + AGLDrawable* _AGLDrawable; //ADEGLI + bool _installEventHandler; }; diff --git a/src/osgViewer/GraphicsWindowCarbon.cpp b/src/osgViewer/GraphicsWindowCarbon.cpp index 60b27cce9..b72dbfebc 100644 --- a/src/osgViewer/GraphicsWindowCarbon.cpp +++ b/src/osgViewer/GraphicsWindowCarbon.cpp @@ -21,6 +21,8 @@ #include #include + +#include using namespace osgViewer; @@ -32,7 +34,7 @@ static pascal OSStatus GraphicsWindowEventHandler(EventHandlerCallRef nextHandle Rect bounds; OSStatus result = eventNotHandledErr; /* report failure by default */ - + osg::notify(osg::INFO) << "GraphicsWindowEventHandler" << std::endl; GraphicsWindowCarbon* w = (GraphicsWindowCarbon*)userData; if (!w) @@ -89,8 +91,8 @@ static pascal OSStatus GraphicsWindowEventHandler(EventHandlerCallRef nextHandle break; } - if (result == eventNotHandledErr) - result = CallNextEventHandler (nextHandler, event); + //if (result == eventNotHandledErr) + // result = CallNextEventHandler (nextHandler, event); return result; } @@ -590,9 +592,8 @@ void GraphicsWindowCarbon::installEventHandler() { {kEventClassKeyboard, kEventHotKeyReleased}, }; - InstallWindowEventHandler(_window, NewEventHandlerUPP(GraphicsWindowEventHandler), GetEventTypeCount(windEventList), windEventList, this, NULL); -} + } bool GraphicsWindowCarbon::realizeImplementation() @@ -602,6 +603,8 @@ bool GraphicsWindowCarbon::realizeImplementation() if (!_initialized) return false; if (!_traits) return false; + osg::notify(osg::INFO) << "GraphicsWindowCarbon:: realizeIMplementation" << std::endl; + setWindowDecoration(_traits->windowDecoration); useCursor(_traits->useCursor); @@ -615,7 +618,9 @@ bool GraphicsWindowCarbon::realizeImplementation() _traits->x += screenLeft; } - WindowData *windowData = _traits.get() ? dynamic_cast(_traits->inheritedWindowData.get()) : 0; + //ADEGLI WindowData *windowData = _traits.get() ? dynamic_cast(_traits->inheritedWindowData.get()) : 0; + WindowData *windowData = ( _traits.get() && _traits->inheritedWindowData.get() ) ? static_cast(_traits->inheritedWindowData.get()) : 0; //ADEGLI + _ownsWindow = (windowData) ? (windowData->getNativeWindowRef() == NULL) : true; if (_ownsWindow) { @@ -635,7 +640,7 @@ bool GraphicsWindowCarbon::realizeImplementation() } } else { - _window = windowData->getNativeWindowRef(); + _window = windowData->getNativeWindowRef(); } Rect titleRect; @@ -670,7 +675,18 @@ bool GraphicsWindowCarbon::realizeImplementation() osg::notify(osg::WARN) << "GraphicsWindowCarbon::realizeImplementation failed creating a context: " << aglGetError() << std::endl; return false; } - + + + if ( windowData && windowData->getAGLDrawable() ) { + aglSetDrawable(_context, (AGLDrawable)*(windowData->getAGLDrawable()) ); //ADEGLI + // ShowWindow(_window); //ADEGLI + + } else { + aglSetDrawable(_context, GetWindowPort(_window)); //ADEGLI + ShowWindow(_window); //ADEGLI + MenubarController::instance()->attachWindow(this); + } + makeCurrent(); if ((_traits->useMultiThreadedOpenGLEngine) && (OpenThreads::GetNumberOfProcessors() > 1)) { @@ -691,8 +707,8 @@ bool GraphicsWindowCarbon::realizeImplementation() osg::notify(osg::INFO) << "GraphicsWindowCarbon:: Multi-threaded OpenGL Execution not available" << std::endl; } } - aglSetDrawable(_context, GetWindowPort(_window)); - ShowWindow(_window); + //ADEGLI aglSetDrawable(_context, GetWindowPort(_window)); + //ADEGLI ShowWindow(_window); //enable vsync if (_traits->vsync) { @@ -700,8 +716,6 @@ bool GraphicsWindowCarbon::realizeImplementation() aglSetInteger (_context, AGL_SWAP_INTERVAL, &swap); } - MenubarController::instance()->attachWindow(this); - _realized = true; return _realized; } @@ -1002,7 +1016,7 @@ bool GraphicsWindowCarbon::handleKeyboardEvent(EventRef theEvent) UInt32 rawkey; GetEventParameter (theEvent,kEventParamKeyCode,typeUInt32, NULL,sizeof(rawkey), NULL,&rawkey); - // std::cout << "key code: " << rawkey << " modifiers: " << modifierKeys << std::endl; + // osg::notify(osg::INFO) << "key code: " << rawkey << " modifiers: " << modifierKeys << std::endl; UInt32 dataSize; /* jbw check return status so that we don't allocate a huge array */ @@ -1021,12 +1035,14 @@ bool GraphicsWindowCarbon::handleKeyboardEvent(EventRef theEvent) case kEventRawKeyRepeat: { //getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask); + osg::notify(osg::INFO) << "GraphicsWindowCarbon::keyPress" << std::endl; getEventQueue()->keyPress(keychar); break; } case kEventRawKeyUp: { + osg::notify(osg::INFO) << "GraphicsWindowCarbon::keyPress" << std::endl; //getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask); getEventQueue()->keyRelease(keychar); break;