src/video/cocoa/SDL_cocoaopengl.m
author stopiccot <alexey.petruchik@gmail.com>
Sun, 06 Jan 2013 19:04:53 +0300
changeset 6832 156e608ec4ef
parent 6567 d50613615139
child 6848 478ecc8a58b3
permissions -rw-r--r--
Replaced manual NSAutoreleasePool handing with @autorelease
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
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6044
diff changeset
     3
  Copyright (C) 1997-2012 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"
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    27
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#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
    29
#include <OpenGL/OpenGL.h>
3570
7812d3e9564e OpenGL hardware acceleration defaults on
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    30
#include <OpenGL/CGLRenderers.h>
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "SDL_loadso.h"
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_opengl.h"
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    35
#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
    36
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    37
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    38
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    39
#define kCGLPFAOpenGLProfile 99
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 kCGLOGLPVersion_Legacy 0x1000
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    41
#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
    42
#endif
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    43
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
Cocoa_GL_LoadLibrary(_THIS, const char *path)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    48
    /* Load the OpenGL library */
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
    if (path == NULL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    50
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    51
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    52
    if (path == NULL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    53
        path = DEFAULT_OPENGL;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    _this->gl_config.dll_handle = SDL_LoadObject(path);
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
    if (!_this->gl_config.dll_handle) {
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
        return -1;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
    SDL_strlcpy(_this->gl_config.driver_path, path,
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
                SDL_arraysize(_this->gl_config.driver_path));
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
    return 0;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
void *
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
Cocoa_GL_GetProcAddress(_THIS, const char *proc)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
{
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    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
    68
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    70
void
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
Cocoa_GL_UnloadLibrary(_THIS)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    73
    SDL_UnloadObject(_this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    74
    _this->gl_config.dll_handle = NULL;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
SDL_GLContext
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
{
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    80
    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
    81
                        (_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
    82
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
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
    83
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    NSOpenGLPixelFormatAttribute attr[32];
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    NSOpenGLPixelFormat *fmt;
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
    87
    NSOpenGLContext *context;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    int i = 0;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    90
    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
    91
        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
    92
        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
    93
    }
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    94
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
    95
    /* 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
    96
       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
    97
    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
    98
        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
    99
        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
   100
    }
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   101
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   102
    @autoreleasepool {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   103
        /* specify a profile if we're on Lion (10.7) or later. */
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   104
        if (data->osversion >= 0x1070) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   105
            NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   106
            if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   107
                if (wantver == 0x0302) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   108
                    profile = kCGLOGLPVersion_3_2_Core;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   109
                }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   110
            }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   111
            attr[i++] = kCGLPFAOpenGLProfile;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   112
            attr[i++] = profile;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   113
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   114
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   115
    #ifndef FULLSCREEN_TOGGLEABLE
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   116
        if (window->flags & SDL_WINDOW_FULLSCREEN) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   117
            attr[i++] = NSOpenGLPFAFullScreen;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   118
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   119
    #endif
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   120
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   121
        attr[i++] = NSOpenGLPFAColorSize;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   122
        attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   123
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   124
        attr[i++] = NSOpenGLPFADepthSize;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   125
        attr[i++] = _this->gl_config.depth_size;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   126
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   127
        if (_this->gl_config.double_buffer) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   128
            attr[i++] = NSOpenGLPFADoubleBuffer;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   129
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   131
        if (_this->gl_config.stereo) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   132
            attr[i++] = NSOpenGLPFAStereo;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   133
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   134
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   135
        if (_this->gl_config.stencil_size) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   136
            attr[i++] = NSOpenGLPFAStencilSize;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   137
            attr[i++] = _this->gl_config.stencil_size;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   138
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   139
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   140
        if ((_this->gl_config.accum_red_size +
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   141
             _this->gl_config.accum_green_size +
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   142
             _this->gl_config.accum_blue_size +
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   143
             _this->gl_config.accum_alpha_size) > 0) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   144
            attr[i++] = NSOpenGLPFAAccumSize;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   145
            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;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   146
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   147
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   148
        if (_this->gl_config.multisamplebuffers) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   149
            attr[i++] = NSOpenGLPFASampleBuffers;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   150
            attr[i++] = _this->gl_config.multisamplebuffers;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   151
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   152
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   153
        if (_this->gl_config.multisamplesamples) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   154
            attr[i++] = NSOpenGLPFASamples;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   155
            attr[i++] = _this->gl_config.multisamplesamples;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   156
            attr[i++] = NSOpenGLPFANoRecovery;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   157
        }
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   158
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   159
        if (_this->gl_config.accelerated >= 0) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   160
            if (_this->gl_config.accelerated) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   161
                attr[i++] = NSOpenGLPFAAccelerated;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   162
            } else {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   163
                attr[i++] = NSOpenGLPFARendererID;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   164
                attr[i++] = kCGLRendererGenericFloatID;
6567
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   165
            }
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   166
        }
d50613615139 Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   167
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   168
        attr[i++] = NSOpenGLPFAScreenMask;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   169
        attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   170
        attr[i] = 0;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   172
        fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   173
        if (fmt == nil) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   174
            SDL_SetError ("Failed creating OpenGL pixel format");
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   175
            return NULL;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   176
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   178
        context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   179
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   180
        [fmt release];
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   182
        if (context == nil) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   183
            SDL_SetError ("Failed creating OpenGL context");
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   184
            return NULL;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   185
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   187
        /*
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   188
         * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   189
         *  "You are blowing a couple of the internal OpenGL function caches. This
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   190
         *  appears to be happening in the VAO case.  You can tell OpenGL to up
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   191
         *  the cache size by issuing the following calls right after you create
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   192
         *  the OpenGL context.  The default cache size is 16."    --ryan.
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   193
         */
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   195
        #ifndef GLI_ARRAY_FUNC_CACHE_MAX
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   196
        #define GLI_ARRAY_FUNC_CACHE_MAX 284
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   197
        #endif
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   199
        #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   200
        #define GLI_SUBMIT_FUNC_CACHE_MAX 280
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   201
        #endif
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   203
        {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   204
            GLint cache_max = 64;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   205
            CGLContextObj ctx = [context CGLContextObj];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   206
            CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   207
            CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
3571
19691cebb866 Default to allow either accelerated or not
Sam Lantinga <slouken@libsdl.org>
parents: 3570
diff changeset
   208
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
    /* End Wisdom from Apple Engineer section. --ryan. */
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   212
    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
   213
        Cocoa_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   214
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   215
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   216
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 1973
diff changeset
   217
    return context;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
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
   222
{
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   223
    @autoreleasepool {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   224
        if (context) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   225
            SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   226
            NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   228
            if (window->flags & SDL_WINDOW_SHOWN) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   229
    #ifndef FULLSCREEN_TOGGLEABLE
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   230
                if (window->flags & SDL_WINDOW_FULLSCREEN) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   231
                    [nscontext setFullScreen];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   232
                } else
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   233
    #endif
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   234
                {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   235
                    [nscontext setView:[windowdata->nswindow contentView]];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   236
                    [nscontext update];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   237
                }
6260
fd494c5f305b Fixed loading textures when the window starts hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   238
            }
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   239
            [nscontext makeCurrentContext];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   240
        } else {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   241
            [NSOpenGLContext clearCurrentContext];
1973
81255f93dfcd Fixed fullscreen modes with Cocoa video driver.
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
   242
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
    return 0;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
Cocoa_GL_SetSwapInterval(_THIS, int interval)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
{
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
    NSOpenGLContext *nscontext;
2703
18a472b6d745 Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   252
    GLint value;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
    int status;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   255
    @autoreleasepool {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   256
        nscontext = [NSOpenGLContext currentContext];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   257
        if (nscontext != nil) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   258
            value = interval;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   259
            [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   260
            status = 0;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   261
        } else {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   262
            SDL_SetError("No current OpenGL context");
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   263
            status = -1;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   264
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
    return status;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
int
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
Cocoa_GL_GetSwapInterval(_THIS)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
{
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
    NSOpenGLContext *nscontext;
2703
18a472b6d745 Fixed compiler warning
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   274
    GLint value;
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6260
diff changeset
   275
    int status = 0;
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   277
    @autoreleasepool {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   278
        nscontext = [NSOpenGLContext currentContext];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   279
        if (nscontext != nil) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   280
            [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   281
            status = (int)value;
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   282
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
    return status;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
void
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
{
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
    NSOpenGLContext *nscontext;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   293
    @autoreleasepool {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   294
        /* FIXME: Do we need to get the context for the window? */
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   295
        nscontext = [NSOpenGLContext currentContext];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   296
        if (nscontext != nil) {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   297
            [nscontext flushBuffer];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   298
        }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    }
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
void
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
{
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
    NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
6832
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   307
    @autoreleasepool {
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   308
        [nscontext clearDrawable];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   309
        [nscontext release];
156e608ec4ef Replaced manual NSAutoreleasePool handing with @autorelease
stopiccot <alexey.petruchik@gmail.com>
parents: 6567
diff changeset
   310
    }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
}
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   313
#endif /* SDL_VIDEO_OPENGL_CGL */
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
/* vi: set ts=4 sw=4 expandtab: */