|
62 | 62 | #include <wbemcli.h> |
63 | 63 | #include <wincrypt.h> |
64 | 64 |
|
| 65 | +#if defined(RD_ENABLED) |
| 66 | +#include "servers/rendering/rendering_device.h" |
| 67 | +#endif |
| 68 | + |
| 69 | +#if defined(GLES3_ENABLED) |
| 70 | +#include "gl_manager_windows_native.h" |
| 71 | +#endif |
| 72 | + |
| 73 | +#if defined(VULKAN_ENABLED) |
| 74 | +#include "rendering_context_driver_vulkan_windows.h" |
| 75 | +#endif |
| 76 | +#if defined(D3D12_ENABLED) |
| 77 | +#include "drivers/d3d12/rendering_context_driver_d3d12.h" |
| 78 | +#endif |
| 79 | +#if defined(GLES3_ENABLED) |
| 80 | +#include "drivers/gles3/rasterizer_gles3.h" |
| 81 | +#endif |
| 82 | + |
65 | 83 | #ifdef DEBUG_ENABLED |
66 | 84 | #pragma pack(push, before_imagehlp, 8) |
67 | 85 | #include <imagehlp.h> |
@@ -2346,6 +2364,99 @@ void OS_Windows::add_frame_delay(bool p_can_draw) { |
2346 | 2364 | } |
2347 | 2365 | } |
2348 | 2366 |
|
| 2367 | +bool OS_Windows::_test_create_rendering_device() const { |
| 2368 | + // Tests Rendering Device creation. |
| 2369 | + |
| 2370 | + bool ok = false; |
| 2371 | +#if defined(RD_ENABLED) |
| 2372 | + Error err; |
| 2373 | + RenderingContextDriver *rcd = nullptr; |
| 2374 | + |
| 2375 | +#if defined(VULKAN_ENABLED) |
| 2376 | + rcd = memnew(RenderingContextDriverVulkan); |
| 2377 | +#endif |
| 2378 | +#ifdef D3D12_ENABLED |
| 2379 | + if (rcd == nullptr) { |
| 2380 | + rcd = memnew(RenderingContextDriverD3D12); |
| 2381 | + } |
| 2382 | +#endif |
| 2383 | + if (rcd != nullptr) { |
| 2384 | + err = rcd->initialize(); |
| 2385 | + if (err == OK) { |
| 2386 | + RenderingDevice *rd = memnew(RenderingDevice); |
| 2387 | + err = rd->initialize(rcd); |
| 2388 | + memdelete(rd); |
| 2389 | + rd = nullptr; |
| 2390 | + if (err == OK) { |
| 2391 | + ok = true; |
| 2392 | + } |
| 2393 | + } |
| 2394 | + memdelete(rcd); |
| 2395 | + rcd = nullptr; |
| 2396 | + } |
| 2397 | +#endif |
| 2398 | + |
| 2399 | + return ok; |
| 2400 | +} |
| 2401 | + |
| 2402 | +bool OS_Windows::_test_create_rendering_device_and_gl() const { |
| 2403 | + // Tests OpenGL context and Rendering Device simultaneous creation. This function is expected to crash on some NVIDIA drivers. |
| 2404 | + |
| 2405 | + WNDCLASSEXW wc_probe; |
| 2406 | + memset(&wc_probe, 0, sizeof(WNDCLASSEXW)); |
| 2407 | + wc_probe.cbSize = sizeof(WNDCLASSEXW); |
| 2408 | + wc_probe.style = CS_OWNDC | CS_DBLCLKS; |
| 2409 | + wc_probe.lpfnWndProc = (WNDPROC)::DefWindowProcW; |
| 2410 | + wc_probe.cbClsExtra = 0; |
| 2411 | + wc_probe.cbWndExtra = 0; |
| 2412 | + wc_probe.hInstance = GetModuleHandle(nullptr); |
| 2413 | + wc_probe.hIcon = LoadIcon(nullptr, IDI_WINLOGO); |
| 2414 | + wc_probe.hCursor = nullptr; |
| 2415 | + wc_probe.hbrBackground = nullptr; |
| 2416 | + wc_probe.lpszMenuName = nullptr; |
| 2417 | + wc_probe.lpszClassName = L"Engine probe window"; |
| 2418 | + |
| 2419 | + if (!RegisterClassExW(&wc_probe)) { |
| 2420 | + return false; |
| 2421 | + } |
| 2422 | + |
| 2423 | + HWND hWnd = CreateWindowExW(WS_EX_WINDOWEDGE, L"Engine probe window", L"", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); |
| 2424 | + if (!hWnd) { |
| 2425 | + UnregisterClassW(L"Engine probe window", GetModuleHandle(nullptr)); |
| 2426 | + return false; |
| 2427 | + } |
| 2428 | + |
| 2429 | + bool ok = true; |
| 2430 | +#ifdef GLES3_ENABLED |
| 2431 | + GLManagerNative_Windows *test_gl_manager_native = memnew(GLManagerNative_Windows); |
| 2432 | + if (test_gl_manager_native->window_create(DisplayServer::MAIN_WINDOW_ID, hWnd, GetModuleHandle(nullptr), 800, 600) == OK) { |
| 2433 | + RasterizerGLES3::make_current(true); |
| 2434 | + } else { |
| 2435 | + ok = false; |
| 2436 | + } |
| 2437 | +#endif |
| 2438 | + |
| 2439 | + MSG msg = {}; |
| 2440 | + while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { |
| 2441 | + TranslateMessage(&msg); |
| 2442 | + DispatchMessageW(&msg); |
| 2443 | + } |
| 2444 | + |
| 2445 | + if (ok) { |
| 2446 | + ok = _test_create_rendering_device(); |
| 2447 | + } |
| 2448 | + |
| 2449 | +#ifdef GLES3_ENABLED |
| 2450 | + if (test_gl_manager_native) { |
| 2451 | + memdelete(test_gl_manager_native); |
| 2452 | + } |
| 2453 | +#endif |
| 2454 | + |
| 2455 | + DestroyWindow(hWnd); |
| 2456 | + UnregisterClassW(L"Engine probe window", GetModuleHandle(nullptr)); |
| 2457 | + return ok; |
| 2458 | +} |
| 2459 | + |
2349 | 2460 | OS_Windows::OS_Windows(HINSTANCE _hInstance) { |
2350 | 2461 | hInstance = _hInstance; |
2351 | 2462 |
|
|
0 commit comments