• Advertisement
Sign in to follow this  

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

This topic is 1277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!      

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. Edited by swiftcoder

Share this post


Link to post
Share on other sites

 

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement