src/video/uikit/SDL_uikitopenglview.m
author Alex Szpakowski <slime73@gmail.com>
Thu, 15 Jan 2015 01:06:14 -0400
branchiOS-improvements
changeset 9532 318042c16b76
parent 9529 4bf9830d8153
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Several improvements to the iOS backend: - Added new custom launch screen code. It uses the launch screen nib when available on iOS 8+, the launch images dictionary if the launch screen nib isn't available, and the old standard image names if the launch image dictionary isn't in the plist. The launch screen is now hidden during the first call to SDL_PumpEvents rather than SDL_CreateWindow so apps can have the launch screen still visible if they do time-consuming loading after creating their window. It also fades out in roughly the same way as the system launch screen behavior. It can be disabled by setting the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h to 0. - A blank UIView is now created and displayed when the window is first created. The old behavior was to defer creating any view until SDL_GL_CreateContext, which prevented rotation, touch events, and other windowing-related things from working until then. This also makes it easier to use SDL_GetWindowWMInfo after creating a window. - Moved the keyboard and animation callback code from SDL's UIView subclasses to its UIViewController subclass, which lets them work properly in all cases when a SDL window is valid, even before SDL_GL_CreateContext is called and after SDL_GL_DeleteContext is called. - SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext are more robust. - Fixed some edge cases where SDL windows weren't rotating properly or their reported sizes were out of sync with their actual sizes. - Removed all calls to [UIApplication setStatusBarOrientation:]. It doesn't seem to work as expected in all cases in recent iOS versions. - Some code style cleanup.
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 <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
    26
#include <OpenGLES/ES2/glext.h>
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    27
#import "SDL_uikitopenglview.h"
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    28
#include "SDL_uikitwindow.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    30
@implementation SDLEAGLContext
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    31
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    32
@end
2765
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 {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    35
    /* The renderbuffer and framebuffer used to render to this layer. */
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    36
    GLuint viewRenderbuffer, viewFramebuffer;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    37
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    38
    /* The depth buffer that is attached to viewFramebuffer, if it exists. */
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    39
    GLuint depthRenderbuffer;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    40
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    41
    /* format of depthRenderbuffer */
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    42
    GLenum depthBufferFormat;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    43
}
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
@synthesize context;
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    46
@synthesize backingWidth;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    47
@synthesize backingHeight;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8891
diff changeset
    48
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    49
+ (Class)layerClass
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    50
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    51
    return [CAEAGLLayer class];
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
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    54
- (instancetype)initWithFrame:(CGRect)frame
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    55
                        scale:(CGFloat)scale
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    56
                retainBacking:(BOOL)retained
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    57
                        rBits:(int)rBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    58
                        gBits:(int)gBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    59
                        bBits:(int)bBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    60
                        aBits:(int)aBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    61
                    depthBits:(int)depthBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    62
                  stencilBits:(int)stencilBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    63
                         sRGB:(BOOL)sRGB
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    64
                 majorVersion:(int)majorVersion
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    65
                   shareGroup:(EAGLSharegroup*)shareGroup
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
{
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    67
    if ((self = [super initWithFrame:frame])) {
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    68
        const BOOL useStencilBuffer = (stencilBits != 0);
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    69
        const BOOL useDepthBuffer = (depthBits != 0);
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    70
        NSString *colorFormat = nil;
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    71
8233
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    72
        /* The EAGLRenderingAPI enum values currently map 1:1 to major GLES
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    73
         * versions, and this allows us to handle future OpenGL ES versions. */
8233
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    74
        EAGLRenderingAPI api = majorVersion;
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    75
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    76
        context = [[SDLEAGLContext alloc] initWithAPI:api sharegroup:shareGroup];
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
    77
        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
    78
            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
    79
            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
    80
        }
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
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    82
        context.sdlView = self;
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    83
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    84
        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
    85
            /* sRGB EAGL drawable support was added in iOS 7. */
9525
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
    86
            if (UIKit_IsSystemVersionAtLeast(7.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
    87
                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
    88
            } else {
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    89
                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
    90
                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
    91
            }
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    92
        } 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
    93
            /* 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
    94
            colorFormat = kEAGLColorFormatRGBA8;
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    95
        } else {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    96
            /* default case (potentially faster) */
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    97
            colorFormat = kEAGLColorFormatRGB565;
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
    98
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    99
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   100
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   101
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   102
        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
   103
        eaglLayer.drawableProperties = @{
9524
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9520
diff changeset
   104
            kEAGLDrawablePropertyRetainedBacking:@(retained),
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9520
diff changeset
   105
            kEAGLDrawablePropertyColorFormat:colorFormat
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
   106
        };
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   107
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
   108
        /* 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
   109
        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
   110
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
   111
        /* 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
   112
        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
   113
        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
   114
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   115
        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
   116
            SDL_SetError("Failed to create OpenGL ES drawable");
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   117
            return nil;
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   118
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   119
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
   120
        /* 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
   121
        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
   122
        glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   123
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
   124
        /* 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
   125
        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
   126
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   127
        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
   128
        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
   129
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   130
        if ((useDepthBuffer) || (useStencilBuffer)) {
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   131
            if (useStencilBuffer) {
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   132
                /* 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
   133
                depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   134
            } else if (useDepthBuffer) {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   135
                /* iOS only uses 32-bit float (exposed as fixed point 24-bit)
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   136
                 * depth buffers. */
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   137
                depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   138
            }
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   139
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   140
            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
   141
            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
   142
            glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   143
            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
   144
                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
   145
            }
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   146
            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
   147
                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
   148
            }
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   149
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   150
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   151
        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
   152
            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
   153
            return nil;
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   154
        }
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   155
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   156
        glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
