我正在尝试通过调用SwapChainPanel (调用ISwapChainPanelNative.SetSwapChain()
)来初始化在文件中所描述的在文件中。
但是,我很难将我的Microsoft.UI.Xaml.Controls.SwapChainPanel
转换为ISwapChainPanelNative
。
我怎样才能从我的ISwapChainPanelNative
WinUI SwapChainPanel
得到一个
到目前为止我尝试过的是:
private void AssociateSwapChainPanel(
Microsoft.UI.Xaml.Controls.SwapChainPanel swapChainPanel,
Vortice.DXGI.IDXGISwapChain3 swapChain)
{
IUnknown swapChainPanelUnknown = swapChainPanel as IUnknown; // null
IInspectable swapChainPanelInspectable = swapChainPanel as IInspectable; // null
var swapChainPanelNative = swapChainPanel as Vortice.WinUI.ISwapChainPanelNative; // Doesn't compile
var swapChainPanelNative = swapChainPanelInspectable.ObjRef.AsInterface<Vortice.WinUI.ISwapChainPanelNative>(); // Exception
var swapChainPanelNative = WinRT.CastExtensions.As<Vortice.WinUI.ISwapChainPanelNative>(swapChainPanel); // Exception
var swapChainPanelNative = (Vortice.WinUI.ISwapChainPanelNative)(object)swapChainPanel; // Exception
发布于 2022-10-11 04:35:13
这就是我正在做的事情。如果它仍然不起作用的话,希望它能帮助你。
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using SharpGen.Runtime;
using Vortice.Direct3D;
using Vortice.Direct3D11;
using Vortice.DXGI;
class ...
{
ID3D11Device2 m_Device;
ID3D11DeviceContext m_DeviceContext;
SwapChainPanel m_SwapChainPanel;
readonly IDXGISwapChain2 m_SwapChain;
void ...()
{
var swapChainDescription = new SwapChainDescription1()
{
AlphaMode = AlphaMode.Ignore,
BufferCount = 2,
Format = Format.R8G8B8A8_UNorm,
Height = (int)m_SwapChainPanel.RenderSize.Height,
Width = (int)m_SwapChainPanel.RenderSize.Width,
SampleDescription = new SampleDescription(1, 0),
Scaling = Scaling.Stretch,
Stereo = false,
SwapEffect = SwapEffect.FlipSequential,
BufferUsage = Usage.RenderTargetOutput
};
D3D11.D3D11CreateDevice(
null,
DriverType.Hardware,
DeviceCreationFlags.None,
new[]
{
FeatureLevel.Level_11_1,
FeatureLevel.Level_11_0,
},
out var defaultDevice);
m_Device = defaultDevice.QueryInterface<ID3D11Device2>();
m_DeviceContext = m_Device.ImmediateContext2;
using (var dxgiDevice3 = m_Device.QueryInterface<IDXGIDevice3>())
using (IDXGIFactory2 dxgiFactory = dxgiDevice3.GetAdapter().GetParent<IDXGIFactory2>())
using (IDXGISwapChain1 swapChain1 = dxgiFactory.CreateSwapChainForComposition(dxgiDevice3, swapChainDescription))
m_SwapChain = swapChain1.QueryInterface<IDXGISwapChain2>();
using (var nativeObject = ComObject.As<Vortice.WinUI.ISwapChainPanelNative2>(m_SwapChainPanel))
nativeObject.SetSwapChain(m_SwapChain);
}
}
https://stackoverflow.com/questions/72891006
复制相似问题