My game runs with DirectX 11. I need to check if my PC supports DirectX 11 and if it is compatible with older DirectX versions.
Will my game that uses DirectX 11 work if my PC only has an older DirectX version?
I wrote this code, and it seems to work, but I'm not entirely sure about it:
bool CheckDirectXSupport(HRESULT &hr) {
// Device descriptor
D3D_FEATURE_LEVEL featureLevel;
// Attempt to create the device Direct3D 11
ID3D11Device* device = nullptr;
ID3D11DeviceContext* context = nullptr;
hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
&device,
&featureLevel,
&context
);
// Test:
// bool isSupported = SUCCEEDED(hr);
bool isFailed = FAILED(hr);
if (isFailed) {
std::cout << "Failed to create DirectX 11 device. Error code: " << hr << std::endl;
return false;
}
// Release recources
if (device) device->Release();
if (context) context->Release();
return true;
}
What if DirectX installed, but it doesn't work because driver failure or etc? Or what if my PC will have DirectX10? Will my game run and will CheckDirectX11Support() return true? Does my function cover all cases of incompatibility?