Ok, so I have been running into some threading issues 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With