寻找比 GDI 更快的解决方案来渲染动态数据图

发布于 2024-07-25 22:57:53 字数 317 浏览 7 评论 0原文

我使用 C++/CLI 编写了一个简单的基于 GDI 的数据绘图仪,但它不是特别快(一些基本分析表明问题在于屏幕渲染)。

有没有办法为 UserControl 启用硬件加速,或者是否有用于 direct3D 的 .net 接口? ...或者我可以考虑其他一些选择。

我们使用托管代码,因此如果可能的话,解决方案确实需要与 CLI 兼容。

[编辑]如果有帮助,我正在使用Graphics::FillRectangle渲染矩形条(128个数据点),每个矩形都是2x2像素 - 也许有更好的方法这样做?

I've written a simple GDI-based data plotter using C++/CLI but it's not particularly fast (some basic profiling indicates it's the rendering to screen that's the problem).

Is there any way to enable hardware acceleration for a UserControl or is there a .net interface for direct3D? ...or are there some other options I could consider.

We're using managed code so the solution really needs to be CLI compatible if at all possible.

[Edit] In case it helps, I'm rending strips (128 data points) of rectangles which are each 2x2 pixels using Graphics::FillRectangle - maybe there's a better way of doing that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不语却知心 2024-08-01 22:57:53

托管 DirectX 已被弃用一段时间。 你真的不想用它。 相反,您应该使用 SlimDX,它是用 C++/CLI 编写的 DirectX SDK API 的开源互操作层。 它比 Managed DirectX 更好,并且得到开发人员专家社区的支持。 (我将很快与他们一起改进 DirectWrite 支持。)

Managed DirectX has been deprecated for some time. You really don't want to use that. Instead, you should use SlimDX which is an open source interop layer for the DirectX SDK APIs written in C++/CLI. It is better than Managed DirectX and is supported by an expert community of developers. (I'm going to be working on improving the DirectWrite support with them soon.)

嘿咻 2024-08-01 22:57:53

根据我的经验,使用 GDI+ 不会获得足够好的性能。 即使对于简单的绘图,您很快就会意识到有很多开销。

替代方案(正如您提到的)是 Direct3D,或者您可以考虑使用系统调用的常规 GDI 。 这显然使得代码依赖于平台,但速度可能相当快。 我用它取得了很好的效果。

这完全取决于您愿意处理的复杂程度。 一旦了解了基础知识,GDI 就会相对容易一些,而 Direct3D 则稍微复杂一些。 尽管 Direct3D 更适合未来。

From my experience, you won't get good enough performance out of using GDI+. Even for simple drawing, you will quickly realize that there's a lot of overhead.

Alternatives would (as you mentioned) be Direct3D, or you could consider regular GDI with system calls. That obviously makes the code platform dependent but it can be quite fast. I've had good results using that.

It all depends on how much complexity you're willing to deal with. GDI can be relatively easy once you figure out the basics, Direct3D is a bit more complex. Though Direct3D is more future proof.

一指流沙 2024-08-01 22:57:53

确实,GDI+ 在性能方面并不是很好,但是我自己在一个与工作相关的项目中编写了一个 GDI+ 绘图仪,它能够在 1680x1050 分辨率下以每秒约 30 帧的速度吐出具有数千个点的图表(滚动图表) )。

为了实现这一目标,需要进行大量的调整:

  • 在绘制之前将所有内容都转换为一条路径。
  • 如果使用后台缓冲区,请使用像素格式 Format32bppPArgb,这可以将位块传送速度加快 2-4 倍。
  • 如果绘制具有大量垂直线(高频信号)的路径,请将它们绘制为后台缓冲区上的水平线,然后绘制在屏幕上旋转的图像。 请注意,绘制旋转图像也有一定的成本。

我看不出你的场景需要大量优化,128 点数据根本不算什么。 将这些点放入一个 GraphicsPath 可以使但还是有区别的,因为这意味着更少的编组开销。

顺便问一下,我们在这里讨论的分辨率和帧速率是多少?

It is true that GDI+ isn't very good performance-wise, however I have myself written a GDI+ plotter in a work-related project that's able to spit out graphs with thousand of points at ~30 frames pr second at 1680x1050 resolution (scrolling graph).

It took a lot of tuning to achieve this:

  • Convert everything to one single path before drawing.
  • If using back-buffer, use one with pixel format Format32bppPArgb, this can speed up blitting 2-4x.
  • If drawing a path with a lot of vertical lines (high frequency signal), draw them as horizontal lines on a back buffer instead, and then draw the image rotated on the screen. Be aware that drawing an image rotated also have certain cost.

I can't see how your scenario requires a whole lot of optimization though, 128 points of data is nothing. Putting these points into one GraphicsPath could make a difference though, since that would mean less marshalling overhead.

What resolution and frame rate are we talking about here by the way?

汐鸠 2024-08-01 22:57:53

Microsoft 现在还有 Direct2D,它是硬件加速的 2D 绘图:

Direct2D 是一种硬件加速的、
立即模式、2D 图形 API
提供高性能和
高质量 2D 渲染
几何图形、位图和文本。 这
Direct2D API 旨在
与 GDI、GDI+ 和
Direct3D。

它需要 Windows 7/Server 2008 R2,但支持已通过 平台重新添加到 Vista/Server 2008更新

Microsoft now also has Direct2D, which is hardware accelerated 2D drawing:

Direct2D is a hardware-accelerated,
immediate-mode, 2-D graphics API that
provides high performance and
high-quality rendering for 2-D
geometry, bitmaps, and text. The
Direct2D API is designed to
interoperate well with GDI, GDI+, and
Direct3D.

It requires Windows 7/Server 2008 R2, but support has been back-added to Vista/Server 2008 through the Platform Update:

め可乐爱微笑 2024-08-01 22:57:53

当我使用 无线完成重定向数据流入时,我正在寻找类似的解决方案热值
EPD 用于为我的 PC 渲染图形文本。 我可能会从上面的评论中找到一种可能的方式。

应该注意的是,并非所有 2D 绘图操作都支持硬件加速,打开它可能会影响某些自定义视图或绘图调用。

I was looking for similar solution when I finishing redirecting data influx using my wireless thermo
EPD for rendering graphics text for my PC. I would probably find a way to fashion out possible way from the comments above.

It should be noted that hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your custom views or drawing calls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文