OpenSceneGraph/include/osgViewer/api/Cocoa/PixelBufferCocoa

116 lines
3.5 KiB
Plaintext
Raw Normal View History

/* -*-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:
2009-12-07 20:35:33 +08:00
struct Implementation;
PixelBufferCocoa(osg::GraphicsContext::Traits* traits):
osg::GraphicsContext(),
osgViewer::GraphicsHandleCocoa(),
2009-12-07 20:35:33 +08:00
_valid(false),
_initialized(false),
_realized(false),
_context(NULL)
2009-12-07 20:35:33 +08:00
{
_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:
2009-12-07 20:35:33 +08:00
~PixelBufferCocoa();
void init();
bool _valid;
bool _initialized;
bool _realized;
2009-12-07 20:35:33 +08:00
NSOpenGLContext* _context;
};
}
#endif
#endif