Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Is clear() that necessary?  (Read 2095 times)

0 Members and 1 Guest are viewing this topic.

upseen

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
[Solved] Is clear() that necessary?
« 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.
« Last Edit: November 01, 2013, 06:56:51 pm by upseen »

Spans

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Is clear() that necessary?
« Reply #1 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.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Is clear() that necessary?
« Reply #2 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...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is clear() that necessary?
« Reply #3 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).
Laurent Gomila - SFML developer

upseen

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Is clear() that necessary?
« Reply #4 on: November 01, 2013, 06:56:23 pm »
^ I must have missed that part.

Thanks everyone! Sorry for the dumb question...