-
I'm trying to use Silk.NET in place of SharpDX to capture the screen as video. I'm following Microsoft tutorial to do this. However, I'm stuck on a generating a Texture2D from a Windows.Graphics.DirectX.Direct3D11.IDirect3DSurface Here's the SharpDX code to do so as provided by Microsoft which runs fine. internal static Guid ID3D11Texture2D = new Guid("6f15aaf2-d208-4e89-9ab4-489535d34f9c");
[Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible(true)]
interface IDirect3DDxgiInterfaceAccess
{
IntPtr GetInterface([In] ref Guid iid);
};
public static class Helper(){
internal static SharpDX.Direct3D11.Texture2D CreateSharpDXTexture2D(IDirect3DSurface surface)
{
var access = (IDirect3DDxgiInterfaceAccess)surface;
var d3dPointer = access.GetInterface(ID3D11Texture2D);
var d3dSurface = new SharpDX.Direct3D11.Texture2D(d3dPointer);
return d3dSurface;
}
} My attempt to translate it to Silk.NET is as follow: [Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible(true)]
interface IDirect3DDxgiInterfaceAccess
{
IntPtr GetInterface([In] ref Guid iid);
};
public static class Helper(){
public static ComPtr<ID3D11Texture2D> Texture2DFromSurface(IDirect3DSurface surface)
{
var access = surface.As<IDirect3DDxgiInterfaceAccess>();
IntPtr pUnknown = access.GetInterface(ID3D11Texture2D.Guid);
var t = new ID3D11Texture2D((void**)pUnknown.ToPointer());
return &t;
}
} this code however results in an exception.
I haven't work with CSharp at this level before 😅 so I'm sure if this is the right way to turn the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Fun use case! I'll try and get IDirect3DDxgiInterfaceAccess exposed for Tuesday's update (and get you a working copy of the code :)) |
Beta Was this translation helpful? Give feedback.
I've had a look at this, and will add IDirect3DDxgiInterfaceAccess in 2.18. However, I won't add any other WinRT APIs like GraphicsCapture primarily because 2.X isn't currently in a fit state for WinRT. I recommend using those APIs through CsWinRT for now.
Your error is here:
You should do
instead.
ID3D11Texture2D
in Silk.NET is a structure wrapping avoid**
.Note that this will also add a ref so watch out for memory leaks!