使用SDL + OpenGL实现高CPU使用率(High CPU usage with SDL + OpenGL)

编程入门 行业动态 更新时间:2024-10-28 19:33:05
使用SDL + OpenGL实现高CPU使用率(High CPU usage with SDL + OpenGL)

我有一个现代CPU(AMD FX 4170)和一个现代GPU(NVidia GTX 660)。 然而,这个简单的程序设法完全使用我的CPU核心之一。 这意味着它使用一个4.2 GHz核心在60 FPS下不抽取任何东西 。 这个程序有什么问题?

#include <SDL/SDL.h> int main(int argc, char** argv) { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_SetVideoMode(800, 600, 0, SDL_OPENGL | SDL_RESIZABLE); while(true) { Uint32 now = SDL_GetTicks(); SDL_GL_SwapBuffers(); int delay = 1000 / 60 - (SDL_GetTicks() - now); if(delay > 0) SDL_Delay(delay); } return 0; }

I have a modern CPU (AMD FX 4170) and a modern GPU (NVidia GTX 660). Yet this simple program manages to fully use one of my CPU's cores. This means it uses one 4.2 GHz core to draw nothing at 60 FPS. What is wrong with this program?

#include <SDL/SDL.h> int main(int argc, char** argv) { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_SetVideoMode(800, 600, 0, SDL_OPENGL | SDL_RESIZABLE); while(true) { Uint32 now = SDL_GetTicks(); SDL_GL_SwapBuffers(); int delay = 1000 / 60 - (SDL_GetTicks() - now); if(delay > 0) SDL_Delay(delay); } return 0; }

最满意答案

事实证明,NVidia的驱动程序实现了等待使用繁忙循环的vsync,导致SDL_GL_SwapBuffers()使用100%CPU。 从NVidia控制面板关闭vsync会消除此问题。

It turns out that NVidia's drivers' implement waiting for vsync with a busy loop which causes SDL_GL_SwapBuffers() to use 100 % CPU. Turning off vsync from NVidia Control Panel removes this problem.

更多推荐

本文发布于:2023-07-30 13:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:使用率   OpenGL   SDL   CPU   usage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!