C#:无法创建 DirectX 设备。硬件类型或软件类型均不起作用
我正在尝试通过以下代码创建 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) )。我已经检查过,以确保有问题的电脑通过 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;
I'm trying to create a DirectX device through the following code:
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);
The problem is that this only works on some computers (such as my work computer), while it doesn't on others (to be specific, a Panasonic CF-19 Toughbook). I've checked to make sure the offending PC has hardware acceleration enabled via dxdiag, and it still doesn't budge.
Unfortunately, the only error message I get is, "Error on the Application." I've even stuck several message boxes between the above code, and it never seems to hit the ex1 and ex2 catch block.
Any ideas on how to fix this?
Edit: Sorry, I just realized I forgot to show my 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。妈的,我已经觉得自己很蠢了。
将 PresentParameters 减少到这 3 行就可以在 Toughbook 上运行了。
Solved it. Darn, I feel stupid already.
Reducing the PresentParameters to just these 3 lines made it work on the Toughbook.