Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering from WPF's internals to a Directx application

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.

like image 211
decaprime Avatar asked Apr 29 '12 21:04

decaprime


1 Answers

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.

like image 85
L. Vandendriessche Avatar answered Sep 26 '22 20:09

L. Vandendriessche