MonoMac Application & OpenGL - Weird frame times

127 views Asked by At

I am trying to create an application with an OpenGL view using MonoMac. Setting up an application and an NSOpenGLView was fairly simple...

...but for some reason I cannot get a consistent frame rate rendering OpenGL. The issue I am having is that 9 out of ten frames have perfect performance and every tenth frame or so I am getting a massive frame time spike (about 60ms-80ms for a single frame). The time of the slow frame correlates with the size of the control (and even more so using retina backing buffer).

I have been digging and have come up with nothing that works for my case.

  • I tried to use NSOpenGLView with CVDisplayLink and rendering on the main thread with timers and DrawRect.
  • I tried MonoMacGameView also both versions. Actually MonoMacGameView has consistent performance but only draws when my window does not have a background color.
  • I reimplemented the run loop to do my own NextEvent polling just to find out that that is not the issue...

So, my current hunch is that it has something to do with layer backed rendering in Cocoa views but I really cannot figure out what is causing this.

Any hint as to what is causing this delay?

1

There are 1 answers

0
echom On BEST ANSWER

I found a solution which produces pretty good results:

  • Do not use NSOpenGLView or MonoMacGameView.
  • Use the approach described in the example on this page: http://cocoa-mono.org/archives/366/monomac-and-opengl/
  • To enable retina support export the ContentScale property on the deriving class and set that depending whether you are running on retina screen or not

In conclusion, using a core animation layer is the only viable solution.