When is it OK not to use SDL_RenderClear ?

I think it’s mostly a case of use case. Ant mentioned doing a very CPU intensive ray traced game for mobile. In that case, you’re gonna need all the hacks you can get to make it run well. For such a game, profiling and seeing what works goes above anything documentation can tell you, and making it work is the highest priority. Sure, it might break in a future update. Sure, you’re gonna need some more work for platforms that don’t take well to those shenanigans, but if it’s worth it, it’s worth it!
Though if you’re making a game where those microseconds aren’t all that important compared to the development time needed to get it on new platforms, putting an SDL_RenderClear in there for ease of mind can’t hurt.

1 Like

The clear should be done by the GPU, which wouldn’t affect doing raytracing on the CPU at all. It’s possible the driver is doing something dumb, like having the GPU clear the tile buffer and the CPU clear the backbuffer.

But that’s the thing that sucks about OpenGL, there’s so much “magic” and hinting and trying to figure out why something that helps performance on one implementation kills it on another.

Thank you for getting it! :pray:

I need to squeeze every bit of FPS that I can, and removing SDL_RenderClear() does exactly that. If your app is locked at 60fps, you’re not going to see any change, but on lower-spec machines my FPS drops to 50. If I employed the kind of paranoia that most here do, I’d only get 1FPS out of my raytraced sandbox engine. Removing SDL_RenderClear() won’t break anything, worst case scenario (as others have said) it will cause a frame copy, which isn’t a massive performance hit. If something changes in the software drivers, then it would break many thousands of games that do the same - as you said, a lot of commercial games cause visual artefacts when you go out of bounds because you can see where they AREN’T clearing the screen.

Hmm, exaggeration doesn’t strengthen your argument! I don’t consider wanting to abide strictly by the API documentation as paranoia, I’d call it professionalism. :roll_eyes:

TL;DR - At the moment clearing the buffer isn’t necessary if you’re going to completely fill the frame, however it’s common practice and recommended by Apple on their platforms.

I think this discussion has completely exhausted its value for everyone. I’m going to mark it read-only now.

2 Likes