Multithreaded video rendering in OpenGL on Mac shows severe flickering issues

你说的曾经没有我的故事 提交于 2019-12-03 20:14:08
Viktor Latypov

From what I see (namely the glPushMatrix calls etc.) I assume you are using not the latest hardware and quite possible you are running into the issues with older videocards, like this with the CGLFlushDrawable Why is CGLFlushDrawable so slow? (I am using VBOs).

The second thing you said is the YUV->RGB shader which obviously access the source texture many times and this must be slow on any videocard, especially the older one. So the large timings for the glDrawArrays() call actually reflect the fact that you're using a very heavy shader program (in terms of memory access), even when the shader code might look "innocent".

The shader code accesses the texture (and thus system's RAM) and it is in terms of performance (for this videocard) the same as doing the RAM->VRAM copy.

General advice: try avoiding non-rectangular and non-power-of-two textures. This can also kill the performance. Any non-standard texture formats and extensions should be avoided also. The simpler - the better. Try using something like 2048x1024 texture or 2048x2048, if you really need the FullHD resolution (by the way, this should be slow by pure arithmetics).

Ok, after a lot more testing and research, I finally managed to solve my problems:

What happened was that first I tried to write to the target texture using a framebuffer (bound to that texture with glFramebufferTexture2D as color attachment 0), and in the same frame then tried to read from it when rendering the frame to the window framebuffer.

Basically I wrongly assumed that (being called in the same frame, and directly in succession of each other) the first call would finish writing to the framebuffer, before the next call would read from it. Therefore a call to glFlush (for the class using the VDADecoder) and a glFinish (for the class using the software decoder) did the trick.

On a sidenote: As indicated in the comments above, I changed my whole code so it doesn't user the fixed pipeline anymore, and to make it look cleaner. Performance tests under OpenGL Profiler (under Mac OS X 10.7) have shown that the changes from my original code to the current code have reduced the time OpenGL used of the total application time from almost 50% down to about 15% (freeing up more resources for the actual video decoding - in the case a VDADecoder object is not available).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!