Enabling antialising in SlimDX (D3D9)

2019-06-12 22:21发布

问题:

I would like to enable antialiasing when drawing triangles like on the following picture:

I found a way to do it with XNA on this page but I want to do the same with SlimDX.

回答1:

On SlimDX/Directx9, when you create your swapchain, use this in PresentParameters:

Multisample = MultisampleType.FourSamples,
MultisampleQuality = 4

Also make sure that the multisample state is on (By default it is, but never sure):

device.SetRenderState(RenderState.MultisampleAntialias, true);

There's of course different type of samples, to find quality/samples, use the following method:

new Direct3D().CheckDeviceMultisampleType

On dx10+ device, when you create your swapchain, you have a SampleDescription parameter,

so set samples count/quality accordingly

SampleDescription samdesc = new SampleDescription(4, 4);

To enumerate allowed samplecount/quality combinations:

int maxsamplecount = Device.MultisampleCountMaximum

Then iterate for sample count using:

int maxquality = device.CheckMultisampleQualityLevels(format, sampleCount);

It will return 0 if sample count is not supported.