src/video/uikit/SDL_uikitopenglview.m
author Alex Szpakowski <slime73@gmail.com>
Tue, 28 Oct 2014 01:34:40 -0300
branchiOS-improvements
changeset 9520 6a655264dd47
parent 9514 5b56ab9ff5fe
child 9524 9de159f9cefd
permissions -rw-r--r--
Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions. Both the extension (OES) and the core versions work, but the core versions are more correct for GLES2+ and they're less verbose.
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
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5209
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: 5209
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: 5209
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: 5209
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: 7784
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: 6022
diff changeset
    22
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6022
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
6686
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
    25
#include <QuartzCore/QuartzCore.h>
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
    26
#include <OpenGLES/EAGLDrawable.h>
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    27
#include <OpenGLES/ES2/gl.h>
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    28
#include <OpenGLES/ES2/glext.h>
6686
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
    29
#include "SDL_uikitopenglview.h"
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
    30
#include "SDL_uikitmessagebox.h"
9502
933ed557b7c1 Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.
Alex Szpakowski <slime73@gmail.com>
parents: 9501
diff changeset
    31
#include "SDL_uikitvideo.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    34
@implementation SDL_uikitopenglview {
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    35
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    36
    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    37
    GLuint viewRenderbuffer, viewFramebuffer;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    38
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    39
    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    40
    GLuint depthRenderbuffer;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    41
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    42
    /* format of depthRenderbuffer */
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    43
    GLenum depthBufferFormat;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    44
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    45
    id displayLink;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    46
    int animationInterval;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    47
    void (*animationCallback)(void*);
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    48
    void *animationCallbackParam;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    49
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    50
}
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
@synthesize context;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    54
@synthesize backingWidth;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    55
@synthesize backingHeight;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8891
diff changeset
    56
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    57
+ (Class)layerClass
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    58
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    59
    return [CAEAGLLayer class];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    62
