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); }
wxGLContext::wxGLContext( AGLPixelFormat fmt, wxGLCanvas *win, const wxPalette& palette, const wxGLContext *other /* for sharing display lists */ ) { m_window = win; #ifndef __LP64__ m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetTopLevelWindowRef())); #endif m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); GLboolean b; #ifndef __LP64__ b = aglSetDrawable(m_glContext, m_drawable); aglEnable(m_glContext , AGL_BUFFER_RECT ) ; #else b = aglSetHIViewRef(m_glContext, (HIViewRef) win->GetHandle()); #endif wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") ); b = aglSetCurrentContext(m_glContext); wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") ); }
bool Window::configInitAGLFullscreen() { AGLContext context = getAGLContext(); if( !context ) { sendError( ERROR_AGLWINDOW_NO_CONTEXT ); return false; } Global::enterCarbon(); aglEnable( context, AGL_FS_CAPTURE_SINGLE ); const PixelViewport& pvp = getPixelViewport(); if( !aglSetFullScreen( context, pvp.w, pvp.h, 0, 0 )) LBWARN << "aglSetFullScreen to " << pvp << " failed: " << aglError() << std::endl; // Do focus hell ProcessSerialNumber selfProcess = { 0, kCurrentProcess }; SetFrontProcess( &selfProcess ); Global::leaveCarbon(); setPixelViewport( pvp ); if( getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE ) != OFF ) initEventHandler(); return true; }
void OSXCarbonWindow::createWindowFromExternal(HIViewRef viewRef) { // TODO: The Control is going to report the incorrect location with a // Metallic / Textured window. The default windows work just fine. // First get the HIViewRef / ControlRef mView = viewRef; mWindow = GetControlOwner(mView); // Lets try hiding the HIView //HIViewSetVisible(mView, false); // Get the rect bounds ::Rect ctrlBounds; GetControlBounds(mView, &ctrlBounds); GLint bufferRect[4]; bufferRect[0] = ctrlBounds.left; // left edge bufferRect[1] = ctrlBounds.bottom; // bottom edge bufferRect[2] = ctrlBounds.right - ctrlBounds.left; // width of buffer rect bufferRect[3] = ctrlBounds.bottom - ctrlBounds.top; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable(mAGLContext, AGL_BUFFER_RECT); mIsExternal = true; }
static void HIOpenGLViewSetContextWindowAndBounds (HIOpenGLViewData* inData) { if (inData == nil) return; if (inData->mControl == nil) return; if (inData->mContext == nil) return; // Determine the AGL_BUFFER_RECT for the control. The coordinate // system for this rectangle is relative to the owning window, with // the origin at the bottom left corner and the y-axis inverted. HIRect ctrlBounds, winBounds; HIViewGetBounds(inData->mControl, &ctrlBounds); WindowRef window = GetControlOwner(inData->mControl); ControlRef root = nil; GetRootControl(window, &root); HIViewGetBounds(root, &winBounds); HIViewConvertRect(&ctrlBounds, inData->mControl, root); GLint bufferRect[4] = { (int)ctrlBounds.origin.x, (int)((winBounds.size.height) - (ctrlBounds.origin.y + ctrlBounds.size.height)), (int)ctrlBounds.size.width, (int)ctrlBounds.size.height }; // Associate the OpenGL context with the control's window, and establish the buffer rect. aglSetDrawable(inData->mContext, GetWindowPort(window)); aglSetInteger(inData->mContext, AGL_BUFFER_RECT, bufferRect); aglEnable(inData->mContext, AGL_BUFFER_RECT); // Establish the clipping region for the OpenGL context. To properly handle clipping // within the view hierarchy, I'm walking the hierarchy to determine the intersection // of this view's bounds with its parents. Is there an easier way to do this? CGRect clipBounds = ctrlBounds; HIViewRef parent = HIViewGetSuperview(inData->mControl); while (parent != root) { CGRect parentBounds; HIViewGetBounds(parent, &parentBounds); HIViewConvertRect(&parentBounds, parent, root); clipBounds = CGRectIntersection(clipBounds, parentBounds); parent = HIViewGetSuperview(parent); } Rect rgnBounds = { (int)clipBounds.origin.y, (int)clipBounds.origin.x, (int)(clipBounds.origin.y + clipBounds.size.height), (int)(clipBounds.origin.x + clipBounds.size.width) }; RgnHandle rgn = NewRgn(); RectRgn(rgn, &rgnBounds); aglSetInteger(inData->mContext, AGL_CLIP_REGION, (const GLint*)rgn); aglEnable(inData->mContext, AGL_CLIP_REGION); }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::windowMovedOrResized() { // External windows will call this method. if(mView != NULL) { // Determine the AGL_BUFFER_RECT for the view. The coordinate // system for this rectangle is relative to the owning window, with // the origin at the bottom left corner and the y-axis inverted. // Also, when leaving fullscreen, the display properties are not guaranteed to be // the same as when we were windowed previously. So resize the window and views back // to their original dimensions. HIRect newFrame = CGRectMake(mLeft, mTop+22, mWidth, mHeight); HIRect viewBounds = CGRectZero, winBounds = CGRectZero; SizeWindow(mWindow, mWidth, mHeight, true); HIViewSetFrame(mView, &newFrame); HIViewGetBounds(mView, &viewBounds); HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView)); HIViewGetBounds(root, &winBounds); HIViewConvertRect(&viewBounds, mView, root); // Set the AGL buffer rectangle (i.e. the bounds that we will use) GLint bufferRect[4]; bufferRect[0] = viewBounds.origin.x; // 0 = left edge bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge bufferRect[2] = viewBounds.size.width; // width of buffer rect bufferRect[3] = viewBounds.size.height; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable(mAGLContext, AGL_BUFFER_RECT); aglUpdateContext(mAGLContext); mLeft = viewBounds.origin.x; mTop = bufferRect[1]; } for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) { (*it).second->_updateDimensions(); } }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::windowResized() { // Ensure the context is current if(!mIsFullScreen) { // Determine the AGL_BUFFER_RECT for the view. The coordinate // system for this rectangle is relative to the owning window, with // the origin at the bottom left corner and the y-axis inverted. HIRect newFrame = CGRectMake(mLeft, mTop+22, mWidth, mHeight); HIRect viewBounds = CGRectZero, winBounds = CGRectZero; SizeWindow(mWindow, mWidth, mHeight, true); HIViewSetFrame(mView, &newFrame); HIViewGetBounds(mView, &viewBounds); HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView)); HIViewGetBounds(root, &winBounds); HIViewConvertRect(&viewBounds, mView, root); // Set the AGL buffer rectangle (i.e. the bounds that we will use) GLint bufferRect[4]; bufferRect[0] = viewBounds.origin.x; // 0 = left edge bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge bufferRect[2] = viewBounds.size.width; // width of buffer rect bufferRect[3] = viewBounds.size.height; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable(mAGLContext, AGL_BUFFER_RECT); aglUpdateContext(mAGLContext); mLeft = viewBounds.origin.x; mTop = bufferRect[1]; } else { swapCGLBuffers(); } for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) { (*it).second->_updateDimensions(); } }
wxGLContext::wxGLContext( AGLPixelFormat fmt, wxGLCanvas *win, const wxPalette& palette, const wxGLContext *other /* for sharing display lists */ ) { m_window = win; m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow())); m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); GLboolean b; b = aglSetDrawable(m_glContext, m_drawable); wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") ); aglEnable(m_glContext , AGL_BUFFER_RECT ) ; b = aglSetCurrentContext(m_glContext); wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") ); }
void wxGLCanvas::SetViewport() { if ( !m_needsUpdate ) return; m_needsUpdate = false; // AGLContext context = aglGetCurrentContext(); // if ( !context ) // return; // viewport is initially set to entire port, adjust it to just this window int x = 0, y = 0; MacClientToRootWindow(&x , &y); int width, height; GetClientSize(&width, &height); Rect bounds; GetWindowPortBounds(MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds); GLint parms[4]; parms[0] = x; parms[1] = bounds.bottom - bounds.top - ( y + height ); parms[2] = width; parms[3] = height; // move the buffer rect out of sight if we're hidden if ( !m_macCanvasIsShown ) parms[0] += 20000; if ( !aglSetInteger(m_dummyContext, AGL_BUFFER_RECT, parms) ) wxLogAGLError("aglSetInteger(AGL_BUFFER_RECT)"); if ( !aglEnable(m_dummyContext, AGL_BUFFER_RECT) ) wxLogAGLError("aglEnable(AGL_BUFFER_RECT)"); if ( !aglUpdateContext(m_dummyContext) ) wxLogAGLError("aglUpdateContext"); }
void PaneView::resize(short left, short top, short right, short bottom) { aglSetCurrentContext(_model._aglContext); aglUpdateContext(_model._aglContext); short width = right - left; short height = bottom - top; float aspectRatio = (float) width / (float) height; // float fieldOfViewY = 45.0f * _model.getSpace().getCurrentShot().getCamera().getZoom(); float fieldOfViewY = 45.0f * _model.getSpace().getShots().next().getCamera().getZoom(); Rect portRect; GetWindowPortBounds(_model._windowRef, &portRect); short portHeight = portRect.bottom - portRect.top; GLint bufferRect[4]; bufferRect[0] = _model._bounds->left; // x bufferRect[1] = portHeight - _model._bounds->bottom; // y bufferRect[2] = _model._bounds->right - _model._bounds->left; // width bufferRect[3] = _model._bounds->bottom - _model._bounds->top; // height aglSetInteger(_model._aglContext, AGL_BUFFER_RECT, bufferRect); aglEnable(_model._aglContext, AGL_BUFFER_RECT); // aglSetInteger(inData->mContext, AGL_CLIP_REGION, (const GLint*)rgn); // aglEnable(inData->mContext, AGL_CLIP_REGION); glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fieldOfViewY, aspectRatio, 1.0f, 1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); InvalWindowRect(_model._windowRef, &portRect); _model.getSpace().resize(width, height); }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::windowMovedOrResized() { // External windows will call this method. if(mView != NULL) { // Determine the AGL_BUFFER_RECT for the view. The coordinate // system for this rectangle is relative to the owning window, with // the origin at the bottom left corner and the y-axis inverted. HIRect viewBounds, winBounds; HIViewGetBounds(mView, &viewBounds); HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView)); HIViewGetBounds(root, &winBounds); HIViewConvertRect(&viewBounds, mView, root); // Set the AGL buffer rectangle (i.e. the bounds that we will use) GLint bufferRect[4]; bufferRect[0] = viewBounds.origin.x; // 0 = left edge bufferRect[1] = winBounds.size.height - (viewBounds.origin.y + viewBounds.size.height); // 0 = bottom edge bufferRect[2] = viewBounds.size.width; // width of buffer rect bufferRect[3] = viewBounds.size.height; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable (mAGLContext, AGL_BUFFER_RECT); mWidth = viewBounds.size.width; mHeight = viewBounds.size.height; mLeft = viewBounds.origin.x; mTop = bufferRect[1]; } for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it) { (*it).second->_updateDimensions(); } }
//-------------------------------------------------------------------------------------------------// void OSXCarbonWindow::create( const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams ) { bool hasDepthBuffer; String title = name; size_t fsaa_samples = 0; int left = 0; int top = 0; int depth = 32; if( miscParams ) { NameValuePairList::const_iterator opt = NULL; // Full screen anti aliasing opt = miscParams->find( "FSAA" ); if( opt != miscParams->end() ) fsaa_samples = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "left" ); if( opt != miscParams->end() ) left = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "top" ); if( opt != miscParams->end() ) top = StringConverter::parseUnsignedInt( opt->second ); opt = miscParams->find( "title" ); if( opt != miscParams->end() ) title = opt->second; opt = miscParams->find( "depthBuffer" ); if( opt != miscParams->end() ) hasDepthBuffer = StringConverter::parseBool( opt->second ); opt = miscParams->find( "colourDepth" ); if( opt != miscParams->end() ) depth = StringConverter::parseUnsignedInt( opt->second ); } if(fullScreen) { GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext *mainContext = (OSXContext*)rs->_getMainContext(); CGLContextObj share = NULL; if(mainContext == 0) { share = NULL; } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* aglShare = static_cast<OSXCarbonContext*>(mainContext); aglGetCGLContext(aglShare->getContext(), &((void*)share)); } else if(mainContext->getContextType() == "CGL") { OSXCGLContext* cglShare = static_cast<OSXCGLContext*>(mainContext); share = cglShare->getContext(); } // create the context createCGLFullscreen(width, height, depth, fsaa_samples, share); } else { int i = 0; AGLPixelFormat pixelFormat; GLint attribs[ 20 ]; attribs[ i++ ] = AGL_NO_RECOVERY; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_ACCELERATED; attribs[ i++ ] = GL_TRUE; attribs[ i++ ] = AGL_RGBA; attribs[ i++ ] = AGL_DOUBLEBUFFER; attribs[ i++ ] = AGL_ALPHA_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_STENCIL_SIZE; attribs[ i++ ] = 8; attribs[ i++ ] = AGL_DEPTH_SIZE; attribs[ i++ ] = depth; if(fsaa_samples > 1) { attribs[ i++ ] = AGL_MULTISAMPLE; attribs[ i++ ] = 1; attribs[ i++ ] = AGL_SAMPLE_BUFFERS_ARB; attribs[ i++ ] = fsaa_samples; } attribs[ i++ ] = AGL_NONE; pixelFormat = aglChoosePixelFormat( NULL, 0, attribs ); // Create the AGLContext from our pixel format // Share it with main GLRenderSystem *rs = static_cast<GLRenderSystem*>(Root::getSingleton().getRenderSystem()); OSXContext* mainContext = static_cast<OSXContext*>( rs->_getMainContext() ); if(mainContext == 0) { mAGLContext = aglCreateContext(pixelFormat, NULL); } else if(mainContext->getContextType() == "AGL") { OSXCarbonContext* context = static_cast<OSXCarbonContext*>( rs->_getMainContext() ); AGLContext shared = context->getContext(); mAGLContext = aglCreateContext(pixelFormat, context->getContext()); } else { // If we do not have an AGL, we can not clone it using this window LogManager::getSingleton().logMessage( "Warning: You asked to create a second window, " "when the previous window was not of this type. OgreOSXCarbonWindow can only share " "with an AGL context."); } NameValuePairList::const_iterator opt = 0; if(miscParams) opt = miscParams->find("externalWindowHandle"); if(!miscParams || opt == miscParams->end()) { // create the window rect in global coords ::Rect windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = width; windowRect.bottom = height; // set the default attributes for the window WindowAttributes windowAttrs = kWindowStandardDocumentAttributes; // default: "resize" if (miscParams) { opt = miscParams->find("border"); if( opt != miscParams->end() ) { String borderType = opt->second; if( borderType == "none" ) windowAttrs = kWindowNoTitleBarAttribute; else if( borderType == "fixed" ) windowAttrs = kWindowStandardFloatingAttributes; } } windowAttrs |= kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowHideOnFullScreenAttribute; // Create the window CreateNewWindow(kDocumentWindowClass, windowAttrs, &windowRect, &mWindow); // Color the window background black SetThemeWindowBackground (mWindow, kThemeBrushBlack, true); // Set the title of our window CFStringRef titleRef = CFStringCreateWithCString( kCFAllocatorDefault, title.c_str(), kCFStringEncodingASCII ); SetWindowTitleWithCFString( mWindow, titleRef ); // Center our window on the screen RepositionWindow( mWindow, NULL, kWindowCenterOnMainScreen ); // Get our view HIViewFindByID( HIViewGetRoot( mWindow ), kHIViewWindowContentID, &mView ); // Set up our UPP for Window Events EventTypeSpec eventSpecs[] = { {kEventClassWindow, kEventWindowActivated}, {kEventClassWindow, kEventWindowDeactivated}, {kEventClassWindow, kEventWindowShown}, {kEventClassWindow, kEventWindowHidden}, {kEventClassWindow, kEventWindowDragCompleted}, {kEventClassWindow, kEventWindowBoundsChanged}, {kEventClassWindow, kEventWindowExpanded}, {kEventClassWindow, kEventWindowCollapsed}, {kEventClassWindow, kEventWindowClosed}, {kEventClassWindow, kEventWindowClose} }; EventHandlerUPP handlerUPP = NewEventHandlerUPP(WindowEventUtilities::_CarbonWindowHandler); // Install the standard event handler for the window EventTargetRef target = GetWindowEventTarget(mWindow); InstallStandardEventHandler(target); // We also need to install the WindowEvent Handler, we pass along the window with our requests InstallEventHandler(target, handlerUPP, 10, eventSpecs, (void*)this, &mEventHandlerRef); // Display and select our window ShowWindow(mWindow); SelectWindow(mWindow); // Add our window to the window event listener class WindowEventUtilities::_addRenderWindow(this); } else { // TODO: The Contol is going to report the incorrect location with a // Metalic / Textured window. The default windows work just fine. // First get the HIViewRef / ControlRef mView = (HIViewRef)StringConverter::parseUnsignedLong(opt->second); mWindow = GetControlOwner(mView); // Lets try hiding the HIView //HIViewSetVisible(mView, false); // Get the rect bounds ::Rect ctrlBounds; GetControlBounds(mView, &ctrlBounds); GLint bufferRect[4]; bufferRect[0] = ctrlBounds.left; // left edge bufferRect[1] = ctrlBounds.bottom; // bottom edge bufferRect[2] = ctrlBounds.right - ctrlBounds.left; // width of buffer rect bufferRect[3] = ctrlBounds.bottom - ctrlBounds.top; // height of buffer rect aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect); aglEnable (mAGLContext, AGL_BUFFER_RECT); mIsExternal = true; } // Set the drawable, and current context // If you do this last, there is a moment before the rendering window pops-up // This could go once inside each case above, before the window is displayed, // if desired. aglSetDrawable(mAGLContext, GetWindowPort(mWindow)); aglSetCurrentContext(mAGLContext); // Give a copy of our context to the render system mContext = new OSXCarbonContext(mAGLContext, pixelFormat); } mName = name; mWidth = width; mHeight = height; mActive = true; mClosed = false; mCreated = true; mIsFullScreen = fullScreen; }
void QGLContext::updatePaintDevice() { Q_D(QGLContext); d->update = false; #if 0 //(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { if(d->paintDevice->devType() == QInternal::Widget) { QWidget *w = (QWidget *)d->paintDevice; aglSetHIViewRef((AGLContext)d->cx, (HIViewRef)w->winId()); } else if(d->paintDevice->devType() == QInternal::Pixmap) { QPixmap *pm = (QPixmap *)d->paintDevice; aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(), qt_mac_pixmap_get_bytes_per_line(pm), qt_mac_pixmap_get_base(pm)); } else { qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!"); } } else #endif { #ifndef Q_OS_MAC64 if(d->paintDevice->devType() == QInternal::Widget) { //get control information QWidget *w = (QWidget *)d->paintDevice; HIViewRef hiview = (HIViewRef)w->winId(); WindowPtr window = qt_mac_window_for(hiview); #ifdef DEBUG_OPENGL_REGION_UPDATE static int serial_no_gl = 0; qDebug("[%d] %p setting on %s::%s %p/%p [%s]", ++serial_no_gl, w, w->metaObject()->className(), w->objectName().toLatin1().constData(), hiview, window, w->handle() ? "Inside" : "Outside"); #endif //update drawable if(0 && w->isWindow() && w->isFullScreen()) { aglSetDrawable((AGLContext)d->cx, 0); aglSetFullScreen((AGLContext)d->cx, w->width(), w->height(), 0, QApplication::desktop()->screenNumber(w)); w->hide(); } else { AGLDrawable old_draw = aglGetDrawable((AGLContext)d->cx), new_draw = GetWindowPort(window); if(old_draw != new_draw) aglSetDrawable((AGLContext)d->cx, new_draw); } if(!w->isWindow()) { QRegion clp = qt_mac_get_widget_rgn(w); //get drawable area #ifdef DEBUG_OPENGL_REGION_UPDATE if(clp.isEmpty()) { qDebug(" Empty area!"); } else { QVector<QRect> rs = clp.rects(); for(int i = 0; i < rs.count(); i++) qDebug(" %d %d %d %d", rs[i].x(), rs[i].y(), rs[i].width(), rs[i].height()); } #endif //update the clip if(!aglIsEnabled((AGLContext)d->cx, AGL_BUFFER_RECT)) aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT); if(clp.isEmpty()) { GLint offs[4] = { 0, 0, 0, 0 }; aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs); if(aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION)) aglDisable((AGLContext)d->cx, AGL_CLIP_REGION); } else { HIPoint origin = { 0., 0. }; HIViewConvertPoint(&origin, HIViewRef(w->winId()), 0); const GLint offs[4] = { qRound(origin.x), w->window()->frameGeometry().height() - (qRound(origin.y) + w->height()), w->width(), w->height() }; aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs); aglSetInteger((AGLContext)d->cx, AGL_CLIP_REGION, (const GLint *)clp.handle(true)); if(!aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION)) aglEnable((AGLContext)d->cx, AGL_CLIP_REGION); } } } else if(d->paintDevice->devType() == QInternal::Pixmap) { QPixmap *pm = (QPixmap *)d->paintDevice; PixMapHandle mac_pm = GetGWorldPixMap((GWorldPtr)pm->macQDHandle()); aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(), GetPixRowBytes(mac_pm), GetPixBaseAddr(mac_pm)); } else { qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!"); } #endif // Q_OS_MAC64 } aglUpdateContext((AGLContext)d->cx); }
/***************************************************************************** QGLContext AGL-specific code *****************************************************************************/ bool QGLContext::chooseContext(const QGLContext* shareContext) { Q_D(QGLContext); d->cx = 0; d->vi = chooseMacVisual(0); if(!d->vi) return false; AGLPixelFormat fmt = (AGLPixelFormat)d->vi; GLint res; aglDescribePixelFormat(fmt, AGL_LEVEL, &res); d->glFormat.setPlane(res); if(deviceIsPixmap()) res = 0; else aglDescribePixelFormat(fmt, AGL_DOUBLEBUFFER, &res); d->glFormat.setDoubleBuffer(res); aglDescribePixelFormat(fmt, AGL_DEPTH_SIZE, &res); d->glFormat.setDepth(res); if (d->glFormat.depth()) d->glFormat.setDepthBufferSize(res); aglDescribePixelFormat(fmt, AGL_RGBA, &res); d->glFormat.setRgba(res); aglDescribePixelFormat(fmt, AGL_RED_SIZE, &res); d->glFormat.setRedBufferSize(res); aglDescribePixelFormat(fmt, AGL_GREEN_SIZE, &res); d->glFormat.setGreenBufferSize(res); aglDescribePixelFormat(fmt, AGL_BLUE_SIZE, &res); d->glFormat.setBlueBufferSize(res); aglDescribePixelFormat(fmt, AGL_ALPHA_SIZE, &res); d->glFormat.setAlpha(res); if (d->glFormat.alpha()) d->glFormat.setAlphaBufferSize(res); aglDescribePixelFormat(fmt, AGL_ACCUM_RED_SIZE, &res); // Bug in Apple OpenGL (rdr://5015603), when we don't have an accumulation // buffer, it still claims that we have a 16-bit one (which is pretty rare). // So, we just assume we can never have a buffer that small. d->glFormat.setAccum(res > 5); if (d->glFormat.accum()) d->glFormat.setAccumBufferSize(res); aglDescribePixelFormat(fmt, AGL_STENCIL_SIZE, &res); d->glFormat.setStencil(res); if (d->glFormat.stencil()) d->glFormat.setStencilBufferSize(res); aglDescribePixelFormat(fmt, AGL_STEREO, &res); d->glFormat.setStereo(res); aglDescribePixelFormat(fmt, AGL_SAMPLE_BUFFERS_ARB, &res); d->glFormat.setSampleBuffers(res); if (d->glFormat.sampleBuffers()) { aglDescribePixelFormat(fmt, AGL_SAMPLES_ARB, &res); d->glFormat.setSamples(res); } if(shareContext && (!shareContext->isValid() || !shareContext->d_func()->cx)) { qWarning("QGLContext::chooseContext(): Cannot share with invalid context"); shareContext = 0; } // sharing between rgba and color-index will give wrong colors if(shareContext && (format().rgba() != shareContext->format().rgba())) shareContext = 0; AGLContext ctx = aglCreateContext(fmt, (AGLContext) (shareContext ? shareContext->d_func()->cx : 0)); if(!ctx) { GLenum err = aglGetError(); if(err == AGL_BAD_MATCH || err == AGL_BAD_CONTEXT) { if(shareContext && shareContext->d_func()->cx) { qWarning("QGLContext::chooseContext(): Context sharing mismatch!"); if(!(ctx = aglCreateContext(fmt, 0))) return false; shareContext = 0; } } if(!ctx) { qWarning("QGLContext::chooseContext(): Unable to create QGLContext"); return false; } } d->cx = ctx; if (shareContext && shareContext->d_func()->cx) { QGLContext *share = const_cast<QGLContext *>(shareContext); d->sharing = true; share->d_func()->sharing = true; } if(deviceIsPixmap()) updatePaintDevice(); // vblank syncing GLint interval = d->reqFormat.swapInterval(); if (interval != -1) { aglSetInteger((AGLContext)d->cx, AGL_SWAP_INTERVAL, &interval); if (interval != 0) aglEnable((AGLContext)d->cx, AGL_SWAP_INTERVAL); else aglDisable((AGLContext)d->cx, AGL_SWAP_INTERVAL); } aglGetInteger((AGLContext)d->cx, AGL_SWAP_INTERVAL, &interval); d->glFormat.setSwapInterval(interval); return true; }