C#:无法创建 DirectX 设备。硬件类型或软件类型均不起作用

发布于 2024-10-19 05:32:50 字数 1540 浏览 6 评论 0原文

我正在尝试通过以下代码创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多孤肩上扛 2024-10-26 05:32:50

解决了。妈的,我已经觉得自己很蠢了。

将 PresentParameters 减少到这 3 行就可以在 Toughbook 上运行了。

// Setup the device parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;

Solved it. Darn, I feel stupid already.

Reducing the PresentParameters to just these 3 lines made it work on the Toughbook.

// Setup the device parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文