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.cpp91
1 files changed, 85 insertions, 6 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index e8d81405f0..9e398473c1 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -1107,6 +1107,11 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) {
context_vulkan->window_destroy(p_window);
}
#endif
+#ifdef D3D12_ENABLED
+ if (context_d3d12) {
+ context_d3d12->window_destroy(p_window);
+ }
+#endif
#ifdef GLES3_ENABLED
if (gl_manager_angle) {
gl_manager_angle->window_destroy(p_window);
@@ -1539,6 +1544,11 @@ void DisplayServerWindows::window_set_size(const Size2i p_size, WindowID p_windo
context_vulkan->window_resize(p_window, w, h);
}
#endif
+#if defined(D3D12_ENABLED)
+ if (context_d3d12) {
+ context_d3d12->window_resize(p_window, w, h);
+ }
+#endif
#if defined(GLES3_ENABLED)
if (gl_manager_native) {
gl_manager_native->window_resize(p_window, w, h);
@@ -2590,6 +2600,12 @@ void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsyn
}
#endif
+#if defined(D3D12_ENABLED)
+ if (context_d3d12) {
+ context_d3d12->set_vsync_mode(p_window, p_vsync_mode);
+ }
+#endif
+
#if defined(GLES3_ENABLED)
if (gl_manager_native) {
gl_manager_native->set_use_vsync(p_window, p_vsync_mode != DisplayServer::VSYNC_DISABLED);
@@ -2608,6 +2624,12 @@ DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_
}
#endif
+#if defined(D3D12_ENABLED)
+ if (context_d3d12) {
+ return context_d3d12->get_vsync_mode(p_window);
+ }
+#endif
+
#if defined(GLES3_ENABLED)
if (gl_manager_native) {
return gl_manager_native->is_using_vsync(p_window) ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED;
@@ -2616,7 +2638,6 @@ DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_
return gl_manager_angle->is_using_vsync() ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED;
}
#endif
-
return DisplayServer::VSYNC_ENABLED;
}
@@ -3769,12 +3790,19 @@ 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 && window.context_created) {
- // Note: Trigger resize event to update swapchains when window is minimized/restored, even if size is not changed.
- context_vulkan->window_resize(window_id, window.width, window.height);
- }
+ 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 (!window.minimized && (!(window_pos_params->flags & SWP_NOMOVE) || window_pos_params->flags & SWP_FRAMECHANGED)) {
@@ -4338,6 +4366,18 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
}
#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;
+ windows.erase(id);
+ ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Failed to create D3D12 Window.");
+ }
+ wd.context_created = true;
+ }
+#endif
+
#ifdef GLES3_ENABLED
if (gl_manager_native) {
if (gl_manager_native->window_create(id, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) != OK) {
@@ -4646,6 +4686,17 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}
}
#endif
+#if defined(D3D12_ENABLED)
+ if (rendering_driver == "d3d12") {
+ context_d3d12 = memnew(D3D12Context);
+ if (context_d3d12->initialize() != OK) {
+ memdelete(context_d3d12);
+ context_d3d12 = nullptr;
+ r_error = ERR_UNAVAILABLE;
+ return;
+ }
+ }
+#endif
// Init context and rendering device
#if defined(GLES3_ENABLED)
@@ -4722,7 +4773,6 @@ 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);
@@ -4730,6 +4780,14 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
RendererCompositorRD::make_current();
}
#endif
+#if defined(D3D12_ENABLED)
+ if (rendering_driver == "d3d12") {
+ rendering_device_d3d12 = memnew(RenderingDeviceD3D12);
+ rendering_device_d3d12->initialize(context_d3d12);
+
+ RendererCompositorRD::make_current();
+ }
+#endif
if (!Engine::get_singleton()->is_editor_hint() && !OS::get_singleton()->is_in_low_processor_usage_mode()) {
// Increase priority for projects that are not in low-processor mode (typically games)
@@ -4764,6 +4822,9 @@ Vector<String> DisplayServerWindows::get_rendering_drivers_func() {
#ifdef VULKAN_ENABLED
drivers.push_back("vulkan");
#endif
+#ifdef D3D12_ENABLED
+ drivers.push_back("d3d12");
+#endif
#ifdef GLES3_ENABLED
drivers.push_back("opengl3");
drivers.push_back("opengl3_angle");
@@ -4828,6 +4889,11 @@ DisplayServerWindows::~DisplayServerWindows() {
context_vulkan->window_destroy(MAIN_WINDOW_ID);
}
#endif
+#ifdef D3D12_ENABLED
+ if (context_d3d12) {
+ context_d3d12->window_destroy(MAIN_WINDOW_ID);
+ }
+#endif
if (wintab_available && windows[MAIN_WINDOW_ID].wtctx) {
wintab_WTClose(windows[MAIN_WINDOW_ID].wtctx);
windows[MAIN_WINDOW_ID].wtctx = 0;
@@ -4848,6 +4914,19 @@ DisplayServerWindows::~DisplayServerWindows() {
}
#endif
+#if defined(D3D12_ENABLED)
+ if (rendering_device_d3d12) {
+ rendering_device_d3d12->finalize();
+ memdelete(rendering_device_d3d12);
+ rendering_device_d3d12 = nullptr;
+ }
+
+ if (context_d3d12) {
+ memdelete(context_d3d12);
+ context_d3d12 = nullptr;
+ }
+#endif
+
if (restore_mouse_trails > 1) {
SystemParametersInfoA(SPI_SETMOUSETRAILS, restore_mouse_trails, 0, 0);
}