title: OpenGL core profile incredible slowdown on OS X
body: <p>I added a new GL renderer to my engine, which uses the core profile. While it runs fine on Windows <strike>and/or nvidia cards</strike>, it is like 10 times slower on OS X (3 fps instead of 30). The weird thing is, that my compatibility profile renderer runs fine.</p>
  
  <p>I collected some traces with Instruments and the GL profiler:</p>
  
  <p><a href="https://www.dropbox.com/sh/311fg9wu0zrarzm/31CGvUcf2q" rel="nofollow">https://www.dropbox.com/sh/311fg9wu0zrarzm/31CGvUcf2q</a></p>
  
  <p>It shows that the application spends its time in glDrawRangeElements.
  I tried the following things:</p>
  
  <ul>
  <li>use glDrawElements instead (no effect)</li>
  <li>flip culling (no effect on speed)</li>
  <li>disable some GL_DYNAMIC_DRAW buffers (no effect)</li>
  <li>bind index buffer after VAO when drawing (no effect)</li>
  <li>converted indices to 4 byte (no effect)</li>
  <li>use GL_BGRA textures (no effect)</li>
  </ul>
  
  <p>What I didn't try is to align my vertices to 16 byte boundary <strike>and/or convert indices to 4 byte</strike>, but seriously, if that would be the issue then why the hell does the standard allow it?</p>
  
  <p>I'm creating the context like this:</p>
  
  <pre><code>NSOpenGLPixelFormatAttribute attributes[] =
  {
      NSOpenGLPFAColorSize, 24,
      NSOpenGLPFAAlphaSize, 8,
      NSOpenGLPFADepthSize, 24,
      NSOpenGLPFAStencilSize, 8,
      NSOpenGLPFADoubleBuffer,
      NSOpenGLPFAAccelerated,
      NSOpenGLPFANoRecovery,
      NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
      0
  };
  
  NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
  NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil];
  
  [self.view setOpenGLContext:context];
  [context makeCurrentContext];
  </code></pre>
  
  <p>Tried on the following specs:</p>
  
  <ul>
  <li>radeon 6630M, OS X 10.7.5</li>
  <li>radeon 6750M, OS X 10.7.5</li>
  <li>geforce GT 330M, OS X 10.8.3</li>
  </ul>
  
  <p>Do you have any ideas what I might do wrong? Again, it works fine with the compatibility profile (not using VAOs though).</p>
  
  <p><strong>UPDATE</strong>: reported to Apple.</p>
  
  <p><strong>UPDATE</strong>: Apple doesn't give a damn to the problem...anyway I created a small test program which is actually good. Now I compared the call stack with Instruments, and found out that when using the engine, <em>glDrawRangeElements</em> does two calls:</p>
  
  <ul>
  <li>gleDrawArraysOrElements_ExecCore</li>
  <li>gleDrawArraysOrElements_Entries_Body</li>
  </ul>
  
  <p>while in the test program it calls only the second. Now the first call does something like an immediate mode render (gleFlushPrimitivesTCLFunc, gleRunVertexSubmitterImmediate), so obviously casues the slowdown.</p>