Search code examples
iosopengl-esglkview

Performance issues with resizing GLKView.


I have a GLKView displaying CIFilter's CIImage. When I resizing the view frame by pinch gesture, I got low frame rate. What is the problem behind this? How can I fit it?


Solution

  • Due to how this API works it will probably create a new frame buffer when resizing. It would be possible to do this with a custom view so "Don't use GLKView" would be an answer. Still scaling a custom view bound to openGL would give a bad resolution when scaled to show zoom.

    You gave a bit too little information on what you are doing but in general it would seem something like using a scroll view with openGL. I have implemented such system by adding a scroll view on top of the drawn view and then listened to its interactions (did scroll, did zoom). Then I computed the visible rect of the scroll view content view and used the same rectangle in the openGL projection matrix. This is simply calling ortho with visible frame parameters.

    So in general you should not simply try to scale, zoom the view you render to as you will need a larger buffer. When a buffer is created from view it will be the same size as the view itself multiplied by the content scale you set (@2x, @3x). So when zooming you actually scale the view which should then resize to the new size which takes time. But if you do not resize it you will lose the resolution. So from what I have seen changing the projection matrix is the way to go and it is quite possible to transfer the data from the scroll view so you get all the bouncing effects and such.

    Just a note if you are already using a display link (keep redrawing the view regardless of interactions) then there is no need to listen to scroll view events. You simply fetch the visible rect of the scroll view on every frame you draw. This will strip down some code.