#include "d3d_device.h" #include "common.h" static Microsoft::WRL::ComPtr g_device; static Microsoft::WRL::ComPtr g_context; static bool g_initialized = false; static bool g_available = false; bool InitializeD3D() { if (g_initialized) return g_available; g_initialized = true; D3D_FEATURE_LEVEL featureLevel; HRESULT hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0, D3D11_SDK_VERSION, &g_device, &featureLevel, &g_context ); if (FAILED(hr)) { DWM_LOG("ERROR: D3D11CreateDevice failed (HRESULT=0x%08lX)", hr); g_available = false; return false; } DWM_LOG("D3D11 device created (feature level 0x%X)", static_cast(featureLevel)); g_available = true; return true; } Microsoft::WRL::ComPtr GetD3DDevice() { return g_device; } Microsoft::WRL::ComPtr GetD3DContext() { return g_context; } bool IsD3DAvailable() { return g_available; }