Show
Ignore:
Timestamp:
03/02/09 15:53:04 (5 years ago)
Author:
shuber
Message:

* fixed several issues with GraphicsWindowCocoa?, correct window-placement + resizing,
* first cut of PixelBufferCocoa?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/PixelBufferCocoa.mm

    r9831 r9836  
    1010#include <iostream> 
    1111#include <osgViewer/api/Cocoa/PixelBufferCocoa> 
    12  
     12#include <osgViewer/api/Cocoa/GraphicsWindowCocoa> 
     13#include <Cocoa/Cocoa.h> 
    1314 
    1415namespace osgViewer { 
     
    1718void PixelBufferCocoa::init() 
    1819{ 
    19         std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl; 
     20        //std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl; 
    2021         
    21         _valid = _initialized = _realized = true;     
     22        _valid = _initialized = true;     
    2223         
    2324 
     
    2728{ 
    2829        std::cout << "PixelBufferCocoa :: realizeImplementation not implemented yet " << std::endl; 
    29         return true; 
     30         
     31    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 
     32          
     33        NSOpenGLPixelFormatAttribute attr[32]; 
     34    int i = 0; 
     35     
     36    attr[i++] = NSOpenGLPFADepthSize; 
     37    attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->depth); 
     38 
     39    if (_traits->doubleBuffer) { 
     40        attr[i++] = NSOpenGLPFADoubleBuffer; 
     41    } 
     42     
     43    if (_traits->alpha) {  
     44        attr[i++] = NSOpenGLPFAAlphaSize; 
     45        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->alpha); 
     46    } 
     47 
     48    if (_traits->stencil) { 
     49        attr[i++] = NSOpenGLPFAStencilSize; 
     50        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->stencil); 
     51    } 
     52   
     53 
     54    if (_traits->sampleBuffers) { 
     55        attr[i++] = NSOpenGLPFASampleBuffers; 
     56        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->sampleBuffers); 
     57        attr[i++] = NSOpenGLPFASamples; 
     58        attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->samples); 
     59    } 
     60 
     61    attr[i++] = NSOpenGLPFAPixelBuffer; // for pbuffer usage 
     62    attr[i++] = NSOpenGLPFAAccelerated; 
     63    attr[i] = static_cast<NSOpenGLPixelFormatAttribute>(0); 
     64     
     65    // create the context 
     66    NSOpenGLContext* sharedContext = NULL; 
     67     
     68    GraphicsWindowCocoa* graphicsWindowCocoa = dynamic_cast<GraphicsWindowCocoa*>(_traits->sharedContext); 
     69    if (graphicsWindowCocoa)  
     70    { 
     71        sharedContext = graphicsWindowCocoa->getContext(); 
     72    } 
     73    else 
     74    { 
     75        PixelBufferCocoa* pixelbuffer = dynamic_cast<PixelBufferCocoa*>(_traits->sharedContext); 
     76        if (pixelbuffer) { 
     77            sharedContext = pixelbuffer->getContext(); 
     78        } 
     79    } 
     80         
     81        NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ]; 
     82    _context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext]; 
     83    NSOpenGLPixelBuffer* pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget: _traits->target textureInternalFormat: _traits->format textureMaxMipMapLevel: _traits->level pixelsWide: _traits->width pixelsHigh: _traits->height]; 
     84     
     85    [_context setPixelBuffer: pbuffer cubeMapFace: _traits->face mipMapLevel:_traits->level currentVirtualScreen: nil]; 
     86     
     87    [pool release]; 
     88     
     89    _realized = (_context != nil); 
     90    return _realized; 
    3091} 
     92 
    3193 
    3294void PixelBufferCocoa::closeImplementation() 
    3395{ 
    34         std::cout << "PixelBufferCocoa :: closeImplementation not implemented yet " << std::endl; 
     96        _realized = false; 
     97     
     98     
    3599} 
     100 
    36101 
    37102 
     
    39104bool PixelBufferCocoa::makeCurrentImplementation() 
    40105{ 
    41         std::cout << "PixelBufferCocoa :: makeCurrentImplementation not implemented yet " << std::endl; 
     106        // osg::notify(osg::INFO) << "PixelBufferCocoa::makeCurrentImplementation" << std::endl; 
     107     
     108    [_context makeCurrentContext]; 
    42109        return true; 
    43110} 
     
    47114bool PixelBufferCocoa::makeContextCurrentImplementation(osg::GraphicsContext* readContext) 
    48115{ 
    49         std::cout << "PixelBufferCocoa :: makeContextCurrentImplementation not implemented yet " << std::endl; 
    50         return true; 
     116        return makeCurrentImplementation(); 
    51117} 
    52118 
     
    54120bool PixelBufferCocoa::releaseContextImplementation() 
    55121{ 
    56         std::cout << "PixelBufferCocoa :: releaseContextImplementation not implemented yet " << std::endl; 
    57         return true; 
     122        // osg::notify(osg::INFO) << "PixelBufferCocoa::releaseContextImplementation" << std::endl; 
     123     
     124    [NSOpenGLContext clearCurrentContext]; 
     125    return true; 
    58126} 
    59127 
     
    67135void PixelBufferCocoa::swapBuffersImplementation() 
    68136{ 
    69         std::cout << "PixelBufferCocoa :: swapBuffersImplementation not implemented yet " << std::endl; 
     137        osg::notify(osg::INFO) << "PixelBufferCocoa::swapBuffersImplementation" << std::endl; 
     138    [_context flushBuffer]; 
    70139} 
    71140 
    72141 PixelBufferCocoa::~PixelBufferCocoa() 
    73142 {       
     143    [_context release]; 
    74144 } 
    75145