mirror of https://github.com/encounter/SDL.git
Cleaned up iOS OpenGL ES context creation code and added sRGB context support on iOS 7+
This commit is contained in:
parent
cf2958a8de
commit
078ca9f078
|
@ -132,13 +132,14 @@ UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
share_group = [view.context sharegroup];
|
||||
}
|
||||
|
||||
/* construct our view, passing in SDL's OpenGL configuration data */
|
||||
CGRect frame;
|
||||
if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
|
||||
frame = [[uiwindow screen] bounds];
|
||||
} else {
|
||||
frame = [[uiwindow screen] applicationFrame];
|
||||
}
|
||||
|
||||
/* construct our view, passing in SDL's OpenGL configuration data */
|
||||
view = [[SDL_uikitopenglview alloc] initWithFrame: frame
|
||||
scale: scale
|
||||
retainBacking: _this->gl_config.retained_backing
|
||||
|
@ -148,6 +149,7 @@ UIKit_GL_CreateContext(_THIS, SDL_Window * window)
|
|||
aBits: _this->gl_config.alpha_size
|
||||
depthBits: _this->gl_config.depth_size
|
||||
stencilBits: _this->gl_config.stencil_size
|
||||
sRGB: _this->gl_config.framebuffer_srgb_capable
|
||||
majorVersion: _this->gl_config.major_version
|
||||
shareGroup: share_group];
|
||||
if (!view) {
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
aBits:(int)aBits
|
||||
depthBits:(int)depthBits
|
||||
stencilBits:(int)stencilBits
|
||||
sRGB:(BOOL)sRGB
|
||||
majorVersion:(int)majorVersion
|
||||
shareGroup:(EAGLSharegroup*)shareGroup;
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
aBits:(int)aBits
|
||||
depthBits:(int)depthBits
|
||||
stencilBits:(int)stencilBits
|
||||
sRGB:(BOOL)sRGB
|
||||
majorVersion:(int)majorVersion
|
||||
shareGroup:(EAGLSharegroup*)shareGroup
|
||||
{
|
||||
|
@ -59,12 +60,29 @@
|
|||
const BOOL useDepthBuffer = (depthBits != 0);
|
||||
NSString *colorFormat = nil;
|
||||
|
||||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.autoresizesSubviews = YES;
|
||||
|
||||
/* The EAGLRenderingAPI enum values currently map 1:1 to major GLES
|
||||
versions, and this allows us to handle future OpenGL ES versions.
|
||||
*/
|
||||
EAGLRenderingAPI api = majorVersion;
|
||||
|
||||
if (rBits == 8 && gBits == 8 && bBits == 8) {
|
||||
context = [[EAGLContext alloc] initWithAPI:api sharegroup:shareGroup];
|
||||
if (!context || ![EAGLContext setCurrentContext:context]) {
|
||||
[self release];
|
||||
SDL_SetError("OpenGL ES %d not supported", majorVersion);
|
||||
return nil;
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_7_0
|
||||
/* sRGB context support was added in iOS 7 */
|
||||
BOOL hasiOS7 = [[UIDevice currentDevice].systemVersion compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
|
||||
if (sRGB && hasiOS7) {
|
||||
colorFormat = kEAGLColorFormatSRGBA8;
|
||||
} else
|
||||
#endif
|
||||
if (rBits >= 8 && gBits >= 8 && bBits >= 8) {
|
||||
/* if user specifically requests rbg888 or some color format higher than 16bpp */
|
||||
colorFormat = kEAGLColorFormatRGBA8;
|
||||
} else {
|
||||
|
@ -81,23 +99,24 @@
|
|||
colorFormat, kEAGLDrawablePropertyColorFormat,
|
||||
nil];
|
||||
|
||||
context = [[EAGLContext alloc] initWithAPI:api sharegroup:shareGroup];
|
||||
if (!context || ![EAGLContext setCurrentContext:context]) {
|
||||
[self release];
|
||||
SDL_SetError("OpenGL ES %d not supported", majorVersion);
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* Set the appropriate scale (for retina display support) */
|
||||
self.contentScaleFactor = scale;
|
||||
|
||||
/* create the buffers */
|
||||
glGenFramebuffersOES(1, &viewFramebuffer);
|
||||
/* Create the color Renderbuffer Object */
|
||||
glGenRenderbuffersOES(1, &viewRenderbuffer);
|
||||
|
||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
|
||||
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
|
||||
|
||||
if (![context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]) {
|
||||
[self release];
|
||||
SDL_SetError("Failed creating OpenGL ES drawable");
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* Create the Framebuffer Object */
|
||||
glGenFramebuffersOES(1, &viewFramebuffer);
|
||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
|
||||
|
||||
/* attach the color renderbuffer to the FBO */
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
|
||||
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
||||
|
@ -124,15 +143,14 @@
|
|||
}
|
||||
|
||||
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
|
||||
return NO;
|
||||
[self release];
|
||||
SDL_SetError("Failed creating OpenGL ES framebuffer");
|
||||
return nil;
|
||||
}
|
||||
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
|
||||
/* end create buffers */
|
||||
|
||||
self.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
|
||||
self.autoresizesSubviews = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -220,12 +238,17 @@
|
|||
|
||||
- (void)destroyFramebuffer
|
||||
{
|
||||
if (viewFramebuffer != 0) {
|
||||
glDeleteFramebuffersOES(1, &viewFramebuffer);
|
||||
viewFramebuffer = 0;
|
||||
}
|
||||
|
||||
if (viewRenderbuffer != 0) {
|
||||
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
|
||||
viewRenderbuffer = 0;
|
||||
}
|
||||
|
||||
if (depthRenderbuffer) {
|
||||
if (depthRenderbuffer != 0) {
|
||||
glDeleteRenderbuffersOES(1, &depthRenderbuffer);
|
||||
depthRenderbuffer = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue