3

I'm trying to update an OSX OpenGL project to OpenGL 4.1. My shaders use #version 410 and everything is working and pretty snappy. Today I noticed that there's a new NSOpenGLPFAOpenGLProfile value for 4.1, so I updated the pixel format profile from NSOpenGLProfileVersion3_2Core to NSOpenGLProfileVersion4_1Core, and now rendering is insanely slow. My pixel format initialization code looks like this:

NSOpenGLPixelFormatAttribute attrs[] =
{
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFADepthSize, 24,
    NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core,
    0
};

NSOpenGLPixelFormat *pf =
    [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];

Anybody know why this would be so much slower - Is there something else I need to update?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Mike Hays
  • 93
  • 6
  • I am not familiar with that constant. When 10.9 was released and they introduced GL 4.1 contexts, the constant was still `NSOpenGLProfileVersion3_2Core` and it was understood that said constant gave you the highest version context the platform supported. It sounds almost as though this is giving you the reference software render path instead of hardware. – Andon M. Coleman Jan 05 '15 at 21:27
  • Thank you for the reply! I saw that the [glfw](https://github.com/glfw/glfw) project updated to use this constant so I assumed it was working... I believe you are correct though - CPU usage spikes when I render using the 4_1 constant. Maybe it's only valid on Yosemite... – Mike Hays Jan 05 '15 at 22:10
  • Ah, you are absolutely right. I checked github and came across line 131 of [`nsgl_context.m`](https://github.com/glfw/glfw/blob/439417a22c584360775ce89450c3548a7a4d28fc/src/nsgl_context.m). There is a pre-processor directive there that only works on OS X 10.10. So it looks like a change specific to 10.10. – Andon M. Coleman Jan 06 '15 at 03:05
  • Yes, sounds like you might be getting a software fallback. You could try `glGetString()` with `GL_VENDOR` or `GL_RENDERER`. I believe those values change if you get a full fallback. Otherwise, for partial fallbacks, I think there used to be an option in OpenGL Profiler to show fallbacks. Is your GPU listed as supporting 4.1 on https://developer.apple.com/opengl/capabilities/? – Reto Koradi Jan 06 '15 at 07:05
  • It is definitely a software fallback. `GL_VENDOR` reports `Apple Computer, Inc.` and `GL_RENDERER` reports `Apple Software Renderer` for the 4.1 pixel format profile. When using `NSOpenGLProfileVersion3_2Core`, the `GL_MAJOR_VERSION`/`GL_MINOR_VERSION` are reported as 4.1, and I'm using #version 410 in my shaders, as I said at the beginning of my question. My video card does support 4.1. Confirmed via Apple Forums that this is fixed in 10.10 (I'm on 10.9.5) – Mike Hays Jan 06 '15 at 23:12

2 Answers2

2

Using NSOpenGLProfileVersion4_1Core on Mavericks causes a full software fallback. This is not an issue on Yosemite.

Mike Hays
  • 93
  • 6
0

Using NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core in either case (10.9 or 10.10) will actually enable OpenGL and GLSL versions 4.1. I've used it myself in both cases.

NSOpenGLProfileVersion3_2Core is a misnomer. It actually enables the latest version available, not necessarily 3.2.

Check this to be true with the following calls in your prepareOpenGL method:

NSLog(@"OpenGL version = %s", glGetString(GL_VERSION));
NSLog(@"GLSL version = %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
jwlaughton
  • 905
  • 1
  • 6
  • 11
  • This is decent information (NSOpenGLProfileVersion3_2Core enables the latest version 3.2 or greater, not really a misnomer IMO), but doesn't answer the question. The reason NSOpenGLProfileVersion4_1Core caused a slowdown for me is an issue with NSOpenGLProfileVersion4_1Core on Mavericks (according to an Apple developer). – Mike Hays Jan 07 '15 at 01:51
  • Sorry, I thought I was giving you an alternative to implement version 4.1 without causing problems. Actually I don't see NSOpenGLProfileVersion4_1Core listed in the Apple docs as a valid profile option. – jwlaughton Jan 07 '15 at 02:59
  • `NSOpenGLProfileVersion3_2Core` does not *semantically* enable the latest version available. It means a GL engine which is compatible with 3.2. For now, the latest version implemented in any driver on OS X is 4.1 which happens to be compatible with 3.2. However, if and when Apple implements 4.2 or later, those will no longer be compatible with 3.2 because a) Apple use forward-compatible contexts in which deprecated features are actually removed, and b) 4.2 deprecates functionality that was present in 3.2. – Ken Thomases Jan 07 '15 at 03:27
  • For those confused about `NSOpenGLProfileVersion4_1Core`, it's not documented but is in the headers in the 10.10 SDK, which makes it public API. The corresponding constant from CGL, `kCGLOGLPVersion_GL4_Core`, is present in the headers in the 10.9 SDK. – Ken Thomases Jan 07 '15 at 03:29
  • @jwlaughton - No worries, thank you taking the time to respond - I am using the `3_2` constant for now since it does the right thing on my machine :) @KenThomases - Good to know about forward-compatibility, thanks. And yep - I stumbled across `NSOpenGLProfileVersion4_1Core` while looking around the headers, re-familiarizing myself with the API. – Mike Hays Jan 07 '15 at 04:49