i have an wpf app and trying to switch from rendering onto winforms control to rendering onto image using d3dimage (cause i want to be able to place some wpf interface on top of rendering image, airspace problem and all that), so i know i need to create directx 9 device and create shared texture, i'm trying to follow other people's examples, but for some reason shared texture creation fails (but not just directx 9 texture, only when i pass handle of directx 11 texture to it's constructor), i tried using both hardware and reference devices for either directx 9 or directx 11, i tried to tweak formats, creation flags, nothing helped, followed all restrictions described here https://learn.microsoft.com/ru-ru/windows/win32/api/d3d11/nf-d3d11-id3d11device-opensharedresource?redirectedfrom=MSDN and still no result, any ideas? xaml:
<Window x:Class="WPFReflectionTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
<WindowsFormsHost>
<wf:Control x:Name="WinFormsControl"/>
</WindowsFormsHost>
</Grid>
</Window>
cb:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SharpDX.Direct3D11.Device device = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.None | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_11_0);
SharpDX.Direct3D11.Texture2D texture = new SharpDX.Direct3D11.Texture2D(device, new Texture2DDescription()
{
Width = WinFormsControl.ClientSize.Width,
Height = WinFormsControl.ClientSize.Height,
ArraySize = 1,
BindFlags = BindFlags.RenderTarget,
Usage = ResourceUsage.Default,
CpuAccessFlags = CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.Shared,
SampleDescription = new SampleDescription(1, 0)
});
Direct3DEx d9context = new Direct3DEx();
DeviceEx d9device = new DeviceEx(d9context,
0,
DeviceType.Hardware,
IntPtr.Zero,
CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve,
new SharpDX.Direct3D9.PresentParameters()
{
Windowed = true,
SwapEffect = SharpDX.Direct3D9.SwapEffect.Discard,
DeviceWindowHandle = WinFormsControl.Handle,
PresentationInterval = PresentInterval.Immediate,
});
IntPtr renderTextureHandle = texture.QueryInterface<SharpDX.DXGI.Resource>().SharedHandle;
SharpDX.Direct3D9.Texture d9texture = new SharpDX.Direct3D9.Texture(d9device,
texture.Description.Width,
texture.Description.Height,
1,
SharpDX.Direct3D9.Usage.RenderTarget,
SharpDX.Direct3D9.Format.A8B8G8R8,
Pool.Default,
ref renderTextureHandle);
}