src/video/uikit/SDL_uikitopenglview.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Jul 2013 23:30:26 -0400
changeset 7423 dfe7ad02f008
parent 6885 700f1b25f77f
child 8149 681eb46b8ac4
permissions -rw-r--r--
Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS. Fixes Bugzilla #1947.
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
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6342
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
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.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
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:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
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.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#import <UIKit/UIKit.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#import <OpenGLES/EAGL.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#import <OpenGLES/ES1/gl.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#import <OpenGLES/ES1/glext.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#import "SDL_uikitview.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
/*
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    28
    This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    29
    The view content is basically an EAGL surface you render your OpenGL scene into.
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    30
    Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
 */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
@interface SDL_uikitopenglview : SDL_uikitview {
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    33
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
@private
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    35
    /* The pixel dimensions of the backbuffer */
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    36
    GLint backingWidth;
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    37
    GLint backingHeight;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    38
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    39
    EAGLContext *context;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    40
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    41
    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    42
    GLuint viewRenderbuffer, viewFramebuffer;
6001
3ae3d1e58d59 Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 5535
diff changeset
    43
5209
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    44
    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
115fff0641ee Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents: 5133
diff changeset
    45
    GLuint depthRenderbuffer;
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    46
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    47
    /* format of depthRenderbuffer */
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    48
    GLenum depthBufferFormat;
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    49
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    50
    id displayLink;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    51
    int animationInterval;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    52
    void (*animationCallback)(void*);
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    53
    void *animationCallbackParam;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
@property (nonatomic, retain, readonly) EAGLContext *context;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
- (void)swapBuffers;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
- (void)setCurrentContext;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
- (id)initWithFrame:(CGRect)frame
6267
ed2cf4669e55 * On iOS, fix support for the case where [UIScreen scale] is not 1.0 (retina)
Tim Angus <tim@blackcompanystudios.co.uk>
parents: 6138
diff changeset
    62
    scale:(CGFloat)scale
6003
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6002
diff changeset
    63
    retainBacking:(BOOL)retained
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6002
diff changeset
    64
    rBits:(int)rBits
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6002
diff changeset
    65
    gBits:(int)gBits
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6002
diff changeset
    66
    bBits:(int)bBits
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6002
diff changeset
    67
    aBits:(int)aBits
fddf81967e2d Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents: 6002
diff changeset
    68
    depthBits:(int)depthBits
6021
a4bf2a9b0fd0 Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6003
diff changeset
    69
    stencilBits:(int)stencilBits
7423
dfe7ad02f008 Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    70
    majorVersion:(int)majorVersion
dfe7ad02f008 Implement SDL_GL_SHARE_WITH_CURRENT_CONTEXT for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
    71
    shareGroup:(EAGLSharegroup*)shareGroup;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
5527
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    73
- (void)updateFrame;
9a03d2300486 iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents: 5262
diff changeset
    74
6342
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    75
- (void)setAnimationCallback:(int)interval
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    76
    callback:(void (*)(void*))callback
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    77
    callbackParam:(void*)callbackParam;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    78
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    79
- (void)startAnimation;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    80
- (void)stopAnimation;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    81
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    82
- (void)doLoop:(id)sender;
ac83b73f0edd Created a header file for system dependent API functions, and added SDL_iPhoneSetAnimationCallback()
Sam Lantinga <slouken@libsdl.org>
parents: 6267
diff changeset
    83
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
@end
5133
b915b3181cc2 Fixed spacing, adding vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    85
b915b3181cc2 Fixed spacing, adding vim spacing hints
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    86
/* vi: set ts=4 sw=4 expandtab: */