- (id)initWithFrame:(CGRect)frame
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    63
              scale:(CGFloat)scale
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    64
      retainBacking:(BOOL)retained
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    65
              rBits:(int)rBits
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    66
              gBits:(int)gBits
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    67
              bBits:(int)bBits
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    68
              aBits:(int)aBits
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    69
          depthBits:(int)depthBits
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    70
        stencilBits:(int)stencilBits
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    71
               sRGB:(BOOL)sRGB
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    72
       majorVersion:(int)majorVersion
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    73
         shareGroup:(EAGLSharegroup*)shareGroup
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
{
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    75
    if ((self = [super initWithFrame:frame])) {
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    76
        const BOOL useStencilBuffer = (stencilBits != 0);
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    77
        const BOOL useDepthBuffer = (depthBits != 0);
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    78
        NSString *colorFormat = nil;
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    79
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    80
        self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    81
        self.autoresizesSubviews = YES;
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    82
8233
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    83
        /* The EAGLRenderingAPI enum values currently map 1:1 to major GLES
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    84
           versions, and this allows us to handle future OpenGL ES versions.
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    85
         */
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    86
        EAGLRenderingAPI api = majorVersion;
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    87
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    88
        context = [[EAGLContext alloc] initWithAPI:api sharegroup:shareGroup];
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    89
        if (!context || ![EAGLContext setCurrentContext:context]) {
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    90
            SDL_SetError("OpenGL ES %d not supported", majorVersion);
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    91
            return nil;
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    92
        }
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
    93
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    94
        if (sRGB) {
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    95
            /* sRGB EAGL drawable support was added in iOS 7. */
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    96
            if (UIKit_IsSystemVersionAtLeast(@"7.0")) {
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    97
                colorFormat = kEAGLColorFormatSRGBA8;
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    98
            } else {
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    99
                SDL_SetError("sRGB drawables are not supported.");
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   100
                return nil;
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   101
            }
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   102
        } else if (rBits >= 8 || gBits >= 8 || bBits >= 8) {
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   103
            /* if user specifically requests rbg888 or some color format higher than 16bpp */
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   104
            colorFormat = kEAGLColorFormatRGBA8;
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   105
        } else {
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   106
            /* default case (faster) */
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   107
            colorFormat = kEAGLColorFormatRGB565;
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   108
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   109
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   110
        /* Get the layer */
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   111
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   112
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   113
        eaglLayer.opaque = YES;
9499
6fe9b44b2d84 Updated the iOS Objective-C code to use NSDictionary/NSArray/NSNumber literals and subscripting, for improved code clarity.
Alex Szpakowski <slime73@gmail.com>
parents: 9498
diff changeset
   114
        eaglLayer.drawableProperties = @{
6fe9b44b2d84 Updated the iOS Objective-C code to use NSDictionary/NSArray/NSNumber literals and subscripting, for improved code clarity.
Alex Szpakowski <slime73@gmail.com>
parents: 9498
diff changeset
   115
            kEAGLDrawablePropertyRetainedBacking: @(retained),
6fe9b44b2d84 Updated the iOS Objective-C code to use NSDictionary/NSArray/NSNumber literals and subscripting, for improved code clarity.
Alex Szpakowski <slime73@gmail.com>
parents: 9498
diff changeset
   116
            kEAGLDrawablePropertyColorFormat: colorFormat
6fe9b44b2d84 Updated the iOS Objective-C code to use NSDictionary/NSArray/NSNumber literals and subscripting, for improved code clarity.
Alex Szpakowski <slime73@gmail.com>
parents: 9498
diff changeset
   117
        };
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   118
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   119
        /* Set the appropriate scale (for retina display support) */
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   120
        self.contentScaleFactor = scale;
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   121
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   122
        /* Create the color Renderbuffer Object */
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   123
        glGenRenderbuffers(1, &viewRenderbuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   124
        glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   125
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   126
        if (![context renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer]) {
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   127
            SDL_SetError("Failed to create OpenGL ES drawable");
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   128
            return nil;
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   129
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   130
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   131
        /* Create the Framebuffer Object */
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   132
        glGenFramebuffers(1, &viewFramebuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   133
        glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   134
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   135
        /* attach the color renderbuffer to the FBO */
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   136
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   137
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   138
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   139
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   140
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   141
        if ((useDepthBuffer) || (useStencilBuffer)) {
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   142
            if (useStencilBuffer) {
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   143
                /* Apparently you need to pack stencil and depth into one buffer. */
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   144
                depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   145
            } else if (useDepthBuffer) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   146
                /* iOS only has 24-bit depth buffers, even with GL_DEPTH_COMPONENT16 */
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   147
                depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   148
            }
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   149
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   150
            glGenRenderbuffers(1, &depthRenderbuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   151
            glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   152
            glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   153
            if (useDepthBuffer) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   154
                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   155
            }
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   156
            if (useStencilBuffer) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   157
                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   158
            }
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   159
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   160
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   161
        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   162
            SDL_SetError("Failed creating OpenGL ES framebuffer");
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   163
            return nil;
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   164
        }
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   165
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   166
        glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   167
    }
5130
ec13e48ee0d9 Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents: 5129
diff changeset
   168
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   169
    return self;
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
9514
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   172
- (GLuint)drawableRenderbuffer
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   173
{
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   174
    return viewRenderbuffer;
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   175
}
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   176
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   177
- (GLuint)drawableFramebuffer
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   178
{
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   179
    return viewFramebuffer;
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   180
}
5b56ab9ff5fe Added iOS-specific functions to get the window view's current OpenGL Renderbuffer and Framebuffer objects, so they can be more easily rebound when necessary.
Alex Szpakowski <slime73@gmail.com>
parents: 9510
diff changeset
   181
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   182
- (void)updateFrame
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   183
{
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   184
    glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   185
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   186
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   187
    glDeleteRenderbuffers(1, &viewRenderbuffer);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   188
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   189
    glGenRenderbuffers(1, &viewRenderbuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   190
    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   191
    [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   192
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   193
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   194
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   195
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   196
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   197
    if (depthRenderbuffer != 0) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   198
        glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   199
        glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   200
    }
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   201
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   202
    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   203
}
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   204
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   205
- (void)setAnimationCallback:(int)interval
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   206
                    callback:(void (*)(void*))callback
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   207
               callbackParam:(void*)callbackParam
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   208
{
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   209
    [self stopAnimation];
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   210
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   211
    animationInterval = interval;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   212
    animationCallback = callback;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   213
    animationCallbackParam = callbackParam;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   214
9492
cad5a9995bde The iOS 7 transparent status bar now uses white text rather than black.
Alex Szpakowski <slime73@gmail.com>
parents: 9488
diff changeset
   215
    if (animationCallback) {
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   216
        [self startAnimation];
9492
cad5a9995bde The iOS 7 transparent status bar now uses white text rather than black.
Alex Szpakowski <slime73@gmail.com>
parents: 9488
diff changeset
   217
    }
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   218
}
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   219
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   220
- (void)startAnimation
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   221
{
8891
7b6472f1b7ba Fixed bug 2563 - Remove obsolete code for supporting iOS < 5
Sam Lantinga <slouken@libsdl.org>
parents: 8233
diff changeset
   222
    displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   223
    [displayLink setFrameInterval:animationInterval];
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   224
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   225
}
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   226
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   227
- (void)stopAnimation
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   228
{
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   229
    [displayLink invalidate];
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   230
    displayLink = nil;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   231
}
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   232
8891
7b6472f1b7ba Fixed bug 2563 - Remove obsolete code for supporting iOS < 5
Sam Lantinga <slouken@libsdl.org>
parents: 8233
diff changeset
   233
- (void)doLoop:(CADisplayLink*)sender
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   234
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   235
    /* Don't run the game loop while a messagebox is up */
6686
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
   236
    if (!UIKit_ShowingMessageBox()) {
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
   237
        animationCallback(animationCallbackParam);
45014250760c Don't run the game loop while a messagebox is up
Sam Lantinga <slouken@libsdl.org>
parents: 6435
diff changeset
   238
    }
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   239
}
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
   240
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   241
- (void)setCurrentContext
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   242
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   243
    [EAGLContext setCurrentContext:context];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   246
- (void)swapBuffers
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   247
{
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   248
    /* viewRenderbuffer should always be bound here. Code that binds something
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   249
       else is responsible for rebinding viewRenderbuffer, to reduce duplicate
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   250
       state changes. */
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   251
    [context presentRenderbuffer:GL_RENDERBUFFER];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   254
- (void)layoutSubviews
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   255
{
9496
abc8df8ce987 The default implementation of [view layoutSubviews] actually does something in iOS 6+, so we should call [super layoutSubviews] when overriding it.
Alex Szpakowski <slime73@gmail.com>
parents: 9492
diff changeset
   256
    [super layoutSubviews];
abc8df8ce987 The default implementation of [view layoutSubviews] actually does something in iOS 6+, so we should call [super layoutSubviews] when overriding it.
Alex Szpakowski <slime73@gmail.com>
parents: 9492
diff changeset
   257
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   258
    [EAGLContext setCurrentContext:context];
6435
6172658e3ce9 We can update the OpenGL layer binding when we're laying out the views
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
   259
    [self updateFrame];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   262
- (void)destroyFramebuffer
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   263
{
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   264
    if (viewFramebuffer != 0) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   265
        glDeleteFramebuffers(1, &viewFramebuffer);
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   266
        viewFramebuffer = 0;
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   267
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   268
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   269
    if (viewRenderbuffer != 0) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   270
        glDeleteRenderbuffers(1, &viewRenderbuffer);
9498
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   271
        viewRenderbuffer = 0;
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   272
    }
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   273
d02c27e3f698 Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
Alex Szpakowski <slime73@gmail.com>
parents: 9496
diff changeset
   274
    if (depthRenderbuffer != 0) {
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   275
        glDeleteRenderbuffers(1, &depthRenderbuffer);
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   276
        depthRenderbuffer = 0;
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   277
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   281
- (void)dealloc
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   282
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   283
    if ([EAGLContext currentContext] == context) {
9510
e19faa3b5d88 Updated the iOS backend code to use Objective-C's automatic reference counting (ARC).
Alex Szpakowski <slime73@gmail.com>
parents: 9502
diff changeset
   284
        [self destroyFramebuffer];
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   285
        [EAGLContext setCurrentContext:nil];
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   286
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   289
@end
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5130
diff changeset
   290
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6022
diff changeset
   291
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6022
diff changeset
   292
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5130
diff changeset
   293
/* vi: set ts=4 sw=4 expandtab: */