Is it better to glClear() before drawing to a buffer or after?

微笑、不失礼 提交于 2019-12-24 18:07:58

问题


I currently have code that does the following:

  1. sleep until next frame
  2. glClear(GL_COLOR_BUFFER_BIT | GL_DPETH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  3. perform all drawing for the frame
  4. flush and display drawing to screen
  5. sleep until next frame (again)

My question is: should the clear (2) be moved to happen after step 4?

This order is nice because it's easier to prep a render buffer for rendering conceptually, like putting primer on a canvas, as opposed to cleaning the render buffer up afterwards. But I'm worried the GPU might get stuck on each clear and delay the drawing commands immediately after it, meaning it should be used when the GPU has nothing to do yet, like right before waiting for the next frame to begin.

Best case scenario: This order is fine and I'm being paranoid, glClear() doesn't delay other opengl drawing commands in any meaningful way.

Worst case scenario: glClear() is best called after a frame is rendered, where there's downtime for it to work since no other opengl commands are queued up yet.

来源:https://stackoverflow.com/questions/56607177/is-it-better-to-glclear-before-drawing-to-a-buffer-or-after

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!