开发者

C#: Unable to create DirectX device. Neither Hardware type or Software type works

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,
    mInvisibl开发者_JAVA技巧ePanel, 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;


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