Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

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

  1. #1
    Intern Contributor
    Join Date
    Apr 2014
    Posts
    67

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

    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!

  2. #2
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    89
    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.

  3. #3
    Intern Contributor
    Join Date
    Apr 2014
    Posts
    67
    Quote Originally Posted by Cornix View Post
    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.

  4. #4
    Intern Contributor
    Join Date
    Mar 2014
    Posts
    50
    Quote Originally Posted by tmason View Post
    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.

  5. #5
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •