将像素写入d3d rendertarget曲面

时间:2019-05-26 07:46:13

标签: wpf directx sharpdx skiasharp

我有一个WPF应用程序,其中D3DImage作为用于渲染某些东西的画布。 D3DImage接受IDirect3DSurface9。我已经使用SharpDX创建了它:

//Create d3d surface
_d3d = new Direct3D();
var windowHandle = new WindowInteropHelper(Window.GetWindow(this)).Handle;
var presentationParams = new PresentParameters(1, 1);
_d3dDevice = new Device(_d3d, 0, DeviceType.Hardware, windowHandle, CreateFlags.HardwareVertexProcessing, presentationParams);
_d3dSurface = Surface.CreateRenderTarget(_d3dDevice, size.Width, size.Height, Format.A8R8G8B8, MultisampleType.None, 0, true);

//Set it to image
_d3dImage = new D3DImage(96, 96);
_d3dImageRect = new Int32Rect(0, 0, size.Width, size.Height);
_d3dImage.Lock();
_d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, _d3dSurface.NativePointer);
_d3dImage.AddDirtyRect(_d3dImageRect);
_d3dImage.Unlock();

这很好用,但是我们的引擎使用SkiaSharp渲染画布,仅支持OpenGL。我们正在向SKSurface渲染某些内容,并希望将像素从SKSurface读取到d3dSurface。

var surface = SKSurface.Create(GrContext, false, info)
// draw something
var rect = _d3dSurface.LockRectangle(LockFlags.None);
surface.ReadPixels(rect.DataPointer);
_d3dSurface.UnlockRectangle();

但是这不起作用,因为我们无法锁定RenderTarget曲面。 那么,有什么可行的方法可以将原始像素数据绘制到d3d表面?

0 个答案:

没有答案