PDA

View Full Version : Which is faster/better - glClearColor/glClear or glClearBuffer* ?



tmason
07-25-2014, 08:00 PM
Hello,

I have a quick question I am curious about.

I am used to using the combination of glClearColor + glClear to clear the color/depth buffers.

However I found another function, glClearBufferfv being one of them, which performs the exact same thing.

So I am curious to learn which practice is "better" or which should be used.

Is it just a stylistic difference or would there be a performance penalty, etc. on using one versus the other?

Thank you for your time!

Cornix
07-25-2014, 11:11 PM
I remember reading that you should always call glClear at least once a frame or modern graphics cards would drop in performance. I cant quite remember the article, but it had to do with certain optimizations that graphics cards do internally. Gl clear will tell them that a frame was finished and all internal information can be discarded since the next frame will begin shortly. Or something like that.

tmason
07-26-2014, 11:10 AM
I remember reading that you should always call glClear at least once a frame or modern graphics cards would drop in performance. I cant quite remember the article, but it had to do with certain optimizations that graphics cards do internally. Gl clear will tell them that a frame was finished and all internal information can be discarded since the next frame will begin shortly. Or something like that.

Thanks. From what I have been gathering on the internet they are functionally the same.

My curiosity stems from the fact that one may be faster than the other; it seems that once you have a particular color you want to clear to set glClear would be faster only because you are not sending four floats all of the time to specify the clear color like you would be doing with glClearBuffer*.

But, of course, I may be wrong.

Was just curious from the experts and experienced users what their real world experience has been.

Thank you.

Nikki_k
07-26-2014, 01:58 PM
Was just curious from the experts and experienced users what their real world experience has been.


In short: It doesn't matter.

You clear the framebuffer once each frame, in overall performance the difference is close to immeasurable. I think ultimately both functions use the same hardware functionality. As I see it, glClearBuffer is just a more versatile and user friendly interface than the somewhat clumsy glClear with its separate setter functions.

Dan Bartlett
07-26-2014, 02:12 PM
glClearBuffer allows you to clear the color attachments to different colors, or to only clear certain attachments. glClear clears every color attachment to the color specified by glClearColor.

glClear/glClearBuffer should be both able to return control fairly quickly without stalling OpenGL. For overall performance the 2 calls should be similar if you're clearing all color attachments. The main thing that will determine how much work needs to be done will be how large an area needs to be cleared.