src/video/uikit/SDL_uikitopengles.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 30 Sep 2012 01:01:48 -0700
changeset 6521 f36bbe0a10c9
parent 6518 42948831d16e
child 6885 700f1b25f77f
child 8314 24f2de48557b
permissions -rw-r--r--
Remove the viewcontroller from the window when he OpenGL context is destroyed
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
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6088
diff changeset
     3
  Copyright (C) 1997-2012 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
*/
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
    21
#include "SDL_config.h"
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"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_uikitopenglview.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_uikitappdelegate.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
    28
#include "SDL_uikitmodes.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_uikitwindow.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include "jumphack.h"
6321
71fa3d8976a3 Fixed includes for Objective C
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    31
#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
    32
#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
    33
#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
    34
#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
    35
#include "SDL_loadso.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include <dlfcn.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
static int UIKit_GL_Initialize(_THIS);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
void *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
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
    42
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    43
    /* Look through all SO's for the proc symbol.  Here's why:
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    44
       -Looking for the path to the OpenGL Library seems not to work in the iPhone Simulator.
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    45
       -We don't know that the path won't change in the future.
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    46
    */
5363
96799a165806 Fixed testgles on iOS (bug 1136)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    47
    return dlsym(RTLD_DEFAULT, proc);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
/*
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    51
    note that SDL_GL_Delete context 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
    52
*/
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    55
    if (context) {
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    56
        SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    57
        [data->view setCurrentContext];
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    58
    }
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    59
    else {
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    60
        [EAGLContext setCurrentContext: nil];
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    61
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    62
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
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
    68
{
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    69
    /*
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    70
        shouldn't be passing a path into this function
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    71
        why?  Because we've already loaded the library
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    72
        and because the SDK forbids loading an external SO
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    73
    */
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    if (path != NULL) {
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    75
        SDL_SetError("iPhone GL Load Library just here for compatibility");
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    76
        return -1;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
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
    82
{
6088
eedb8e10ac22 Fix iOS build when SDL_POWER_UIKIT isn't defined.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
    83
#if SDL_POWER_UIKIT
4444
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    84
    // Check once a frame to see if we should turn off the battery monitor.
42e1092225f9 Implemented SDL power APIs for iPhoneOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    85
    SDL_UIKit_UpdateBatteryMonitoring();
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    86
#endif
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    88
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    89
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    90
    if (nil == data->view) {
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    91
        return;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    92
    }
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    93
    [data->view swapBuffers];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    95
    /* we need to let the event cycle run, or the OS won't update the OpenGL view! */
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
    96
    SDL_PumpEvents();
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   101
    SDL_uikitopenglview *view;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   102
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
6267
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   103
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   104
    SDL_DisplayData *displaydata = display->driverdata;
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   105
    SDL_DisplayModeData *displaymodedata = display->current_mode.driverdata;
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   106
    UIWindow *uiwindow = data->uiwindow;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4444
diff changeset
   108
    /* construct our view, passing in SDL's OpenGL configuration data */
6439
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   109
    CGRect frame;
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   110
    if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   111
        frame = [displaydata->uiscreen bounds];
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   112
    } else {
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   113
        frame = [displaydata->uiscreen applicationFrame];
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   114
    }
fbbd640d7867 Fixed touch coordinates with the new UI bounds calculation
Sam Lantinga <slouken@libsdl.org>
parents: 6437
diff changeset
   115
    view = [[SDL_uikitopenglview alloc] initWithFrame: frame
6267
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   116
                                    scale: displaymodedata->scale
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   117
                                    retainBacking: _this->gl_config.retained_backing
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   118
                                    rBits: _this->gl_config.red_size
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   119
                                    gBits: _this->gl_config.green_size
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   120
                                    bBits: _this->gl_config.blue_size
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   121
                                    aBits: _this->gl_config.alpha_size
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   122
                                    depthBits: _this->gl_config.depth_size
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6003
diff changeset
   123
                                    stencilBits: _this->gl_config.stencil_size
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5132
diff changeset
   124
                                    majorVersion: _this->gl_config.major_version];
6179
a83eb92704f3 Fixed bug 1342 - SDL_CreateRenderer creates OpenGL ES 2.0 renderer in iPhone 3G using default index (-1)
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   125
    if (!view) {
a83eb92704f3 Fixed bug 1342 - SDL_CreateRenderer creates OpenGL ES 2.0 renderer in iPhone 3G using default index (-1)
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   126
        return NULL;
a83eb92704f3 Fixed bug 1342 - SDL_CreateRenderer creates OpenGL ES 2.0 renderer in iPhone 3G using default index (-1)
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   127
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   128
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   129
    data->view = view;
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   130
    view->viewcontroller = data->viewcontroller;
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   131
    if (view->viewcontroller != nil) {
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   132
        [view->viewcontroller setView:view];
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   133
        [view->viewcontroller retain];
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   134
    }
6521
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   135
    [uiwindow addSubview: view];
6451
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6439
diff changeset
   136
    
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6439
diff changeset
   137
    // The view controller needs to be the root in order to control rotation on iOS 6.0
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6439
diff changeset
   138
    if (uiwindow.rootViewController == nil) {
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6439
diff changeset
   139
        uiwindow.rootViewController = view->viewcontroller;
52e5a05ca795 Fixed autorotate / resize support on iOS 6.0, tested with iPad and iPhone simulators with iOS 5.1 and 6.0
Sam Lantinga <slouken@libsdl.org>
parents: 6439
diff changeset
   140
    }
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   141
6521
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   142
    if (UIKit_GL_MakeCurrent(_this, window, view) < 0) {
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
        UIKit_GL_DeleteContext(_this, view);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
        return NULL;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    }
4488
6dc6a2bdd55e Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   146
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   147
    /* Make this window the current mouse focus for touch input */
6267
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   148
    if (displaydata->uiscreen == [UIScreen mainScreen]) {
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   149
        SDL_SetMouseFocus(window);
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   150
        SDL_SetKeyboardFocus(window);
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6179
diff changeset
   151
    }
4488
6dc6a2bdd55e Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
   152
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   153
    return view;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
{
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   158
    /* the delegate has retained the view, this will release him */
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   159
    SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   160
    if (view->viewcontroller) {
6521
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   161
        UIWindow *uiwindow = (UIWindow *)view.superview;
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   162
        if (uiwindow.rootViewController == view->viewcontroller) {
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   163
            uiwindow.rootViewController = nil;
f36bbe0a10c9 Remove the viewcontroller from the window when he OpenGL context is destroyed
Sam Lantinga <slouken@libsdl.org>
parents: 6518
diff changeset
   164
        }
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   165
        [view->viewcontroller setView:nil];
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   166
        [view->viewcontroller release];
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   167
    }
5131
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 4490
diff changeset
   168
    [view removeFromSuperview];
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5363
diff changeset
   169
    [view release];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6021
diff changeset
   172
#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
   173
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5131
diff changeset
   174
/* vi: set ts=4 sw=4 expandtab: */