Can a DirectX surface be plotted to a WPF control?
Asked Answered
F

2

7

Can DirectX be used to plot a set of points on a WPF control (or something that can be used by WPF).

I need to implement a control in WPF that should plot 16k points with an update rate of 30 Hz, and i'm running out of solutions rigth now.

This idea is from a comment in this question.

Any help would be very appreciated.

Footless answered 9/9, 2011 at 4:42 Comment(3)
Is D3DImage what you're after? msdn.microsoft.com/en-us/library/…Dippold
@Dippold i'm really don't know, i have been reading all the docs about D3DImage, and it seems to fit. But how to draw on that control the set of points??Footless
I'm no expert. You probably want to start here: msdn.microsoft.com/en-us/library/cc656785.aspx. In general, I think you need a native DLL to render the DX content (or use a managed wrapper like SlimDX), and then you Lock/SetBackBuffer etc on the D3DImage objectDippold
R
6

Yes it can. It's usually quite smooth, because WPF itself is an implementation of DirectX.

See MS' Greg Schechter blog:

Redirecting GDI, DirectX, and WPF applications

You can also have a sample of D3DImage on a surface on WPF from Codeproject: http://www.codeproject.com/KB/WPF/D3DImage.aspx

Republic answered 9/9, 2011 at 9:34 Comment(1)
Updated link learn.microsoft.com/en-us/archive/blogs/greg_schechter/…Bedcover
E
1

Yes. You use D3DImage, Texture (SharpDX or SlimDX) and Surface. You need create texture outside your application and update its conent by video driver or by another way. In WPF you create D3DImage:

Texture = new Texture(Device.DeviceEx, width, height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default, ref handle);

Very important is that you foram must be Format.A8R8G8B8 (it is restriction of WPF):

using (var surface = texture.GetSurfaceLevel(0))
        {
            var handle = surface.NativePointer;
            Lock();
                SetBackBuffer(D3DResourceType.IDirect3DSurface9, handle);
                Unlock();
        }

And after each updating of frame you need only

Lock();
                AddDirtyRect(new Int32Rect(0, 0, PixelWidth, PixelHeight));
                Unlock();

It's better, if you will put your D3DImage in separate Dispatcher

Embattle answered 23/11, 2018 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.