我正在 DirectX10 中设置我的 SlimDX 项目,但我无法让多重采样工作。这是我的设备初始化:
// Create swap chain description
DXGI.SwapChainDescription swapChainDesc = new DXGI.SwapChainDescription()
{
BufferCount = 1,
Usage = DXGI.Usage.RenderTargetOutput,
OutputHandle = Window.Handle,
IsWindowed = true,
ModeDescription = new DXGI.ModeDescription(0, 0, new Rational(60, 1), DXGI.Format.R8G8B8A8_UNorm),
SampleDescription = new DXGI.SampleDescription(2, 0),
Flags = DXGI.SwapChainFlags.AllowModeSwitch,
SwapEffect = DXGI.SwapEffect.Discard
};
// Get device
DX10.Device.CreateWithSwapChain(null, DX10.DriverType.Hardware, DX10.DeviceCreationFlags.None, swapChainDesc, out Device, out SwapChain);
// Get back buffer
using (DX10.Texture2D texture = DX10.Resource.FromSwapChain<DX10.Texture2D>(SwapChain, 0))
BackBuffer = new DX10.RenderTargetView(Device, texture);
// Set viewport
var viewport = new DX10.Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
Device.OutputMerger.SetTargets(BackBuffer);
Device.Rasterizer.SetViewports(viewport);
// Disable alt+enter
using (var factory = SwapChain.GetParent<DXGI.Factory>())
factory.SetWindowAssociation(Window.Handle, DXGI.WindowAssociationFlags.IgnoreAll);
// Create depth buffer description
DX10.Texture2DDescription depthDesc = new DX10.Texture2DDescription
{
Width = Window.ClientSize.Width,
Height = Window.ClientSize.Height,
MipLevels = 1,
ArraySize = 1,
Format = DXGI.Format.D24_UNorm_S8_UInt,
SampleDescription = new DXGI.SampleDescription(1, 0),
Usage = DX10.ResourceUsage.Default,
BindFlags = DX10.BindFlags.DepthStencil,
CpuAccessFlags = DX10.CpuAccessFlags.None,
OptionFlags = DX10.ResourceOptionFlags.None
};
// Get depth buffer
DX10.Texture2D depthStencilBuffer = new DX10.Texture2D(Device, depthDesc);
DX10.DepthStencilView depthStencilView = new DX10.DepthStencilView(Device, depthStencilBuffer);
depthStencilBuffer.Dispose();
我正在渲染一个简单的盒子。我也查了
Device.CheckMultisampleQualityLevels(DXGI.Format.R8G8B8A8_UNorm, 4)
有 1、2、4、8 和 16 个样本。每次该函数返回 1。但是,当我将 1 放入 SwapChainDescription SampleDescription Quality 时,设备创建会抛出错误:
E_INVALIDARG:向返回函数传递了一个无效参数 (-2147024809)
我基本上只能将 0 用于质量计数。然而,在我的笔记本上,我可以选择不同的质量级别,但多重采样在那里也不起作用,而且 PC 和笔记本显卡都支持多重采样。
有什么我做错了吗?