OpenGL OS-X Lion 2.1 vs 3.2 context
I’ve been developing a cross-platform rendering engine that once complete will serve as the basis for physics simulations. Up until this week I’ve been targeting Windows using Qt 4.8RC using the msvc2010 toolchain w/ CDB. I have access now to a Macbook w/ a 9400m Nvidia card that shows it will support OpenGL 3.2 w/ GLSL 1.5 (using 10.7.2).
After downloading and installing Xcode and Qt 4.8 (I use Creator as my IDE) I’ve compiled my code but can’t seem to get a 3.2 context setup, which seems should be straightforward using the following code snippet I have in main.cpp, before the window is created.
But when the GLWidget is created it reports a v2.1 context and tells me that my v1.5 shaders are not compatible (makes sense given 2.1 compatibility context). Is this a bug or some other implementation issue? I went w/ 4.8 because it appears 3.2/GLSL1.5 is supported but I can’t figure out how to get it to work. I can create a 3.2 context not using Qt so I’m wondering if it is something in the initialization.
Any help appreciated.
Have you checked the output of the
- QGLFormat::openGLVersionFlags ()
The following outputs that 3.2 isn’t supported:
- TRACE("GL 3.2 Not supported");
BUT if I compile the following example code from Apple it will run and as you can see below it’s using OpenGL 3.2, so it is accessible/available.
[Switching to process 7647 thread 0×0]
2011-12-28 20:05:29.590 MacGLEssentials[7647:407] NVIDIA GeForce 9400M OpenGL Engine 3.2 NVIDIA-7.12.9
Even though I don’t program in Objective-C, here is the code snippet that seems to properly initialize the context, it seems the 3.2 profile must be requested directly. Wondering if somewhere under the hood of Qt this isn’t happening.
- NSOpenGLPixelFormatAttribute attrs =
- NSOpenGLPFADepthSize, 24,
- // Must specify the 3.2 Core Profile to use OpenGL 3.2
- #if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
- NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
So last night I downloaded the source for Qt4.8, configured and built it then I modified the qgl_mac.mm file at line 431 I added the following lines:
- attribs[cnt++] = NSOpenGLPFAOpenGLProfile;
- attribs[cnt++] = NSOpenGLProfileVersion3_2Core;
Rebuilt and installed. With this modification I get OpenGL 3.2 and GLSL 1.5 working on my Macbook under Lion 10.7.2 – I found no other references to the above attributes in the Qt code so I’m guessing these have been mistakenly skipped? Do I submit this as a bug?