Which is faster/better - glClearColor/glClear or glClearBuffer* ?

Started by
7 comments, last by tmason 9 years, 9 months ago

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!

Advertisement

Hey !

glClear/glClearColor resets the (bound/unbound) buffers to their preset value.

glClearBuffer resets the currentlly bound Buffer to a value you like

so if your scene has dynamic changing buffers i would stick to glClearBuffer.

glClearCOlor does not clear anything

The glClearColor function specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values specified by glClearColor are clamped to the range [0,1].

https://www.opengl.org/sdk/docs/man/html/glClearColor.xhtml

http://msdn.microsoft.com/en-us/library/windows/desktop/dd318377(v=vs.85).aspx

glClearCOlor does not clear anything

The glClearColor function specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values specified by glClearColor are clamped to the range [0,1].

https://www.opengl.org/sdk/docs/man/html/glClearColor.xhtml

http://msdn.microsoft.com/en-us/library/windows/desktop/dd318377(v=vs.85).aspx

I understand the glClearColor itself doesn't clear anything; in my original post I specify glClearColor + glClear because I know you essentially use glClearColor to set the color and glClear to perform the actual clearing.

That may not be the most technical explaination but in theory that is what happens.

Hey !

glClear/glClearColor resets the (bound/unbound) buffers to their preset value.

glClearBuffer resets the currentlly bound Buffer to a value you like

so if your scene has dynamic changing buffers i would stick to glClearBuffer.

OK, so it seems like functionally they are identical but is there a difference in speed? In theory it seems like glClear is faster because you are only clearing and not setting any values.

I was searching around and I found this post: http://www.gamedev.net/topic/646400-speed-up-glclearbuffer/

I just wanted to know what others' real world experience was (as well as get opinions from those more experienced than myself).

Thanks again.

In theory it seems like glClear is faster because you are only clearing and not setting any values

You are setting values - clearing a buffer just means setting each pixel to a pre-defined value.

In particular, you are setting the buffer to the values provided to glClearColor(...) for GL_COLOR_BUFFER_BIT, and the value provided to glClearDepth(...) for GL_DEPTH_BUFFER_BIT (and so on for other buffer types).

I was searching around and I found this post: http://www.gamedev.net/topic/646400-speed-up-glclearbuffer/

I'd take that topic with a liberal pinch of salt. It's not clear whether the measurements were accurate (glFinish is not a good way to take GPU-side timings), nor whether the operations as specified were actually equivalent.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

In theory it seems like glClear is faster because you are only clearing and not setting any values

You are setting values - clearing a buffer just means setting each pixel to a pre-defined value.

In particular, you are setting the buffer to the values provided to glClearColor(...) for GL_COLOR_BUFFER_BIT, and the value provided to glClearDepth(...) for GL_DEPTH_BUFFER_BIT (and so on for other buffer types).

I was searching around and I found this post: http://www.gamedev.net/topic/646400-speed-up-glclearbuffer/

I'd take that topic with a liberal pinch of salt. It's not clear whether the measurements were accurate (glFinish is not a good way to take GPU-side timings), nor whether the operations as specified were actually equivalent.

Thank you; so essentially they are functionally and performance wise identical, correct?

Thank you; so essentially they are functionally and performance wise identical, correct?

They are not strictly speaking equivalent. As far as I can tell, glClearBuffer is intended for clearing framebuffer attachments, and the fact that it can be used to clear the backbuffer is just a side-effect of the standard's use of framebuffer 0 as the backbuffer.

In general, I doubt there's enough difference in the backbuffer case to warrant not just sticking to glClear.

If you are dealing with framebuffer attachments, then glClearBuffer gives you the additional ability to only clear specific attachments (which you can't do using glClear).

And if you really want to get into the ins and outs of performance here, you should benchmark both of these methods against ARB_clear_texture.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Thank you; so essentially they are functionally and performance wise identical, correct?

They are not strictly speaking equivalent. As far as I can tell, glClearBuffer is intended for clearing framebuffer attachments, and the fact that it can be used to clear the backbuffer is just a side-effect of the standard's use of framebuffer 0 as the backbuffer.

In general, I doubt there's enough difference in the backbuffer case to warrant not just sticking to glClear.

If you are dealing with framebuffer attachments, then glClearBuffer gives you the additional ability to only clear specific attachments (which you can't do using glClear).

And if you really want to get into the ins and outs of performance here, you should benchmark both of these methods against ARB_clear_texture.

Thanks again for the in-depth response; I'll do a benchmark.

This topic is closed to new replies.

Advertisement