I am working through Lazy Foo’s tutorials and am seeing really poor performance with SDL2 on my MacBook Pro. I am doing what I thought to be a pretty simple program: create surface, create texture from surface, then call SDL_RenderCopy to display an image. I have tried setting the backend to both “opengl” and “metal” both with the same results.
As soon as I run my program, the GPU% spikes to 80+%, fans turn on, system overheats, and rest of my applications are very sluggish.
So I am trying to figure out: are there major performance issues with SDL2 and Metal? I tried setting the renderer hint to use “opengl”, but am observing the same problem. Interestingly, setting the renderer hint to “software” results in still poor performance, but better than “metal”.
I am using SDL version 2.0.12_1.
Any help would be appreciated, have spent the last several days trying to figure out what the problem is and have not been able to find a solution. At this point, this is kind of a deal-breaker for me to use SDL2 unless I can figure out what is going on. Does anyone out there have any experience running SDL2 programs on OS X?
Additional note: I tried running the game “Into the Breach” which I have read uses SDL on my machine and it seems to run fine, I don’t observe any of the same performance issues.
The simplest explanation would be that you have not specified the SDL_RENDERER_PRESENTVSYNC flag in your SDL_CreateRenderer() call; that would cause your program to spin continuously, using large amounts of CPU and GPU time. So I would check that flag first.
// call back again in ‘iIntervalInMilliseconds’ milliseconds
Calling SDL_WaitEvent lets the CPU sleep until an event occurs and then the code continues, but Lazy Foo’s example uses SDL_PollEvent which exits immediately so the CPU never sleeps. Don’t worry about your CPU activity right now (the code is actually telling your computer to blast the CPU!), just work your way through Lazy Foo’s examples to get the hang of SDL for now.