1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
16#ifndef OSGVIEWER_PIXELBUFFERCOCOA
17#define OSGVIEWER_PIXELBUFFERCOCOA 1
21#include <osg/GraphicsContext>
22#include <osgViewer/Export>
23#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
28class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public osgViewer::GraphicsHandleCocoa
31 struct Implementation;
33 PixelBufferCocoa(osg::GraphicsContext::Traits* traits):
34 osg::GraphicsContext(),
35 osgViewer::GraphicsHandleCocoa(),
47 setState( new osg::State );
48 getState()->setGraphicsContext(this);
50 if (_traits.valid() && _traits->sharedContext.valid())
52 getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
53 incrementContextIDUsageCount( getState()->getContextID() );
57 getState()->setContextID( osg::GraphicsContext::createNewContextID() );
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"; }
67 virtual bool valid() const { return _valid; }
69 /** Realise the GraphicsContext.*/
70 virtual bool realizeImplementation();
72 /** Return true if the graphics context has been realised and is ready to use.*/
73 virtual bool isRealizedImplementation() const { return _realized; }
75 /** Close the graphics context.*/
76 virtual void closeImplementation();
78 /** Make this graphics context current.*/
79 virtual bool makeCurrentImplementation();
81 /** Make this graphics context current with specified read context implementation. */
82 virtual bool makeContextCurrentImplementation(osg::GraphicsContext* readContext);
84 /** Release the graphics context.*/
85 virtual bool releaseContextImplementation();
87 /** Bind the graphics context to associated texture implementation.*/
88 virtual void bindPBufferToTextureImplementation( GLenum buffer );
90 /** Swap the front and back buffers.*/
91 virtual void swapBuffersImplementation();
93 NSOpenGLContext* getContext() { return _context; }
108 NSOpenGLContext* _context;