Why WebGL 'clear' draw to front buffer?

后端 未结 1 1127
情深已故
情深已故 2020-12-12 03:35

Why no need for swap-buffers or glFinish?



    
        Game v.0.0
        

        
相关标签:
1条回答
  • 2020-12-12 04:13

    Because that's the way WebGL works.

    WebGL swaps/copies automatically. Anytime you do anything that effects the WebGL drawingBuffer (think "backbuffer) it gets marked to swap/copy. The next time the browser composites the web page it will do either a swap or a copy. You can tell it to always copy. You can not tell it to always swap

    Specifically, creating the WebGL context with {preserveDrawingBuffer: true} as in

    gl = someCanvas.getContext("webgl", {preserveDrawingBuffer: true});
    

    Tells WebGL you always want it to do a copy.

    The default is WebGL chooses swap or copy depending on various factors. For example if anti-aliasing is on it's always effectively a copy (a resolve) where as if anti-aliasing is off it might be a swap. Also, in this default case, when preserveDrawingBuffer is false after it does a copy or swap it will clear the backbuffer. This is to try to make it appear consistent regardless of whether it chooses to copy or swap.

    If preserveDrawingBuffer = true then it never clears the backbuffer.

    If you want to do a bunch of work over multiple JavaScript events and not let the user see the results until all your work is done you'll need to render to a framebuffer with an attached texture or renderbuffer and then when all your work is done render than attachment to the canvas (the backbuffer).

    as for gl.finish that's a no-op in WebGL. It has no point.

    0 讨论(0)
提交回复
热议问题