SFML community forums

Help => Graphics => Topic started by: upseen on November 01, 2013, 10:58:24 am

Title: [Solved] Is clear() that necessary?
Post by: upseen on November 01, 2013, 10:58:24 am
Hello,

I have a case where I fill up the entire screen, opaque pixels and all, at every frame, so I don't use clear() for the microscopic performance gain i could have?

Just wondering if this is alright since i might be missing something, if ever it's going to cause problems on others computers or something.

Thanks.
Title: Re: Is clear() that necessary?
Post by: Spans on November 01, 2013, 12:10:21 pm
Graphics cards/APIs are designed for the clear + draw + display loop, so there is no point leaving clearing out. You are getting close to nothing more performance, but things may get messy without clearing.
Title: Re: Is clear() that necessary?
Post by: wintertime on November 01, 2013, 02:12:19 pm
Yeah, the clear call may be optimized in many gpu to not do that equivalent of memset of gpu-memory you assume but just set a few bits to indicate its cleared. That means you wont get a performance win.

The bigger problem is there can be quirks in some gpu/drivers you wont imagine. For example I read there may be a few gpu doing tiled drawing(especially on mobile), where they first do all vertex processing for new data, then write all data of the frame back into memory by appending it to some kind of internal queue, then repeatedly do fragment processing for everything inside that queue for all screen tiles. When the clear call is done it would also empty that queue, but if you never call it that queue may get longer and longer keeping all the old data from previous frames...
Title: Re: Is clear() that necessary?
Post by: Laurent on November 01, 2013, 02:47:29 pm
Please read the available documentation before asking questions.

Quote from: tutorial
Calling clear before drawing anything is mandatory, otherwise you may keep undefined pixels from previous frames. The only exception is when you cover the entire window with what you draw, so that no pixel is left undrawn; in this case you can avoid calling clear (although it won't make a big difference on performances).
Title: Re: Is clear() that necessary?
Post by: upseen on November 01, 2013, 06:56:23 pm
^ I must have missed that part.

Thanks everyone! Sorry for the dumb question...