SDL Performance |
SDL Performance |
Gerry Jo Jellestad
Guest
|
Well, one thing you can do is optimize your surfaces for display with
SDL_DisplayFormat (or SDL_DisplayFormatAlpha if they've got alpha). Something like this: SDL_Surface *optimize (SDL_Surface *surf) { SDL_Surface *opt = SDL_DisplayFormat(surf); if (opt) { SDL_FreeSurface(surf); return opt; } return surf; } Just wrap your loads with that: img[0] = optimize(IMG_Load("big.png")); img[1] = optimize(IMG_Load("big2.png")); Another thing is that your fps code is a bit inaccurate. It includes everything like initial setup and loading, so if you don't run your example for a long time the framerate will be reported a bit lower than it really is. Better to calculate it directly: Uint32 start = SDL_GetTicks(); while (!quit) { ... } double fps = frames / ((SDL_GetTicks() - start) / 1000.0); Also, you don't enable optimization in your compiler invocation. Optimization probably won't hurt. Anyways, if you really want performance, you probably want hardware acceleration.. Hardware-accelerated OpenGL will always be faster than anything you can do in pure software. You can use it directly, or indirectly through something like SDL 1.3, for example. -g Den 15. okt. 2011 16:18, skrev Yuri David Santos:
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
SDL Performance |
Ryan C. Gordon
Guest
|
(The short answer is: this is the wrong way to do this. But if you
really want to do this with software surfaces, there is still room for improvement.)
Did you actually want a 16-bit surface? It's likely that you're not able to get this from the OS, so SDL is converting all your pixels on the fly...so you draw everything twice...once to the surface, and then again when SDL converts it to the format the OS wants. Specifying 0 ("take whatever the OS gives me by default") there may help here, since you don't actually require an array of 16-bit pixels for your work in this case.
Convert these surfaces to the screen format. Otherwise, every blit isn't a copy, but a possibly-expensive conversion. SDL_ConvertSurface() handles that.
Use a NULL instead of &rect. Some systems can (theoretically) optimize for clearing the whole surface this way. Also, if you're just going to draw over the entire surface with a 1280x800 png, don't clear it at all. All you're doing is drawing to pixels you're about to write over again anyhow.
Doing a software blit of a 1280x800 image is going to be slow in any case. The successful examples you listed are either using OpenGL, or they're not redrawing the whole screen every frame. Use OpenGL, upload those PNGs to a textures once, and draw a textured quad each frame, and it'll run at thousands of frames per second. --ryan. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||||
|
SDL Performance |
Yuri David Santos
Guest
|
Hi,
Gerry and Ryan, thank you for the tips, you solved my problem. I did the same tests, now using the SDL_ANYFORMAT flag and specifying 0 in the bit-dept parameter, and optimizing the surfaces with the SDL_DisplayFormatAlpha. The results was outstanding! - With only the SDL_SetVideoMode modifications the performance improved from about 17 FPS to 30 FPS. - With only the SDL_DisplayFormatAlpha modification it improved from 17 to 33 FPS. - And with both, it improved to amazing 97,28 FPS. - Tests with little images exceeded 360 FPS, without OpenGL. I know my timing method is not so accurate, but running the test for more than 20 seconds it gives a good average measure. Thanks! Problem solved! 2011/10/15 Ryan C. Gordon
-- Yuri David Santos Aleva - Soluções em Software www.aleva.com.br |
|||||||||||||||||||||
|