Direct2D 是否使用后备缓冲区?
阅读 https://learn.microsoft.com /en-us/windows/win32/direct2d/comparing-direct2d-and-gdi :
演示模型
当Windows 最初设计的时候,还不够 内存允许每个窗口 存储在自己的位图中。因此, GDI 总是直接逻辑渲染 到屏幕上,进行各种剪辑 地区申请以确保它做到了 不在其窗口之外渲染。在 契约,Direct2D 遵循模型 应用程序渲染到的位置 后台缓冲区,结果是 原子地“翻转”时 应用程序已完成绘制。这 允许 Direct2D 处理动画 场景比 GDI 更加流畅 可以。
作者说 Direct2D 使用后台缓冲区,我猜他所说的“翻转”是指交换链。我创建了一个简单的演示,通过单击鼠标在随机位置绘制一个矩形。但是之前的矩形没有被清除,所以看起来它是直接绘制到屏幕上并且不使用任何后台缓冲区。
Reading https://learn.microsoft.com/en-us/windows/win32/direct2d/comparing-direct2d-and-gdi :
Presentation Model
When Windows was
first designed, there was insufficient
memory to allow every window to be
stored in its own bitmap. As a result,
GDI always rendered logically directly
to the screen, with various clipping
regions applied to ensure that it did
not render outside of its window. In
contract, Direct2D follows a model
where the application renders to a
back-buffer and the result is
atomically “flipped” when the
application is done drawing. This
allows Direct2D to handle animation
scenarios much more fluidly that GDI
can.
The author says Direct2D uses back-buffer and by 'flipped' he meant swap-chain I guess. I created a simple demo that draw a rectangle at random location on mouse click. But previous rectangles are not cleared so it seems that it is drawn directly to the screen and does not use any back-buffer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您为 Direct2D 操作初始化 RenderTarget 时,您可以在第二个参数中指定 D2D1_PRESENT_OPTIONS 选项。
我认为让您感到困惑的是 D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS 以及缓冲区没有被交换而是被复制的事实。
When you initialize the RenderTarget for your Direct2D operations you can specify in the second parameter the D2D1_PRESENT_OPTIONS option.
I think what confuses you is the D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS and the fact that the buffer isn't swapped but copied.
这并不反驳后台缓冲区的存在,它仅意味着后台缓冲区在重绘之间不会被清除。正确的观察,错误的结论!
如果增加链中后台缓冲区的数量,当您继续单击时,您将开始注意到闪烁的矩形,因此您应该始终在重绘之间清除后台缓冲区。
That doesn't disprove the existence of back-buffers, it only means the back-buffer isn't cleared between redraws. Right observation, wrong conclusion!
If you increase the number of back-buffers in the chain, you'll start noticing flickering rectangles as you keep clicking, so you should always clear your back-buffer between redraws.
Direct2D 确实使用后备缓冲区。
也许您忘记在调用 begindraw 之后立即清除渲染目标(即后台缓冲区),因此之前的绘制仍保留在那里?
Direct2D indeed uses back-buffer.
Perhaps you forgot to clear your render target, which is the back-buffer, right after calling begindraw and so previous draws stayed there?