2009-03-10 18:13:20 +08:00
|
|
|
/*
|
|
|
|
* PixelBufferCocoa.cpp
|
|
|
|
* OpenSceneGraph
|
|
|
|
*
|
|
|
|
* Created by Stephan Huber on 27.06.08.
|
|
|
|
* Copyright 2008 Stephan Maximilian Huber, digital mind. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <osgViewer/api/Cocoa/PixelBufferCocoa>
|
|
|
|
#include <osgViewer/api/Cocoa/GraphicsWindowCocoa>
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
namespace osgViewer {
|
|
|
|
|
|
|
|
|
|
|
|
void PixelBufferCocoa::init()
|
|
|
|
{
|
2009-12-11 01:52:40 +08:00
|
|
|
//std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl;
|
|
|
|
|
|
|
|
_valid = _initialized = true;
|
|
|
|
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PixelBufferCocoa::realizeImplementation()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
2009-12-11 01:52:40 +08:00
|
|
|
|
|
|
|
NSOpenGLPixelFormatAttribute attr[32];
|
2009-03-10 18:13:20 +08:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
attr[i++] = NSOpenGLPFADepthSize;
|
|
|
|
attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->depth);
|
|
|
|
|
|
|
|
if (_traits->doubleBuffer) {
|
|
|
|
attr[i++] = NSOpenGLPFADoubleBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_traits->alpha) {
|
|
|
|
attr[i++] = NSOpenGLPFAAlphaSize;
|
|
|
|
attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_traits->stencil) {
|
|
|
|
attr[i++] = NSOpenGLPFAStencilSize;
|
|
|
|
attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->stencil);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_traits->sampleBuffers) {
|
|
|
|
attr[i++] = NSOpenGLPFASampleBuffers;
|
|
|
|
attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->sampleBuffers);
|
|
|
|
attr[i++] = NSOpenGLPFASamples;
|
|
|
|
attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
attr[i++] = NSOpenGLPFAPixelBuffer; // for pbuffer usage
|
|
|
|
attr[i++] = NSOpenGLPFAAccelerated;
|
|
|
|
attr[i] = static_cast<NSOpenGLPixelFormatAttribute>(0);
|
|
|
|
|
|
|
|
// create the context
|
|
|
|
NSOpenGLContext* sharedContext = NULL;
|
|
|
|
|
2012-09-06 05:03:41 +08:00
|
|
|
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
|
2009-12-11 01:52:40 +08:00
|
|
|
if (graphicsHandleCocoa)
|
2009-03-10 18:13:20 +08:00
|
|
|
{
|
2009-12-11 01:52:40 +08:00
|
|
|
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
|
2009-03-10 18:13:20 +08:00
|
|
|
}
|
2009-12-11 01:52:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ];
|
2009-03-10 18:13:20 +08:00
|
|
|
_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];
|
|
|
|
|
|
|
|
[_context setPixelBuffer: pbuffer cubeMapFace: _traits->face mipMapLevel:_traits->level currentVirtualScreen: nil];
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
_realized = (_context != nil);
|
|
|
|
return _realized;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PixelBufferCocoa::closeImplementation()
|
|
|
|
{
|
2009-12-11 01:52:40 +08:00
|
|
|
_realized = false;
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Make this graphics context current.*/
|
|
|
|
bool PixelBufferCocoa::makeCurrentImplementation()
|
|
|
|
{
|
2010-05-28 23:56:43 +08:00
|
|
|
// OSG_INFO << "PixelBufferCocoa::makeCurrentImplementation" << std::endl;
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
[_context makeCurrentContext];
|
2009-12-11 01:52:40 +08:00
|
|
|
return true;
|
2009-03-10 18:13:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Make this graphics context current with specified read context implementation. */
|
|
|
|
bool PixelBufferCocoa::makeContextCurrentImplementation(osg::GraphicsContext* readContext)
|
|
|
|
{
|
2009-12-11 01:52:40 +08:00
|
|
|
return makeCurrentImplementation();
|
2009-03-10 18:13:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Release the graphics context.*/
|
|
|
|
bool PixelBufferCocoa::releaseContextImplementation()
|
|
|
|
{
|
2010-05-28 23:56:43 +08:00
|
|
|
// OSG_INFO << "PixelBufferCocoa::releaseContextImplementation" << std::endl;
|
2009-03-10 18:13:20 +08:00
|
|
|
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Bind the graphics context to associated texture implementation.*/
|
|
|
|
void PixelBufferCocoa::bindPBufferToTextureImplementation( GLenum buffer )
|
|
|
|
{
|
2009-12-11 01:52:40 +08:00
|
|
|
std::cout << "PixelBufferCocoa :: bindPBufferToTextureImplementation not implemented yet " << std::endl;
|
2009-03-10 18:13:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Swap the front and back buffers.*/
|
|
|
|
void PixelBufferCocoa::swapBuffersImplementation()
|
|
|
|
{
|
2010-05-28 23:56:43 +08:00
|
|
|
OSG_INFO << "PixelBufferCocoa::swapBuffersImplementation" << std::endl;
|
2009-03-10 18:13:20 +08:00
|
|
|
[_context flushBuffer];
|
|
|
|
}
|
|
|
|
|
|
|
|
PixelBufferCocoa::~PixelBufferCocoa()
|
2009-12-11 01:52:40 +08:00
|
|
|
{
|
2009-03-10 18:13:20 +08:00
|
|
|
[_context release];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|