src/video/uikit/SDL_uikitopenglview.m
author Alex Szpakowski <slime73@gmail.com>
Sun, 19 Jul 2015 19:56:16 -0300
changeset 9811 9d44e8794a9b
parent 9810 1e079120100e
child 9866 88e9cf11b8eb
permissions -rw-r--r--
iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
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
9619
b94b6d0bff0f Updated the copyright year to 2015
Sam Lantinga <slouken@libsdl.org>
parents: 9532
diff changeset
     3
  Copyright (C) 1997-2015 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
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    30
@implementation SDL_uikitopenglview {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    31
    /* 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
    32
    GLuint viewRenderbuffer, viewFramebuffer;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    33
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    34
    /* 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
    35
    GLuint depthRenderbuffer;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    36
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    37
    GLenum colorBufferFormat;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    38
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    39
    /* format of depthRenderbuffer */
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    40
    GLenum depthBufferFormat;
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    41
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    42
    /* The framebuffer and renderbuffer used for rendering with MSAA. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    43
    GLuint msaaFramebuffer, msaaRenderbuffer;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    44
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    45
    /* The number of MSAA samples. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    46
    int samples;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    47
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    48
    BOOL retainedBacking;
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    49
}
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
@synthesize context;
9501
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    52
@synthesize backingWidth;
574db299498f More cleanup of the iOS Objective-C code.
Alex Szpakowski <slime73@gmail.com>
parents: 9500
diff changeset
    53
@synthesize backingHeight;
9488
f15520430c94 Changed the way retina resolutions are handled in iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 8891
diff changeset
    54
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    55
+ (Class)layerClass
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
    56
{
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    57
    return [CAEAGLLayer class];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    60
- (instancetype)initWithFrame:(CGRect)frame
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    61
                        scale:(CGFloat)scale
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    62
                retainBacking:(BOOL)retained
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    63
                        rBits:(int)rBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    64
                        gBits:(int)gBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    65
                        bBits:(int)bBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    66
                        aBits:(int)aBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    67
                    depthBits:(int)depthBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    68
                  stencilBits:(int)stencilBits
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
    69
                         sRGB:(BOOL)sRGB
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    70
                 multisamples:(int)multisamples
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    71
                      context:(EAGLContext *)glcontext
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
{
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    73
    if ((self = [super initWithFrame:frame])) {
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    74
        const BOOL useStencilBuffer = (stencilBits != 0);
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    75
        const BOOL useDepthBuffer = (depthBits != 0);
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    76
        NSString *colorFormat = nil;
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
    77
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    78
        context = glcontext;
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    79
        samples = multisamples;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
    80
        retainedBacking = retained;
8233
ffece8ab18a6 Fixed bug 2407 - Support for OpenGL ES 3 contexts on iOS
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    81
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
    82
        if (!context || ![EAGLContext setCurrentContext:context]) {
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
    83
            SDL_SetError("Could not create OpenGL ES drawable (could not make context current)");
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
    84
            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
    85
        }
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
    86
9811
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    87
        if (samples > 0) {
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    88
            GLint maxsamples = 0;
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    89
            glGetIntegerv(GL_MAX_SAMPLES, &maxsamples);
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    90
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    91
            /* Verify that the sample count is supported before creating any
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    92
             * multisample Renderbuffers, to avoid generating GL errors. */
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    93
            if (samples > maxsamples) {
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    94
                SDL_SetError("Failed creating OpenGL ES framebuffer: Unsupported MSAA sample count");
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    95
                return nil;
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    96
            }
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    97
        }
