diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2019-07-12 16:18:30 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-02-11 11:57:34 +0100 |
commit | b456bfad5cee3922f55621bf7c133cc67337636a (patch) | |
tree | d3c77c49894591ea67dac3ad1551e9f36206b9c1 /platform/windows | |
parent | eb48be51dbe97aa4fbbbe0d0ebd8a98bee6b263e (diff) |
Add runtime GLES2 / Vulkan context selection.
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/SCsub | 9 | ||||
-rw-r--r-- | platform/windows/detect.py | 35 | ||||
-rwxr-xr-x | platform/windows/os_windows.cpp | 179 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 5 |
4 files changed, 105 insertions, 123 deletions
diff --git a/platform/windows/SCsub b/platform/windows/SCsub index cde8c3d480..6f01460025 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -13,14 +13,11 @@ common_win = [ "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" ] -if (env["renderer"] == "vulkan"): - common_win += ["vulkan_context_win.cpp"] -else: - common_win += ["context_gl_windows.cpp"] - res_file = 'godot_res.rc' res_target = "godot_res" + env["OBJSUFFIX"] res_obj = env.RES(res_target, res_file) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index a4873ac24e..0b65565a37 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -224,16 +224,15 @@ def configure_msvc(env, manual_msvc_config): 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt', 'Avrt', 'dwmapi'] - if (env["renderer"] == "vulkan"): - 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.Prepend(CPPPATH=['#thirdparty/vulkan/include/', "#thirdparty/vulkan/registry/"]) + env.AppendUnique(CPPDEFINES = ['VULKAN_ENABLED']) + if not env["builtin_vulkan_loader"]: + LIBS += ['vulkan'] else: - env.AppendUnique(CPPDEFINES = ['OPENGL_ENABLED']) - LIBS += ['opengl32'] + LIBS += ['cfgmgr32'] + + #env.AppendUnique(CPPDEFINES = ['OPENGL_ENABLED']) + LIBS += ['opengl32'] env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS]) @@ -362,16 +361,16 @@ def configure_mingw(env): env.Append(CPPDEFINES=[('WINVER', env['target_win_version']), ('_WIN32_WINNT', env['target_win_version'])]) env.Append(LIBS=['mingw32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi']) - if (env["renderer"] == "vulkan"): - 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']) + 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(CPPDEFINES=['OPENGL_ENABLED']) - env.Append(LIBS=['opengl32']) + 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 1f2fbd3f4f..40ced686c8 100755 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -38,10 +38,10 @@ #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/rasterizer_rd.h" +#include "servers/visual/rasterizer_rd/rasterizer_rd.h" #endif #include "drivers/windows/dir_access_windows.h" @@ -901,7 +901,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) set_window_size(Size2(video_mode.width, video_mode.height)); } #if defined(VULKAN_ENABLED) - context_vulkan->window_resize(0, video_mode.width, video_mode.height); + if (video_driver_index == VIDEO_DRIVER_VULKAN) { + context_vulkan->window_resize(0, video_mode.width, video_mode.height); + } #endif } @@ -1426,91 +1428,61 @@ 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; } - - video_driver_index = p_video_driver; - - gl_context->set_use_vsync(video_mode.use_vsync); - set_vsync_via_compositor(video_mode.vsync_via_compositor); #endif #if defined(VULKAN_ENABLED) - video_driver_index = VIDEO_DRIVER_VULKAN; + 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); + } - context_vulkan = memnew(VulkanContextWindows); - context_vulkan->initialize(); - context_vulkan->window_create(hWnd, hInstance, get_video_mode().width, get_video_mode().height); + //temporary + rendering_device_vulkan = memnew(RenderingDeviceVulkan); + rendering_device_vulkan->initialize(context_vulkan); - //temporary - rendering_device = memnew(RenderingDeviceVulkan); - rendering_device->initialize(context_vulkan); - RasterizerRD::make_current(); + RasterizerRD::make_current(); + } #endif + visual_server = memnew(VisualServerRaster); if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); @@ -1681,16 +1653,26 @@ void OS_Windows::finalize() { cursors_cache.clear(); visual_server->finish(); memdelete(visual_server); -#ifdef OPENGL_ENABLED - if (gl_context) - memdelete(gl_context); -#endif +#if defined(OPENGL_ENABLED) + if (video_driver_index == VIDEO_DRIVER_GLES2) { + + if (context_gles2) + memdelete(context_gles2); + + } +#endif #if defined(VULKAN_ENABLED) - rendering_device->finalize(); - memdelete(rendering_device); + if (video_driver_index == VIDEO_DRIVER_VULKAN) { + + if (rendering_device_vulkan) { + rendering_device_vulkan->finalize(); + memdelete(rendering_device_vulkan); + } - memdelete(context_vulkan); + if (context_vulkan) + memdelete(context_vulkan); + } #endif if (user_proc) { @@ -1992,9 +1974,10 @@ void OS_Windows::set_window_size(const Size2 p_size) { video_mode.width = w; video_mode.height = h; - #if defined(VULKAN_ENABLED) - context_vulkan->window_resize(0, video_mode.width, video_mode.height); + if (video_driver_index == VIDEO_DRIVER_VULKAN) { + context_vulkan->window_resize(0, video_mode.width, video_mode.height); + } #endif if (video_mode.fullscreen) { @@ -3154,22 +3137,30 @@ OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const { void OS_Windows::release_rendering_thread() { #if defined(OPENGL_ENABLED) - gl_context->release_current(); + if (video_driver_index == VIDEO_DRIVER_GLES2) { + context_gles2->release_current(); + } #endif } void OS_Windows::make_rendering_thread() { #if defined(OPENGL_ENABLED) - gl_context->make_current(); + if (video_driver_index == VIDEO_DRIVER_GLES2) { + context_gles2->make_current(); + } #endif } void OS_Windows::swap_buffers() { #if defined(OPENGL_ENABLED) - gl_context->swap_buffers(); + if (video_driver_index == VIDEO_DRIVER_GLES2) { + context_gles2->swap_buffers(); + } #endif #if defined(VULKAN_ENABLED) - context_vulkan->swap_buffers(); + if (video_driver_index == VIDEO_DRIVER_VULKAN) { + context_vulkan->swap_buffers(); + } #endif } @@ -3338,18 +3329,12 @@ String OS_Windows::get_joy_guid(int p_device) const { void OS_Windows::_set_use_vsync(bool p_enable) { #if defined(OPENGL_ENABLED) - if (gl_context) - gl_context->set_use_vsync(p_enable); + 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 64c7ed56dc..89b67f8d91 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -178,13 +178,14 @@ 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; + RenderingDeviceVulkan *rendering_device_vulkan; #endif VisualServer *visual_server; |