aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2018-10-07 00:47:57 +0200
committerAhmad Fatoum <ahmad@a3f.at>2018-10-07 02:14:30 +0200
commit1fe6d9fc06156257d5210cfa71ecb839fb190722 (patch)
treea44a000c30e9942048f4f63518e8d222376f64b7
parent6572d5ff8c3299d3915f2b3155ef2275baa971fd (diff)
downloadraylib-1fe6d9fc06156257d5210cfa71ecb839fb190722.tar.gz
raylib-1fe6d9fc06156257d5210cfa71ecb839fb190722.zip
core: workaround window not being rendered till moved on macOS Mojave
Apple ought to fix their OpenGL implementation, but with OpenGL now deprecated this might not happen. This has been reported upstream in GLFW in glfw/glfw#1334. The workaround comes from kovidgoyal/kitty@b82e74f99 This also fixes the HiDPI (Retina) scaling issues reported in #497, so the workaround is enabled anywhere __APPLE__ is defined.
-rw-r--r--src/core.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/core.c b/src/core.c
index 203da4d9..558cc854 100644
--- a/src/core.c
+++ b/src/core.c
@@ -134,12 +134,6 @@
#define CHDIR chdir
#endif
-#if defined(__linux__) || defined(PLATFORM_WEB)
- #include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
-#elif defined(__APPLE__)
- #include <unistd.h> // Required for: usleep()
-#endif
-
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
#if defined(PLATFORM_WEB)
#define GLFW_INCLUDE_ES2
@@ -155,6 +149,15 @@
#endif
#endif
+#if defined(__linux__) || defined(PLATFORM_WEB)
+ #include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
+#elif defined(__APPLE__)
+ #include <unistd.h> // Required for: usleep()
+ #include <objc/message.h> // Required for: objc_msgsend(), sel_registerName()
+ #define GLFW_EXPOSE_NATIVE_NSGL
+ #include <GLFW/glfw3native.h> // Required for: glfwGetNSGLContext()
+#endif
+
#if defined(PLATFORM_ANDROID)
//#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
@@ -233,6 +236,11 @@ static bool windowReady = false; // Check if window has been init
static bool windowMinimized = false; // Check if window has been minimized
static const char *windowTitle = NULL; // Window text title...
+#if defined(__APPLE__)
+static int windowNeedsUpdating = 2; // Times the Cocoa window needs to be updated initially
+#endif
+
+
#if defined(PLATFORM_ANDROID)
static struct android_app *androidApp; // Android activity
static struct android_poll_source *source; // Android events polling source
@@ -2870,6 +2878,15 @@ static void SwapBuffers(void)
{
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
glfwSwapBuffers(window);
+#if __APPLE__
+ // workaround for missing/erroneous initial rendering on macOS
+ if (windowNeedsUpdating) {
+ // Desugared version of Objective C: [glfwGetNSGLContext(window) update]
+ ((id (*)(id, SEL))objc_msgSend)(glfwGetNSGLContext(window),
+ sel_registerName("update"));
+ windowNeedsUpdating--;
+ }
+#endif
#endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP)