src/video/cocoa/SDL_cocoaopengl.m
author Ryan C. Gordon <icculus@icculus.org>
Fri, 14 Jun 2019 21:18:53 -0400
changeset 12863 bddd4ba329cc
parent 12840 1b6f67e84802
child 12940 1e6980ce45c0
permissions -rw-r--r--
cocoa: ignore compiler warnings about OpenGL being deprecated.
slouken@1936
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@1936
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1936
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1936
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1936
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1936
    22
slouken@1936
    23
/* NSOpenGL implementation of SDL OpenGL support */
slouken@1936
    24
slouken@1952
    25
#if SDL_VIDEO_OPENGL_CGL
slouken@6044
    26
#include "SDL_cocoavideo.h"
jorgen@7594
    27
#include "SDL_cocoaopengl.h"
slouken@11723
    28
#include "SDL_cocoaopengles.h"
slouken@6044
    29
slouken@1936
    30
#include <OpenGL/CGLTypes.h>
slouken@2738
    31
#include <OpenGL/OpenGL.h>
slouken@3570
    32
#include <OpenGL/CGLRenderers.h>
slouken@1936
    33
slouken@1936
    34
#include "SDL_loadso.h"
slouken@1936
    35
#include "SDL_opengl.h"
slouken@1936
    36
icculus@6567
    37
#define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
slouken@1936
    38
icculus@12863
    39
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
icculus@12863
    40
#ifdef __clang__
icculus@12863
    41
#pragma clang diagnostic push
icculus@12863
    42
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
icculus@12863
    43
#endif
icculus@12863
    44
jorgen@7594
    45
@implementation SDLOpenGLContext : NSOpenGLContext
jorgen@7594
    46
jorgen@7594
    47
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
jorgen@7594
    48
        shareContext:(NSOpenGLContext *)share
jorgen@7594
    49
{
jorgen@7595
    50
    self = [super initWithFormat:format shareContext:share];
jorgen@7595
    51
    if (self) {
jorgen@7595
    52
        SDL_AtomicSet(&self->dirty, 0);
jorgen@7595
    53
        self->window = NULL;
jorgen@7595
    54
    }
jorgen@7595
    55
    return self;
jorgen@7594
    56
}
jorgen@7594
    57
jorgen@7594
    58
- (void)scheduleUpdate
jorgen@7594
    59
{
jorgen@7594
    60
    SDL_AtomicAdd(&self->dirty, 1);
jorgen@7594
    61
}
jorgen@7594
    62
jorgen@7594
    63
/* This should only be called on the thread on which a user is using the context. */
jorgen@7594
    64
- (void)updateIfNeeded
jorgen@7594
    65
{
jorgen@7594
    66
    int value = SDL_AtomicSet(&self->dirty, 0);
jorgen@7594
    67
    if (value > 0) {
jorgen@7594
    68
        /* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
jorgen@7594
    69
        [super update];
jorgen@7594
    70
    }
jorgen@7594
    71
}
jorgen@7594
    72
jorgen@7594
    73
/* This should only be called on the thread on which a user is using the context. */
jorgen@7594
    74
- (void)update
jorgen@7594
    75
{
jorgen@7594
    76
    /* This ensures that regular 'update' calls clear the atomic dirty flag. */
jorgen@7594
    77
    [self scheduleUpdate];
jorgen@7594
    78
    [self updateIfNeeded];
jorgen@7594
    79
}
jorgen@7594
    80
jorgen@7595
    81
/* Updates the drawable for the contexts and manages related state. */
jorgen@7595
    82
- (void)setWindow:(SDL_Window *)newWindow
jorgen@7595
    83
{
jorgen@7595
    84
    if (self->window) {
jorgen@7595
    85
        SDL_WindowData *oldwindowdata = (SDL_WindowData *)self->window->driverdata;
jorgen@7595
    86
jorgen@7595
    87
        /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */
jorgen@7595
    88
        NSMutableArray *contexts = oldwindowdata->nscontexts;
jorgen@7595
    89
        @synchronized (contexts) {
jorgen@7595
    90
            [contexts removeObject:self];
jorgen@7595
    91
        }
jorgen@7595
    92
    }
jorgen@7595
    93
jorgen@7595
    94
    self->window = newWindow;
jorgen@7595
    95
jorgen@7595
    96
    if (newWindow) {
jorgen@7595
    97
        SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
jorgen@7595
    98
jorgen@7595
    99
        /* Now sign up for scheduled updates for the new window. */
jorgen@7595
   100
        NSMutableArray *contexts = windowdata->nscontexts;
jorgen@7595
   101
        @synchronized (contexts) {
jorgen@7595
   102
            [contexts addObject:self];
jorgen@7595
   103
        }
jorgen@7595
   104
jorgen@7595
   105
        if ([self view] != [windowdata->nswindow contentView]) {
jorgen@7595
   106
            [self setView:[windowdata->nswindow contentView]];
jorgen@8258
   107
            if (self == [NSOpenGLContext currentContext]) {
jorgen@8258
   108
                [self update];
jorgen@8258
   109
            } else {
jorgen@8258
   110
                [self scheduleUpdate];
jorgen@8258
   111
            }
jorgen@7595
   112
        }
jorgen@7595
   113
    } else {
jorgen@7595
   114
        [self clearDrawable];
jorgen@8258
   115
        if (self == [NSOpenGLContext currentContext]) {
jorgen@8258
   116
            [self update];
jorgen@8258
   117
        } else {
jorgen@8258
   118
            [self scheduleUpdate];
jorgen@8258
   119
        }
jorgen@7595
   120
    }
jorgen@7595
   121
}
jorgen@7595
   122
jorgen@7594
   123
@end
jorgen@7594
   124
slouken@1936
   125
slouken@1936
   126
int
slouken@1936
   127
Cocoa_GL_LoadLibrary(_THIS, const char *path)
slouken@1936
   128
{
slouken@3057
   129
    /* Load the OpenGL library */
slouken@1936
   130
    if (path == NULL) {
slouken@1952
   131
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
slouken@1952
   132
    }
slouken@1952
   133
    if (path == NULL) {
slouken@1952
   134
        path = DEFAULT_OPENGL;
slouken@1936
   135
    }
slouken@1936
   136
    _this->gl_config.dll_handle = SDL_LoadObject(path);
slouken@1936
   137
    if (!_this->gl_config.dll_handle) {
slouken@1936
   138
        return -1;
slouken@1936
   139
    }
slouken@1936
   140
    SDL_strlcpy(_this->gl_config.driver_path, path,
slouken@1936
   141
                SDL_arraysize(_this->gl_config.driver_path));
slouken@1936
   142
    return 0;
slouken@1936
   143
}
slouken@1936
   144
slouken@1936
   145
void *
slouken@1936
   146
Cocoa_GL_GetProcAddress(_THIS, const char *proc)
slouken@1936
   147
{
slouken@1936
   148
    return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
slouken@1936
   149
}
slouken@1936
   150
slouken@3057
   151
void
slouken@1936
   152
Cocoa_GL_UnloadLibrary(_THIS)
slouken@1936
   153
{
slouken@3057
   154
    SDL_UnloadObject(_this->gl_config.dll_handle);
slouken@3057
   155
    _this->gl_config.dll_handle = NULL;
slouken@1936
   156
}
slouken@1936
   157
slouken@1936
   158
SDL_GLContext
slouken@1936
   159
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
slime73@9587
   160
{ @autoreleasepool
slouken@1936
   161
{
slouken@5246
   162
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@1936
   163
    SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
slouken@8986
   164
    SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
slouken@1936
   165
    NSOpenGLPixelFormatAttribute attr[32];
slouken@1936
   166
    NSOpenGLPixelFormat *fmt;
jorgen@7594
   167
    SDLOpenGLContext *context;
flibitijibibo@7152
   168
    NSOpenGLContext *share_context = nil;
slouken@1936
   169
    int i = 0;
icculus@8276
   170
    const char *glversion;
icculus@8276
   171
    int glversion_major;
icculus@8276
   172
    int glversion_minor;
slouken@1936
   173
icculus@6567
   174
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
slouken@11723
   175
#if SDL_VIDEO_OPENGL_EGL
slouken@11723
   176
        /* Switch to EGL based functions */
slouken@11723
   177
        Cocoa_GL_UnloadLibrary(_this);
slouken@11723
   178
        _this->GL_LoadLibrary = Cocoa_GLES_LoadLibrary;
slouken@11723
   179
        _this->GL_GetProcAddress = Cocoa_GLES_GetProcAddress;
slouken@11723
   180
        _this->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary;
slouken@11723
   181
        _this->GL_CreateContext = Cocoa_GLES_CreateContext;
slouken@11723
   182
        _this->GL_MakeCurrent = Cocoa_GLES_MakeCurrent;
slouken@11723
   183
        _this->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
slouken@11723
   184
        _this->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
slouken@11723
   185
        _this->GL_SwapWindow = Cocoa_GLES_SwapWindow;
slouken@11723
   186
        _this->GL_DeleteContext = Cocoa_GLES_DeleteContext;
slouken@11723
   187
        
slouken@11723
   188
        if (Cocoa_GLES_LoadLibrary(_this, NULL) != 0) {
slouken@11723
   189
            return NULL;
slouken@11723
   190
        }
slouken@11723
   191
        return Cocoa_GLES_CreateContext(_this, window);
slouken@11723
   192
#else
slouken@11723
   193
        SDL_SetError("SDL not configured with EGL support");
icculus@6567
   194
        return NULL;
slouken@11723
   195
#endif
icculus@6567
   196
    }
slouken@8986
   197
    if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) {
icculus@8276
   198
        SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
icculus@6567
   199
        return NULL;
icculus@6567
   200
    }
icculus@6567
   201
icculus@10008
   202
    attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
icculus@10008
   203
slouken@6848
   204
    /* specify a profile if we're on Lion (10.7) or later. */
slouken@8986
   205
    if (lion_or_later) {
icculus@8276
   206
        NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
slouken@6848
   207
        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
icculus@8276
   208
            profile = NSOpenGLProfileVersion3_2Core;
alexey@6832
   209
        }
icculus@8276
   210
        attr[i++] = NSOpenGLPFAOpenGLProfile;
slouken@6848
   211
        attr[i++] = profile;
slouken@6848
   212
    }
slouken@1936
   213
slouken@6848
   214
    attr[i++] = NSOpenGLPFAColorSize;
slouken@6848
   215
    attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
slouken@6848
   216
slouken@6848
   217
    attr[i++] = NSOpenGLPFADepthSize;
slouken@6848
   218
    attr[i++] = _this->gl_config.depth_size;
slouken@6848
   219
slouken@6848
   220
    if (_this->gl_config.double_buffer) {
slouken@6848
   221
        attr[i++] = NSOpenGLPFADoubleBuffer;
slouken@6848
   222
    }
slouken@6848
   223
slouken@6848
   224
    if (_this->gl_config.stereo) {
slouken@6848
   225
        attr[i++] = NSOpenGLPFAStereo;
slouken@6848
   226
    }
slouken@6848
   227
slouken@6848
   228
    if (_this->gl_config.stencil_size) {
slouken@6848
   229
        attr[i++] = NSOpenGLPFAStencilSize;
slouken@6848
   230
        attr[i++] = _this->gl_config.stencil_size;
slouken@6848
   231
    }
slouken@6848
   232
slouken@6848
   233
    if ((_this->gl_config.accum_red_size +
slouken@6848
   234
         _this->gl_config.accum_green_size +
slouken@6848
   235
         _this->gl_config.accum_blue_size +
slouken@6848
   236
         _this->gl_config.accum_alpha_size) > 0) {
slouken@6848
   237
        attr[i++] = NSOpenGLPFAAccumSize;
slouken@6848
   238
        attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
slouken@6848
   239
    }
slouken@6848
   240
slouken@6848
   241
    if (_this->gl_config.multisamplebuffers) {
slouken@6848
   242
        attr[i++] = NSOpenGLPFASampleBuffers;
slouken@6848
   243
        attr[i++] = _this->gl_config.multisamplebuffers;
slouken@6848
   244
    }
slouken@6848
   245
slouken@6848
   246
    if (_this->gl_config.multisamplesamples) {
slouken@6848
   247
        attr[i++] = NSOpenGLPFASamples;
slouken@6848
   248
        attr[i++] = _this->gl_config.multisamplesamples;
slouken@6848
   249
        attr[i++] = NSOpenGLPFANoRecovery;
slouken@6848
   250
    }
slouken@6848
   251
slouken@6848
   252
    if (_this->gl_config.accelerated >= 0) {
slouken@6848
   253
        if (_this->gl_config.accelerated) {
slouken@6848
   254
            attr[i++] = NSOpenGLPFAAccelerated;
slouken@6848
   255
        } else {
slouken@6848
   256
            attr[i++] = NSOpenGLPFARendererID;
slouken@6848
   257
            attr[i++] = kCGLRendererGenericFloatID;
alexey@6832
   258
        }
slouken@6848
   259
    }
slouken@6848
   260
slouken@6848
   261
    attr[i++] = NSOpenGLPFAScreenMask;
slouken@6848
   262
    attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
slouken@6848
   263
    attr[i] = 0;
slouken@6848
   264
slouken@6848
   265
    fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
slouken@6848
   266
    if (fmt == nil) {
slouken@8601
   267
        SDL_SetError("Failed creating OpenGL pixel format");
slouken@6848
   268
        return NULL;
slouken@6848
   269
    }
slouken@6848
   270
flibitijibibo@7152
   271
    if (_this->gl_config.share_with_current_context) {
slouken@7412
   272
        share_context = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
flibitijibibo@7152
   273
    }
flibitijibibo@7152
   274
jorgen@7594
   275
    context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
slouken@6848
   276
slouken@6848
   277
    [fmt release];
slouken@6848
   278
slouken@6848
   279
    if (context == nil) {
slouken@8601
   280
        SDL_SetError("Failed creating OpenGL context");
slouken@6848
   281
        return NULL;
slouken@6848
   282
    }
slouken@6848
   283
slouken@2178
   284
    if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
slouken@2178
   285
        Cocoa_GL_DeleteContext(_this, context);
slouken@8601
   286
        SDL_SetError("Failed making OpenGL context current");
slouken@2178
   287
        return NULL;
slouken@2178
   288
    }
slouken@2178
   289
slouken@8604
   290
    if (_this->gl_config.major_version < 3 &&
slouken@8604
   291
        _this->gl_config.profile_mask == 0 &&
slouken@8604
   292
        _this->gl_config.flags == 0) {
slouken@8604
   293
        /* This is a legacy profile, so to match other backends, we're done. */
slouken@8604
   294
    } else {
slouken@8604
   295
        const GLubyte *(APIENTRY * glGetStringFunc)(GLenum);
slouken@8601
   296
slouken@8604
   297
        glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
slouken@8604
   298
        if (!glGetStringFunc) {
slouken@8604
   299
            Cocoa_GL_DeleteContext(_this, context);
slouken@8604
   300
            SDL_SetError ("Failed getting OpenGL glGetString entry point");
slouken@8604
   301
            return NULL;
slouken@8604
   302
        }
slouken@8601
   303
slouken@8604
   304
        glversion = (const char *)glGetStringFunc(GL_VERSION);
slouken@8604
   305
        if (glversion == NULL) {
slouken@8604
   306
            Cocoa_GL_DeleteContext(_this, context);
slouken@8604
   307
            SDL_SetError ("Failed getting OpenGL context version");
slouken@8604
   308
            return NULL;
slouken@8604
   309
        }
slouken@8604
   310
slouken@8604
   311
        if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
slouken@8604
   312
            Cocoa_GL_DeleteContext(_this, context);
slouken@8604
   313
            SDL_SetError ("Failed parsing OpenGL context version");
slouken@8604
   314
            return NULL;
slouken@8604
   315
        }
slouken@8604
   316
slouken@8604
   317
        if ((glversion_major < _this->gl_config.major_version) ||
slouken@8604
   318
           ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
slouken@8604
   319
            Cocoa_GL_DeleteContext(_this, context);
slouken@8604
   320
            SDL_SetError ("Failed creating OpenGL context at version requested");
slouken@8604
   321
            return NULL;
slouken@8604
   322
        }
slouken@8604
   323
slouken@8604
   324
        /* In the future we'll want to do this, but to match other platforms
slouken@8604
   325
           we'll leave the OpenGL version the way it is for now
slouken@8604
   326
         */
slouken@8604
   327
        /*_this->gl_config.major_version = glversion_major;*/
slouken@8604
   328
        /*_this->gl_config.minor_version = glversion_minor;*/
icculus@8278
   329
    }
slouken@2178
   330
    return context;
slime73@9587
   331
}}
slouken@1936
   332
slouken@1936
   333
int
slouken@1936
   334
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
slime73@9587
   335
{ @autoreleasepool
slouken@1936
   336
{
slouken@6848
   337
    if (context) {
jorgen@7594
   338
        SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
jorgen@7595
   339
        [nscontext setWindow:window];
jorgen@7594
   340
        [nscontext updateIfNeeded];
slouken@6848
   341
        [nscontext makeCurrentContext];
slouken@6848
   342
    } else {
slouken@6848
   343
        [NSOpenGLContext clearCurrentContext];
slouken@1936
   344
    }
slouken@1936
   345
slouken@1936
   346
    return 0;
slime73@9587
   347
}}
slouken@1936
   348
urkle@7746
   349
void
urkle@7746
   350
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
urkle@7746
   351
{
urkle@7746
   352
    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
urkle@7746
   353
    NSView *contentView = [windata->nswindow contentView];
urkle@7746
   354
    NSRect viewport = [contentView bounds];
urkle@7746
   355
icculus@12338
   356
    if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
icculus@12338
   357
        /* This gives us the correct viewport for a Retina-enabled view, only
icculus@12338
   358
         * supported on 10.7+. */
icculus@12338
   359
        if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
icculus@12338
   360
            viewport = [contentView convertRectToBacking:viewport];
icculus@12338
   361
        }
urkle@7746
   362
    }
urkle@7746
   363
urkle@7746
   364
    if (w) {
urkle@7746
   365
        *w = viewport.size.width;
urkle@7746
   366
    }
urkle@7746
   367
urkle@7746
   368
    if (h) {
urkle@7746
   369
        *h = viewport.size.height;
urkle@7746
   370
    }
urkle@7746
   371
}
urkle@7746
   372
slouken@1936
   373
int
slouken@1936
   374
Cocoa_GL_SetSwapInterval(_THIS, int interval)
slime73@9587
   375
{ @autoreleasepool
slouken@1936
   376
{
icculus@12840
   377
    NSOpenGLContext *nscontext;
icculus@12840
   378
    GLint value;
slouken@1936
   379
    int status;
slouken@1936
   380
icculus@12840
   381
    if (interval < 0) {  /* no extension for this on Mac OS X at the moment. */
icculus@12840
   382
        return SDL_SetError("Late swap tearing currently unsupported");
icculus@12840
   383
    }
icculus@12840
   384
icculus@12840
   385
    nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
icculus@12840
   386
    if (nscontext != nil) {
icculus@12840
   387
        value = interval;
icculus@12840
   388
        [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
icculus@12840
   389
        status = 0;
icculus@12840
   390
    } else {
icculus@12477
   391
        status = SDL_SetError("No current OpenGL context");
slouken@1936
   392
    }
slouken@1936
   393
slouken@1936
   394
    return status;
slime73@9587
   395
}}
slouken@1936
   396
slouken@1936
   397
int
slouken@1936
   398
Cocoa_GL_GetSwapInterval(_THIS)
slime73@9587
   399
{ @autoreleasepool
slouken@1936
   400
{
icculus@12840
   401
    NSOpenGLContext *nscontext;
icculus@12840
   402
    GLint value;
icculus@12840
   403
    int status = 0;
icculus@12840
   404
icculus@12840
   405
    nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
icculus@12840
   406
    if (nscontext != nil) {
icculus@12840
   407
        [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
icculus@12840
   408
        status = (int)value;
icculus@12840
   409
    }
icculus@12840
   410
icculus@12840
   411
    return status;
slime73@9587
   412
}}
slouken@1936
   413
slouken@10690
   414
int
slouken@1936
   415
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
slime73@9587
   416
{ @autoreleasepool
slouken@1936
   417
{
slouken@7738
   418
    SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
icculus@12343
   419
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
icculus@12343
   420
icculus@12343
   421
    /* on 10.14 ("Mojave") and later, this deadlocks if two contexts in two
icculus@12343
   422
       threads try to swap at the same time, so put a mutex around it. */
icculus@12343
   423
    SDL_LockMutex(videodata->swaplock);
slouken@7408
   424
    [nscontext flushBuffer];
jorgen@7594
   425
    [nscontext updateIfNeeded];
icculus@12343
   426
    SDL_UnlockMutex(videodata->swaplock);
slouken@10690
   427
    return 0;
slime73@9587
   428
}}
slouken@1936
   429
slouken@1936
   430
void
slouken@1936
   431
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
slime73@9587
   432
{ @autoreleasepool
slouken@1936
   433
{
jorgen@7595
   434
    SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
slouken@1936
   435
jorgen@7595
   436
    [nscontext setWindow:NULL];
slouken@6848
   437
    [nscontext release];
slime73@9587
   438
}}
slouken@1936
   439
icculus@12863
   440
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
icculus@12863
   441
#ifdef __clang__
icculus@12863
   442
#pragma clang diagnostic pop
icculus@12863
   443
#endif
icculus@12863
   444
slouken@1952
   445
#endif /* SDL_VIDEO_OPENGL_CGL */
slouken@1936
   446
slouken@1936
   447
/* vi: set ts=4 sw=4 expandtab: */