Changeset 7039

Show
Ignore:
Timestamp:
06/27/07 22:44:12 (7 years ago)
Author:
robert
Message:

From Stephan Huber, "attached you'll find a first implementation of pbuffer-support for os x.

I used osgprerender --pbuffer to test the carbon-implementation, for now
it works :)
"

Location:
OpenSceneGraph/trunk
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgViewer/CMakeLists.txt

    r7025 r7039  
    4949 
    5050        # FIXME: OS X needs selection mechanism for Cocoa, Carbon, X11 
    51         SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS} ${HEADER_PATH}/api/Carbon/GraphicsWindowCarbon) 
    52         SET(LIB_COMMON_FILES ${LIB_COMMON_FILES} GraphicsWindowCarbon.cpp) 
     51        SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS}  
     52            ${HEADER_PATH}/api/Carbon/GraphicsWindowCarbon 
     53            ${HEADER_PATH}/api/Carbon/PixelBufferCarbon 
     54        ) 
     55        SET(LIB_COMMON_FILES ${LIB_COMMON_FILES}  
     56            GraphicsWindowCarbon.cpp 
     57            PixelBufferCarbon.cpp 
     58        ) 
    5359 
    5460    ELSE(APPLE) 
  • OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCarbon.cpp

    r6944 r7039  
    1414#ifdef __APPLE__ 
    1515#include <osg/observer_ptr> 
     16#include <osgViewer/api/Carbon/PixelBufferCarbon> 
    1617#include <osgViewer/api/Carbon/GraphicsWindowCarbon> 
    1718#include <Carbon/Carbon.h> 
     
    195196} 
    196197 
    197 /** creates a pixelformat from a Trait */         
    198 static AGLPixelFormat createPixelFormat(osg::GraphicsContext::Traits* traits) { 
    199  
    200     std::vector<GLint> attributes; 
    201      
    202     if (!traits->pbuffer) attributes.push_back(AGL_NO_RECOVERY); 
    203     attributes.push_back(AGL_RGBA); 
    204     if (!traits->pbuffer) attributes.push_back(AGL_COMPLIANT); 
    205      
    206     if (traits->doubleBuffer) attributes.push_back(AGL_DOUBLEBUFFER); 
    207     if (traits->quadBufferStereo) attributes.push_back(AGL_STEREO); 
    208      
    209     attributes.push_back(AGL_RED_SIZE); attributes.push_back(traits->red); 
    210     attributes.push_back(AGL_GREEN_SIZE); attributes.push_back(traits->green); 
    211     attributes.push_back(AGL_BLUE_SIZE); attributes.push_back(traits->blue); 
    212     attributes.push_back(AGL_DEPTH_SIZE); attributes.push_back(traits->depth); 
    213      
    214     if (traits->alpha) { attributes.push_back(AGL_ALPHA_SIZE); attributes.push_back(traits->alpha); } 
    215      
    216     if (traits->stencil) { attributes.push_back(AGL_STENCIL_SIZE); attributes.push_back(traits->stencil); } 
    217      
    218     // TODO  
    219     // missing accumulation-buffer-stuff 
    220  
    221 #if defined(AGL_SAMPLE_BUFFERS_ARB) && defined (AGL_SAMPLES_ARB) 
    222  
    223     if (traits->sampleBuffers) { attributes.push_back(AGL_SAMPLE_BUFFERS_ARB); attributes.push_back(traits->sampleBuffers); } 
    224     if (traits->sampleBuffers) { attributes.push_back(AGL_SAMPLES_ARB); attributes.push_back(traits->samples); } 
    225  
    226 #endif 
    227     attributes.push_back(AGL_NONE); 
    228      
    229     return aglChoosePixelFormat(NULL, 0, &(attributes.front())); 
    230 } 
    231  
    232  
    233 #pragma mark * * * GraphicsContextCarbon * * *  
    234  
    235 /** This is the class we need to create for pbuffers, note its not a GraphicsWindow as it won't need any of the event handling and window mapping facilities.*/ 
    236 class GraphicsContextCarbon : public osg::GraphicsContext 
    237 { 
    238     public: 
    239  
    240         GraphicsContextCarbon(osg::GraphicsContext::Traits* traits): 
    241             _valid(false), 
    242             _realized(false), 
    243             _context(NULL) 
    244         { 
    245             _traits = traits; 
    246              
    247             _valid = true; 
    248         } 
    249      
    250         virtual bool valid() const { return _valid; } 
    251  
    252         /** Realise the GraphicsContext implementation,  
    253           * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 
    254         virtual bool realizeImplementation()  
    255         { 
    256             AGLPixelFormat pixelformat = createPixelFormat(_traits.get()); 
    257              
    258             if (!pixelformat) { 
    259                 osg::notify(osg::WARN) << "GraphicsContext::realizeImplementation() aglChoosePixelFormat failed! " << aglErrorString(aglGetError()) << std::endl; 
    260                 return false; 
    261             } 
    262              
    263             _context = aglCreateContext (pixelformat, NULL); 
    264              
    265             if (!_context) { 
    266                 osg::notify(osg::WARN) << "GraphicsContext::realizeImplementation() aglCreateContext failed! " << aglErrorString(aglGetError()) << std::endl; 
    267                 return false; 
    268             } 
    269              
    270             aglDestroyPixelFormat(pixelformat); 
    271              
    272             _realized = aglCreatePBuffer (_traits->width, _traits->height, _traits->target, GL_RGBA, _traits->level, &(_pbuffer)); 
    273             if (!_realized) { 
    274                 osg::notify(osg::WARN) << "GraphicsContext::realizeImplementation() aglCreatePBuffer failed! " << aglErrorString(aglGetError()) << std::endl; 
    275             } 
    276             return _realized; 
    277         } 
    278  
    279         /** Return true if the graphics context has been realised, and is ready to use, implementation. 
    280           * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 
    281         virtual bool isRealizedImplementation() const  { return _realized; } 
    282  
    283         /** Close the graphics context implementation. 
    284           * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 
    285         virtual void closeImplementation()   
    286         {  
    287             if (_pbuffer) aglDestroyPBuffer(_pbuffer); 
    288             if (_context) aglDestroyContext(_context); 
    289             _valid = _realized = false; 
    290         } 
    291  
    292         /** Make this graphics context current implementation. 
    293           * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 
    294         virtual bool makeCurrentImplementation()  
    295         {  
    296             return (_realized) ? (aglSetCurrentContext(_context) == GL_TRUE) : false; 
    297         } 
    298          
    299         /** Make this graphics context current with specified read context implementation. 
    300           * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 
    301         virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/)  { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false;} 
    302  
    303          /** Release the graphics context.*/ 
    304         virtual bool releaseContextImplementation()  
    305         {   
    306              return (aglSetCurrentContext(NULL) == GL_TRUE); 
    307         } 
    308  
    309  
    310         /** Pure virtual, Bind the graphics context to associated texture implementation. 
    311           * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 
    312         virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/)  { osg::notify(osg::NOTICE)<<"GraphicsWindow::void bindPBufferToTextureImplementation(..) not implemented."<<std::endl; } 
    313  
    314         /** Swap the front and back buffers implementation. 
    315           * Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */ 
    316         virtual void swapBuffersImplementation()   
    317         {  
    318              aglSwapBuffers(_context); 
    319         } 
    320          
    321     protected: 
    322          
    323         bool        _valid; 
    324         bool        _realized; 
    325         AGLContext    _context; 
    326         AGLPbuffer    _pbuffer; 
    327  
    328 }; 
     198 
     199 
    329200 
    330201#pragma mark * * * MenubarController * * *  
     
    576447        if (traits->pbuffer) 
    577448        { 
    578             osg::ref_ptr<osgViewer::GraphicsContextCarbon> pbuffer = new GraphicsContextCarbon(traits); 
     449            osg::ref_ptr<osgViewer::PixelBufferCarbon> pbuffer = new PixelBufferCarbon(traits); 
    579450            if (pbuffer->valid()) return pbuffer.release(); 
    580451            else return 0; 
     
    610481    _context = NULL; 
    611482    _window = NULL; 
    612     _pixelFormat = createPixelFormat(_traits.get()); 
     483    _pixelFormat = PixelBufferCarbon::createPixelFormat(_traits.get()); 
    613484    if (!_pixelFormat) 
    614485        osg::notify(osg::WARN) << "GraphicsWindowCarbon::init could not create a valid pixelformat" << std::endl; 
     
    764635     
    765636    // create the context 
    766     GraphicsWindowCarbon* sharedContextCarbon = dynamic_cast<GraphicsWindowCarbon*>(_traits->sharedContext); 
    767     if (sharedContextCarbon)  
    768     { 
    769         _context = aglCreateContext (_pixelFormat, sharedContextCarbon->getAGLContext()); 
     637    AGLContext sharedContextCarbon = NULL; 
     638     
     639    GraphicsWindowCarbon* graphicsWindowCarbon = dynamic_cast<GraphicsWindowCarbon*>(_traits->sharedContext); 
     640    if (graphicsWindowCarbon)  
     641    { 
     642        sharedContextCarbon = graphicsWindowCarbon->getAGLContext(); 
    770643    } 
    771644    else 
    772645    { 
    773         _context = aglCreateContext (_pixelFormat, NULL); 
    774     } 
     646        PixelBufferCarbon* pixelbuffer = dynamic_cast<PixelBufferCarbon*>(_traits->sharedContext); 
     647        if (pixelbuffer) { 
     648            sharedContextCarbon = pixelbuffer->getAGLContext(); 
     649        } 
     650    } 
     651    _context = aglCreateContext (_pixelFormat, sharedContextCarbon); 
    775652 
    776653