src/video/cocoa/SDL_cocoaopengl.m
author Ryan C. Gordon <icculus@icculus.org>
Sat, 14 Sep 2013 01:30:57 -0400
changeset 7743 360acf8c1526
parent 7738 10981a646a6d
child 7746 6a05d7352575
permissions -rw-r--r--
Don't incorrectly report success for negative swap intervals on Mac OS X.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6848
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
/* NSOpenGL implementation of SDL OpenGL support */
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    25
#if SDL_VIDEO_OPENGL_CGL
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    26
#include "SDL_cocoavideo.h"
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    27
#include "SDL_cocoaopengl.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    28
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include <OpenGL/CGLTypes.h>
2738
79c1bd651f04 Fixed a bunch of compile warnings on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2703
diff changeset
    30
#include <OpenGL/OpenGL.h>
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    31
#include <OpenGL/CGLRenderers.h>
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_loadso.h"
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "SDL_opengl.h"
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    36
#define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    38
6952
d2e309e7f77c Compile SDL on older versions of Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    39
#ifndef kCGLPFAOpenGLProfile
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    40
#define kCGLPFAOpenGLProfile 99
6952
d2e309e7f77c Compile SDL on older versions of Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    41
#endif
d2e309e7f77c Compile SDL on older versions of Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    42
#ifndef kCGLOGLPVersion_Legacy
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    43
#define kCGLOGLPVersion_Legacy 0x1000
6952
d2e309e7f77c Compile SDL on older versions of Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    44
#endif
d2e309e7f77c Compile SDL on older versions of Xcode
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    45
#ifndef kCGLOGLPVersion_3_2_Core
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    46
#define kCGLOGLPVersion_3_2_Core 0x3200
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    47
#endif
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    48
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    49
@implementation SDLOpenGLContext : NSOpenGLContext
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    50
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    51
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    52
        shareContext:(NSOpenGLContext *)share
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    53
{
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    54
    self = [super initWithFormat:format shareContext:share];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    55
    if (self) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    56
        SDL_AtomicSet(&self->dirty, 0);
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    57
        self->window = NULL;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    58
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    59
    return self;
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    60
}
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    61
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    62
- (void)scheduleUpdate
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    63
{
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    64
    SDL_AtomicAdd(&self->dirty, 1);
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    65
}
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    66
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    67
/* This should only be called on the thread on which a user is using the context. */
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    68
- (void)updateIfNeeded
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    69
{
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    70
    int value = SDL_AtomicSet(&self->dirty, 0);
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    71
    if (value > 0) {
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    72
        /* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    73
        [super update];
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    74
    }
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    75
}
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    76
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    77
/* This should only be called on the thread on which a user is using the context. */
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    78
- (void)update
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    79
{
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    80
    /* This ensures that regular 'update' calls clear the atomic dirty flag. */
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    81
    [self scheduleUpdate];
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    82
    [self updateIfNeeded];
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    83
}
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
    84
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    85
/* Updates the drawable for the contexts and manages related state. */
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    86
- (void)setWindow:(SDL_Window *)newWindow
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    87
{
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    88
    if (self->window) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    89
        SDL_WindowData *oldwindowdata = (SDL_WindowData *)self->window->driverdata;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    90
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    91
        /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    92
        NSMutableArray *contexts = oldwindowdata->nscontexts;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    93
        @synchronized (contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    94
            [contexts removeObject:self];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    95
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    96
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    97
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    98
    self->window = newWindow;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
    99
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   100
    if (newWindow) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   101
        SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   102
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   103
        /* Now sign up for scheduled updates for the new window. */
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   104
        NSMutableArray *contexts = windowdata->nscontexts;
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   105
        @synchronized (contexts) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   106
            [contexts addObject:self];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   107
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   108
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   109
        if ([self view] != [windowdata->nswindow contentView]) {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   110
            [self setView:[windowdata->nswindow contentView]];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   111
            [self scheduleUpdate];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   112
        }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   113
    } else {
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   114
        [self clearDrawable];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   115
        [self scheduleUpdate];
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   116
    }
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   117
}
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   118
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   119
@end
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   120
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
Cocoa_GL_LoadLibrary(_THIS, const char *path)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   125
    /* Load the OpenGL library */
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    if (path == NULL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   127
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   128
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   129
    if (path == NULL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   130
        path = DEFAULT_OPENGL;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
    _this->gl_config.dll_handle = SDL_LoadObject(path);
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    if (!_this->gl_config.dll_handle) {
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
        return -1;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    SDL_strlcpy(_this->gl_config.driver_path, path,
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
                SDL_arraysize(_this->gl_config.driver_path));
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    return 0;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
void *
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
Cocoa_GL_GetProcAddress(_THIS, const char *proc)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
{
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
    return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   147
void
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
Cocoa_GL_UnloadLibrary(_THIS)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   150
    SDL_UnloadObject(_this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   151
    _this->gl_config.dll_handle = NULL;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
SDL_GLContext
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
{
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   157
    const int wantver = (_this->gl_config.major_version << 8) |
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   158
                        (_this->gl_config.minor_version);
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   159
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   160
    NSAutoreleasePool *pool;
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 4925
diff changeset
   161
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    NSOpenGLPixelFormatAttribute attr[32];
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    NSOpenGLPixelFormat *fmt;
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   165
    SDLOpenGLContext *context;
7152
e9ed46195235 Implemented SDL_GL_SHARE_WITH_CURRENT_CONTEXT for Mac OS X.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 7108
diff changeset
   166
    NSOpenGLContext *share_context = nil;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    int i = 0;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   169
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   170
        SDL_SetError ("OpenGL ES not supported on this platform");
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   171
        return NULL;
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   172
    }
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   173
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   174
    /* Sadly, we'll have to update this as life progresses, since we need to
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   175
       set an enum for context profiles, not a context version number */
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   176
    if (wantver > 0x0302) {
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   177
        SDL_SetError ("OpenGL > 3.2 is not supported on this platform");
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   178
        return NULL;
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   179
    }
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   180
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   181
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   182
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   183
    /* specify a profile if we're on Lion (10.7) or later. */
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   184
    if (data->osversion >= 0x1070) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   185
        NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   186
        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   187
            if (wantver == 0x0302) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   188
                profile = kCGLOGLPVersion_3_2_Core;
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   189
            }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   190
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   191
        attr[i++] = kCGLPFAOpenGLProfile;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   192
        attr[i++] = profile;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   193
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   194
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   195
    attr[i++] = NSOpenGLPFAColorSize;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   196
    attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   197
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   198
    attr[i++] = NSOpenGLPFADepthSize;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   199
    attr[i++] = _this->gl_config.depth_size;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   200
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   201
    if (_this->gl_config.double_buffer) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   202
        attr[i++] = NSOpenGLPFADoubleBuffer;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   203
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   204
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   205
    if (_this->gl_config.stereo) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   206
        attr[i++] = NSOpenGLPFAStereo;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   207
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   208
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   209
    if (_this->gl_config.stencil_size) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   210
        attr[i++] = NSOpenGLPFAStencilSize;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   211
        attr[i++] = _this->gl_config.stencil_size;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   212
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   213
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   214
    if ((_this->gl_config.accum_red_size +
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   215
         _this->gl_config.accum_green_size +
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   216
         _this->gl_config.accum_blue_size +
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   217
         _this->gl_config.accum_alpha_size) > 0) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   218
        attr[i++] = NSOpenGLPFAAccumSize;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   219
        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;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   220
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   221
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   222
    if (_this->gl_config.multisamplebuffers) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   223
        attr[i++] = NSOpenGLPFASampleBuffers;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   224
        attr[i++] = _this->gl_config.multisamplebuffers;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   225
    }
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   226
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   227
    if (_this->gl_config.multisamplesamples) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   228
        attr[i++] = NSOpenGLPFASamples;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   229
        attr[i++] = _this->gl_config.multisamplesamples;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   230
        attr[i++] = NSOpenGLPFANoRecovery;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   231
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   232
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   233
    if (_this->gl_config.accelerated >= 0) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   234
        if (_this->gl_config.accelerated) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   235
            attr[i++] = NSOpenGLPFAAccelerated;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   236
        } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   237
            attr[i++] = NSOpenGLPFARendererID;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   238
            attr[i++] = kCGLRendererGenericFloatID;
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   239
        }
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   240
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   241
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   242
    attr[i++] = NSOpenGLPFAScreenMask;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   243
    attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   244
    attr[i] = 0;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   245
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   246
    fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   247
    if (fmt == nil) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   248
        SDL_SetError ("Failed creating OpenGL pixel format");
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   249
        [pool release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   250
        return NULL;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   251
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   252
7152
e9ed46195235 Implemented SDL_GL_SHARE_WITH_CURRENT_CONTEXT for Mac OS X.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 7108
diff changeset
   253
    if (_this->gl_config.share_with_current_context) {
7412
50211a1fd557 Fixed bug 1946 - OpenGL contexts in threads
Sam Lantinga <slouken@libsdl.org>
parents: 7408
diff changeset
   254
        share_context = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
7152
e9ed46195235 Implemented SDL_GL_SHARE_WITH_CURRENT_CONTEXT for Mac OS X.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 7108
diff changeset
   255
    }
e9ed46195235 Implemented SDL_GL_SHARE_WITH_CURRENT_CONTEXT for Mac OS X.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 7108
diff changeset
   256
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   257
    context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   258
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   259
    [fmt release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   260
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   261
    if (context == nil) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   262
        SDL_SetError ("Failed creating OpenGL context");
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   263
        [pool release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   264
        return NULL;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   265
    }
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   266
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   267
    [pool release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   269
    if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   270
        Cocoa_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   271
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   272
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   273
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   274
    return context;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   280
    NSAutoreleasePool *pool;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   281
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   282
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   283
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   284
    if (context) {
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   285
        SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   286
        [nscontext setWindow:window];
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   287
        [nscontext updateIfNeeded];
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   288
        [nscontext makeCurrentContext];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   289
    } else {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   290
        [NSOpenGLContext clearCurrentContext];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   293
    [pool release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    return 0;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
Cocoa_GL_SetSwapInterval(_THIS, int interval)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   300
    NSAutoreleasePool *pool;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
    NSOpenGLContext *nscontext;
2703
18a472b6d745 Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   302
    GLint value;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
    int status;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
7743
360acf8c1526 Don't incorrectly report success for negative swap intervals on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 7738
diff changeset
   305
    if (interval < 0) {  /* no extension for this on Mac OS X at the moment. */
360acf8c1526 Don't incorrectly report success for negative swap intervals on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 7738
diff changeset
   306
        return SDL_SetError("Late swap tearing currently unsupported");
360acf8c1526 Don't incorrectly report success for negative swap intervals on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 7738
diff changeset
   307
    }
360acf8c1526 Don't incorrectly report success for negative swap intervals on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 7738
diff changeset
   308
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   309
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   310
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   311
    nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   312
    if (nscontext != nil) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   313
        value = interval;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   314
        [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   315
        status = 0;
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   316
    } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6952
diff changeset
   317
        status = SDL_SetError("No current OpenGL context");
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   320
    [pool release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    return status;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
Cocoa_GL_GetSwapInterval(_THIS)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   327
    NSAutoreleasePool *pool;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
    NSOpenGLContext *nscontext;
2703
18a472b6d745 Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   329
    GLint value;
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6260
diff changeset
   330
    int status = 0;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   332
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   333
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   334
    nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   335
    if (nscontext != nil) {
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   336
        [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   337
        status = (int)value;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   340
    [pool release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
    return status;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
void
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   347
    NSAutoreleasePool *pool;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   349
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   350
7738
10981a646a6d Mac: Fix cast warning.
Sam Lantinga <slouken@libsdl.org>
parents: 7595
diff changeset
   351
    SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
7408
c50e165abfdf Fixed bug 1958 - Cocoa SwapWindow doesn't swap the specified window
Sam Lantinga <slouken@libsdl.org>
parents: 7389
diff changeset
   352
    [nscontext flushBuffer];
7594
6abcf951af68 Mac: Don't -[NSOpenGLContext update] on (potentially) the wrong thread.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7412
diff changeset
   353
    [nscontext updateIfNeeded];
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   354
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   355
    [pool release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
void
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
{
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   361
    NSAutoreleasePool *pool;
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   362
    SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   364
    pool = [[NSAutoreleasePool alloc] init];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   365
7595
ede2237fcebf Mac: Support for multiple contexts per SDL_Window.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents: 7594
diff changeset
   366
    [nscontext setWindow:NULL];
6848
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   367
    [nscontext release];
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   368
478ecc8a58b3 Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
Sam Lantinga <slouken@libsdl.org>
parents: 6832
diff changeset
   369
    [pool release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   372
#endif /* SDL_VIDEO_OPENGL_CGL */
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
/* vi: set ts=4 sw=4 expandtab: */