summaryrefslogtreecommitdiffstats
path: root/platform/macos
diff options
context:
space:
mode:
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/SCsub1
-rw-r--r--platform/macos/detect.py27
-rw-r--r--platform/macos/display_server_macos.h5
-rw-r--r--platform/macos/display_server_macos.mm120
-rw-r--r--platform/macos/doc_classes/EditorExportPlatformMacOS.xml3
-rw-r--r--platform/macos/export/export_plugin.cpp23
-rw-r--r--platform/macos/gl_manager_macos_angle.h63
-rw-r--r--platform/macos/gl_manager_macos_angle.mm70
-rw-r--r--platform/macos/gl_manager_macos_legacy.h25
-rw-r--r--platform/macos/gl_manager_macos_legacy.mm73
-rw-r--r--platform/macos/godot_content_view.mm6
-rw-r--r--platform/macos/platform_config.h1
-rw-r--r--platform/macos/platform_gl.h52
13 files changed, 350 insertions, 119 deletions
diff --git a/platform/macos/SCsub b/platform/macos/SCsub
index 7ffb80f70b..30202e5de7 100644
--- a/platform/macos/SCsub
+++ b/platform/macos/SCsub
@@ -24,6 +24,7 @@ files = [
"tts_macos.mm",
"joypad_macos.cpp",
"vulkan_context_macos.mm",
+ "gl_manager_macos_angle.mm",
"gl_manager_macos_legacy.mm",
]
diff --git a/platform/macos/detect.py b/platform/macos/detect.py
index 21e824b2d3..c97cd19211 100644
--- a/platform/macos/detect.py
+++ b/platform/macos/detect.py
@@ -1,6 +1,6 @@
import os
import sys
-from methods import detect_darwin_sdk_path
+from methods import detect_darwin_sdk_path, get_compiler_version, is_vanilla_clang
from platform_methods import detect_arch
from typing import TYPE_CHECKING
@@ -32,6 +32,7 @@ def get_opts():
BoolVariable("use_asan", "Use LLVM/GCC compiler address sanitizer (ASAN)", False),
BoolVariable("use_tsan", "Use LLVM/GCC compiler thread sanitizer (TSAN)", False),
BoolVariable("use_coverage", "Use instrumentation codes in the binary (e.g. for code coverage)", False),
+ ("angle_libs", "Path to the ANGLE static libraries", ""),
]
@@ -119,6 +120,22 @@ def configure(env: "Environment"):
env.Append(CCFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.13"])
env.Append(LINKFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.13"])
+ cc_version = get_compiler_version(env) or {
+ "major": None,
+ "minor": None,
+ "patch": None,
+ "metadata1": None,
+ "metadata2": None,
+ "date": None,
+ }
+ cc_version_major = int(cc_version["major"] or -1)
+ cc_version_minor = int(cc_version["minor"] or -1)
+ vanilla = is_vanilla_clang(env)
+
+ # Workaround for Xcode 15 linker bug.
+ if not vanilla and cc_version_major == 15 and cc_version_minor == 0:
+ env.Prepend(LINKFLAGS=["-ld_classic"])
+
env.Append(CCFLAGS=["-fobjc-arc"])
if not "osxcross" in env: # regular native build
@@ -239,7 +256,13 @@ def configure(env: "Environment"):
if env["opengl3"]:
env.Append(CPPDEFINES=["GLES3_ENABLED"])
- env.Append(LINKFLAGS=["-framework", "OpenGL"])
+ if env["angle_libs"] != "":
+ env.AppendUnique(CPPDEFINES=["EGL_STATIC"])
+ env.Append(LINKFLAGS=["-L" + env["angle_libs"]])
+ env.Append(LINKFLAGS=["-lANGLE.macos." + env["arch"]])
+ env.Append(LINKFLAGS=["-lEGL.macos." + env["arch"]])
+ env.Append(LINKFLAGS=["-lGLES.macos." + env["arch"]])
+ env.Prepend(CPPPATH=["#thirdparty/angle/include"])
env.Append(LINKFLAGS=["-rpath", "@executable_path/../Frameworks", "-rpath", "@executable_path"])
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index 69f6008043..c03b4765f8 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -35,6 +35,7 @@
#include "servers/display_server.h"
#if defined(GLES3_ENABLED)
+#include "gl_manager_macos_angle.h"
#include "gl_manager_macos_legacy.h"
#endif // GLES3_ENABLED
@@ -127,7 +128,8 @@ public:
private:
#if defined(GLES3_ENABLED)
- GLManager_MacOS *gl_manager = nullptr;
+ GLManagerLegacy_MacOS *gl_manager_legacy = nullptr;
+ GLManagerANGLE_MacOS *gl_manager_angle = nullptr;
#endif
#if defined(VULKAN_ENABLED)
VulkanContextMacOS *context_vulkan = nullptr;
@@ -244,7 +246,6 @@ public:
void mouse_enter_window(WindowID p_window);
void mouse_exit_window(WindowID p_window);
- void window_update(WindowID p_window);
void window_destroy(WindowID p_window);
void window_resize(WindowID p_window, int p_width, int p_height);
void window_set_custom_window_buttons(WindowData &p_wd, bool p_enabled);
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index bc78f343ee..2989f8d1c0 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -139,7 +139,7 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod
// initWithContentRect uses bottom-left corner of the window’s frame as origin.
wd.window_object = [[GodotWindow alloc]
- initWithContentRect:NSMakeRect(100, 100, p_rect.size.width / scale, p_rect.size.height / scale)
+ initWithContentRect:NSMakeRect(100, 100, MAX(1, p_rect.size.width / scale), MAX(1, p_rect.size.height / scale))
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable
backing:NSBackingStoreBuffered
defer:NO];
@@ -185,9 +185,13 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod
}
#endif
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- Error err = gl_manager->window_create(window_id_counter, wd.window_view, p_rect.size.width, p_rect.size.height);
- ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL context");
+ if (gl_manager_legacy) {
+ Error err = gl_manager_legacy->window_create(window_id_counter, wd.window_view, p_rect.size.width, p_rect.size.height);
+ ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL context.");
+ }
+ if (gl_manager_angle) {
+ Error err = gl_manager_angle->window_create(window_id_counter, nullptr, (__bridge void *)[wd.window_view layer], p_rect.size.width, p_rect.size.height);
+ ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL context.");
}
window_set_vsync_mode(p_vsync_mode, window_id_counter);
#endif
@@ -219,8 +223,11 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod
}
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_resize(id, wd.size.width, wd.size.height);
+ if (gl_manager_legacy) {
+ gl_manager_legacy->window_resize(id, wd.size.width, wd.size.height);
+ }
+ if (gl_manager_angle) {
+ gl_manager_angle->window_resize(id, wd.size.width, wd.size.height);
}
#endif
#if defined(VULKAN_ENABLED)
@@ -279,8 +286,8 @@ void DisplayServerMacOS::_set_window_per_pixel_transparency_enabled(bool p_enabl
[layer setOpaque:NO];
}
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_set_per_pixel_transparency_enabled(p_window, true);
+ if (gl_manager_legacy) {
+ gl_manager_legacy->window_set_per_pixel_transparency_enabled(p_window, true);
}
#endif
wd.layered_window = true;
@@ -299,8 +306,8 @@ void DisplayServerMacOS::_set_window_per_pixel_transparency_enabled(bool p_enabl
[layer setOpaque:YES];
}
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_set_per_pixel_transparency_enabled(p_window, false);
+ if (gl_manager_legacy) {
+ gl_manager_legacy->window_set_per_pixel_transparency_enabled(p_window, false);
}
#endif
wd.layered_window = false;
@@ -730,18 +737,10 @@ bool DisplayServerMacOS::get_is_resizing() const {
return is_resizing;
}
-void DisplayServerMacOS::window_update(WindowID p_window) {
-#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_update(p_window);
- }
-#endif
-}
-
void DisplayServerMacOS::window_destroy(WindowID p_window) {
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_destroy(p_window);
+ if (gl_manager_legacy) {
+ gl_manager_legacy->window_destroy(p_window);
}
#endif
#ifdef VULKAN_ENABLED
@@ -754,8 +753,11 @@ void DisplayServerMacOS::window_destroy(WindowID p_window) {
void DisplayServerMacOS::window_resize(WindowID p_window, int p_width, int p_height) {
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_resize(p_window, p_width, p_height);
+ if (gl_manager_legacy) {
+ gl_manager_legacy->window_resize(p_window, p_width, p_height);
+ }
+ if (gl_manager_angle) {
+ gl_manager_angle->window_resize(p_window, p_width, p_height);
}
#endif
#if defined(VULKAN_ENABLED)
@@ -2912,7 +2914,7 @@ void DisplayServerMacOS::window_set_size(const Size2i p_size, WindowID p_window)
top_left.x = old_frame.origin.x;
top_left.y = NSMaxY(old_frame);
- NSRect new_frame = NSMakeRect(0, 0, size.x, size.y);
+ NSRect new_frame = NSMakeRect(0, 0, MAX(1, size.x), MAX(1, size.y));
new_frame = [wd.window_object frameRectForContentRect:new_frame];
new_frame.origin.x = top_left.x;
@@ -3370,8 +3372,11 @@ int64_t DisplayServerMacOS::window_get_native_handle(HandleType p_handle_type, W
}
#ifdef GLES3_ENABLED
case OPENGL_CONTEXT: {
- if (gl_manager) {
- return (int64_t)gl_manager->get_context(p_window);
+ if (gl_manager_legacy) {
+ return (int64_t)gl_manager_legacy->get_context(p_window);
+ }
+ if (gl_manager_angle) {
+ return (int64_t)gl_manager_angle->get_context(p_window);
}
return 0;
}
@@ -3398,8 +3403,11 @@ ObjectID DisplayServerMacOS::window_get_attached_instance_id(WindowID p_window)
void DisplayServerMacOS::gl_window_make_current(DisplayServer::WindowID p_window_id) {
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->window_make_current(p_window_id);
+ if (gl_manager_legacy) {
+ gl_manager_legacy->window_make_current(p_window_id);
+ }
+ if (gl_manager_angle) {
+ gl_manager_angle->window_make_current(p_window_id);
}
#endif
}
@@ -3407,8 +3415,11 @@ void DisplayServerMacOS::gl_window_make_current(DisplayServer::WindowID p_window
void DisplayServerMacOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) {
_THREAD_SAFE_METHOD_
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
+ if (gl_manager_angle) {
+ gl_manager_angle->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
+ }
+ if (gl_manager_legacy) {
+ gl_manager_legacy->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED);
}
#endif
#if defined(VULKAN_ENABLED)
@@ -3421,8 +3432,11 @@ void DisplayServerMacOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_
DisplayServer::VSyncMode DisplayServerMacOS::window_get_vsync_mode(WindowID p_window) const {
_THREAD_SAFE_METHOD_
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- return (gl_manager->is_using_vsync() ? DisplayServer::VSyncMode::VSYNC_ENABLED : DisplayServer::VSyncMode::VSYNC_DISABLED);
+ if (gl_manager_angle) {
+ return (gl_manager_angle->is_using_vsync() ? DisplayServer::VSyncMode::VSYNC_ENABLED : DisplayServer::VSyncMode::VSYNC_DISABLED);
+ }
+ if (gl_manager_legacy) {
+ return (gl_manager_legacy->is_using_vsync() ? DisplayServer::VSyncMode::VSYNC_ENABLED : DisplayServer::VSyncMode::VSYNC_DISABLED);
}
#endif
#if defined(VULKAN_ENABLED)
@@ -3805,8 +3819,11 @@ void DisplayServerMacOS::make_rendering_thread() {
void DisplayServerMacOS::swap_buffers() {
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- gl_manager->swap_buffers();
+ if (gl_manager_angle) {
+ gl_manager_angle->swap_buffers();
+ }
+ if (gl_manager_legacy) {
+ gl_manager_legacy->swap_buffers();
}
#endif
}
@@ -3917,6 +3934,7 @@ Vector<String> DisplayServerMacOS::get_rendering_drivers_func() {
#endif
#if defined(GLES3_ENABLED)
drivers.push_back("opengl3");
+ drivers.push_back("opengl3_angle");
#endif
return drivers;
@@ -4155,13 +4173,22 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM
#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
- GLManager_MacOS::ContextType opengl_api_type = GLManager_MacOS::GLES_3_0_COMPATIBLE;
- gl_manager = memnew(GLManager_MacOS(opengl_api_type));
- if (gl_manager->initialize() != OK) {
- memdelete(gl_manager);
- gl_manager = nullptr;
+ gl_manager_legacy = memnew(GLManagerLegacy_MacOS);
+ if (gl_manager_legacy->initialize() != OK) {
+ memdelete(gl_manager_legacy);
+ gl_manager_legacy = nullptr;
r_error = ERR_UNAVAILABLE;
- ERR_FAIL_MSG("Could not initialize OpenGL");
+ ERR_FAIL_MSG("Could not initialize OpenGL.");
+ return;
+ }
+ }
+ if (rendering_driver == "opengl3_angle") {
+ gl_manager_angle = memnew(GLManagerANGLE_MacOS);
+ if (gl_manager_angle->initialize() != OK) {
+ memdelete(gl_manager_angle);
+ gl_manager_angle = nullptr;
+ r_error = ERR_UNAVAILABLE;
+ ERR_FAIL_MSG("Could not initialize OpenGL.");
}
}
#endif
@@ -4199,7 +4226,10 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM
#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
- RasterizerGLES3::make_current();
+ RasterizerGLES3::make_current(true);
+ }
+ if (rendering_driver == "opengl3_angle") {
+ RasterizerGLES3::make_current(false);
}
#endif
#if defined(VULKAN_ENABLED)
@@ -4230,9 +4260,13 @@ DisplayServerMacOS::~DisplayServerMacOS() {
// Destroy drivers.
#if defined(GLES3_ENABLED)
- if (gl_manager) {
- memdelete(gl_manager);
- gl_manager = nullptr;
+ if (gl_manager_legacy) {
+ memdelete(gl_manager_legacy);
+ gl_manager_legacy = nullptr;
+ }
+ if (gl_manager_angle) {
+ memdelete(gl_manager_angle);
+ gl_manager_angle = nullptr;
}
#endif
#if defined(VULKAN_ENABLED)
diff --git a/platform/macos/doc_classes/EditorExportPlatformMacOS.xml b/platform/macos/doc_classes/EditorExportPlatformMacOS.xml
index 7ba1379fd0..99187fe60e 100644
--- a/platform/macos/doc_classes/EditorExportPlatformMacOS.xml
+++ b/platform/macos/doc_classes/EditorExportPlatformMacOS.xml
@@ -22,6 +22,9 @@
<member name="application/copyright_localized" type="Dictionary" setter="" getter="">
Copyright notice for the bundle visible to the user (localized).
</member>
+ <member name="application/export_angle" type="int" setter="" getter="">
+ If set to [code]1[/code], ANGLE libraries are exported with the exported application. If set to [code]0[/code], ANGLE libraries are exported only if [member ProjectSettings.rendering/gl_compatibility/driver] is set to [code]"opengl3_angle"[/code].
+ </member>
<member name="application/icon" type="String" setter="" getter="">
Application icon file. If left empty, it will fallback to [member ProjectSettings.application/config/macos_native_icon], and then to [member ProjectSettings.application/config/icon].
</member>
diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp
index 559c2c4e62..639a7699ee 100644
--- a/platform/macos/export/export_plugin.cpp
+++ b/platform/macos/export/export_plugin.cpp
@@ -384,6 +384,7 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version"), "10.12"));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18"));
@@ -1618,6 +1619,14 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
// Now process our template.
bool found_binary = false;
+ int export_angle = p_preset->get("application/export_angle");
+ bool include_angle_libs = false;
+ if (export_angle == 0) {
+ include_angle_libs = String(GLOBAL_GET("rendering/gl_compatibility/driver.macos")) == "opengl3_angle";
+ } else if (export_angle == 1) {
+ include_angle_libs = true;
+ }
+
while (ret == UNZ_OK && err == OK) {
// Get filename.
unz_file_info info;
@@ -1665,6 +1674,20 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
continue; // next
}
+ if (file == "Contents/Frameworks/libEGL.dylib") {
+ if (!include_angle_libs) {
+ ret = unzGoToNextFile(src_pkg_zip);
+ continue; // skip
+ }
+ }
+
+ if (file == "Contents/Frameworks/libGLESv2.dylib") {
+ if (!include_angle_libs) {
+ ret = unzGoToNextFile(src_pkg_zip);
+ continue; // skip
+ }
+ }
+
if (file == "Contents/Info.plist") {
_fix_plist(p_preset, data, pkg_name);
}
diff --git a/platform/macos/gl_manager_macos_angle.h b/platform/macos/gl_manager_macos_angle.h
new file mode 100644
index 0000000000..919b8ec9c8
--- /dev/null
+++ b/platform/macos/gl_manager_macos_angle.h
@@ -0,0 +1,63 @@
+/**************************************************************************/
+/* gl_manager_macos_angle.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* 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 GL_MANAGER_MACOS_ANGLE_H
+#define GL_MANAGER_MACOS_ANGLE_H
+
+#if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
+
+#include "core/error/error_list.h"
+#include "core/os/os.h"
+#include "core/templates/local_vector.h"
+#include "drivers/egl/egl_manager.h"
+#include "servers/display_server.h"
+
+#include <AppKit/AppKit.h>
+#include <ApplicationServices/ApplicationServices.h>
+#include <CoreVideo/CoreVideo.h>
+
+class GLManagerANGLE_MacOS : public EGLManager {
+private:
+ virtual const char *_get_platform_extension_name() const override;
+ virtual EGLenum _get_platform_extension_enum() const override;
+ virtual EGLenum _get_platform_api_enum() const override;
+ virtual Vector<EGLAttrib> _get_platform_display_attributes() const override;
+ virtual Vector<EGLint> _get_platform_context_attribs() const override;
+
+public:
+ void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height) {}
+
+ GLManagerANGLE_MacOS() {}
+ ~GLManagerANGLE_MacOS() {}
+};
+
+#endif // MACOS_ENABLED && GLES3_ENABLED
+
+#endif // GL_MANAGER_MACOS_ANGLE_H
diff --git a/platform/macos/gl_manager_macos_angle.mm b/platform/macos/gl_manager_macos_angle.mm
new file mode 100644
index 0000000000..ec0ca3e1f3
--- /dev/null
+++ b/platform/macos/gl_manager_macos_angle.mm
@@ -0,0 +1,70 @@
+/**************************************************************************/
+/* gl_manager_macos_angle.mm */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* 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 "gl_manager_macos_angle.h"
+
+#if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <EGL/eglext_angle.h>
+
+const char *GLManagerANGLE_MacOS::_get_platform_extension_name() const {
+ return "EGL_ANGLE_platform_angle";
+}
+
+EGLenum GLManagerANGLE_MacOS::_get_platform_extension_enum() const {
+ return EGL_PLATFORM_ANGLE_ANGLE;
+}
+
+Vector<EGLAttrib> GLManagerANGLE_MacOS::_get_platform_display_attributes() const {
+ Vector<EGLAttrib> ret;
+ ret.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
+ ret.push_back(EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE);
+ ret.push_back(EGL_NONE);
+
+ return ret;
+}
+
+EGLenum GLManagerANGLE_MacOS::_get_platform_api_enum() const {
+ return EGL_OPENGL_ES_API;
+}
+
+Vector<EGLint> GLManagerANGLE_MacOS::_get_platform_context_attribs() const {
+ Vector<EGLint> ret;
+ ret.push_back(EGL_CONTEXT_CLIENT_VERSION);
+ ret.push_back(3);
+ ret.push_back(EGL_NONE);
+
+ return ret;
+}
+
+#endif // MACOS_ENABLED && GLES3_ENABLED
diff --git a/platform/macos/gl_manager_macos_legacy.h b/platform/macos/gl_manager_macos_legacy.h
index 94d966f4ed..bafe825efb 100644
--- a/platform/macos/gl_manager_macos_legacy.h
+++ b/platform/macos/gl_manager_macos_legacy.h
@@ -45,17 +45,12 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // OpenGL is deprecated in macOS 10.14
-class GLManager_MacOS {
-public:
- enum ContextType {
- GLES_3_0_COMPATIBLE,
- };
+typedef CGLError (*CGLEnablePtr)(CGLContextObj ctx, CGLContextEnable pname);
+typedef CGLError (*CGLSetParameterPtr)(CGLContextObj ctx, CGLContextParameter pname, const GLint *params);
+typedef CGLContextObj (*CGLGetCurrentContextPtr)(void);
-private:
+class GLManagerLegacy_MacOS {
struct GLWindow {
- int width = 0;
- int height = 0;
-
id window_view = nullptr;
NSOpenGLContext *context = nullptr;
};
@@ -68,23 +63,21 @@ private:
Error create_context(GLWindow &win);
bool use_vsync = false;
- ContextType context_type;
+ CGLEnablePtr CGLEnable = nullptr;
+ CGLSetParameterPtr CGLSetParameter = nullptr;
+ CGLGetCurrentContextPtr CGLGetCurrentContext = nullptr;
public:
Error window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height);
void window_destroy(DisplayServer::WindowID p_window_id);
void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
- int window_get_width(DisplayServer::WindowID p_window_id = 0);
- int window_get_height(DisplayServer::WindowID p_window_id = 0);
-
void release_current();
void make_current();
void swap_buffers();
void window_make_current(DisplayServer::WindowID p_window_id);
- void window_update(DisplayServer::WindowID p_window_id);
void window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled);
Error initialize();
@@ -94,8 +87,8 @@ public:
NSOpenGLContext *get_context(DisplayServer::WindowID p_window_id);
- GLManager_MacOS(ContextType p_context_type);
- ~GLManager_MacOS();
+ GLManagerLegacy_MacOS();
+ ~GLManagerLegacy_MacOS();
};
#pragma clang diagnostic push
diff --git a/platform/macos/gl_manager_macos_legacy.mm b/platform/macos/gl_manager_macos_legacy.mm
index 550e2d5c59..3e5a96bffd 100644
--- a/platform/macos/gl_manager_macos_legacy.mm
+++ b/platform/macos/gl_manager_macos_legacy.mm
@@ -38,7 +38,7 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // OpenGL is deprecated in macOS 10.14
-Error GLManager_MacOS::create_context(GLWindow &win) {
+Error GLManagerLegacy_MacOS::create_context(GLWindow &win) {
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAClosestPolicy,
@@ -64,10 +64,8 @@ Error GLManager_MacOS::create_context(GLWindow &win) {
return OK;
}
-Error GLManager_MacOS::window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height) {
+Error GLManagerLegacy_MacOS::window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height) {
GLWindow win;
- win.width = p_width;
- win.height = p_height;
win.window_view = p_view;
if (create_context(win) != OK) {
@@ -80,16 +78,13 @@ Error GLManager_MacOS::window_create(DisplayServer::WindowID p_window_id, id p_v
return OK;
}
-void GLManager_MacOS::window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height) {
+void GLManagerLegacy_MacOS::window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height) {
if (!windows.has(p_window_id)) {
return;
}
GLWindow &win = windows[p_window_id];
- win.width = p_width;
- win.height = p_height;
-
GLint dim[2];
dim[0] = p_width;
dim[1] = p_height;
@@ -104,25 +99,7 @@ void GLManager_MacOS::window_resize(DisplayServer::WindowID p_window_id, int p_w
[win.context update];
}
-int GLManager_MacOS::window_get_width(DisplayServer::WindowID p_window_id) {
- if (!windows.has(p_window_id)) {
- return 0;
- }
-
- GLWindow &win = windows[p_window_id];
- return win.width;
-}
-
-int GLManager_MacOS::window_get_height(DisplayServer::WindowID p_window_id) {
- if (!windows.has(p_window_id)) {
- return 0;
- }
-
- GLWindow &win = windows[p_window_id];
- return win.height;
-}
-
-void GLManager_MacOS::window_destroy(DisplayServer::WindowID p_window_id) {
+void GLManagerLegacy_MacOS::window_destroy(DisplayServer::WindowID p_window_id) {
if (!windows.has(p_window_id)) {
return;
}
@@ -134,7 +111,7 @@ void GLManager_MacOS::window_destroy(DisplayServer::WindowID p_window_id) {
windows.erase(p_window_id);
}
-void GLManager_MacOS::release_current() {
+void GLManagerLegacy_MacOS::release_current() {
if (current_window == DisplayServer::INVALID_WINDOW_ID) {
return;
}
@@ -142,7 +119,7 @@ void GLManager_MacOS::release_current() {
[NSOpenGLContext clearCurrentContext];
}
-void GLManager_MacOS::window_make_current(DisplayServer::WindowID p_window_id) {
+void GLManagerLegacy_MacOS::window_make_current(DisplayServer::WindowID p_window_id) {
if (current_window == p_window_id) {
return;
}
@@ -156,7 +133,7 @@ void GLManager_MacOS::window_make_current(DisplayServer::WindowID p_window_id) {
current_window = p_window_id;
}
-void GLManager_MacOS::make_current() {
+void GLManagerLegacy_MacOS::make_current() {
if (current_window == DisplayServer::INVALID_WINDOW_ID) {
return;
}
@@ -168,21 +145,12 @@ void GLManager_MacOS::make_current() {
[win.context makeCurrentContext];
}
-void GLManager_MacOS::swap_buffers() {
+void GLManagerLegacy_MacOS::swap_buffers() {
GLWindow &win = windows[current_window];
[win.context flushBuffer];
}
-void GLManager_MacOS::window_update(DisplayServer::WindowID p_window_id) {
- if (!windows.has(p_window_id)) {
- return;
- }
-
- GLWindow &win = windows[p_window_id];
- [win.context update];
-}
-
-void GLManager_MacOS::window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled) {
+void GLManagerLegacy_MacOS::window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled) {
if (!windows.has(p_window_id)) {
return;
}
@@ -198,26 +166,28 @@ void GLManager_MacOS::window_set_per_pixel_transparency_enabled(DisplayServer::W
[win.context update];
}
-Error GLManager_MacOS::initialize() {
+Error GLManagerLegacy_MacOS::initialize() {
return OK;
}
-void GLManager_MacOS::set_use_vsync(bool p_use) {
+void GLManagerLegacy_MacOS::set_use_vsync(bool p_use) {
use_vsync = p_use;
CGLContextObj ctx = CGLGetCurrentContext();
if (ctx) {
GLint swapInterval = p_use ? 1 : 0;
- CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+ if (CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval) != kCGLNoError) {
+ WARN_PRINT("Could not set V-Sync mode.");
+ }
use_vsync = p_use;
}
}
-bool GLManager_MacOS::is_using_vsync() const {
+bool GLManagerLegacy_MacOS::is_using_vsync() const {
return use_vsync;
}
-NSOpenGLContext *GLManager_MacOS::get_context(DisplayServer::WindowID p_window_id) {
+NSOpenGLContext *GLManagerLegacy_MacOS::get_context(DisplayServer::WindowID p_window_id) {
if (!windows.has(p_window_id)) {
return nullptr;
}
@@ -226,11 +196,16 @@ NSOpenGLContext *GLManager_MacOS::get_context(DisplayServer::WindowID p_window_i
return win.context;
}
-GLManager_MacOS::GLManager_MacOS(ContextType p_context_type) {
- context_type = p_context_type;
+GLManagerLegacy_MacOS::GLManagerLegacy_MacOS() {
+ CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
+ CFBundleLoadExecutable(framework);
+
+ CGLEnable = (CGLEnablePtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLEnable"));
+ CGLSetParameter = (CGLSetParameterPtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLSetParameter"));
+ CGLGetCurrentContext = (CGLGetCurrentContextPtr)CFBundleGetFunctionPointerForName(framework, CFSTR("CGLGetCurrentContext"));
}
-GLManager_MacOS::~GLManager_MacOS() {
+GLManagerLegacy_MacOS::~GLManagerLegacy_MacOS() {
release_current();
}
diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm
index 8b6e1cdb79..22a9aa14c0 100644
--- a/platform/macos/godot_content_view.mm
+++ b/platform/macos/godot_content_view.mm
@@ -139,12 +139,6 @@
return [[CAMetalLayer class] layer];
}
-- (void)updateLayer {
- DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
- ds->window_update(window_id);
- [super updateLayer];
-}
-
- (BOOL)wantsUpdateLayer {
return YES;
}
diff --git a/platform/macos/platform_config.h b/platform/macos/platform_config.h
index 65a898dcc1..1a571b689a 100644
--- a/platform/macos/platform_config.h
+++ b/platform/macos/platform_config.h
@@ -30,5 +30,4 @@
#include <alloca.h>
-#define OPENGL_INCLUDE_H "thirdparty/glad/glad/gl.h"
#define PTHREAD_RENAME_SELF
diff --git a/platform/macos/platform_gl.h b/platform/macos/platform_gl.h
new file mode 100644
index 0000000000..3bad9d5a5f
--- /dev/null
+++ b/platform/macos/platform_gl.h
@@ -0,0 +1,52 @@
+/**************************************************************************/
+/* platform_gl.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* 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 PLATFORM_GL_H
+#define PLATFORM_GL_H
+
+#ifndef GL_API_ENABLED
+#define GL_API_ENABLED // Allow using desktop GL.
+#endif
+
+#ifndef GLES_API_ENABLED
+#define GLES_API_ENABLED // Allow using GLES (ANGLE).
+#endif
+
+#ifdef EGL_STATIC
+#define KHRONOS_STATIC 1
+#include "thirdparty/angle/include/EGL/egl.h"
+#include "thirdparty/angle/include/EGL/eglext.h"
+#undef KHRONOS_STATIC
+#else
+#include "thirdparty/glad/glad/egl.h"
+#endif
+#include "thirdparty/glad/glad/gl.h"
+
+#endif // PLATFORM_GL_H