summaryrefslogtreecommitdiff
path: root/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows')
-rw-r--r--platform/windows/SCsub5
-rw-r--r--platform/windows/detect.py33
-rwxr-xr-xplatform/windows/os_windows.cpp188
-rw-r--r--platform/windows/os_windows.h19
-rw-r--r--platform/windows/vulkan_context_win.cpp57
-rw-r--r--platform/windows/vulkan_context_win.h48
6 files changed, 259 insertions, 91 deletions
diff --git a/platform/windows/SCsub b/platform/windows/SCsub
index 892d734734..6f01460025 100644
--- a/platform/windows/SCsub
+++ b/platform/windows/SCsub
@@ -8,13 +8,14 @@ import platform_windows_builders
common_win = [
"godot_windows.cpp",
- "context_gl_windows.cpp",
"crash_handler_windows.cpp",
"os_windows.cpp",
"key_mapping_windows.cpp",
"joypad_windows.cpp",
"power_windows.cpp",
- "windows_terminal_logger.cpp"
+ "windows_terminal_logger.cpp",
+ "vulkan_context_win.cpp",
+ "context_gl_windows.cpp"
]
res_file = 'godot_res.rc'
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 72c3f60d99..0b65565a37 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -207,7 +207,7 @@ def configure_msvc(env, manual_msvc_config):
else:
print("Missing environment variable: WindowsSdkDir")
- env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED', 'OPENGL_ENABLED',
+ env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED',
'WASAPI_ENABLED', 'WINMIDI_ENABLED',
'TYPED_METHOD_BIND',
'WIN32', 'MSVC',
@@ -219,10 +219,21 @@ def configure_msvc(env, manual_msvc_config):
## Libs
- LIBS = ['winmm', 'opengl32', 'dsound', 'kernel32', 'ole32', 'oleaut32',
+ LIBS = ['winmm', 'dsound', 'kernel32', 'ole32', 'oleaut32',
'user32', 'gdi32', 'IPHLPAPI', 'Shlwapi', 'wsock32', 'Ws2_32',
- 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt','Avrt',
+ 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt', 'Avrt',
'dwmapi']
+
+ env.Prepend(CPPPATH=['#thirdparty/vulkan/include/', "#thirdparty/vulkan/registry/"])
+ env.AppendUnique(CPPDEFINES = ['VULKAN_ENABLED'])
+ if not env["builtin_vulkan_loader"]:
+ LIBS += ['vulkan']
+ else:
+ LIBS += ['cfgmgr32']
+
+ #env.AppendUnique(CPPDEFINES = ['OPENGL_ENABLED'])
+ LIBS += ['opengl32']
+
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS])
if manual_msvc_config:
@@ -345,9 +356,21 @@ def configure_mingw(env):
## Compile flags
env.Append(CCFLAGS=['-mwindows'])
- env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'OPENGL_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
+
+ env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
env.Append(CPPDEFINES=[('WINVER', env['target_win_version']), ('_WIN32_WINNT', env['target_win_version'])])
- env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
+ env.Append(LIBS=['mingw32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
+
+ env.Prepend(CPPPATH=['#thirdparty/vulkan/include/', "#thirdparty/vulkan/registry/"])
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env["builtin_vulkan_loader"]:
+ env.Append(LIBS=['vulkan'])
+ else:
+ env.Append(LIBS=['cfgmgr32'])
+
+ ## TODO !!! Reenable when OpenGLES Rendering Device is implemented !!!
+ #env.Append(CPPDEFINES=['OPENGL_ENABLED'])
+ env.Append(LIBS=['opengl32'])
env.Append(CPPDEFINES=['MINGW_ENABLED', ('MINGW_HAS_SECURE_API', 1)])
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 3a8e8bdb5a..40ced686c8 100755
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -35,8 +35,15 @@
#include "core/io/marshalls.h"
#include "core/version_generated.gen.h"
+
+#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
+#endif
+
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
#include "drivers/windows/mutex_windows.h"
@@ -893,6 +900,11 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
preserve_window_size = false;
set_window_size(Size2(video_mode.width, video_mode.height));
}
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->window_resize(0, video_mode.width, video_mode.height);
+ }
+#endif
}
if (wParam == SIZE_MAXIMIZED) {
@@ -1416,78 +1428,59 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
SetWindowPos(hWnd, video_mode.always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
-#if defined(OPENGL_ENABLED)
-
- bool gles3_context = true;
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gles3_context = false;
- }
-
- bool editor = Engine::get_singleton()->is_editor_hint();
- bool gl_initialization_error = false;
-
- gl_context = NULL;
- while (!gl_context) {
- gl_context = memnew(ContextGL_Windows(hWnd, gles3_context));
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //TODO - do Vulkan and GLES2 support checks, driver selection and fallback
+ video_driver_index = p_video_driver;
+ print_verbose("Driver: " + String(get_video_driver_name(video_driver_index)) + " [" + itos(video_driver_index) + "]");
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
- if (gl_context->initialize() != OK) {
- memdelete(gl_context);
- gl_context = NULL;
+ // Init context and rendering device
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gl_initialization_error = true;
- break;
- }
+ context_gles2 = memnew(ContextGL_Windows(hWnd, false));
- p_video_driver = VIDEO_DRIVER_GLES2;
- gles3_context = false;
- } else {
- gl_initialization_error = true;
- break;
- }
+ if (context_gles2->initialize() != OK) {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
- }
- while (true) {
- if (gles3_context) {
- if (RasterizerGLES3::is_viable() == OK) {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- gles3_context = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
+ context_gles2->set_use_vsync(video_mode.use_vsync);
+ set_vsync_via_compositor(video_mode.vsync_via_compositor);
+
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
} else {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
- }
- if (gl_initialization_error) {
- OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
- "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
- "Unable to initialize Video driver");
- return ERR_UNAVAILABLE;
}
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ context_vulkan = memnew(VulkanContextWindows);
+ if (context_vulkan->initialize() != OK) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
+ if (context_vulkan->window_create(hWnd, hInstance, get_video_mode().width, get_video_mode().height) == -1) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- video_driver_index = p_video_driver;
+ //temporary
+ rendering_device_vulkan = memnew(RenderingDeviceVulkan);
+ rendering_device_vulkan->initialize(context_vulkan);
- gl_context->set_use_vsync(video_mode.use_vsync);
- set_vsync_via_compositor(video_mode.vsync_via_compositor);
+ RasterizerRD::make_current();
+ }
#endif
visual_server = memnew(VisualServerRaster);
@@ -1660,9 +1653,26 @@ void OS_Windows::finalize() {
cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
-#ifdef OPENGL_ENABLED
- if (gl_context)
- memdelete(gl_context);
+
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+
+ if (context_gles2)
+ memdelete(context_gles2);
+
+ }
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ if (rendering_device_vulkan) {
+ rendering_device_vulkan->finalize();
+ memdelete(rendering_device_vulkan);
+ }
+
+ if (context_vulkan)
+ memdelete(context_vulkan);
+ }
#endif
if (user_proc) {
@@ -1964,6 +1974,11 @@ void OS_Windows::set_window_size(const Size2 p_size) {
video_mode.width = w;
video_mode.height = h;
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->window_resize(0, video_mode.width, video_mode.height);
+ }
+#endif
if (video_mode.fullscreen) {
return;
@@ -3121,18 +3136,32 @@ OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const {
}
void OS_Windows::release_rendering_thread() {
-
- gl_context->release_current();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->release_current();
+ }
+#endif
}
void OS_Windows::make_rendering_thread() {
-
- gl_context->make_current();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->make_current();
+ }
+#endif
}
void OS_Windows::swap_buffers() {
-
- gl_context->swap_buffers();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->swap_buffers();
+ }
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->swap_buffers();
+ }
+#endif
}
void OS_Windows::force_process_input() {
@@ -3299,18 +3328,13 @@ String OS_Windows::get_joy_guid(int p_device) const {
}
void OS_Windows::_set_use_vsync(bool p_enable) {
-
- if (gl_context)
- gl_context->set_use_vsync(p_enable);
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (context_gles2)
+ context_gles2->set_use_vsync(p_enable);
+ }
+#endif
}
-/*
-bool OS_Windows::is_vsync_enabled() const {
-
- if (gl_context)
- return gl_context->is_using_vsync();
-
- return true;
-}*/
OS::PowerState OS_Windows::get_power_state() {
return power_manager->get_power_state();
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index cf16295a70..89b67f8d91 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -31,7 +31,6 @@
#ifndef OS_WINDOWS_H
#define OS_WINDOWS_H
-#include "context_gl_windows.h"
#include "core/os/input.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -49,6 +48,15 @@
#include "drivers/xaudio2/audio_driver_xaudio2.h"
#endif
+#if defined(OPENGL_ENABLED)
+#include "context_gl_windows.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/windows/vulkan_context_win.h"
+#endif
+
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
@@ -170,9 +178,16 @@ class OS_Windows : public OS {
bool outside;
int old_x, old_y;
Point2i center;
+
#if defined(OPENGL_ENABLED)
- ContextGL_Windows *gl_context;
+ ContextGL_Windows *context_gles2;
#endif
+
+#if defined(VULKAN_ENABLED)
+ VulkanContextWindows *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
+#endif
+
VisualServer *visual_server;
int pressrc;
HINSTANCE hInstance; // Holds The Instance Of The Application
diff --git a/platform/windows/vulkan_context_win.cpp b/platform/windows/vulkan_context_win.cpp
new file mode 100644
index 0000000000..5e298897e7
--- /dev/null
+++ b/platform/windows/vulkan_context_win.cpp
@@ -0,0 +1,57 @@
+/*************************************************************************/
+/* vulkan_context_win.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "vulkan_context_win.h"
+#include <vulkan/vulkan_win32.h>
+
+const char *VulkanContextWindows::_get_platform_surface_extension() const {
+ return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
+}
+
+int VulkanContextWindows::window_create(HWND p_window, HINSTANCE p_instance, int p_width, int p_height) {
+
+ VkWin32SurfaceCreateInfoKHR createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.hinstance = p_instance;
+ createInfo.hwnd = p_window;
+
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateWin32SurfaceKHR(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
+}
+
+VulkanContextWindows::VulkanContextWindows() {
+}
+
+VulkanContextWindows::~VulkanContextWindows() {
+}
diff --git a/platform/windows/vulkan_context_win.h b/platform/windows/vulkan_context_win.h
new file mode 100644
index 0000000000..24fd759827
--- /dev/null
+++ b/platform/windows/vulkan_context_win.h
@@ -0,0 +1,48 @@
+/*************************************************************************/
+/* vulkan_context_win.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef VULKAN_DEVICE_WIN_H
+#define VULKAN_DEVICE_WIN_H
+
+#include "drivers/vulkan/vulkan_context.h"
+#include <windows.h>
+
+class VulkanContextWindows : public VulkanContext {
+
+ virtual const char *_get_platform_surface_extension() const;
+
+public:
+ int window_create(HWND p_window, HINSTANCE p_instance, int p_width, int p_height);
+
+ VulkanContextWindows();
+ ~VulkanContextWindows();
+};
+
+#endif // VULKAN_DEVICE_WIN_H