9d44e8794a9b iOS: Avoid generating an OpenGL error (but still fail to create the context) if the specified MSAA sample count is unsupported.
Alex Szpakowski <slime73@gmail.com>
parents: 9810
diff changeset
    98
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
    99
        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
   100
            /* 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
   101
            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
   102
                colorFormat = kEAGLColorFormatSRGBA8;
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   103
                colorBufferFormat = GL_SRGB8_ALPHA8;
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   104
            } else {
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   105
                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
   106
                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
   107
            }
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   108
        } 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
   109
            /* 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
   110
            colorFormat = kEAGLColorFormatRGBA8;
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   111
            colorBufferFormat = GL_RGBA8;
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   112
        } else {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   113
            /* default case (potentially faster) */
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   114
            colorFormat = kEAGLColorFormatRGB565;
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   115
            colorBufferFormat = GL_RGB565;
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   116
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   117
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   118
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   119
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   120
        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
   121
        eaglLayer.drawableProperties = @{
9524
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9520
diff changeset
   122
            kEAGLDrawablePropertyRetainedBacking:@(retained),
9de159f9cefd Minor objective-c code style improvements
Alex Szpakowski <slime73@gmail.com>
parents: 9520
diff changeset
   123
            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
   124
        };
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   125
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
   126
        /* 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
   127
        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
   128
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
   129
        /* 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
   130
        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
   131
        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
   132
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   133
        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
   134
            SDL_SetError("Failed to create OpenGL ES drawable");
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   135
            return nil;
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   136
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   137
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
   138
        /* 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
   139
        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
   140
        glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   141
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
   142
        /* 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
   143
        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
   144
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   145
        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
   146
        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
   147
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   148
        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   149
            SDL_SetError("Failed creating OpenGL ES framebuffer");
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   150
            return nil;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   151
        }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   152
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   153
        /* When MSAA is used we'll use a separate framebuffer for rendering to,
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   154
         * since we'll need to do an explicit MSAA resolve before presenting. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   155
        if (samples > 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   156
            glGenFramebuffers(1, &msaaFramebuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   157
            glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   158
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   159
            glGenRenderbuffers(1, &msaaRenderbuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   160
            glBindRenderbuffer(GL_RENDERBUFFER, msaaRenderbuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   161
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   162
            glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, colorBufferFormat, backingWidth, backingHeight);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   163
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   164
            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, msaaRenderbuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   165
        }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   166
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   167
        if (useDepthBuffer || useStencilBuffer) {
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   168
            if (useStencilBuffer) {
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   169
                /* 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
   170
                depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   171
            } else if (useDepthBuffer) {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   172
                /* 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
   173
                 * depth buffers. */
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   174
                depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   175
            }
6022
e0327dd7d0c0 More cleanup in SDL_uikitopenglview.m
Ryan C. Gordon <icculus@icculus.org>
parents: 6021
diff changeset
   176
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   177
            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
   178
            glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   179
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   180
            if (samples > 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   181
                glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, depthBufferFormat, backingWidth, backingHeight);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   182
            } else {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   183
                glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   184
            }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   185
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   186
            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
   187
                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
   188
            }
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6008
diff changeset
   189
            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
   190
                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
   191
            }
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   192
        }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
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
        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
   195
            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
   196
            return nil;
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   197
        }
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   198
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   199
        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
   200
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
        [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
   202
    }
5130
ec13e48ee0d9 Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents: 5129
diff changeset
   203
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   204
    return self;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
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
   207
- (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
   208
{
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
   209
    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
   210
}
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
   211
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
   212
- (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
   213
{
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   214
    /* When MSAA is used, the MSAA draw framebuffer is used for drawing. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   215
    if (msaaFramebuffer) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   216
        return msaaFramebuffer;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   217
    } else {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   218
        return viewFramebuffer;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   219
    }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   220
}
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   221
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   222
- (GLuint)msaaResolveFramebuffer
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   223
{
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   224
    /* When MSAA is used, the MSAA draw framebuffer is used for drawing and the
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   225
     * view framebuffer is used as a MSAA resolve framebuffer. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   226
    if (msaaFramebuffer) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   227
        return viewFramebuffer;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   228
    } else {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   229
        return 0;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   230
    }
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
   231
}
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
   232
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   233
- (void)updateFrame
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   234
{
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
   235
    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
   236
    glGetIntegerv(GL_RENDERBUFFER_BINDING, &prevRenderbuffer);
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   237
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   238
    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   239
    [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
   240
9520
6a655264dd47 Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.
Alex Szpakowski <slime73@gmail.com>
parents: 9514
diff changeset
   241
    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
   242
    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
   243
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   244
    if (msaaRenderbuffer != 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   245
        glBindRenderbuffer(GL_RENDERBUFFER, msaaRenderbuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   246
        glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, backingWidth, backingHeight);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   247
    }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   248
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   249
    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
   250
        glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   251
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   252
        if (samples > 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   253
            glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, depthBufferFormat, backingWidth, backingHeight);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   254
        } else {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   255
            glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   256
        }
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   257
    }
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   258
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
   259
    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
   260
}
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
   261
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
   262
- (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
   263
{
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
   264
    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
   265
        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
   266
    }
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
   267
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
   268
    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
   269
        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
   270
    }
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
   271
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
   272
    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
   273
        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
   274
            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
   275
        } 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
   276
            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
   277
        }
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
   278
    }
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   279
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   280
    if (msaaFramebuffer != 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   281
        glLabelObjectEXT(GL_FRAMEBUFFER, msaaFramebuffer, 0, "context MSAA FBO");
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   282
    }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   283
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   284
    if (msaaRenderbuffer != 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   285
        glLabelObjectEXT(GL_RENDERBUFFER, msaaRenderbuffer, 0, "context MSAA renderbuffer");
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   286
    }
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   287
}
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5520
diff changeset
   288
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   289
- (void)swapBuffers
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   290
{
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   291
    if (msaaFramebuffer) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   292
        const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   293
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   294
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, viewFramebuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   295
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   296
        /* OpenGL ES 3+ provides explicit MSAA resolves via glBlitFramebuffer.
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   297
         * In OpenGL ES 1 and 2, MSAA resolves must be done via an extension. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   298
        if (context.API >= kEAGLRenderingAPIOpenGLES3) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   299
            int w = backingWidth;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   300
            int h = backingHeight;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   301
            glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   302
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   303
            if (!retainedBacking) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   304
                /* Discard the contents of the MSAA drawable color buffer. */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   305
                glInvalidateFramebuffer(GL_READ_FRAMEBUFFER, 1, attachments);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   306
            }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   307
        } else {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   308
            glResolveMultisampleFramebufferAPPLE();
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   309
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   310
            if (!retainedBacking) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   311
                glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER, 1, attachments);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   312
            }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   313
        }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   314
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   315
        /* We assume the "drawable framebuffer" (MSAA draw framebuffer) was
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   316
         * previously bound... */
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   317
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, msaaFramebuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   318
    }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   319
