Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does OpenGL double-buffering seem to be inconsistent performance-wise?
    primarykey
    data
    text
    <p>I'm making a simple graphical app on OSX. I just started monitoring the frame rate by checking the difference in system time between frames. It seems to be hanging a bit every few frames.</p> <p>The app runs on an NSTimer object, currently set to 200 fps (5 ms frames). To make sure it wasn't just my main code being slow, I commented out the entire main loop, except for [self.context flushBuffer]; (and of course the frame-rate sampling code). Even repeating this single call is causing it to hang for several frames at a time. Here is an example of my console output:</p> <pre><code>4 5 6 10 5 5 5 4 6 10 5 5 5 5 5 5 20 4 5 6 20 5 5 5 </code></pre> <p>This is the time in milliseconds between each loop iteration. At 200 fps, it should be about 5 ms for each frame, but it repeatedly hangs for 10, 15, or even 20 ms. Vsyncing is disabled, as you can see in my -initOpenGL function.</p> <pre><code>-(void)initOpenGL{ NSOpenGLPixelFormatAttribute attributes[] = {NSOpenGLPFADoubleBuffer, 0}; NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes: attributes]; self.context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; [self.context setView:[self.window contentView]]; [self.context makeCurrentContext]; //Disable Vsync int temp = 0; [self.context setValues: &amp;temp forParameter: NSOpenGLCPSwapInterval]; glViewport(0, 0, windowWidth, windowHeight); glMatrixMode(GL_PROJECTION); glOrtho(0, windowWidth, 0, windowHeight, -1, 100); //Flip all textures right side up glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glEnable(GL_SCISSOR_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } </code></pre> <p><strong>Edit, new information: I can confirm that this has something to do with double-buffering vs single. When I initialize the NSOpenGLPixelFormat without the DoubleBuffer attribute, it runs perfectly at 200 fps. Whereas with that attribute, I continue to get the stuttering.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload