2012-10-15 45 views
5

工作,我想画一样的三角形上时,下面的图片,使多重采样: enter image description here多重采样不以独占方式

我找到了一种方法做SlimDXanother question,但它不工作在独家模式。

这里是我的代码:

void Form1_Load(object sender, EventArgs e) 
{ 
    Direct3D d3d = new Direct3D(); 

    PresentParameters presentParams; 

    presentParams.Windowed = false; 
    presentParams.BackBufferFormat = Format.X8R8G8B8; 
    presentParams.BackBufferWidth = 800; 
    presentParams.BackBufferHeight = 600; 
    presentParams.FullScreenRefreshRateInHertz = 60; 
    presentParams.SwapEffect = SwapEffect.Copy; 
    presentParams.BackBufferCount = 1; 
    presentParams.PresentationInterval = PresentInterval.One; 

    int multisampleQuality; 
    Result result; 
    if (d3d.CheckDeviceMultisampleType(adaptor, DeviceType.Hardware, Format.X8R8G8B8, false, MultisampleType.FourSamples, out multisampleQuality, out result)) 
    { 
     if(multisampleQuality > 4) 
     { 
      presentParams.Multisample = multisampleType; 
      presentParams.MultisampleQuality = 4; 
     } 
    } 

    // Device creation 
    Device device = new Device(d3d, adaptor, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, presentParams); 
} 

最后一行送花儿给人以 D3DERR_INVALIDCALL错误crashs即使CheckDeviceMultisampleType回报没有错误multisampleQuality总是正确和8。

它适用于如果我使用窗口模式或如果我删除multisample选项。

有人可以告诉我什么是错?

回答

1

尝试用

presentParams.SwapEffect = SwapEffect.Discard; 
+0

它的工作原理就像一个魅力!非常感谢:) –

+0

嗨@catflier!你有解释吗?我意识到,实际上我确实需要将此参数设置为* SwapEffect.Copy * ... –

+0

@tinmaru:是的,有一些原因让你无法做到这一点,主要是因为swapeffect.copy需要每像素复制像素,所以它不适用于msaa(因为你有子像素样本)。此外,为什么你需要SwapEffect.Copy?放弃标准很重要 – catflier