7784
70b305e09b4e Avoid redundant state changes in the GLES2 renderer.
Ryan C. Gordon <icculus@icculus.org>
parents: 7423
diff changeset
   320
    /* 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
   321
     * 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
   322
     * 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
   323
    [context presentRenderbuffer:GL_RENDERBUFFER];
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   326
- (void)layoutSubviews
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   327
{
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
   328
    [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
   329
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   330
    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
   331
    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
   332
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
   333
    /* 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
   334
    if (width != backingWidth || height != backingHeight) {
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   335
        EAGLContext *prevContext = [EAGLContext currentContext];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   336
        if (prevContext != context) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   337
            [EAGLContext setCurrentContext:context];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   338
        }
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   339
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
   340
        [self updateFrame];
9532
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   341
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   342
        if (prevContext != context) {
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   343
            [EAGLContext setCurrentContext:prevContext];
318042c16b76 Several improvements to the iOS backend:
Alex Szpakowski <slime73@gmail.com>
parents: 9529
diff changeset
   344
        }
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
   345
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   348
- (void)destroyFramebuffer
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   349
{
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
   350
    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
   351
        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
   352
        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
   353
    }
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
   354
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
   355
    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
   356
        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
   357
        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
   358
    }
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
   359
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
   360
    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
   361
        glDeleteRenderbuffers(1, &depthRenderbuffer);
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   362
        depthRenderbuffer = 0;
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   363
    }
9810
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   364
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   365
    if (msaaFramebuffer != 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   366
        glDeleteFramebuffers(1, &msaaFramebuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   367
        msaaFramebuffer = 0;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   368
    }
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   369
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   370
    if (msaaRenderbuffer != 0) {
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   371
        glDeleteRenderbuffers(1, &msaaRenderbuffer);
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   372
        msaaRenderbuffer = 0;
1e079120100e Added MSAA support for OpenGL ES contexts on iOS.
Alex Szpakowski <slime73@gmail.com>
parents: 9727
diff changeset
   373
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   376
- (void)dealloc
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6001
diff changeset
   377
{
9727
b845f659e015 iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes.
Alex Szpakowski <slime73@gmail.com>
parents: 9619
diff changeset
   378
    if (context && context == [EAGLContext currentContext]) {
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
   379
        [self destroyFramebuffer];
5129
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   380
        [EAGLContext setCurrentContext:nil];
5690ebc772c7 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   381
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   384
@end
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5130
diff changeset
   385
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6022
diff changeset
   386
#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
   387
5132
5f09cb749d75 Added vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 5130
diff changeset
   388
/* vi: set ts=4 sw=4 expandtab: */