2.8 branch: Support for OS X 10.6. Several changes to GraphicsWIndowCocoa and DarwinUtils. The following trunk revisions were merged in this commit: 9879, 9895, 10208, 10340, 10417, 10456, 10622, 10858, and 10887.
This commit is contained in:
53
include/osgViewer/api/Cocoa/GraphicsHandleCocoa
Normal file
53
include/osgViewer/api/Cocoa/GraphicsHandleCocoa
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_GRAPHICSHANDLECOCOA
|
||||
#define OSGVIEWER_GRAPHICSHANDLECOCOA 1
|
||||
|
||||
#include <osgViewer/Export>
|
||||
|
||||
|
||||
#ifdef __OBJC__
|
||||
@class NSOpenGLContext;
|
||||
#else
|
||||
class NSOpenGLContext;
|
||||
#endif
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
|
||||
/** Class to encapsulate platform-specific OpenGL context handle variables.
|
||||
* Derived osg::GraphicsContext classes can inherit from this class to
|
||||
* share OpenGL resources.*/
|
||||
|
||||
class OSGVIEWER_EXPORT GraphicsHandleCocoa
|
||||
{
|
||||
public:
|
||||
|
||||
GraphicsHandleCocoa():
|
||||
_context(0) {}
|
||||
|
||||
/** Set native AGL graphics context.*/
|
||||
inline void setNSOpenGLContext(NSOpenGLContext* context) { _context = context; }
|
||||
|
||||
/** Get native AGL graphics context.*/
|
||||
inline NSOpenGLContext* getNSOpenGLContext() const { return _context; }
|
||||
|
||||
protected:
|
||||
|
||||
NSOpenGLContext* _context;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
199
include/osgViewer/api/Cocoa/GraphicsWindowCocoa
Executable file
199
include/osgViewer/api/Cocoa/GraphicsWindowCocoa
Executable file
@@ -0,0 +1,199 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
|
||||
* a guide to use of X11/GLX and copiying directly in the case of setBorder().
|
||||
* These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
|
||||
*/
|
||||
|
||||
#ifndef OSGVIEWER_GRAPHICSWINDOWCOCOA
|
||||
#define OSGVIEWER_GRAPHICSWINDOWCOCOA 1
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#ifdef __OBJC__
|
||||
@class GraphicsWindowCocoaWindow;
|
||||
@class GraphicsWindowCocoaGLView;
|
||||
@class NSOpenGLContext;
|
||||
@class NSWindow;
|
||||
@class NSView;
|
||||
#else
|
||||
class GraphicsWindowCocoaGLView;
|
||||
class GraphicsWindowCocoaWindow;
|
||||
class NSOpenGLContext;
|
||||
class NSWindow;
|
||||
class NSView;
|
||||
#endif
|
||||
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
|
||||
|
||||
// we may not include any cocoa-header here, because this will pollute the name-sapce and tend to compile-errors
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
|
||||
class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCocoa
|
||||
{
|
||||
public:
|
||||
class Implementation;
|
||||
|
||||
GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits):
|
||||
osgViewer::GraphicsWindow(),
|
||||
osgViewer::GraphicsHandleCocoa(),
|
||||
_valid(false),
|
||||
_initialized(false),
|
||||
_realized(false),
|
||||
_closeRequested(false),
|
||||
_checkForEvents(true),
|
||||
_ownsWindow(true),
|
||||
_currentCursor(RightArrowCursor),
|
||||
_window(NULL)
|
||||
{
|
||||
_traits = traits;
|
||||
|
||||
init();
|
||||
|
||||
if (valid())
|
||||
{
|
||||
setState( new osg::State );
|
||||
getState()->setGraphicsContext(this);
|
||||
|
||||
if (_traits.valid() && _traits->sharedContext)
|
||||
{
|
||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||
incrementContextIDUsageCount( getState()->getContextID() );
|
||||
}
|
||||
else
|
||||
{
|
||||
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowCocoa*>(object)!=0; }
|
||||
virtual const char* libraryName() const { return "osgViewer"; }
|
||||
virtual const char* className() const { return "GraphicsWindowCarbon"; }
|
||||
|
||||
virtual bool valid() const { return _valid; }
|
||||
|
||||
/** Realise the GraphicsContext.*/
|
||||
virtual bool realizeImplementation();
|
||||
|
||||
/** Return true if the graphics context has been realised and is ready to use.*/
|
||||
virtual bool isRealizedImplementation() const { return _realized; }
|
||||
|
||||
/** Close the graphics context.*/
|
||||
virtual void closeImplementation();
|
||||
|
||||
/** Make this graphics context current.*/
|
||||
virtual bool makeCurrentImplementation();
|
||||
|
||||
/** Release the graphics context.*/
|
||||
virtual bool releaseContextImplementation();
|
||||
|
||||
/** Swap the front and back buffers.*/
|
||||
virtual void swapBuffersImplementation();
|
||||
|
||||
/** Check to see if any events have been generated.*/
|
||||
virtual void checkEvents();
|
||||
|
||||
/** Set Window decoration.*/
|
||||
virtual bool setWindowDecorationImplementation(bool flag);
|
||||
|
||||
/** Get focus.*/
|
||||
virtual void grabFocus();
|
||||
|
||||
/** Get focus on if the pointer is in this window.*/
|
||||
virtual void grabFocusIfPointerInWindow();
|
||||
|
||||
bool requestClose() { bool b = _closeRequested; _closeRequested = true; return b; }
|
||||
|
||||
virtual void resizedImplementation(int x, int y, int width, int height);
|
||||
|
||||
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
|
||||
|
||||
virtual void setWindowName (const std::string & name);
|
||||
virtual void useCursor(bool cursorOn);
|
||||
virtual void setCursor(MouseCursor mouseCursor);
|
||||
|
||||
/** WindowData is used to pass in the Cocoa window handle attached the GraphicsContext::Traits structure. */
|
||||
class WindowData : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
enum Options { CreateOnlyView = 1, CheckForEvents = 2, PoseAsStandaloneApp = 4};
|
||||
WindowData(unsigned int options)
|
||||
: _createOnlyView(options & CreateOnlyView),
|
||||
_checkForEvents(options & CheckForEvents),
|
||||
_poseAsStandaloneApp(options & PoseAsStandaloneApp),
|
||||
_view(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
inline NSView* getCreatedNSView() { return _view; }
|
||||
bool createOnlyView() const { return _createOnlyView; }
|
||||
bool checkForEvents() const { return _checkForEvents; }
|
||||
bool poseAsStandaloneApp() const { return _poseAsStandaloneApp; }
|
||||
|
||||
protected:
|
||||
inline void setCreatedNSView(NSView* view) { _view = view; }
|
||||
|
||||
private:
|
||||
bool _createOnlyView, _checkForEvents, _poseAsStandaloneApp;
|
||||
NSView* _view;
|
||||
|
||||
friend class GraphicsWindowCocoa;
|
||||
|
||||
};
|
||||
|
||||
NSOpenGLContext* getContext() { return _context; }
|
||||
GraphicsWindowCocoaWindow* getWindow() { return _window; }
|
||||
|
||||
void setVSync(bool f);
|
||||
|
||||
/** adapts a resize / move of the window, coords in global screen space */
|
||||
void adaptResize(int x, int y, int w, int h);
|
||||
|
||||
protected:
|
||||
|
||||
void init();
|
||||
|
||||
void transformMouseXY(float& x, float& y);
|
||||
void setupNSWindow(NSWindow* win);
|
||||
|
||||
|
||||
virtual ~GraphicsWindowCocoa();
|
||||
|
||||
|
||||
bool _valid;
|
||||
bool _initialized;
|
||||
bool _realized;
|
||||
bool _useWindowDecoration;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
bool _closeRequested, _checkForEvents,_ownsWindow;
|
||||
MouseCursor _currentCursor;
|
||||
GraphicsWindowCocoaWindow* _window;
|
||||
GraphicsWindowCocoaGLView* _view;
|
||||
NSOpenGLContext* _context;
|
||||
bool _updateContext;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
115
include/osgViewer/api/Cocoa/PixelBufferCocoa
Executable file
115
include/osgViewer/api/Cocoa/PixelBufferCocoa
Executable file
@@ -0,0 +1,115 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef OSGVIEWER_PIXELBUFFERCOCOA
|
||||
#define OSGVIEWER_PIXELBUFFERCOCOA 1
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <osg/GraphicsContext>
|
||||
#include <osgViewer/Export>
|
||||
#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
|
||||
|
||||
namespace osgViewer
|
||||
{
|
||||
|
||||
class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public osgViewer::GraphicsHandleCocoa
|
||||
{
|
||||
public:
|
||||
struct Implementation;
|
||||
|
||||
PixelBufferCocoa(osg::GraphicsContext::Traits* traits):
|
||||
osg::GraphicsContext(),
|
||||
osgViewer::GraphicsHandleCocoa(),
|
||||
_valid(false),
|
||||
_initialized(false),
|
||||
_realized(false),
|
||||
_context(NULL)
|
||||
{
|
||||
_traits = traits;
|
||||
|
||||
init();
|
||||
|
||||
if (valid())
|
||||
{
|
||||
setState( new osg::State );
|
||||
getState()->setGraphicsContext(this);
|
||||
|
||||
if (_traits.valid() && _traits->sharedContext)
|
||||
{
|
||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||
incrementContextIDUsageCount( getState()->getContextID() );
|
||||
}
|
||||
else
|
||||
{
|
||||
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const PixelBufferCocoa*>(object)!=0; }
|
||||
virtual const char* libraryName() const { return "osgViewer"; }
|
||||
virtual const char* className() const { return "PixelBufferCarbon"; }
|
||||
|
||||
virtual bool valid() const { return _valid; }
|
||||
|
||||
/** Realise the GraphicsContext.*/
|
||||
virtual bool realizeImplementation();
|
||||
|
||||
/** Return true if the graphics context has been realised and is ready to use.*/
|
||||
virtual bool isRealizedImplementation() const { return _realized; }
|
||||
|
||||
/** Close the graphics context.*/
|
||||
virtual void closeImplementation();
|
||||
|
||||
/** Make this graphics context current.*/
|
||||
virtual bool makeCurrentImplementation();
|
||||
|
||||
/** Make this graphics context current with specified read context implementation. */
|
||||
virtual bool makeContextCurrentImplementation(osg::GraphicsContext* readContext);
|
||||
|
||||
/** Release the graphics context.*/
|
||||
virtual bool releaseContextImplementation();
|
||||
|
||||
/** Bind the graphics context to associated texture implementation.*/
|
||||
virtual void bindPBufferToTextureImplementation( GLenum buffer );
|
||||
|
||||
/** Swap the front and back buffers.*/
|
||||
virtual void swapBuffersImplementation();
|
||||
|
||||
NSOpenGLContext* getContext() { return _context; }
|
||||
public:
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
~PixelBufferCocoa();
|
||||
|
||||
void init();
|
||||
|
||||
bool _valid;
|
||||
bool _initialized;
|
||||
bool _realized;
|
||||
NSOpenGLContext* _context;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user