| [9879] | 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #ifndef OSGVIEWER_PIXELBUFFERCOCOA |
|---|
| 17 | #define OSGVIEWER_PIXELBUFFERCOCOA 1 |
|---|
| 18 | |
|---|
| 19 | #ifdef __APPLE__ |
|---|
| 20 | |
|---|
| 21 | #include <osg/GraphicsContext> |
|---|
| 22 | #include <osgViewer/Export> |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | #ifdef __OBJC__ |
|---|
| 26 | @class NSOpenGLContext; |
|---|
| 27 | #else |
|---|
| 28 | class NSOpenGLContext; |
|---|
| 29 | #endif |
|---|
| 30 | |
|---|
| 31 | namespace osgViewer |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext |
|---|
| 35 | { |
|---|
| 36 | public: |
|---|
| [10858] | 37 | struct Implementation; |
|---|
| [9879] | 38 | |
|---|
| 39 | PixelBufferCocoa(osg::GraphicsContext::Traits* traits): |
|---|
| [10858] | 40 | _valid(false), |
|---|
| 41 | _initialized(false), |
|---|
| [9879] | 42 | _realized(false), |
|---|
| 43 | _context(NULL) |
|---|
| [10858] | 44 | { |
|---|
| [9879] | 45 | _traits = traits; |
|---|
| 46 | |
|---|
| 47 | init(); |
|---|
| 48 | |
|---|
| 49 | if (valid()) |
|---|
| 50 | { |
|---|
| 51 | setState( new osg::State ); |
|---|
| 52 | getState()->setGraphicsContext(this); |
|---|
| 53 | |
|---|
| 54 | if (_traits.valid() && _traits->sharedContext) |
|---|
| 55 | { |
|---|
| 56 | getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); |
|---|
| 57 | incrementContextIDUsageCount( getState()->getContextID() ); |
|---|
| 58 | } |
|---|
| 59 | else |
|---|
| 60 | { |
|---|
| 61 | getState()->setContextID( osg::GraphicsContext::createNewContextID() ); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const PixelBufferCocoa*>(object)!=0; } |
|---|
| 68 | virtual const char* libraryName() const { return "osgViewer"; } |
|---|
| 69 | virtual const char* className() const { return "PixelBufferCarbon"; } |
|---|
| 70 | |
|---|
| 71 | virtual bool valid() const { return _valid; } |
|---|
| 72 | |
|---|
| 73 | /** Realise the GraphicsContext.*/ |
|---|
| 74 | virtual bool realizeImplementation(); |
|---|
| 75 | |
|---|
| 76 | /** Return true if the graphics context has been realised and is ready to use.*/ |
|---|
| 77 | virtual bool isRealizedImplementation() const { return _realized; } |
|---|
| 78 | |
|---|
| 79 | /** Close the graphics context.*/ |
|---|
| 80 | virtual void closeImplementation(); |
|---|
| 81 | |
|---|
| 82 | /** Make this graphics context current.*/ |
|---|
| 83 | virtual bool makeCurrentImplementation(); |
|---|
| 84 | |
|---|
| 85 | /** Make this graphics context current with specified read context implementation. */ |
|---|
| 86 | virtual bool makeContextCurrentImplementation(osg::GraphicsContext* readContext); |
|---|
| 87 | |
|---|
| 88 | /** Release the graphics context.*/ |
|---|
| 89 | virtual bool releaseContextImplementation(); |
|---|
| 90 | |
|---|
| 91 | /** Bind the graphics context to associated texture implementation.*/ |
|---|
| 92 | virtual void bindPBufferToTextureImplementation( GLenum buffer ); |
|---|
| 93 | |
|---|
| 94 | /** Swap the front and back buffers.*/ |
|---|
| 95 | virtual void swapBuffersImplementation(); |
|---|
| 96 | |
|---|
| 97 | NSOpenGLContext* getContext() { return _context; } |
|---|
| 98 | public: |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | protected: |
|---|
| [10858] | 102 | |
|---|
| [9879] | 103 | |
|---|
| 104 | |
|---|
| 105 | ~PixelBufferCocoa(); |
|---|
| 106 | |
|---|
| 107 | void init(); |
|---|
| 108 | |
|---|
| 109 | bool _valid; |
|---|
| 110 | bool _initialized; |
|---|
| 111 | bool _realized; |
|---|
| [10858] | 112 | NSOpenGLContext* _context; |
|---|
| [9879] | 113 | }; |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | #endif |
|---|
| 118 | |
|---|
| 119 | #endif |
|---|