| 217 | |
| 218 | template <typename T> |
| 219 | static void init_device_proxy(T *&device, D3DDEVTYPE device_type, HWND device_window, bool use_software_rendering) |
| 220 | { |
| 221 | // Enable software vertex processing if the application requested a software device |
| 222 | if (use_software_rendering) |
| 223 | device->SetSoftwareVertexProcessing(TRUE); |
| 224 | |
| 225 | if (device_type == D3DDEVTYPE_NULLREF) |
| 226 | { |
| 227 | reshade::log::message(reshade::log::level::warning, "Skipping device because the device type is 'D3DDEVTYPE_NULLREF'."); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // Some video applications create a non-displaying device targeting the desktop window |
| 232 | if (GetDesktopWindow() == device_window) |
| 233 | { |
| 234 | reshade::log::message(reshade::log::level::warning, "Skipping device because the focus window is the desktop window."); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | IDirect3DSwapChain9 *swapchain = nullptr; |
| 239 | device->GetSwapChain(0, &swapchain); |
| 240 | assert(swapchain != nullptr); // There should always be an implicit swap chain |
| 241 | |
| 242 | const auto device_proxy = new Direct3DDevice9(device, use_software_rendering); |
| 243 | device_proxy->_implicit_swapchain = new Direct3DSwapChain9(device_proxy, swapchain); |
| 244 | |
| 245 | // Overwrite returned device with proxy device |
| 246 | device = device_proxy; |
| 247 | |
| 248 | // Check if this device was created via D3D9on12 and hook it too if so |
| 249 | init_device_proxy_for_d3d9on12(device_proxy); |
| 250 | |
| 251 | // Upgrade to extended interface if available to prevent compatibility issues with some games |
| 252 | com_ptr<IDirect3DDevice9Ex> deviceex; |
| 253 | device_proxy->QueryInterface(IID_PPV_ARGS(&deviceex)); |
| 254 | |
| 255 | #if RESHADE_VERBOSE_LOG |
| 256 | reshade::log::message( |
| 257 | reshade::log::level::debug, |
| 258 | "Returning IDirect3DDevice9%s object %p (%p).", |
| 259 | device_proxy->_extended_interface ? "Ex" : "", device_proxy, device_proxy->_orig); |
| 260 | #endif |
| 261 | } |
| 262 | |
| 263 | // Needs to be set before entering the D3D9 runtime, to avoid hooking internal D3D device creation (e.g. when PIX is attached) |
| 264 | thread_local bool g_in_d3d9_runtime = false; |
no test coverage detected