summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/export/export.cpp4
-rw-r--r--platform/iphone/export/export.cpp2
-rw-r--r--platform/iphone/semaphore_iphone.cpp2
-rw-r--r--platform/iphone/semaphore_iphone.h4
-rw-r--r--platform/javascript/export/export.cpp8
-rw-r--r--platform/javascript/os_javascript.cpp2
-rw-r--r--platform/osx/SCsub2
-rw-r--r--platform/osx/context_gl_osx.h75
-rw-r--r--platform/osx/context_gl_osx.mm172
-rw-r--r--platform/osx/detect.py24
-rw-r--r--platform/osx/export/export.cpp2
-rw-r--r--platform/osx/godot_main_osx.mm6
-rw-r--r--platform/osx/os_osx.h21
-rw-r--r--platform/osx/os_osx.mm384
-rw-r--r--platform/osx/semaphore_osx.cpp2
-rw-r--r--platform/osx/semaphore_osx.h4
-rw-r--r--platform/osx/vulkan_context_osx.h48
-rw-r--r--platform/osx/vulkan_context_osx.mm56
-rw-r--r--platform/uwp/export/export.cpp2
-rw-r--r--platform/windows/SCsub5
-rw-r--r--platform/windows/detect.py31
-rwxr-xr-xplatform/windows/os_windows.cpp190
-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
-rw-r--r--platform/x11/SCsub1
-rw-r--r--platform/x11/detect.py15
-rw-r--r--platform/x11/os_x11.cpp277
-rw-r--r--platform/x11/os_x11.h18
-rw-r--r--platform/x11/vulkan_context_x11.cpp57
-rw-r--r--platform/x11/vulkan_context_x11.h48
31 files changed, 1142 insertions, 444 deletions
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 78d87c5629..7bbcb8cfa2 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -1424,7 +1424,7 @@ public:
return "Android";
}
- virtual Ref<Texture> get_logo() const {
+ virtual Ref<Texture2D> get_logo() const {
return logo;
}
@@ -1639,7 +1639,7 @@ public:
#undef CLEANUP_AND_RETURN
}
- virtual Ref<Texture> get_run_icon() const {
+ virtual Ref<Texture2D> get_run_icon() const {
return run_icon;
}
diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp
index 3561be8174..f9276c16b5 100644
--- a/platform/iphone/export/export.cpp
+++ b/platform/iphone/export/export.cpp
@@ -137,7 +137,7 @@ protected:
public:
virtual String get_name() const { return "iOS"; }
virtual String get_os_name() const { return "iOS"; }
- virtual Ref<Texture> get_logo() const { return logo; }
+ virtual Ref<Texture2D> get_logo() const { return logo; }
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
List<String> list;
diff --git a/platform/iphone/semaphore_iphone.cpp b/platform/iphone/semaphore_iphone.cpp
index 0c1d4d2d5c..0461f58c40 100644
--- a/platform/iphone/semaphore_iphone.cpp
+++ b/platform/iphone/semaphore_iphone.cpp
@@ -91,7 +91,7 @@ int SemaphoreIphone::get() const {
return 0;
}
-Semaphore *SemaphoreIphone::create_semaphore_iphone() {
+SemaphoreOld *SemaphoreIphone::create_semaphore_iphone() {
return memnew(SemaphoreIphone);
}
diff --git a/platform/iphone/semaphore_iphone.h b/platform/iphone/semaphore_iphone.h
index 9356c65f1e..54ff3c17f9 100644
--- a/platform/iphone/semaphore_iphone.h
+++ b/platform/iphone/semaphore_iphone.h
@@ -39,11 +39,11 @@ typedef struct cgsem cgsem_t;
#include "core/os/semaphore.h"
-class SemaphoreIphone : public Semaphore {
+class SemaphoreIphone : public SemaphoreOld {
mutable cgsem_t sem;
- static Semaphore *create_semaphore_iphone();
+ static SemaphoreOld *create_semaphore_iphone();
public:
virtual Error wait();
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index c1cb8bcb58..6e1f7d749b 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -212,7 +212,7 @@ public:
virtual String get_name() const;
virtual String get_os_name() const;
- virtual Ref<Texture> get_logo() const;
+ virtual Ref<Texture2D> get_logo() const;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
@@ -224,7 +224,7 @@ public:
virtual String get_option_tooltip(int p_index) const { return p_index ? TTR("Stop HTTP Server") : TTR("Run exported HTML in the system's default browser."); }
virtual Ref<ImageTexture> get_option_icon(int p_index) const;
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags);
- virtual Ref<Texture> get_run_icon() const;
+ virtual Ref<Texture2D> get_run_icon() const;
virtual void get_platform_features(List<String> *r_features) {
@@ -300,7 +300,7 @@ String EditorExportPlatformJavaScript::get_os_name() const {
return "HTML5";
}
-Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
+Ref<Texture2D> EditorExportPlatformJavaScript::get_logo() const {
return logo;
}
@@ -598,7 +598,7 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese
return OK;
}
-Ref<Texture> EditorExportPlatformJavaScript::get_run_icon() const {
+Ref<Texture2D> EditorExportPlatformJavaScript::get_run_icon() const {
return run_icon;
}
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 13615de65b..f657ef483e 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -480,7 +480,7 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index e15b4339a7..09f213cb0e 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -13,6 +13,8 @@ files = [
'dir_access_osx.mm',
'joypad_osx.cpp',
'power_osx.cpp',
+ 'vulkan_context_osx.mm',
+ 'context_gl_osx.mm'
]
prog = env.add_program('#bin/godot', files)
diff --git a/platform/osx/context_gl_osx.h b/platform/osx/context_gl_osx.h
new file mode 100644
index 0000000000..6e73c2203a
--- /dev/null
+++ b/platform/osx/context_gl_osx.h
@@ -0,0 +1,75 @@
+/*************************************************************************/
+/* context_gl_osx.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 CONTEXT_GL_OSX_H
+#define CONTEXT_GL_OSX_H
+
+#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED)
+
+#include "core/error_list.h"
+#include "core/os/os.h"
+
+#include <AppKit/AppKit.h>
+#include <ApplicationServices/ApplicationServices.h>
+#include <CoreVideo/CoreVideo.h>
+
+class ContextGL_OSX {
+
+ bool opengl_3_context;
+ bool use_vsync;
+
+ void *framework;
+ id window_view;
+ NSOpenGLPixelFormat *pixelFormat;
+ NSOpenGLContext *context;
+
+public:
+ void release_current();
+
+ void make_current();
+ void update();
+
+ void set_opacity(GLint p_opacity);
+
+ int get_window_width();
+ int get_window_height();
+ void swap_buffers();
+
+ Error initialize();
+
+ void set_use_vsync(bool p_use);
+ bool is_using_vsync() const;
+
+ ContextGL_OSX(id p_view, bool p_opengl_3_context);
+ ~ContextGL_OSX();
+};
+
+#endif
+#endif \ No newline at end of file
diff --git a/platform/osx/context_gl_osx.mm b/platform/osx/context_gl_osx.mm
new file mode 100644
index 0000000000..91d1332d24
--- /dev/null
+++ b/platform/osx/context_gl_osx.mm
@@ -0,0 +1,172 @@
+/*************************************************************************/
+/* context_gl_osx.mm */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 "context_gl_osx.h"
+
+#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED)
+
+void ContextGL_OSX::release_current() {
+
+ [NSOpenGLContext clearCurrentContext];
+}
+
+void ContextGL_OSX::make_current() {
+
+ [context makeCurrentContext];
+}
+
+void ContextGL_OSX::update() {
+
+ [context update];
+}
+
+void ContextGL_OSX::set_opacity(GLint p_opacity) {
+
+ [context setValues:&p_opacity forParameter:NSOpenGLCPSurfaceOpacity];
+}
+
+int ContextGL_OSX::get_window_width() {
+
+ return OS::get_singleton()->get_video_mode().width;
+}
+
+int ContextGL_OSX::get_window_height() {
+
+ return OS::get_singleton()->get_video_mode().height;
+}
+
+void ContextGL_OSX::swap_buffers() {
+
+ [context flushBuffer];
+}
+
+void ContextGL_OSX::set_use_vsync(bool p_use) {
+
+ CGLContextObj ctx = CGLGetCurrentContext();
+ if (ctx) {
+ GLint swapInterval = p_use ? 1 : 0;
+ CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+ use_vsync = p_use;
+ }
+}
+
+bool ContextGL_OSX::is_using_vsync() const {
+
+ return use_vsync;
+}
+
+Error ContextGL_OSX::initialize() {
+
+ framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
+ ERR_FAIL_COND_V(!framework, ERR_CANT_CREATE);
+
+ unsigned int attributeCount = 0;
+
+ // OS X needs non-zero color size, so set reasonable values
+ int colorBits = 32;
+
+ // Fail if a robustness strategy was requested
+
+#define ADD_ATTR(x) \
+ { attributes[attributeCount++] = x; }
+#define ADD_ATTR2(x, y) \
+ { \
+ ADD_ATTR(x); \
+ ADD_ATTR(y); \
+ }
+
+ // Arbitrary array size here
+ NSOpenGLPixelFormatAttribute attributes[40];
+
+ ADD_ATTR(NSOpenGLPFADoubleBuffer);
+ ADD_ATTR(NSOpenGLPFAClosestPolicy);
+
+ if (!opengl_3_context) {
+ ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy);
+ } else {
+ //we now need OpenGL 3 or better, maybe even change this to 3_3Core ?
+ ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
+ }
+
+ ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
+
+ /*
+ if (fbconfig->alphaBits > 0)
+ ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
+*/
+
+ ADD_ATTR2(NSOpenGLPFADepthSize, 24);
+
+ ADD_ATTR2(NSOpenGLPFAStencilSize, 8);
+
+ /*
+ if (fbconfig->stereo)
+ ADD_ATTR(NSOpenGLPFAStereo);
+*/
+
+ /*
+ if (fbconfig->samples > 0) {
+ ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
+ ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
+ }
+*/
+
+ // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
+ // framebuffer, so there's no need (and no way) to request it
+
+ ADD_ATTR(0);
+
+#undef ADD_ATTR
+#undef ADD_ATTR2
+
+ pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
+ ERR_FAIL_COND_V(pixelFormat == nil, ERR_CANT_CREATE);
+
+ context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
+
+ ERR_FAIL_COND_V(context == nil, ERR_CANT_CREATE);
+
+ [context setView:window_view];
+
+ [context makeCurrentContext];
+
+ return OK;
+}
+
+ContextGL_OSX::ContextGL_OSX(id p_view, bool p_opengl_3_context) {
+
+ opengl_3_context = p_opengl_3_context;
+ window_view = p_view;
+ use_vsync = false;
+}
+
+ContextGL_OSX::~ContextGL_OSX() {}
+
+#endif
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index fe839199e8..0b164a2c56 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -1,5 +1,6 @@
import os
import sys
+import subprocess
from methods import detect_darwin_sdk_path
@@ -25,6 +26,7 @@ def get_opts():
return [
('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
('MACOS_SDK_PATH', 'Path to the macOS SDK', ''),
+ BoolVariable('use_static_mvk', 'Link MoltenVK statically as Level-0 driver (better portability) or use Vulkan ICD loader (enables validation layers)', False),
EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')),
BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False),
BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False),
@@ -148,9 +150,19 @@ def configure(env):
## Flags
env.Prepend(CPPPATH=['#platform/osx'])
- env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'GLES_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
- env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'AVFoundation', '-framework', 'CoreMedia', '-framework', 'CoreVideo'])
- env.Append(LIBS=['pthread'])
-
- env.Append(CCFLAGS=['-mmacosx-version-min=10.9'])
- env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])
+ env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
+ env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo', '-framework', 'AVFoundation', '-framework', 'CoreMedia'])
+ env.Append(LIBS=['pthread', 'z'])
+
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ env.Append(LINKFLAGS=['-framework', 'Metal', '-framework', 'QuartzCore', '-framework', 'IOSurface'])
+ if (env['use_static_mvk']):
+ env.Append(LINKFLAGS=['-framework', 'MoltenVK'])
+ env['builtin_vulkan'] = False
+ elif not env['builtin_vulkan']:
+ env.Append(LIBS=['vulkan'])
+
+ #env.Append(CPPDEFINES=['GLES_ENABLED', 'OPENGL_ENABLED'])
+
+ env.Append(CCFLAGS=['-mmacosx-version-min=10.11'])
+ env.Append(LINKFLAGS=['-mmacosx-version-min=10.11'])
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index f372093268..312987b8cb 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -74,7 +74,7 @@ protected:
public:
virtual String get_name() const { return "Mac OSX"; }
virtual String get_os_name() const { return "OSX"; }
- virtual Ref<Texture> get_logo() const { return logo; }
+ virtual Ref<Texture2D> get_logo() const { return logo; }
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
List<String> list;
diff --git a/platform/osx/godot_main_osx.mm b/platform/osx/godot_main_osx.mm
index e6f8cbecf1..eacd2b5cc6 100644
--- a/platform/osx/godot_main_osx.mm
+++ b/platform/osx/godot_main_osx.mm
@@ -36,6 +36,12 @@
#include <unistd.h>
int main(int argc, char **argv) {
+
+#if defined(VULKAN_ENABLED)
+ //MoltenVK - enable full component swizzling support
+ setenv("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE", "1", 1);
+#endif
+
int first_arg = 1;
const char *dbg_arg = "-NSDocumentRevisionsDebugMode";
printf("arguments\n");
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 190dbcf662..00fc56def6 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -46,6 +46,15 @@
#include "servers/visual/visual_server_wrap_mt.h"
#include "servers/visual_server.h"
+#if defined(OPENGL_ENABLED)
+#include "context_gl_osx.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/osx/vulkan_context_osx.h"
+#endif
+
#include <AppKit/AppKit.h>
#include <AppKit/NSCursor.h>
#include <ApplicationServices/ApplicationServices.h>
@@ -93,7 +102,6 @@ public:
void process_events();
void process_key_events();
- void *framework;
// pthread_key_t current;
bool mouse_grab;
Point2 mouse_pos;
@@ -104,8 +112,15 @@ public:
id window_view;
id autoreleasePool;
id cursor;
- NSOpenGLPixelFormat *pixelFormat;
- NSOpenGLContext *context;
+
+#if defined(OPENGL_ENABLED)
+ ContextGL_OSX *context_gles2;
+#endif
+
+#if defined(VULKAN_ENABLED)
+ VulkanContextOSX *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
+#endif
bool layered_window;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 314f369dc6..87ab8b3420 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -34,11 +34,19 @@
#include "core/print_string.h"
#include "core/version_generated.gen.h"
#include "dir_access_osx.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 "main/main.h"
#include "semaphore_osx.h"
#include "servers/visual/visual_server_raster.h"
+#include "servers/visual/visual_server_wrap_mt.h"
#include <mach-o/dyld.h>
@@ -52,6 +60,9 @@
#include <os/log.h>
#endif
+#import <QuartzCore/CAMetalLayer.h>
+#include <vulkan/vulkan_metal.h>
+
#include <dlfcn.h>
#include <fcntl.h>
#include <libproc.h>
@@ -260,29 +271,6 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
return NSTerminateCancel;
}
-- (void)applicationDidHide:(NSNotification *)notification {
- /*
- _Godotwindow* window;
- for (window = _Godot.windowListHead; window; window = window->next)
- _GodotInputWindowVisibility(window, GL_FALSE);
-*/
-}
-
-- (void)applicationDidUnhide:(NSNotification *)notification {
- /*
- _Godotwindow* window;
-
- for (window = _Godot.windowListHead; window; window = window->next) {
- if ([window_object isVisible])
- _GodotInputWindowVisibility(window, GL_TRUE);
- }
-*/
-}
-
-- (void)applicationDidChangeScreenParameters:(NSNotification *)notification {
- //_GodotInputMonitorChange();
-}
-
- (void)showAbout:(id)sender {
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_ABOUT);
@@ -294,6 +282,8 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
//_Godotwindow* window;
}
+- (void)windowWillClose:(NSNotification *)notification;
+
@end
@implementation GodotWindowDelegate
@@ -306,6 +296,24 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
return NO;
}
+- (void)windowWillClose:(NSNotification *)notification {
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+
+ if (OS_OSX::singleton->rendering_device_vulkan) {
+ OS_OSX::singleton->rendering_device_vulkan->finalize();
+ memdelete(OS_OSX::singleton->rendering_device_vulkan);
+ OS_OSX::singleton->rendering_device_vulkan = NULL;
+ }
+
+ if (OS_OSX::singleton->context_vulkan) {
+ memdelete(OS_OSX::singleton->context_vulkan);
+ OS_OSX::singleton->context_vulkan = NULL;
+ }
+ }
+#endif
+}
+
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
OS_OSX::singleton->zoomed = true;
@@ -336,11 +344,16 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
NSWindow *window = (NSWindow *)[notification object];
CGFloat newBackingScaleFactor = [window backingScaleFactor];
CGFloat oldBackingScaleFactor = [[[notification userInfo] objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue];
- if (OS_OSX::singleton->is_hidpi_allowed()) {
- [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:YES];
- } else {
- [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:NO];
+
+#if defined(OPENGL_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_GLES2) {
+ if (OS_OSX::singleton->is_hidpi_allowed()) {
+ [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:YES];
+ } else {
+ [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:NO];
+ }
}
+#endif
if (newBackingScaleFactor != oldBackingScaleFactor) {
//Set new display scale and window size
@@ -352,6 +365,12 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
OS_OSX::singleton->window_size.width = fbRect.size.width * newDisplayScale;
OS_OSX::singleton->window_size.height = fbRect.size.height * newDisplayScale;
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ CALayer *layer = [OS_OSX::singleton->window_view layer];
+ layer.contentsScale = OS_OSX::singleton->_display_scale();
+ }
+#endif
//Update context
if (OS_OSX::singleton->main_loop) {
//Force window resize event
@@ -361,8 +380,12 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
}
- (void)windowDidResize:(NSNotification *)notification {
- [OS_OSX::singleton->context update];
+#if defined(OPENGL_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_GLES2) {
+ OS_OSX::singleton->context_gles2->update();
+ }
+#endif
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
const NSRect fbRect = contentRect;
@@ -370,6 +393,14 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
OS_OSX::singleton->window_size.width = fbRect.size.width * displayScale;
OS_OSX::singleton->window_size.height = fbRect.size.height * displayScale;
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ CALayer *layer = [OS_OSX::singleton->window_view layer];
+ layer.contentsScale = OS_OSX::singleton->_display_scale();
+ OS_OSX::singleton->context_vulkan->window_resize(0, OS_OSX::singleton->window_size.width, OS_OSX::singleton->window_size.height);
+ }
+#endif
+
if (OS_OSX::singleton->main_loop) {
Main::force_redraw();
//Event retrieval blocks until resize is over. Call Main::iteration() directly.
@@ -377,15 +408,6 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
Main::iteration();
}
}
-
- /*
- _GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
- _GodotInputWindowSize(window, contentRect.size.width, contentRect.size.height);
- _GodotInputWindowDamage(window);
-
- if (window->cursorMode == Godot_CURSOR_DISABLED)
- centerCursor(window);
-*/
}
- (void)windowDidMove:(NSNotification *)notification {
@@ -393,17 +415,6 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
if (OS_OSX::singleton->get_main_loop()) {
OS_OSX::singleton->input->release_pressed_events();
}
-
- /*
- [window->nsgl.context update];
-
- int x, y;
- _GodotPlatformGetWindowPos(window, &x, &y);
- _GodotInputWindowPos(window, x, y);
-
- if (window->cursorMode == Godot_CURSOR_DISABLED)
- centerCursor(window);
-*/
}
- (void)windowDidBecomeKey:(NSNotification *)notification {
@@ -450,8 +461,12 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
bool imeInputEventInProgress;
}
- (void)cancelComposition;
+
+- (CALayer *)makeBackingLayer;
+
- (BOOL)wantsUpdateLayer;
- (void)updateLayer;
+
@end
@implementation GodotContentView
@@ -462,12 +477,32 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
}
}
-- (BOOL)wantsUpdateLayer {
- return YES;
+- (CALayer *)makeBackingLayer {
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ CALayer *layer = [[CAMetalLayer class] layer];
+ layer.contentsScale = OS_OSX::singleton->_display_scale();
+ return layer;
+ }
+#endif
+ return [super makeBackingLayer];
}
- (void)updateLayer {
- [OS_OSX::singleton->context update];
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ [super updateLayer];
+ }
+#endif
+#if defined(OPENGL_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_GLES2) {
+ OS_OSX::singleton->context_gles2->update();
+ }
+#endif
+}
+
+- (BOOL)wantsUpdateLayer {
+ return YES;
}
- (id)init {
@@ -1458,6 +1493,14 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
// Register to be notified on displays arrangement changes
CGDisplayRegisterReconfigurationCallback(displays_arrangement_changed, NULL);
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //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) + "]");
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+ //Create window
+
window_delegate = [[GodotWindowDelegate alloc] init];
// Don't use accumulation buffer support; it's not accelerated
@@ -1498,14 +1541,20 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
window_size.height = p_desired.height * displayScale;
if (displayScale > 1.0) {
- [window_view setWantsBestResolutionOpenGLSurface:YES];
- //if (current_videomode.resizable)
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ [window_view setWantsBestResolutionOpenGLSurface:YES];
+ }
+#endif
[window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
} else {
- [window_view setWantsBestResolutionOpenGLSurface:NO];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ [window_view setWantsBestResolutionOpenGLSurface:NO];
+ }
+#endif
}
- //[window_object setTitle:[NSString stringWithUTF8String:"GodotEnginies"]];
[window_object setContentView:window_view];
[window_object setDelegate:window_delegate];
[window_object setAcceptsMouseMovedEvents:YES];
@@ -1513,77 +1562,51 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
[window_object setRestorable:NO];
- unsigned int attributeCount = 0;
+ // Init context and rendering device
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
- // OS X needs non-zero color size, so set reasonable values
- int colorBits = 32;
+ context_gles2 = memnew(ContextGL_OSX(window_view, false));
- // Fail if a robustness strategy was requested
-
-#define ADD_ATTR(x) \
- { attributes[attributeCount++] = x; }
-#define ADD_ATTR2(x, y) \
- { \
- ADD_ATTR(x); \
- ADD_ATTR(y); \
- }
-
- // Arbitrary array size here
- NSOpenGLPixelFormatAttribute attributes[40];
+ if (context_gles2->initialize() != OK) {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- ADD_ATTR(NSOpenGLPFADoubleBuffer);
- ADD_ATTR(NSOpenGLPFAClosestPolicy);
+ context_gles2->set_use_vsync(p_desired.use_vsync);
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy);
- } else {
- //we now need OpenGL 3 or better, maybe even change this to 3_3Core ?
- ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
}
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ context_vulkan = memnew(VulkanContextOSX);
+ if (context_vulkan->initialize() != OK) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
+ if (context_vulkan->window_create(window_view, get_video_mode().width, get_video_mode().height) == -1) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
-
- /*
- if (fbconfig->alphaBits > 0)
- ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
-*/
-
- ADD_ATTR2(NSOpenGLPFADepthSize, 24);
-
- ADD_ATTR2(NSOpenGLPFAStencilSize, 8);
-
- /*
- if (fbconfig->stereo)
- ADD_ATTR(NSOpenGLPFAStereo);
-*/
+ rendering_device_vulkan = memnew(RenderingDeviceVulkan);
+ rendering_device_vulkan->initialize(context_vulkan);
- /*
- if (fbconfig->samples > 0) {
- ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
- ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
+ RasterizerRD::make_current();
}
-*/
-
- // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
- // framebuffer, so there's no need (and no way) to request it
-
- ADD_ATTR(0);
-
-#undef ADD_ATTR
-#undef ADD_ATTR2
-
- pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
- ERR_FAIL_COND_V(pixelFormat == nil, ERR_UNAVAILABLE);
-
- context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
-
- ERR_FAIL_COND_V(context == nil, ERR_UNAVAILABLE);
-
- [context setView:window_view];
-
- [context makeCurrentContext];
-
- set_use_vsync(p_desired.use_vsync);
+#endif
[NSApp activateIgnoringOtherApps:YES];
@@ -1594,53 +1617,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
if (p_desired.fullscreen)
zoomed = true;
- /*** END OSX INITIALIZATION ***/
-
- bool gles3 = true;
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gles3 = false;
- }
-
- bool editor = Engine::get_singleton()->is_editor_hint();
- bool gl_initialization_error = false;
-
- while (true) {
- if (gles3) {
- 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 = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- } else {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- }
-
- 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;
-
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));
@@ -1673,6 +1649,14 @@ void OS_OSX::finalize() {
midi_driver.close();
#endif
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+
+ if (context_gles2)
+ memdelete(context_gles2);
+ }
+#endif
+
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
CGDisplayRemoveReconfigurationCallback(displays_arrangement_changed, NULL);
@@ -1684,7 +1668,6 @@ void OS_OSX::finalize() {
cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
- //memdelete(rasterizer);
}
void OS_OSX::set_main_loop(MainLoop *p_main_loop) {
@@ -1861,7 +1844,7 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -1916,7 +1899,6 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
image->lock();
- /* Premultiply the alpha channel */
for (int i = 0; i < len; i++) {
int row_index = floor(i / texture_size.width) + atlas_rect.position.y;
int column_index = (i % int(texture_size.width)) + atlas_rect.position.x;
@@ -2228,13 +2210,19 @@ String OS_OSX::get_clipboard() const {
}
void OS_OSX::release_rendering_thread() {
-
- [NSOpenGLContext clearCurrentContext];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->release_current();
+ }
+#endif
}
void OS_OSX::make_rendering_thread() {
-
- [context makeCurrentContext];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->make_current();
+ }
+#endif
}
Error OS_OSX::shell_open(String p_uri) {
@@ -2249,7 +2237,16 @@ String OS_OSX::get_locale() const {
}
void OS_OSX::swap_buffers() {
- [context flushBuffer];
+#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_OSX::wm_minimized(bool p_minimized) {
@@ -2659,21 +2656,31 @@ void OS_OSX::set_window_per_pixel_transparency_enabled(bool p_enabled) {
if (layered_window != p_enabled) {
if (p_enabled) {
set_borderless_window(true);
- GLint opacity = 0;
[window_object setBackgroundColor:[NSColor clearColor]];
[window_object setOpaque:NO];
[window_object setHasShadow:NO];
- [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->set_opacity(0);
+ }
+#endif
layered_window = true;
} else {
- GLint opacity = 1;
[window_object setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1]];
[window_object setOpaque:YES];
[window_object setHasShadow:YES];
- [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->set_opacity(1);
+ }
+#endif
layered_window = false;
}
- [context update];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->update();
+ }
+#endif
NSRect frame = [window_object frame];
[window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, 1, 1) display:YES];
[window_object setFrame:frame display:YES];
@@ -2992,11 +2999,12 @@ Error OS_OSX::move_to_trash(const String &p_path) {
}
void OS_OSX::_set_use_vsync(bool p_enable) {
- CGLContextObj ctx = CGLGetCurrentContext();
- if (ctx) {
- GLint swapInterval = p_enable ? 1 : 0;
- CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (context_gles2)
+ context_gles2->set_use_vsync(p_enable);
}
+#endif
}
OS_OSX *OS_OSX::singleton = NULL;
@@ -3018,16 +3026,6 @@ OS_OSX::OS_OSX() {
CGEventSourceSetLocalEventsSuppressionInterval(eventSource, 0.0);
- /*
- if (pthread_key_create(&_Godot.nsgl.current, NULL) != 0) {
- _GodotInputError(Godot_PLATFORM_ERROR, "NSGL: Failed to create context TLS");
- return GL_FALSE;
- }
-*/
-
- framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
- ERR_FAIL_COND(!framework);
-
// Implicitly create shared NSApplication instance
[GodotApplication sharedApplication];
diff --git a/platform/osx/semaphore_osx.cpp b/platform/osx/semaphore_osx.cpp
index e75f5103cc..e4e5991637 100644
--- a/platform/osx/semaphore_osx.cpp
+++ b/platform/osx/semaphore_osx.cpp
@@ -86,7 +86,7 @@ int SemaphoreOSX::get() const {
return 0;
}
-Semaphore *SemaphoreOSX::create_semaphore_osx() {
+SemaphoreOld *SemaphoreOSX::create_semaphore_osx() {
return memnew(SemaphoreOSX);
}
diff --git a/platform/osx/semaphore_osx.h b/platform/osx/semaphore_osx.h
index 2348c8efa6..9aa2b47bc8 100644
--- a/platform/osx/semaphore_osx.h
+++ b/platform/osx/semaphore_osx.h
@@ -39,11 +39,11 @@ typedef struct cgsem cgsem_t;
#include "core/os/semaphore.h"
-class SemaphoreOSX : public Semaphore {
+class SemaphoreOSX : public SemaphoreOld {
mutable cgsem_t sem;
- static Semaphore *create_semaphore_osx();
+ static SemaphoreOld *create_semaphore_osx();
public:
virtual Error wait();
diff --git a/platform/osx/vulkan_context_osx.h b/platform/osx/vulkan_context_osx.h
new file mode 100644
index 0000000000..619e91d1f6
--- /dev/null
+++ b/platform/osx/vulkan_context_osx.h
@@ -0,0 +1,48 @@
+/*************************************************************************/
+/* vulkan_context_osx.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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_OSX_H
+#define VULKAN_DEVICE_OSX_H
+
+#include "drivers/vulkan/vulkan_context.h"
+#include <AppKit/AppKit.h>
+
+class VulkanContextOSX : public VulkanContext {
+
+ virtual const char *_get_platform_surface_extension() const;
+
+public:
+ int window_create(id p_window, int p_width, int p_height);
+
+ VulkanContextOSX();
+ ~VulkanContextOSX();
+};
+
+#endif // VULKAN_DEVICE_OSX_H
diff --git a/platform/osx/vulkan_context_osx.mm b/platform/osx/vulkan_context_osx.mm
new file mode 100644
index 0000000000..c132bd334a
--- /dev/null
+++ b/platform/osx/vulkan_context_osx.mm
@@ -0,0 +1,56 @@
+/*************************************************************************/
+/* vulkan_context_osx.mm */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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_osx.h"
+#include <vulkan/vulkan_macos.h>
+
+const char *VulkanContextOSX::_get_platform_surface_extension() const {
+ return VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
+}
+
+int VulkanContextOSX::window_create(id p_window, int p_width, int p_height) {
+
+ VkMacOSSurfaceCreateInfoMVK createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.pView = p_window;
+
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateMacOSSurfaceMVK(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
+}
+
+VulkanContextOSX::VulkanContextOSX() {
+}
+
+VulkanContextOSX::~VulkanContextOSX() {
+}
diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp
index 96a196c65d..533293387d 100644
--- a/platform/uwp/export/export.cpp
+++ b/platform/uwp/export/export.cpp
@@ -1004,7 +1004,7 @@ public:
return list;
}
- virtual Ref<Texture> get_logo() const {
+ virtual Ref<Texture2D> get_logo() const {
return logo;
}
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..3ab0d38a6a 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,20 @@ 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.AppendUnique(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env['builtin_vulkan']:
+ 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 +355,20 @@ 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.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env['builtin_vulkan']:
+ 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 2daaf9359a..133dc9004d 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,58 @@ 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);
}
}
+#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);
+ }
- 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;
+ //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 +1652,25 @@ 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 +1972,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;
@@ -2517,7 +2530,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -3121,18 +3134,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 +3326,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..20e1b46682
--- /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-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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..1289f2a299
--- /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-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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
diff --git a/platform/x11/SCsub b/platform/x11/SCsub
index 3d5aa15208..9027c244be 100644
--- a/platform/x11/SCsub
+++ b/platform/x11/SCsub
@@ -7,6 +7,7 @@ import platform_x11_builders
common_x11 = [
"context_gl_x11.cpp",
+ "vulkan_context_x11.cpp",
"crash_handler_x11.cpp",
"os_x11.cpp",
"key_mapping_x11.cpp",
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index bd5e5e0812..9d5affcb3c 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -318,8 +318,19 @@ def configure(env):
env.ParseConfig('pkg-config zlib --cflags --libs')
env.Prepend(CPPPATH=['#platform/x11'])
- env.Append(CPPDEFINES=['X11_ENABLED', 'UNIX_ENABLED', 'OPENGL_ENABLED', 'GLES_ENABLED'])
- env.Append(LIBS=['GL', 'pthread'])
+ env.Append(CPPDEFINES=['X11_ENABLED', 'UNIX_ENABLED'])
+
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env['builtin_vulkan']:
+ env.ParseConfig('pkg-config vulkan --cflags --libs')
+ if not env['builtin_glslang']:
+ # No pkgconfig file for glslang so far
+ env.Append(LIBS=['glslang', 'SPIRV'])
+
+ #env.Append(CPPDEFINES=['OPENGL_ENABLED'])
+ env.Append(LIBS=['GL'])
+
+ env.Append(LIBS=['pthread'])
if (platform.system() == "Linux"):
env.Append(LIBS=['dl'])
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 1cd763853c..338194fcae 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -33,10 +33,17 @@
#include "core/os/dir_access.h"
#include "core/print_string.h"
-#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
#include "errno.h"
#include "key_mapping_x11.h"
+
+#if defined(OPENGL_ENABLED)
+#include "drivers/gles2/rasterizer_gles2.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
+#endif
+
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@@ -230,137 +237,126 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
XFree(imvalret);
}
-/*
- char* windowid = getenv("GODOT_WINDOWID");
- if (windowid) {
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //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) + "]");
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
- //freopen("/home/punto/stdout", "w", stdout);
- //reopen("/home/punto/stderr", "w", stderr);
- x11_window = atol(windowid);
+ //Create window
- XWindowAttributes xwa;
- XGetWindowAttributes(x11_display,x11_window,&xwa);
+ long visualMask = VisualScreenMask;
+ int numberOfVisuals;
+ XVisualInfo vInfoTemplate = {};
+ vInfoTemplate.screen = DefaultScreen(x11_display);
+ XVisualInfo *visualInfo = XGetVisualInfo(x11_display, visualMask, &vInfoTemplate, &numberOfVisuals);
- current_videomode.width = xwa.width;
- current_videomode.height = xwa.height;
- };
- */
+ Colormap colormap = XCreateColormap(x11_display, RootWindow(x11_display, vInfoTemplate.screen), visualInfo->visual, AllocNone);
-// maybe contextgl wants to be in charge of creating the window
-#if defined(OPENGL_ENABLED)
- if (getenv("DRI_PRIME") == NULL) {
- int use_prime = -1;
+ XSetWindowAttributes windowAttributes = {};
+ windowAttributes.colormap = colormap;
+ windowAttributes.background_pixel = 0xFFFFFFFF;
+ windowAttributes.border_pixel = 0;
+ windowAttributes.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask | ExposureMask;
- if (getenv("PRIMUS_DISPLAY") ||
- getenv("PRIMUS_libGLd") ||
- getenv("PRIMUS_libGLa") ||
- getenv("PRIMUS_libGL") ||
- getenv("PRIMUS_LOAD_GLOBAL") ||
- getenv("BUMBLEBEE_SOCKET")) {
+ unsigned long valuemask = CWBorderPixel | CWColormap | CWEventMask;
+ x11_window = XCreateWindow(x11_display, RootWindow(x11_display, visualInfo->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, visualInfo->depth, InputOutput, visualInfo->visual, valuemask, &windowAttributes);
- print_verbose("Optirun/primusrun detected. Skipping GPU detection");
- use_prime = 0;
- }
+ //set_class_hint(x11_display, x11_window);
+ XMapWindow(x11_display, x11_window);
+ XFlush(x11_display);
- if (getenv("LD_LIBRARY_PATH")) {
- String ld_library_path(getenv("LD_LIBRARY_PATH"));
- Vector<String> libraries = ld_library_path.split(":");
+ XSync(x11_display, False);
+ //XSetErrorHandler(oldHandler);
- for (int i = 0; i < libraries.size(); ++i) {
- if (FileAccess::exists(libraries[i] + "/libGL.so.1") ||
- FileAccess::exists(libraries[i] + "/libGL.so")) {
+ XFree(visualInfo);
- print_verbose("Custom libGL override detected. Skipping GPU detection");
- use_prime = 0;
- }
+ // Init context and rendering device
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (getenv("DRI_PRIME") == NULL) {
+ int use_prime = -1;
+
+ if (getenv("PRIMUS_DISPLAY") ||
+ getenv("PRIMUS_libGLd") ||
+ getenv("PRIMUS_libGLa") ||
+ getenv("PRIMUS_libGL") ||
+ getenv("PRIMUS_LOAD_GLOBAL") ||
+ getenv("BUMBLEBEE_SOCKET")) {
+
+ print_verbose("Optirun/primusrun detected. Skipping GPU detection");
+ use_prime = 0;
}
- }
-
- if (use_prime == -1) {
- print_verbose("Detecting GPUs, set DRI_PRIME in the environment to override GPU detection logic.");
- use_prime = detect_prime();
- }
- if (use_prime) {
- print_line("Found discrete GPU, setting DRI_PRIME=1 to use it.");
- print_line("Note: Set DRI_PRIME=0 in the environment to disable Godot from using the discrete GPU.");
- setenv("DRI_PRIME", "1", 1);
- }
- }
-
- ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_3_0_COMPATIBLE;
-
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
- }
-
- bool editor = Engine::get_singleton()->is_editor_hint();
- bool gl_initialization_error = false;
+ if (getenv("LD_LIBRARY_PATH")) {
+ String ld_library_path(getenv("LD_LIBRARY_PATH"));
+ Vector<String> libraries = ld_library_path.split(":");
- context_gl = NULL;
- while (!context_gl) {
- context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+ for (int i = 0; i < libraries.size(); ++i) {
+ if (FileAccess::exists(libraries[i] + "/libGL.so.1") ||
+ FileAccess::exists(libraries[i] + "/libGL.so")) {
- if (context_gl->initialize() != OK) {
- memdelete(context_gl);
- context_gl = NULL;
-
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gl_initialization_error = true;
- break;
+ print_verbose("Custom libGL override detected. Skipping GPU detection");
+ use_prime = 0;
+ }
}
+ }
- p_video_driver = VIDEO_DRIVER_GLES2;
- opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
- } else {
- gl_initialization_error = true;
- break;
+ if (use_prime == -1) {
+ print_verbose("Detecting GPUs, set DRI_PRIME in the environment to override GPU detection logic.");
+ use_prime = detect_prime();
}
- }
- }
- while (true) {
- if (opengl_api_type == ContextGL_X11::GLES_3_0_COMPATIBLE) {
- 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;
- opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
+ if (use_prime) {
+ print_line("Found discrete GPU, setting DRI_PRIME=1 to use it.");
+ print_line("Note: Set DRI_PRIME=0 in the environment to disable Godot from using the discrete GPU.");
+ setenv("DRI_PRIME", "1", 1);
}
}
- if (opengl_api_type == ContextGL_X11::GLES_2_0_COMPATIBLE) {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
+ ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+
+ context_gles2 = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+
+ if (context_gles2->initialize() != OK) {
+ 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;
+ context_gles2->set_use_vsync(current_videomode.use_vsync);
+
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
}
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
- video_driver_index = p_video_driver;
+ context_vulkan = memnew(VulkanContextX11);
+ if (context_vulkan->initialize() != OK) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
+ if (context_vulkan->window_create(x11_window, x11_display, get_video_mode().width, get_video_mode().height) == -1) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- context_gl->set_use_vsync(current_videomode.use_vsync);
+ //temporary
+ rendering_device_vulkan = memnew(RenderingDeviceVulkan);
+ rendering_device_vulkan->initialize(context_vulkan);
+ RasterizerRD::make_current();
+ }
#endif
visual_server = memnew(VisualServerRaster);
@@ -868,19 +864,35 @@ void OS_X11::finalize() {
cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
- //memdelete(rasterizer);
memdelete(power_manager);
+#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 (xrandr_handle)
dlclose(xrandr_handle);
XUnmapWindow(x11_display, x11_window);
XDestroyWindow(x11_display, x11_window);
-#if defined(OPENGL_ENABLED)
- memdelete(context_gl);
-#endif
for (int i = 0; i < CURSOR_MAX; i++) {
if (cursors[i] != None)
XFreeCursor(x11_display, cursors[i]);
@@ -2122,6 +2134,12 @@ void OS_X11::_window_changed(XEvent *event) {
current_videomode.width = event->xconfigure.width;
current_videomode.height = event->xconfigure.height;
+
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->window_resize(0, current_videomode.width, current_videomode.height);
+ }
+#endif
}
void OS_X11::process_xevents() {
@@ -3010,7 +3028,7 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -3106,24 +3124,33 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
}
void OS_X11::release_rendering_thread() {
-
#if defined(OPENGL_ENABLED)
- context_gl->release_current();
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->release_current();
+ }
#endif
}
void OS_X11::make_rendering_thread() {
-
#if defined(OPENGL_ENABLED)
- context_gl->make_current();
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->make_current();
+ }
#endif
}
void OS_X11::swap_buffers() {
-
#if defined(OPENGL_ENABLED)
- context_gl->swap_buffers();
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->swap_buffers();
+ }
#endif
+ /* not needed for now
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->swap_buffers();
+ }
+#endif*/
}
void OS_X11::alert(const String &p_alert, const String &p_title) {
@@ -3311,19 +3338,13 @@ String OS_X11::get_joy_guid(int p_device) const {
void OS_X11::_set_use_vsync(bool p_enable) {
#if defined(OPENGL_ENABLED)
- if (context_gl)
- context_gl->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_X11::is_vsync_enabled() const {
-
- if (context_gl)
- return context_gl->is_using_vsync();
- return true;
-}
-*/
void OS_X11::set_context(int p_context) {
XClassHint *classHint = XAllocClassHint();
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 25b406743b..fd8a981763 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -31,7 +31,6 @@
#ifndef OS_X11_H
#define OS_X11_H
-#include "context_gl_x11.h"
#include "core/os/input.h"
#include "crash_handler_x11.h"
#include "drivers/alsa/audio_driver_alsa.h"
@@ -44,7 +43,15 @@
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
-//#include "servers/visual/visual_server_wrap_mt.h"
+
+#if defined(OPENGL_ENABLED)
+#include "context_gl_x11.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/x11/vulkan_context_x11.h"
+#endif
#include <X11/Xcursor/Xcursor.h>
#include <X11/Xlib.h>
@@ -92,8 +99,13 @@ class OS_X11 : public OS_Unix {
int xdnd_version;
#if defined(OPENGL_ENABLED)
- ContextGL_X11 *context_gl;
+ ContextGL_X11 *context_gles2;
#endif
+#if defined(VULKAN_ENABLED)
+ VulkanContextX11 *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
+#endif
+
//Rasterizer *rasterizer;
VisualServer *visual_server;
VideoMode current_videomode;
diff --git a/platform/x11/vulkan_context_x11.cpp b/platform/x11/vulkan_context_x11.cpp
new file mode 100644
index 0000000000..602dbc77a2
--- /dev/null
+++ b/platform/x11/vulkan_context_x11.cpp
@@ -0,0 +1,57 @@
+/*************************************************************************/
+/* vulkan_context_x11.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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_x11.h"
+#include <vulkan/vulkan_xlib.h>
+
+const char *VulkanContextX11::_get_platform_surface_extension() const {
+ return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
+}
+
+int VulkanContextX11::window_create(::Window p_window, Display *p_display, int p_width, int p_height) {
+
+ VkXlibSurfaceCreateInfoKHR createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.dpy = p_display;
+ createInfo.window = p_window;
+
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateXlibSurfaceKHR(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
+}
+
+VulkanContextX11::VulkanContextX11() {
+}
+
+VulkanContextX11::~VulkanContextX11() {
+}
diff --git a/platform/x11/vulkan_context_x11.h b/platform/x11/vulkan_context_x11.h
new file mode 100644
index 0000000000..573f994ea6
--- /dev/null
+++ b/platform/x11/vulkan_context_x11.h
@@ -0,0 +1,48 @@
+/*************************************************************************/
+/* vulkan_context_x11.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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_X11_H
+#define VULKAN_DEVICE_X11_H
+
+#include "drivers/vulkan/vulkan_context.h"
+#include <X11/Xlib.h>
+
+class VulkanContextX11 : public VulkanContext {
+
+ virtual const char *_get_platform_surface_extension() const;
+
+public:
+ int window_create(::Window p_window, Display *p_display, int p_width, int p_height);
+
+ VulkanContextX11();
+ ~VulkanContextX11();
+};
+
+#endif // VULKAN_DEVICE_X11_H