- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/PixelBufferCarbon.cpp
r12292 r13041 7 7 * 8 8 */ 9 9 10 10 #if defined (__APPLE__) && (!__LP64__) 11 11 … … 20 20 21 21 22 /** creates a pixelformat from a Trait */ 22 /** creates a pixelformat from a Trait */ 23 23 AGLPixelFormat PixelBufferCarbon::createPixelFormat(osg::GraphicsContext::Traits* traits) { 24 24 25 25 std::vector<GLint> attributes; 26 26 27 27 attributes.push_back(AGL_NO_RECOVERY); 28 28 attributes.push_back(AGL_RGBA); 29 if (!traits->pbuffer) 29 if (!traits->pbuffer) 30 30 attributes.push_back(AGL_COMPLIANT); 31 31 else 32 32 attributes.push_back(AGL_CLOSEST_POLICY); 33 33 34 34 if (traits->doubleBuffer) attributes.push_back(AGL_DOUBLEBUFFER); 35 35 if (traits->quadBufferStereo) attributes.push_back(AGL_STEREO); 36 36 37 37 attributes.push_back(AGL_RED_SIZE); attributes.push_back(traits->red); 38 38 attributes.push_back(AGL_GREEN_SIZE); attributes.push_back(traits->green); 39 39 attributes.push_back(AGL_BLUE_SIZE); attributes.push_back(traits->blue); 40 40 attributes.push_back(AGL_DEPTH_SIZE); attributes.push_back(traits->depth); 41 41 42 42 if (traits->alpha) { attributes.push_back(AGL_ALPHA_SIZE); attributes.push_back(traits->alpha); } 43 43 44 44 if (traits->stencil) { attributes.push_back(AGL_STENCIL_SIZE); attributes.push_back(traits->stencil); } 45 46 // TODO 45 46 // TODO 47 47 // missing accumulation-buffer-stuff 48 48 … … 54 54 #endif 55 55 attributes.push_back(AGL_NONE); 56 56 57 57 return aglChoosePixelFormat(NULL, 0, &(attributes.front())); 58 58 } … … 70 70 71 71 /** 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.*/ 72 /** Realise the GraphicsContext implementation, 72 /** Realise the GraphicsContext implementation, 73 73 * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 74 bool PixelBufferCarbon::realizeImplementation() 74 bool PixelBufferCarbon::realizeImplementation() 75 75 { 76 76 if (!_valid) { … … 78 78 return false; 79 79 } 80 80 81 81 AGLContext sharedContext = NULL; 82 82 83 // get any shared AGL contexts 83 // get any shared AGL contexts 84 84 GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext); 85 if (graphicsHandleCarbon) 85 if (graphicsHandleCarbon) 86 86 { 87 87 sharedContext = graphicsHandleCarbon->getAGLContext(); 88 88 } 89 89 90 90 _context = aglCreateContext (_pixelformat, sharedContext); 91 91 92 92 if (!_context) { 93 93 OSG_WARN << "PixelBufferCarbon::realizeImplementation() aglCreateContext failed! " << aglErrorString(aglGetError()) << std::endl; 94 94 return false; 95 95 } 96 97 96 98 97 98 99 99 _realized = aglCreatePBuffer (_traits->width, _traits->height, _traits->target, GL_RGBA, _traits->level, &(_pbuffer)); 100 100 if (!_realized) { 101 101 OSG_WARN << "PixelBufferCarbon::realizeImplementation() aglCreatePBuffer failed! " << aglErrorString(aglGetError()) << std::endl; 102 102 } 103 103 104 104 makeCurrentImplementation(); 105 105 106 106 _realized = aglSetPBuffer(_context, _pbuffer, _traits->face, _traits->level, 0); 107 107 if (!_realized) { … … 111 111 } 112 112 113 void PixelBufferCarbon::closeImplementation() 114 { 113 void PixelBufferCarbon::closeImplementation() 114 { 115 115 if (_pbuffer) aglDestroyPBuffer(_pbuffer); 116 116 if (_context) aglDestroyContext(_context); 117 117 if (_pixelformat) aglDestroyPixelFormat(_pixelformat); 118 118 119 119 _pbuffer = NULL; 120 120 _context = NULL; 121 121 _pixelformat = NULL; 122 122 123 123 _valid = _realized = false; 124 124 } … … 126 126 /** Make this graphics context current implementation. 127 127 * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 128 bool PixelBufferCarbon::makeCurrentImplementation() 129 { 128 bool PixelBufferCarbon::makeCurrentImplementation() 129 { 130 130 return (_realized) ? (aglSetCurrentContext(_context) == GL_TRUE) : false; 131 131 } 132 132 133 133 /** Make this graphics context current with specified read context implementation. 134 134 * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 135 bool PixelBufferCarbon::makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { 135 bool PixelBufferCarbon::makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { 136 136 return makeCurrentImplementation(); 137 137 } 138 138 139 139 /** Release the graphics context.*/ 140 bool PixelBufferCarbon::releaseContextImplementation() 141 { 140 bool PixelBufferCarbon::releaseContextImplementation() 141 { 142 142 return (aglSetCurrentContext(NULL) == GL_TRUE); 143 143 } … … 146 146 /** Pure virtual, Bind the graphics context to associated texture implementation. 147 147 * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ 148 void PixelBufferCarbon::bindPBufferToTextureImplementation( GLenum buffer ){ 148 void PixelBufferCarbon::bindPBufferToTextureImplementation( GLenum buffer ){ 149 149 150 OSG_NOTICE<<"GraphicsWindow::void bindPBufferToTextureImplementation(..) not implemented."<<std::endl; 150 OSG_NOTICE<<"GraphicsWindow::void bindPBufferToTextureImplementation(..) not implemented."<<std::endl; 151 151 } 152 152 153 153 /** Swap the front and back buffers implementation. 154 154 * Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */ 155 void PixelBufferCarbon::swapBuffersImplementation() 156 { 155 void PixelBufferCarbon::swapBuffersImplementation() 156 { 157 157 aglSwapBuffers(_context); 158 158 } 159 160 161 PixelBufferCarbon::~PixelBufferCarbon() 159 160 161 PixelBufferCarbon::~PixelBufferCarbon() 162 162 { 163 163 close(true);
