寻找比 GDI 更快的解决方案来渲染动态数据图
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
托管 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.)
根据我的经验,使用 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.
确实,GDI+ 在性能方面并不是很好,但是我自己在一个与工作相关的项目中编写了一个 GDI+ 绘图仪,它能够在 1680x1050 分辨率下以每秒约 30 帧的速度吐出具有数千个点的图表(滚动图表) )。
为了实现这一目标,需要进行大量的调整:
我看不出你的场景需要大量优化,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:
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?
Microsoft 现在还有 Direct2D,它是硬件加速的 2D 绘图:
它需要 Windows 7/Server 2008 R2,但支持已通过 平台重新添加到 Vista/Server 2008更新:
Microsoft now also has Direct2D, which is hardware accelerated 2D drawing:
It requires Windows 7/Server 2008 R2, but support has been back-added to Vista/Server 2008 through the Platform Update:
当我使用 无线完成重定向数据流入时,我正在寻找类似的解决方案热值
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.