Rendering from WPF's internals to a Directx application

て烟熏妆下的殇ゞ 提交于 2019-12-12 07:57:41

问题


I have a WPF application that is intended for overlaying a HUD in a live stream. The original idea was to create a plugin for xsplit (a popular application for presenting live streams) to display the content of the WPF application. The problem with this approach is that rendering a bitmap to the COM interface of xsplit is far to damaging in CPU performance to release the application (As I believe there are issues in xsplit's COM interface as well as using RenderTargetBitmap taxing the CPU).

I've been looking at directly rendering the overlay into the game (The target DirectX application) because it provides a number of benefits. Chiefly it circumvents the performance problems in xsplit, but also opens the application up to a variety of streaming and capture applications.


I'm not a very experienced with DirectX but I think this is the outline of the solution

  1. Initialize the WPF application and capture WPF's Direct3d device (via this method)

  2. Find and hook the target DirectX application's EndScene call (using EasyHook+Slimdx)

  3. Render contents of the WPF Device's surface ontop of hooked DirectX application


The main question I have is how to accomplish step 3 using SlimDX. I'd hope a solution could somehow reuse the surface and not rely on copying as the goal is to not impact the performance of the hooked application. I'd also like to be able to limit the region and support transparency. I am also wondering if using WPF's Direct3d device in the hooked DirectX application's device might cause any instabilities.

Any insight would be appreciated, thank you.


回答1:


I'm trying to do the same. What I've found so far is that you can render your wpfvisualtree to a bitmap and afterwards write is bitmap to the d3d device captured in point 2.

void render(Direct3D.Device device)
{

wpfRenderTargetBitmap.Render(WpfVisualTree);
wpfRenderTargetBitmap.CopyPixels(devicePtr);

}

I didnt test this yet but I think I'm on the right track with this. The only problem I now have is that I loose all interactivity from my window. Button clicks and so on will no longer be captured...

Any help on that would be nice.



来源:https://stackoverflow.com/questions/10376016/rendering-from-wpfs-internals-to-a-directx-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!