Direct2D - 保留现有内容并覆盖新值 [英] Direct2D - preserve the existing content and overwrite the new values
问题描述
我计划为我的应用程序开发 XY 绘图仪.为了给出一些基本的想法,它应该是什么样子(当然实现会有所不同),请参考 此处 和此处.
I am planning to develop a XY Plotter for my application. To give some basic idea, how it should look like (of course the implementation would be different), please refer here and here.
在模拟过程中(假设完成模拟需要 4 小时),在固定的 X 轴上,新的 Y 值应该(覆盖).
During the simulation (let's assume, it takes 4 hours to complete the simulation), on a fixed X axis, the new Y values should be (over)written.
但是,Direct2D 的问题在于,每次调用 pRenderTarget->BeginDraw()
时,都会删除现有的绘图(/Plot/BitMap/Image 等)并生成一个新图像正在绘制.因此我会失去旧的价值观.
But, the problem with Direct2D is that, every time pRenderTarget->BeginDraw()
is called, the existing Drawing(/Plot/BitMap/Image, etc) is deleted and a new image is being drawn. Therefore I would lose the old values.
当然,我总是可以在缓冲区/变量中缓冲旧的 Y 值,并在下一个绘图中使用它.但是,模拟运行了 4 个小时,不幸的是我无法保存所有的 Y 值.这就是为什么我需要在现有的目标图像/绘图/等上渲染/绘制新的 Y 值.
Of course, I can always buffer the old Y values in a buffer/variable and use it in the next drawing. But, the simulation runs for 4 hours and unfortunately I can't afford to save all the Y values. That's why, I need to render/draw the new Y values on the existing target-image/plot/etc.
而且,如果在一定时间内不调用 pRenderTarget->EndDraw()
,我的应用程序将因资源限制而崩溃.
And, If don't call pRenderTarget->EndDraw()
within a definite amount of time, my application would crash due to resource constraints.
如何防止这个问题并达到要求?
How do I prevent this problem and achieve the requirement?
推荐答案
您要问的是一个相当复杂的要求 - 它比看起来更困难!Direct2D 是一个 立即模式绘图API.您在即时模式图形中绘制到屏幕上的内容没有状态维护或持久性.
What you're asking is quite a complex requirement - it's more difficult than it appears! Direct2D is an Immediate-Mode drawing API. There is no state maintenance or persistence of what you have drawn to the screen in immediate mode graphics.
在大多数即时模式图形 API 中,都有裁剪和脏矩形的概念.在 Direct2D 中,您可以使用这三种技术之一来绘制屏幕的子集.将屏幕外渲染到位图和双缓冲可能是一个很好的尝试技术.例如你的流程变成:
In most immediate-mode graphics APIs, there is the concept of clipping and dirty rects. In Direct2D you can use one of these three techniques to draw to a subset of the screen. Rendering offscreen to bitmap and double-buffering might be a good technique to try. e.g. your process becomes:
- 绘制到离屏位图
- 点阵位图到屏幕
- 在新数据上,绘制到新位图/与现有位图结合
只有当您添加新数据/绘图时,您的绘图没有滚动或更改比例时,此技术才有效.
This technique will only work if your plot is not scrolling or changing in scale as you append new data / draw.
这篇关于Direct2D - 保留现有内容并覆盖新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!