9525
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   157
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   158
        [self setDebugLabels];
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
   159
    }
5130
ec13e48ee0d9 Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents: 5129
diff changeset
   160
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   161
    return self;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
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
   164
- (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
   165
{
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
   166
    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
   167
}
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
   168
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
   169
- (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
   170
{
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
   171
    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
   172
}
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
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   174
- (void)updateFrame
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   175
{
9526
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   176
    GLint prevRenderbuffer = 0;
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   177
    glGetIntegerv(GL_RENDERBUFFER_BINDING, &prevRenderbuffer);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   178
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   179
    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   180
    [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   181
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   182
    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
   183
    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
   184
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   185
    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
   186
        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
   187
        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
   188
    }
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   189
9526
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   190
    glBindRenderbuffer(GL_RENDERBUFFER, prevRenderbuffer);
9525
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   191
}
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   192
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   193
- (void)setDebugLabels
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   194
{
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   195
    if (viewFramebuffer != 0) {
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   196
        glLabelObjectEXT(GL_FRAMEBUFFER, viewFramebuffer, 0, "context FBO");
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   197
    }
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   198
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   199
    if (viewRenderbuffer != 0) {
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   200
        glLabelObjectEXT(GL_RENDERBUFFER, viewRenderbuffer, 0, "context color buffer");
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   201
    }
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   202
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   203
    if (depthRenderbuffer != 0) {
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   204
        if (depthBufferFormat == GL_DEPTH24_STENCIL8_OES) {
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   205
            glLabelObjectEXT(GL_RENDERBUFFER, depthRenderbuffer, 0, "context depth-stencil buffer");
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   206
        } else {
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   207
            glLabelObjectEXT(GL_RENDERBUFFER, depthRenderbuffer, 0, "context depth buffer");
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   208
        }
64e3f446d6d7 Added debug labels for the OpenGL ES objects created with SDL_GL_CreateContext on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9524
diff changeset
   209
    }
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   210
}
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   211
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   212
- (void)setCurrentContext
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   213
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   214
    [EAGLContext setCurrentContext:context];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   217
- (void)swapBuffers
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   218
{
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   219
    /* viewRenderbuffer should always be bound here. Code that binds something
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   220
     * else is responsible for rebinding viewRenderbuffer, to reduce duplicate
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   221
     * state changes. */
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   222
    [context presentRenderbuffer:GL_RENDERBUFFER];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   225
- (void)layoutSubviews
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   226
{
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
   227
    [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
   228
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   229
    int width  = (int) (self.bounds.size.width * self.contentScaleFactor);
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   230
    int height = (int) (self.bounds.size.height * self.contentScaleFactor);
9526
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   231
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   232
    /* Update the color and depth buffer storage if the layer size has changed. */
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   233
    if (width != backingWidth || height != backingHeight) {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   234
        EAGLContext *prevContext = [EAGLContext currentContext];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   235
        if (prevContext != context) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   236
            [EAGLContext setCurrentContext:context];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   237
        }
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   238
9526
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   239
        [self updateFrame];
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   240
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   241
        if (prevContext != context) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   242
            [EAGLContext setCurrentContext:prevContext];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   243
        }
9526
b1e51123fbea The iOS OpenGL ES context's color Renderbuffer Object is no longer completely destroyed and recreated in layoutSubviews. Its storage is now only reallocated when the actual size of the layer changes. The framebuffer object and renderbuffer object binding states are no longer clobbered by the storage reallocation code in layoutSubviews.
Alex Szpakowski <slime73@gmail.com>
parents: 9525
diff changeset
   244
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   247
- (void)destroyFramebuffer
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   248
{
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
   249
    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
   250
        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
   251
        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
   252
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   253
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
   254
    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
   255
        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
   256
        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
   257
    }
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
   258
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
   259
    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
   260
        glDeleteRenderbuffers(1, &depthRenderbuffer);
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   261
        depthRenderbuffer = 0;
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   262
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   265
- (void)dealloc
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   266
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   267
    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
   268
        [self destroyFramebuffer];
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   269
        [EAGLContext setCurrentContext:nil];
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   270
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   273
@end
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5130
diff changeset
   274
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6022
diff changeset
   275
#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
   276
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5130
diff changeset
   277
/* vi: set ts=4 sw=4 expandtab: */