从WPF内部渲染到Directx应用程序 [英] Rendering from WPF's internals to a Directx application

查看:455
本文介绍了从WPF内部渲染到Directx应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,用于在直播流中覆盖HUD.最初的想法是为xsplit(用于显示实时流的流行应用程序)创建一个插件,以显示WPF应用程序的内容.这种方法的问题在于,将位图呈现到xsplit的COM接口上不会损害释放应用程序的CPU性能(我相信xsplit的COM接口以及使用RenderTargetBitmap会对CPU造成负担).

我一直在考虑直接将叠加层渲染到游戏(目标DirectX应用程序)中,因为它具有许多优点.首先,它避免了xsplit的性能问题,但同时也将应用程序开放给各种流和捕获应用程序.


我对DirectX不太了解,但是我认为这是解决方案的概述

  1. 初始化WPF应用程序并捕获WPF的Direct3d设备解决方案

我正在尝试做同样的事情.到目前为止,我发现您可以将wpfvisualtree渲染为位图,然后将点2捕获的d3d设备写入位图.

void render(Direct3D.Device device)
{

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

}

我尚未对此进行测试,但是我认为我在此方面是正确的.我现在唯一的问题是我从窗口中删除了所有交互性.按钮点击等将不再被捕获...

任何帮助都很好.

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.

解决方案

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.

这篇关于从WPF内部渲染到Directx应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