问题
I currently have code that does the following:
- sleep until next frame
glClear(GL_COLOR_BUFFER_BIT | GL_DPETH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);- perform all drawing for the frame
- flush and display drawing to screen
- 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