-
I have written a graphics API that uses Direct3D 11.x (via SharpDX), and currently it uses Windows Forms to interact with the swap chain. This API also has an editor application that is entirely built in Windows Forms. Because of this, I'm tied to .NET Framework 4.x. I am aware that .NET 5/Core 3.1 "supports" WPF/WinForms, but that support is... well... it's crap so far (at least where designers are concerned). So, I would like to jump to .NET 5 and I've done some preliminary work on this and the performance gains were impressive even with no code changes. However the UI stuff has proven to be a painful challenge. I could jump to WPF and I have a WPF interop layer, but there are limitations that are imposed by WPF, and it introduces stuttering when rendering. It's not ideal at all. So, I'm looking into other UI frameworks and Avalonia comes up a lot as a good alternative for UI on .NET 5/Core. So, to my question: Am I able to integrate Direct3D with Avalonia? More specifically, can I assign a swap chain to a control? Just as a note: I have dug through the repo and I saw an interop sample there, but from the issues list, I saw that it no longer works properly (Issue #2024). But that was so long ago that things may have changed? TLDR: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 17 replies
-
Short answer: yes, that's possible, but requires tinkering with Skia and ANGLE
Obviously the 3rd step is the hardest one. var egl = (EglPlatformOpenGlInterface)AvaloniaLocator.Current.GetService<IPlatformOpenGlInterface>();
var angle = (AngleWin32EglDisplay)egl.Display; This will give you access to EGL and OpenGL entry points. At some point I'll make it work out of the box with some simple D3DImage-like API, but that probably won't happen until summer/fall. |
Beta Was this translation helpful? Give feedback.
Short answer: yes, that's possible, but requires tinkering with Skia and ANGLE
Long answer:
Win32PlatformOptions
to always enable GPU andAngleOptions
to use DirectX11ICustomDrawingOperation
, that will give you access to Skia on the render thread, see CustomSkiaPage.cs example. Note that the following steps can be ONLY done from ICustomDrawingOperation::Draw callback.Obviously the 3rd step is the hardest one.