web - 为什么 RenderingContext.drawElements 在绘制之前清除屏幕?

标签 web three.js dart webgl dart-html

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

考虑这些屏幕截图,这些屏幕截图显示了调用 drawElements 的一个步骤,其中已绘制的对象被删除。

enter image description here

enter image description here

最佳答案

WebGL 在页面合成后有效地清除屏幕。当您一次一行地浏览内容时,每次停止时都会对其进行合成。
如果您不希望它被清除,请询问 preserveDrawingBuffer: true当您创建 WebGL 上下文时

gl = someCanvas.getContext("webgl", { preserveDrawingBuffer: true });
至于为什么,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.


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

关于web - 为什么 RenderingContext.drawElements 在绘制之前清除屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27812153/

相关文章:

flutter - 如何在flutter(dart)中创建函数列表/调用函数的列表

css - 添加其他 div 时,标题 div 会更改其位置

javascript - 是否可以在 html 文本字段中显示图像?

html - 如何在 Vue.js 中将日期选择器的下拉面板置于顶部?

javascript - Three.js - 如何修改ArrowHelper的宽度

Flutter 等价于新版本 Riverpod 中的 useProvider

升级后 Flutter 不再工作

javascript - 过滤并保存 HAR 文件

javascript - 三个 js 通过 GUI 防止光线转换拾取

ios - Safari 在 Three.js 中使用 webgl 的局限性