diff options
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/context_gl_osx.h | 6 | ||||
-rw-r--r-- | platform/osx/context_gl_osx.mm | 8 | ||||
-rw-r--r-- | platform/osx/detect.py | 2 | ||||
-rw-r--r-- | platform/osx/display_server_osx.h | 6 | ||||
-rw-r--r-- | platform/osx/display_server_osx.mm | 30 | ||||
-rw-r--r-- | platform/osx/os_osx.h | 2 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 58 | ||||
-rw-r--r-- | platform/osx/platform_config.h | 1 |
8 files changed, 87 insertions, 26 deletions
diff --git a/platform/osx/context_gl_osx.h b/platform/osx/context_gl_osx.h index ac45559217..77bae3247d 100644 --- a/platform/osx/context_gl_osx.h +++ b/platform/osx/context_gl_osx.h @@ -31,7 +31,7 @@ #ifndef CONTEXT_GL_OSX_H #define CONTEXT_GL_OSX_H -#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) +#if defined(GLES3_ENABLED) || defined(GLES_ENABLED) #include "core/error/error_list.h" #include "core/os/os.h" @@ -41,7 +41,7 @@ #include <CoreVideo/CoreVideo.h> class ContextGL_OSX { - bool opengl_3_context; + bool gles3_context; bool use_vsync; void *framework; @@ -66,7 +66,7 @@ public: void set_use_vsync(bool p_use); bool is_using_vsync() const; - ContextGL_OSX(id p_view, bool p_opengl_3_context); + ContextGL_OSX(id p_view, bool p_gles3_context); ~ContextGL_OSX(); }; diff --git a/platform/osx/context_gl_osx.mm b/platform/osx/context_gl_osx.mm index 88db1a296e..eab9d8dc0c 100644 --- a/platform/osx/context_gl_osx.mm +++ b/platform/osx/context_gl_osx.mm @@ -30,7 +30,7 @@ #include "context_gl_osx.h" -#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) +#if defined(GLES3_ENABLED) || defined(GLES_ENABLED) void ContextGL_OSX::release_current() { [NSOpenGLContext clearCurrentContext]; @@ -98,7 +98,7 @@ Error ContextGL_OSX::initialize() { ADD_ATTR(NSOpenGLPFADoubleBuffer); ADD_ATTR(NSOpenGLPFAClosestPolicy); - if (!opengl_3_context) { + if (!gles3_context) { ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy); } else { //we now need OpenGL 3 or better, maybe even change this to 3_3Core ? @@ -150,8 +150,8 @@ Error ContextGL_OSX::initialize() { return OK; } -ContextGL_OSX::ContextGL_OSX(id p_view, bool p_opengl_3_context) { - opengl_3_context = p_opengl_3_context; +ContextGL_OSX::ContextGL_OSX(id p_view, bool p_gles3_context) { + gles3_context = p_gles3_context; window_view = p_view; use_vsync = false; } diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 6c07c2416e..d9b55631cd 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -189,4 +189,4 @@ def configure(env): if not env["use_volk"]: env.Append(LINKFLAGS=["-L$VULKAN_SDK_PATH/MoltenVK/MoltenVK.xcframework/macos-arm64_x86_64/", "-lMoltenVK"]) - # env.Append(CPPDEFINES=['GLES_ENABLED', 'OPENGL_ENABLED']) + # env.Append(CPPDEFINES=['GLES_ENABLED', 'GLES3_ENABLED']) diff --git a/platform/osx/display_server_osx.h b/platform/osx/display_server_osx.h index e8f2858489..96baeb4dec 100644 --- a/platform/osx/display_server_osx.h +++ b/platform/osx/display_server_osx.h @@ -36,7 +36,7 @@ #include "core/input/input.h" #include "servers/display_server.h" -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) #include "context_gl_osx.h" //TODO - reimplement OpenGLES #endif @@ -64,7 +64,7 @@ public: NSMenu *_get_dock_menu() const; void _menu_callback(id p_sender); -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) ContextGL_OSX *context_gles2; #endif #if defined(VULKAN_ENABLED) @@ -109,7 +109,7 @@ public: Vector<Vector2> mpath; -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) ContextGL_OSX *context_gles2 = nullptr; #endif Point2i mouse_pos; diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 3fe055a511..d89e64cd7d 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -45,7 +45,7 @@ #include <IOKit/hid/IOHIDKeys.h> #include <IOKit/hid/IOHIDLib.h> -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) //TODO - reimplement OpenGLES #import <AppKit/NSOpenGLView.h> @@ -166,7 +166,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { [pwd.window_object makeKeyAndOrderFront:nil]; // Move focus back to main window if there is no parent or other windows left. } -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (DS_OSX->rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -271,7 +271,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { layer.contentsScale = scale; } -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (DS_OSX->rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -405,7 +405,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { } - (CALayer *)makeBackingLayer { -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (DS_OSX->rendering_driver == "opengl_es") { CALayer *layer = [[NSOpenGLLayer class] layer]; return layer; @@ -421,7 +421,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { } - (void)updateLayer { -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (DS_OSX->rendering_driver == "opengl_es") { [super updateLayer]; //TODO - reimplement OpenGLES @@ -2586,7 +2586,7 @@ void DisplayServerOSX::_set_window_per_pixel_transparency_enabled(bool p_enabled //TODO - implement transparency for Vulkan } #endif -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -2605,14 +2605,14 @@ void DisplayServerOSX::_set_window_per_pixel_transparency_enabled(bool p_enabled //TODO - implement transparency for Vulkan } #endif -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } #endif wd.layered_window = false; } -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -3475,7 +3475,7 @@ Vector<String> DisplayServerOSX::get_rendering_drivers_func() { #if defined(VULKAN_ENABLED) drivers.push_back("vulkan"); #endif -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) drivers.push_back("opengl_es"); #endif @@ -3579,7 +3579,7 @@ DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, V } } #endif -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -3600,7 +3600,7 @@ DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, V layer.contentsScale = scale; } -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -3750,7 +3750,7 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode [main_menu setSubmenu:apple_menu forItem:menu_item]; //!!!!!!!!!!!!!!!!!!!!!!!!!! - //TODO - do Vulkan and GLES2 support checks, driver selection and fallback + //TODO - do Vulkan and OpenGL support checks, driver selection and fallback rendering_driver = p_rendering_driver; #ifndef _MSC_VER @@ -3758,7 +3758,7 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode #endif rendering_driver = "vulkan"; -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -3787,7 +3787,7 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode } show_window(MAIN_WINDOW_ID); -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } @@ -3820,7 +3820,7 @@ DisplayServerOSX::~DisplayServerOSX() { } //destroy drivers -#if defined(OPENGL_ENABLED) +#if defined(GLES3_ENABLED) if (rendering_driver == "opengl_es") { //TODO - reimplement OpenGLES } diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index a52436a70a..fc78fb28a8 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -92,6 +92,8 @@ public: String get_locale() const override; virtual String get_executable_path() const override; + virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override; + virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override; virtual String get_unique_id() const override; //++ diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 489cbe074b..307ab03c48 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -491,6 +491,64 @@ String OS_OSX::get_executable_path() const { } } +Error OS_OSX::create_instance(const List<String> &p_arguments, ProcessID *r_child_id) { + // If executable is bundled, always execute editor instances as an app bundle to ensure app window is registered and activated correctly. + NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; + if (nsappname != nil) { + String path; + path.parse_utf8([[[NSBundle mainBundle] bundlePath] UTF8String]); + return create_process(path, p_arguments, r_child_id); + } else { + return create_process(get_executable_path(), p_arguments, r_child_id); + } +} + +Error OS_OSX::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id) { + if (@available(macOS 10.15, *)) { + // Use NSWorkspace if path is an .app bundle. + NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())]; + NSBundle *bundle = [NSBundle bundleWithURL:url]; + if (bundle) { + NSMutableArray *arguments = [[NSMutableArray alloc] init]; + for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) { + [arguments addObject:[NSString stringWithUTF8String:E->get().utf8().get_data()]]; + } + NSWorkspaceOpenConfiguration *configuration = [[NSWorkspaceOpenConfiguration alloc] init]; + [configuration setArguments:arguments]; + [configuration setCreatesNewApplicationInstance:YES]; + __block dispatch_semaphore_t lock = dispatch_semaphore_create(0); + __block Error err = ERR_TIMEOUT; + __block pid_t pid = 0; + [[NSWorkspace sharedWorkspace] openApplicationAtURL:url + configuration:configuration + completionHandler:^(NSRunningApplication *app, NSError *error) { + if (error) { + err = ERR_CANT_FORK; + NSLog(@"Failed to execute: %@", error.localizedDescription); + } else { + pid = [app processIdentifier]; + err = OK; + } + dispatch_semaphore_signal(lock); + }]; + dispatch_semaphore_wait(lock, dispatch_time(DISPATCH_TIME_NOW, 20000000000)); // 20 sec timeout, wait for app to launch. + dispatch_release(lock); + + if (err == OK) { + if (r_child_id) { + *r_child_id = (ProcessID)pid; + } + } + + return err; + } else { + return OS_Unix::create_process(p_path, p_arguments, r_child_id); + } + } else { + return OS_Unix::create_process(p_path, p_arguments, r_child_id); + } +} + void OS_OSX::run() { force_quit = false; diff --git a/platform/osx/platform_config.h b/platform/osx/platform_config.h index 2d0fd872dc..7bfa466b97 100644 --- a/platform/osx/platform_config.h +++ b/platform/osx/platform_config.h @@ -30,4 +30,5 @@ #include <alloca.h> +#define OPENGL_INCLUDE_H "thirdparty/glad/glad/glad.h" #define PTHREAD_RENAME_SELF |