From Stephan Huber, "attached you'll find the missing GraphicsHandleCocoa-implementation."

This commit is contained in:
Robert Osfield
2009-12-10 17:52:40 +00:00
parent fa189316bb
commit b7b86ba5f4
6 changed files with 88 additions and 49 deletions

View File

@@ -0,0 +1,53 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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_GRAPHICSHANDLECOCOA
#define OSGVIEWER_GRAPHICSHANDLECOCOA 1
#include <osgViewer/Export>
#ifdef __OBJC__
@class NSOpenGLContext;
#else
class NSOpenGLContext;
#endif
namespace osgViewer
{
/** Class to encapsulate platform-specific OpenGL context handle variables.
* Derived osg::GraphicsContext classes can inherit from this class to
* share OpenGL resources.*/
class OSGVIEWER_EXPORT GraphicsHandleCocoa
{
public:
GraphicsHandleCocoa():
_context(0) {}
/** Set native AGL graphics context.*/
inline void setNSOpenGLContext(NSOpenGLContext* context) { _context = context; }
/** Get native AGL graphics context.*/
inline NSOpenGLContext* getNSOpenGLContext() const { return _context; }
protected:
NSOpenGLContext* _context;
};
}
#endif

View File

@@ -36,18 +36,21 @@ class NSView;
#endif
#include <osgViewer/GraphicsWindow>
#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
// we may not include any cocoa-header here, because this will pollute the name-sapce and tend to compile-errors
namespace osgViewer
{
class GraphicsWindowCocoa : public osgViewer::GraphicsWindow
class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCocoa
{
public:
class Implementation;
GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits):
osgViewer::GraphicsWindow(),
osgViewer::GraphicsHandleCocoa(),
_valid(false),
_initialized(false),
_realized(false),
@@ -55,8 +58,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow
_checkForEvents(true),
_ownsWindow(true),
_currentCursor(RightArrowCursor),
_window(NULL),
_context(NULL)
_window(NULL)
{
_traits = traits;

View File

@@ -20,23 +20,19 @@
#include <osg/GraphicsContext>
#include <osgViewer/Export>
#ifdef __OBJC__
@class NSOpenGLContext;
#else
class NSOpenGLContext;
#endif
#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
namespace osgViewer
{
class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext
class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public osgViewer::GraphicsHandleCocoa
{
public:
struct Implementation;
PixelBufferCocoa(osg::GraphicsContext::Traits* traits):
osg::GraphicsContext(),
osgViewer::GraphicsHandleCocoa(),
_valid(false),
_initialized(false),
_realized(false),

View File

@@ -72,6 +72,7 @@ ELSE()
IF(${OSG_WINDOWING_SYSTEM} STREQUAL "Cocoa")
ADD_DEFINITIONS(-DUSE_DARWIN_COCOA_IMPLEMENTATION)
SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}
${HEADER_PATH}/api/Cocoa/GraphicsHandleCocoa
${HEADER_PATH}/api/Cocoa/GraphicsWindowCocoa
${HEADER_PATH}/api/Cocoa/PixelBufferCocoa
)

View File

@@ -971,17 +971,10 @@ bool GraphicsWindowCocoa::realizeImplementation()
// create the context
NSOpenGLContext* sharedContext = NULL;
GraphicsWindowCocoa* graphicsWindowCocoa = dynamic_cast<GraphicsWindowCocoa*>(_traits->sharedContext);
if (graphicsWindowCocoa)
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
if (graphicsHandleCocoa)
{
sharedContext = graphicsWindowCocoa->getContext();
}
else
{
PixelBufferCocoa* pixelbuffer = dynamic_cast<PixelBufferCocoa*>(_traits->sharedContext);
if (pixelbuffer) {
sharedContext = pixelbuffer->getContext();
}
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
}
NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];

View File

@@ -17,20 +17,20 @@ namespace osgViewer {
void PixelBufferCocoa::init()
{
//std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl;
_valid = _initialized = true;
//std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl;
_valid = _initialized = true;
}
bool PixelBufferCocoa::realizeImplementation()
{
std::cout << "PixelBufferCocoa :: realizeImplementation not implemented yet " << std::endl;
std::cout << "PixelBufferCocoa :: realizeImplementation not implemented yet " << std::endl;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormatAttribute attr[32];
int i = 0;
attr[i++] = NSOpenGLPFADepthSize;
@@ -65,20 +65,14 @@ bool PixelBufferCocoa::realizeImplementation()
// create the context
NSOpenGLContext* sharedContext = NULL;
GraphicsWindowCocoa* graphicsWindowCocoa = dynamic_cast<GraphicsWindowCocoa*>(_traits->sharedContext);
if (graphicsWindowCocoa)
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
if (graphicsHandleCocoa)
{
sharedContext = graphicsWindowCocoa->getContext();
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
}
else
{
PixelBufferCocoa* pixelbuffer = dynamic_cast<PixelBufferCocoa*>(_traits->sharedContext);
if (pixelbuffer) {
sharedContext = pixelbuffer->getContext();
}
}
NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];
NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];
_context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext];
NSOpenGLPixelBuffer* pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget: _traits->target textureInternalFormat: _traits->format textureMaxMipMapLevel: _traits->level pixelsWide: _traits->width pixelsHigh: _traits->height];
@@ -93,7 +87,7 @@ bool PixelBufferCocoa::realizeImplementation()
void PixelBufferCocoa::closeImplementation()
{
_realized = false;
_realized = false;
}
@@ -103,23 +97,23 @@ void PixelBufferCocoa::closeImplementation()
/** Make this graphics context current.*/
bool PixelBufferCocoa::makeCurrentImplementation()
{
// osg::notify(osg::INFO) << "PixelBufferCocoa::makeCurrentImplementation" << std::endl;
// osg::notify(osg::INFO) << "PixelBufferCocoa::makeCurrentImplementation" << std::endl;
[_context makeCurrentContext];
return true;
return true;
}
/** Make this graphics context current with specified read context implementation. */
bool PixelBufferCocoa::makeContextCurrentImplementation(osg::GraphicsContext* readContext)
{
return makeCurrentImplementation();
return makeCurrentImplementation();
}
/** Release the graphics context.*/
bool PixelBufferCocoa::releaseContextImplementation()
{
// osg::notify(osg::INFO) << "PixelBufferCocoa::releaseContextImplementation" << std::endl;
// osg::notify(osg::INFO) << "PixelBufferCocoa::releaseContextImplementation" << std::endl;
[NSOpenGLContext clearCurrentContext];
return true;
@@ -128,18 +122,18 @@ bool PixelBufferCocoa::releaseContextImplementation()
/** Bind the graphics context to associated texture implementation.*/
void PixelBufferCocoa::bindPBufferToTextureImplementation( GLenum buffer )
{
std::cout << "PixelBufferCocoa :: bindPBufferToTextureImplementation not implemented yet " << std::endl;
std::cout << "PixelBufferCocoa :: bindPBufferToTextureImplementation not implemented yet " << std::endl;
}
/** Swap the front and back buffers.*/
void PixelBufferCocoa::swapBuffersImplementation()
{
osg::notify(osg::INFO) << "PixelBufferCocoa::swapBuffersImplementation" << std::endl;
osg::notify(osg::INFO) << "PixelBufferCocoa::swapBuffersImplementation" << std::endl;
[_context flushBuffer];
}
PixelBufferCocoa::~PixelBufferCocoa()
{
{
[_context release];
}