Skip to content

Instantly share code, notes, and snippets.

@kaneta1992
Created October 25, 2017 02:09
Show Gist options
  • Save kaneta1992/e67d3fd2cda9c0f73628fdf725bc9ec1 to your computer and use it in GitHub Desktop.
Save kaneta1992/e67d3fd2cda9c0f73628fdf725bc9ec1 to your computer and use it in GitHub Desktop.
#pragma comment(lib,"d3d11.lib")
#include <d3d11.h>
D3D_DRIVER_TYPE g_driverType;
D3D_FEATURE_LEVEL g_featureLevel;
ID3D11Device* g_pd3dDevice = nullptr;
ID3D11DeviceContext* g_pImmediateContext = nullptr;
HRESULT InitDevice()
{
HRESULT hr = S_OK;
UINT createDeviceFlags = 0;
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE(driverTypes);
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
};
UINT numFeatureLevels = ARRAYSIZE(featureLevels);
for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDevice(nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext);
if (SUCCEEDED(hr))
break;
}
return hr;
}
void main()
{
InitDevice();
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment