开发者

OpenGL on Windows uses Tons of CPU when SwapBuffers is called on a RenderThread

Ok, so I have been running into some threading iss开发者_运维知识库ues with OpenGL on Windows. I'm using C# .NET to wrap GL. I'm on Windows7 x64.

So ive tried two different tests. In each test i'm rendering a untextured quad(aka two triangles). The CPU hit seems to be related to SwapBuffers from what I can tell.

Single threaded test(This works fine)::

{
Draw stuff;
SwapBuffers;
Sleep(15);
}

RenderingThread test(This eats all my CPU)::

{
Draw stuff;
SwapBuffers;
//glFinish(); //<< If used this seems to make the CPU usage normal
Sleep(15);
}

I know this example is simplistic, but the real question is why does OpenGL suck all my CPU when calling SwapBuffers on a different thread other then the one the Windows GUI thread runs on?? And why does glFinish() seem to fix this? Everybody say's not to use glFinish, so i'm not sure what i'm doing wrong or if OpenGL just sucks on Windows...?

I run the same test on OSX, CPU seems normal. I run the same test with D3D9 & D3D10 on windows, CPU seems normal. Haven't tested on Linux as my L-box is down.


This issue is simply solved by doing:

glFlush();
glFinish();

Before calling::

wglSwapBuffers(dc); // Windows
glxSwapBuffers(dc, handle); // Linux
cglFlushDrawable(ctx); // OS X

Although drivers make a big difference with OpenGL on Windows, and Windows still performs far better with Direct3D.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