Skip to content

Display and control your Android device

Force OpenGL Core Profile context on macOS

Yanc083a7cc9015
diff --git a/app/src/display.c b/app/src/display.c
index 96ff9e06..4852952b 100644
--- a/app/src/display.c
+++ b/app/src/display.c
@@ -23,6 +23,22 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
// starts with "opengl"
bool use_opengl = renderer_name && !strncmp(renderer_name, "opengl", 6);
if (use_opengl) {
+
+#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
+ // Persuade macOS to give us something better than OpenGL 2.1.
+ // If we create a Core Profile context, we get the best OpenGL version.
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+ SDL_GL_CONTEXT_PROFILE_CORE);
+
+ LOGD("Creating OpenGL Core Profile context");
+ display->gl_context = SDL_GL_CreateContext(window);
+ if (!display->gl_context) {
+ LOGE("Could not create OpenGL context: %s", SDL_GetError());
+ SDL_DestroyRenderer(display->renderer);
+ return false;
+ }
+#endif
+
struct sc_opengl *gl = &display->gl;
sc_opengl_init(gl);
@@ -51,6 +67,9 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
void
sc_display_destroy(struct sc_display *display) {
+#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
+ SDL_GL_DeleteContext(display->gl_context);
+#endif
if (display->texture) {
SDL_DestroyTexture(display->texture);
}
diff --git a/app/src/display.h b/app/src/display.h
index 8856afcd..e30b4822 100644
--- a/app/src/display.h
+++ b/app/src/display.h
@@ -10,11 +10,19 @@
#include "coords.h"
#include "opengl.h"
+#ifdef __APPLE__
+# define SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
+#endif
+
struct sc_display {
SDL_Renderer *renderer;
SDL_Texture *texture;
struct sc_opengl gl;
+#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
+ SDL_GLContext *gl_context;
+#endif
+
bool mipmaps;
};