dengfan
Topic Author
Posts: 16
Joined: 19 Nov 2023, 10:32

opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

21 Nov 2023, 14:21

Hello, everyone:

I have tried multiple versions of native SDK + opengl on windows, integrated glud or glfw, x86 or x64, and finally the generated exe has a high CPU usage when it runs.

But after the other samples are compiled, the CPU usage is very, very low, most of the time 0%.

Why is that?
How do I fix this?
2023-11-21 211209.png
 
User avatar
jsantos
Site Admin
Posts: 3938
Joined: 20 Jan 2012, 17:18
Contact:

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

21 Nov 2023, 14:39

The IntegrationGLUT example is always using OpenGL while the other examples take by default Direct3D (you can override this with --render GL). For some reasons, your GL driver is disabling vsync, this could be the reason of high cpu usage. You can debug the source code of GLRenderContext, the Init() function take the boolean vsync for enabling vertical sync.
 
dengfan
Topic Author
Posts: 16
Joined: 19 Nov 2023, 10:32

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

22 Nov 2023, 08:26

The IntegrationGLUT example is always using OpenGL while the other examples take by default Direct3D (you can override this with --render GL). For some reasons, your GL driver is disabling vsync, this could be the reason of high cpu usage. You can debug the source code of GLRenderContext, the Init() function take the boolean vsync for enabling vertical sync.
After testing, it is indeed a problem with vsync.
I switched to GLFW,
add under line code,
glfwSwapInterval(1); 
and the problem was fixed.

Thanks very much!
 
User avatar
jsantos
Site Admin
Posts: 3938
Joined: 20 Jan 2012, 17:18
Contact:

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

22 Nov 2023, 19:22

Our GLUT implementation in the IntegrationGLUT sample is already doing:
typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT != 0)
{
    wglSwapIntervalEXT(1);
}
I assume this was not working on your machine?
 
dengfan
Topic Author
Posts: 16
Joined: 19 Nov 2023, 10:32

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

24 Nov 2023, 11:35

Our GLUT implementation in the IntegrationGLUT sample is already doing:
typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT != 0)
{
 wglSwapIntervalEXT(1);
}
I assume this was not working on your machine?
Yes, this didn't work under GLUT, so I switched to GLFW

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest