summaryrefslogtreecommitdiffstats
path: root/platform/windows/display_server_windows.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows/display_server_windows.cpp')
-rw-r--r--platform/windows/display_server_windows.cpp188
1 files changed, 74 insertions, 114 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 77dfff2e5d..811d124230 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -1102,14 +1102,9 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) {
window_set_transient(p_window, INVALID_WINDOW_ID);
}
-#ifdef VULKAN_ENABLED
- if (context_vulkan) {
- context_vulkan->window_destroy(p_window);
- }
-#endif
-#ifdef D3D12_ENABLED
- if (context_d3d12) {
- context_d3d12->window_destroy(p_window);
+#ifdef RD_ENABLED
+ if (context_rd) {
+ context_rd->window_destroy(p_window);
}
#endif
#ifdef GLES3_ENABLED
@@ -1539,14 +1534,9 @@ void DisplayServerWindows::window_set_size(const Size2i p_size, WindowID p_windo
wd.width = w;
wd.height = h;
-#if defined(VULKAN_ENABLED)
- if (context_vulkan) {
- context_vulkan->window_resize(p_window, w, h);
- }
-#endif
-#if defined(D3D12_ENABLED)
- if (context_d3d12) {
- context_d3d12->window_resize(p_window, w, h);
+#if defined(RD_ENABLED)
+ if (context_rd) {
+ context_rd->window_resize(p_window, w, h);
}
#endif
#if defined(GLES3_ENABLED)
@@ -2594,15 +2584,9 @@ void DisplayServerWindows::set_icon(const Ref<Image> &p_icon) {
void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) {
_THREAD_SAFE_METHOD_
-#if defined(VULKAN_ENABLED)
- if (context_vulkan) {
- context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
- }
-#endif
-
-#if defined(D3D12_ENABLED)
- if (context_d3d12) {
- context_d3d12->set_vsync_mode(p_window, p_vsync_mode);
+#if defined(RD_ENABLED)
+ if (context_rd) {
+ context_rd->set_vsync_mode(p_window, p_vsync_mode);
}
#endif
@@ -2618,15 +2602,9 @@ void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsyn
DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_window) const {
_THREAD_SAFE_METHOD_
-#if defined(VULKAN_ENABLED)
- if (context_vulkan) {
- return context_vulkan->get_vsync_mode(p_window);
- }
-#endif
-
-#if defined(D3D12_ENABLED)
- if (context_d3d12) {
- return context_d3d12->get_vsync_mode(p_window);
+#if defined(RD_ENABLED)
+ if (context_rd) {
+ return context_rd->get_vsync_mode(p_window);
}
#endif
@@ -3788,19 +3766,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
rect_changed = true;
}
- // Note: Trigger resize event to update swapchains when window is minimized/restored, even if size is not changed.
- if (window_created && window.context_created) {
-#if defined(VULKAN_ENABLED)
- if (context_vulkan) {
- context_vulkan->window_resize(window_id, window.width, window.height);
- }
-#endif
-#if defined(D3D12_ENABLED)
- if (context_d3d12) {
- context_d3d12->window_resize(window_id, window.width, window.height);
- }
-#endif
+#if defined(RD_ENABLED)
+ if (context_rd && window.context_created) {
+ // Note: Trigger resize event to update swapchains when window is minimized/restored, even if size is not changed.
+ context_rd->window_resize(window_id, window.width, window.height);
}
+#endif
}
if (!window.minimized && (!(window_pos_params->flags & SWP_NOMOVE) || window_pos_params->flags & SWP_FRAMECHANGED)) {
@@ -3826,7 +3797,6 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
// Return here to prevent WM_MOVE and WM_SIZE from being sent
// See: https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanged#remarks
return 0;
-
} break;
case WM_ENTERSIZEMOVE: {
@@ -4352,25 +4322,32 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
::DwmSetWindowAttribute(wd.hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
}
+#ifdef RD_ENABLED
+ if (context_rd) {
+ union {
#ifdef VULKAN_ENABLED
- if (context_vulkan) {
- if (context_vulkan->window_create(id, p_vsync_mode, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) != OK) {
- memdelete(context_vulkan);
- context_vulkan = nullptr;
- windows.erase(id);
- ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create Vulkan Window.");
+ VulkanContextWindows::WindowPlatformData vulkan;
+#endif
+#ifdef D3D12_ENABLED
+ D3D12Context::WindowPlatformData d3d12;
+#endif
+ } wpd;
+#ifdef VULKAN_ENABLED
+ if (rendering_driver == "vulkan") {
+ wpd.vulkan.window = wd.hWnd;
+ wpd.vulkan.instance = hInstance;
}
- wd.context_created = true;
- }
#endif
-
#ifdef D3D12_ENABLED
- if (context_d3d12) {
- if (context_d3d12->window_create(id, p_vsync_mode, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) != OK) {
- memdelete(context_d3d12);
- context_d3d12 = nullptr;
+ if (rendering_driver == "d3d12") {
+ wpd.d3d12.window = wd.hWnd;
+ }
+#endif
+ if (context_rd->window_create(id, p_vsync_mode, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, &wpd) != OK) {
+ memdelete(context_rd);
+ context_rd = nullptr;
windows.erase(id);
- ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create D3D12 Window.");
+ ERR_FAIL_V_MSG(INVALID_WINDOW_ID, vformat("Failed to create %s Window.", context_rd->get_api_name()));
}
wd.context_created = true;
}
@@ -4673,29 +4650,28 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
_register_raw_input_devices(INVALID_WINDOW_ID);
+#if defined(RD_ENABLED)
#if defined(VULKAN_ENABLED)
if (rendering_driver == "vulkan") {
- context_vulkan = memnew(VulkanContextWindows);
- if (context_vulkan->initialize() != OK) {
- memdelete(context_vulkan);
- context_vulkan = nullptr;
- r_error = ERR_UNAVAILABLE;
- return;
- }
+ context_rd = memnew(VulkanContextWindows);
}
#endif
#if defined(D3D12_ENABLED)
if (rendering_driver == "d3d12") {
- context_d3d12 = memnew(D3D12Context);
- if (context_d3d12->initialize() != OK) {
- memdelete(context_d3d12);
- context_d3d12 = nullptr;
+ context_rd = memnew(D3D12Context);
+ }
+#endif
+
+ if (context_rd) {
+ if (context_rd->initialize() != OK) {
+ memdelete(context_rd);
+ context_rd = nullptr;
r_error = ERR_UNAVAILABLE;
return;
}
}
#endif
- // Init context and rendering device
+// Init context and rendering device
#if defined(GLES3_ENABLED)
#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64)
@@ -4777,18 +4753,10 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
show_window(MAIN_WINDOW_ID);
-#if defined(VULKAN_ENABLED)
- if (rendering_driver == "vulkan") {
- rendering_device_vulkan = memnew(RenderingDeviceVulkan);
- rendering_device_vulkan->initialize(context_vulkan);
-
- RendererCompositorRD::make_current();
- }
-#endif
-#if defined(D3D12_ENABLED)
- if (rendering_driver == "d3d12") {
- rendering_device_d3d12 = memnew(RenderingDeviceD3D12);
- rendering_device_d3d12->initialize(context_d3d12);
+#if defined(RD_ENABLED)
+ if (context_rd) {
+ rendering_device = memnew(RenderingDevice);
+ rendering_device->initialize(context_rd);
RendererCompositorRD::make_current();
}
@@ -4851,6 +4819,16 @@ DisplayServer *DisplayServerWindows::create_func(const String &p_rendering_drive
"If you have recently updated your video card drivers, try rebooting.",
executable_name),
"Unable to initialize Vulkan video driver");
+ } else if (p_rendering_driver == "d3d12") {
+ String executable_name = OS::get_singleton()->get_executable_path().get_file();
+ OS::get_singleton()->alert(
+ vformat("Your video card drivers seem not to support the required DirectX 12 version.\n\n"
+ "If possible, consider updating your video card drivers or using the OpenGL 3 driver.\n\n"
+ "You can enable the OpenGL 3 driver by starting the engine from the\n"
+ "command line with the command:\n\n \"%s\" --rendering-driver opengl3\n\n"
+ "If you have recently updated your video card drivers, try rebooting.",
+ executable_name),
+ "Unable to initialize DirectX 12 video driver");
} else {
OS::get_singleton()->alert(
"Your video card drivers seem not to support the required OpenGL 3.3 version.\n\n"
@@ -4889,14 +4867,9 @@ DisplayServerWindows::~DisplayServerWindows() {
#endif
if (windows.has(MAIN_WINDOW_ID)) {
-#ifdef VULKAN_ENABLED
- if (context_vulkan) {
- context_vulkan->window_destroy(MAIN_WINDOW_ID);
- }
-#endif
-#ifdef D3D12_ENABLED
- if (context_d3d12) {
- context_d3d12->window_destroy(MAIN_WINDOW_ID);
+#ifdef RD_ENABLED
+ if (context_rd) {
+ context_rd->window_destroy(MAIN_WINDOW_ID);
}
#endif
if (wintab_available && windows[MAIN_WINDOW_ID].wtctx) {
@@ -4906,29 +4879,16 @@ DisplayServerWindows::~DisplayServerWindows() {
DestroyWindow(windows[MAIN_WINDOW_ID].hWnd);
}
-#if defined(VULKAN_ENABLED)
- if (rendering_device_vulkan) {
- rendering_device_vulkan->finalize();
- memdelete(rendering_device_vulkan);
- rendering_device_vulkan = nullptr;
- }
-
- if (context_vulkan) {
- memdelete(context_vulkan);
- context_vulkan = nullptr;
- }
-#endif
-
-#if defined(D3D12_ENABLED)
- if (rendering_device_d3d12) {
- rendering_device_d3d12->finalize();
- memdelete(rendering_device_d3d12);
- rendering_device_d3d12 = nullptr;
+#ifdef RD_ENABLED
+ if (rendering_device) {
+ rendering_device->finalize();
+ memdelete(rendering_device);
+ rendering_device = nullptr;
}
- if (context_d3d12) {
- memdelete(context_d3d12);
- context_d3d12 = nullptr;
+ if (context_rd) {
+ memdelete(context_rd);
+ context_rd = nullptr;
}
#endif