我正在尝试通过以下代码创建一个DirectX设备:
Caps deviceCapability;
int deviceAdapter = Manager.Adapters.Default.Adapter;
try
{
deviceCapability = Manager.GetDeviceCaps(
deviceAdapter, DeviceType.Hardware);
}
catch (Exception ex1)
{
try
{
deviceCapability = Manager.GetDeviceCaps(
deviceAdapter, DeviceType.Software);
}
catch (Exception ex2)
{
deviceCapability = Manager.GetDeviceCaps(
deviceAdapter, DeviceType.Reference);
}
}
CreateFlags deviceFlags = CreateFlags.SoftwareVertexProcessing;
if(deviceCapability.DeviceCaps.SupportsHardwareTransformAndLight == true)
{
deviceFlags = CreateFlags.HardwareVertexProcessing;
}
mDevice = new Device(deviceAdapter, deviceCapability.DeviceType,
mInvisiblePanel, deviceFlags, mPresentParams);问题是,这只适用于一些电脑(如我的工作电脑),而它不能在其他电脑(具体地说,松下CF-19 Toughbook)。我已经检查过,以确保有问题的PC通过dxdiag启用了硬件加速,但它仍然不动。
不幸的是,我得到的唯一错误消息是“应用程序出错”。我甚至在上面的代码之间插入了几个消息框,它似乎从未命中过ex1和ex2 catch块。
有什么办法解决这个问题吗?
编辑:对不起,我刚刚意识到我忘了展示我的PresentParameters了。
// Setup the device parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;
mPresentParams.AutoDepthStencilFormat = DepthFormat.D16;
mPresentParams.EnableAutoDepthStencil = true;
///* TODO: Anti-aliasing is not working
mPresentParams.MultiSample = MultiSampleType.NonMaskable;
mPresentParams.MultiSampleQuality = 0;发布于 2011-02-25 01:22:04
解决了它。该死,我已经觉得自己很傻了。
将PresentParameters减少到这3行,就可以在Toughbook上工作了。
// Setup the device parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;https://stackoverflow.com/questions/5099159
复制相似问题