我正在尝试在 C++ 中初始化 Direct3D11。在安装了 Visual Studio 的机器上(所有这些都在 Windows 10 上运行),它运行良好。在其他计算机上(未安装 Visual Studio,Windows 10 和 7)它返回 E_INVALIDARG。
这些计算机上的标志P_FeatureLevelsSupported为0。在我的上面写着D3D_FEATURE_LEVEL_11_1。所以我想这与 DirectX 安装有关,或者可能是因为缺少 SDK(但这不会很奇怪吗?:D)
通过运行 dxdiag,我知道那些机器支持 DirectX11_0。
有什么我需要安装的吗?该软件必须在我们客户的 PC 上运行。
导致错误的代码:
const D3D_FEATURE_LEVEL lvl[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1,
};
D3D_FEATURE_LEVEL P_FeatureLevelsSupported;
//see microsoft documentation, we use 11_1 or 11_0 if 11_1 is not supported by the client machine
//https://docs.microsoft.com/en-us/windows/desktop/direct3d11/overviews-direct3d-11-devices-initialize
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, lvl, _countof(lvl), D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, &P_FeatureLevelsSupported, &deviceContext);
if(result == E_INVALIDARG) //check with FEATURE_LEVEL_11_0
D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
&lvl[1],
_countof(lvl) - 1,
D3D11_SDK_VERSION,
&swapChainDesc,
&swapChain,
&device,
&P_FeatureLevelsSupported,
&deviceContext);
提前致谢 :)