2009-03-10 18:13:20 +08:00
|
|
|
/* -*-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>
|
2009-12-11 01:52:40 +08:00
|
|
|
#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
namespace osgViewer
|
|
|
|
{
|
|
|
|
|
2009-12-11 01:52:40 +08:00
|
|
|
class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public osgViewer::GraphicsHandleCocoa
|
2009-03-10 18:13:20 +08:00
|
|
|
{
|
|
|
|
public:
|
2009-12-07 20:35:33 +08:00
|
|
|
struct Implementation;
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
PixelBufferCocoa(osg::GraphicsContext::Traits* traits):
|
2009-12-11 01:52:40 +08:00
|
|
|
osg::GraphicsContext(),
|
|
|
|
osgViewer::GraphicsHandleCocoa(),
|
2009-12-07 20:35:33 +08:00
|
|
|
_valid(false),
|
|
|
|
_initialized(false),
|
2009-03-10 18:13:20 +08:00
|
|
|
_realized(false),
|
|
|
|
_context(NULL)
|
2009-12-07 20:35:33 +08:00
|
|
|
{
|
2009-03-10 18:13:20 +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
|
|
|
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
~PixelBufferCocoa();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
bool _valid;
|
|
|
|
bool _initialized;
|
|
|
|
bool _realized;
|
2009-12-07 20:35:33 +08:00
|
|
|
NSOpenGLContext* _context;
|
2009-03-10 18:13:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|