static void init_gl(WindowRef wref) { GLint major, minor; aglGetVersion(&major, &minor); SkDebugf("---- agl version %d %d\n", major, minor); const GLint pixelAttrs[] = { AGL_RGBA, AGL_DEPTH_SIZE, 32, AGL_OFFSCREEN, AGL_NONE }; AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs); SkDebugf("----- agl format %p\n", format); gAGLContext = aglCreateContext(format, NULL); SkDebugf("----- agl context %p\n", gAGLContext); aglDestroyPixelFormat(format); aglEnable(gAGLContext, GL_BLEND); aglEnable(gAGLContext, GL_LINE_SMOOTH); aglEnable(gAGLContext, GL_POINT_SMOOTH); aglEnable(gAGLContext, GL_POLYGON_SMOOTH); aglSetCurrentContext(gAGLContext); }
AGLPixelFormat Window::chooseAGLPixelFormat() { Global::enterCarbon(); CGOpenGLDisplayMask glDisplayMask = CGDisplayIDToOpenGLDisplayMask( _impl->cgDisplayID ); // build attribute list std::vector<GLint> attributes; attributes.push_back( AGL_RGBA ); attributes.push_back( GL_TRUE ); attributes.push_back( AGL_ACCELERATED ); attributes.push_back( GL_TRUE ); if( getIAttribute( WindowSettings::IATTR_HINT_FULLSCREEN ) == ON ) attributes.push_back( AGL_FULLSCREEN ); attributes.push_back( AGL_DISPLAY_MASK ); attributes.push_back( glDisplayMask ); GLint colorSize = getIAttribute( WindowSettings::IATTR_PLANES_COLOR ); if( colorSize != OFF ) { switch( colorSize ) { case RGBA16F: attributes.push_back( AGL_COLOR_FLOAT ); colorSize = 16; break; case RGBA32F: attributes.push_back( AGL_COLOR_FLOAT ); colorSize = 32; break; case AUTO: colorSize = 8; break; default: break; } attributes.push_back( AGL_RED_SIZE ); attributes.push_back( colorSize ); attributes.push_back( AGL_GREEN_SIZE ); attributes.push_back( colorSize ); attributes.push_back( AGL_BLUE_SIZE ); attributes.push_back( colorSize ); const int alphaSize = getIAttribute( WindowSettings::IATTR_PLANES_ALPHA ); if( alphaSize > 0 || alphaSize == AUTO ) { attributes.push_back( AGL_ALPHA_SIZE ); attributes.push_back( alphaSize > 0 ? alphaSize : colorSize ); } } const int depthSize = getIAttribute( WindowSettings::IATTR_PLANES_DEPTH ); if( depthSize > 0 || depthSize == AUTO ) { attributes.push_back( AGL_DEPTH_SIZE ); attributes.push_back( depthSize>0 ? depthSize : 24 ); } const int stencilSize = getIAttribute( WindowSettings::IATTR_PLANES_STENCIL ); if( stencilSize > 0 || stencilSize == AUTO ) { attributes.push_back( AGL_STENCIL_SIZE ); attributes.push_back( stencilSize>0 ? stencilSize : 1 ); } const int accumSize = getIAttribute( WindowSettings::IATTR_PLANES_ACCUM ); const int accumAlpha = getIAttribute( WindowSettings::IATTR_PLANES_ACCUM_ALPHA ); if( accumSize >= 0 ) { attributes.push_back( AGL_ACCUM_RED_SIZE ); attributes.push_back( accumSize ); attributes.push_back( AGL_ACCUM_GREEN_SIZE ); attributes.push_back( accumSize ); attributes.push_back( AGL_ACCUM_BLUE_SIZE ); attributes.push_back( accumSize ); attributes.push_back( AGL_ACCUM_ALPHA_SIZE ); attributes.push_back( accumAlpha >= 0 ? accumAlpha : accumSize ); } else if( accumAlpha >= 0 ) { attributes.push_back( AGL_ACCUM_ALPHA_SIZE ); attributes.push_back( accumAlpha ); } const int samplesSize = getIAttribute( WindowSettings::IATTR_PLANES_SAMPLES ); if( samplesSize >= 0 ) { attributes.push_back( AGL_SAMPLE_BUFFERS_ARB ); attributes.push_back( 1 ); attributes.push_back( AGL_SAMPLES_ARB ); attributes.push_back( samplesSize ); } if( getIAttribute( WindowSettings::IATTR_HINT_DOUBLEBUFFER ) == ON || ( getIAttribute( WindowSettings::IATTR_HINT_DOUBLEBUFFER ) == AUTO && getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE ) == WINDOW )) { attributes.push_back( AGL_DOUBLEBUFFER ); attributes.push_back( GL_TRUE ); } if( getIAttribute( WindowSettings::IATTR_HINT_STEREO ) == ON ) { attributes.push_back( AGL_STEREO ); attributes.push_back( GL_TRUE ); } attributes.push_back( AGL_NONE ); // build backoff list, least important attribute last std::vector<int> backoffAttributes; if( getIAttribute( WindowSettings::IATTR_HINT_DOUBLEBUFFER ) == AUTO && getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE ) == WINDOW ) backoffAttributes.push_back( AGL_DOUBLEBUFFER ); if( stencilSize == AUTO ) backoffAttributes.push_back( AGL_STENCIL_SIZE ); // choose pixel format AGLPixelFormat pixelFormat = 0; while( true ) { pixelFormat = aglCreatePixelFormat( &attributes.front( )); if( pixelFormat || // found one or backoffAttributes.empty( )) // nothing else to try break; // Gradually remove backoff attributes const GLint attribute = backoffAttributes.back(); backoffAttributes.pop_back(); std::vector<GLint>::iterator iter = find( attributes.begin(), attributes.end(), attribute ); LBASSERT( iter != attributes.end( )); attributes.erase( iter, iter+2 ); // remove two item (attr, value) } if( !pixelFormat ) sendError( ERROR_SYSTEMWINDOW_PIXELFORMAT_NOTFOUND ); Global::leaveCarbon(); return pixelFormat; }