通过 D3DImage 的 WPF 和 DirectX 11
我想在非托管 C++ 代码中使用 DirectX 11,并使用 WFP 作为 GUI。 SlimDX 不适合我。 我找到了使 WPF 与 DirectX 10 一起工作的解决方案:
但我无法在 DirectX 11 上使用它。只是带有两个按钮的空白屏幕。 有谁知道如何使 WPF 与 DirectX 11 一起工作。
此外,我还发现,当我刚刚运行此示例时,Intel i5 750(Windows 7 64 位、NVidia Geforce 430)的 CPU 使用率约为 4-5%。我认为这太多了..是否可以减少CPU使用率?
您可以在这里找到我的代码: http://www.gamedev .net/topic/619534-wpf-directx-11-via-d3dimage/
I want to use DirectX 11 from unmanaged C++ code and use WFP for the GUI. SlimDX is not suitable for me.
I have found the solution to make working WPF with DirectX 10:
But I couldn't manage to work it with DirectX 11. Just blank screen with two buttons.
Does anybody know how to make WPF working with DirectX 11.
Also I had seen that when I'm just running this example the CPU usage is about 4-5% for Intel i5 750 (Windows 7 64 bit, NVidia Geforce 430). I think it's too much.. Is it possible to decrease CPU usage ?
You can find my code here: http://www.gamedev.net/topic/619534-wpf-directx-11-via-d3dimage/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对顶点缓冲区布局使用了错误的格式。我使用了 DXGI_FORMAT_B8G8R8A8_UNORM,但在我的情况下必须使用 DXGI_FORMAT_R32G32B32_FLOAT。
I used wrong format for the vertex buffer layout. I used DXGI_FORMAT_B8G8R8A8_UNORM, but have to use DXGI_FORMAT_R32G32B32_FLOAT in my case.
您错过了对 D3DImage.AddDirtyRect 的调用。使用 Direct3D11 渲染场景后,您需要告诉 WPF 有一个新图像可供显示。为此,您需要执行以下操作,其中 d3dimage 是您的 D3DImage 实例:
这需要在每一帧中完成。
有关 AddDirtyRect 的其他信息
You're missing a call to D3DImage.AddDirtyRect. After you render your scene with Direct3D11, you need to tell WPF that there is a new image ready to be shown. To do that, you perform the following, where d3dimage is your D3DImage instance:
This needs to be done each frame.
Additional info about AddDirtyRect
我无法评论如何使 DirectX11 与该示例一起工作,但您看到的 5% CPU 可能是 DirectX 旋转中的渲染循环,但没有任何工作可做。
渲染循环通常在游戏中用于“尽可能快地”渲染,同时在不同线程上更新场景/物理/AI。在桌面可视化应用程序中,这通常是不必要的。
对于仅在用户交互(例如拖动项目、平移视口)时才发生 GUI 更新的科学可视化应用程序,我重新设计了渲染循环,使其仅在有更新时渲染。即:在 mousemove 中平移视口后,您可以通过设置标志或类似的方式强制 DirectX 重新绘制。这种“需要时绘图”的方式会在应用程序空闲时将您的 CPU 降低到接近于零,更适合桌面应用程序。
I can't comment on how to make DirectX11 work with that example, but the 5% CPU you are witnessing is probably the render loop in DirectX spinning but with no work to do.
A render loop is commonly used in games to render "as fast as you can" while updating the scene/physics/AI on a different thread. In desktop visualization applications this is not usually necessary.
For scientific visualization applications where updates to the GUI only occur when the user interacts (e.g. drags an item, pans the viewport) I've redesigned the render loop to only render when there is an update. ie: after your work to pan the viewport within mousemove, you force DirectX to re-draw by setting a flag or similar. This way "drawing when you need it" will reduce your CPU to near zero while the application is idling and is more suitable for desktop applications.