Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 922
zezba9000 Avatar asked May 14 '11 03:05

zezba9000


1 Answers

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.

like image 110
zezba9000 Avatar answered Oct 13 '22 10:10

zezba9000