OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelBufferCocoa.h
Go to the documentation of this file.
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 #include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
24 
25 namespace osgViewer
26 {
27 
28 class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public osgViewer::GraphicsHandleCocoa
29 {
30  public:
31  struct Implementation;
32 
33  PixelBufferCocoa(osg::GraphicsContext::Traits* traits):
34  osg::GraphicsContext(),
35  osgViewer::GraphicsHandleCocoa(),
36  _valid(false),
37  _initialized(false),
38  _realized(false),
39  _context(NULL)
40  {
41  _traits = traits;
42 
43  init();
44 
45  if (valid())
46  {
47  setState( new osg::State );
48  getState()->setGraphicsContext(this);
49 
50  if (_traits.valid() && _traits->sharedContext.valid())
51  {
52  getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
53  incrementContextIDUsageCount( getState()->getContextID() );
54  }
55  else
56  {
57  getState()->setContextID( osg::GraphicsContext::createNewContextID() );
58  }
59 
60  }
61  }
62 
63  virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const PixelBufferCocoa*>(object)!=0; }
64  virtual const char* libraryName() const { return "osgViewer"; }
65  virtual const char* className() const { return "PixelBufferCarbon"; }
66 
67  virtual bool valid() const { return _valid; }
68 
70  virtual bool realizeImplementation();
71 
73  virtual bool isRealizedImplementation() const { return _realized; }
74 
76  virtual void closeImplementation();
77 
79  virtual bool makeCurrentImplementation();
80 
82  virtual bool makeContextCurrentImplementation(osg::GraphicsContext* readContext);
83 
85  virtual bool releaseContextImplementation();
86 
88  virtual void bindPBufferToTextureImplementation( GLenum buffer );
89 
91  virtual void swapBuffersImplementation();
92 
93  NSOpenGLContext* getContext() { return _context; }
94  public:
95 
96 
97  protected:
98 
99 
100 
101  ~PixelBufferCocoa();
102 
103  void init();
104 
105  bool _valid;
106  bool _initialized;
107  bool _realized;
108  NSOpenGLContext* _context;
109 };
110 
111 }
112 
113 #endif
114 
115 #endif
#define NULL
Definition: Export.h:59
#define OSGVIEWER_EXPORT
Definition: Export.h:40
static unsigned int createNewContextID()
Definition: AlphaFunc.h:19