OSX and opengl profile > 2.1 on Qt 4.8



  • Hi All,

    I'm not working on a game, but rather tools for games.

    I'm curious: Is there a way in OSX to get access to opengl > 2.1 using Qt 4.8?

    I'm running a modern Intel HD5000 graphics laptop, and GLView reports that OpenGL 4.1 is available. However, when I attempt to set QGL to any core profile above 2.1 I end up with the version string reporting 2.1; which can't be right.

    Do any of you have example code that can set the GL context up in something higher than 2.1 on an OSX machine?

    My particulars are:

    •  OSX 10.9.3, XCode 5
      
    • Qt 4.8.6
      
    • Intel HD 5000 graphics.
      

    Thanks,

    -bms20



  • Ok - I'll answer my own question.

    The answer is that QGL in Qt 4.8 does not support profiles above compatibility 2.1.

    To do so requires hacking the file qgl_mac.mm and adding NSOpenGLPFAOpenGLProfile and NSOpenGLProfileVersion3_2Core to the NSOpenGLPixelFormatAttributes structures used.

    Don't treat the following diff as a complete solution - it will break any old style OpenGL on mac:

    diff --git a/build/packages/qt-everywhere-opensource-src-4.8.6/src/opengl/qgl_mac.mm b/build/packages/qt-everywhere-opensource-src-4.8.6/src/opengl/qgl_mac.mm
    index 4ecf888..52b24ed 100644
    --- a/build/packages/qt-everywhere-opensource-src-4.8.6/src/opengl/qgl_mac.mm
    +++ b/build/packages/qt-everywhere-opensource-src-4.8.6/src/opengl/qgl_mac.mm
    @@ -148,7 +148,11 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
    aglDestroyPixelFormat(fmt);
    #else
    QMacCocoaAutoReleasePool pool;

    • NSOpenGLPixelFormatAttribute attribs[] = { 0 };
    • NSOpenGLPixelFormatAttribute attribs[] = {
    •           NSOpenGLPFAOpenGLProfile,
      
    •           NSOpenGLProfileVersion3_2Core,
      
    •           0
      
    • };
      NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
      if (!fmt) {
      qWarning("QGLTemporaryContext: Cannot find any visuals");
      @@ -350,7 +354,7 @@ bool QGLContext::chooseContext(const QGLContext *shareContext)

    void *QGLContextPrivate::tryFormat(const QGLFormat &format)
    {

    • static const int Max = 40;
    • static const int Max = 42;
      #ifndef QT_MAC_USE_COCOA
      GLint attribs[Max], cnt = 0;
      bool device_is_pixmap = (paintDevice->devType() == QInternal::Pixmap);
      @@ -464,6 +468,10 @@ void *QGLContextPrivate::tryFormat(const QGLFormat &format)
      if (devType == QInternal::Pbuffer)
      attribs[cnt++] = NSOpenGLPFAPixelBuffer;

    • attribs[cnt++] = NSOpenGLPFAOpenGLProfile;

    • attribs[cnt++] = NSOpenGLProfileVersion3_2Core;

    • attribs[cnt] = 0;
      Q_ASSERT(cnt < Max);
      return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.