src/video/uikit/SDL_uikitopengles.m
author Alex Szpakowski <slime73@gmail.com>
Sun, 10 Apr 2016 22:07:10 -0300
changeset 10143 14719cd1bde2
parent 10141 fe9cf7c678f4
permissions -rw-r--r--
iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
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: 5527
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9879
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
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: 5527
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: 5527
diff changeset
     7
  arising from the use of this software.
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
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: 5527
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: 5527
diff changeset
    11
  freely, subject to the following restrictions:
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
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: 5527
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: 5527
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: 5527
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5527
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: 5527
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: 5527
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7425
diff changeset
    21
#include "../../SDL_internal.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_uikitopengles.h"
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    26
#import "SDL_uikitopenglview.h"
6518
42948831d16e Refactored the UIKit mode code into a separate file so it's cleaner and more consistent with other backends
Sam Lantinga <slouken@libsdl.org>
parents: 6451
diff changeset
    27
#include "SDL_uikitmodes.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_uikitwindow.h"
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    29
#include "SDL_uikitevents.h"
6321
71fa3d8976a3 Fixed includes for Objective C
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    30
#include "../SDL_sysvideo.h"
4490
06c7423f8c60 Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents: 4488
diff changeset
    31
#include "../../events/SDL_keyboard_c.h"
06c7423f8c60 Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents: 4488
diff changeset
    32
#include "../../events/SDL_mouse_c.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    33
#include "../../power/uikit/SDL_syspower.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "SDL_loadso.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include <dlfcn.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    37
@interface SDLEAGLContext : EAGLContext
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    38
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    39
/* The OpenGL ES context owns a view / drawable. */
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    40
@property (nonatomic, strong) SDL_uikitopenglview *sdlView;
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    41
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    42
@end
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    43
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    44
@implementation SDLEAGLContext
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    45
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    46
- (void)dealloc
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    47
{
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    48
    /* When the context is deallocated, its view should be removed from any
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    49
     * SDL window that it's attached to. */
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    50
    [self.sdlView setSDLWindow:NULL];
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    51
}
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    52
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    53
@end
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    54
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
void *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
UIKit_GL_GetProcAddress(_THIS, const char *proc)
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    57
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    58
    /* Look through all SO's for the proc symbol.  Here's why:
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    59
     * -Looking for the path to the OpenGL Library seems not to work in the iOS Simulator.
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    60
     * -We don't know that the path won't change in the future. */
5363
96799a165806 Fixed testgles on iOS (bug 1136)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    61
    return dlsym(RTLD_DEFAULT, proc);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
/*
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    65
  note that SDL_GL_DeleteContext makes it current without passing the window
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
*/
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    67
int
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    68
UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    70
    @autoreleasepool {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    71
        SDLEAGLContext *eaglcontext = (__bridge SDLEAGLContext *) context;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    72
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    73
        if (![EAGLContext setCurrentContext:eaglcontext]) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    74
            return SDL_SetError("Could not make EAGL context current");
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    75
        }
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    76
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    77
        if (eaglcontext) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    78
            [eaglcontext.sdlView setSDLWindow:window];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    79
        }
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    80
    }
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    81
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
9529
4bf9830d8153 Minor Objective-C code tweaks.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
    85
void
4bf9830d8153 Minor Objective-C code tweaks.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
    86
UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
    87
{
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    88
    @autoreleasepool {
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
    89
        SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    90
        UIView *view = data.viewcontroller.view;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    91
        if ([view isKindOfClass:[SDL_uikitopenglview class]]) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    92
            SDL_uikitopenglview *glview = (SDL_uikitopenglview *) view;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    93
            if (w) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    94
                *w = glview.backingWidth;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    95
            }
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    96
            if (h) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    97
                *h = glview.backingHeight;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    98
            }
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
    99
        }
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   100
    }
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   101
}
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   102
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
UIKit_GL_LoadLibrary(_THIS, const char *path)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
{
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   106
    /* We shouldn't pass a path to this function, since we've already loaded the
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   107
     * library. */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    if (path != NULL) {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   109
        return SDL_SetError("iOS GL Load Library just here for compatibility");
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   116
    @autoreleasepool {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   117
        SDLEAGLContext *context = (__bridge SDLEAGLContext *) SDL_GL_GetCurrentContext();
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   118
6088
eedb8e10ac22 Fix iOS build when SDL_POWER_UIKIT isn't defined.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   119
#if SDL_POWER_UIKIT
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   120
        /* Check once a frame to see if we should turn off the battery monitor. */
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   121
        SDL_UIKit_UpdateBatteryMonitoring();
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   122
#endif
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   124
        [context.sdlView swapBuffers];
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   125
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   126
        /* You need to pump events in order for the OS to make changes visible.
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   127
         * We don't pump events here because we don't want iOS application events
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   128
         * (low memory, terminate, etc.) to happen inside low level rendering. */
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   129
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   132
SDL_GLContext
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   133
UIKit_GL_CreateContext(_THIS, SDL_Window * window)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   135
    @autoreleasepool {
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   136
        SDLEAGLContext *context = nil;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   137
        SDL_uikitopenglview *view;
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9506
diff changeset
   138
        SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   139
        CGRect frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen);
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   140
        EAGLSharegroup *sharegroup = nil;
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   141
        CGFloat scale = 1.0;
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   142
        int samples = 0;
10143
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   143
        int major = _this->gl_config.major_version;
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   144
        int minor = _this->gl_config.minor_version;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   145
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   146
        /* The EAGLRenderingAPI enum values currently map 1:1 to major GLES
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   147
         * versions. */
10143
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   148
        EAGLRenderingAPI api = major;
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   149
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   150
        /* iOS currently doesn't support GLES >3.0. iOS 6 also only supports up
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   151
         * to GLES 2.0. */
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   152
        if (major > 3 || (major == 3 && (minor > 0 || !UIKit_IsSystemVersionAtLeast(7.0)))) {
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   153
            SDL_SetError("OpenGL ES %d.%d context could not be created", major, minor);
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   154
            return NULL;
14719cd1bde2 iOS: Fixed SDL_GL_CreateContext crashing instead of returning null when a GLES3 context is requested on iOS 6 and older.
Alex Szpakowski <slime73@gmail.com>
parents: 10141
diff changeset
   155
        }
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   156
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   157
        if (_this->gl_config.multisamplebuffers > 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   158
            samples = _this->gl_config.multisamplesamples;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   159
        }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   160
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   161
        if (_this->gl_config.share_with_current_context) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   162
            EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   163
            sharegroup = context.sharegroup;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   164
        }
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   165
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   166
        if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
9517
dbe19a0cad97 Enabling highdpi mode on an iPhone 6 Plus should now create a 1080x1920 OpenGL view, rather than 1242x2208 (414x736@3x.)
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   167
            /* Set the scale to the natural scale factor of the screen - the
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   168
             * backing dimensions of the OpenGL view will match the pixel
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   169
             * dimensions of the screen rather than the dimensions in points. */
9517
dbe19a0cad97 Enabling highdpi mode on an iPhone 6 Plus should now create a 1080x1920 OpenGL view, rather than 1242x2208 (414x736@3x.)
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   170
#ifdef __IPHONE_8_0
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   171
            if ([data.uiwindow.screen respondsToSelector:@selector(nativeScale)]) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   172
                scale = data.uiwindow.screen.nativeScale;
9517
dbe19a0cad97 Enabling highdpi mode on an iPhone 6 Plus should now create a 1080x1920 OpenGL view, rather than 1242x2208 (414x736@3x.)
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   173
            } else
dbe19a0cad97 Enabling highdpi mode on an iPhone 6 Plus should now create a 1080x1920 OpenGL view, rather than 1242x2208 (414x736@3x.)
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   174
#endif
dbe19a0cad97 Enabling highdpi mode on an iPhone 6 Plus should now create a 1080x1920 OpenGL view, rather than 1242x2208 (414x736@3x.)
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   175
            {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   176
                scale = data.uiwindow.screen.scale;
9517
dbe19a0cad97 Enabling highdpi mode on an iPhone 6 Plus should now create a 1080x1920 OpenGL view, rather than 1242x2208 (414x736@3x.)
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   177
            }
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   178
        }
7423
dfe7ad02f008 Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 7285
diff changeset
   179
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   180
        context = [[SDLEAGLContext alloc] initWithAPI:api sharegroup:sharegroup];
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   181
        if (!context) {
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   182
            SDL_SetError("OpenGL ES %d context could not be created", _this->gl_config.major_version);
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   183
            return NULL;
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   184
        }
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   185
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   186
        /* construct our view, passing in SDL's OpenGL configuration data */
9524
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   187
        view = [[SDL_uikitopenglview alloc] initWithFrame:frame
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   188
                                                    scale:scale
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   189
                                            retainBacking:_this->gl_config.retained_backing
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   190
                                                    rBits:_this->gl_config.red_size
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   191
                                                    gBits:_this->gl_config.green_size
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   192
                                                    bBits:_this->gl_config.blue_size
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   193
                                                    aBits:_this->gl_config.alpha_size
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   194
                                                depthBits:_this->gl_config.depth_size
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   195
                                              stencilBits:_this->gl_config.stencil_size
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9517
diff changeset
   196
                                                     sRGB:_this->gl_config.framebuffer_srgb_capable
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   197
                                             multisamples:samples
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   198
                                                  context:context];
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   199
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   200
        if (!view) {
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   201
            return NULL;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   202
        }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   204
        /* The context owns the view / drawable. */
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   205
        context.sdlView = view;
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   206
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   207
        if (UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext) context) < 0) {
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   208
            UIKit_GL_DeleteContext(_this, (SDL_GLContext) CFBridgingRetain(context));
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   209
            return NULL;
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   210
        }
4488
6dc6a2bdd55e Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   211
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   212
        /* We return a +1'd context. The window's driverdata owns the view (via
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   213
         * MakeCurrent.) */
9512
c9f61d1dac7b Merged default into iOS-improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9510 9045
diff changeset
   214
        return (SDL_GLContext) CFBridgingRetain(context);
6439
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   215
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   218
void
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8583
diff changeset
   219
UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
{
9506
18e3f94bd860 Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   221
    @autoreleasepool {
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   222
        /* The context was retained in SDL_GL_CreateContext, so we release it
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   223
         * here. The context's view will be detached from its window when the
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   224
         * context is deallocated. */
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   225
        CFRelease(context);
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   226
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
10141
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   229
void
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   230
UIKit_GL_RestoreCurrentContext()
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   231
{
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   232
    @autoreleasepool {
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   233
        /* Some iOS system functionality (such as Dictation on the on-screen
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   234
         keyboard) uses its own OpenGL ES context but doesn't restore the
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   235
         previous one when it's done. This is a workaround to make sure the
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   236
         expected SDL-created OpenGL ES context is active after the OS is
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   237
         finished running its own code for the frame. If this isn't done, the
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   238
         app may crash or have other nasty symptoms when Dictation is used.
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   239
         */
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   240
        EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   241
        if (context != NULL && [EAGLContext currentContext] != context) {
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   242
            [EAGLContext setCurrentContext:context];
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   243
        }
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   244
    }
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   245
}
fe9cf7c678f4 iOS: Also do the Dictation crash workaround before executing the animation callback.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
   246
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
   247
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
   248
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5131
diff changeset
   249
/* vi: set ts=4 sw=4 expandtab: */