author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 22 Oct 2011 01:23:21 -0400 | |
changeset 6021 | a4bf2a9b0fd0 |
parent 6008 | 73951a50e6db |
child 6022 | e0327dd7d0c0 |
permissions | -rw-r--r-- |
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 |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5527
diff
changeset
|
3 |
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org> |
5262 | 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 | 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 | 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 | 20 |
*/ |
2765
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 <QuartzCore/QuartzCore.h> |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
#import <OpenGLES/EAGLDrawable.h> |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
#import "SDL_uikitopenglview.h" |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
@implementation SDL_uikitopenglview |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
@synthesize context; |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
31 |
+ (Class)layerClass |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
32 |
{ |
5129 | 33 |
return [CAEAGLLayer class]; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
36 |
- (id)initWithFrame:(CGRect)frame |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
37 |
retainBacking:(BOOL)retained |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
38 |
rBits:(int)rBits |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
39 |
gBits:(int)gBits |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
40 |
bBits:(int)bBits |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
41 |
aBits:(int)aBits |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
42 |
depthBits:(int)depthBits |
6021
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
43 |
stencilBits:(int)stencilBits |
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
44 |
majorVersion:(int)majorVersion |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
{ |
6021
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
46 |
const BOOL useStencilBuffer = (stencilBits != 0); |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
47 |
const BOOL useDepthBuffer = (depthBits != 0); |
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
48 |
NSString *colorFormat = nil; |
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
49 |
|
5129 | 50 |
if (rBits == 8 && gBits == 8 && bBits == 8) { |
51 |
/* if user specifically requests rbg888 or some color format higher than 16bpp */ |
|
52 |
colorFormat = kEAGLColorFormatRGBA8; |
|
53 |
} |
|
54 |
else { |
|
55 |
/* default case (faster) */ |
|
56 |
colorFormat = kEAGLColorFormatRGB565; |
|
57 |
} |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
58 |
|
5527
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
59 |
depthBufferFormat = 0; |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
60 |
|
6021
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
61 |
if (useDepthBuffer) { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
62 |
if (depthBits == 24) { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
63 |
depthBufferFormat = GL_DEPTH_COMPONENT24_OES; |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
64 |
} |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
65 |
else { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
66 |
/* default case when depth buffer is not disabled */ |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
67 |
/* |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
68 |
strange, even when we use this, we seem to get a 24 bit depth buffer on iPhone. |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
69 |
perhaps that's the only depth format iPhone actually supports |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
70 |
*/ |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
71 |
depthBufferFormat = GL_DEPTH_COMPONENT16_OES; |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
72 |
} |
5129 | 73 |
} |
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
74 |
|
5129 | 75 |
if ((self = [super initWithFrame:frame])) { |
76 |
// Get the layer |
|
77 |
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
78 |
|
5129 | 79 |
eaglLayer.opaque = YES; |
80 |
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: |
|
81 |
[NSNumber numberWithBool: retained], kEAGLDrawablePropertyRetainedBacking, colorFormat, kEAGLDrawablePropertyColorFormat, nil]; |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
82 |
|
5209
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5132
diff
changeset
|
83 |
if (majorVersion > 1) { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5132
diff
changeset
|
84 |
context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2]; |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5132
diff
changeset
|
85 |
} else { |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5132
diff
changeset
|
86 |
context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1]; |
115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
Sam Lantinga <slouken@libsdl.org>
parents:
5132
diff
changeset
|
87 |
} |
5129 | 88 |
if (!context || ![EAGLContext setCurrentContext:context]) { |
89 |
[self release]; |
|
90 |
return nil; |
|
91 |
} |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
92 |
|
5129 | 93 |
/* create the buffers */ |
94 |
glGenFramebuffersOES(1, &viewFramebuffer); |
|
95 |
glGenRenderbuffersOES(1, &viewRenderbuffer); |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
96 |
|
5129 | 97 |
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); |
98 |
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); |
|
99 |
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer]; |
|
100 |
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer); |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
101 |
|
5129 | 102 |
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); |
103 |
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); |
|
5527
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
104 |
|
6021
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
105 |
if ((useDepthBuffer) || (useStencilBuffer)) { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
106 |
if (useStencilBuffer) { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
107 |
// Apparently you need to pack stencil and depth into one buffer. |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
108 |
// !!! FIXME: this is the only thing (currently) supported. May not always be true. |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
109 |
depthBufferFormat = GL_DEPTH24_STENCIL8_OES; |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
110 |
} |
5129 | 111 |
glGenRenderbuffersOES(1, &depthRenderbuffer); |
112 |
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); |
|
113 |
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight); |
|
6021
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
114 |
if (useDepthBuffer) { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
115 |
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
116 |
} |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
117 |
if (useStencilBuffer) { |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
118 |
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); |
a4bf2a9b0fd0
Added stencil buffer support on iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
6008
diff
changeset
|
119 |
} |
5129 | 120 |
} |
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
121 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
122 |
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) { |
5129 | 123 |
return NO; |
124 |
} |
|
125 |
/* end create buffers */ |
|
5130
ec13e48ee0d9
Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents:
5129
diff
changeset
|
126 |
|
5520
09b500e0656d
Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
5262
diff
changeset
|
127 |
// !!! FIXME: use the screen this is on! |
5130
ec13e48ee0d9
Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents:
5129
diff
changeset
|
128 |
/* Use the main screen scale (for retina display support) */ |
ec13e48ee0d9
Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents:
5129
diff
changeset
|
129 |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) |
ec13e48ee0d9
Fixed bug #1112 (retina display support)
Sam Lantinga <slouken@libsdl.org>
parents:
5129
diff
changeset
|
130 |
self.contentScaleFactor = [UIScreen mainScreen].scale; |
5520
09b500e0656d
Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
5262
diff
changeset
|
131 |
|
5527
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
132 |
self.autoresizingMask = 0; // don't allow autoresize, since we need to do some magic in -(void)updateFrame. |
5129 | 133 |
} |
134 |
return self; |
|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
137 |
- (void)updateFrame |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
138 |
{ |
5527
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
139 |
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
140 |
glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
141 |
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, 0); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
142 |
glDeleteRenderbuffersOES(1, &viewRenderbuffer); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
143 |
|
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
144 |
glGenRenderbuffersOES(1, &viewRenderbuffer); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
145 |
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
146 |
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer]; |
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
147 |
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer); |
5527
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
148 |
|
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
149 |
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
150 |
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
151 |
|
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
152 |
if (depthRenderbuffer != 0) { |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
153 |
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
154 |
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight); |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
155 |
} |
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
156 |
|
5527
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
157 |
// !!! FIXME: use the screen this is on! |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
158 |
/* Use the main screen scale (for retina display support) */ |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
159 |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
160 |
self.contentScaleFactor = [UIScreen mainScreen].scale; |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
161 |
} |
9a03d2300486
iOS: Correctly resize renderbuffers when rotating orientation.
Ryan C. Gordon <icculus@icculus.org>
parents:
5520
diff
changeset
|
162 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
163 |
- (void)setCurrentContext |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
164 |
{ |
5129 | 165 |
[EAGLContext setCurrentContext:context]; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
169 |
- (void)swapBuffers |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
170 |
{ |
5129 | 171 |
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); |
172 |
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; |
|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
176 |
- (void)layoutSubviews |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
177 |
{ |
5129 | 178 |
[EAGLContext setCurrentContext:context]; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
181 |
- (void)destroyFramebuffer |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
182 |
{ |
5129 | 183 |
glDeleteFramebuffersOES(1, &viewFramebuffer); |
184 |
viewFramebuffer = 0; |
|
185 |
glDeleteRenderbuffersOES(1, &viewRenderbuffer); |
|
186 |
viewRenderbuffer = 0; |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
187 |
|
5129 | 188 |
if (depthRenderbuffer) { |
189 |
glDeleteRenderbuffersOES(1, &depthRenderbuffer); |
|
190 |
depthRenderbuffer = 0; |
|
191 |
} |
|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
|
6003
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
195 |
- (void)dealloc |
fddf81967e2d
Use a consistent source code format in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
6001
diff
changeset
|
196 |
{ |
5129 | 197 |
[self destroyFramebuffer]; |
198 |
if ([EAGLContext currentContext] == context) { |
|
199 |
[EAGLContext setCurrentContext:nil]; |
|
200 |
} |
|
6001
3ae3d1e58d59
Cleanup out trailing whitespace in src/video/uikit
Kees Bakker <kees@ijzerbout.nl>
parents:
5535
diff
changeset
|
201 |
[context release]; |
5129 | 202 |
[super dealloc]; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
|
2859 | 205 |
@end |
5132 | 206 |
|
207 |
/* vi: set ts=4 sw=4 expandtab: */ |