Merge pull request #27071 from samgreen/ios_gles2_fix
Resolve GLES 2 crash on older iOS devices
This commit is contained in:
commit
b00c96a861
2 changed files with 31 additions and 19 deletions
|
@ -615,18 +615,6 @@ static int frame_count = 0;
|
||||||
|
|
||||||
// Create a full-screen window
|
// Create a full-screen window
|
||||||
window = [[UIWindow alloc] initWithFrame:rect];
|
window = [[UIWindow alloc] initWithFrame:rect];
|
||||||
// window.autoresizesSubviews = YES;
|
|
||||||
//[window setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
|
|
||||||
// UIViewAutoresizingFlexibleWidth];
|
|
||||||
|
|
||||||
// Create the OpenGL ES view and add it to the window
|
|
||||||
GLView *glView = [[GLView alloc] initWithFrame:rect];
|
|
||||||
printf("glview is %p\n", glView);
|
|
||||||
//[window addSubview:glView];
|
|
||||||
glView.delegate = self;
|
|
||||||
// glView.autoresizesSubviews = YES;
|
|
||||||
//[glView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
|
|
||||||
// UIViewAutoresizingFlexibleWidth];
|
|
||||||
|
|
||||||
OS::VideoMode vm = _get_video_mode();
|
OS::VideoMode vm = _get_video_mode();
|
||||||
|
|
||||||
|
@ -641,6 +629,12 @@ static int frame_count = 0;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// WARNING: We must *always* create the GLView after we have constructed the
|
||||||
|
// OS with iphone_main. This allows the GLView to access project settings so
|
||||||
|
// it can properly initialize the OpenGL context
|
||||||
|
GLView *glView = [[GLView alloc] initWithFrame:rect];
|
||||||
|
glView.delegate = self;
|
||||||
|
|
||||||
view_controller = [[ViewController alloc] init];
|
view_controller = [[ViewController alloc] init];
|
||||||
view_controller.view = glView;
|
view_controller.view = glView;
|
||||||
window.rootViewController = view_controller;
|
window.rootViewController = view_controller;
|
||||||
|
|
|
@ -284,19 +284,37 @@ static void clear_touches() {
|
||||||
kEAGLColorFormatRGBA8,
|
kEAGLColorFormatRGBA8,
|
||||||
kEAGLDrawablePropertyColorFormat,
|
kEAGLDrawablePropertyColorFormat,
|
||||||
nil];
|
nil];
|
||||||
|
bool fallback_gl2 = false;
|
||||||
// Create our EAGLContext, and if successful make it current and create our framebuffer.
|
// Create a GL ES 3 context based on the gl driver from project settings
|
||||||
|
if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3") {
|
||||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
||||||
|
NSLog(@"Setting up an OpenGL ES 3.0 context. Based on Project Settings \"rendering/quality/driver/driver_name\"");
|
||||||
if (!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
|
if (!context && GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
||||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
|
||||||
gles3_available = false;
|
gles3_available = false;
|
||||||
if (!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
|
fallback_gl2 = true;
|
||||||
[self release];
|
NSLog(@"Failed to create OpenGL ES 3.0 context. Falling back to OpenGL ES 2.0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create GL ES 2 context
|
||||||
|
if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES2" || fallback_gl2) {
|
||||||
|
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||||
|
NSLog(@"Setting up an OpenGL ES 2.0 context.");
|
||||||
|
if (!context) {
|
||||||
|
NSLog(@"Failed to create OpenGL ES 2.0 context!");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (![EAGLContext setCurrentContext:context]) {
|
||||||
|
NSLog(@"Failed to set EAGLContext!");
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
if (![self createFramebuffer]) {
|
||||||
|
NSLog(@"Failed to create frame buffer!");
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
// Default the animation interval to 1/60th of a second.
|
// Default the animation interval to 1/60th of a second.
|
||||||
animationInterval = 1.0 / 60.0;
|
animationInterval = 1.0 / 60.0;
|
||||||
return self;
|
return self;
|
||||||
|
|
Loading…
Reference in a new issue