为什么RenderingContext.drawElements在绘制前清除屏幕? [英] Why is RenderingContext.drawElements clearing the screen before it draws?

查看:965
本文介绍了为什么RenderingContext.drawElements在绘制前清除屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当RenderingContext.drawElements在绘制之前清除屏幕时是否正确?



考虑这些屏幕截图,显示一个调用drawElements的步骤,已删除。



>




有效地在页面合成后清除屏幕。



如果你不希望它被清除,请求

  gl = someCanvas创建WebGL上下文时,code> preserveDrawingBuffer:true  .getContext(webgl,{preserveDrawingBuffer:true}); 

至于为什么,从规范


希望保留绘图缓冲区,它可能会导致在一些平台上显着的性能损失。只要有可能,这个标志应该保持假,并使用其他技术。诸如同步绘图缓冲器访问(例如,在呈现给绘图缓冲器的相同函数中调用readPixels或toDataURL)的技术可以用于获得绘图缓冲器的内容。如果作者需要通过一系列调用来渲染到相同的绘图缓冲区,那么可以使用Framebuffer对象。



实现可以优化掉所需的隐式清除操作绘图缓冲区,只要能保证作者不能从另一个进程访问缓冲区内容。例如,如果作者执行明确清除,则不需要隐式清除。


TL; DR版本为 preserveDrawingBuffer:false (默认)允许WebGL在合成时交换缓冲区(这不意味着它将交换缓冲区,但如果它选择,它可以)。 preserveDrawingBuffer:true 意味着它不能交换缓冲区,它必须复制缓冲区。复制比交换慢得多。


Is RenderingContext.drawElements correct when it clears the screen before it draws?

Consider these screenshots that show a step across a call to drawElements with the object already drawn being erased.

解决方案

WebGL effectively clears the screen after the page has been composited. When you're stepping through stuff one line at a time it's going to be composited every time you stop.

If you don't want it to be cleared ask for preserveDrawingBuffer: true when you create the WebGL context as in

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

As for why, from the spec

While it is sometimes desirable to preserve the drawing buffer, it can cause significant performance loss on some platforms. Whenever possible this flag should remain false and other techniques used. Techniques like synchronous drawing buffer access (e.g., calling readPixels or toDataURL in the same function that renders to the drawing buffer) can be used to get the contents of the drawing buffer. If the author needs to render to the same drawing buffer over a series of calls, a Framebuffer Object can be used.

Implementations may optimize away the required implicit clear operation of the Drawing Buffer as long as a guarantee can be made that the author cannot gain access to buffer contents from another process. For instance, if the author performs an explicit clear then the implicit clear is not needed.

The TL;DR version is preserveDrawingBuffer: false (the default) allows WebGL to swap buffers when compositing (that doesn't mean it will swap buffers but it can if it chooses to). preserveDrawingBuffer: true means it can't swap buffers, it must copy buffers. Copying is much slower than swapping.

这篇关于为什么RenderingContext.drawElements在绘制前清除屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