我有一个带有SlimDX控件的WPF应用程序(DirectX 11)。我在init上创建了一个SwapChain
:
var description = new SwapChainDescription()
{
ModeDescription = new ModeDescription(WindowWidth, WindowHeight, new Rational(60, 1), Format.B8G8R8A8_UNorm)
{
ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified,
Scaling = DisplayModeScaling.Unspecified,
},
SampleDescription = new SampleDescription(1, 0),
Usage = Usage.Shared | Usage.RenderTargetOutput | Usage.ShaderInput,
BufferCount = 1,
OutputHandle = D3DDeviceManager.SafeNativeMethods.GetDesktopWindow(),
IsWindowed = true,
SwapEffect = SwapEffect.Discard,
Flags = SwapChainFlags.AllowModeSwitch,
};
SwapChain = new SwapChain(Device.Factory, Device, description);
注意,我设置了Shared
标志。当我的窗口调整大小时,我想更新缓冲区大小并从SwapChain
获取新的共享纹理。我是这样做的:
SwapChain.ResizeBuffers(1, WindowWidth, WindowHeight, Format.B8G8R8A8_UNorm, SwapChainFlags.None);
SharedTexture = SlimDX.Direct3D11.Resource.FromSwapChain<Texture2D>(SwapChain, 0);
但是生成的纹理将OptionFlags
设置为None
而不是Shared
。这是为什么?难道我做错了什么?如果我从Texture2DDescription
创建纹理,它可以正常工作。