Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 tmason   Members   -  Reputation: 280

Like
0Likes
Like

Posted 25 July 2014 - 09:06 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!      



Sponsor:

#2 DaeryLee   Members   -  Reputation: 108

Like
0Likes
Like

Posted 26 July 2014 - 03:46 AM

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. 



#3 WiredCat   Members   -  Reputation: 324

Like
1Likes
Like

Posted 26 July 2014 - 09:45 AM

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



#4 tmason   Members   -  Reputation: 280

Like
0Likes
Like

Posted 26 July 2014 - 12:04 PM

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.



#5 tmason   Members   -  Reputation: 280

Like
0Likes
Like

Posted 26 July 2014 - 12:07 PM

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.



#6 swiftcoder   Senior Moderators   -  Reputation: 10060

Like
0Likes
Like

Posted 26 July 2014 - 01:21 PM

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, 26 July 2014 - 01:24 PM.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#7 tmason   Members   -  Reputation: 280

Like
0Likes
Like

Posted 26 July 2014 - 01:27 PM

 

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?



#8 swiftcoder   Senior Moderators   -  Reputation: 10060

Like
0Likes
Like

Posted 26 July 2014 - 01:55 PM

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 - Software Engineer @Amazon - [swiftcoding]


#9 tmason   Members   -  Reputation: 280

Like
0Likes
Like

Posted 26 July 2014 - 01:58 PM

 

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS